164 lines
5.7 KiB
Vue
164 lines
5.7 KiB
Vue
<script>
|
||
import {
|
||
getVersion
|
||
} from './request/api/api'
|
||
import { webSocketManager } from '@/utils/ws/websocket.js';
|
||
import {checkDev} from "@/utils/utils";
|
||
import {bindUserApi} from "@/request/api/salesperson";
|
||
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)
|
||
|
||
|
||
|
||
console.log('获取更新机制', uni.canIUse('getUpdateManager'))
|
||
// 获取小程序更新机制兼容
|
||
if (uni.canIUse('getUpdateManager')) {
|
||
const updateManager = uni.getUpdateManager()
|
||
console.log('updateManager', updateManager)
|
||
// 检查是否有新版本发布
|
||
updateManager.onCheckForUpdate(function(res) {
|
||
console.log('检查是否有新版本发布', 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) {
|
||
//第二次提示后,强制更新
|
||
if (res.confirm) {
|
||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||
updateManager.applyUpdate()
|
||
} else if (res.cancel) {
|
||
//重新回到版本更新提示
|
||
autoUpdate()
|
||
}
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
})
|
||
// 新的版本下载失败
|
||
updateManager.onUpdateFailed(function() {
|
||
uni.showModal({
|
||
title: '温馨提示',
|
||
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
|
||
})
|
||
})
|
||
}
|
||
})
|
||
} else {
|
||
// 提示用户在最新版本的客户端上体验
|
||
uni.showModal({
|
||
title: '温馨提示',
|
||
content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
|
||
})
|
||
}
|
||
|
||
if (checkDev('open-im')) {
|
||
this.initWebSocket();
|
||
}
|
||
},
|
||
|
||
onShow: function(e) {
|
||
// console.log('App Show')
|
||
// this.$store.dispatch('initLogin')
|
||
// 解析scene里面的参数
|
||
if (e === undefined)
|
||
return {};
|
||
|
||
const scene = decodeURIComponent(e.query.scene)
|
||
// 这里接收扫码参数
|
||
if (scene) {
|
||
// 判断scene中是否包含sal_id
|
||
let isSalespersonId = decodeURIComponent(e.query.scene).includes('sal_id');
|
||
const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
||
if (scene[1]) {
|
||
uni.setStorageSync('stores_id', scene[1])
|
||
uni.setStorageSync('store_id', scene[1])
|
||
}
|
||
// uni.setStorageSync('stores_id', scene[1])
|
||
const st_id = decodeURIComponent(e.query.scene).split('&')
|
||
let store_id = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
||
store_id = decodeURIComponent(store_id[1]).split('&')
|
||
const doctors_id = decodeURIComponent(e.query.scene).split('=')
|
||
if (store_id[0] !== 'undefined') {
|
||
uni.setStorageSync('stores_id', store_id[0])
|
||
uni.setStorageSync('store_id', store_id[0])
|
||
}
|
||
uni.setStorageSync('doctors_id', st_id[0].split('su_id=')[1])
|
||
if (isSalespersonId) {
|
||
uni.setStorageSync('sal_id', st_id[1].split('sal_id=')[1])
|
||
}
|
||
uni.setStorageSync('st_id', doctors_id[2])
|
||
|
||
let userId = uni.getStorageSync('user_id')
|
||
if (isSalespersonId && userId) {
|
||
bindUserApi({
|
||
user_id: userId,
|
||
salesperson_id: st_id[1].split('sal_id=')[1],
|
||
}).then((res) => {
|
||
console.log('userId', userId, st_id[0].split('su_id=')[1], res);
|
||
})
|
||
}
|
||
// console.log(st_id, '4444111111111');
|
||
// console.log(scene, '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')
|
||
},
|
||
methods: {
|
||
initWebSocket() {
|
||
webSocketManager.connect();
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
|
||
@import "uview-ui/index.scss";
|
||
@import url("static/iconfont/index.css");
|
||
</style>
|