90 lines
2.4 KiB
Vue
90 lines
2.4 KiB
Vue
<script>
|
|
import silenceUpdate from '@/uni_modules/rt-uni-update/js_sdk/silence-update.js' //引入静默更新
|
|
import config from './config';
|
|
export default {
|
|
methods: {
|
|
networkStatusChange(res) {
|
|
if (res.isConnected) {
|
|
uni.redirectTo({
|
|
url: "/pages/index/index",
|
|
});
|
|
} else {
|
|
uni.redirectTo({
|
|
url: "/pages/networko/index",
|
|
});
|
|
}
|
|
},
|
|
// 获取本地应用资源版本号
|
|
getLocalVersion() {
|
|
return new Promise((resolve, reject) => {
|
|
plus.runtime.getProperty(plus.runtime.appid, function (widgetInfo) {
|
|
resolve(widgetInfo);
|
|
});
|
|
});
|
|
},
|
|
// 获取服务端应用资源版本号
|
|
getServerVersion(widgetInfo) {
|
|
return new Promise((resolve, reject) => {
|
|
uni.request({
|
|
url: config.apiBaseUrl + "/version-info",
|
|
method:'POST',
|
|
data:{
|
|
edition_type:widgetInfo.appid,
|
|
version_type:uni.getSystemInfoSync().platform,
|
|
edition_number:Number(widgetInfo.versionCode)
|
|
},
|
|
success: (res) => {
|
|
console.log("res4", res.data.data);
|
|
resolve(res.data.data);
|
|
},
|
|
});
|
|
});
|
|
},
|
|
|
|
// 检测更新
|
|
checkUpdate() {
|
|
// 检测更新
|
|
this.getLocalVersion().then((widgetInfo) => {
|
|
console.log("本地信息", widgetInfo);
|
|
console.log("config", config);
|
|
this.getServerVersion(widgetInfo).then((serverVersionData) => {
|
|
if (Number(widgetInfo.versionCode) !== serverVersionData.edition_number) {
|
|
uni.navigateTo({
|
|
url:
|
|
"/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj=" +
|
|
JSON.stringify(serverVersionData),
|
|
});
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
onLaunch: function () {},
|
|
onShow: function () {
|
|
console.log("App 1onShow");
|
|
this.checkUpdate();
|
|
// silenceUpdate('555')
|
|
// uni.navigateTo({
|
|
// url: "./uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update",
|
|
// });
|
|
uni.getNetworkType({
|
|
success: (res) => {
|
|
if (res.networkType === "none") {
|
|
uni.redirectTo({
|
|
url: "/pages/networko/index",
|
|
});
|
|
}
|
|
},
|
|
});
|
|
uni.onNetworkStatusChange(this.networkStatusChange);
|
|
},
|
|
onHide: function () {
|
|
uni.offNetworkStatusChange(this.networkStatusChange);
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style>
|
|
/*每个页面公共css */
|
|
</style>
|