feat(distribution): 站内信与通知体系多租户独立分支隔离
- 新增 000071 数据库迁移:notifications 表支持 distribution_site_id 并自动回填历史分销订单通知 - 通知自动归属:在事务内根据订单或申诉自动关联当前分销站点 ID - 隔离查询与已读控制:列表、未读统计与批量已读均严格按站点隔离,防止主站与分站交叉泄漏 - 前台界面联动:消息中心通知 Tab 及移动端/PC端站内信页面展示分站专属标识与精准过滤
This commit is contained in:
@@ -10,37 +10,78 @@ export interface NotificationItem {
|
||||
content: string
|
||||
biz_type: string
|
||||
biz_id?: number
|
||||
distribution_site_id?: number | null
|
||||
read_at?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export async function fetchNotifications(page = 1, pageSize = 20) {
|
||||
export async function fetchNotifications(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode =
|
||||
distributionSiteCode ||
|
||||
(typeof window !== 'undefined' ? localStorage.getItem('hfb_site_code') : '') ||
|
||||
undefined
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
}
|
||||
const { data } = await apiClient.get<ApiResponse<PaginatedResult<NotificationItem>>>(
|
||||
'/notifications',
|
||||
{
|
||||
params: { page, page_size: pageSize },
|
||||
params,
|
||||
}
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function markNotificationRead(id: number) {
|
||||
const { data } = await apiClient.post<ApiResponse<{ read: boolean }>>(`/notifications/${id}/read`)
|
||||
export async function markNotificationRead(id: number, distributionSiteCode?: string) {
|
||||
const siteCode =
|
||||
distributionSiteCode ||
|
||||
(typeof window !== 'undefined' ? localStorage.getItem('hfb_site_code') : '') ||
|
||||
undefined
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
}
|
||||
const { data } = await apiClient.post<ApiResponse<{ read: boolean }>>(
|
||||
`/notifications/${id}/read`,
|
||||
{},
|
||||
{ params }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchUnreadNotificationCount() {
|
||||
export async function fetchUnreadNotificationCount(distributionSiteCode?: string) {
|
||||
const siteCode =
|
||||
distributionSiteCode ||
|
||||
(typeof window !== 'undefined' ? localStorage.getItem('hfb_site_code') : '') ||
|
||||
undefined
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
}
|
||||
const { data } = await apiClient.get<ApiResponse<{ unread_count: number }>>(
|
||||
'/notifications/unread-count',
|
||||
{
|
||||
params,
|
||||
silent: true,
|
||||
}
|
||||
)
|
||||
return data.data.unread_count
|
||||
}
|
||||
|
||||
export async function markAllNotificationsRead() {
|
||||
const { data } =
|
||||
await apiClient.put<ApiResponse<{ read_count: number }>>('/notifications/read-all')
|
||||
export async function markAllNotificationsRead(distributionSiteCode?: string) {
|
||||
const siteCode =
|
||||
distributionSiteCode ||
|
||||
(typeof window !== 'undefined' ? localStorage.getItem('hfb_site_code') : '') ||
|
||||
undefined
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
}
|
||||
const { data } = await apiClient.put<ApiResponse<{ read_count: number }>>(
|
||||
'/notifications/read-all',
|
||||
{},
|
||||
{ params }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ import {
|
||||
} from '@/features/auth/api/notifications'
|
||||
import { notificationUnreadChangedEvent } from '@/features/auth/composables/useNotificationUnreadCount'
|
||||
import { formatDateMinute } from '@/shared/utils/time'
|
||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||
|
||||
const router = useRouter()
|
||||
const distributionStore = useDistributionSiteStore()
|
||||
const loading = ref(false)
|
||||
const refreshing = ref(false)
|
||||
const loadingMore = ref(false)
|
||||
@@ -36,7 +38,8 @@ async function loadNotifications(reset = false) {
|
||||
loadingMore.value = true
|
||||
}
|
||||
try {
|
||||
const result = await fetchNotifications(currentPage.value, pageSize)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
const result = await fetchNotifications(currentPage.value, pageSize, siteCode)
|
||||
notifications.value = reset ? result.items : [...notifications.value, ...result.items]
|
||||
total.value = result.total
|
||||
if (notifications.value.length < result.total && result.items.length > 0) {
|
||||
@@ -54,7 +57,8 @@ async function loadNotifications(reset = false) {
|
||||
async function markRead(item: NotificationItem) {
|
||||
if (item.read_at) return
|
||||
try {
|
||||
await markNotificationRead(item.id)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
await markNotificationRead(item.id, siteCode)
|
||||
item.read_at = new Date().toISOString()
|
||||
window.dispatchEvent(new Event(notificationUnreadChangedEvent))
|
||||
showToast({ message: '已标记为已读', icon: 'passed' })
|
||||
@@ -98,14 +102,33 @@ function typeLabel(type: string) {
|
||||
<van-icon name="arrow-left" :size="20" />
|
||||
</button>
|
||||
<div>
|
||||
<h1>站内信</h1>
|
||||
<p>{{ total > 0 ? `共 ${total} 条通知` : '订单、审核和申诉消息会出现在这里' }}</p>
|
||||
<h1>
|
||||
{{
|
||||
distributionStore.isDistribution ? `${distributionStore.siteName} · 站内信` : '站内信'
|
||||
}}
|
||||
</h1>
|
||||
<p>
|
||||
{{
|
||||
distributionStore.isDistribution
|
||||
? `【${distributionStore.siteName}】专属通知 · 共 ${total} 条`
|
||||
: total > 0
|
||||
? `共 ${total} 条通知`
|
||||
: '订单、审核和申诉消息会出现在这里'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<van-pull-refresh v-model="refreshing" @refresh="loadNotifications(true)">
|
||||
<section class="notification-list">
|
||||
<van-empty v-if="!loading && notifications.length === 0" description="暂无站内信" />
|
||||
<van-empty
|
||||
v-if="!loading && notifications.length === 0"
|
||||
:description="
|
||||
distributionStore.isDistribution
|
||||
? `暂无【${distributionStore.siteName}】专属站内信`
|
||||
: '暂无站内信'
|
||||
"
|
||||
/>
|
||||
<article
|
||||
v-for="item in notifications"
|
||||
:key="item.id"
|
||||
|
||||
@@ -9,7 +9,9 @@ import {
|
||||
} from '@/features/auth/api/notifications'
|
||||
import { notificationUnreadChangedEvent } from '@/features/auth/composables/useNotificationUnreadCount'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||
|
||||
const distributionStore = useDistributionSiteStore()
|
||||
const loading = ref(false)
|
||||
const notifications = ref<NotificationItem[]>([])
|
||||
const currentPage = ref(1)
|
||||
@@ -21,7 +23,8 @@ onMounted(loadNotifications)
|
||||
async function loadNotifications() {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await fetchNotifications(currentPage.value, currentPageSize.value)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
const result = await fetchNotifications(currentPage.value, currentPageSize.value, siteCode)
|
||||
notifications.value = result.items
|
||||
total.value = result.total
|
||||
} finally {
|
||||
@@ -35,7 +38,8 @@ function handleSizeChange() {
|
||||
}
|
||||
|
||||
async function markRead(id: number) {
|
||||
await markNotificationRead(id)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
await markNotificationRead(id, siteCode)
|
||||
window.dispatchEvent(new Event(notificationUnreadChangedEvent))
|
||||
ElMessage.success('已标记为已读')
|
||||
await loadNotifications()
|
||||
@@ -45,12 +49,38 @@ async function markRead(id: number) {
|
||||
<template>
|
||||
<section class="page">
|
||||
<div class="page-header">
|
||||
<p class="eyebrow">Notifications</p>
|
||||
<h1>站内信</h1>
|
||||
<p>接收审核、交接、归还、申诉和仲裁结果通知。</p>
|
||||
<p class="eyebrow">
|
||||
Notifications
|
||||
<el-tag
|
||||
v-if="distributionStore.isDistribution"
|
||||
type="warning"
|
||||
effect="light"
|
||||
size="small"
|
||||
class="distribution-site-tag"
|
||||
>
|
||||
{{ distributionStore.siteName }}专属分站
|
||||
</el-tag>
|
||||
</p>
|
||||
<h1>
|
||||
{{ distributionStore.isDistribution ? `${distributionStore.siteName} · 站内信` : '站内信' }}
|
||||
</h1>
|
||||
<p>
|
||||
{{
|
||||
distributionStore.isDistribution
|
||||
? `接收【${distributionStore.siteName}】专属分站订单交易、交接、申诉和客服通知。`
|
||||
: '接收审核、交接、归还、申诉和仲裁结果通知。'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<el-empty v-if="!loading && notifications.length === 0" description="暂无站内信" />
|
||||
<el-empty
|
||||
v-if="!loading && notifications.length === 0"
|
||||
:description="
|
||||
distributionStore.isDistribution
|
||||
? `暂无【${distributionStore.siteName}】专属站内信`
|
||||
: '暂无站内信'
|
||||
"
|
||||
/>
|
||||
<div v-else v-loading="loading" class="notification-list">
|
||||
<div
|
||||
v-for="item in notifications"
|
||||
@@ -91,3 +121,11 @@ async function markRead(id: number) {
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.distribution-site-tag {
|
||||
margin-left: 8px;
|
||||
vertical-align: middle;
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -130,7 +130,8 @@ async function loadNotifications(reset = false) {
|
||||
if (reset) notiPage.value = 1
|
||||
notiLoading.value = true
|
||||
try {
|
||||
const result = await fetchNotifications(notiPage.value, notiPageSize)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
const result = await fetchNotifications(notiPage.value, notiPageSize, siteCode)
|
||||
notifications.value = reset ? result.items : [...notifications.value, ...result.items]
|
||||
notiTotal.value = result.total
|
||||
if (notifications.value.length < result.total && result.items.length > 0) {
|
||||
@@ -146,7 +147,8 @@ async function loadNotifications(reset = false) {
|
||||
async function markNotiRead(item: NotificationItem) {
|
||||
if (item.read_at) return
|
||||
try {
|
||||
await markNotificationRead(item.id)
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
await markNotificationRead(item.id, siteCode)
|
||||
item.read_at = new Date().toISOString()
|
||||
window.dispatchEvent(new Event(notificationUnreadChangedEvent))
|
||||
ElMessage.success('已标记为已读')
|
||||
@@ -159,7 +161,8 @@ async function markAllNotiRead() {
|
||||
if (notiSubmitting.value) return
|
||||
notiSubmitting.value = true
|
||||
try {
|
||||
const result = await markAllNotificationsRead()
|
||||
const siteCode = distributionStore.isDistribution ? distributionStore.siteCode : undefined
|
||||
const result = await markAllNotificationsRead(siteCode)
|
||||
window.dispatchEvent(new Event(notificationUnreadChangedEvent))
|
||||
ElMessage.success(result.read_count > 0 ? `已标记 ${result.read_count} 条通知` : '暂无未读通知')
|
||||
await loadNotifications(true)
|
||||
@@ -301,10 +304,21 @@ function handleTabChange(tab: string) {
|
||||
</template>
|
||||
|
||||
<div class="noti-toolbar">
|
||||
<span v-if="notificationUnreadCount > 0" class="noti-toolbar-text">
|
||||
{{ notificationUnreadCount }} 条未读
|
||||
</span>
|
||||
<span v-else class="noti-toolbar-text">暂无未读通知</span>
|
||||
<div class="noti-toolbar-left">
|
||||
<el-tag
|
||||
v-if="distributionStore.isDistribution"
|
||||
type="warning"
|
||||
effect="light"
|
||||
size="small"
|
||||
class="noti-site-tag"
|
||||
>
|
||||
{{ distributionStore.siteName }}专属通知
|
||||
</el-tag>
|
||||
<span v-if="notificationUnreadCount > 0" class="noti-toolbar-text">
|
||||
{{ notificationUnreadCount }} 条未读
|
||||
</span>
|
||||
<span v-else class="noti-toolbar-text">暂无未读通知</span>
|
||||
</div>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
@@ -322,7 +336,13 @@ function handleTabChange(tab: string) {
|
||||
/>
|
||||
|
||||
<div v-else-if="!notiLoading && notifications.length === 0" class="empty-panel">
|
||||
<el-empty description="暂无站内信" />
|
||||
<el-empty
|
||||
:description="
|
||||
distributionStore.isDistribution
|
||||
? `暂无【${distributionStore.siteName}】专属站内通知`
|
||||
: '暂无站内信'
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else v-loading="notiLoading" class="notification-list">
|
||||
@@ -442,6 +462,16 @@ function handleTabChange(tab: string) {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.noti-toolbar-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.noti-site-tag {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.noti-toolbar-text {
|
||||
color: #6b7280;
|
||||
font-size: 13px;
|
||||
|
||||
Reference in New Issue
Block a user