子卷出入站

This commit is contained in:
2022-11-09 13:30:32 +08:00
parent 4d19700411
commit ed086b9bd5
13 changed files with 306 additions and 178 deletions

View File

@@ -24,7 +24,7 @@
<script>
import {getCLodop, getPrinterList} from "@/utils/CLodopfuncs.js"
import { RSAencrypt } from '@/utils/jsencrypt.js'
import {handLogin} from '@/utils/api.js'
import {handLogin} from '@/utils/getData2.js'
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
export default {
data() {
@@ -44,13 +44,114 @@
plus.runtime.getProperty(plus.runtime.appid, (info) => {
this.version = info.version;
this.versionCode = info.versionCode ;
if (Number(this.versionCode) < 102) {
if (Number(this.versionCode) < 103) {
checkUpdate();
}
})
//#endif
},
methods: {
// 检测版本更新
async checkUpdates() {
// #ifdef APP-PLUS
//调用接口获取后台版本信息,检查是否需要更新
let versionInfo = await this.$api.login.getAppInfo();
console.log('获取后台版本信息', versionInfo);
// 待更新版本
const currentVersion = versionInfo.versionName;
console.log('后台需要更新版本', currentVersion);
// 更新地址
let androidUrl = versionInfo.url;
// 是否强制更新 isMust 0.否 1.强制更新
let showCancel = versionInfo.isMust ? true : false;
// 比较版本是否不同 当前版本plus.runtime.version
const localVersion = plus.runtime.version.split('.');
let current = currentVersion.split('.');
// 默认是同一个版本,不需要更新
let flag = false;
current.forEach((item, i) => {
if (item !== localVersion[i]) {
// 检测到版本不同,需要更新
flag = true;
}
});
if (flag) {
uni.showModal({
// 更新提醒
title: '发现新版本,是否更新',
content: '待更新版本号:' + currentVersion ,
// showCancel: showCancel,
success: res => {
if (res.confirm) {
this.doUpData(androidUrl);
this.showdownLine = true;
// plus.runtime.openURL(androidUrl)
} else if (res.cancel) {
// 不更新强制退出app
if (showCancel) {
console.log('不更新强制退出app');
plus.runtime.quit();
}
}
}
});
} else {
this.$myToast('无更新', 'none');
}
// #endif
},
doUpData(Url) {
uni.showLoading({
title: '更新中……'
});
const downloadTask = uni.downloadFile({
//执行下载
url: Url, //下载地址
timeout: 1000 * 30, //30秒超时时间
success: downloadResult => {
//下载成功
console.log(downloadResult);
this.showdownLine = false;
uni.hideLoading();
if (downloadResult.statusCode == 200) {
plus.runtime.install(
//安装软件
downloadResult.tempFilePath,
{
force: true
},
function(res) {
plus.runtime.restart();
}
);
}
},
fail: err => {
uni.hideLoading();
this.showdownLine = false;
this.$u.toast(err.errMsg);
console.log(err);
},
complete: com => {
console.log(com);
}
});
// 下载进度
downloadTask.onProgressUpdate(res => {
// this.$u.toast(res.progress)
this.downloadNum = res.progress;
// console.log('下载进度' + res.progress);
// console.log('已经下载的数据长度' + res.totalBytesWritten);
// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
// 满足测试条件,取消下载任务。
// if (res.progress > 50) {
// downloadTask.abort();
// }
});
},
test() {
let LODOP = getCLodop();
// 更换为打印服务器ip 不需要加前缀