优化长连接

This commit is contained in:
duan
2024-06-06 14:55:23 +08:00
parent 1e9797f09a
commit 554217180e
4 changed files with 39 additions and 19 deletions

View File

@@ -60,7 +60,8 @@
</view>
<view class="shop-item" v-for="(item1,index1) in item.products" :key="item1.id">
<view class="cover" style="width:180rpx; height: 180rpx;">
<c-image :src="`${item1.coverImg}?x-oss-process=image/resize,m_lfit,w_180,h_180`" width="180" height="180"></c-image>
<c-image :src="`${item1.coverImg}?x-oss-process=image/resize,m_lfit,w_180,h_180`"
width="180" height="180"></c-image>
</view>
<view class="info " style="display: flex;flex-direction: column;justify-content: center;">
<view class="name">
@@ -310,6 +311,7 @@
// // ...这里写你的业务逻辑
// }
// });
// setTimeout()
setTimeout(() => {
console.log('调试1')
if (uni.cache.get('token') && uni.cache.get('tableCode')) {
@@ -328,10 +330,10 @@
console.log(time, '时间戳')
uni.cache.set('shopUser', res.data)
this.handlemessage()
}else{
setTimeout(()=>{
} else {
setTimeout(() => {
uni.pro.switchTab('index/index')
},1000)
}, 1000)
}
// try {
// if (res.data) {
@@ -428,10 +430,17 @@
},
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}/websocket/table?tableId=${uni.cache.get('tableCode')}&shopId=${uni.cache.get('shopUser')}&userId=${uni.cache.get('userInfo').id}`,
// `${uni.conf.baseUrlwws}/websocket/table/${uni.cache.get('tableCode')}/${uni.cache.get('shopUser')}/${uni.cache.get('userInfo').id}`,
5000)
`${uni.conf.baseUrlwws}`,
5000, {
tableId: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopUser'),
userId: uni.cache.get('userInfo').id,
"type": "connect",
})
},
// 数据处理
socketSendMsg(data) {
@@ -488,6 +497,7 @@
},
async cartadd(item, index, index1, a, b, guge) { //列表添加
console.log(item, index, index1, a, b, guge)
if (guge == '单规格') { //没有规格为空
this.specifications.duoguge = ''
this.skuidname = []