fix: 代客下单优化离开代客下单页面时主动断开scoket,添加优惠券修改,修改获取优惠券记录请求方式改为get
This commit is contained in:
parent
d310638697
commit
31d451894f
|
|
@ -25,11 +25,11 @@ const API = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 店铺优惠券获取记录
|
// 店铺优惠券获取记录
|
||||||
queryReceive(data: queryReceive) {
|
queryReceive(params: queryReceive) {
|
||||||
return request({
|
return request({
|
||||||
url: `${baseURL}/queryReceive`,
|
url: `${baseURL}/queryReceive`,
|
||||||
method: "post",
|
method: "get",
|
||||||
data: data,
|
params
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 查找优惠券 生成订单后使用
|
// 查找优惠券 生成订单后使用
|
||||||
|
|
|
||||||
|
|
@ -623,6 +623,10 @@ export const useCartsStore = defineStore("carts", () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disconnect() {
|
||||||
|
sendMessage('disconnect', undefined)
|
||||||
|
}
|
||||||
|
|
||||||
const delArr = ['skuData', 'coverImg', 'specInfo', 'placeNum', 'update_time', 'create_time', 'packFee', 'memberPrice', 'type']
|
const delArr = ['skuData', 'coverImg', 'specInfo', 'placeNum', 'update_time', 'create_time', 'packFee', 'memberPrice', 'type']
|
||||||
function sendMessage(operate_type: msgType, message: any) {
|
function sendMessage(operate_type: msgType, message: any) {
|
||||||
const msg = { ...message, operate_type: operate_type, table_code: table_code.value }
|
const msg = { ...message, operate_type: operate_type, table_code: table_code.value }
|
||||||
|
|
@ -633,6 +637,7 @@ export const useCartsStore = defineStore("carts", () => {
|
||||||
WebSocketManager.sendMessage(msg);
|
WebSocketManager.sendMessage(msg);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
disconnect,
|
||||||
dinnerType,
|
dinnerType,
|
||||||
changePack,
|
changePack,
|
||||||
giftMoney,
|
giftMoney,
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,13 @@ export interface ApifoxModel {
|
||||||
[property: string]: string | number | undefined; // 限制额外属性类型
|
[property: string]: string | number | undefined; // 限制额外属性类型
|
||||||
}
|
}
|
||||||
|
|
||||||
export type msgType = 'add' | 'reduce' | 'remove' | 'edit' | 'init' | 'cleanup' | 'del' | 'rottable' | 'batch';
|
export type msgType = 'add' | 'reduce' | 'remove' | 'edit' | 'init' | 'cleanup' | 'del' | 'rottable' | 'batch' | 'disconnect';
|
||||||
|
|
||||||
class WebSocketManager {
|
class WebSocketManager {
|
||||||
private client: WebSocket | null = null;
|
private client: WebSocket | null = null;
|
||||||
private connected: boolean = false;
|
private connected: boolean = false;
|
||||||
private shop_id = user.userInfo.shopId ? String(user.userInfo.shopId) : '';
|
private shop_id = user.userInfo.shopId ? String(user.userInfo.shopId) : '';
|
||||||
|
private autoConnect: boolean = true;
|
||||||
private initParams: ApifoxModel = {
|
private initParams: ApifoxModel = {
|
||||||
type: 'manage',
|
type: 'manage',
|
||||||
account: this.shop_id || '', // 提供默认值
|
account: this.shop_id || '', // 提供默认值
|
||||||
|
|
@ -65,7 +66,9 @@ class WebSocketManager {
|
||||||
this.clearTimer();
|
this.clearTimer();
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
console.log("WebSocket 连接已断开");
|
console.log("WebSocket 连接已断开");
|
||||||
|
if (this.autoConnect) {
|
||||||
this.reconnect(); // 自动重连
|
this.reconnect(); // 自动重连
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.client.onerror = (error: Event) => {
|
this.client.onerror = (error: Event) => {
|
||||||
|
|
@ -101,6 +104,7 @@ class WebSocketManager {
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
this.setupWebSocket();
|
this.setupWebSocket();
|
||||||
this.onMessage = onMessage;
|
this.onMessage = onMessage;
|
||||||
|
this.autoConnect = true
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendMessage(message: any) {
|
public sendMessage(message: any) {
|
||||||
|
|
@ -109,7 +113,10 @@ class WebSocketManager {
|
||||||
this.reconnect();
|
this.reconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (message.operate_type == 'disconnect') {
|
||||||
|
this.disconnect();
|
||||||
|
return
|
||||||
|
}
|
||||||
const msg = JSON.stringify({ ...this.initParams, ...message });
|
const msg = JSON.stringify({ ...this.initParams, ...message });
|
||||||
try {
|
try {
|
||||||
this.client?.send(msg);
|
this.client?.send(msg);
|
||||||
|
|
@ -132,11 +139,15 @@ class WebSocketManager {
|
||||||
this.client.close();
|
this.client.close();
|
||||||
this.client = null;
|
this.client = null;
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
this.autoConnect = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自动重连机制
|
// 自动重连机制
|
||||||
private reconnect() {
|
private reconnect() {
|
||||||
|
if (!this.autoConnect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
||||||
this.reconnectAttempts++;
|
this.reconnectAttempts++;
|
||||||
console.log(`尝试第 ${this.reconnectAttempts} 次重连...`);
|
console.log(`尝试第 ${this.reconnectAttempts} 次重连...`);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
<el-form-item label="优惠券券名" prop="title" style="width: 100%">
|
<el-form-item label="优惠券券名" prop="title" style="width: 100%">
|
||||||
<el-input v-model="form.title" placeholder="" style="width: 289px" />
|
<el-input v-model="form.title" placeholder="" style="width: 289px" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item v-if="form.type == 1" label="使用门槛" prop="fullAmount">
|
<el-form-item label="使用门槛" prop="fullAmount">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="form.fullAmount"
|
v-model="form.fullAmount"
|
||||||
oninput="value= value.replace(/[^\d|\.]/g, '')"
|
oninput="value= value.replace(/[^\d|\.]/g, '')"
|
||||||
|
|
@ -300,7 +300,7 @@ export default {
|
||||||
shopId: "",
|
shopId: "",
|
||||||
type: "1",
|
type: "1",
|
||||||
title: "",
|
title: "",
|
||||||
fullAmount: null,
|
fullAmount: 0,
|
||||||
discountAmount: null,
|
discountAmount: null,
|
||||||
validityType: "fixed",
|
validityType: "fixed",
|
||||||
validStartTime: "",
|
validStartTime: "",
|
||||||
|
|
|
||||||
|
|
@ -700,6 +700,11 @@ function init() {
|
||||||
getGoods();
|
getGoods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeRouteLeave(() => {
|
||||||
|
console.log("离开");
|
||||||
|
carts.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const { id, tableCode } = route.query;
|
const { id, tableCode } = route.query;
|
||||||
if (id) {
|
if (id) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue