重构: 前端架构审查降技术债·i18n收口(高ROI)

- 新建 src/i18n/i18n-helpers.ts: 类型安全 t + currentLocale(any中转内部1处带注释)
- 12文件改 i18n as any 样板收口: utils/time + stores(knowledge/project/{ideas,projects,tasks,workflow}) + composables(aiShared/useAiConversations/useAiEvents/useAiSend/useAiStream/useToolCard)
- as any 22→10(i18n 13→0对外), 签名统一(key, named?)
- useToolCard文档块同步(防AI被过时注释误导)
This commit is contained in:
2026-06-19 12:25:10 +08:00
parent cfae6027d2
commit 11b579eb87
13 changed files with 48 additions and 52 deletions

View File

@@ -11,11 +11,10 @@
* 正确做法:先转 number 再 new Date。本模块统一处理毫秒字符串 / 秒级 / ISO / number / 空。
*/
import i18n from '@/i18n'
import { t, currentLocale } from '@/i18n/i18n-helpers'
// CR-260615-08(P1-10):相对时间走 i18n(原硬编码中文,en locale 时间恒中文)。
// utils 纯函数无 setup,用 vue-i18n 全局实例(参考 useAiEvents.ts:16-25),any 中转规避 TS2589。
const t = ((i18n as any).global.t as (k: string, named?: Record<string, unknown>) => string).bind((i18n as any).global)
// 类型安全访问经 i18n-helpers 收口(规避 vue-i18n TS2589)
/** 解析任意时间值为毫秒时间戳;无效或空返回 null */
export function parseTs(v: string | number | null | undefined): number | null {
@@ -41,7 +40,7 @@ export function formatDate(v: string | number | null | undefined): string {
const ms = parseTs(v)
if (ms == null) return '—'
const d = new Date(ms)
const locale = (i18n as any).global.locale.value === 'en' ? 'en-US' : 'zh-CN'
const locale = currentLocale() === 'en' ? 'en-US' : 'zh-CN'
return d.toLocaleDateString(locale) + ' ' + d.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })
}