app升级更新添加

This commit is contained in:
GaoHao 2024-12-11 10:41:13 +08:00
parent c9ce807a17
commit 7376e40fe3
4 changed files with 158 additions and 1 deletions

143
App.vue
View File

@ -6,8 +6,9 @@ App.vue本身不是页面这里不能编写视图元素也就是没有<tem
import {
onLaunch
} from '@dcloudio/uni-app';
import { getFindBySource } from '@/http/yskApi/version.js'
onLaunch(() => {
let that = this
uni.hideTabBar()
// #ifdef MP-WEIXIN
const updateManager = wx.getUpdateManager() //
@ -23,6 +24,146 @@ App.vue本身不是页面这里不能编写视图元素也就是没有<tem
//
})
// #endif
//#ifdef APP-PLUS
//
plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
//
console.log("widgetInfo==",widgetInfo)
getFindBySource({source:'APP'}).then(res => {
console.log("selectNewApp==",res)
console.log("version===",res.url && widgetInfo.version < res.version)
if (res.url && widgetInfo.version < res.version) {
console.log("version===222")
let downloadLink = res.url;
// let downloadLink = "https://short-video.hnsiyao.cn/app/sy-duanju.apk";
console.log(downloadLink)
// let androidLink = res.androidWgtUrl;
// let iosLink = res.iosWgtUrl;
let ready = false;
//
if (res.isUp == 1) {
uni.showModal({
showCancel: false,
title: '发现新版本',
confirmText: '立即更新',
content: res.message,
success: res => {
if (res.confirm) {
uni.showLoading('下载中...');
if (uni.getSystemInfoSync().platform ==
'android') {
uni.downloadFile({
url: downloadLink,
success: downloadResult => {
if (downloadResult.statusCode === 200) {
plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, entry => {
entry.getParent(_oldFile=>{
entry.moveTo(_oldFile,'.apk',newFilePath=>{
console.log('newFilePath',newFilePath.fullPath)
plus.runtime
.install(newFilePath.fullPath, { force: false },
d => {
console
.log(
'install success...'
);
plus.runtime
.restart();
},
e => {
console.log(e)
console
.error(
'install fail...'
);
}
);
})
})
})
}
}
});
}
if (uni.getSystemInfoSync().platform ==
'ios') {
plus.runtime.openURL(downloadLink, function(
res) {});
}
} else if (res.cancel) {
console.log('取消');
}
}
});
} else {
uni.showModal({
title: '发现新版本',
confirmText: '立即更新',
cancelText: '下次更新',
content: res.message,
success: res => {
if (res.confirm) {
uni.showLoading('下载中...');
if (uni.getSystemInfoSync().platform ==
'android') {
uni.downloadFile({
url: downloadLink,
success: downloadResult => {
if (downloadResult
.statusCode ===
200) {
plus.io.resolveLocalFileSystemURL(downloadResult.tempFilePath, entry => {
entry.getParent(_oldFile=>{
entry.moveTo(_oldFile,'.apk',newFilePath=>{
console.log('newFilePath',newFilePath.fullPath)
plus.runtime
.install(newFilePath.fullPath, { force: false },
d => {
console
.log(
'install success...'
);
plus.runtime
.restart();
},
e => {
console.log(e)
console
.error(
'install fail...'
);
}
);
})
})
})
}
}
});
}
if (uni.getSystemInfoSync().platform ==
'ios') {
plus.runtime.openURL(downloadLink, function(
res) {});
}
} else if (res.cancel) {
console.log('取消');
}
}
});
}
}
}).catch((res)=>{
console.log(res)
})
});
// #endif
});
</script>

View File

@ -202,6 +202,7 @@ function request(args) {
method: method,
header: getHeader()
}, extParams)
)
})
}

15
http/yskApi/version.js Normal file
View File

@ -0,0 +1,15 @@
import http from './http.js'
const request=http.request
/**
* 查询所属渠道升级版本
* @returns
*/
export function getFindBySource(params) {
return request({
url: `/api/tbVersion/findBySource`,
method: 'get',
params
})
}

Binary file not shown.