zhuguifei
2024-12-25 576d28de6be2d75bfd5a213874dd8d06657635b5
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
112
113
114
115
116
117
<script>
    import Vue from 'vue'
 
    export default {
        //全局变量(同步数据可用全局变量,异步数据使用vuex)
        globalData: {
            token: "",
            //当前选择tab
            selectTab: 0,
            //当前网络模式(cloud-云服务、lan-局域网)
            mode: "",
        },
        onLaunch: function() {
 
 
 
            //此处为unipush2.0的推送方法
            // uni-app客户端获取push客户端标记
            // uni.getPushClientId({
            //     success: (res) => {
            //         let push_clientid = res.cid
            //         console.log('客户端推送标识:', push_clientid)
            //     },
            //     fail(err) {
            //         console.log(err)
            //     }
            // })
            // uni.onPushMessage((res) => {
            //     console.log("收到推送消息:", res) //监听推送消息
            // })
 
 
            //推送仅支持Android ios原生平台
            // #ifdef APP-PLUS
            // 此处为unipush1.0的推送方法
            plus.push.getClientInfoAsync((info) => {
                let cid = info["clientid"];
                console.log('客户端推送标识:', cid)
                this.$store.dispatch('setClientPushId', cid); // 使用 action 更新 cid
 
            });
            // #endif
            uni.onPushMessage((res) => {
                console.log("收到推送消息:", res) //监听推送消息
            })
 
            uni.getSystemInfo({
                success: function(e) {
                    // #ifndef MP
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    if (e.platform == 'android') {
                        Vue.prototype.CustomBar = e.statusBarHeight + 50;
                    } else {
                        Vue.prototype.CustomBar = e.statusBarHeight + 45;
                    };
                    // #endif
 
                    // #ifdef MP-WEIXIN
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    let custom = wx.getMenuButtonBoundingClientRect();
                    Vue.prototype.Custom = custom;
                    Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight + 4;
                    // #endif        
 
                    // #ifdef MP-ALIPAY
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
                    // #endif
                }
            });
            console.log('App Launch')
        },
        onShow: function() {
            console.log('App Show')
            // this.conn()
 
 
        },
        onHide: function() {
            console.log('App Hide')
            // this.disconn()
        },
        methods: {
            //处理掉线重连
            conn() {
                console.log(this.$mqttTool.client)
                if (this.$mqttTool.client) {
                    console.log(this.$mqttTool.client.connected)
                }
                if (this.$mqttTool.client && !this.$mqttTool.client.connected) {
                    console.info("开始重连")
                    this.$mqttTool.reconnect()
                } else {
 
                }
            },
            disconn() {
                console.log(this.$mqttTool.client)
                if (this.$mqttTool.client) {
                    console.log(this.$mqttTool.client.connected)
                }
            
            }
 
        },
        mounted() {
 
        }
    }
</script>
 
<style lang="scss">
    /*每个页面公共css */
    @import "colorui/main.css";
    @import "colorui/icon.css";
    @import "uview-ui/index.scss";
</style>