This commit is contained in:
魏啾
2024-06-07 17:21:52 +08:00
parent c8633827cc
commit 5a16a5199e
2 changed files with 166 additions and 192 deletions

View File

@@ -283,42 +283,32 @@
uni.reLaunch({
url: '/pages/login/login?types=' + 0
});
return false
}
uni.$on('message', this.getMessage)
setTimeout(() => {
if (uni.cache.get('token') && uni.cache.get('tableCode')) {
this.productqueryShopIdByTableCode() //获取shop User id
}
}, 500)
this.$nextTick(() => {
this.countTitleTopNum(); //导航栏
});
},
onUnload() {
this.socketSendMsg({ //定义socket数据传参
"type": "close", //“addcart:添加购物车create0rder:生成订单clearCart:庆康购物车”,
})
console.log(this.socketTicket, '关闭长连接')
try {
this.socketSendMsg({ //定义socket数据传参
"type": "close", //“addcart:添加购物车create0rder:生成订单clearCart:庆康购物车”,
})
} catch (e) {
//TODO handle the exception
}
this.socketTicket.Close()
uni.$off('message')
},
onShow() {
// console.log(this.socketTicket,'进入页面')
// if (this.socketTicket) {
// this.socketTicket.Close()
// uni.$off('message')
// }
// uni.onNetworkStatusChange((res) => { //监听网络状态变化
// if (!res.isConnected) {
// // 检查网络是否连接
// } else {
// console.log(res, 111);
// // ...这里写你的业务逻辑
// }
// });
// setTimeout()
this.handlemessage()
setTimeout(() => {
console.log('调试1')
if (uni.cache.get('token') && uni.cache.get('tableCode')) {
this.productqueryShopIdByTableCode() //获取shop User id
}
}, 500)
},
methods: {
// 单独获取他的shopUserid
@@ -337,16 +327,6 @@
uni.pro.switchTab('index/index')
}, 1000)
}
// try {
// if (res.data) {
// let time = new Date
// console.log(time, '时间戳')
// uni.cache.set('shopUser', res.data)
// this.handlemessage()
// }
// } catch (e) {
// //TODO handle the exception
// }
},
getMessage(msg) { //wss 回显数据
if (msg.status != 'success') {
@@ -432,17 +412,12 @@
},
handlemessage() {
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
// this.socketTicket = new webSocketUtils(
// `${uni.conf.baseUrlwws}/websocket/table?tableId=${uni.cache.get('tableCode')}&shopId=${uni.cache.get('shopUser')}&userId=${uni.cache.get('userInfo').id}`,
// 5000)
this.socketTicket = new webSocketUtils(
`${uni.conf.baseUrlwws}`,
5000, {
tableId: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
userId: uni.cache.get('userInfo').id,
"type": "connect",
})
this.socketTicket = new webSocketUtils(`${uni.conf.baseUrlwws}`, 5000, {
tableId: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
userId: uni.cache.get('userInfo').id,
"type": "connect",
})
},
// 数据处理
socketSendMsg(data) {
@@ -499,7 +474,7 @@
},
async cartadd(item, index, index1, a, b, guge) { //列表添加
console.log(item, index, index1, a, b, guge)
if (guge == '单规格') { //没有规格为空
this.specifications.duoguge = ''
this.skuidname = []
@@ -665,6 +640,7 @@
switch (t) {
case 1:
// 返回
this.socketTicket.Close()
uni.switchTab({
url: '/pages/index/index'
})