优化长连接
This commit is contained in:
@@ -125,10 +125,10 @@ class webSocketUtils {
|
|||||||
start(data) {
|
start(data) {
|
||||||
console.log('开启心跳检测',data)
|
console.log('开启心跳检测',data)
|
||||||
this.heartbeatInterval = setInterval(() => {
|
this.heartbeatInterval = setInterval(() => {
|
||||||
// this.send({
|
this.send({
|
||||||
// data: '心跳检测',
|
data: '心跳检测',
|
||||||
// type: 'jc',
|
type: 'heartbeat',
|
||||||
// });
|
});
|
||||||
}, this.timeout);
|
}, this.timeout);
|
||||||
}
|
}
|
||||||
//重新连接
|
//重新连接
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ const baseUrl = debug ? proxyApi : "https://wxcashiertest.sxczgkj.cn/cashierServ
|
|||||||
const baseUrlwws = 'ws://cashier.sxczgkj.cn/cashierService'
|
const baseUrlwws = 'ws://cashier.sxczgkj.cn/cashierService'
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef APP || MP-WEIXIN
|
// #ifdef APP || MP-WEIXIN
|
||||||
const baseUrl = 'https://cashier.sxczgkj.cn/cashierService'// 线上
|
// const baseUrl = 'https://cashier.sxczgkj.cn/cashierService'// 线上
|
||||||
const baseUrlwws = 'wss://cashier.sxczgkj.cn/cashierService' // 线上
|
// const baseUrlwws = 'wss://cashier.sxczgkj.cn/cashierService' // 线上
|
||||||
// const baseUrl = 'http://192.168.2.42:9888/cashierService'// 测试-w
|
// const baseUrl = 'http://192.168.2.42:9888/cashierService'// 测试-w
|
||||||
// const baseUrlwws ='wss://192.168.2.42:9999/cashierService' // 测试-w
|
// const baseUrlwws ='wss://192.168.2.42:9999/netty' // 测试-w
|
||||||
// const baseUrl = 'https://wxcashiertest.sxczgkj.cn/cashierService'// 测试
|
const baseUrl = 'https://wxcashiertest.sxczgkj.cn/cashierService'// 测试
|
||||||
// const baseUrlwws ='wss://wxcashiertest.sxczgkj.cn/cashierService' // 测试
|
const baseUrlwws ='wss://wxcashiertest.sxczgkj.cn/cashierService' // 测试
|
||||||
|
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
|||||||
@@ -300,10 +300,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handlemessage() {
|
handlemessage() {
|
||||||
|
console.log(this.socketTicket,'detail页面')
|
||||||
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
|
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
|
||||||
this.socketTicket = new webSocketUtils(
|
// this.socketTicket = new webSocketUtils(
|
||||||
`${uni.conf.baseUrlwws}/websocket/table/${uni.cache.get('tableCode')}/${uni.cache.get('shopUser')}/${uni.cache.get('userInfo').id}`,
|
// `${uni.conf.baseUrlwws}/websocket/table/${uni.cache.get('tableCode')}/${uni.cache.get('shopUser')}/${uni.cache.get('userInfo').id}`,
|
||||||
5000)
|
// 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",
|
||||||
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
// 数据处理
|
// 数据处理
|
||||||
|
|||||||
@@ -60,7 +60,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="shop-item" v-for="(item1,index1) in item.products" :key="item1.id">
|
<view class="shop-item" v-for="(item1,index1) in item.products" :key="item1.id">
|
||||||
<view class="cover" style="width:180rpx; height: 180rpx;">
|
<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>
|
||||||
<view class="info " style="display: flex;flex-direction: column;justify-content: center;">
|
<view class="info " style="display: flex;flex-direction: column;justify-content: center;">
|
||||||
<view class="name">
|
<view class="name">
|
||||||
@@ -310,6 +311,7 @@
|
|||||||
// // ...这里写你的业务逻辑
|
// // ...这里写你的业务逻辑
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
// setTimeout()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('调试1')
|
console.log('调试1')
|
||||||
if (uni.cache.get('token') && uni.cache.get('tableCode')) {
|
if (uni.cache.get('token') && uni.cache.get('tableCode')) {
|
||||||
@@ -328,10 +330,10 @@
|
|||||||
console.log(time, '时间戳')
|
console.log(time, '时间戳')
|
||||||
uni.cache.set('shopUser', res.data)
|
uni.cache.set('shopUser', res.data)
|
||||||
this.handlemessage()
|
this.handlemessage()
|
||||||
}else{
|
} else {
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
uni.pro.switchTab('index/index')
|
uni.pro.switchTab('index/index')
|
||||||
},1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
// try {
|
// try {
|
||||||
// if (res.data) {
|
// if (res.data) {
|
||||||
@@ -428,10 +430,17 @@
|
|||||||
},
|
},
|
||||||
handlemessage() {
|
handlemessage() {
|
||||||
// this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
|
// 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(
|
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}`,
|
||||||
// `${uni.conf.baseUrlwws}/websocket/table/${uni.cache.get('tableCode')}/${uni.cache.get('shopUser')}/${uni.cache.get('userInfo').id}`,
|
5000, {
|
||||||
5000)
|
tableId: uni.cache.get('tableCode'),
|
||||||
|
shopId: uni.cache.get('shopUser'),
|
||||||
|
userId: uni.cache.get('userInfo').id,
|
||||||
|
"type": "connect",
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 数据处理
|
// 数据处理
|
||||||
socketSendMsg(data) {
|
socketSendMsg(data) {
|
||||||
@@ -488,6 +497,7 @@
|
|||||||
},
|
},
|
||||||
async cartadd(item, index, index1, a, b, guge) { //列表添加
|
async cartadd(item, index, index1, a, b, guge) { //列表添加
|
||||||
console.log(item, index, index1, a, b, guge)
|
console.log(item, index, index1, a, b, guge)
|
||||||
|
|
||||||
if (guge == '单规格') { //没有规格为空
|
if (guge == '单规格') { //没有规格为空
|
||||||
this.specifications.duoguge = ''
|
this.specifications.duoguge = ''
|
||||||
this.skuidname = []
|
this.skuidname = []
|
||||||
|
|||||||
Reference in New Issue
Block a user