fix(chat): 修复一键清理未读失败

This commit is contained in:
yml2213
2026-08-25 19:32:04 +08:00
parent 52dcb18c96
commit 16237dcefc
6 changed files with 85 additions and 2 deletions
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Close, Picture } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Check, Close, Picture } from '@element-plus/icons-vue'
import {
fetchAdminChat,
fetchAdminChatMessages,
@@ -10,6 +10,7 @@ import {
fetchAdminChats,
fetchQuickReplies,
markAdminChatRead,
markAllAdminChatsRead,
sendAdminChatMessage,
updateChatRemark,
type AdminChatCounts,
@@ -54,6 +55,7 @@ const activePaymentRecords = ref<AdminPayment[]>([])
const loading = ref(false)
const messageLoading = ref(false)
const sending = ref(false)
const clearingAll = ref(false)
const uploading = ref(false)
const content = ref('')
const attachments = ref<string[]>([])
@@ -265,6 +267,29 @@ function refreshAll() {
void Promise.all([loadConversations(true), loadCounts(true)])
}
async function clearAllUnread() {
if (clearingAll.value) return
try {
await ElMessageBox.confirm(
'将把全部客服会话标记为已读,不会删除聊天记录。后续新消息仍会正常提醒。',
'一键清理未读提醒',
{ type: 'warning', confirmButtonText: '确认清理', cancelButtonText: '取消' }
)
} catch {
return
}
clearingAll.value = true
try {
await markAllAdminChatsRead()
await Promise.all([loadConversations(true), loadCounts(true)])
ElMessage.success('未读提醒已清理')
} catch {
ElMessage.error('清理失败,请稍后重试')
} finally {
clearingAll.value = false
}
}
async function loadQuickReplies() {
try {
quickReplies.value = await fetchQuickReplies()
@@ -654,6 +679,7 @@ function firstQueryValue(value: unknown) {
<div class="head-right">
<NotificationSettings scope="admin" />
<el-button @click="quickReplyVisible = true">快捷回复管理</el-button>
<el-button :loading="clearingAll" :icon="Check" @click="clearAllUnread">一键清理</el-button>
<el-button :loading="loading" @click="refreshAll">刷新</el-button>
</div>
</div>
+5
View File
@@ -170,6 +170,11 @@ export async function fetchAdminChatCounts(query: AdminChatQuery = {}) {
return data.data
}
export async function markAllAdminChatsRead() {
const { data } = await apiClient.post<ApiResponse<{ read: boolean }>>('/admin/chats/read-all')
return data.data
}
export async function fetchAdminChat(id: number) {
const { data } = await apiClient.get<ApiResponse<ChatConversation>>(`/admin/chats/${id}`)
return data.data