2026-01-07 14:33:30 +08:00
|
|
|
|
<!-- eslint-disable vue/no-v-html -->
|
|
|
|
|
|
<template>
|
2025-12-30 17:02:30 +08:00
|
|
|
|
<div class="page-container-flex">
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<van-pull-refresh
|
|
|
|
|
|
v-model="refreshing"
|
|
|
|
|
|
@refresh="onRefresh"
|
|
|
|
|
|
>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
<van-list
|
|
|
|
|
|
v-model:loading="loading"
|
|
|
|
|
|
:finished="finished"
|
|
|
|
|
|
finished-text="没有更多了"
|
|
|
|
|
|
@load="onLoad"
|
|
|
|
|
|
>
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<van-cell-group
|
|
|
|
|
|
v-if="list.length"
|
|
|
|
|
|
inset
|
|
|
|
|
|
style="margin-top: 10px"
|
|
|
|
|
|
>
|
|
|
|
|
|
<van-swipe-cell
|
|
|
|
|
|
v-for="item in list"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="message-card"
|
|
|
|
|
|
@click="viewDetail(item)"
|
|
|
|
|
|
>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
<div class="card-left">
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="message-title"
|
|
|
|
|
|
:class="{ unread: !item.isRead }"
|
|
|
|
|
|
>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
{{ item.title }}
|
|
|
|
|
|
</div>
|
2025-12-29 16:07:43 +08:00
|
|
|
|
<div class="message-content">
|
|
|
|
|
|
{{ item.content }}
|
|
|
|
|
|
</div>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
<div class="message-info">
|
|
|
|
|
|
{{ item.createTime }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="card-right">
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<van-tag
|
|
|
|
|
|
v-if="!item.isRead"
|
|
|
|
|
|
type="danger"
|
|
|
|
|
|
>
|
|
|
|
|
|
未读
|
|
|
|
|
|
</van-tag>
|
|
|
|
|
|
<van-icon
|
|
|
|
|
|
name="arrow"
|
|
|
|
|
|
size="16"
|
|
|
|
|
|
class="arrow-icon"
|
|
|
|
|
|
/>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<template #right>
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<van-button
|
|
|
|
|
|
square
|
|
|
|
|
|
text="删除"
|
|
|
|
|
|
type="danger"
|
|
|
|
|
|
class="delete-button"
|
|
|
|
|
|
@click="handleDelete(item)"
|
|
|
|
|
|
/>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</van-swipe-cell>
|
|
|
|
|
|
</van-cell-group>
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<van-empty
|
|
|
|
|
|
v-else-if="!loading"
|
|
|
|
|
|
description="暂无消息"
|
|
|
|
|
|
/>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
</van-list>
|
|
|
|
|
|
</van-pull-refresh>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 详情弹出层 -->
|
2026-02-20 14:57:19 +08:00
|
|
|
|
<PopupContainerV2
|
|
|
|
|
|
v-model:show="detailVisible"
|
2025-12-30 17:02:30 +08:00
|
|
|
|
:title="currentMessage.title"
|
2026-02-20 14:57:19 +08:00
|
|
|
|
:height="'75%'"
|
2025-12-29 14:18:09 +08:00
|
|
|
|
>
|
2026-02-20 14:57:19 +08:00
|
|
|
|
<div style="padding: 16px">
|
|
|
|
|
|
<p style="color: #999; font-size: 14px; margin-bottom: 12px; margin-top: 0">
|
|
|
|
|
|
{{ currentMessage.createTime }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="currentMessage.messageType === 2"
|
|
|
|
|
|
class="rich-html-content"
|
|
|
|
|
|
style="font-size: 14px; line-height: 1.6"
|
|
|
|
|
|
v-html="currentMessage.content"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-else
|
|
|
|
|
|
style="font-size: 14px; line-height: 1.6; white-space: pre-wrap"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ currentMessage.content }}
|
|
|
|
|
|
</div>
|
2025-12-29 14:18:09 +08:00
|
|
|
|
</div>
|
2026-01-16 11:15:44 +08:00
|
|
|
|
<template
|
|
|
|
|
|
v-if="currentMessage.url && currentMessage.messageType === 1"
|
|
|
|
|
|
#footer
|
|
|
|
|
|
>
|
|
|
|
|
|
<van-button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
block
|
|
|
|
|
|
round
|
|
|
|
|
|
@click="handleUrlJump(currentMessage.url)"
|
|
|
|
|
|
>
|
2026-01-10 12:22:37 +08:00
|
|
|
|
查看详情
|
|
|
|
|
|
</van-button>
|
2026-01-10 23:01:02 +08:00
|
|
|
|
</template>
|
2026-02-20 14:57:19 +08:00
|
|
|
|
</PopupContainerV2>
|
2025-12-28 10:23:57 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-16 11:15:44 +08:00
|
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { showToast, showDialog } from 'vant'
|
|
|
|
|
|
import { getMessageList, markAsRead, deleteMessage, markAllAsRead } from '@/api/message'
|
|
|
|
|
|
import { useMessageStore } from '@/stores/message'
|
2026-02-20 14:57:19 +08:00
|
|
|
|
import PopupContainerV2 from '@/components/PopupContainerV2.vue'
|
2026-01-16 11:15:44 +08:00
|
|
|
|
|
|
|
|
|
|
const messageStore = useMessageStore()
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const list = ref([])
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const finished = ref(false)
|
|
|
|
|
|
const refreshing = ref(false)
|
|
|
|
|
|
const pageIndex = ref(1)
|
|
|
|
|
|
const pageSize = ref(20)
|
|
|
|
|
|
|
|
|
|
|
|
const detailVisible = ref(false)
|
|
|
|
|
|
const currentMessage = ref({})
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
const onLoad = async () => {
|
|
|
|
|
|
if (refreshing.value) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
list.value = []
|
|
|
|
|
|
pageIndex.value = 1
|
|
|
|
|
|
refreshing.value = false
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await getMessageList({
|
|
|
|
|
|
pageIndex: pageIndex.value,
|
|
|
|
|
|
pageSize: pageSize.value
|
2026-01-16 11:15:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
if (res.success) {
|
|
|
|
|
|
// 格式化时间
|
2026-01-16 11:15:44 +08:00
|
|
|
|
const data = res.data.map((item) => ({
|
2025-12-29 14:18:09 +08:00
|
|
|
|
...item,
|
|
|
|
|
|
createTime: new Date(item.createTime).toLocaleString()
|
2026-01-16 11:15:44 +08:00
|
|
|
|
}))
|
|
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
if (pageIndex.value === 1) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
list.value = data
|
2025-12-29 14:18:09 +08:00
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
list.value = [...list.value, ...data]
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
// 判断是否加载完成
|
|
|
|
|
|
if (list.value.length >= res.total || data.length < pageSize.value) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
finished.value = true
|
2025-12-29 14:18:09 +08:00
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
pageIndex.value++
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast(res.message || '加载失败')
|
|
|
|
|
|
finished.value = true
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
console.error(error)
|
|
|
|
|
|
showToast('加载失败')
|
|
|
|
|
|
finished.value = true
|
2025-12-29 14:18:09 +08:00
|
|
|
|
} finally {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
loading.value = false
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
}
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
const onRefresh = () => {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
finished.value = false
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
onLoad()
|
|
|
|
|
|
}
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
const viewDetail = async (item) => {
|
|
|
|
|
|
if (!item.isRead) {
|
|
|
|
|
|
try {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
await markAsRead(item.id)
|
|
|
|
|
|
item.isRead = true
|
|
|
|
|
|
messageStore.updateUnreadCount()
|
2025-12-29 14:18:09 +08:00
|
|
|
|
} catch (error) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
console.error('标记已读失败', error)
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-06 13:45:39 +08:00
|
|
|
|
|
2026-01-16 11:15:44 +08:00
|
|
|
|
currentMessage.value = item
|
|
|
|
|
|
detailVisible.value = true
|
|
|
|
|
|
}
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
2026-01-10 12:22:37 +08:00
|
|
|
|
const handleUrlJump = (targetUrl) => {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
if (!targetUrl) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-10 12:22:37 +08:00
|
|
|
|
if (targetUrl.startsWith('http')) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
window.open(targetUrl, '_blank')
|
2026-01-10 12:22:37 +08:00
|
|
|
|
} else if (targetUrl.startsWith('/')) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
router.push(targetUrl)
|
|
|
|
|
|
detailVisible.value = false
|
2026-01-10 12:22:37 +08:00
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast('无效的URL')
|
2026-01-10 12:22:37 +08:00
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
}
|
2026-01-10 12:22:37 +08:00
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
const handleDelete = (item) => {
|
|
|
|
|
|
showDialog({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
message: '确定要删除这条消息吗?',
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showCancelButton: true
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}).then(async (action) => {
|
|
|
|
|
|
if (action === 'confirm') {
|
|
|
|
|
|
try {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
const res = await deleteMessage(item.id)
|
2025-12-29 14:18:09 +08:00
|
|
|
|
if (res.success) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast('删除成功')
|
|
|
|
|
|
const wasUnread = !item.isRead
|
|
|
|
|
|
list.value = list.value.filter((i) => i.id !== item.id)
|
2025-12-29 14:18:09 +08:00
|
|
|
|
if (wasUnread) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
messageStore.updateUnreadCount()
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast(res.message || '删除失败')
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
console.error('删除消息失败', error)
|
|
|
|
|
|
showToast('删除失败')
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
const handleMarkAllRead = () => {
|
|
|
|
|
|
showDialog({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
message: '确定要将所有消息标记为已读吗?',
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showCancelButton: true
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}).then(async (action) => {
|
|
|
|
|
|
if (action === 'confirm') {
|
|
|
|
|
|
try {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
const res = await markAllAsRead()
|
2025-12-29 14:18:09 +08:00
|
|
|
|
if (res.success) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast('操作成功')
|
2025-12-29 14:18:09 +08:00
|
|
|
|
// 刷新列表
|
2026-01-16 11:15:44 +08:00
|
|
|
|
onRefresh()
|
2025-12-29 14:18:09 +08:00
|
|
|
|
// 更新未读计数
|
2026-01-16 11:15:44 +08:00
|
|
|
|
messageStore.updateUnreadCount()
|
2025-12-29 14:18:09 +08:00
|
|
|
|
} else {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
showToast(res.message || '操作失败')
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2026-01-16 11:15:44 +08:00
|
|
|
|
console.error('标记所有已读失败', error)
|
|
|
|
|
|
showToast('操作失败')
|
2025-12-29 14:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-12-29 14:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
// onLoad 会由 van-list 自动触发
|
2026-01-16 11:15:44 +08:00
|
|
|
|
})
|
2026-01-06 20:55:11 +08:00
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
|
handleMarkAllRead
|
2026-01-16 11:15:44 +08:00
|
|
|
|
})
|
2025-12-29 14:18:09 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.message-card {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-left {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
padding-right: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-right {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.arrow-icon {
|
|
|
|
|
|
color: var(--van-gray-5);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-title {
|
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
|
margin-bottom: 6px;
|
|
|
|
|
|
color: var(--van-text-color);
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 11:15:44 +08:00
|
|
|
|
.message-content {
|
2025-12-29 16:07:43 +08:00
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: var(--van-text-color-2);
|
|
|
|
|
|
margin-bottom: 6px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-29 14:18:09 +08:00
|
|
|
|
.message-title.unread {
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-info {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: var(--van-text-color-2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.delete-button {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-30 17:02:30 +08:00
|
|
|
|
:deep(.van-pull-refresh) {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
-webkit-overflow-scrolling: touch;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 设置页面容器背景色 */
|
|
|
|
|
|
:deep(.van-nav-bar) {
|
|
|
|
|
|
background: transparent !important;
|
|
|
|
|
|
}
|
2026-01-16 11:15:44 +08:00
|
|
|
|
</style>
|