This commit is contained in:
gyq
2025-12-06 17:14:19 +08:00
7 changed files with 726 additions and 375 deletions

View File

@@ -43,3 +43,13 @@ export function chatCouponRecord(params) {
params, params,
}); });
} }
export function deleteRecord(params) {
return request({
url: urlType + `/admin/coupon/deleteRecord?id=`+params.id,
method: "delete",
params,
});
}

View File

@@ -84,4 +84,9 @@ export const messageSessionList = (data) => {
export const groupDoNotDisturb = (data) => { export const groupDoNotDisturb = (data) => {
return request(prveUrl + "group/do-not-disturb", "POST", data, true); return request(prveUrl + "group/do-not-disturb", "POST", data, true);
}; };
export const groupEditTitle = (data) => {
return request(prveUrl + "group/editTitle", "POST", data, true);
};

View File

@@ -1,72 +1,104 @@
<template> <template>
<view class="min-page bg-f7 u-font-28 color-333" :style="pageHeight"> <view class="min-page bg-f7 u-font-28 color-333" :style="pageHeight">
<view class="top u-flex u-row-between"> <view class="top u-flex u-row-between">
<view> <view>
<text style="max-width: 286rpx" class="u-line-1 u-font-32"> <text style="max-width: 286rpx" class="u-line-1 u-font-32">
{{ groupInfo.name }} {{ groupInfo.name }}
</text> </text>
<text class="u-m-l-22">{{ membersRes.user_list.length }}</text> <text class="u-m-l-22">{{ membersRes.user_list.length }}</text>
</view> </view>
<view class="" @click="toMore()"> <view class="" @click="toMore()">
<view class="u-flex u-row-center"> <view class="u-flex u-row-center">
<up-icon name="more-dot-fill" color="#333" size="14"></up-icon> <up-icon name="more-dot-fill" color="#333" size="14"></up-icon>
</view> </view>
<view class="color-666">更多</view> <view class="color-666">更多</view>
</view> </view>
</view> </view>
<view class="box-1"> <view class="box-1">
<!-- @refresherrefresh="refresherrefresh" --> <!-- @refresherrefresh="refresherrefresh" -->
<scroll-view <scroll-view
scroll-y scroll-y
refresher-background="transparent" refresher-background="transparent"
style="height: 100%" style="height: 100%"
@scrolltoupper="refresherrefresh" @scrolltoupper="refresherrefresh"
:refresher-enabled="false" :refresher-enabled="false"
:scroll-with-animation="false" :scroll-with-animation="false"
:refresher-triggered="scrollView.refresherTriggered" :refresher-triggered="scrollView.refresherTriggered"
:scroll-into-view="scrollView.intoView" :scroll-into-view="scrollView.intoView"
> >
<view class="scroll-view-box"> <view class="scroll-view-box">
<view class="talk-list"> <view class="talk-list">
<view :id="'msg-' + index" v-for="(item, index) in chatStore.chatList" :key="index"> <view
<!-- 发消息 --> :id="'msg-' + index"
<template v-if="item.operate_type == 'sendMsg' || item.is_user_send == 1"> v-for="(item, index) in chatStore.chatList"
<view class="shop u-flex u-row-right"> :key="index"
<view class="u-p-r-18"> >
<view class="u-flex u-row-right name-wrap"> <!-- 发消息 -->
<view class="tag">商家</view> <template
<view class="name">{{ shopInfo.shopName }}</view> v-if="
</view> item.operate_type == 'sendMsg' ||
<view class="u-m-t-14 msg" :class="['type' + item.msg_type]"> item.is_user_send == 1 ||
<chatItem :item="item"></chatItem> item.from_id == shopInfo.id
</view> "
<view class="text-center u-m-t-20" v-if="item.msg_type == 4 && item.hasGet"> >
<text>{{ item.hasGet || 0 }}人已领取</text> <view class="shop u-flex u-row-right">
<text class="color-main">优惠券</text> <view class="u-p-r-18">
</view> <view class="u-flex u-row-right">
</view> <view class="tag">商家</view>
<up-avatar size="70rpx" shape="square" bg-color="#fff" :src="shopInfo.logo"></up-avatar> <view class="color-000">{{ shopInfo.shopName }}</view>
</view> </view>
</template> <view
<!-- 收消息 --> class="u-m-t-14 msg"
<template v-else> :class="['type' + item.msg_type]"
<view class="user u-flex"> >
<up-avatar size="70rpx" :src="item.avatar" shape="square" bg-color="#fff"></up-avatar> <chatItem :item="item"></chatItem>
<view class="u-p-l-18"> </view>
<view class="u-line-1 name">{{ item.nick_name }}</view> <view
<view class="u-m-t-14 msg u-p-l-30" :class="['type' + item.msg_type]"> class="text-center u-m-t-20"
<chatItem :item="item"></chatItem> v-if="item.msg_type == 4 && item.hasGet"
</view> >
</view> <text>{{ item.hasGet || 0 }}人已领取</text>
</view> <text class="color-main">优惠券</text>
</template> </view>
</view> </view>
</view> <up-avatar
<up-loadmore v-if="isEnd" :status="isEnd ? 'nomore' : 'loading'"></up-loadmore> size="122rpx"
</view> shape="square"
</scroll-view> bg-color="#fff"
</view> :src="shopInfo.logo"
></up-avatar>
</view>
</template>
<!-- 收消息 -->
<template v-else>
<view class="user u-flex">
<up-avatar
size="122rpx"
:src="item.avatar"
shape="square"
bg-color="#fff"
></up-avatar>
<view class="u-p-l-18">
<view class="color-000 u-line-1">{{ item.nick }}</view>
<view
class="u-m-t-14 msg u-p-l-30"
:class="['type' + item.msg_type]"
>
<chatItem :item="item"></chatItem>
</view>
</view>
</view>
</template>
</view>
</view>
<up-loadmore
v-if="isEnd"
:status="isEnd ? 'nomore' : 'loading'"
></up-loadmore>
</view>
</scroll-view>
</view>
<!-- <view :style="bottomSlotHeight"></view> --> <!-- <view :style="bottomSlotHeight"></view> -->
@@ -78,65 +110,111 @@
placeholder="请输入内容" placeholder="请输入内容"
v-model="msg" v-model="msg"
/> --> /> -->
<view class="u-flex-1 u-m-r-52 iput"> <view class="u-flex-1 u-m-r-52 iput">
<up-input v-model="msg" border="none" placeholder="请输入内容"></up-input> <up-input
</view> v-model="msg"
<button class="send-btn" v-if="msg.trim().length > 0" @click="sendText">发送</button> border="none"
<up-icon name="plus-circle" color="#666" size="40rpx" @click="showMoreBtnToggle" v-else></up-icon> placeholder="请输入内容"
</view> ></up-input>
<view class="more-btn" v-if="showMoreBtn"> </view>
<view v-for="(item, index) in moreBtns" @click="moreBtnsClick(item, index)" class="u-flex-col u-row-center u-col-center"> <button class="send-btn" v-if="msg.trim().length > 0" @click="sendText">
<view class="u-flex icon"> 发送
<image :src="item.icon" class="img" mode="aspectFill"></image> </button>
</view> <up-icon
<view class="u-m-t-8">{{ item.title }}</view> name="plus-circle"
</view> color="#666"
</view> size="60rpx"
</view> @click="showMoreBtnToggle"
v-else
></up-icon>
</view>
<view class="more-btn" v-if="showMoreBtn">
<view
v-for="(item, index) in moreBtns"
@click="moreBtnsClick(item, index)"
class="u-flex-col u-row-center u-col-center"
>
<view class="u-flex icon">
<image :src="item.icon" class="img" mode="aspectFill"></image>
</view>
<view class="u-m-t-8">{{ item.title }}</view>
</view>
</view>
</view>
<!-- 发送优惠券 --> <!-- 发送优惠券 -->
<Modal title="发送优惠券" v-model="modalData.show" confirmText="确认发送" @close="closeModal" @confirm="confirmCoupon"> <Modal
<view class="u-p-30"> title="发送优惠券"
<view class="font-bold u-m-b-16">自定义文案</view> v-model="modalData.show"
<up-input v-model="modalData.form.title" placeholder="请输入自定义文案" :placeholderStyle="placeholderStyle"></up-input> confirmText="确认发送"
<view class="font-bold u-m-b-16 u-m-t-32">发放数量()</view> @close="closeModal"
@confirm="confirmCoupon"
>
<view class="u-p-30">
<view class="font-bold u-m-b-16">自定义文案</view>
<up-input
v-model="modalData.form.title"
placeholder="请输入自定义文案"
:placeholderStyle="placeholderStyle"
maxlength="12"
></up-input>
<view class="font-bold u-m-b-16 u-m-t-32">发放数量(张)</view>
<up-number-box v-model="modalData.form.giveNum" inputWidth="240rpx" @change="valChange"></up-number-box> <up-number-box v-model="modalData.form.giveNum" inputWidth="240rpx" @change="valChange"></up-number-box>
<view class="font-bold u-m-b-16 u-m-t-32">每人限领量()</view> <view class="font-bold u-m-b-16 u-m-t-32">每人限领量(张)</view>
<up-number-box v-model="modalData.form.getLimit" inputWidth="240rpx" @change="valChange"></up-number-box> <up-number-box
<view class="font-bold u-m-b-16 u-m-t-32">选择优惠券</view> v-model="modalData.form.getLimit"
<chooseCoupon v-model="modalData.form.couponId"></chooseCoupon> :max="modalData.form.giveNum"
</view> inputWidth="240rpx"
</Modal> @change="valChange"
</view> ></up-number-box>
<view class="font-bold u-m-b-16 u-m-t-32">选择优惠券</view>
<chooseCoupon v-model="modalData.form.couponId"></chooseCoupon>
</view>
</Modal>
</view>
</template> </template>
<script setup> <script setup>
import { onReady, onReachBottom, onLoad, onShow, onPageScroll } from '@dcloudio/uni-app'; import {
import { ref, inject, onMounted, nextTick, reactive, watch, computed } from 'vue'; onReady,
import { useChatStore } from '@/store/chat'; onReachBottom,
import * as chatApi from '@/http/php/chat'; onLoad,
import * as chatCouponApi from '@/http/api/market/chat'; onShow,
import { uploadFile } from '@/http/api/index.js'; onPageScroll,
import go from '@/commons/utils/go.js'; } from "@dcloudio/uni-app";
import Modal from './components/modal.vue'; import {
import chooseCoupon from './components/coupon.vue'; ref,
import chatItem from './components/chat-item.vue'; inject,
onMounted,
onUnmounted,
nextTick,
reactive,
watch,
computed,
} from "vue";
import { useChatStore } from "@/store/chat";
import * as chatApi from "@/http/php/chat";
import * as chatCouponApi from "@/http/api/market/chat";
import { uploadFile } from "@/http/api/index.js";
import go from "@/commons/utils/go.js";
import Modal from "./components/modal.vue";
import chooseCoupon from "./components/coupon.vue";
import chatItem from "./components/chat-item.vue";
const placeholderStyle = { const placeholderStyle = {
color: '#999', color: '#999',
fontSize: '28rpx' fontSize: '28rpx'
}; };
function refresherrefresh() { function refresherrefresh() {
console.log('refresherrefresh'); console.log("refresherrefresh");
// 关键:同时判断「正在加载」和「无更多数据」,只要一个为真就关闭刷新 // 关键:同时判断「正在加载」和「无更多数据」,只要一个为真就关闭刷新
if (isLoading.value || isEnd.value) { if (isLoading.value || isEnd.value) {
scrollView.refresherTriggered = false; // 立即关闭刷新状态 scrollView.refresherTriggered = false; // 立即关闭刷新状态
if (isEnd.value) { if (isEnd.value) {
uni.showToast({ title: '没有更多了', icon: 'none' }); }
} return; // 终止后续逻辑
return; // 终止后续逻辑 }
}
query.page++; query.page++;
getMsgList(); getMsgList();
@@ -165,12 +243,16 @@ const modalData = reactive({
}); });
const chatStore = useChatStore(); const chatStore = useChatStore();
chatStore.onReceiveMsg = (msg) => {
nextTick(() => { const handleReceiveMsg = (msg) => {
scrollView.intoView = 'msg-0'; nextTick(() => {
}); scrollView.intoView = "msg-0";
});
}; };
const msg = ref('');
// 注册消息回调
chatStore.registerReceiveMsgCallback(handleReceiveMsg);
const msg = ref("");
const shopInfo = uni.getStorageSync('shopInfo'); const shopInfo = uni.getStorageSync('shopInfo');
@@ -207,19 +289,18 @@ function moreBtnsClick(item, index) {
function videoErrorCallback(e) { function videoErrorCallback(e) {
console.error('视频播放失败', e); console.error('视频播放失败', e);
} }
// 图片选择与发送优化
async function sendImg() { async function sendImg() {
try { try {
// 1. 调用图片选择API添加fail回调 // 1. 调用图片选择API添加fail回调
const res = await new Promise((resolve, reject) => { const res = await new Promise((resolve, reject) => {
uni.chooseImage({ uni.chooseImage({
count: 3, count: 3,
sizeType: ['original', 'compressed'], sizeType: ["original", "compressed"],
sourceType: ['album', 'camera'], sourceType: ["album", "camera"],
success: resolve, success: resolve,
fail: reject // 捕获选择失败(含权限拒绝) fail: reject, // 捕获选择失败(含权限拒绝)
}); });
}); });
uni.showLoading({ title: '发送中' }); uni.showLoading({ title: '发送中' });
console.log('选择图片成功', res); console.log('选择图片成功', res);
@@ -246,17 +327,17 @@ async function sendImg() {
// 视频选择与发送优化 // 视频选择与发送优化
async function sendVideo() { async function sendVideo() {
try { try {
// 1. 调用视频选择API添加fail回调 // 1. 调用视频选择API添加fail回调
const res = await new Promise((resolve, reject) => { const res = await new Promise((resolve, reject) => {
uni.chooseVideo({ uni.chooseVideo({
count: 1, count: 1,
sizeType: ['original', 'compressed'], sizeType: ["original", "compressed"],
sourceType: ['album', 'camera'], sourceType: ["album", "camera"],
success: resolve, success: resolve,
fail: reject // 捕获选择失败(含权限拒绝) fail: reject, // 捕获选择失败(含权限拒绝)
}); });
}); });
uni.showLoading({ title: '发送中' }); uni.showLoading({ title: '发送中' });
console.log('选择视频成功', res); console.log('选择视频成功', res);
@@ -286,48 +367,61 @@ async function sendVideo() {
// 通用权限错误处理函数 // 通用权限错误处理函数
function handlePermissionError(err, mediaType) { function handlePermissionError(err, mediaType) {
const errMsg = err.errMsg || ''; const errMsg = err.errMsg || "";
// 识别权限拒绝关键词(兼容不同平台) // 识别权限拒绝关键词(兼容不同平台)
const isAuthDenied = ['auth deny', 'permission denied', 'auth denied', '用户拒绝'].some((keyword) => errMsg.includes(keyword)); const isAuthDenied = [
"auth deny",
"permission denied",
"auth denied",
"用户拒绝",
].some((keyword) => errMsg.includes(keyword));
if (isAuthDenied) { if (isAuthDenied) {
// 弹窗提示用户,并引导至设置页 // 弹窗提示用户,并引导至设置页
uni.showModal({ uni.showModal({
title: '权限提示', title: "权限提示",
content: `需要${mediaType}权限才能使用该功能,请前往设置开启`, content: `需要${mediaType}权限才能使用该功能,请前往设置开启`,
confirmText: '去设置', confirmText: "去设置",
cancelText: '取消', cancelText: "取消",
success: (modalRes) => { success: (modalRes) => {
if (modalRes.confirm) { if (modalRes.confirm) {
// 跳转到小程序设置页 // 跳转到小程序设置页
uni.openSetting({ uni.openSetting({
success: (settingRes) => { success: (settingRes) => {
console.log('设置页返回结果', settingRes); console.log("设置页返回结果", settingRes);
// 可根据需要添加权限开启后的回调逻辑 // 可根据需要添加权限开启后的回调逻辑
} },
}); });
} }
} },
}); });
} else { } else {
// 其他错误(如取消选择),仅轻提示 // 其他错误(如取消选择),仅轻提示
if (!errMsg.includes('cancel')) { if (!errMsg.includes("cancel")) {
uni.showToast({ uni.showToast({
title: `${mediaType}选择失败`, title: `${mediaType}选择失败`,
icon: 'none' icon: "none",
}); });
} }
} }
} }
const groupInfo = ref({}); const groupInfo = ref({});
async function init() { async function init() {
const res = await chatApi.groupInfo({ const res = await chatApi.groupInfo({
group_id: options.group_id group_id: options.group_id,
}); });
console.log(res); console.log(res);
groupInfo.value = res || {}; groupInfo.value = res || {};
getMsgList(); if (res) {
chatStore.connectSocket();
// 确保状态监听已初始化
if (!chatStore._listenersInitialized) {
chatStore.initStateListeners();
chatStore._listenersInitialized = true;
}
}
getMsgList();
} }
const query = reactive({ const query = reactive({
page: 1, page: 1,
@@ -381,34 +475,32 @@ async function getMsgList() {
const options = reactive({}); const options = reactive({});
const membersRes = reactive({ const membersRes = reactive({
user_list: [] user_list: [],
}); });
onLoad((opt) => { onLoad((opt) => {
Object.assign(options, opt); Object.assign(options, opt);
init(); init();
chatApi.messageMarkReadAll({ chatApi.messageMarkReadAll({
session_ids: options.session_id session_ids: options.group_id,
}); });
chatApi.groupMembers({ group_id: options.group_id }).then((res) => { chatStore.group_id = options.group_id;
console.log(res); chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
membersRes.user_list = res.user_list || []; console.log(res);
}); membersRes.user_list = res.user_list || [];
// #ifdef H5 });
scrollView.safeAreaHeight = uni.getSystemInfoSync().safeArea.height; // #ifdef H5
// #endif scrollView.safeAreaHeight = uni.getSystemInfoSync().safeArea.height;
// #endif
}); });
onMounted(() => { onShow(() => {
chatStore.connectSocket(); // 页面显示时,检查连接状态
// 确保状态监听已初始化 if (!chatStore.isConnect || !chatStore.socketTask) {
if (!chatStore._listenersInitialized) { console.log("聊天页显示检查Socket连接");
chatStore.initStateListeners(); chatStore.forceReconnect();
chatStore._listenersInitialized = true; }
}
}); });
onShow(() => {});
function toMore() { function toMore() {
go.to('PAGES_CHAT_GROUP_INFO', { go.to('PAGES_CHAT_GROUP_INFO', {
group_id: groupInfo.value.id, group_id: groupInfo.value.id,
@@ -422,16 +514,16 @@ function sendText() {
} }
function sendMsg(msg) { function sendMsg(msg) {
chatStore.sendMessage({ chatStore.sendMessage({
to_id: groupInfo.value.id, to_id: groupInfo.value.id,
to_user_type: groupInfo.value.id, to_user_type: groupInfo.value.id,
chat_type: 2, chat_type: 2,
content: msg.value, content: msg.value,
image_url: '', image_url: "",
order_id: '', order_id: "",
session_id: groupInfo.value.session_id || options.session_id, session_id: groupInfo.value.session_id || options.session_id,
...msg ...msg,
}); });
} }
function closeModal() { function closeModal() {
modalData.form = { modalData.form = {
@@ -442,52 +534,57 @@ function closeModal() {
}; };
} }
function confirmCoupon() { function confirmCoupon() {
console.log(modalData.form); console.log(modalData.form);
if (!modalData.form.title) { // if (!modalData.form.title) {
uni.showToast({ // uni.showToast({
title: '请输入自定义文案', // title: "请输入自定义文案",
icon: 'none' // icon: "none",
}); // });
return; // return;
} // }
if (!modalData.form.couponId) { if (!modalData.form.couponId) {
uni.showToast({ uni.showToast({
title: '请选择优惠券', title: "请选择优惠券",
icon: 'none' icon: "none",
}); });
return; return;
} }
if (!modalData.form.giveNum) { if (!modalData.form.giveNum) {
uni.showToast({ uni.showToast({
title: '请输入发放数量', title: "请输入发放数量",
icon: 'none' icon: "none",
}); });
return; return;
} }
if (!modalData.form.getLimit) { if (!modalData.form.getLimit) {
uni.showToast({ uni.showToast({
title: '请输入每人限领量', title: "请输入每人限领量",
icon: 'none' icon: "none",
}); });
return; return;
} }
chatCouponApi.chatCouponCreate(modalData.form).then((res) => { chatCouponApi.chatCouponCreate(modalData.form).then((res) => {
if (res) { if (res) {
modalData.show = false; modalData.show = false;
const couponJson = JSON.parse(res.couponJson); const couponJson = JSON.parse(res.couponJson);
sendMsg({ sendMsg({
coupon: { ...couponJson, title: modalData.form.title, activity_id: res.id }, coupon: {
chat_coupon_id: res.id, ...couponJson,
msg_type: 4 title: modalData.form.title,
}); activity_id: res.id,
} else { },
uni.showToast({ chat_coupon_id: res.id,
title: '发送失败', msg_type: 4,
icon: 'none' });
}); closeModal();
} } else {
}); uni.showToast({
title: "发送失败",
icon: "none",
});
}
});
} }
function previewImage(url) { function previewImage(url) {
@@ -528,6 +625,11 @@ const pageHeight = computed(() => {
} }
return ''; return '';
}); });
onUnmounted(() => {
// 组件卸载时,移除消息回调
chatStore.removeReceiveMsgCallback(handleReceiveMsg);
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.top { .top {

View File

@@ -41,20 +41,29 @@
</view> </view>
<view class="u-m-t-32 table bg-fff"> <view class="u-m-t-32 table bg-fff">
<view class="header"> <view class="header">
<view class="user">用户</view> <view class="user">用户</view>
<view class="gettime">领取时间</view> <view class="gettime">领取时间</view>
<view class="usetime">使用时间</view> <view class="usetime">使用时间</view>
<view class="status">状态</view> <view class="status">状态</view>
<view class="operation">操作</view> <view class="operation">操作</view>
</view> </view>
<view class="body"> <view class="body">
<view class="item" v-for="(item,index) in 10" :key="index"> <view class="item" v-for="(item, index) in list" :key="index">
<view class="user">用户昵称40239</view> <view class="user">
<view class="gettime">2025/06/27 20:07:18</view> <view>
<view class="usetime">2025/01/15 08:02:38</view> {{ item.nickName }}
<view class="status">已使用</view> </view>
<view class="operation status3">失效</view> <view> ({{ item.shopUserId }}) </view>
</view>
<view class="gettime">{{ item.createTime }}</view>
<view class="usetime">{{ item.useTime }}</view>
<view class="status">{{ returnStatus(item.status) }}</view>
<view class="operation status3">
<text v-if="item.status == 0" @click="deleteRecord(item)"
>失效</text
></view
>
</view> </view>
</view> </view>
</view> </view>
@@ -70,12 +79,49 @@ import { reactive, ref, watch } from "vue";
import { onShow } from "@dcloudio/uni-app"; import { onShow } from "@dcloudio/uni-app";
import go from "@/commons/utils/go.js"; import go from "@/commons/utils/go.js";
import * as chatCouponApi from "@/http/api/market/chat"; import * as chatCouponApi from "@/http/api/market/chat";
function deleteRecord(item) {
uni
.showModal({
title: "提示",
content: "确定要让该记录失效吗?",
})
.then((res) => {
if (res.confirm) {
chatCouponApi
.deleteRecord({
id: item.id,
})
.then((res) => {
uni.showToast({
title: "操作成功",
icon: "none",
});
setTimeout(() => {
refresh();
}, 1000);
});
}
});
}
const statusOptions = ref([ const statusOptions = ref([
{ label: "全部", value: "" }, { label: "全部", value: "" },
{ label: "未使用", value: 0 }, { label: "未使用", value: 0 },
{ label: "已使用", value: 1 }, { label: "已使用", value: 1 },
{ label: "已过期", value: 2 }, { label: "已过期", value: 2 },
]); ]);
function returnStatus(status) {
if (status == 0) {
return "未使用";
}
if (status == 1) {
return "已使用";
}
if (status == 2) {
return "已过期";
}
}
const selStatus = ref(""); const selStatus = ref("");
const query = reactive({ const query = reactive({
page: 1, page: 1,
@@ -146,39 +192,39 @@ onLoad((opt) => {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
.table{ .table {
.user{ .user {
width: 142rpx; width: 142rpx;
} }
.gettime{ .gettime {
width: 172rpx; width: 172rpx;
} }
.usetime{ .usetime {
width: 158rpx; width: 158rpx;
} }
.status{ .status {
width: 84rpx; width: 84rpx;
} }
.operation{ .operation {
width: 56rpx; width: 56rpx;
&.status3{ &.status3 {
color: #FF383C; color: #ff383c;
} }
} }
.header{ .header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 32rpx 16rpx; padding: 32rpx 16rpx;
color: #666; color: #666;
border-bottom: 1px solid #E5E5E5; border-bottom: 1px solid #e5e5e5;
} }
.body{ .body {
.item{ .item {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 24rpx 16rpx; padding: 24rpx 16rpx;
border-bottom: 1px solid #E5E5E5; border-bottom: 1px solid #e5e5e5;
}
} }
}
} }
</style> </style>

View File

@@ -2,7 +2,7 @@
<view class="min-page bg-f7 u-font-28"> <view class="min-page bg-f7 u-font-28">
<view class="user-list bg-fff"> <view class="user-list bg-fff">
<view class="u-flex u-row-between u-col-center"> <view class="u-flex u-row-between u-col-center">
<text class="color-000">群成员{{allUser.length}}</text> <text class="color-000">群成员{{ allUser.length }}</text>
<text class="color-red" @click="showRemove = !showRemove">移除</text> <text class="color-red" @click="showRemove = !showRemove">移除</text>
</view> </view>
<view class="list u-m-t-26"> <view class="list u-m-t-26">
@@ -17,7 +17,9 @@
:src="item.avatar" :src="item.avatar"
round="8rpx" round="8rpx"
></up-avatar> ></up-avatar>
<view class="u-m-t-8 color-000 u-line-1" style="max-width: 104rpx;">{{ item.nick_name }}</view> <view class="u-m-t-8 color-000 u-line-1" style="max-width: 104rpx">{{
item.nick_name
}}</view>
<view <view
class="remove u-absolute" class="remove u-absolute"
v-if="showRemove && item.role != 1" v-if="showRemove && item.role != 1"
@@ -40,7 +42,10 @@
</view> </view>
<view class="bottom"> <view class="bottom">
<view class="u-flex u-row-between default-padding bg-fff border-bottom"> <view
class="u-flex u-row-between default-padding bg-fff border-bottom"
@click="toEditTitle"
>
<text>群聊名称</text> <text>群聊名称</text>
<view class="u-flex color-666"> <view class="u-flex color-666">
<text>{{ groupInfo.name }}</text> <text>{{ groupInfo.name }}</text>
@@ -77,6 +82,17 @@
</view> </view>
</view> </view>
</view> </view>
<Modal v-model="modalData.show" title="修改群名称" @confirm="modalConfirm">
<view class="u-p-40">
<view class="font-bold u-m-b-16">群名称</view>
<up-input
v-model="modalData.form.title"
placeholder="请输入群名称"
maxlength="20"
></up-input>
</view>
</Modal>
</view> </view>
</template> </template>
<script setup> <script setup>
@@ -84,10 +100,50 @@ import go from "@/commons/utils/go.js";
import * as chatApi from "@/http/php/chat"; import * as chatApi from "@/http/php/chat";
import { onShow, onLoad } from "@dcloudio/uni-app"; import { onShow, onLoad } from "@dcloudio/uni-app";
import { reactive, toRefs, computed, watch, onMounted, ref } from "vue"; import { reactive, toRefs, computed, watch, onMounted, ref } from "vue";
import Modal from "@/pageChat/components/modal.vue";
const options = reactive({}); const options = reactive({});
const groupInfo = ref({}); const groupInfo = ref({});
onLoad((opt) => { const modalData = reactive({
Object.assign(options, opt); show: false,
form: {
title: "",
},
key: "editTitle",
});
function toEditTitle() {
modalData.show = true;
modalData.form.title = groupInfo.value.name || "";
}
function modalConfirm(e) {
if (modalData.key == "editTitle") {
if (!modalData.form.title.trim().length) {
uni.showToast({
title: "请输入群名称",
icon: "none",
});
return;
}
chatApi
.groupEditTitle({
group_id: options.group_id,
title: modalData.form.title,
})
.then((res) => {
if (res) {
groupInfo.value.name = modalData.form.title;
modalData.show = false;
uni.showToast({
title: "修改成功",
icon: "none",
});
}
});
}
}
function getGroupInfo() {
chatApi chatApi
.groupInfo({ .groupInfo({
group_id: options.group_id, group_id: options.group_id,
@@ -95,6 +151,10 @@ onLoad((opt) => {
.then((res) => { .then((res) => {
groupInfo.value = res || {}; groupInfo.value = res || {};
}); });
}
onLoad((opt) => {
Object.assign(options, opt);
getGroupInfo();
}); });
function groupMuteChange(e) { function groupMuteChange(e) {
if (e) { if (e) {
@@ -137,8 +197,8 @@ function getMembers() {
}); });
} }
function loadMore() { function loadMore() {
userLists.value=allUser.value userLists.value = allUser.value;
} }
onShow(() => { onShow(() => {
getMembers(); getMembers();

View File

@@ -19,36 +19,37 @@
</up-sticky> </up-sticky>
<view class="list"> <view class="list">
<up-swipe-action> <up-swipe-action>
<up-swipe-action-item <template v-for="(item, index) in list" :key="item.id">
:options="options1" <up-swipe-action-item
v-for="(item, index) in list" :options="options1"
v-model:show="item.showOptions" v-model:show="item.showOptions"
@click="optionsClick($event, item, index)" @click="optionsClick($event, item, index)"
:key="item.id" >
> <view class="item u-flex" @click="toDetail(item)">
<view class="item u-flex" @click="toDetail(item)"> <view class="u-flex avatar">
<view class="u-flex avatar"> <up-avatar
<up-avatar size="118rpx"
size="118rpx" :src="item.avatar"
:src="item.avatar" shape="square"
shape="square" round="8rpx"
round="8rpx" ></up-avatar>
></up-avatar> <view class="bandage" v-if="item.unread_count > 0">{{
<view class="bandage" v-if="item.unread_count > 0">{{ item.unread_count >= 99 ? "99" : item.unread_count
item.unread_count >= 99 ? "99" : item.unread_count
}}</view>
</view>
<view class="u-flex-1 u-flex u-row-between u-p-l-14">
<view style="max-width: 364rpx">
<view class="color-000 u-line-1">{{ item.name }}</view>
<view class="u-m-t-28 u-line-1 u-font-24 color-999">{{
item.msg
}}</view> }}</view>
</view> </view>
<view class="color-333 u-font-24">{{ item.send_time }}</view> <view class="u-flex-1 u-flex u-row-between u-p-l-14">
<view style="max-width: 364rpx">
<view class="color-000 u-line-1">{{ item.name }}</view>
<view class="u-m-t-28 u-line-1 u-font-24 color-999">{{
item.msg
}}</view>
</view>
<view class="color-333 u-font-24">{{ item.send_time }}</view>
</view>
</view> </view>
</view> </up-swipe-action-item>
</up-swipe-action-item> <view style="height: 16rpx" class="bg-f7"></view>
</template>
</up-swipe-action> </up-swipe-action>
</view> </view>
</view> </view>
@@ -56,45 +57,49 @@
<script setup> <script setup>
import * as chatApi from "@/http/php/chat"; import * as chatApi from "@/http/php/chat";
import { ref, reactive, inject, onMounted,onUnmounted } from "vue"; import { ref, reactive, onMounted, onUnmounted } from "vue";
import { onShow } from "@dcloudio/uni-app"; import { onShow } from "@dcloudio/uni-app";
import { useChatStore } from "@/store/chat"; import { useChatStore } from "@/store/chat";
import dayjs from "dayjs";
const chatStore = useChatStore(); const chatStore = useChatStore();
onMounted(() => { const originalOnReceiveMsg = chatStore.onReceiveMsg;
chatStore.connectSocket();
// 确保状态监听已初始化 // 定义消息回调函数
if (!chatStore._listenersInitialized) { const handleReceiveMsg = (msg) => {
chatStore.initStateListeners(); // 先执行原始回调(如果有)
chatStore._listenersInitialized = true; if (typeof originalOnReceiveMsg === "function") {
originalOnReceiveMsg(msg);
} }
});
const startReciveMsg=ref(true)
onUnmounted(() => {
startReciveMsg.value=false
})
chatStore.onReceiveMsg = (msg) => {
if(!startReciveMsg.value){
return
}
if (msg.operate_type == "receive_msg" && msg.chat_type == 2) { if (msg.operate_type == "receive_msg" && msg.chat_type == 2) {
const index = allList.value.findIndex((v) => v.group_id == msg.group_id); const index = allList.value.findIndex((v) => v.group_id == msg.group_id);
if (index != -1) { if (index != -1) {
allList.value[index].unread_count += 1; allList.value[index].unread_count += 1;
allList.value[index].msg = returnMsg(msg); allList.value[index].msg = returnMsg(msg);
allList.value[index].send_time = msg.send_time; allList.value[index].send_time = msg.send_time;
allList.value[index].send_time_origin = msg.send_time_origin;
allList.value = listSort(allList.value);
} }
const index1 = list.value.findIndex((v) => v.group_id == msg.group_id); const index1 = list.value.findIndex((v) => v.group_id == msg.group_id);
if (index1 != -1) { if (index1 != -1) {
list.value[index1].unread_count += 1; list.value[index1].unread_count += 1;
list.value[index1].msg = returnMsg(msg); list.value[index1].msg = returnMsg(msg);
list.value[index1].send_time = msg.send_time; list.value[index1].send_time = msg.send_time;
list.value[index1].send_time_origin = msg.send_time_origin;
list.value = listSort(list.value);
} }
} }
}; };
onMounted(() => {
chatStore.registerReceiveMsgCallback(handleReceiveMsg);
});
onUnmounted(() => {
// 移除消息回调,避免内存泄漏
chatStore.removeReceiveMsgCallback(handleReceiveMsg);
});
function returnMsg(msg) { function returnMsg(msg) {
if (msg.msg_type == 1) { if (msg.msg_type == 1) {
return msg.nick + "" + msg.content; return msg.nick + "" + msg.content;
@@ -168,7 +173,7 @@ function throttle(fn, delay) {
//使用节流函数 //使用节流函数
const throttleSearch = throttle(search, 500); const throttleSearch = throttle(search, 500);
function search() { function search() {
list.value = allList.value const arr = allList.value
.filter((v) => v.name.includes(query.key.trim())) .filter((v) => v.name.includes(query.key.trim()))
.map((v) => { .map((v) => {
return { return {
@@ -176,10 +181,20 @@ function search() {
showOptions: false, showOptions: false,
}; };
}); });
list.value = listSort(arr);
} }
function listSort(arr) {
return arr.sort((a, b) => {
return dayjs(b.send_time_origin).unix() - dayjs(a.send_time_origin).unix();
});
}
async function getList() { async function getList() {
const res = await chatApi.messageSessionList({}); const res = await chatApi.messageSessionList({});
allList.value = (res.list || []).filter((v) => !v.is_del); const arr = (res.list || []).filter((v) => !v.is_del);
allList.value = listSort(arr);
search(); search();
} }
@@ -190,7 +205,7 @@ async function clearAllmsg() {
success: async (res) => { success: async (res) => {
if (res.confirm) { if (res.confirm) {
const res = await chatApi.messageMarkReadAll({ const res = await chatApi.messageMarkReadAll({
session_ids: list.value.map((v) => v.session_id).join(","), session_ids: list.value.map((v) => v.group_id).join(","),
}); });
if (res) { if (res) {
uni.showToast({ uni.showToast({
@@ -224,8 +239,16 @@ function toDetail(item) {
const messageUnreadCount = ref(0); const messageUnreadCount = ref(0);
onShow(() => { onShow(() => {
startReciveMsg.value=true
getList(); getList();
// 检查连接状态,确保连接活跃
if (!chatStore.isConnect || !chatStore.socketTask) {
console.log("列表页显示检查Socket连接");
chatStore.forceReconnect();
} else {
chatStore.shop_id = "";
chatStore.init();
}
// 获取未读消息总数 // 获取未读消息总数
chatApi.messageUnreadCount({}).then((res) => { chatApi.messageUnreadCount({}).then((res) => {
console.log(res); console.log(res);
@@ -245,13 +268,11 @@ onShow(() => {
} }
.list { .list {
padding: 36rpx 28rpx; padding: 36rpx 28rpx;
.item { .item {
padding: 32rpx 28rpx; padding: 32rpx 28rpx;
background-color: #fff; background-color: #fff;
border-radius: 16rpx; border-radius: 16rpx;
display: flex;
flex-direction: column;
gap: 16rpx;
.avatar { .avatar {
position: relative; position: relative;
.bandage { .bandage {
@@ -273,4 +294,10 @@ onShow(() => {
} }
} }
} }
:deep(.u-swipe-action-item__content) {
background-color: transparent;
}
:deep(.u-swipe-action-item) {
border-radius: 16rpx;
}
</style> </style>

View File

@@ -16,10 +16,13 @@ export const useChatStore = defineStore("chat", {
socketTask: null, socketTask: null,
onReceiveMsg: () => {}, onReceiveMsg: () => {},
chatList: [], chatList: [],
shop_id: uni.getStorageSync("shopId"),
token: uni.getStorageSync("iToken").tokenValue || "",
group_id:'',
isManualClose: false, // 是否主动关闭true不重连false自动重连 isManualClose: false, // 是否主动关闭true不重连false自动重连
heartbeatTimer: null, // 心跳定时器 heartbeatTimer: null, // 心跳定时器
reconnectTimer: null, // 重连定时器 reconnectTimer: null, // 重连定时器
connectionMonitorTimer: null, // 连接状态监控定时器
reconnectCount: 0, // 当前重连次数 reconnectCount: 0, // 当前重连次数
maxReconnectCount: 5, // 最大重连次数(避免无限重连) maxReconnectCount: 5, // 最大重连次数(避免无限重连)
reconnectDelay: 1000, // 初始重连延迟ms reconnectDelay: 1000, // 初始重连延迟ms
@@ -28,6 +31,7 @@ export const useChatStore = defineStore("chat", {
isAppActive: true, // 应用是否在前台 isAppActive: true, // 应用是否在前台
lastHeartbeatTime: 0, // 上次心跳时间戳 lastHeartbeatTime: 0, // 上次心跳时间戳
lastConnectTime: 0, // 上次连接时间(防止短时间内频繁连接)
// ========== 新增:修复未定义的状态 ========== // ========== 新增:修复未定义的状态 ==========
_listenersInitialized: false, // 状态监听器是否已初始化 _listenersInitialized: false, // 状态监听器是否已初始化
@@ -39,6 +43,9 @@ export const useChatStore = defineStore("chat", {
recentMessages: new Map(), // 最近处理的消息映射表key=消息特征哈希value=处理时间戳 recentMessages: new Map(), // 最近处理的消息映射表key=消息特征哈希value=处理时间戳
deduplicationWindow: 5000, // 去重时间窗口5秒内相同消息只处理一次 deduplicationWindow: 5000, // 去重时间窗口5秒内相同消息只处理一次
maxRecentMessages: 100, // 最近消息缓存最大数量 maxRecentMessages: 100, // 最近消息缓存最大数量
// ========== 新增:多页面消息监听支持 ==========
receiveMsgCallbacks: [], // 消息接收回调队列,支持多页面同时监听
}; };
}, },
@@ -91,6 +98,7 @@ export const useChatStore = defineStore("chat", {
// 2. 重置重连状态 // 2. 重置重连状态
this.reconnectCount = 0; this.reconnectCount = 0;
this.stopHeartbeat(); this.stopHeartbeat();
this.stopConnectionMonitor();
// 3. 立即重新连接 // 3. 立即重新连接
setTimeout(() => { setTimeout(() => {
@@ -128,13 +136,14 @@ export const useChatStore = defineStore("chat", {
{ {
type: "OnbocChat", type: "OnbocChat",
operate_type: "init", operate_type: "init",
shop_id: uni.getStorageSync("shopId"), shop_id: this.shop_id,
token: uni.getStorageSync("iToken").tokenValue || "", token: this.token,
}, },
false false
); );
}, },
// ========== 增强发送消息容错性 ==========
sendMessage(msg, isAutoAppend = true) { sendMessage(msg, isAutoAppend = true) {
// 1. 主动关闭状态:提示用户 // 1. 主动关闭状态:提示用户
if (this.isManualClose) { if (this.isManualClose) {
@@ -144,13 +153,14 @@ export const useChatStore = defineStore("chat", {
}); });
} }
// 2. 连接未建立:尝试重连后发送 // 2. 连接未建立或SocketTask失效:尝试重连后发送
if (!this.isConnect) { if (!this.isConnect || !this.socketTask) {
console.warn("Socket连接未建立尝试重连...");
this.reconnect(); this.reconnect();
// 延迟发送,确保重连成 // 延长延迟时间,确保重连
setTimeout(() => { setTimeout(() => {
this.sendMessage(msg, isAutoAppend); this.sendMessage(msg, isAutoAppend);
}, this.reconnectDelay); }, 1500);
return; return;
} }
@@ -166,25 +176,41 @@ export const useChatStore = defineStore("chat", {
} }
: msg; : msg;
this.socketTask.send({ try {
data: JSON.stringify(message), this.socketTask.send({
success: (res) => { data: JSON.stringify(message),
console.log("发送成功", res); success: (res) => {
}, console.log("发送成功", res);
fail: (error) => { },
console.log("发送失败", error); fail: (error) => {
// 发送失败可能是连接断开,触发重连 console.error("发送失败,触发重连", error);
if (!this.isManualClose) { // 发送失败可能是连接断开,触发重连
this.reconnect(); if (!this.isManualClose) {
} this.forceReconnect();
}, // 重连后重试发送
}); setTimeout(() => {
this.sendMessage(msg, isAutoAppend);
}, 1500);
}
},
});
} catch (error) {
console.error("发送消息异常,触发重连", error);
// 捕获异常,立即重连
if (!this.isManualClose) {
this.forceReconnect();
// 重连后重试发送
setTimeout(() => {
this.sendMessage(msg, isAutoAppend);
}, 1500);
}
}
}, },
// ========== 发送心跳包 ========== // ========== 发送心跳包 ==========
sendHeartbeat() { sendHeartbeat() {
// 应用在后台时可调整心跳策略(如降低频率) // 应用在后台时可调整心跳策略(如降低频率)
if (!this.isConnect || this.isManualClose) return; if (!this.isConnect || this.isManualClose || !this.socketTask) return;
const now = Date.now(); const now = Date.now();
// 记录心跳时间 // 记录心跳时间
@@ -196,7 +222,7 @@ export const useChatStore = defineStore("chat", {
}), }),
fail: (error) => { fail: (error) => {
console.log("心跳发送失败,触发重连", error); console.log("心跳发送失败,触发重连", error);
this.reconnect(); this.forceReconnect();
}, },
}); });
}, },
@@ -224,6 +250,31 @@ export const useChatStore = defineStore("chat", {
this.heartbeatTimer = null; this.heartbeatTimer = null;
} }
}, },
// ========== 新增:启动连接状态监控 ==========
startConnectionMonitor() {
// 清除旧定时器
if (this.connectionMonitorTimer) {
clearInterval(this.connectionMonitorTimer);
}
// 每30秒检查一次连接状态
this.connectionMonitorTimer = setInterval(() => {
// 如果应该连接但实际未连接,触发重连
if (!this.isManualClose && this.isConnect && !this.socketTask) {
console.warn("连接监控:发现连接状态异常,强制重置");
this.forceReconnect();
}
}, 30000);
},
// ========== 新增:停止连接状态监控 ==========
stopConnectionMonitor() {
if (this.connectionMonitorTimer) {
clearInterval(this.connectionMonitorTimer);
this.connectionMonitorTimer = null;
}
},
// ========== 智能重连逻辑 ========== // ========== 智能重连逻辑 ==========
reconnect() { reconnect() {
@@ -235,19 +286,26 @@ export const useChatStore = defineStore("chat", {
console.log("正在建立连接中,跳过重连"); console.log("正在建立连接中,跳过重连");
return; return;
} }
// 3. 短时间内已尝试连接:不重连(防止频繁连接)
const now = Date.now();
if (now - this.lastConnectTime < 1000) {
console.log("短时间内已尝试连接,跳过重连");
return;
}
// 3. 超过最大重连次数:停止重连 // 4. 超过最大重连次数:停止重连
if (this.reconnectCount >= this.maxReconnectCount) { if (this.reconnectCount >= this.maxReconnectCount) {
console.log("已达最大重连次数,停止重连"); console.log("已达最大重连次数,停止重连");
return; return;
} }
// 4. 清除旧重连定时器 // 5. 清除旧重连定时器
if (this.reconnectTimer) { if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer); clearTimeout(this.reconnectTimer);
} }
// 5. 计算重连延迟退避算法1s → 2s → 4s → 8s → 8s... // 6. 计算重连延迟退避算法1s → 2s → 4s → 8s → 8s...
const delay = Math.min( const delay = Math.min(
this.reconnectDelay * Math.pow(2, this.reconnectCount), this.reconnectDelay * Math.pow(2, this.reconnectCount),
this.maxReconnectDelay this.maxReconnectDelay
@@ -255,7 +313,7 @@ export const useChatStore = defineStore("chat", {
console.log(`${this.reconnectCount + 1}次重连,延迟${delay}ms`); console.log(`${this.reconnectCount + 1}次重连,延迟${delay}ms`);
// 6. 延迟执行重连 // 7. 延迟执行重连
this.reconnectTimer = setTimeout(() => { this.reconnectTimer = setTimeout(() => {
this.connectSocket(); this.connectSocket();
this.reconnectCount++; this.reconnectCount++;
@@ -271,11 +329,18 @@ export const useChatStore = defineStore("chat", {
isConnecting: this.isConnecting, isConnecting: this.isConnecting,
isManualClose: this.isManualClose isManualClose: this.isManualClose
}); });
// 关键:如果 socketTask 已失效但 isConnect 为 true强制重置状态
if (this.isConnect && !this.socketTask) {
console.warn("Socket连接状态异常强制重置");
this.isConnect = false;
this.forceReconnect();
}
return; return;
} }
// 2. 设置连接中状态 // 2. 设置连接中状态
this.isConnecting = true; this.isConnecting = true;
this.lastConnectTime = Date.now();
// 3. 重置主动关闭标记 // 3. 重置主动关闭标记
this.isManualClose = false; this.isManualClose = false;
@@ -309,6 +374,7 @@ export const useChatStore = defineStore("chat", {
// 缩短心跳间隔到15s更频繁的心跳维持连接活跃 // 缩短心跳间隔到15s更频繁的心跳维持连接活跃
this.heartbeatInterval = 15000; this.heartbeatInterval = 15000;
this.startHeartbeat(); this.startHeartbeat();
this.startConnectionMonitor(); // 启动连接状态监控
// 初始化状态监听(仅在首次连接时执行) // 初始化状态监听(仅在首次连接时执行)
if (!this._listenersInitialized) { if (!this._listenersInitialized) {
@@ -357,7 +423,7 @@ export const useChatStore = defineStore("chat", {
this.isConnect = false; this.isConnect = false;
this.isConnecting = false; this.isConnecting = false;
// 错误触发重连 // 错误触发重连
this.reconnect(); this.forceReconnect();
}); });
// 8. 连接关闭回调(区分主动/意外关闭) // 8. 连接关闭回调(区分主动/意外关闭)
@@ -367,6 +433,7 @@ export const useChatStore = defineStore("chat", {
this.isConnect = false; this.isConnect = false;
this.isConnecting = false; this.isConnecting = false;
this.stopHeartbeat(); // 停止心跳 this.stopHeartbeat(); // 停止心跳
this.stopConnectionMonitor(); // 停止连接状态监控
// 只有非主动关闭时才重连 // 只有非主动关闭时才重连
if (!this.isManualClose) { if (!this.isManualClose) {
@@ -410,8 +477,41 @@ export const useChatStore = defineStore("chat", {
} }
// 5. 正常处理消息 // 5. 正常处理消息
this.chatList.unshift(msg); if(this.group_id==msg.to_id){
this.onReceiveMsg(msg); this.chatList.unshift(msg);
}
// 触发所有消息回调(支持多页面同时监听)
this.triggerReceiveMsgCallbacks(msg);
},
// ========== 新增:触发消息回调 ==========
triggerReceiveMsgCallbacks(msg) {
// 调用旧的单个回调(兼容原有代码)
if (typeof this.onReceiveMsg === 'function') {
this.onReceiveMsg(msg);
}
// 调用所有注册的回调
this.receiveMsgCallbacks.forEach(callback => {
if (typeof callback === 'function') {
callback(msg);
}
});
},
// ========== 新增:注册消息回调 ==========
registerReceiveMsgCallback(callback) {
if (typeof callback === 'function' && !this.receiveMsgCallbacks.includes(callback)) {
this.receiveMsgCallbacks.push(callback);
}
},
// ========== 新增:移除消息回调 ==========
removeReceiveMsgCallback(callback) {
const index = this.receiveMsgCallbacks.indexOf(callback);
if (index > -1) {
this.receiveMsgCallbacks.splice(index, 1);
}
}, },
// ========== 新增:生成消息特征哈希 ========== // ========== 新增:生成消息特征哈希 ==========
@@ -468,6 +568,7 @@ export const useChatStore = defineStore("chat", {
// 2. 停止所有定时器,清理资源 // 2. 停止所有定时器,清理资源
this.stopHeartbeat(); this.stopHeartbeat();
this.stopConnectionMonitor();
if (this.reconnectTimer) { if (this.reconnectTimer) {
clearTimeout(this.reconnectTimer); clearTimeout(this.reconnectTimer);
this.reconnectTimer = null; this.reconnectTimer = null;