gaoluyang
2026-06-04 ed39f5e8cb15ece064c45ee6ee0f370fc740244d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
    <Splash v-if="showSplash" />
    <view v-else>
        <router-view />
    </view>
</template>
<script setup>
import { ref, onMounted } from "vue";
import Splash from "./components/Splash.vue";
import { confirmMessage } from "@/api/login.js";
 
const showSplash = ref(true);
 
onMounted(() => {
    setTimeout(() => {
        showSplash.value = false;
    }, 5000);
    
    // 初始化推送服务,暂时注释,客户需要打开
    // initPushService();
});
// 初始化推送服务(uni-push 1.0)
const initPushService = () => {
    // #ifdef APP-PLUS
    console.log("开始初始化推送服务(uni-push 1.0)");
    if (typeof plus !== "undefined" && plus.push) {
        console.log("plus.push 存在:", plus.push);
        
        // 获取客户端推送标识
        console.log("使用 plus.push.getClientInfo 获取客户端标识");
        plus.push.getClientInfoAsync(info => {
            console.log("客户端推送标识:", info);
            uni.setStorageSync("clientid", info.clientid);
            
            // 这里可以将客户端标识发送到服务器
        });
        setTimeout(() => {
            console.log("使用 plus.push.getClientInfoAsync 获取客户端标识");
            plus.push.getClientInfoAsync(info => {
                console.log("客户端推送标识:", info);
                // 这里可以将客户端标识发送到服务器
            });
        }, 1000);
        
        // 监听推送消息点击事件
        plus.push.addEventListener("click", handlePushClick, false);
        // 监听推送消息接收事件
        plus.push.addEventListener("receive", handlePushReceive, false);
        console.log("推送服务注册成功");
    } else {
        console.log("推送服务不可用");
    }
    // #endif
};
 
// 处理推送消息点击事件
const handlePushClick = msg => {
    console.log("点击推送消息:", msg);
    console.log("解析后:", msg.payload.noticeId);
    try {
        if (msg.payload.needMarkRead) {
            confirmMessage(msg.payload.noticeId, 1).then(res => {
                if (msg.payload.url) {
                    if (msg.payload.url.indexOf("/") === 0) {
                        uni.navigateTo({
                            url: msg.payload.url,
                        });
                    } else {
                        uni.navigateTo({
                            url: "/" + msg.payload.url,
                        });
                    }
                }
            });
        } else {
            if (msg.payload.url) {
                if (msg.payload.url.indexOf("/") === 0) {
                    uni.navigateTo({
                        url: msg.payload.url,
                    });
                } else {
                    uni.navigateTo({
                        url: "/" + msg.payload.url,
                    });
                }
            }
        }
    } catch (error) {
        uni.showToast({
            title: "路径:" + msg.payload,
            icon: "none",
        });
        uni.showToast({
            title: "跳转失败:" + error.message,
            icon: "none",
        });
    }
    // 解析并处理推送消息...
};
 
// 处理推送消息接收事件
const handlePushReceive = msg => {
    console.log("收到推送消息:", msg);
    // 处理接收的推送消息...
};
</script>
 
<style lang="scss">
@import "uview-plus/index.scss";
@import "@/static/scss/index.scss";
</style>