完善系统接入诊断与审核状态展示
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import type { SecureIntegrationConfigVO } from '@/api/admin'
|
||||
|
||||
export type ModerationNotice = {
|
||||
type: 'info' | 'warning' | 'error' | 'success'
|
||||
title: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export function buildModerationNotice(config: SecureIntegrationConfigVO | null, statusUnavailable = false): ModerationNotice {
|
||||
if (statusUnavailable) return {
|
||||
type: 'error',
|
||||
title: '无法读取内容审核状态',
|
||||
description: '状态未知时请勿假设微信审核已生效;可重试加载或前往系统设置检查接入配置。'
|
||||
}
|
||||
if (!config) return {
|
||||
type: 'info',
|
||||
title: '正在读取内容审核状态',
|
||||
description: '正在读取当前环境的真实审核渠道和最近探测结果。'
|
||||
}
|
||||
const latest = (config.probeResults || [])
|
||||
.filter(item => item.service === 'CONTENT_MODERATION')
|
||||
.sort((a, b) => String(b.checkedAt || '').localeCompare(String(a.checkedAt || '')))[0]
|
||||
if (config.moderationProvider === 'MOCK' && config.mockProviderAllowed) return {
|
||||
type: 'warning',
|
||||
title: '当前使用本地模拟审核',
|
||||
description: '不会调用微信内容安全接口,仅适用于当前允许模拟的开发环境。正式环境请切换为微信内容安全审核。'
|
||||
}
|
||||
if (config.moderationProvider === 'MOCK') return {
|
||||
type: 'error',
|
||||
title: '当前环境不允许模拟审核',
|
||||
description: '已保存的模拟渠道不能在当前环境生效,内容仍保持隔离。请切换到微信审核或停用后人工处理。'
|
||||
}
|
||||
if (config.moderationProvider === 'DISABLED') return {
|
||||
type: 'error',
|
||||
title: '内容审核未启用',
|
||||
description: '内容会保持隔离,不会自动放行。请在系统设置的服务接入中完成配置。'
|
||||
}
|
||||
if (!config.moderationReady) {
|
||||
const missing = [
|
||||
!config.encryptionKeyConfigured && '服务端加密主密钥',
|
||||
!config.wechatMiniAppConfigured && '小程序 AppID/AppSecret',
|
||||
!config.moderationCallbackTokenConfigured && '回调 Token',
|
||||
!config.moderationEncodingAesKeyConfigured && 'EncodingAESKey',
|
||||
!config.moderationCallbackReady && '公网 HTTPS 回调'
|
||||
].filter(Boolean).join('、')
|
||||
return {
|
||||
type: 'warning',
|
||||
title: '微信内容审核尚未就绪',
|
||||
description: `当前已选择微信审核,但${missing || '配置校验未通过'}。请先完成配置并运行接入测试。`
|
||||
}
|
||||
}
|
||||
const latestText = latest
|
||||
? `最近探测:${probeLabel(latest.status)} · ${latest.summary}(${latest.checkedAt ? new Date(latest.checkedAt).toLocaleString('zh-CN', { hour12: false }) : '暂无时间'})`
|
||||
: '尚未运行接入探测。'
|
||||
return {
|
||||
type: 'success',
|
||||
title: '当前使用微信内容安全审核',
|
||||
description: `内容须通过微信审核后才会公开展示。${latestText}`
|
||||
}
|
||||
}
|
||||
|
||||
function probeLabel(status?: string) {
|
||||
return ({ PASS: '通过', WARN: '需关注', FAIL: '失败', PENDING: '等待回调' } as Record<string, string>)[status || ''] || '未知'
|
||||
}
|
||||
Reference in New Issue
Block a user