fix(界面文案): 前端两棵树加 userNotice 闸——非中文提示语一律换成中文句

后端仍有出口把底层异常原文写进 error_message / fileError / 匹配原因 / 响应 message,逐条翻译
跟不上新增;用户 2026-10-09 要求整个项目的提示语都用中文,所以把规矩做进界面出口。

规则:原文含中文照原样透出;整条无中文换成中文兜底句;**含中文但冒号后是纯英文尾巴的剥掉尾巴**
("转换结果打包失败: No space left on device" 只留主干)。被隐去的原文进 console 供核对日志。

闸口:用户端 http.ts 的 extractErrorMessage 五条返回路径与 unwrapJavaResponse、后台 envelope 的
textOf/errorTextOf、13 处任务卡 `错误:${item.error}`、2 处 fileError 兜底句、发布页文件错误与
匹配原因函数、dispatch-guard 的解析失败原因清单、22 处 ElMessage.error(result.error) 型展示、
后台看板与数字人详情页两处模板。

尺子:frontend-vue/tests/user-notice-chinese-only-guard.test.ts、admin-frontend-vue/tests/user-notice-chinese-only.test.ts
(分母硬钉+内存造违例自证+摘壳写法仍计入分母);source-pin 台账只登记本轮新增那一个文件,
别人的在飞格子没重算。node --test 用户端 782/782、后台 1782/1782,两棵树 vue-tsc 均 rc=0。
This commit is contained in:
2026-10-09 19:34:54 +08:00
parent 2a4d15b801
commit 282ad7be9f
34 changed files with 396 additions and 78 deletions
+8 -5
View File
@@ -6,6 +6,9 @@ import axios, {
type InternalAxiosRequestConfig,
} from 'axios'
import { authReasonOf, handleKicked, handleSessionExpired, isKickedPayload, isUnauthorizedPayload } from '../auth/kick-handler.ts'
import { userNotice } from '../utils/user-notice.ts'
const REQUEST_FALLBACK = '请求未能完成,请稍后重试'
export interface LegacyApiSuccess<T> {
success: true
@@ -35,20 +38,20 @@ export function extractErrorMessage(error: unknown) {
if (field in data && typeof (data as Record<string, unknown>)[field] === 'string') {
const value = ((data as Record<string, string>)[field]).trim()
if (value) {
return value
return userNotice(value, REQUEST_FALLBACK)
}
}
}
}
if (typeof data === 'string' && data.trim()) {
return data
return userNotice(data, REQUEST_FALLBACK)
}
return error.message || '请求失败'
return userNotice(error.message, '请求失败')
}
return error instanceof Error ? error.message : '请求失败'
return error instanceof Error ? userNotice(error.message, '请求失败') : '请求失败'
}
/** 从 axios 错误对象里取响应体(兼容真实 AxiosError 与测试桩)。 */
@@ -166,7 +169,7 @@ export const requestDeleteJson = del
export async function unwrapJavaResponse<T>(promise: Promise<JavaApiResponse<T>>) {
const response = await promise
if (!response.success) {
throw new Error(response.message || '请求失败')
throw new Error(userNotice(response.message, '请求失败'))
}
return response.data as T
}
@@ -20,6 +20,7 @@
<script setup lang="ts">
import { ref } from 'vue'
import { userNotice } from '@/shared/utils/user-notice'
import { ElMessage } from 'element-plus'
import {
@@ -67,7 +68,7 @@ async function downloadTemplate() {
if (result.success) {
ElMessage.success(`已保存:${result.path || props.filename}`)
} else if (result.error && result.error !== '用户取消') {
ElMessage.error(result.error)
ElMessage.error(userNotice(result.error))
}
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '模板下载失败')
@@ -1,4 +1,5 @@
import { computed, ref, type ComputedRef, type Ref } from 'vue'
import { userNotice } from '../utils/user-notice.ts'
import { ElMessage } from 'element-plus'
import { getTaskPollIntervalMs } from '../task-progress-config.ts'
import { createCategorizedTimers } from '../utils/categorized-timers.ts'
@@ -638,7 +639,7 @@ export function useLiveTaskBoard<T extends LiveTaskHistoryItem>(
if (result.success) {
ElMessage.success(`已保存: ${result.path || filename}`)
} else if (result.error && result.error !== '用户取消') {
ElMessage.error(result.error)
ElMessage.error(userNotice(result.error))
}
}
+2 -1
View File
@@ -18,6 +18,7 @@
* 纯 TS 无副作用模块:不引入 Vue / Element Plus,输入对象永不修改,任何输入
* 都返回 GuardResult 而不抛错(弹窗文案由 dispatch-guard-ui 负责渲染)。
*/
import { userNotice } from './utils/user-notice.ts'
/** block:必须修数据,禁止继续;confirm:可疑但可继续,需用户确认 */
export type GuardSeverity = 'block' | 'confirm'
@@ -348,7 +349,7 @@ export function checkParseResult(
severity: 'block',
message:
'以下文件解析未通过,没有可执行的数据行:\n' +
shown.map((item) => `· ${item}`).join('\n') +
shown.map((item) => `· ${userNotice(item)}`).join('\n') +
(fileErrors.length > shown.length
? `\n· 另有 ${fileErrors.length - shown.length} 条不同原因`
: '') +
@@ -0,0 +1,33 @@
/**
* 用户可见提示语把关(2026-10-09 收口)。
*
* 后端仍有大量出口把底层异常原文写进 error_message / fileError / 匹配原因等字段,
* 逐条翻译跟不上新增速度。这里按"只把中文给用户看"收口:原文含中文照原样透出,
* 纯英文(Java 栈名、Coze/MinIO 报错、`Network Error` 这类 axios 文案)一律换成中文兜底句,
* 原文只进 console,供支持同学对着后端日志核对。
*/
const CJK = /[㐀-䶿一-鿿]/
const DEFAULT_FALLBACK = '操作未能完成,请稍后重试'
export function userNotice(text?: string | null, fallback: string = DEFAULT_FALLBACK): string {
const raw = typeof text === 'string' ? text.trim() : ''
if (!raw) {
return fallback
}
if (!CJK.test(raw)) {
console.warn('[user-notice] 提示语原文不是中文,已换成中文兜底句,原文:', raw)
return fallback
}
// 中文主干 + 英文尾巴(后端把底层异常原文拼在冒号后):留主干,尾巴只进 console
const at = Math.max(raw.lastIndexOf(':'), raw.lastIndexOf(':'))
if (at > 0 && !CJK.test(raw.slice(at + 1))) {
const head = raw.slice(0, at).trim()
if (CJK.test(head)) {
console.warn('[user-notice] 提示语尾巴是英文,已隐去,原文:', raw)
return head
}
}
return raw
}