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:
@@ -1,4 +1,5 @@
|
||||
/** API 响应解包与错误归一化(任务 22):纯函数,无框架依赖(只借 config/app 的 base 常量)。 */
|
||||
import { userNotice } from './user-notice.ts'
|
||||
import { joinAdminPath } from '../config/app.ts'
|
||||
|
||||
export const REQUEST_FALLBACK_MESSAGE = '网络异常,请稍后重试'
|
||||
@@ -6,8 +7,8 @@ export const REQUEST_FALLBACK_MESSAGE = '网络异常,请稍后重试'
|
||||
function textOf(value: Record<string, unknown>): string {
|
||||
const message = value.message
|
||||
const error = value.error
|
||||
if (typeof message === 'string' && message.trim()) return message.trim()
|
||||
if (typeof error === 'string' && error.trim()) return error.trim()
|
||||
if (typeof message === 'string' && message.trim()) return userNotice(message)
|
||||
if (typeof error === 'string' && error.trim()) return userNotice(error)
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -31,12 +32,12 @@ export function unwrap<T>(payload: unknown): T {
|
||||
|
||||
/** 从任意负载取错误文案;缺省回退。 */
|
||||
export function errorTextOf(payload: unknown): string {
|
||||
if (payload instanceof Error) return payload.message.trim() || REQUEST_FALLBACK_MESSAGE
|
||||
if (payload instanceof Error) return userNotice(payload.message, REQUEST_FALLBACK_MESSAGE)
|
||||
if (payload && typeof payload === 'object') {
|
||||
const text = textOf(payload as Record<string, unknown>)
|
||||
if (text) return text
|
||||
}
|
||||
if (typeof payload === 'string' && payload.trim()) return payload.trim()
|
||||
if (typeof payload === 'string' && payload.trim()) return payload
|
||||
return REQUEST_FALLBACK_MESSAGE
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 后台提示语把关(2026-10-09):只把中文给用户看。
|
||||
*
|
||||
* Java 侧仍有出口把底层异常原文写进 message/errorMessage,后台同学看到
|
||||
* `Invalid export date range` 这类句子既看不懂也没法转述给用户。这里统一换成中文兜底句,
|
||||
* 原文进 console 供对着日志核对。
|
||||
*/
|
||||
|
||||
const CJK = /[\u3400-\u4dbf\u4e00-\u9fff]/
|
||||
|
||||
export const NOTICE_FALLBACK = '操作未能完成,请稍后重试'
|
||||
|
||||
export function userNotice(text?: string | null, fallback: string = NOTICE_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
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
* 页签二「变体采集」= 麦象批量任务(variant-collection),数据口径与列不同故独立页签。
|
||||
* 30s 轮询:页面隐藏暂停、回前台立即刷新、卸载清理;另有手动刷新。 */
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import { userNotice } from '@/api/user-notice'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
@@ -579,7 +580,7 @@ onUnmounted(() => {
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="当前处理">{{ currentScopeOf(detail) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="错误信息" :span="2">{{ detail.errorMessage || detail.message || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="错误信息" :span="2">{{ userNotice(detail.errorMessage || detail.message, '—') }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<h4 class="detail-title">分组明细({{ (detail.shops || []).length }} 组)</h4>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { userNotice } from '@/api/user-notice'
|
||||
/** 视频任务记录页 · 像素复刻旧版 admin.html panel-image-video-tasks(自绘:form-box 筛选[用户名/提交起止+查询/重置] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 任务卡片网格 + 旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(批量打包/明细抽屉/权限授权)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -394,7 +395,7 @@ onMounted(load)
|
||||
<el-descriptions-item label="提交时间">{{ formatDateTime(detail.submittedAt) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="生成时间">{{ formatDateTime(imageVideoGeneratedAt(detail)) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="执行ID">{{ detail.cozeExecuteId || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="错误">{{ detail.errorMessage || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="错误">{{ userNotice(detail.errorMessage, '—') }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 237,
|
||||
"cases": 1703,
|
||||
"files": 238,
|
||||
"cases": 1707,
|
||||
"pins": 436,
|
||||
"reads": 620
|
||||
"reads": 621
|
||||
},
|
||||
"files": {
|
||||
"admin-scaffold.test.ts": {
|
||||
@@ -1191,6 +1191,11 @@
|
||||
"cases": 7,
|
||||
"pins": 2,
|
||||
"reads": 2
|
||||
},
|
||||
"user-notice-chinese-only.test.ts": {
|
||||
"cases": 4,
|
||||
"pins": 0,
|
||||
"reads": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,9 @@ test('test_task_022_envelope_rules_boundary_limit_or_missing_field', () => {
|
||||
// 边界上限/缺字段:success=false 且 message 缺失回落到通用失败。
|
||||
assert.throws(() => unwrap({ success: false }), /请求失败/)
|
||||
assert.equal(errorTextOf({ error: '权限不足' }), '权限不足')
|
||||
assert.equal(errorTextOf({ message: '', error: 'X' }), 'X')
|
||||
assert.equal(errorTextOf({ message: '', error: '参数不对' }), '参数不对')
|
||||
// 英文原文不透出:同一条空 message + 英文 error 只会给到中文兜底句
|
||||
assert.equal(errorTextOf({ message: '', error: 'Invalid export date range' }), '操作未能完成,请稍后重试')
|
||||
})
|
||||
|
||||
test('test_task_022_envelope_rules_invalid_input_rejected', () => {
|
||||
@@ -58,7 +60,8 @@ test('test_task_022_envelope_rules_invalid_input_rejected', () => {
|
||||
assert.equal(isUnauthorized({ statusCode: 401 }), true)
|
||||
assert.equal(isUnauthorized({ code: 403 }), false)
|
||||
assert.equal(isUnauthorized(null), false)
|
||||
assert.equal(requestErrorMessage(new Error('Network Error')), 'Network Error')
|
||||
assert.equal(requestErrorMessage(new Error('网络连接不上')), '网络连接不上')
|
||||
assert.equal(requestErrorMessage(new Error('Network Error')), '网络异常,请稍后重试')
|
||||
})
|
||||
|
||||
test('test_task_022_envelope_rules_dependency_failure_returns_actionable_message', () => {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { resolve, dirname } from 'node:path'
|
||||
import { errorTextOf, requestErrorMessage, unwrap } from '../src/api/envelope.ts'
|
||||
import { userNotice, NOTICE_FALLBACK } from '../src/api/user-notice.ts'
|
||||
|
||||
/**
|
||||
* 后台中文文案尺子(2026-10-09)。
|
||||
*
|
||||
* 起因:去重库导出失败时后台弹的是 `invalid export date range`,客服照着这句话没法回答用户,
|
||||
* 也没法判断是不是自己的操作问题。写侧已把这几句改成中文,这里钉两件事:
|
||||
* ① 解包出口(textOf / errorTextOf)不许再把非中文原文透出;② 模板里直接渲染 errorMessage
|
||||
* 的两处必须过 userNotice。
|
||||
*/
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
function read(rel: string): string {
|
||||
return readFileSync(resolve(here, '../src', rel), 'utf-8')
|
||||
}
|
||||
|
||||
test('userNotice 放行中文、替换英文', () => {
|
||||
assert.equal(userNotice('导出的日期范围不对'), '导出的日期范围不对')
|
||||
assert.equal(userNotice('export dedupe total data failed'), NOTICE_FALLBACK)
|
||||
assert.equal(userNotice('', '默认句'), '默认句')
|
||||
// 库里存的是"中文主干: 底层英文原文",界面上只留主干
|
||||
assert.equal(userNotice('去重结果打包失败: Broken pipe'), '去重结果打包失败')
|
||||
})
|
||||
|
||||
test('响应体里的英文原文不会从解包出口透出', () => {
|
||||
assert.equal(requestErrorMessage({ response: { data: { message: 'Invalid export date range' } } }), NOTICE_FALLBACK)
|
||||
const fromError = requestErrorMessage(new Error('Internal Server Error'))
|
||||
assert.ok(!/^[A-Za-z]/.test(fromError), `axios/Error 原文仍被透出: ${fromError}`)
|
||||
assert.ok(/[㐀-䶿一-鿿]/.test(fromError), `兜底句必须是中文: ${fromError}`)
|
||||
assert.equal(requestErrorMessage({ response: { data: { error: 'MinIO 连接被拒绝' } } }), 'MinIO 连接被拒绝')
|
||||
})
|
||||
|
||||
test('unwrap 抛出的错误也是中文', () => {
|
||||
assert.throws(() => unwrap({ success: false, message: 'Coze workflow finished with status FAILED' }),
|
||||
(err: unknown) => {
|
||||
assert.ok(err instanceof Error)
|
||||
assert.ok(!/^[A-Za-z]/.test(err.message), `抛给界面的还是英文: ${err.message}`)
|
||||
return true
|
||||
})
|
||||
assert.doesNotThrow(() => unwrap({ success: true, data: 1 }))
|
||||
})
|
||||
|
||||
test('直接渲染错误字段的模板已过闸', () => {
|
||||
const sites: Array<[string, string]> = [
|
||||
['pages/task-center/TaskCenterBoardPage.vue', 'detail.errorMessage || detail.message'],
|
||||
['pages/tasks/ImageVideoTasksPage.vue', 'detail.errorMessage'],
|
||||
]
|
||||
for (const [file, needle] of sites) {
|
||||
const source = read(file)
|
||||
const line = source.split(/\r?\n/).find((l) => l.includes(needle) && l.includes('{{'))
|
||||
assert.ok(line, `${file} 里找不到渲染 ${needle} 的那一行——改动没落地或字段名变了`)
|
||||
assert.ok(line.includes('userNotice('), `${file}: ${needle} 仍被直接渲染进界面`)
|
||||
assert.ok(source.includes('user-notice'), `${file} 缺 userNotice 的 import`)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user