Files
JayuCloud/JC-Salon-Frontend/src/views/admin/PrivacyComplianceView.vue
T

363 lines
18 KiB
Vue
Raw Normal View History

2026-10-22 00:27:12 +08:00
<template>
<div class="privacy-page">
<a-alert
:type="moderationNotice.type"
2026-10-22 00:27:12 +08:00
show-icon
:message="moderationNotice.title"
:description="moderationNotice.description"
2026-10-22 00:27:12 +08:00
class="page-notice"
>
<template #action>
<a-space>
<a-button v-if="integrationStatusError" size="small" @click="loadIntegrationStatus">重试</a-button>
<a-button size="small" @click="openIntegrationSettings">服务接入设置</a-button>
</a-space>
</template>
</a-alert>
2026-10-22 00:27:12 +08:00
<a-tabs v-model:active-key="activeTab" @change="loadActiveTab">
<a-tab-pane key="closures">
<template #tab>
<span class="privacy-tab-title">
账号注销申请
<span v-if="closures.length" class="privacy-tab-count" :aria-label="`${closures.length} 条待处理申请`">
{{ closures.length > 99 ? '99+' : closures.length }}
</span>
</span>
</template>
2026-10-22 00:27:12 +08:00
<a-table :columns="closureColumns" :data-source="closures" :loading="closureLoading" row-key="id" :scroll="{ x: 'max-content' }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'account'">{{ record.nickname }}({{ record.userType === 2 ? '店长' : '员工' }})</template>
<template v-else-if="column.key === 'shops'">{{ (record.shopNames || []).join('、') || '无关联门店' }}</template>
<template v-else-if="column.key === 'time'">{{ record.requestedAt || '-' }}</template>
<template v-else-if="column.key === 'action'">
<a-space>
<a-button type="link" @click="openClosure(record as AccountClosureRequestVO, 'APPROVE')">处理</a-button>
<a-button type="link" danger @click="openClosure(record as AccountClosureRequestVO, 'REJECT')">驳回</a-button>
</a-space>
</template>
</template>
</a-table>
</a-tab-pane>
<a-tab-pane key="moderation">
<template #tab>
<span class="privacy-tab-title">
内容复核
<span v-if="moderation.length" class="privacy-tab-count" :aria-label="`${moderation.length} 条待处理内容`">
{{ moderation.length > 99 ? '99+' : moderation.length }}
</span>
</span>
</template>
<div class="moderation-toolbar">
<span>待处理内容 {{ moderation.length }} 条</span>
<a-button :loading="moderationLoading" @click="loadModeration">刷新列表</a-button>
</div>
2026-10-22 00:27:12 +08:00
<a-table :columns="moderationColumns" :data-source="moderation" :loading="moderationLoading" row-key="id" :scroll="{ x: 'max-content' }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'type'">{{ moderationType(record.contentType) }}</template>
<template v-else-if="column.key === 'content'">
<div class="moderation-content">
<div class="moderation-author">{{ record.authorName || '未知发布者' }}</div>
<pre class="payload-preview">{{ record.textPreview || '无文字内容' }}</pre>
<a-space v-if="record.images?.length" wrap>
<a-image
v-for="image in record.images"
:key="String(image.fileId)"
:src="image.url"
:width="56"
:height="56"
fit="cover"
:preview="Boolean(image.url)"
/>
<span v-if="record.images.some((image: NonNullable<ContentModerationRecordVO['images']>[number]) => !image.url)" class="image-pending">图片预览不可用</span>
</a-space>
</div>
2026-10-22 00:27:12 +08:00
</template>
<template v-else-if="column.key === 'status'">{{ record.status === 'RETRY' ? '待复核(审核服务暂不可用)' : '待复核' }}</template>
2026-10-22 00:27:12 +08:00
<template v-else-if="column.key === 'action'">
<a-space>
<a-button type="link" @click="openModeration(record as ContentModerationRecordVO, true)">通过</a-button>
<a-button type="link" danger @click="openModeration(record as ContentModerationRecordVO, false)">拒绝</a-button>
</a-space>
</template>
</template>
</a-table>
</a-tab-pane>
<a-tab-pane key="backfill" tab="手机号加密回填">
<a-space direction="vertical" size="middle" class="backfill-panel">
<p>先查看冲突和待处理记录数。正式回填仅在 Nacos 显式启用后可执行;检测到重复数据时会整批停止,不覆盖冲突记录。</p>
<a-space>
<a-button :loading="backfillLoading" @click="loadBackfillReport">检查数据</a-button>
<a-button type="primary" danger :disabled="!backfillReport || hasBackfillConflicts" :loading="backfillLoading" @click="runBackfill">执行回填</a-button>
</a-space>
<a-descriptions v-if="backfillReport" bordered :column="2" size="small">
<a-descriptions-item label="待处理账号">{{ backfillReport.userRowsToUpdate }}</a-descriptions-item>
<a-descriptions-item label="待处理订单">{{ backfillReport.orderRowsToUpdate }}</a-descriptions-item>
<a-descriptions-item label="账号冲突">{{ backfillReport.accountConflictRows }}</a-descriptions-item>
<a-descriptions-item label="手机号冲突">{{ backfillReport.phoneConflictRows }}</a-descriptions-item>
</a-descriptions>
<a-alert v-if="backfillReport?.conflictingUserIds?.length" type="error" show-icon message="发现冲突,已禁止执行回填" :description="`涉及账号 ID:${backfillReport.conflictingUserIds.join('、')}`" />
</a-space>
</a-tab-pane>
</a-tabs>
<a-modal v-model:open="closureOpen" :title="closureDecision === 'APPROVE' ? '处理注销申请' : '驳回注销申请'" :confirm-loading="actionLoading" :mask-closable="false" @ok="submitClosure">
<template v-if="closureTarget && closureDecision === 'APPROVE'">
<div v-if="closureTarget.userType === 2 && closureTarget.shopIds?.length" class="closure-shops">
<p>关联门店:{{ (closureTarget.shopNames || []).join('、') }}</p>
<a-radio-group v-model:value="closureMode">
<a-radio value="transfer">移交门店</a-radio>
<a-radio value="archive">归档全部门店</a-radio>
</a-radio-group>
<a-select v-if="closureMode === 'transfer'" v-model:value="successorManagerId" class="full-width" placeholder="选择接手店长" :options="successorOptions" />
</div>
<p v-else>确认清理该账号资料并撤销其会话?必要业务记录会保留并去除账号身份关联。</p>
</template>
<a-form-item :label="closureDecision === 'REJECT' ? '驳回原因' : '处理说明'">
<a-textarea v-model:value="closureNote" :rows="3" :placeholder="closureDecision === 'REJECT' ? '请填写驳回原因' : '可填写处理说明'" />
</a-form-item>
</a-modal>
<a-modal v-model:open="moderationOpen" :title="moderationApproved ? '通过内容复核' : '拒绝内容'" :confirm-loading="actionLoading" :mask-closable="false" @ok="submitModeration">
<p v-if="moderationTarget">{{ moderationType(moderationTarget.contentType) }}内容,记录号 {{ moderationTarget.id }}</p>
<p class="moderation-provider-context">{{ moderationReviewContext }}</p>
<a-form-item label="复核说明"><a-textarea v-model:value="moderationReason" :rows="3" :placeholder="moderationApproved ? '说明本次复核通过原因' : '说明本次拒绝原因'" /></a-form-item>
2026-10-22 00:27:12 +08:00
</a-modal>
</div>
</template>
<script setup lang="ts">
import { computed, onActivated, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
2026-10-22 00:27:12 +08:00
import { message, Modal } from 'ant-design-vue'
import { buildModerationNotice } from '@/utils/moderation-status'
2026-10-22 00:27:12 +08:00
import {
adminPrivacyComplianceApi,
type AccountClosureRequestVO,
type ClosureSuccessorManagerVO,
type ContentModerationRecordVO,
type PhoneBackfillReportVO,
type SecureIntegrationConfigVO
2026-10-22 00:27:12 +08:00
} from '@/api/admin'
import { adminSecureIntegrationConfigApi } from '@/api/admin'
2026-10-22 00:27:12 +08:00
const activeTab = ref('closures')
const closures = ref<AccountClosureRequestVO[]>([])
const moderation = ref<ContentModerationRecordVO[]>([])
const successorManagers = ref<ClosureSuccessorManagerVO[]>([])
const backfillReport = ref<PhoneBackfillReportVO | null>(null)
const closureLoading = ref(false)
const moderationLoading = ref(false)
const backfillLoading = ref(false)
const actionLoading = ref(false)
const closureOpen = ref(false)
const closureTarget = ref<AccountClosureRequestVO | null>(null)
const closureDecision = ref<'APPROVE' | 'REJECT'>('APPROVE')
const closureMode = ref<'transfer' | 'archive'>('transfer')
const successorManagerId = ref<string | number>()
const closureNote = ref('')
const moderationOpen = ref(false)
const moderationTarget = ref<ContentModerationRecordVO | null>(null)
const moderationApproved = ref(false)
const moderationReason = ref('')
const secureIntegration = ref<SecureIntegrationConfigVO | null>(null)
const integrationStatusError = ref(false)
const router = useRouter()
const moderationNotice = computed(() => buildModerationNotice(secureIntegration.value, integrationStatusError.value))
const moderationReviewContext = computed(() => {
if (secureIntegration.value?.moderationProvider === 'WECHAT' && secureIntegration.value.moderationReady) return '当前环境使用微信内容审核;此处用于处理微信要求人工复核或审核服务异常的记录。'
if (secureIntegration.value?.moderationProvider === 'MOCK' && secureIntegration.value.mockProviderAllowed) return '当前环境允许本地模拟审核;此操作不会调用微信内容安全接口。'
return '请依据内容和平台审核规范填写复核说明;审核渠道不可用时,内容仍保持隔离。'
})
2026-10-22 00:27:12 +08:00
const hasBackfillConflicts = computed(() => Boolean(backfillReport.value?.accountConflictRows || backfillReport.value?.phoneConflictRows))
const successorOptions = computed(() => successorManagers.value.map(manager => ({ label: `${manager.nickname || '店长'}(${manager.id})`, value: manager.id })))
const closureColumns = [
{ title: '申请人', key: 'account' },
{ title: '关联门店', key: 'shops' },
{ title: '申请时间', key: 'time' },
{ title: '处理', key: 'action', width: 140 }
]
const moderationColumns = [
{ title: '类型', key: 'type', width: 120 },
{ title: '隔离内容', key: 'content', width: 420 },
{ title: '状态', key: 'status', width: 180 },
{ title: '提交时间', dataIndex: 'createTime', key: 'createTime' },
{ title: '复核', key: 'action', width: 140 }
]
async function loadClosures() {
closureLoading.value = true
try {
const [items, managers] = await Promise.all([
adminPrivacyComplianceApi.listClosures(),
adminPrivacyComplianceApi.listSuccessorManagers()
])
closures.value = items || []
successorManagers.value = managers || []
} catch (error) {
message.error(error instanceof Error ? error.message : '获取注销申请失败')
} finally {
closureLoading.value = false
}
}
async function loadModeration() {
moderationLoading.value = true
try { moderation.value = await adminPrivacyComplianceApi.listModeration() || [] }
catch (error) { message.error(error instanceof Error ? error.message : '获取复核列表失败') }
finally { moderationLoading.value = false }
}
async function loadIntegrationStatus() {
integrationStatusError.value = false
try { secureIntegration.value = await adminSecureIntegrationConfigApi.getConfig() }
catch (error) { integrationStatusError.value = true; message.error(error instanceof Error ? error.message : '读取内容审核状态失败') }
}
function openIntegrationSettings() {
void router.push({ path: '/admin/settings', query: { section: 'services' } })
}
2026-10-22 00:27:12 +08:00
function loadActiveTab() {
if (activeTab.value === 'closures') void loadClosures()
if (activeTab.value === 'moderation') void loadModeration()
if (activeTab.value === 'backfill') void loadBackfillReport()
}
function openClosure(record: AccountClosureRequestVO, decision: 'APPROVE' | 'REJECT') {
closureTarget.value = record
closureDecision.value = decision
closureMode.value = 'transfer'
successorManagerId.value = undefined
closureNote.value = decision === 'REJECT' ? '' : '已完成门店交接或归档,并按要求清理账号资料。'
closureOpen.value = true
}
async function submitClosure() {
if (!closureTarget.value) return
if (closureDecision.value === 'REJECT' && !closureNote.value.trim()) {
message.warning('请填写驳回原因')
return
}
const managerHasShops = closureDecision.value === 'APPROVE' && closureTarget.value.userType === 2 && (closureTarget.value.shopIds || []).length > 0
if (managerHasShops && closureMode.value === 'transfer' && !successorManagerId.value) {
message.warning('请选择接手店长')
return
}
if (managerHasShops && closureMode.value === 'archive' && !(await confirmArchive())) return
actionLoading.value = true
try {
await adminPrivacyComplianceApi.processClosure(closureTarget.value.id, {
decision: closureDecision.value,
successorManagerId: managerHasShops && closureMode.value === 'transfer' ? successorManagerId.value : undefined,
archiveShopIds: managerHasShops && closureMode.value === 'archive' ? closureTarget.value.shopIds : undefined,
note: closureNote.value.trim() || undefined
})
message.success(closureDecision.value === 'APPROVE' ? '账号资料已处理' : '申请已驳回')
closureOpen.value = false
await loadClosures()
} catch (error) { message.error(error instanceof Error ? error.message : '处理失败') }
finally { actionLoading.value = false }
}
function confirmArchive() {
return new Promise<boolean>(resolve => Modal.confirm({
title: '确认归档全部门店?',
content: '归档后关联门店将停止营业,请确认已完成必要交接。',
okText: '确认归档',
cancelText: '返回',
onOk: () => resolve(true),
onCancel: () => resolve(false)
}))
}
function openModeration(record: ContentModerationRecordVO, approved: boolean) {
moderationTarget.value = record
moderationApproved.value = approved
moderationReason.value = approved
? secureIntegration.value?.moderationProvider === 'MOCK' && secureIntegration.value.mockProviderAllowed ? '本地模拟复核通过。' : '经管理员复核,内容符合平台规范。'
: ''
2026-10-22 00:27:12 +08:00
moderationOpen.value = true
}
async function submitModeration() {
if (!moderationTarget.value) return
if (!moderationReason.value.trim()) {
message.warning('请填写复核说明')
return
}
actionLoading.value = true
try {
await adminPrivacyComplianceApi.reviewContent(moderationTarget.value.id, { approved: moderationApproved.value, reason: moderationReason.value.trim() })
message.success(moderationApproved.value ? '内容已通过复核' : '内容已拒绝')
moderationOpen.value = false
await loadModeration()
} catch (error) { message.error(error instanceof Error ? error.message : '复核失败') }
finally { actionLoading.value = false }
}
async function loadBackfillReport() {
backfillLoading.value = true
try { backfillReport.value = await adminPrivacyComplianceApi.phoneBackfillReport() }
catch (error) { message.error(error instanceof Error ? error.message : '检查失败') }
finally { backfillLoading.value = false }
}
function runBackfill() {
Modal.confirm({
title: '执行手机号加密回填?',
content: '该操作只更新无重复冲突的历史账号和订单手机号。请确认已在目标环境 Nacos 显式开启回填开关。',
okText: '执行回填',
cancelText: '取消',
onOk: async () => {
backfillLoading.value = true
try {
backfillReport.value = await adminPrivacyComplianceApi.runPhoneBackfill()
message.success(`回填完成:账号 ${backfillReport.value.userRowsUpdated} 条,订单 ${backfillReport.value.orderRowsUpdated} 条`)
} catch (error) { message.error(error instanceof Error ? error.message : '回填失败') }
finally { backfillLoading.value = false }
}
})
}
function moderationType(type: string) {
return ({ USER_PROFILE: '个人资料', USER_AVATAR: '头像', PRODUCT: '作品', EFFECT_DIAGRAM: '效果图', COMMENT: '评论', ORDER_ARTIST_REVIEW: '订单评价', SHOP: '门店资料', ANNOUNCEMENT: '公告', SYSTEM_MESSAGE: '系统消息' } as Record<string, string>)[type] || type
2026-10-22 00:27:12 +08:00
}
let skipInitialActivationRefresh = true
onMounted(() => {
void loadClosures()
void loadModeration()
void loadIntegrationStatus()
})
onActivated(() => {
if (skipInitialActivationRefresh) {
skipInitialActivationRefresh = false
return
}
void loadClosures()
void loadModeration()
void loadIntegrationStatus()
})
2026-10-22 00:27:12 +08:00
</script>
<style scoped>
.privacy-page { display: grid; gap: 16px; }
.page-notice { border-radius: 8px; }
.privacy-tab-title { display: inline-flex; align-items: center; gap: 8px; }
.privacy-tab-count { display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px; align-items: center; justify-content: center; border-radius: 10px; background: var(--ant-color-error); color: #fff; font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 600; line-height: 1; }
.moderation-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; color: var(--ant-color-text-secondary); font-size: 13px; }
2026-10-22 00:27:12 +08:00
.payload-preview { max-width: 420px; max-height: 180px; margin: 0; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12px; }
.moderation-content { display: grid; gap: 6px; }
.moderation-author { color: var(--ant-color-text-secondary); font-size: 12px; }
.moderation-provider-context { color: var(--ant-color-text-secondary); font-size: 12px; line-height: 1.55; }
.image-pending { color: var(--ant-color-text-secondary); font-size: 12px; }
2026-10-22 00:27:12 +08:00
.backfill-panel { width: 100%; padding: 8px 0; }
.closure-shops { display: grid; gap: 12px; margin-bottom: 16px; }
.closure-shops p { margin: 0; }
.full-width { width: 100%; margin-top: 12px; }
</style>