Files
xk-client-wx/App.vue

122 lines
4.2 KiB
Vue
Raw Normal View History

2024-09-19 12:51:35 +08:00
<script>
import {
getVersion
} from './request/api/api'
export default {
// //初始化状态-如果登录过,保持登录状态
onLaunch: async function() {
const version = 4 // 如果当前版本和后台返回的版本一致,那就是审核中,审核通过后 后台设置加1,如果后台的比本地的大 那就是生产版本
const res = await getVersion()
const val = Number(res.data.data.value)
// const accountInfo = uni.getAccountInfoSync();
// if (accountInfo.miniProgram.envVersion === 'develop') {
// // 跳转预留好的页面-调试使用中
// // wx.navigateTo() // 开发时,可以注释本行,方便自己预览
// // console.log(accountInfo,'aaaaaaaaaaaaaaaa');
// uni.navigateTo({
// url:'/pages/home/index',
// success() {
// // console.log(accountInfo,'aaaaaaaaaaaaaaaa');
// }
// })
// }
// 生产
const isShow = val <= version;
// 测试
// const isShow = accountInfo.miniProgram.envVersion != 'develop';
// 存储当前版本,也可以使用globalData
uni.setStorageSync('isShow_envVersion', isShow)
2025-02-13 10:39:12 +08:00
// 获取小程序更新机制兼容
2024-09-19 12:51:35 +08:00
if (uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager()
// 检查是否有新版本发布
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
//小程序有新版本,则静默下载新版本,做好更新准备
updateManager.onUpdateReady(function() {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
} else if (res.cancel) {
//如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
uni.showModal({
title: '温馨提示',
content: '我们已经做了新的优化,请及时更新哦~',
showCancel: false, //隐藏取消按钮,也可显示,取消会走res.cancel,然后从新开始提示
success: function(res) {
2025-02-13 10:39:12 +08:00
//第二次提示后,强制更新
2024-09-19 12:51:35 +08:00
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
} else if (res.cancel) {
//重新回到版本更新提示
autoUpdate()
}
}
})
}
}
})
})
// 新的版本下载失败
updateManager.onUpdateFailed(function() {
uni.showModal({
title: '温馨提示',
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
})
})
}
})
} else {
// 提示用户在最新版本的客户端上体验
uni.showModal({
title: '温馨提示',
content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
})
}
},
onShow: function(e) {
// console.log('App Show')
// this.$store.dispatch('initLogin')
// 解析scene里面的参数
if (e === undefined)
return {};
const scene = decodeURIComponent(e.query.scene)
if (scene) {
const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
uni.setStorageSync('stores_id', scene[1])
const st_id = decodeURIComponent(e.query.scene).split('&')
const doctors_id = decodeURIComponent(e.query.scene).split('=')
uni.setStorageSync('doctors_id', st_id[0].split('su_id=')[1])
uni.setStorageSync('st_id', doctors_id[2])
// console.log(scene[1], '4444');
}
// const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
// console.log(scene, '11111');
},
onHide: function() {
// console.log('App Hide')
// this.$store.dispatch('closeWebSocket')
},
onUnload:function() {
// uni.removeStorageSync('token')
}
}
</script>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
@import url("static/iconfont/index.css");
2025-02-13 10:39:12 +08:00
</style>