Files
JayuCloud/JC-Salon-Frontend/src/utils/moderation-status.ts
T
xiaowang d4fc48bc2a
自动发布开发环境 Nacos 配置 / publish (push) Successful in 20s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 6s
完善系统接入诊断与审核状态展示
2026-11-04 12:39:47 +08:00

65 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 || ''] || '未知'
}