From a65b0e83b177663f04e72b865402920c35bdc1bb Mon Sep 17 00:00:00 2001
From: YeMingfei666 <1619116647@qq.com>
Date: Fri, 5 Dec 2025 19:19:44 +0800
Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E9=97=AE=E9=A2=98=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8D=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
http/api/market/chat.js | 10 ++
http/php/chat.js | 7 +-
pageChat/chat.vue | 113 ++++++++++++--------
pageChat/coupon-activity/detail.vue | 106 +++++++++++++------
pageChat/group-info/index.vue | 74 +++++++++++--
pageChat/index.vue | 131 ++++++++++++++---------
store/chat.js | 159 +++++++++++++++++++++++-----
7 files changed, 438 insertions(+), 162 deletions(-)
diff --git a/http/api/market/chat.js b/http/api/market/chat.js
index ab9f423..af92e73 100644
--- a/http/api/market/chat.js
+++ b/http/api/market/chat.js
@@ -43,3 +43,13 @@ export function chatCouponRecord(params) {
params,
});
}
+
+export function deleteRecord(params) {
+ return request({
+ url: urlType + `/admin/coupon/deleteRecord?id=`+params.id,
+ method: "delete",
+ params,
+ });
+}
+
+
diff --git a/http/php/chat.js b/http/php/chat.js
index e9933a4..7e53678 100644
--- a/http/php/chat.js
+++ b/http/php/chat.js
@@ -84,4 +84,9 @@ export const messageSessionList = (data) => {
export const groupDoNotDisturb = (data) => {
return request(prveUrl + "group/do-not-disturb", "POST", data, true);
-};
\ No newline at end of file
+};
+
+export const groupEditTitle = (data) => {
+ return request(prveUrl + "group/editTitle", "POST", data, true);
+};
+
diff --git a/pageChat/chat.vue b/pageChat/chat.vue
index b7971f7..43de208 100644
--- a/pageChat/chat.vue
+++ b/pageChat/chat.vue
@@ -5,7 +5,7 @@
{{ groupInfo.name }}
- ({{membersRes.user_list.length}}人)
+ ({{ membersRes.user_list.length }}人)
@@ -36,7 +36,11 @@
>
@@ -50,8 +54,11 @@
>
-
- {{item.hasGet||0}}人已领取
+
+ {{ item.hasGet || 0 }}人已领取
优惠券
@@ -73,7 +80,7 @@
bg-color="#fff"
>
- {{ item.nick_name }}
+ {{ item.nick }}
@@ -149,6 +156,7 @@
v-model="modalData.form.title"
placeholder="请输入自定义文案"
:placeholderStyle="placeholderStyle"
+ maxlength="12"
>
发放数量(张)
@@ -161,6 +169,7 @@
每人限领量(张)
@@ -174,13 +183,15 @@
import {
onReady,
onReachBottom,
- onLoad,onShow,
+ onLoad,
+ onShow,
onPageScroll,
} from "@dcloudio/uni-app";
import {
ref,
inject,
onMounted,
+ onUnmounted,
nextTick,
reactive,
watch,
@@ -205,7 +216,6 @@ function refresherrefresh() {
if (isLoading.value || isEnd.value) {
scrollView.refresherTriggered = false; // 立即关闭刷新状态
if (isEnd.value) {
- uni.showToast({ title: "没有更多了", icon: "none" });
}
return; // 终止后续逻辑
}
@@ -236,13 +246,16 @@ const modalData = reactive({
},
});
-
const chatStore = useChatStore();
-chatStore.onReceiveMsg = (msg) => {
+
+const handleReceiveMsg = (msg) => {
nextTick(() => {
scrollView.intoView = "msg-0";
});
};
+
+// 注册消息回调
+chatStore.registerReceiveMsgCallback(handleReceiveMsg);
const msg = ref("");
const shopInfo = uni.getStorageSync("shopInfo");
@@ -280,7 +293,6 @@ function moreBtnsClick(item, index) {
function videoErrorCallback(e) {
console.error("视频播放失败", e);
}
-// 图片选择与发送优化
async function sendImg() {
try {
// 1. 调用图片选择API,添加fail回调
@@ -290,7 +302,7 @@ async function sendImg() {
sizeType: ["original", "compressed"],
sourceType: ["album", "camera"],
success: resolve,
- fail: reject // 捕获选择失败(含权限拒绝)
+ fail: reject, // 捕获选择失败(含权限拒绝)
});
});
@@ -327,7 +339,7 @@ async function sendVideo() {
sizeType: ["original", "compressed"],
sourceType: ["album", "camera"],
success: resolve,
- fail: reject // 捕获选择失败(含权限拒绝)
+ fail: reject, // 捕获选择失败(含权限拒绝)
});
});
@@ -365,8 +377,8 @@ function handlePermissionError(err, mediaType) {
"auth deny",
"permission denied",
"auth denied",
- "用户拒绝"
- ].some(keyword => errMsg.includes(keyword));
+ "用户拒绝",
+ ].some((keyword) => errMsg.includes(keyword));
if (isAuthDenied) {
// 弹窗提示用户,并引导至设置页
@@ -382,17 +394,17 @@ function handlePermissionError(err, mediaType) {
success: (settingRes) => {
console.log("设置页返回结果", settingRes);
// 可根据需要添加权限开启后的回调逻辑
- }
+ },
});
}
- }
+ },
});
} else {
// 其他错误(如取消选择),仅轻提示
if (!errMsg.includes("cancel")) {
uni.showToast({
title: `${mediaType}选择失败`,
- icon: "none"
+ icon: "none",
});
}
}
@@ -405,6 +417,14 @@ async function init() {
});
console.log(res);
groupInfo.value = res || {};
+ if (res) {
+ chatStore.connectSocket();
+ // 确保状态监听已初始化
+ if (!chatStore._listenersInitialized) {
+ chatStore.initStateListeners();
+ chatStore._listenersInitialized = true;
+ }
+ }
getMsgList();
}
const query = reactive({
@@ -458,36 +478,33 @@ async function getMsgList() {
}
const options = reactive({});
-const membersRes=reactive({
- user_list:[]
-})
+const membersRes = reactive({
+ user_list: [],
+});
onLoad((opt) => {
Object.assign(options, opt);
init();
chatApi.messageMarkReadAll({
- session_ids: options.session_id,
+ session_ids: options.group_id,
});
+ chatStore.group_id = options.group_id;
chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
console.log(res);
- membersRes.user_list=res.user_list||[]
- })
+ membersRes.user_list = res.user_list || [];
+ });
// #ifdef H5
scrollView.safeAreaHeight = uni.getSystemInfoSync().safeArea.height;
// #endif
});
-onMounted(() => {
- chatStore.connectSocket();
- // 确保状态监听已初始化
- if (!chatStore._listenersInitialized) {
- chatStore.initStateListeners();
- chatStore._listenersInitialized = true;
+onShow(() => {
+ // 页面显示时,检查连接状态
+ if (!chatStore.isConnect || !chatStore.socketTask) {
+ console.log("聊天页显示,检查Socket连接");
+ chatStore.forceReconnect();
}
});
-onShow(() => {
-});
-
function toMore() {
go.to("PAGES_CHAT_GROUP_INFO", {
group_id: groupInfo.value.id,
@@ -508,7 +525,7 @@ function sendMsg(msg) {
content: msg.value,
image_url: "",
order_id: "",
- session_id: groupInfo.value.session_id||options.session_id,
+ session_id: groupInfo.value.session_id || options.session_id,
...msg,
});
}
@@ -522,13 +539,13 @@ function closeModal() {
}
function confirmCoupon() {
console.log(modalData.form);
- if (!modalData.form.title) {
- uni.showToast({
- title: "请输入自定义文案",
- icon: "none",
- });
- return;
- }
+ // if (!modalData.form.title) {
+ // uni.showToast({
+ // title: "请输入自定义文案",
+ // icon: "none",
+ // });
+ // return;
+ // }
if (!modalData.form.couponId) {
uni.showToast({
title: "请选择优惠券",
@@ -556,10 +573,15 @@ function confirmCoupon() {
modalData.show = false;
const couponJson = JSON.parse(res.couponJson);
sendMsg({
- coupon: { ...couponJson, title: modalData.form.title,activity_id:res.id },
- chat_coupon_id:res.id,
+ coupon: {
+ ...couponJson,
+ title: modalData.form.title,
+ activity_id: res.id,
+ },
+ chat_coupon_id: res.id,
msg_type: 4,
});
+ closeModal();
} else {
uni.showToast({
title: "发送失败",
@@ -607,6 +629,11 @@ const pageHeight = computed(() => {
}
return "";
});
+
+onUnmounted(() => {
+ // 组件卸载时,移除消息回调
+ chatStore.removeReceiveMsgCallback(handleReceiveMsg);
+});
diff --git a/pageChat/group-info/index.vue b/pageChat/group-info/index.vue
index 7bc5124..e3f996a 100644
--- a/pageChat/group-info/index.vue
+++ b/pageChat/group-info/index.vue
@@ -2,7 +2,7 @@
- 群成员({{allUser.length}}人)
+ 群成员({{ allUser.length }}人)
移除
@@ -17,7 +17,9 @@
:src="item.avatar"
round="8rpx"
>
- {{ item.nick_name }}
+ {{
+ item.nick_name
+ }}
-
+
群聊名称
{{ groupInfo.name }}
@@ -77,6 +82,17 @@
+
+
+
+ 群名称
+
+
+