fix: 优化后端数据

This commit is contained in:
Daniel
2026-03-02 16:29:11 +08:00
parent 81628a136a
commit a9caf6e7c0
18 changed files with 295 additions and 15 deletions

35
src/utils/tickerText.ts Normal file
View File

@@ -0,0 +1,35 @@
/**
* 滚动情报文本处理:转为简体中文,过滤非中文内容
*/
import { Converter } from 'opencc-js/t2cn'
const t2s = Converter({ from: 'twp', to: 'cn' })
/** 简体中文字符范围 */
const ZH_REGEX = /[\u4e00-\u9fff]/g
/** 文本中中文占比是否达标至少30% */
export function isMostlyChinese(text: string): boolean {
if (!text?.trim()) return false
const zh = text.match(ZH_REGEX)
const zhCount = zh ? zh.length : 0
return zhCount / text.length >= 0.3
}
/** 繁体转简体 */
export function toSimplifiedChinese(text: string): string {
if (!text?.trim()) return text
try {
return t2s(text)
} catch {
return text
}
}
/** 处理滚动情报项:转为简体,非中文为主则过滤 */
export function processTickerText(text: string): string | null {
const t = (text || '').trim()
if (!t) return null
if (!isMostlyChinese(t)) return null
return toSimplifiedChinese(t)
}