<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>
|