增加分享优惠券功能

This commit is contained in:
2025-12-04 10:03:35 +08:00
parent f86048bbc0
commit 1b58014462
5 changed files with 135 additions and 20 deletions

View File

@@ -15,9 +15,7 @@ export const useChatStore = defineStore("chat", {
socketUrl,
isConnect: false,
socketTask: null,
onReceiveMsg:()=>{
},
onReceiveMsg: () => {},
chatList: [],
};
},
@@ -83,20 +81,35 @@ export const useChatStore = defineStore("chat", {
this.socketTask.onMessage((res) => {
const data = JSON.parse(res.data);
console.log("收到服务器消息", data);
if(data.msg){
if (data.msg) {
uni.showToast({
title: data.msg,
icon: "none",
});
}
if(data&&data.operate_type=="sendMsg"){
if (data && data.operate_type == "sendMsg") {
this.chatList.unshift(data.data);
this.onReceiveMsg(data.data);
console.log(this.chatList);
}
});
this.socketTask.onError((res) => {
this.isConnect = false;
console.log("连接错误", res);
});
this.socketTask.onClose(() => {
this.isConnect = false;
console.log("连接已关闭");
this.connectSocket();
});
},
closeSocket() {
this.socketTask.close();
this.isConnect = false;
},
},
unistorage: false, // 开启后对 state 的数据读写都将持久化