版本更新
This commit is contained in:
@@ -144,8 +144,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { onShow } from "@dcloudio/uni-app";
|
||||
import navTo from "@/utils/navTo"
|
||||
import my_api from '@/api/my_api.js'
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
@@ -181,12 +180,65 @@
|
||||
|
||||
// 检查版本更新
|
||||
const checkUpdate = () => {
|
||||
uni.showToast({
|
||||
title: '检查版本更新',
|
||||
icon: 'none'
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||
console.log('App 名称:', widgetInfo.name);
|
||||
console.log('App 版本号 (version):', widgetInfo.version); // 如:1.0.0
|
||||
console.log('App 版本代码 (versionCode):', widgetInfo.versionCode); // 数字,如:100
|
||||
});
|
||||
|
||||
my_api.checkVersion().then(res=>{
|
||||
console.log(res)
|
||||
}).catch(err=>{
|
||||
console.log(err)
|
||||
if(err.data.code === 80002){
|
||||
if(err.data.data.apk_path){
|
||||
appdownLoad(err.data.data.apk_path)
|
||||
}else{
|
||||
uni.showToast({
|
||||
title: err.data.msg || '当前版本已是最新版本',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
};
|
||||
|
||||
//执行下载app
|
||||
const appdownLoad = (url) => {
|
||||
uni.showLoading({
|
||||
title: '安装包下载中……'
|
||||
})
|
||||
const downloadTask = uni.downloadFile({
|
||||
url: url, //服务器 app 的下载地址
|
||||
success: (downloadResult) => {
|
||||
uni.hideLoading();
|
||||
console.log(downloadResult)
|
||||
if (downloadResult.statusCode === 200) {
|
||||
uni.showModal({
|
||||
title: '',
|
||||
content: '下载成功,是否允许安装新版本?',
|
||||
confirmText: '确定',
|
||||
success: function(res) {
|
||||
if (res.confirm == true) {
|
||||
plus.runtime.install( //安装
|
||||
downloadResult.tempFilePath, {
|
||||
force: true
|
||||
},
|
||||
function(res) {
|
||||
utils.showToast('更新成功,重启中');
|
||||
plus.runtime.restart();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 跳转到关于页面
|
||||
const goToAbout = () => {
|
||||
uni.showToast({
|
||||
|
||||
Reference in New Issue
Block a user