版本更新

This commit is contained in:
haomingming
2025-09-26 08:41:01 +08:00
parent 36cda41b14
commit df4d95993a
4 changed files with 67 additions and 7 deletions
+57 -5
View File
@@ -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({