examTeamApp/App.vue

167 lines
4.0 KiB
Vue
Raw Normal View History

2024-05-02 15:59:36 +08:00
<script>
export default {
2024-06-13 18:03:50 +08:00
data() {
2024-07-26 16:43:31 +08:00
return {}
2024-06-13 18:03:50 +08:00
},
2024-05-02 15:59:36 +08:00
onLaunch: function() {
2024-06-13 18:03:50 +08:00
this.checkForUpdates()
2024-07-26 16:43:31 +08:00
// uni.switchTab({
// url: "/pages/index/index"
// })
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')
},
methods: {
// 版本信息监测
checkForUpdates() {
let that = this
let platform = ""
// 返回的是apk包信息
uni.getSystemInfo({
success(e) {
platform = e.platform
2024-07-22 14:13:19 +08:00
that.$store.commit('changePhoneInfo', {
platform: e.platform
})
2024-06-13 18:03:50 +08:00
}
})
plus.runtime.getProperty(plus.runtime.appid, function(info) {
uni.setStorageSync('VERSION', info.version)
let res_version = info.version;
2024-07-22 14:13:19 +08:00
that.$store.commit('changePhoneInfo', {
info: info
})
2024-06-13 18:03:50 +08:00
that.$model.getloginversion({}).then(res => {
let downloadUrl = res.data.url
let latestVersion = res.data.version
console.log("版本信息", info)
console.log("res", res)
2024-07-22 14:13:19 +08:00
that.$store.commit('changePhoneInfo', {
versionUrl: res.data
})
2024-06-13 18:03:50 +08:00
// 比对版本号
if (latestVersion !== res_version) {
uni.showModal({
title: '发现新版本',
content: '检查到新版本' + res.data.version + ',是否更新?',
success: (modalRes) => {
if (modalRes.confirm) {
if (platform === 'android') {
uni.showLoading({
2024-07-22 14:13:19 +08:00
title: '正在升级,请耐心等待'
2024-06-13 18:03:50 +08:00
})
uni.setStorageSync('VERSION', res.data.version)
that.downloadNewVersion(downloadUrl, res.code);
} else {
uni.showModal({
title: '发现新版本 ' + res.data.version,
content: '请到App store进行升级',
showCancel: false
})
}
} else {
console.log("用户放弃更新")
if (res.code == 0) {
that.handleUserList()
} else {
2024-07-22 14:13:19 +08:00
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/login'
})
2024-07-26 16:43:31 +08:00
}, 800);
2024-06-13 18:03:50 +08:00
}
}
}
});
} else {
console.log("版本号相同")
if (res.code == 0) {
that.handleUserList()
} else {
2024-07-22 14:13:19 +08:00
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/login'
})
}, 500);
2024-06-13 18:03:50 +08:00
}
}
})
})
},
// 下载新版本
downloadNewVersion(downloadUrl, code) {
const dtask = uni.downloadFile({
url: downloadUrl,
success: (downloadRes) => {
if (downloadRes.statusCode === 200) {
uni.hideLoading();
plus.runtime.install(
downloadRes.tempFilePath, {
force: true
},
function() {
console.log('install success...');
plus.runtime.restart();
},
function(e) {
console.error('install fail...');
});
}
},
fail: () => {
uni.showToast({
2024-07-22 14:13:19 +08:00
title: '升级失败',
2024-06-13 18:03:50 +08:00
icon: 'none'
});
}
});
dtask.onProgressUpdate((res) => {
console.log('下载进度' + res.progress + '%');
});
},
// 成员列表
handleUserList() {
let that = this
that.$model.getUserList({
type: 2
}).then(res => {
console.log("用户列表", res)
if (res.code != 0) {
that.$tools.msg(res.msg)
return
}
that.$store.commit('changeFamilay', res.data)
if (res.data.length) {
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
0].id
})
that.$store.dispatch("getCardList", {
aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
0].id
})
}
}).catch(err => {})
},
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 "/assets/common.scss";
@import "/assets/iconfont.css";
@import "/assets/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>