#
whycq
2023-12-04 903890d942de1271784032ff18ac68749086b897
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<template>
    <view class="container">
        <image class="logo" src="/static/image/logo.png"></image>
        <!-- 登录信息 -->
        <view class="user-info">
            <view class="user-info-item shadow-warp">
                <view class="icons">
                    <uni-icons type="person" size="20"></uni-icons>
                </view>
                <text>手机号:</text>
                <input type="text" placeholder="请输入账号!" v-model="user.phone"
                    placeholder-style="font-size:14px;color:#ccc;">
            </view>
            <view class="user-info-item shadow-warp">
                <view class="icons">
                    <uni-icons type="locked" size="20"></uni-icons>
                </view>
                <text>验证码:</text>
                <input :password="!showPassword" v-model="user.code" placeholder="请输入验证码!"
                    placeholder-style="font-size:14px;color:#ccc;">
                <view style="font-size: 24rpx;" >
                    <text @click="getCode" v-show="!codeTimeShow">获取验证码</text>
                    <text v-show="codeTimeShow">{{codeTime}}秒后重获</text>
                </view>
                <!-- <view class="showPassword" v-if="showPassword" @click="changePassword">
                    <uni-icons type="eye" size="20"></uni-icons>
                </view>
                <view class="showPassword" v-if="!showPassword" @click="changePassword">
                    <uni-icons type="eye-slash" size="20"></uni-icons>
                </view> -->
            </view>
        </view>
        <!-- 登录按钮 -->
        <view class="loging">
            <button class="button" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button>
        </view>
        
        <view>
            <!-- 提示窗示例 -->
            <uni-popup ref="upVersion" type="dialog">
                <uni-popup-dialog :type="msgType" title="通知" :content="dialogContent" @confirm="dialogConfirm"
                    @close="dialogClose"></uni-popup-dialog>
            </uni-popup>
        </view>
        
        <!-- #ifdef APP-PLUS -->
        <view class="version">
            当前版本: {{version}}
        </view>
        <!-- #endif -->
    </view>
</template>
 
<script>
    import md5 from '../../common/md5.js'
    export default {
        data() {
            return {
                version: '',
                showPassword: true,
                user: {
                    phone: '',
                    code: '',
                },
                load: {
                    loading: false,
                    btnText: '登录'
                },
                msgType: 'success',
                filename: '',
                dialogContent: '',
                codeTime: 60,
                codeTimeShow: false,
                download: '' 
            }
        },
        onLoad: function() {
            this.user.userName = uni.getStorageSync('userName')
            this.user.password = uni.getStorageSync('password')
            // #ifdef APP-PLUS
            var that = this
            plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
                that.version = wgtinfo.version
            });
            // #endif
        },
        onShow() {
            this.getVersion()
        },
        methods: {
            // 获取验证码
            getCode() {
                let _this = this
                uni.request({
                    url: `${_this.baseUrl}/smsCode/sendCode`,
                    header: {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'},
                    data: {phone: _this.user.phone},
                    sslVerify: false,
                    method: 'POST',
                    success(res) {
                        res = res.data 
                        console.log(res);
                        _this.codeTimeShow = true
                        let time = setInterval(()=>{
                            _this.codeTime--
                        },1000)
                        setTimeout(()=>{
                            _this.codeTimeShow = false
                            clearTimeout(time);
                            _this.codeTime = 60
                        },60000)
                    }
                })
            },
            changePassword: function() {
                this.showPassword = !this.showPassword;
            },
            //检测当前平台,如果是安卓则启动安卓更新
            getVersion() {
                let that = this;
                uni.getSystemInfo({
                    success: (res) => {
                        if (res.platform == "android") {
                            that.AndroidCheckUpdate();
                        }
                    }
                })
            },
            // 获取当前版本号
            AndroidCheckUpdate() {
                let that = this;
                plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
                    that.version = wgtinfo.version //客户端版本号
                })
                setTimeout(()=>{
                    that.getUpdateVersion()
                },100)
            },
            // 校验版本
            getUpdateVersion() {
                let that = this
                let type = 0
                if (that.baseUrl == 'http://undefined:undefined/undefined') {
                    return
                }
                
                let url = that.baseUrl + '/appVersion/checkUpdate/' + that.version + '/' + type
                uni.request({
                    url: url,
                    method: 'GET',
                    success(res) {
                        console.log(res);
                        var res = res.data
                        if (res.data) {
                            console.log(res);
                            that.filename = res.data.path
                            that.dialogContent = '发现新版本:' + res.data.version + ', 是否立即更新'
                            that.download = res.data.url
                            that.$refs.upVersion.open()
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: "none",
                                position: 'top'
                            })
                        }
                        
                    }
                })
            },
            dialogConfirm() {
                this.$refs.upVersion.close()
                this.downWgt()
            },
            dialogClose() {
                this.$refs.upVersion.close()
            },
            downWgt() {
                let that = this;
                const downloadUrl = that.download
                uni.showLoading({
                    title: '更新中……'
                })
                const downloadTask = uni.downloadFile({ //执行下载
                    url: downloadUrl, //下载地址
                    timeout: 1000 * 30, //30秒超时时间
                    success: downloadResult => { //下载成功
                        console.log(downloadResult);
                        that.showdownLine = false
                        uni.hideLoading();
                        if (downloadResult.statusCode == 200) {
                            uni.showModal({
                                title: '',
                                content: '更新成功,确定现在重启吗?',
                                confirmText: '重启',
                                confirmColor: '#EE8F57',
                                success: function(res) {
                                    if (res.confirm == true) {
                                        plus.runtime.install( //安装
                                            downloadResult.tempFilePath, {
                                                force: true
                                            },
                                            function(res) {
                                                utils.showToast('更新成功,重启中');
                                                plus.runtime.restart();
                                            }
                                        );
                                    }
                                }
                            });
                        } else {
                            uni.hideLoading();
                            that.showdownLine = false
                            uni.showToast({
                                title:'请先上传安装包',
                                icon: 'error'
                            })
                        }
                    },
                    fail: err => {
                        uni.hideLoading();
                        that.showdownLine = false
                        that.$u.toast(downloadResult.errMsg)
                    },
                    complete: com => {
                        
                        console.log(com)
                    }
                });
            
                // 下载进度
                downloadTask.onProgressUpdate(res => {
                    that.downloadNum = res.progress
                    console.log('下载进度' + that.downloadNum);
                });
            },
            onLogin() {
                let that = this
                if (that.user.phone == '') {
                    uni.showToast({ title: '请输入手机号', icon: "none" })
                    return
                }
                if (that.user.code == '') {
                    uni.showToast({ title: '验证码不能为空', icon: "none" })
                    return
                }
                uni.request({
                    url: that.baseUrl + '/smsLogin.action',
                    fail(result) {
                        uni.showToast({
                            icon: 'error',
                            title: '请求失败'
                        })
                    },
                    data: {
                        phone: that.user.phone,
                        code: that.user.code
                    },
                    header: { "content-type": "application/json" },
                    success(result) {
                        if (result.statusCode === 404) {
                            uni.showToast({
                                title: '登录失败',
                                icon: "error"
                            })
                            return
                        }
                        let res = result.data
                        if (res.code === 200) {
                            that.load.loading = true;
                            that.load.btnText = '登录中';
                            uni.setStorageSync('token', res.data.token);
                            uni.setStorageSync('userName', that.user.userName);
                            uni.setStorageSync('password', that.user.password);
                            setTimeout(() => {
                                uni.showToast({
                                    title: '登录成功'
                                })
                                setTimeout(() => {
                                    uni.reLaunch({
                                        url: '../index/index'
                                    });
                                }, 300)
                            }, 700)
                        } else {
                            uni.showToast({
                                title: res.msg
                            })
                        }
                    },
 
 
                })
            },
        }
    }
</script>
 
<style>
    .container {
        display: flex;
        flex-direction: column; // 表示垂直方向,由上到下
        width: 100%;
        min-height: 93.4vh;
    }
 
    .logo {
        width: 300px;
        height: 163px;
        margin-top: 100rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
 
    .user-info {
        display: flex;
        align-items: center;
        flex-direction: column;
        width: 100%;
        height: 400rpx;
        font-size: 14px;
        letter-spacing: 1px;
    }
 
    .user-info-item {
        display: flex;
        width: 650rpx;
        height: 100rpx;
        line-height: 100rpx;
        align-items: center;
        background-color: #fff;
        margin-bottom: 30rpx;
        font-size: 28rpx;
        font-weight: 500;
    }
 
    .user-info-item>input {
        width: 300rpx;
        color: #606266;
        font-weight: 500;
        caret-color: #606266; // 光标颜色
    }
 
    .icons {
        margin-left: 20rpx;
        margin-right: 18rpx;
    }
 
    .showPassword {
        position: absolute;
        right: 10rpx;
    }
 
    .shadow-warp {
        position: relative;
        box-shadow: 0 0 10upx rgba(0, 0, 0, 0.1);
    }
 
    .shadow-warp:before,
    .shadow-warp:after {
        position: absolute;
        content: "";
        top: 20upx;
        bottom: 30upx;
        left: 20upx;
        width: 50%;
        box-shadow: 0 30upx 20upx rgba(0, 0, 0, 0.2);
        transform: rotate(-3deg);
        z-index: -1;
    }
 
    .shadow-warp:after {
        right: 20upx;
        left: auto;
        transform: rotate(3deg);
    }
 
    .loging {
        position: fixed;
        bottom: 100rpx;
        left: 0;
        right: 0;
        margin-left: auto;
        margin-right: auto;
    }
 
    .button {
        color: #fff;
        background-color: #409EFF;
        width: 150px;
        height: 40px;
        line-height: 40px;
    }
 
    button::after {
        border: initial;
    }
 
    .button-hover {
        color: #fff;
        background-color: #6fc1ff;
    }
 
    .version {
        width: 100%;
        position: fixed;
        bottom: 30rpx;
        left: 0;
        right: 0;
        margin-left: auto;
        margin-right: auto;
        text-align: center;
        font-size: 10px;
        color: #C0C4CC;
    }
 
    .input {
        display: block;
        font-size: 14px;
    }
 
    .uni-input {
        height: 50rpx;
        padding: 15rpx 25rpx;
        line-height: 50rpx;
        font-size: 28rpx;
        background: #FFF;
        flex: 1;
    }
</style>