examTeamApp/App.vue

195 lines
5.2 KiB
Vue
Raw Permalink Normal View History

2024-05-02 15:59:36 +08:00
<script>
let platform = ""
2024-05-02 15:59:36 +08:00
export default {
2024-06-13 18:03:50 +08:00
data() {
return {}
2024-06-13 18:03:50 +08:00
},
2024-05-02 15:59:36 +08:00
onLaunch: function() {
let that = this
// 返回的是apk包信息
2024-10-11 10:04:19 +08:00
// #ifdef APP-PLUS
uni.getSystemInfo({
success(e) {
platform = e.platform
that.$store.commit('changePhoneInfo', {
platform: e.platform
})
console.log("getSystemInfo", e.platform)
}
})
if (platform === 'ios') { // ios首次安装没有网络
uni.onNetworkStatusChange(function(res) {
if (res.isConnected == true) {
2025-09-30 09:46:29 +08:00
that.handleConfig()
that.handleCityList()
that.handleCooperationUrl()
uni.reLaunch({
2024-10-11 10:04:19 +08:00
url: '/pageTwo/login/login'
})
console.log("有网络连接", res.isConnected)
}
});
}
that.checkForUpdates()
2024-10-11 10:04:19 +08:00
// #endif
2024-12-14 09:42:21 +08:00
// #ifdef MP-WEIXIN
// 版本更新
2025-09-30 09:46:29 +08:00
that.handleConfig()
that.handleCityList()
that.handleCooperationUrl()
2024-12-14 09:42:21 +08:00
that.updataWeiXin()
// #endif
2024-06-13 18:03:50 +08:00
console.log('App Launch')
2024-05-02 15:59:36 +08:00
},
onShow: function() {
2024-06-13 18:03:50 +08:00
console.log('App Show')
2024-05-02 15:59:36 +08:00
},
onHide: function() {
2024-06-13 18:03:50 +08:00
console.log('App Hide')
2024-10-11 10:04:19 +08:00
// #ifdef APP-PLUS
uni.offNetworkStatusChange(function(res) {
console.log("取消网络监听")
})
2024-10-11 10:04:19 +08:00
// #endif
2024-06-13 18:03:50 +08:00
},
methods: {
// 版本信息监测
checkForUpdates() {
let that = this
plus.runtime.getProperty(plus.runtime.appid, function(info) {
uni.setStorageSync('VERSION', info.version)
2024-07-22 14:13:19 +08:00
that.$store.commit('changePhoneInfo', {
info: info
})
console.log("当前应用版本号", info)
that.handleCityList()
2025-09-30 09:46:29 +08:00
that.handleConfig()
that.handleCooperationUrl()
that.handleoginversion(info)
})
},
// 版本信息
handleoginversion(info) {
let that = this
that.$model.getloginversion({}).then(res => {
console.log("是否登录及版本号", res)
2024-10-11 10:04:19 +08:00
that.handleCancelUpdate(res.code)
2025-03-19 17:05:37 +08:00
// #ifdef APP-PLUS||APP
2024-10-11 10:04:19 +08:00
let currentVersion = info.version;
let latestVersion = res.data.version
that.$store.commit('changePhoneInfo', {
versionUrl: res.data
})
// 比对版本号
2024-09-12 11:20:52 +08:00
let version = that.$tools.compareVersions(currentVersion, latestVersion)
if (version == -1) { // 0版本号相通1第一个版本号大于第二个版本号-1第一个版本号小于第二个版本号
uni.showModal({
title: '发现新版本',
content: '检查到新版本' + res.data.version + ',是否更新?',
success: (modalRes) => {
2024-09-03 09:52:19 +08:00
if (modalRes.confirm) { //确定更新
2025-03-19 17:05:37 +08:00
if (platform === 'android') { //安卓更新
uni.setStorageSync('VERSION', res.data.version)
2025-03-19 17:14:21 +08:00
uni.navigateTo({
url: "/pageTwo/my/about"
})
2025-03-19 17:05:37 +08:00
} else { //ios跳转
plus.runtime.launchApplication({
action: `itms-apps://itunes.apple.com/cn/app/id6654906497?mt=8`
})
}
} else {
2025-03-19 17:05:37 +08:00
that.$tools.msg("稍后可在'关于我们'内更新程序!")
2024-06-13 18:03:50 +08:00
}
}
});
}
2024-10-11 10:04:19 +08:00
// #endif
2024-06-13 18:03:50 +08:00
})
},
2024-09-03 09:52:19 +08:00
// 取消更新
handleCancelUpdate(code) {
let that = this
if (code == 0) {
2024-10-11 10:04:19 +08:00
uni.reLaunch({
url: "/pages/home/home?type=1"
})
2024-09-03 09:52:19 +08:00
} else {
setTimeout(() => {
uni.reLaunch({
2024-10-11 10:04:19 +08:00
url: '/pageTwo/login/login'
2024-09-03 09:52:19 +08:00
})
}, 500);
}
},
// 地区
handleCityList() {
2024-09-26 09:18:27 +08:00
let that = this
that.$model.getGradeList({}).then((res) => {
2025-03-19 17:05:37 +08:00
// console.log("|全部地区", res.data)
if (res.code != 0) return
that.$store.commit('changeCityList', res.data.area_list)
that.$store.commit('changeGradeList', res.data.grade_list)
that.$store.commit('changeIdentityList', res.data.identity_list)
2024-09-26 09:18:27 +08:00
})
},
2025-09-30 09:46:29 +08:00
// 通用枚举
handleConfig() {
let that = this
that.$model.getConfig({}).then((res) => {
// console.log("|全部枚举", res.data)
if (res.code != 0) return
that.$store.commit('changeConfig', res.data)
})
},
// 合作服务
handleCooperationUrl() {
let that = this
that.$model.getCooperationUrl({}).then((res) => {
2025-03-19 17:05:37 +08:00
// console.log("合作服务", res.data)
if (res.code != 0) return
this.$store.commit("changeCooperationUrl", res.data);
})
},
2024-12-14 09:42:21 +08:00
// 微信小程序更新
updataWeiXin() {
let that = this
const updateManager = uni.getUpdateManager()
// 请求完新版本信息的回调
updateManager.onCheckForUpdate(function(res) {
2025-03-19 17:05:37 +08:00
// console.log("是否有新版本", res.hasUpdate)
2024-12-14 09:42:21 +08:00
})
updateManager.onUpdateReady(function() {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function() {
uni.showModal({
title: '新版本更新失败',
content: '请退出并移除小程序,重新打开...',
})
})
}
2024-05-02 15:59:36 +08:00
}
}
</script>
<style lang="scss">
/*每个页面公共css */
2024-05-29 16:35:45 +08:00
/* #ifndef APP-NVUE */
@import "/uni.scss";
@import "/scss/common.scss";
@import "/scss/iconfont.css";
@import "/scss/iconfont-weapp-icon.css";
2024-05-02 15:59:36 +08:00
2024-05-29 16:35:45 +08:00
/* #endif*/
2024-05-02 15:59:36 +08:00
</style>