<template>
|
<view class="pages-version-app-update">
|
<view>
|
<a-button type="primary" class="max-button" :disabled="updating"
|
@click="clickCheckUpdate">{{translate('check_update')}}</a-button>
|
|
</view>
|
<view class="group" v-if="newPack.version">
|
<view class="item big-text ">
|
{{translate('updatable_version')}}:{{newPack.fileTime}}_{{newPack.version}}
|
</view>
|
<view class="item gray-text" v-if="newPack.size">
|
{{newPack.size}}
|
</view>
|
<view class="item">
|
{{translate('version_info')}}:{{newPack.info}}
|
</view>
|
<view class="item">
|
{{translate('current_version')}}:{{appVersion.date}}_{{appVersion.ver}}
|
</view>
|
</view>
|
<view class="no-version gray-text" v-else>
|
<uni-icons type="upload-filled" size="150" color="#888"></uni-icons>
|
{{ translate('current_version')}}:{{appVersion.date}}_{{appVersion.ver}}
|
</view>
|
|
<view class="button-group" v-if="newPack.version">
|
<a-button type="primary" class="button" :disabled="updating"
|
@click="clickNowUpdate">{{translate('update_immediately')}}</a-button>
|
<cmdProgress v-if="updating" :percent="percentage"
|
stroke-color="linear-gradient(to right, #ef32d9, #89fffd)">
|
</cmdProgress>
|
</view>
|
|
</view>
|
</template>
|
<script>
|
import {
|
session,
|
showToast,
|
showModal,
|
showError
|
} from "@/comm/utils.js"
|
import {
|
Button
|
} from 'antd-mobile-vue-next'
|
import {
|
getAppVersion,
|
getServerVersion
|
} from "@/api/version.js"
|
import cmdProgress from "@/components/cmd-progress/index.vue"
|
export default {
|
name: "PagesVersionAppUpdate",
|
components: {
|
'a-button': Button,
|
cmdProgress
|
},
|
data() {
|
return {
|
appVersion: {
|
date: "",
|
ver: ""
|
},
|
newPack: {
|
version: "",
|
fileName: "",
|
size: "",
|
info: "",
|
fileTime: "",
|
},
|
percentage: 0, //下载进度
|
updating: false
|
|
}
|
},
|
onLoad(option) {
|
|
|
uni.setNavigationBarTitle({
|
title: this.translate('version_update')
|
})
|
this.loadData()
|
|
},
|
computed: {
|
newVersionSize() {
|
const packSize = this.newPack?.size || 0
|
let size = 0
|
if (packSize < 1024 * 1024) {
|
size = Math.round(packSize * 100 / 1024)
|
return `${size/100} KB`
|
} else if (packSize < 1024 * 1024 * 1024) {
|
size = Math.round(packSize * 100 / (1024 * 1024))
|
return `${size/100} MB`
|
} else {
|
size = Math.round(packSize * 100 / (1024 * 1024 * 1024))
|
return `${size/100} GB`
|
}
|
}
|
|
},
|
methods: {
|
setData(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
loadData() {
|
const _this = this
|
// #ifdef APP-PLUS
|
plus.runtime.getProperty(plus.runtime.appid, (info) => {
|
// console.log(info);
|
const verStr = info.version || "";
|
const arVer = verStr.split("_")
|
if (arVer.length > 1) {
|
_this.setData({
|
appVersion: {
|
date: arVer[0],
|
ver: arVer[1]
|
}
|
})
|
} else if (arVer.length == 1) {
|
_this.setData({
|
appVersion: {
|
date: "",
|
ver: arVer[0]
|
}
|
})
|
|
}
|
});
|
//#endif
|
},
|
updateAPP(fileName, ver) {
|
let _this = this;
|
let sys = uni.getSystemInfoSync().platform //检查系统
|
|
downloadUpdatePackage(fileName, (path) => {
|
_this.updating = false
|
plus.runtime.openFile(result.tempFilePath); //选择软件打开文件
|
|
}, (res) => {
|
console.log('下载进度' + res.progress);
|
_this.percentage = res.progress
|
}, (err) => {
|
showToast(this.translate('update_fail'));
|
_this.updating = false
|
})
|
|
},
|
async checkAppVersion(version) {
|
try {
|
const listVer = await getAppVersion() || []
|
const appVer = listVer[0] || {}
|
const fileName = appVer.file_name || ""
|
if (fileName) {
|
var isver = this.compareVersion({
|
date: appVer.file_time,
|
ver: appVer.version
|
}, version);
|
if (isver) {
|
this.newPack.version = appVer.version
|
this.newPack.fileName = fileName
|
this.newPack.fileTime = appVer.file_time
|
this.newPack.size = appVer.size || ""
|
this.newPack.info = appVer.info
|
} else {
|
this.newPack = {
|
version: "",
|
fileName: "",
|
size: "",
|
info: "",
|
fileTime: "",
|
|
}
|
showToast(this.translate("is_latest_version"))
|
console.log('当前已是最新版本')
|
}
|
}
|
} catch (ex) {
|
showError(ex)
|
this.newPack = {
|
version: "",
|
fileName: "",
|
size: "",
|
info: "",
|
fileTime: "",
|
}
|
}
|
},
|
compareVersion(curV, reqV) {
|
if (curV.date == reqV.date) {
|
return curV.ver > reqV.ver
|
}
|
return curV.date > reqV.date
|
},
|
clickCheckUpdate() {
|
this.checkAppVersion(this.appVersion)
|
},
|
|
clickNowUpdate() {
|
this.updateAPP(this.newPack.fileName)
|
},
|
translate(t) {
|
if (typeof this.$t == "function") return this.$t(`page.${t}`)
|
else return t;
|
},
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.pages-version-app-update {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
|
.group {
|
width: calc(100% - 40rpx);
|
// border: 2rpx solid #ccc;
|
// background-color: #fff;
|
border-radius: 20rpx;
|
margin: 20rpx;
|
padding: 0 20rpx;
|
display: flex;
|
flex-direction: column;
|
|
.item {
|
width: 100%;
|
padding: 20rpx 10rpx;
|
display: flex;
|
flex-direction: row;
|
align-items: center;
|
|
.right {
|
flex: 1;
|
text-align: right;
|
color: #888;
|
}
|
}
|
|
|
}
|
|
.tip {
|
color: #888;
|
padding: 10rpx;
|
margin-left: 50rpx;
|
}
|
|
.gray-text {
|
color: #888;
|
}
|
|
.big-text {
|
font-size: 40rpx;
|
}
|
|
.no-version {
|
margin: auto;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.button-group {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
flex-direction: column;
|
font-size: 30rpx !important;
|
|
|
}
|
|
.max-button {
|
margin: auto;
|
margin-top: 20rpx;
|
margin-bottom: 20rpx;
|
border-radius: 40rpx;
|
height: 80rpx;
|
line-height: 60rpx;
|
width: 600rpx;
|
}
|
|
.button {
|
margin: auto;
|
margin-top: 20rpx;
|
border-radius: 10rpx;
|
height: 50rpx;
|
line-height: 32rpx;
|
width: 400rpx;
|
}
|
|
|
}
|
</style>
|