This commit is contained in:
aihe 2024-06-16 02:31:52 +08:00
parent 9257d4018d
commit d815574e97

View File

@ -21,10 +21,12 @@ export const getCurrentAppInfo = ()=> {
} }
const installNewApk = (url)=> { const installNewApk = (url)=> {
console.log("installNewApk url===", url)
return new Promise((resolve, reject)=> { return new Promise((resolve, reject)=> {
let downInstance = uni.downloadFile({ let downInstance = uni.downloadFile({
url: url, url: url,
success: (downloadResult) => { success: (downloadResult) => {
console.log("===downloadResult===", downloadResult)
hideLoading() hideLoading()
if (downloadResult.statusCode === 200) { if (downloadResult.statusCode === 200) {
showLoading('正在安装...') showLoading('正在安装...')
@ -41,11 +43,13 @@ const installNewApk = (url)=> {
reject() reject()
}); });
} else { } else {
showToast(`文件下载失败, 错误码:${downloadResult.statusCode}`)
reject() reject()
} }
}, },
fail: (err)=> { fail: (err)=> {
console.log('download file err...', err); console.log('download file err...', err);
showToast("文件下载失败")
hideLoading() hideLoading()
} }
}); });
@ -61,8 +65,8 @@ const getLastAppInfo = async (curAppInfo)=> {
return { return {
version: '1.0.1', version: '1.0.1',
versionCode: 101, versionCode: 101,
apkUrl: '', apkUrl: 'http://localhost:5173/static/t.apk?t.apk',
wgtUrl: '', wgtUrl: 'http://localhost:5173/static/t.wgt?t.wgt',
// whiteDeviceIds: ['F9E778C90D0E9A8DA9D95AA97B00A3FB'], // whiteDeviceIds: ['F9E778C90D0E9A8DA9D95AA97B00A3FB'],
} }
} }
@ -97,8 +101,9 @@ export const checkUpdate = async ()=> {
let curAppInfo = await getCurrentAppInfo() let curAppInfo = await getCurrentAppInfo()
let lastAppInfo = await getLastAppInfo(curAppInfo) let lastAppInfo = await getLastAppInfo(curAppInfo)
let cmpRes = await compareInfo(curAppInfo, lastAppInfo) let cmpRes = await compareInfo(curAppInfo, lastAppInfo)
console.log("checkUpdate cmpRes ====", cmpRes)
if(cmpRes.hasNewVersion) { if(cmpRes.hasNewVersion) {
let fmBl = confirmModal(`app最新版本:${cmpRes.lastAppInfo.version}.${cmpRes.lastAppInfo.versionCode}, 是否更新?`) let fmBl = await confirmModal(`app最新版本:${cmpRes.lastAppInfo.version}.${cmpRes.lastAppInfo.versionCode}, 是否更新?`)
if(fmBl) { if(fmBl) {
await installNewApk(cmpRes.url) await installNewApk(cmpRes.url)
} }