feat(compliance): add content compliance detection across tenant, ops, and clients
Implements the Revision 8/9 compliance design: tenant + ops backends, ops-web content-safety pages, admin-web editor/publish gate integration, desktop publish block surfacing, and supporting migrations / shared types / config plumbing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import {
|
||||
CloseOutlined,
|
||||
LeftOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
import type { ComplianceCheckResult, ComplianceViolation } from '@geo/shared-types'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
@@ -8,9 +14,13 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import ArticleEditorCanvas from '@/components/ArticleEditorCanvas.vue'
|
||||
import PublishArticleModal from '@/components/PublishArticleModal.vue'
|
||||
import { articlesApi } from '@/lib/api'
|
||||
import { articlesApi, complianceApi } from '@/lib/api'
|
||||
import { formatError } from '@/lib/errors'
|
||||
|
||||
type EditorCanvasPublic = InstanceType<typeof ArticleEditorCanvas> & {
|
||||
scrollToText?: (text: string) => boolean
|
||||
}
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -23,6 +33,9 @@ const initialTitle = ref('')
|
||||
const initialMarkdown = ref('')
|
||||
const leaveModalOpen = ref(false)
|
||||
const publishModalOpen = ref(false)
|
||||
const compliancePanelOpen = ref(false)
|
||||
const editorComplianceResult = ref<ComplianceCheckResult | null>(null)
|
||||
const editorCanvasRef = ref<EditorCanvasPublic | null>(null)
|
||||
|
||||
const detailQuery = useQuery({
|
||||
queryKey: computed(() => ['articles', 'detail', articleId.value]),
|
||||
@@ -91,6 +104,18 @@ const saveDisabled = computed(
|
||||
title.value.trim() === '' ||
|
||||
!hasChanges.value,
|
||||
)
|
||||
const complianceCheckLoading = ref(false)
|
||||
const editorComplianceViolations = computed(() =>
|
||||
compliancePanelOpen.value ? (editorComplianceResult.value?.violations ?? []) : [],
|
||||
)
|
||||
const complianceGroups = computed(() => groupViolations(editorComplianceResult.value?.violations ?? []))
|
||||
const complianceElapsedLabel = computed(() => {
|
||||
const duration = editorComplianceResult.value?.duration_ms ?? 0
|
||||
return duration > 0 ? `${duration} ms` : '< 1 ms'
|
||||
})
|
||||
const complianceDecisionTone = computed(() =>
|
||||
(editorComplianceResult.value?.hit_count ?? 0) > 0 ? 'warning' : 'success',
|
||||
)
|
||||
const leaveSaveDisabled = computed(
|
||||
() => editorLocked.value || saveMutation.isPending.value || title.value.trim() === '',
|
||||
)
|
||||
@@ -146,6 +171,120 @@ async function handlePublish(): Promise<void> {
|
||||
publishModalOpen.value = true
|
||||
}
|
||||
|
||||
async function handleComplianceCheck(): Promise<void> {
|
||||
if (editorLocked.value || complianceCheckLoading.value) {
|
||||
return
|
||||
}
|
||||
|
||||
if (hasChanges.value && !saveMutation.isPending.value) {
|
||||
try {
|
||||
await saveMutation.mutateAsync()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
complianceCheckLoading.value = true
|
||||
try {
|
||||
const currentDetail = (await detailQuery.refetch()).data ?? detail.value
|
||||
const versionId = currentDetail?.current_version_id ?? null
|
||||
const result = await complianceApi.checkArticle(articleId.value, {
|
||||
article_version_id: versionId,
|
||||
title: title.value.trim(),
|
||||
plaintext: markdown.value,
|
||||
target_platforms: [],
|
||||
trigger_source: 'editor_manual',
|
||||
})
|
||||
editorComplianceResult.value = result
|
||||
compliancePanelOpen.value = true
|
||||
if (result.hit_count > 0) {
|
||||
message.warning(`发现 ${result.hit_count} 条合规风险`)
|
||||
} else {
|
||||
message.success('合规检测通过')
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(formatError(error))
|
||||
} finally {
|
||||
complianceCheckLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function closeCompliancePanel(): void {
|
||||
compliancePanelOpen.value = false
|
||||
}
|
||||
|
||||
function focusViolation(violation: ComplianceViolation): void {
|
||||
const ok = editorCanvasRef.value?.scrollToText?.(violation.matched_text)
|
||||
if (!ok) {
|
||||
message.info('未能在当前编辑器内容中定位该命中片段')
|
||||
}
|
||||
}
|
||||
|
||||
function groupViolations(violations: ComplianceViolation[]) {
|
||||
const groups = new Map<string, ComplianceViolation[]>()
|
||||
for (const violation of violations) {
|
||||
const key = violation.platform_code || 'all'
|
||||
const list = groups.get(key) ?? []
|
||||
list.push(violation)
|
||||
groups.set(key, list)
|
||||
}
|
||||
return Array.from(groups.entries()).map(([key, items]) => ({ key, items }))
|
||||
}
|
||||
|
||||
function violationGroupTitle(key: string): string {
|
||||
return key === 'all' ? '全部平台共用规则' : `平台规则:${key}`
|
||||
}
|
||||
|
||||
function violationKey(violation: ComplianceViolation): string {
|
||||
return [
|
||||
violation.id || 0,
|
||||
violation.source,
|
||||
violation.platform_code ?? 'all',
|
||||
violation.start_offset,
|
||||
violation.end_offset,
|
||||
violation.matched_text,
|
||||
].join(':')
|
||||
}
|
||||
|
||||
function levelColor(level: ComplianceViolation['level']): string {
|
||||
switch (level) {
|
||||
case 'block':
|
||||
return 'red'
|
||||
case 'high':
|
||||
return 'orange'
|
||||
case 'medium':
|
||||
return 'gold'
|
||||
default:
|
||||
return 'blue'
|
||||
}
|
||||
}
|
||||
|
||||
function levelLabel(level: ComplianceViolation['level']): string {
|
||||
switch (level) {
|
||||
case 'block':
|
||||
return '重点风险'
|
||||
case 'high':
|
||||
return '高风险'
|
||||
case 'medium':
|
||||
return '中风险'
|
||||
default:
|
||||
return '提示'
|
||||
}
|
||||
}
|
||||
|
||||
function sourceLabel(source: ComplianceViolation['source']): string {
|
||||
switch (source) {
|
||||
case 'dict':
|
||||
return '词库'
|
||||
case 'regex':
|
||||
return '正则'
|
||||
case 'llm':
|
||||
return 'LLM'
|
||||
default:
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadEditorImage(file: File): Promise<string> {
|
||||
const result = await articlesApi.uploadImage(articleId.value, file)
|
||||
return result.url
|
||||
@@ -287,6 +426,14 @@ onBeforeUnmount(() => {
|
||||
</button>
|
||||
|
||||
<div class="article-editor-view__actions">
|
||||
<a-button
|
||||
:disabled="editorLocked"
|
||||
:loading="complianceCheckLoading"
|
||||
@click="handleComplianceCheck"
|
||||
>
|
||||
<template #icon><SafetyCertificateOutlined /></template>
|
||||
合规检测
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="saveDisabled"
|
||||
:loading="saveMutation.isPending.value"
|
||||
@@ -314,17 +461,101 @@ onBeforeUnmount(() => {
|
||||
show-icon
|
||||
:message="t('article.editor.messages.locked')"
|
||||
/>
|
||||
<div class="article-editor-view__layout">
|
||||
<div
|
||||
class="article-editor-view__layout"
|
||||
:class="{ 'article-editor-view__layout--with-compliance': compliancePanelOpen }"
|
||||
>
|
||||
<section class="article-editor-view__main">
|
||||
<ArticleEditorCanvas
|
||||
ref="editorCanvasRef"
|
||||
:key="String(articleId)"
|
||||
v-model:title="title"
|
||||
v-model="markdown"
|
||||
:article-id="articleId"
|
||||
:disabled="editorLocked"
|
||||
:upload-image="uploadEditorImage"
|
||||
:compliance-violations="editorComplianceViolations"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<aside
|
||||
v-if="compliancePanelOpen"
|
||||
class="article-editor-view__compliance-panel"
|
||||
aria-label="内容合规检测"
|
||||
>
|
||||
<div class="article-editor-view__compliance-panel-head">
|
||||
<h2>内容合规检测</h2>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
aria-label="关闭合规检测"
|
||||
@click="closeCompliancePanel"
|
||||
>
|
||||
<template #icon><CloseOutlined /></template>
|
||||
</a-button>
|
||||
</div>
|
||||
|
||||
<template v-if="editorComplianceResult">
|
||||
<a-alert
|
||||
show-icon
|
||||
:type="complianceDecisionTone"
|
||||
:message="
|
||||
editorComplianceResult.hit_count > 0
|
||||
? `发现 ${editorComplianceResult.hit_count} 条风险,仅供编辑参考`
|
||||
: '当前版本未发现合规风险'
|
||||
"
|
||||
:description="
|
||||
editorComplianceResult.truncated
|
||||
? '命中明细已达到保存上限,请优先处理高风险词条后重新检测。'
|
||||
: undefined
|
||||
"
|
||||
/>
|
||||
|
||||
<div class="article-editor-view__compliance-meta">
|
||||
<a-tag :color="editorComplianceResult.hit_count > 0 ? 'orange' : 'green'">
|
||||
{{ editorComplianceResult.hit_count > 0 ? '发现风险' : '检测通过' }}
|
||||
</a-tag>
|
||||
<span>耗时 {{ complianceElapsedLabel }}</span>
|
||||
</div>
|
||||
|
||||
<a-empty v-if="!complianceGroups.length" description="没有命中项" />
|
||||
|
||||
<section
|
||||
v-for="group in complianceGroups"
|
||||
v-else
|
||||
:key="group.key"
|
||||
class="article-editor-view__violation-group"
|
||||
>
|
||||
<h3>{{ violationGroupTitle(group.key) }}</h3>
|
||||
<article
|
||||
v-for="violation in group.items"
|
||||
:key="violationKey(violation)"
|
||||
class="article-editor-view__violation"
|
||||
>
|
||||
<div class="article-editor-view__violation-head">
|
||||
<a-tag :color="levelColor(violation.level)">
|
||||
{{ levelLabel(violation.level) }}
|
||||
</a-tag>
|
||||
<a-tag>{{ sourceLabel(violation.source) }}</a-tag>
|
||||
<strong>{{ violation.matched_text }}</strong>
|
||||
</div>
|
||||
<p v-if="violation.dictionary_name || violation.term_pattern">
|
||||
{{ violation.dictionary_name || '词库规则' }}
|
||||
<span v-if="violation.term_pattern"> · {{ violation.term_pattern }}</span>
|
||||
</p>
|
||||
<p v-if="violation.hint">{{ violation.hint }}</p>
|
||||
<div class="article-editor-view__violation-actions">
|
||||
<a-button size="small" @click="focusViolation(violation)">
|
||||
<template #icon><SearchOutlined /></template>
|
||||
定位
|
||||
</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<a-empty v-else description="还没有检测结果" />
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -433,14 +664,112 @@ onBeforeUnmount(() => {
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.article-editor-view__layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.article-editor-view__layout--with-compliance {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.article-editor-view__compliance-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
height: calc(100vh - 180px);
|
||||
overflow-y: auto;
|
||||
padding: 18px;
|
||||
border: 1px solid rgba(216, 225, 237, 0.9);
|
||||
border-radius: 24px;
|
||||
background: rgba(255, 255, 255, 0.94);
|
||||
box-shadow: 0 18px 40px rgba(15, 23, 42, 0.05);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.article-editor-view__compliance-panel-head {
|
||||
position: sticky;
|
||||
top: -18px;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin: -18px -18px 16px;
|
||||
padding: 16px 16px 14px 18px;
|
||||
border-bottom: 1px solid #eef2f8;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.article-editor-view__compliance-panel-head h2 {
|
||||
margin: 0;
|
||||
color: #111827;
|
||||
font-size: 16px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.article-editor-view__leave-copy {
|
||||
margin: 0;
|
||||
color: #475467;
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.article-editor-view__layout {
|
||||
min-width: 0;
|
||||
.article-editor-view__compliance-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
margin: 16px 0 18px;
|
||||
color: #667085;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.article-editor-view__violation-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.article-editor-view__violation-group h3 {
|
||||
margin: 0;
|
||||
color: #111827;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.article-editor-view__violation {
|
||||
padding: 14px;
|
||||
border: 1px solid #e6edf5;
|
||||
border-radius: 12px;
|
||||
background: #fbfcff;
|
||||
}
|
||||
|
||||
.article-editor-view__violation-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.article-editor-view__violation-head strong {
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.article-editor-view__violation p {
|
||||
margin: 10px 0 0;
|
||||
color: #667085;
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.article-editor-view__violation-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.article-editor-view__main {
|
||||
@@ -449,6 +778,22 @@ onBeforeUnmount(() => {
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.article-editor-view__layout--with-compliance {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.article-editor-view__layout--with-compliance {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.article-editor-view__compliance-panel {
|
||||
height: min(560px, calc(100vh - 180px));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.article-editor-view__topbar {
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user