修复切换页面nan问题
This commit is contained in:
parent
1f59082bcb
commit
ac28ee855f
|
|
@ -72,7 +72,11 @@ const useWebSocket = (options = {}) => {
|
|||
}
|
||||
|
||||
// 关闭现有连接并清理资源
|
||||
closeExistingConnection();
|
||||
try{
|
||||
closeExistingConnection();
|
||||
}catch(err){
|
||||
|
||||
}
|
||||
socketTask.value = uni.connectSocket({
|
||||
url: uni.conf.baseUrlwws,
|
||||
success: (res) => {
|
||||
|
|
@ -353,7 +357,7 @@ const useWebSocket = (options = {}) => {
|
|||
connect,
|
||||
onShowconnect,
|
||||
initNetworkListener,
|
||||
connect
|
||||
connect,allowReconnect
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@
|
|||
|
||||
</view>
|
||||
|
||||
<view class="total-wrap" v-if="listinfo.status == 'unpaid'||!listinfo.id">
|
||||
<view class="total-wrap u-m-t-30" v-if="listinfo.status == 'unpaid'||!listinfo.id">
|
||||
<view>总计¥</view>
|
||||
<view class="price"> {{listinfo.totalCost||''}} </view>
|
||||
</view>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<view class="container">
|
||||
<up-navbar :title="navTitle" @leftClick="back" placeholder></up-navbar>
|
||||
<up-navbar :title="navTitle" @leftClick="onback" placeholder></up-navbar>
|
||||
<view class="headStatus">
|
||||
<view class="status">
|
||||
|
||||
|
|
@ -106,6 +106,11 @@
|
|||
import {
|
||||
back
|
||||
} from '@/utils/uniapp.js'
|
||||
|
||||
function onback() {
|
||||
closeSocket()
|
||||
back()
|
||||
}
|
||||
const customStyle = {
|
||||
'width': '180rpx',
|
||||
'height': '70rpx',
|
||||
|
|
@ -121,7 +126,9 @@
|
|||
onUnmounted,
|
||||
watchEffect,
|
||||
nextTick,
|
||||
watch
|
||||
watch,
|
||||
onBeforeMount,
|
||||
onBeforeUnmount
|
||||
} from 'vue';
|
||||
import {
|
||||
getTableInfo
|
||||
|
|
@ -143,26 +150,8 @@
|
|||
} from '@/stores/carts.js';
|
||||
import useWebSocket from '@/common/js/carts-websocket.js';
|
||||
const cartStore = useCartsStore()
|
||||
let cartsSocket = null
|
||||
watch(() => cartStore.goodsIsloading, (newValue) => {
|
||||
console.log('cartStore.goodsIsloading', cartStore.goodsIsloading);
|
||||
if (!newValue) {
|
||||
cartsSocket = useWebSocket(socketInitOptions);
|
||||
cartsSocket.connect();
|
||||
}
|
||||
})
|
||||
if (cartStore.goodsIsloading) {
|
||||
cartStore.goodsInit()
|
||||
} else {
|
||||
cartsSocket = useWebSocket(socketInitOptions);
|
||||
cartsSocket.connect();
|
||||
}
|
||||
|
||||
|
||||
const noPayStatus = {
|
||||
cancelled: "订单已取消",
|
||||
done: "订单已关闭",
|
||||
};
|
||||
console.log(cartStore.goodsIsloading);
|
||||
console.log(cartStore.goodsMap);
|
||||
async function onMessage(Message) {
|
||||
console.log('onMessage');
|
||||
cartStore.onMessage(Message, cartsSocket)
|
||||
|
|
@ -171,6 +160,7 @@
|
|||
youhuiReset()
|
||||
}
|
||||
if (Message.operate_type == "cleanup") {
|
||||
listinfo.totalCost = 0;
|
||||
youhuiReset()
|
||||
if (listinfo.id) {
|
||||
let res = await APIgetOrderById({
|
||||
|
|
@ -203,6 +193,38 @@
|
|||
youhuiReset()
|
||||
}
|
||||
}
|
||||
let cartsSocket = null
|
||||
const socketInitOptions = {
|
||||
initMessage: {
|
||||
type: 'shopping',
|
||||
operate_type: 'init',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
},
|
||||
onMessage
|
||||
}
|
||||
watch(() => cartStore.goodsIsloading, (newValue) => {
|
||||
console.log('cartStore.goodsIsloading', cartStore.goodsIsloading);
|
||||
if (!newValue) {
|
||||
cartsSocket = useWebSocket(socketInitOptions);
|
||||
cartsSocket.allowReconnect = true;
|
||||
cartsSocket.connect();
|
||||
}
|
||||
})
|
||||
if (cartStore.goodsIsloading) {
|
||||
cartStore.goodsInit()
|
||||
} else {
|
||||
cartsSocket = useWebSocket(socketInitOptions);
|
||||
cartsSocket.allowReconnect = true;
|
||||
cartsSocket.connect();
|
||||
}
|
||||
|
||||
|
||||
const noPayStatus = {
|
||||
cancelled: "订单已取消",
|
||||
done: "订单已关闭",
|
||||
};
|
||||
|
||||
|
||||
|
||||
function youhuiReset() {
|
||||
|
|
@ -213,15 +235,7 @@
|
|||
uniqueIds.value = []
|
||||
orderInfoAfterRef.value.IntegralInputclose();
|
||||
}
|
||||
const socketInitOptions = {
|
||||
initMessage: {
|
||||
type: 'shopping',
|
||||
operate_type: 'init',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
},
|
||||
onMessage
|
||||
}
|
||||
|
||||
|
||||
// 结账管理
|
||||
import {
|
||||
|
|
@ -743,19 +757,19 @@
|
|||
orderorderInfo()
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
uni.$off('returnData', handleReturnData);
|
||||
clearTimeout(backtimer)
|
||||
if (cartsSocket) {
|
||||
cartsSocket.closeExistingConnection()
|
||||
}
|
||||
closeSocket()
|
||||
});
|
||||
onHide(() => {
|
||||
if (cartsSocket) {
|
||||
cartsSocket.closeExistingConnection()
|
||||
}
|
||||
closeSocket()
|
||||
})
|
||||
|
||||
function closeSocket() {
|
||||
// cartsSocket.closeExistingConnection()
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
if (cartsSocket) {
|
||||
cartsSocket.connect()
|
||||
|
|
|
|||
|
|
@ -471,7 +471,8 @@
|
|||
} from "@/common/api/order/index.js";
|
||||
|
||||
// websocket
|
||||
import useWebSocket from '@/common/js/websocket.js';
|
||||
// import useWebSocket from '@/common/js/websocket.js';
|
||||
import useWebSocket from '@/common/js/carts-websocket.js';
|
||||
|
||||
// pinia管理
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -440,6 +440,7 @@ export const useCartsStore = defineStore('cart',
|
|||
carts,
|
||||
isEmpty,
|
||||
setGoodsMap,
|
||||
goodsMap,
|
||||
goodsIsloading,
|
||||
goodsInit,
|
||||
onMessage,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import {
|
|||
APIuser
|
||||
} from '@/common/api/api.js'
|
||||
import {
|
||||
APIproductqueryShop,APIusershopInfodetail,
|
||||
APIproductqueryShop,
|
||||
APIusershopInfodetail,
|
||||
APIshopUserInfo
|
||||
} from '@/common/api/member.js'
|
||||
export const Storelogin = defineStore('login', {
|
||||
|
|
@ -17,11 +18,13 @@ export const Storelogin = defineStore('login', {
|
|||
token: '',
|
||||
miniAppOpenId: '',
|
||||
userInfo: '',
|
||||
shopInfo:{}
|
||||
shopInfo: {}
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId){
|
||||
const shopRes=await APIusershopInfodetail({shopId})
|
||||
async getShopInfo(shopId) {
|
||||
const shopRes = await APIusershopInfodetail({
|
||||
shopId
|
||||
})
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
|
|
@ -104,15 +107,15 @@ export const productStore = defineStore('product', {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q)
|
||||
let tableCode =""
|
||||
let tableCode = ""
|
||||
// #ifdef MP-WEIXIN
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
tableCode = q
|
||||
tableCode = q
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
tableCode= q.tableCode
|
||||
tableCode = q.tableCode
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
|
|
@ -120,6 +123,8 @@ export const productStore = defineStore('product', {
|
|||
if (tableCode) {
|
||||
console.log(uni.cache.get('tableCode'));
|
||||
let data = await this.actionsproductqueryShop(tableCode)
|
||||
|
||||
console.log('data', data)
|
||||
// -4请求登录
|
||||
if (data.code == '500') {
|
||||
if (await this.actionslogin()) {
|
||||
|
|
@ -149,6 +154,13 @@ export const productStore = defineStore('product', {
|
|||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
if (!data) {
|
||||
uni.showToast({
|
||||
title: '店铺已过期或其他问题,请联系商家',
|
||||
icon:'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
|
|
@ -176,7 +188,7 @@ export const productStore = defineStore('product', {
|
|||
});
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
|
|
@ -184,21 +196,33 @@ export const productStore = defineStore('product', {
|
|||
actionsproductqueryShop(tableCode) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode?tableCode:uni.cache.get('tableCode'),
|
||||
})
|
||||
res.shopInfo.isVip = res.vip ? '1' : '0'
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap
|
||||
// 店铺信息
|
||||
uni.cache.set('shopTable', res.shopTable)
|
||||
// 台桌信息
|
||||
uni.cache.set('shopInfo', res.shopInfo)
|
||||
uni.cache.set('shopId', res.shopTable.shopId, 30)
|
||||
// 当前用户距离店铺的米数
|
||||
uni.cache.set('distance', res.distance)
|
||||
try {
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode ? tableCode : uni.cache.get('tableCode'),
|
||||
})
|
||||
if (res) {
|
||||
res.shopInfo.isVip = res.vip ? '1' : '0'
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap
|
||||
// 店铺信息
|
||||
uni.cache.set('shopTable', res.shopTable)
|
||||
// 台桌信息
|
||||
uni.cache.set('shopInfo', res.shopInfo)
|
||||
uni.cache.set('shopId', res.shopTable.shopId, 30)
|
||||
// 当前用户距离店铺的米数
|
||||
uni.cache.set('distance', res.distance)
|
||||
|
||||
resolve(res)
|
||||
} else {
|
||||
console.log(res)
|
||||
reject()
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject()
|
||||
//TODO handle the exception
|
||||
}
|
||||
|
||||
resolve(res)
|
||||
// } catch (e) {
|
||||
// reject(false)
|
||||
// }
|
||||
|
|
@ -214,7 +238,7 @@ export const productStore = defineStore('product', {
|
|||
uni.cache.set('shopUserInfo', res);
|
||||
uni.cache.set('orderVIP', res)
|
||||
uni.cache.set('ordershopUserInfo', res.shopInfo)
|
||||
resolve(true)
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
reject(false)
|
||||
}
|
||||
|
|
@ -226,14 +250,16 @@ export const productStore = defineStore('product', {
|
|||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = null
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get('shopId')) {
|
||||
this.actionsproductqueryProduct()
|
||||
res = await this.actionsproductqueryProduct()
|
||||
} else {
|
||||
let res = await APIuser()
|
||||
res = await APIuser()
|
||||
uni.cache.set('userInfo', res);
|
||||
}
|
||||
resolve(true)
|
||||
console.log('actionsAPIuser res', res);
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
reject(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue