2024-09-19 12:51:35 +08:00
|
|
|
|
<script>
|
|
|
|
|
|
import {
|
2026-01-12 12:36:50 +08:00
|
|
|
|
getVersion,
|
|
|
|
|
|
getSystemConfig
|
2024-09-19 12:51:35 +08:00
|
|
|
|
} from './request/api/api'
|
2025-07-19 16:04:43 +08:00
|
|
|
|
import { webSocketManager } from '@/utils/ws/websocket.js';
|
2026-01-07 14:21:29 +08:00
|
|
|
|
import { ChatManager } from '@/store/chat/chat.js';
|
2025-08-30 14:17:19 +08:00
|
|
|
|
import {checkDev} from "@/utils/utils";
|
2025-11-19 13:48:42 +08:00
|
|
|
|
import {bindUserApi} from "@/request/api/salesperson";
|
2026-01-12 12:36:50 +08:00
|
|
|
|
import { silentLogin } from '@/utils/login.js';
|
|
|
|
|
|
import { isGuestMode } from '@/common/utils/auth.js';
|
2024-09-19 12:51:35 +08:00
|
|
|
|
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)
|
|
|
|
|
|
|
2026-01-12 12:36:50 +08:00
|
|
|
|
// 检查是否已登录,如果未登录才检查配置并决定是否静默登录
|
|
|
|
|
|
const token = uni.getStorageSync('token');
|
|
|
|
|
|
const userInfo = uni.getStorageSync('userinfo');
|
|
|
|
|
|
|
|
|
|
|
|
if (!token || !userInfo) {
|
|
|
|
|
|
// 未登录,获取系统配置,判断是否需要静默登录
|
|
|
|
|
|
try {
|
|
|
|
|
|
const configRes = await getSystemConfig({
|
|
|
|
|
|
method: "get",
|
|
|
|
|
|
data: {
|
|
|
|
|
|
store_id: uni.getStorageSync('store_id') || '11001'
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-09-19 12:51:35 +08:00
|
|
|
|
|
2026-01-12 12:36:50 +08:00
|
|
|
|
// 根据配置决定是否静默登录
|
|
|
|
|
|
// 注意:需要根据实际接口返回格式解析 need_login 字段
|
|
|
|
|
|
const isGuest = isGuestMode();
|
|
|
|
|
|
let needLogin = true; // 默认需要登录页
|
|
|
|
|
|
|
|
|
|
|
|
if (isGuest && (configRes.data.code === 0 || configRes.data.code === '0')) {
|
|
|
|
|
|
// 新格式:从 result 中获取
|
|
|
|
|
|
const configData = configRes.data.result || {};
|
|
|
|
|
|
needLogin = configData.need_login !== false; // false 表示静默登录
|
|
|
|
|
|
} else if (!isGuest && (configRes.data.errcode === 0 || configRes.data.errcode === '0')) {
|
|
|
|
|
|
// 旧格式:从 data 中获取
|
|
|
|
|
|
const configData = configRes.data.data || {};
|
|
|
|
|
|
needLogin = configData.need_login !== false; // false 表示静默登录
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果配置为静默登录(need_login: false),直接执行静默登录
|
|
|
|
|
|
if (!needLogin) {
|
|
|
|
|
|
// 执行静默登录(不显示提示,不跳转)
|
|
|
|
|
|
silentLogin().then((loginResult) => {
|
|
|
|
|
|
if (loginResult.success) {
|
|
|
|
|
|
console.log('静默登录成功');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error('静默登录失败:', loginResult.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
console.error('静默登录异常:', error);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果配置为需要登录页(need_login: true),不执行任何操作,等待用户手动登录
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
// 配置接口调用失败,不影响应用启动,仅记录日志
|
|
|
|
|
|
console.error('获取系统配置失败:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-19 12:51:35 +08:00
|
|
|
|
|
2025-08-30 14:17:19 +08:00
|
|
|
|
console.log('获取更新机制', uni.canIUse('getUpdateManager'))
|
2025-02-13 10:39:12 +08:00
|
|
|
|
// 获取小程序更新机制兼容
|
2024-09-19 12:51:35 +08:00
|
|
|
|
if (uni.canIUse('getUpdateManager')) {
|
|
|
|
|
|
const updateManager = uni.getUpdateManager()
|
2025-08-30 14:17:19 +08:00
|
|
|
|
console.log('updateManager', updateManager)
|
2024-09-19 12:51:35 +08:00
|
|
|
|
// 检查是否有新版本发布
|
|
|
|
|
|
updateManager.onCheckForUpdate(function(res) {
|
2025-08-30 14:17:19 +08:00
|
|
|
|
console.log('检查是否有新版本发布', res)
|
2024-09-19 12:51:35 +08:00
|
|
|
|
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: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-07-19 16:04:43 +08:00
|
|
|
|
|
2025-08-30 14:17:19 +08:00
|
|
|
|
if (checkDev('open-im')) {
|
|
|
|
|
|
this.initWebSocket();
|
|
|
|
|
|
}
|
2024-09-19 12:51:35 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShow: function(e) {
|
|
|
|
|
|
// console.log('App Show')
|
|
|
|
|
|
// this.$store.dispatch('initLogin')
|
|
|
|
|
|
// 解析scene里面的参数
|
|
|
|
|
|
if (e === undefined)
|
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
|
|
const scene = decodeURIComponent(e.query.scene)
|
2025-11-19 13:48:42 +08:00
|
|
|
|
// 这里接收扫码参数
|
2024-09-19 12:51:35 +08:00
|
|
|
|
if (scene) {
|
2025-11-19 13:48:42 +08:00
|
|
|
|
// 判断scene中是否包含sal_id
|
|
|
|
|
|
let isSalespersonId = decodeURIComponent(e.query.scene).includes('sal_id');
|
2024-09-19 12:51:35 +08:00
|
|
|
|
const scene = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
2025-11-19 13:48:42 +08:00
|
|
|
|
if (scene[1]) {
|
|
|
|
|
|
uni.setStorageSync('stores_id', scene[1])
|
|
|
|
|
|
uni.setStorageSync('store_id', scene[1])
|
|
|
|
|
|
}
|
|
|
|
|
|
// uni.setStorageSync('stores_id', scene[1])
|
2024-09-19 12:51:35 +08:00
|
|
|
|
const st_id = decodeURIComponent(e.query.scene).split('&')
|
2025-11-19 13:48:42 +08:00
|
|
|
|
let store_id = decodeURIComponent(e.query.scene).split('STORE_QR_CODE_')
|
|
|
|
|
|
store_id = decodeURIComponent(store_id[1]).split('&')
|
2024-09-19 12:51:35 +08:00
|
|
|
|
const doctors_id = decodeURIComponent(e.query.scene).split('=')
|
2025-11-19 13:48:42 +08:00
|
|
|
|
if (store_id[0] !== 'undefined') {
|
|
|
|
|
|
uni.setStorageSync('stores_id', store_id[0])
|
|
|
|
|
|
uni.setStorageSync('store_id', store_id[0])
|
|
|
|
|
|
}
|
2024-09-19 12:51:35 +08:00
|
|
|
|
uni.setStorageSync('doctors_id', st_id[0].split('su_id=')[1])
|
2025-11-19 13:48:42 +08:00
|
|
|
|
if (isSalespersonId) {
|
|
|
|
|
|
uni.setStorageSync('sal_id', st_id[1].split('sal_id=')[1])
|
|
|
|
|
|
}
|
2024-09-19 12:51:35 +08:00
|
|
|
|
uni.setStorageSync('st_id', doctors_id[2])
|
2025-11-19 13:48:42 +08:00
|
|
|
|
|
|
|
|
|
|
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');
|
2024-09-19 12:51:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 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')
|
2025-07-19 16:04:43 +08:00
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
initWebSocket() {
|
|
|
|
|
|
webSocketManager.connect();
|
2026-01-07 14:21:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 注册全局消息处理器
|
|
|
|
|
|
webSocketManager.addMessageHandler((data) => {
|
|
|
|
|
|
// 只处理聊天消息(包含 room_id 的消息)
|
|
|
|
|
|
if (data.room_id) {
|
|
|
|
|
|
// 获取当前页面路径
|
|
|
|
|
|
const pages = getCurrentPages();
|
|
|
|
|
|
const currentPage = pages[pages.length - 1];
|
|
|
|
|
|
const currentPath = currentPage ? currentPage.route : '';
|
|
|
|
|
|
|
|
|
|
|
|
// 如果用户在聊天页面,不调用 ChatManager(chat.vue 会自己处理)
|
|
|
|
|
|
// 避免消息重复推送
|
|
|
|
|
|
if (currentPath && currentPath.includes('chat/chat')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ChatManager.handleIncomingMessage(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 监听全局通知事件
|
|
|
|
|
|
uni.$on('show-global-notification', this.handleShowNotification);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 处理显示通知
|
|
|
|
|
|
* @param {Object} message 消息对象
|
|
|
|
|
|
*/
|
|
|
|
|
|
handleShowNotification(message) {
|
|
|
|
|
|
// 获取当前页面路径
|
|
|
|
|
|
const pages = getCurrentPages();
|
|
|
|
|
|
const currentPage = pages[pages.length - 1];
|
|
|
|
|
|
const currentPath = currentPage ? currentPage.route : '';
|
|
|
|
|
|
|
|
|
|
|
|
// 如果在聊天页面,不显示顶部通知
|
|
|
|
|
|
if (currentPath && currentPath.includes('chat/chat')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取消息预览文本
|
|
|
|
|
|
const messagePreview = ChatManager.getMessagePreview(message);
|
|
|
|
|
|
|
|
|
|
|
|
// 从消息中提取发送者信息
|
|
|
|
|
|
let senderName = '新消息';
|
|
|
|
|
|
let senderAvatar = '/static/xx/ysxx.png';
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试解析发送者ID获取更多信息
|
|
|
|
|
|
const senderId = message.sender_user_id || '';
|
|
|
|
|
|
if (senderId.startsWith('doctor-')) {
|
|
|
|
|
|
senderName = '医生消息';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 触发通知组件显示
|
|
|
|
|
|
uni.$emit('show-message-notification', {
|
|
|
|
|
|
avatar: senderAvatar,
|
|
|
|
|
|
title: senderName,
|
|
|
|
|
|
message: messagePreview,
|
|
|
|
|
|
roomId: message.room_id,
|
|
|
|
|
|
roomData: {
|
|
|
|
|
|
nick_name: senderName,
|
|
|
|
|
|
user_id: senderId,
|
|
|
|
|
|
avatar: senderAvatar
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-07-19 16:04:43 +08:00
|
|
|
|
}
|
2026-01-07 14:21:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
// 移除全局通知事件监听
|
|
|
|
|
|
uni.$off('show-global-notification', this.handleShowNotification);
|
2025-07-19 16:04:43 +08:00
|
|
|
|
}
|
2024-09-19 12:51:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
</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>
|