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({
|
||||
url: `${baseURL}/queryReceive`,
|
||||
method: "post",
|
||||
data: data,
|
||||
method: "get",
|
||||
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']
|
||||
function sendMessage(operate_type: msgType, message: any) {
|
||||
const msg = { ...message, operate_type: operate_type, table_code: table_code.value }
|
||||
|
|
@ -633,6 +637,7 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
WebSocketManager.sendMessage(msg);
|
||||
}
|
||||
return {
|
||||
disconnect,
|
||||
dinnerType,
|
||||
changePack,
|
||||
giftMoney,
|
||||
|
|
|
|||
|
|
@ -13,12 +13,13 @@ export interface ApifoxModel {
|
|||
[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 {
|
||||
private client: WebSocket | null = null;
|
||||
private connected: boolean = false;
|
||||
private shop_id = user.userInfo.shopId ? String(user.userInfo.shopId) : '';
|
||||
private autoConnect: boolean = true;
|
||||
private initParams: ApifoxModel = {
|
||||
type: 'manage',
|
||||
account: this.shop_id || '', // 提供默认值
|
||||
|
|
@ -65,7 +66,9 @@ class WebSocketManager {
|
|||
this.clearTimer();
|
||||
this.connected = false;
|
||||
console.log("WebSocket 连接已断开");
|
||||
if (this.autoConnect) {
|
||||
this.reconnect(); // 自动重连
|
||||
}
|
||||
};
|
||||
|
||||
this.client.onerror = (error: Event) => {
|
||||
|
|
@ -101,6 +104,7 @@ class WebSocketManager {
|
|||
this.disconnect();
|
||||
this.setupWebSocket();
|
||||
this.onMessage = onMessage;
|
||||
this.autoConnect = true
|
||||
}
|
||||
|
||||
public sendMessage(message: any) {
|
||||
|
|
@ -109,7 +113,10 @@ class WebSocketManager {
|
|||
this.reconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.operate_type == 'disconnect') {
|
||||
this.disconnect();
|
||||
return
|
||||
}
|
||||
const msg = JSON.stringify({ ...this.initParams, ...message });
|
||||
try {
|
||||
this.client?.send(msg);
|
||||
|
|
@ -132,11 +139,15 @@ class WebSocketManager {
|
|||
this.client.close();
|
||||
this.client = null;
|
||||
this.connected = false;
|
||||
this.autoConnect = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 自动重连机制
|
||||
private reconnect() {
|
||||
if (!this.autoConnect) {
|
||||
return;
|
||||
}
|
||||
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
||||
this.reconnectAttempts++;
|
||||
console.log(`尝试第 ${this.reconnectAttempts} 次重连...`);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
<el-form-item label="优惠券券名" prop="title" style="width: 100%">
|
||||
<el-input v-model="form.title" placeholder="" style="width: 289px" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type == 1" label="使用门槛" prop="fullAmount">
|
||||
<el-form-item label="使用门槛" prop="fullAmount">
|
||||
<el-input
|
||||
v-model="form.fullAmount"
|
||||
oninput="value= value.replace(/[^\d|\.]/g, '')"
|
||||
|
|
@ -300,7 +300,7 @@ export default {
|
|||
shopId: "",
|
||||
type: "1",
|
||||
title: "",
|
||||
fullAmount: null,
|
||||
fullAmount: 0,
|
||||
discountAmount: null,
|
||||
validityType: "fixed",
|
||||
validStartTime: "",
|
||||
|
|
|
|||
|
|
@ -700,6 +700,11 @@ function init() {
|
|||
getGoods();
|
||||
}
|
||||
|
||||
onBeforeRouteLeave(() => {
|
||||
console.log("离开");
|
||||
carts.disconnect();
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const { id, tableCode } = route.query;
|
||||
if (id) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue