153 lines
4.8 KiB
Vue
153 lines
4.8 KiB
Vue
<script>
|
||
import Vue from 'vue'
|
||
|
||
export default {
|
||
created() {
|
||
// #ifdef APP-PLUS
|
||
plus.navigator.closeSplashscreen();
|
||
// #endif
|
||
},
|
||
onLoad() {
|
||
console.log(12222)
|
||
uni.onNetworkStatusChange((res) => {
|
||
console.log('网络类型变化:', res.networkType);
|
||
console.log('连接网络状态变化:', res.isConnected ? '已连接' : '断开连接');
|
||
});
|
||
},
|
||
onLaunch: async function() {
|
||
uni.getSystemInfo({
|
||
success: function(e) {
|
||
// #ifndef MP
|
||
Vue.prototype.StatusBar = e.statusBarHeight;
|
||
if (e.platform == 'android') {
|
||
Vue.prototype.CustomBar = e.statusBarHeight + 50;
|
||
} else {
|
||
Vue.prototype.CustomBar = e.statusBarHeight + 45;
|
||
};
|
||
// #endif
|
||
|
||
// #ifdef MP-WEIXIN
|
||
Vue.prototype.StatusBar = e.statusBarHeight;
|
||
let custom = wx.getMenuButtonBoundingClientRect();
|
||
Vue.prototype.Custom = custom;
|
||
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
|
||
// #endif
|
||
|
||
// #ifdef MP-ALIPAY
|
||
Vue.prototype.StatusBar = e.statusBarHeight;
|
||
Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
|
||
// #endif
|
||
}
|
||
});
|
||
|
||
// 是否更新APP
|
||
// #ifdef APP-PLUS
|
||
await this.getIsUpdata();
|
||
// #endif
|
||
},
|
||
onShow: function() {
|
||
|
||
uni.getNetworkType({
|
||
success: function (res) {
|
||
console.log(res.networkType);
|
||
}
|
||
});
|
||
uni.onNetworkStatusChange(function (res) {
|
||
console.log(res.isConnected);
|
||
console.log(res.networkType);
|
||
});
|
||
console.log('App 开启')
|
||
},
|
||
onHide: function() {
|
||
|
||
console.log('App 关闭')
|
||
},
|
||
methods: {
|
||
getIsUpdata() {
|
||
// 获取本地应用资源版本号
|
||
plus.runtime.getProperty(plus.runtime.appid, (info) => {
|
||
this.version = info.version; // 版本号 1.0.0
|
||
this.versionCode = info.versionCode ; // 版本号名称 100
|
||
let params = {
|
||
version: info.version
|
||
};
|
||
this.$store.dispatch('api/getVersion', params).then(res2=> {
|
||
if (this.compareVersions(res.data.version, params.version) == 1) {
|
||
console.log(res2)
|
||
uni.showModal({
|
||
title: "版本更新",
|
||
content: '有新的版本发布,是否立即进行新版本下载?',
|
||
confirmText:'立即更新',
|
||
cancelText:'稍后进行',
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
//#ifdef APP-PLUS
|
||
// encodeURI要大写
|
||
plus.runtime.openURL(encodeURI(res2.data.url));
|
||
//#endif
|
||
} else if (res.cancel) {
|
||
console.log('稍后更新');
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
// 下面执行需要更新的安卓端热更新代码
|
||
// var data = {
|
||
// // 版本更新内容 支持<br>自动换行
|
||
// describe: "1.修复已知问题2.优化用户体验3.新增聊天室4.修复部分bug4.修复部分bug14.",
|
||
// edition_url: 'https://img.agrimedia.cn/bmsc/apps/1.1.8s.wgt', //apk、wgt包下载地址或者应用市场地址 安卓应用市场 market://details?id=xxxx 苹果store itms-apps://itunes.apple.com/cn/app/xxxxxx
|
||
// edition_force: 0, //是否强制更新 0代表否 1代表是, 弹窗关闭
|
||
// package_type: 1, //0是整包升级(apk或者appstore或者安卓应用市场) 1是wgt升级
|
||
// edition_number: 100, //版本号 最重要的manifest里的版本号 (检查更新主要以服务器返回的edition_number版本号是否大于当前app的版本号来实现是否更新)
|
||
// edition_name: '1.0.0', // 版本名称 manifest里的版本名称
|
||
// }
|
||
|
||
// // 这里也可以让前端判断本地和接口返回的版本号是否一致
|
||
// if (Number(this.versionCode) == 117) {
|
||
// //跳转更新页面 (注意!!!如果pages.json第一页的代码里有一打开就跳转其他页面的操作,下面这行代码最好写在setTimeout里面设置延时3到5秒再执行)
|
||
// uni.navigateTo({
|
||
// url: `/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj=${JSON.stringify(data)}`
|
||
// });
|
||
// }
|
||
})
|
||
})
|
||
},
|
||
|
||
compareVersions(v1, v2) {
|
||
const v1Parts = v1.split('.').map(Number);
|
||
const v2Parts = v2.split('.').map(Number);
|
||
|
||
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
||
const v1Part = v1Parts[i] || 0;
|
||
const v2Part = v2Parts[i] || 0;
|
||
|
||
if (v1Part > v2Part) {
|
||
return 1;
|
||
}
|
||
if (v1Part < v2Part) {
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style >
|
||
page {
|
||
background-color: #f7f8fa;
|
||
}
|
||
|
||
body{
|
||
background: #f7f8fa !important;
|
||
}
|
||
|
||
</style>
|
||
<style lang="scss">
|
||
/*每个页面公共css */
|
||
@import "@/common/css/common.scss";
|
||
@import "~@/static/icon-font/css/iconfont.css"
|
||
</style> |