192 lines
5.5 KiB
Vue
192 lines
5.5 KiB
Vue
<template>
|
|
<s-pages title="版本号">
|
|
<view class="pages relative h100 p-t-50">
|
|
<view class="w_150 h_150 m-b-50" style="margin: 0 auto">
|
|
<image class="w100 h100" src="/static/logo.png" mode="scaleToFill" />
|
|
</view>
|
|
<view class="center"> 最新版本号: {{ newversion }} </view>
|
|
<view class="center m-t-50"> 当前版本号: {{ version }} </view>
|
|
<view class="flex-center m-t-100 absolute b50 w100 p-x-32">
|
|
<view class="ai-button2 m-r-20" @click="downloadFile()">更新最新版本</view>
|
|
<view class="ai-button2" @click="copy()">复制APP下载链接</view>
|
|
</view>
|
|
</view>
|
|
</s-pages>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { ref, reactive, onMounted, onUnmounted, getCurrentInstance, watch, nextTick } from 'vue';
|
|
import { gethotupdatelist, getAndroidAppUrl } from '@/sheep/api/index/index';
|
|
import sheep from '@/sheep';
|
|
let { proxy } = getCurrentInstance();
|
|
let newversion = ref('');
|
|
let version = ref('');
|
|
let filePath = ref();
|
|
let androidUrl = ref(); //安卓apk地址
|
|
|
|
const wgtUp = async () => {
|
|
// console.log(plus.runtime);
|
|
let res = await gethotupdatelist();
|
|
if (res.code !== 0) return;
|
|
filePath.value = res.data.filePath;
|
|
let localVersion = uni.getSystemInfoSync().appWgtVersion;
|
|
version.value = localVersion;
|
|
newversion.value = res.data.versionNumber;
|
|
if (res.data.versionNumber != localVersion) {
|
|
if (res.data.type == 'min') {
|
|
if (res.data.isForceUpdate) {
|
|
// 强制更新
|
|
downloadFile();
|
|
} else {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '发现新的版本,是否更新?',
|
|
confirmColor: '#FA7E31',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
downloadFile();
|
|
} else if (res.cancel) {
|
|
if (res.data.isForceUpdate) {
|
|
plus.runtime.quit(); //退出应用
|
|
}
|
|
}
|
|
},
|
|
});
|
|
}
|
|
} else {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '发现新的版本,请到立即更新到最新版本',
|
|
confirmText: '立即更新',
|
|
cancelText: res.data.isForceUpdate ? '关闭' : '取消',
|
|
confirmColor: '#FA7E31',
|
|
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
updateApp(filePath.value);
|
|
} else if (res.cancel) {
|
|
if (res.data.isForceUpdate) {
|
|
plus.runtime.quit(); //退出应用
|
|
}
|
|
}
|
|
},
|
|
});
|
|
}
|
|
}
|
|
};
|
|
const updateApp = (url) => {
|
|
uni.showLoading({
|
|
title: '下载中',
|
|
});
|
|
uni.downloadFile({
|
|
url: url, //下载地址
|
|
success: (res) => {
|
|
console.log(res, '下载成功');
|
|
if (res.statusCode === 200) {
|
|
console.log('下载成功');
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '下载成功',
|
|
icon: 'success',
|
|
});
|
|
uni.saveFile({
|
|
tempFilePath: res.tempFilePath,
|
|
success: function (res) {
|
|
uni.openDocument({
|
|
filePath: res.savedFilePath,
|
|
success: function (res) {
|
|
console.log(res, '打开安装包');
|
|
},
|
|
});
|
|
},
|
|
fail: (err) => {
|
|
console.log(err, '打开安装包-失败');
|
|
},
|
|
});
|
|
}
|
|
},
|
|
fail(e) {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '下载失败,请检查网络',
|
|
icon: 'none',
|
|
});
|
|
console.log(e);
|
|
},
|
|
});
|
|
};
|
|
const copy = () => {
|
|
uni.setClipboardData({
|
|
data: androidUrl.value,
|
|
success: () => {
|
|
uni.showToast({
|
|
title: '链接已复制,请在浏览器打开',
|
|
icon: 'none',
|
|
});
|
|
},
|
|
});
|
|
};
|
|
const downloadFile = () => {
|
|
if (newversion.value == version.value) {
|
|
uni.showToast({ title: '已经是最新版本', icon: 'none' });
|
|
return;
|
|
}
|
|
let url = filePath.value;
|
|
uni.downloadFile({
|
|
url: url,
|
|
success: (downloadResult) => {
|
|
uni.showToast({
|
|
title: '更新中....',
|
|
icon: 'none',
|
|
});
|
|
if (downloadResult) {
|
|
if (downloadResult.statusCode === 200) {
|
|
plus.runtime.install(
|
|
downloadResult.tempFilePath,
|
|
{
|
|
force: true,
|
|
},
|
|
function () {
|
|
uni.showModal({
|
|
title: '成功提示',
|
|
content: '热更新成功,请重启应用',
|
|
confirmColor: '#FA7E31',
|
|
showCancel: false,
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
plus.runtime.restart(); //自动重启软件
|
|
}
|
|
},
|
|
});
|
|
},
|
|
function (e) {
|
|
uni.showModal({
|
|
title: '失败提示',
|
|
content: e,
|
|
showCancel: false,
|
|
confirmColor: '#FA7E31',
|
|
});
|
|
},
|
|
);
|
|
}
|
|
}
|
|
},
|
|
});
|
|
};
|
|
|
|
//获取安卓apk
|
|
function getAndroid() {
|
|
getAndroidAppUrl().then((res) => {
|
|
console.log(res.data);
|
|
androidUrl.value = res.data || 'http://8.136.55.200:1080/app.apk';
|
|
});
|
|
}
|
|
onMounted(() => {
|
|
getAndroid();
|
|
wgtUp();
|
|
});
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.pages {
|
|
}
|
|
</style>
|