quanyawei
2024-01-10 e13367edf304cb78f978e321f1679299a66b3a23
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<script>
    import {
        getDic
    } from '@/utils/login.js' // 配置文件
    import store from '@/store/index.js'
    import {
        httpPost,
        httpGet
    } from '@/utils/http.js'
    export default {
        onShow(options) {
            this.checkUpdate()
            console.log('optionsonShow', options)
            if (options.scene === 1007 || options.scene === 1014 || options.scene === 1008) {
                // 通过单人聊天会话分享进入
                // this.getWXCode()
            }
        },
        onLaunch() {
            // 自动登录检测
            let token = uni.getStorageSync('token')
            console.log('apptoken1', !token)
            if (!token) {
                uni.login({
                    provider: 'weixin',
                    success: loginRes => {
                        console.log('loginRes1', loginRes)
                        httpGet('/AppUser/wx/login', {
                            'code': loginRes.code
                        }).then(result => {
                            console.log('AppUser1', result)
                            try {
                                if (result.data.code === 0) {
                                    uni.clearStorageSync()
                                    uni.setStorageSync('userInfor', JSON.stringify(result.data))
                                    uni.setStorageSync('tonken', result.data.token)
                                    uni.setStorageSync('openId', result.data.openId)
                                    getDic()
                                    this.$isResolve()
                                } else {
                                    uni.clearStorageSync()
                                    uni.setStorageSync('openId', result.data.openId)
                                    uni.showModal({
                                        title: '未登录',
                                        content: '您未登录,需要登录后才能继续',
                                        showCancel: false,
                                        confirmText: '确定',
                                        success: res => {
                                            if (res.confirm) {
                                                uni.reLaunch({
                                                    url: '/pages/login/login',
                                                })
                                            }
                                        },
                                    })
                                    this.$isResolve()
                                }
                            } catch (e) {
                                console.error(e)
                            }
                        }).catch(errors => {
                            console.log('appdddd', errors)
                            uni.showToast({
                                title: errors,
                                icon: 'none',
                            })
                            this.$isResolve()
                        })
                    }
                })
            } else {
                this.$isResolve()
            }
        },
        methods: {
            checkUpdate() {
                // 判断当前微信版本是否支持检测更新接口,注:(基础库版本大于v1.9.90才可以使用getUpdateManager接口所以要做低版本兼容处理)
                if (uni.canIUse('getUpdateManager')) {
                    const updateManager = uni.getUpdateManager()
                    // 请求完新版本信息的回调
                    updateManager.onCheckForUpdate(function(res) {
                        // 如有新版本则进行静默下载更新并提示
                        console.log('res.hasUpdate', res.hasUpdate)
                        console.log('版本信息', res)
                        if (res.hasUpdate) {
                            // 新版本下载成功
                            updateManager.onUpdateReady(function() {
                                uni.showModal({
                                    title: '更新提示',
                                    content: '发现新版本',
                                    showCancel: false,
                                    success(res) {
                                        if (res.confirm) {
                                            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                                            updateManager.applyUpdate()
                                        }
                                    }
                                })
                            })
                            // 新版本下载失败
                            updateManager.onUpdateFailed(function() {
                                uni.showModal({
                                    title: '更新提示',
                                    content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
                                    showCancel: false
                                })
                            })
                        }
                    })
                } else {
                    // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
                    uni.showModal({
                        title: '提示',
                        content: '当前微信版本过低,无法使用最新版的小程序,请升级到最新微信版本后重试。',
                        success(res) {
                            if (res.confirm) {
                                // 使用此接口可直接跳转至微信客户端更新下载页面
                                uni.updateWeChatApp()
                            }
                        }
                    })
                }
            },
            /**
             * 自动登录
             * 判断本地是否有账号信息,如果有,就自动重新登录
             *
             */
            getWXCode() {
                uni.login({
                    provider: 'weixin',
                    success: loginRes => {
                        console.log('loginRes2', loginRes)
                        httpGet('/AppUser/wx/login', {
                            'code': loginRes.code
                        }).then(result => {
                            console.log('AppUser2', result)
                            try {
                                if (result.data.code === 0) {
                                    uni.clearStorageSync()
                                    uni.setStorageSync('userInfor', JSON.stringify(result.data))
                                    uni.setStorageSync('tonken', result.data.token)
                                    uni.setStorageSync('openId', result.data.openId)
                                    getDic()
                                    this.$isResolve()
                                } else {
                                    uni.clearStorageSync()
                                    uni.setStorageSync('openId', result.data.openId)
                                    uni.showModal({
                                        title: '未登录',
                                        content: '您未登录,需要登录后才能继续',
                                        showCancel: false,
                                        confirmText: '确定',
                                        success: res => {
                                            if (res.confirm) {
                                                uni.reLaunch({
                                                    url: '/pages/login/login',
                                                })
                                            }
                                        },
                                    })
                                    this.$isResolve()
                                }
                            } catch (e) {
                                console.error(e)
                            }
                        }).catch(errors => {
                            console.log('appdddd2', errors)
                            uni.showToast({
                                title: errors,
                                icon: 'none',
                            })
                            this.$isResolve()
                        })
                    }
                })
            },
            getLogin(data) {
                // 调用接口。将登录code传给后端进行判断
                httpGet('/AppUser/wx/login', {
                    'code': data
                }).then(result => {
                    if (result.data.code === 0) {
                        // 存在用户
                        uni.clearStorage()
                        store.commit('setUserInfor', result.data)
                        store.commit('setTonken', result.data.token)
                        getDic()
                        try {
                            this.$isResolve()
                        } catch (e) {
                            console.error(e)
                        }
                        // getUserInfor(result.data.token)
                    } else {
                        // 不存在用户
                        // console.log('openId', result.data.openId)
                    }
                })
            }
        },
    }
</script>
<style lang="scss">
    /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
    @import "@/uni_modules/uview-ui/index.scss";
 
    html {
        height: 100%;
        overflow-x: hidden;
        width: 750rpx;
    }
 
    .formItemContent {
        ::v-deep.u-form-item {
            padding: 5px 0;
            border-bottom: 1px dashed #bbb;
        }
 
        ::v-deep.u-form-item__body__left__content__label {
            font-size: 16px !important;
        }
 
        ::v-deep.u-form-item__body,
        /deep/.u-textarea {
            padding: 0 !important;
        }
    }
 
    .tabarStyle {
        /deep/.u-tabbar-item__text {
            font-size: 18px !important;
        }
 
        /deep/.u-tabbar__content__item-wrapper {
            height: 60px !important;
        }
 
        /deep/.u-icon__icon {
            font-size: 25px !important;
        }
    }
 
    .dataRangeSerch {
 
        /deep/.range-separator,
        /deep/.uni-date__x-input {
            height: 30px !important;
            line-height: 30px !important;
        }
    }
 
    .ridoaBox {
        text-align: center;
        padding: 10px 0px;
 
        /deep/.u-radio {
            padding-right: 10px;
        }
    }
</style>