1
fei.wang
2025-03-07 1b6a3e58e8d3f9a4a56810b5433e28230fe8f3bb
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<script>
    import Vue from 'vue'
    import store from './store/index.js'
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
    import updateCustomBarInfo from './tuniao-ui/libs/function/updateCustomBarInfo.js'
    export default {
        onLaunch: function() { 
            setTimeout(() => {
                        // app 检测更新
                        checkUpdate();
                    }, 2000);
                        console.log('App Launch')
                        uni.getPushClientId({
                            success: (res) => { 
                                console.log(res.cid);
                                store.commit('$tStore', {
                                    name: 'uuid',
                                    value: res.cid
                                })
                                
                            },
                            fail(err) {
                                console.log(err)
                            }
                        });
                        uni.onPushMessage((res) => {
                            console.log("收到推送消息:",res) //监听推送消息
                            if(res.data){
                                console.log(res.data)
                                uni.createPushMessage(res.data)  //收到消息推送,创建系统状态栏及锁屏通 知
                            }
                        })
                    // },
            console.log(uni.getStorageSync('access_token'));
            var data = {}
            data.token =  uni.getStorageSync('access_token')
            var method ='GET'
            var contentType='application/x-www-form-urlencoded'
            uni.request({ 
                // url: "http://192.168.31.101:8181/Fence/", //接口地址。
                // url: "http://111.198.60.6:6008/Fence/", //接口地址。
                // url: "http://123.56.113.213:8081/api/wx/checkLogin", //接口地址。
                url: "http://39.106.210.13:8090/api/wx/checkLogin", //接口地址。
                data: data,
                method: method,
                header: { //请求头可自定义
                'Authorization':uni.getStorageSync('access_token'),
                    'content-type': contentType,
                },
                timeout:5000,//设置超时时间,默认5秒
                success: (rep) => { //具体捕获请看自己接口返回的形式
                console.log(rep);
            if (rep.data.code!=0) {
                store.commit('$tStore', {
                    name: 'vuex_is_login',
                    value: false
                })
                // uni.reLaunch({
                //     url: '/pages/index/login'
                // });
                uni.reLaunch({
                    url: '/pages/index/index'
                });
            }else{
                uni.reLaunch({
                    url: '/pages/index/index'
                });
            }
        
                },
                fail(error) {
                    console.log(error);
                    // uni.hideLoading();
                    // uni.$u.toast('网络不通');
                    // reject(error)
                },
                // complete() { 
                //     uni.hideLoading();
                // }
            });
            uni.getSystemInfo({
                success: function(e) {
                    
                    
                    console.info('e',e)
                    Vue.prototype.screenHeight = e.screenHeight
                    Vue.prototype.safeBottom = e.safeAreaInsets.bottom
 
                    // #ifndef H5
                    // 获取手机系统版本
                    const system = e.system.toLowerCase()
                    const platform = e.platform.toLowerCase()
                    // 判断是否为ios设备
                    if (platform.indexOf('ios') != -1 && (system.indexOf('ios') != -1 || system.indexOf(
                            'macos') != -1)) {
                        Vue.prototype.SystemPlatform = 'apple'
                    } else if (platform.indexOf('android') != -1 && (system.indexOf('android') != -1)) {
                        Vue.prototype.SystemPlatform = 'android'
                    } else {
                        Vue.prototype.SystemPlatform = 'devtools'
                    }
                    // #endif
                }
            })
 
            // 获取设备的状态栏信息和自定义顶栏信息
            // store.dispatch('updateCustomBarInfo')
            updateCustomBarInfo().then((res) => {
                store.commit('$tStore', {
                    name: 'vuex_status_bar_height',
                    value: res.statusBarHeight
                })
                store.commit('$tStore', {
                    name: 'vuex_custom_bar_height',
                    value: res.customBarHeight
                })
            })
 
            // #ifdef MP-WEIXIN
            //更新检测
            if (wx.canIUse('getUpdateManager')) {
                const updateManager = wx.getUpdateManager();
                updateManager && updateManager.onCheckForUpdate((res) => {
                    if (res.hasUpdate) {
                        updateManager.onUpdateReady(() => {
                            uni.showModal({
                                title: '更新提示',
                                content: '新版本已经准备就绪,是否需要重新启动应用?',
                                success: (res) => {
                                    if (res.confirm) {
                                        uni.clearStorageSync() // 更新完成后刷新storage的数据
                                        updateManager.applyUpdate()
                                    }
                                }
                            })
                        })
 
                        updateManager.onUpdateFailed(() => {
                            uni.showModal({
                                title: '已有新版本上线',
                                content: '小程序自动更新失败,请删除该小程序后重新搜索打开哟~~~',
                                showCancel: false
                            })
                        })
                    } else {
                        //没有更新
                    }
                })
            } else {
                uni.showModal({
                    title: '提示',
                    content: '当前微信版本过低,无法使用该功能,请更新到最新的微信后再重试。',
                    showCancel: false
                })
            }
            // #endif
        },
        onShow: function() {
            console.log('App Show')
 
        },
        onHide: function() {
            console.log('App Hide')
        }
    }
</script>
 
<style lang="scss">
    :root {
        --main-color--: #40A290;
    }
 
    /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
    @import './tuniao-ui/index.scss';
    @import './tuniao-ui/iconfont.css';
 
    @import "uview-ui/index.scss";
 
    .page-title {
        font-weight: bold;
    }
 
    .list-null {
        width: 100%;
        height: 100%;
        padding-top: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>