schangxiang@126.com
2025-09-17 c0e20b1b0f1298cdc0af0037d60e74d51e364501
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<template>
    <view class="width height overflow_hidden bg">
        <view class="logo">
            <image src="../../static/logo.jpg" ></image>
        </view>
        <view class="width height50">
            <view class="text_align_center fontSize56rpx ">
                
            </view>
            <view class="text_align_center margin_bottom18 "
                style="font-size: 40rpx;color: #9fa09f;padding: 25rpx 0 0;">
                —鲁丽家居包装线—
            </view>
        <!--     <tki-barcode :loadMake="false" :opations="opations" :onval="true" format="code128" :val="val" ref="barcode"
                @result="barresult" /> -->
            <view class="width80 margin_auto margin_top5">
                <view class="flex align-center height80rpx padding border border_radius box_sizing">
                    <view class="fontSize42rpx iconfont icon-zhanghao"></view>
                    <input v-model.trim="loginform.account" class="width94 height padding_left10rpx fontSize28rpx"
                        type="text" placeholder="请输入账号" />
                    <u-icon name="arrow-down" style="color: #b5b5b5;" v-if="accList.length!==0" @click="accshow=true">
                    </u-icon>
                </view>
                <u-select v-model="accshow" :list="accList" @confirm="confirm"></u-select>
            </view>
            <view class="width80 margin_auto margin_top5 margin_bottom13">
                <view class="flex align-center height80rpx padding border border_radius box_sizing">
                    <view class="fontSize42rpx iconfont icon-mima1"></view>
                    <input v-model.trim="loginform.password" class=" padding_left10rpx fontSize28rpx" placeholder="请输入密码"
                        type="password" value="" />
                </view>
            </view>
            <view @click="register"
                class="width80 fontSize36rpx text_align_center margin_auto margin_top5 color_F2F2F2 padding_up_down25 border_radius"
                style="background-color: #f18202;">
                登录
            </view>
 
             <!-- <view @click="tui1"
                class="width80 fontSize36rpx text_align_center margin_auto margin_top5 color_F2F2F2 padding_up_down25 border_radius"
                style="background-color: #f18202;">
                推送
            </view> -->
            <!--     <view class="update" @click="AndroidCheckUpdate">
                更新APP
            </view>
            <view class="ip" @tap="modalshow=true">
                切换地址
            </view>             -->        
            <!-- <view class="fixed left50 bottom0 transformX">
                应用版本号 {{wgtVer}}
            </view> -->
 
            <view class="fixed left50 bottom0 transformX " @click="plusReady(1)" style="padding: 40rpx 0;">
                <view v-if="wgtVer">版本号 {{wgtVer}} - {{ versionTime }}</view>
                <view v-else>更新版本</view>
            </view>
 
        </view>
        <cu-modal :modalshow='modalshow' placeholder='服务信息' @hideModal='modalshow=false'>
            <view slot='modal' class="">
                <u-input type="text" placeholder="请输入地址" border v-model="ip_pk" />
                <button class="margin_top40rpx bg-grey" @tap="confirmclikc">确认</button>
            </view>
        </cu-modal>
 
    </view>
</template>
 
<script>
    // import {mixin} from '../../utils/mixin.js'
    // import { TencentKonaInit, SM4_DEF, SM4_GCM, SM2,SM2_UTIL, SM4_ECB, SM3 } from "@/uni_modules/sm-crypto"
    import CuModal from '../../components/CuModal.vue'
    import md5 from "../../utils/md5.js";
    import tkiBarcode from '@/components/tki-barcode/tki-barcode'
    import tkiQrcode from '@/components/tki-qrcode/tki-qrcode'
    import {
        login,
        getLoginUser,
        getWgt
    } from '../../api/login.js'
 
 
    export default {
        data() {
            return {
                backButtonPress:0,
                loginform: {
                    account: 'superAdmin',
                    password: '123456'
                },
                // flag: true,
                wgtVer: '',
                versionTime: '',
                ip_pk: '',
                modalshow: false,
                accList: [],
                accshow: false,
                opations: {
                    width: 4,
                    height: 120,
                    fontSize: 24,
                    fontColor: "#000000",
                    displayValue: true,
                    textAlign: "center",
                    textPosition: "bottom",
                    textMargin: 5,
                    background: "#FFFFFF",
                    margin: 5
                },
                val: "",
                bar: ['barcode']
            };
        },
        components: {
            CuModal,
            tkiBarcode,
            tkiQrcode
        },
        onLoad() {
            //获取当前版本信息,和远程的最新打包版本
            // this.plusReady()
            // this.version = plus.runtime.version; //应用的版本信息
 
        //     setInterval(() => {
        //     this.tui1();
        // }, 10000);//20秒
 
 
        },
        onShow() {
            this.remove()
            // uni.clearStorageSync();
            if (uni.getStorageSync('accList')) {
                let a = JSON.parse(uni.getStorageSync('accList'))
                let obj = {}
                for (let key in a) {
                    obj[key] = a[key]
                }
                this.accList = Object.keys(obj).map(val => ({
                    label: obj[val]
                }))
                this.accList.forEach((item, index) => {
                    item.value = index + 1
                })
            }
        },
        mounted() {
            this.plusReady();
            this.tongzhiPerssiom();
        },
        methods: {
            // 获取当前版本号
            plusReady(parmam) {
                var that = this;
                // 获取本地应用资源版本号  
                plus.runtime.getProperty(plus.runtime.appid, function(inf) {
                    console.log(inf)
                    that.data = inf
                    that.wgtVer = inf.version ||''; //获取当前版本号
                    that.versionTime = inf.description ||''//获取版本文件的更新时间
                    if(parmam){
                        that.checkUpdate(inf.version)
                    }
                });
            },
            // 获取文件名和拓展名
            getFilenameAndExtension(pathfilename){
                var filenameextension = pathfilename.replace(/^.*[\\\/]/, '');
                var filename = filenameextension.substring(0, filenameextension.lastIndexOf('.'));
                var ext = filenameextension.split('.').pop();
                return [filename, ext];
            },
            // 自动更新 通过接口获取wgt包地址 1.0.1
            checkUpdate(appVer){
                var that = this;
                console.log('当前版本号')
                console.log(appVer)
                getWgt().then(res => {
                    console.log(res)
                    if(res.code==200){
                        res.data = res.result;
                        console.log(res.data)
                        if(res.data==''){
                            console.log('没有wgt更新包')
                            return
                        }
                        let fileUrlArr = that.getFilenameAndExtension(res.data) // ['1.0.2', 'wgt']
                        if(fileUrlArr[1]!='wgt'){
                            uni.showToast({
                                title: '不是wgt文件,无法更新',
                                mask: false,
                                duration: 5000,
                                icon: "none"
                            });
                            return
                        }
                        let VersionNew = fileUrlArr[0] //1.0.2
                        var downurl = res.data;
                        var ck1 = that.compareVersion(appVer, VersionNew);
                        var    ck2 ='';
                        console.log("appVer:" + appVer)
                        console.log("VersionNew:" + VersionNew)
                        console.log("检测结果1:" + ck1)
                        if (ck1==true) {
                            console.log('下载地址')
                            console.log( downurl )
                            that.downWgt(downurl);
                        }else{
                            console.log('暂无新版本更新')
                            uni.showToast({
                                title: '暂无新版本更新',
                                mask: false,
                                duration: 5000,
                                icon: "none"
                            });
                        }
                    }
                }).catch((err)=>{
                    uni.showToast({
                        title: '请检查网络或接口打包路径baseUrl',
                        mask: false,
                        duration: 1000,
                        icon: "none"
                    });
                })
            },
            // 对比版本号
            compareVersion(ov, nv, len){
                if (!ov || !nv || ov == "" || nv == "") {
                    return false;
                }
                var b = false;
                var ova = ov.split(".", len);
                var nva = nv.split(".", len);
                var l = Math.min(ova.length, nva.length)
                for (var i = 0; i < l; i++) {
                    var so = ova[i];
                    var no = parseInt(so);
                    var sn = nva[i];
                    var nn = parseInt(sn);
                    if (nn > no) {
                        b = true;
                        break;
                    }
                }
                //新1.1.1 旧1.1 为版本升级
                if (nva.length > ova.length && 0 == nv.indexOf(ov)) {
                    b = true;
                }
                return b;
            },
            // // 下载wgt文件
            downWgt(wgtUrl){
                console.log('downWgt方法')
                console.log(wgtUrl)
                var that = this;
                var wgtWaiting = '';
                console.log(plus.downloader)
                var task = plus.downloader.createDownload(wgtUrl, {
                    filename: "_doc/update/"
                }, function(d, status) {
                    console.log(status)
                    if (status == 200) {
                        console.log("下载资源成功:" + d.filename);
                        that.installWgt(d.filename); // 安装wgt包
                    } else {
                        uni.showToast({
                            title: '下载升级文件失败!请检查网络再试!',
                            mask: false,
                            duration: 5000,
                            icon: "none"
                        });
                        //plus.nativeUI.alert("更新资源失败!");
                    }
                    plus.nativeUI.closeWaiting();
                });
                var totalSize = 0; //总大小
                var downloadedSize = 0;
                task.addEventListener("statechanged", function(download, status) {
                    console.log('status-' + status )
                    console.log("download.downloadedSize-" + download.downloadedSize)
                    if(status==200){
                        if (download.downloadedSize != 0) {
                            downloadedSize = Math.floor(download.downloadedSize / 1048576 * 100) / 100;
                        }
                        if (download.totalSize != 0) {
                            totalSize = Math.floor(download.totalSize / 1048576 * 100) / 100;
                        }
                        wgtWaiting.setTitle("已下载 " + downloadedSize + 'M /' + totalSize + "M");
                    }
                });
                if (plus.os.name == 'Android') {
                    console.log(plus.os.name)
                    uni.showModal({
                        title: '应用升级?',
                        content: `${wgtUrl}`,
                        showCancel: true,
                        cancelColor: '#333333',
                        success: (res => {
                            if (res.confirm) {
                                task.start();
                                wgtWaiting = plus.nativeUI.showWaiting("开始下载");
                            } else if (res.cancel) {
                                plus.runtime.quit();
                            }
                        })
                    });
 
                }
            },
            // 更新应用资源
            installWgt(path){
                var that = this;
                plus.nativeUI.showWaiting("更新中...");
                plus.runtime.install(path, {}, function() {
                    plus.nativeUI.closeWaiting();
                    console.log("安装wgt文件成功!");
                    plus.runtime.restart();
                }, function(e) {
                    plus.nativeUI.closeWaiting();
                    console.log("安装wgt文件失败[" + e.code + "]:" + e.message);
                    plus.nativeUI.alert("更新资源失败[" + e.code + "]:" + e.message);
                });
            },
            //清除缓存
            remove() {
                uni.removeStorageSync('token')
                uni.removeStorageSync('userInfo')
            },
            //确认选择账号
            confirm(e) {
                this.loginform.account = e[0].label
            },
            // 自动更新
            AndroidCheckUpdate() {
                //比较当前版本和远程服务版本是否一致
                if(this.wgtVer == this.version) {
                    uni.showToast({
                        title: '当前版本已是最新版本',
                        mask: true,
                        duration: 5000,
                        icon: "none"
                    });
                }else {
                    uni.showLoading({
                        title:"更新中....."
                    })
                    uni.downloadFile({
                        url: '',
                        success: (fileResult) => {
                            uni.hideLoading()
                            plus.runtime.install(fileResult.tempFilePath,{force: false},_ => {
                                plus.runtime.restart()
                            },(e)=> {
                                uni.hideLoading()
                                uni.showToast({
                                    title:"更新失败"
                                })
                            })
                        }
                    })
                }
            },
            //登录
            register() {
                if(!this.loginform.account || !this.loginform.password) {
                    uni.showModal({
                        title: '提示',
                        content: "用户名和密码不能为空",
                        showCancel: false,
                    });
                    return;
                }
                //公钥
                // var publicKey = "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312";
                // // vue中使用SM2加密
                // const password = sm2.doEncrypt(this.loginform.password, publicKey, 1);
 
                let params = {
                    account: this.loginform.account,
                    // password: md5.hex_md5(this.loginform.password),
                    // password:password,
                    codeId:0,
                    password:"1c2f1d59ef1b820f7b0a8f787778a607f82c7f03ed7deee1516f6322b22d20f2b79166980b96258e3b1497cd9e241fd5ceae9ef372ceaaa32decbe40aa21d91db66e6fce4a88b21120c9889e4b471dd6f9b6e13ef7e1c4655aebfb27048fb2e06de43da824fa",
                }
                login(params).then(res => {
                    uni.hideKeyboard()
                    let data = res.data
                    uni.setStorageSync('token',res.result.accessToken)
                    getLoginUser().then(res => {
                        uni.setStorageSync('userInfo', JSON.stringify(res.result))
                        uni.navigateTo({
                            url: '../index/index'
                        })
                        // if (uni.getStorageSync('accList')) {
                        //     let a = JSON.parse(uni.getStorageSync('accList'))
                        //     a.push(this.loginform.account)
                        //     let list = []
                        //     a.forEach(function(item) {
                        //         if (list.indexOf(item) == -1) {
                        //             list.push(item)
                        //         }
                        //     })
                        //     uni.setStorageSync('accList', JSON.stringify(list))
                        // } else {
                        //     uni.setStorageSync('accList', JSON.stringify(Array(this.loginform
                        //         .account)))
                        // }
                        // this.loginform = {
                        //     account: '',
                        //     password: ''
                        // }
                    
                    })
                
                })
            },
            //切换ip
            confirmclikc() {
                // uni.setStorageSync('ippk', this.ip_pk)
                // this.modalshow = false
            },
            // 推送
            tui1(){
                console.log("444444444444")
                var content="您有一条新的消息!";
                var options ={
                    'cover':true,//覆盖上次cover""
                    'when':new Date(),
                    'title':"通知消息"    
                }
                var body ={
                    'id':'id',
                    'key2':"key"
                }
                var payload = JSON.stringify(body);
                plus.push.createMessage(content,payload,options);
 
            },
            // 是否开启通知权限--如果没有,跳转设置开启
            tongzhiPerssiom(){
                var main = plus.android.runtimeMainActivity();  
                var pkName = main.getPackageName();  
    
                var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");  
 
                // console.log("666666666666666666")
                // console.log(pkName)
 
                var packageNames = NotificationManagerCompat.from(main);  
                if (packageNames.areNotificationsEnabled()) {  
                    console.log('已开启通知权限');  
                }else{  
                    uni.showModal({  
                        title: '通知权限开启提醒',  
                        content: '您还没有开启通知权限,无法接收到消息通知,是否前往设置',  
                        showCancel: false,  
                        success: function (res) {  
                            if (res.confirm) {  
                                var Intent = plus.android.importClass('android.content.Intent');  
                                var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');//可设置表中所有Action字段  
                                intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);  
                                main.startActivity(intent);  
                            }  
                        }  
                    });  
                }
            }
 
 
 
        }
    }
</script>
 
<style lang="scss" scoped>
    page {
        background-color: #fff;
    }
    .bg {
        padding-top: 120rpx;
        box-sizing: border-box;
    }
 
    .logo {
        width: 220rpx;
        height: 72rpx;
        margin: 30rpx auto;
        image {
            width: 100%;
            height: 100%;
        }
    }
 
    .update,
    .ip {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        padding-right: 30rpx;
        padding-top: 30rpx;
        text-decoration: underline;
        color: #5173e4;
    }
 
    .ip {
        color: #333;
    }
    .tki-barcode {
            padding: 10rpx 5rpx;
        }
     
        .tki-barcode>>>image {
            width: 100% !important;
            height: 84rpx;
        }
     
        .tki-barcode>>>.tki-barcode-canvas {
            width: 100% !important;
            height: 84rpx;
    }
</style>