mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-06-04 23:29:47 +08:00
feat(ux): toast 智能行动按钮 + 拓展 ⓘ 到 gateway/agents + sidebar 加术语表入口
延续上一轮小白 UX 改造的尾声三连:
## 1. toast 智能行动按钮(U2 收尾)
- humanizeError 输出新增 action 字段:{ label, route?, handler?, kind }
- 自动按错误 kind 给默认按钮:
· gatewayDown → [去启动 Gateway] → /services
· cmdMissing / permission → [打开设置] → /settings
· auth → [检查 API Key] → /models
· network / timeout / rateLimit / generic → 不给(重试由用户控制)
- toast 结构化分支渲染 .toast-action-btn 按钮,点击后用 navigate(route) 或调 handler,并自动关闭 toast
- common.js 加 errorAction.* 三个按钮文案 i18n(11 语言)
## 2. ⓘ 拓展到 gateway / agents
- gateway.js: token label 后加 ⓘ(apikey 术语),renderConfig 末尾 attachTermTooltips
- agents.js: addAgent 弹窗 workspace 字段 label 加 ⓘ,setTimeout 扫 document.body 绑定
- term-tooltip.js 精简表新增 4 个术语:workspace / provider / baseurl + scope(已有)
## 3. sidebar 加术语表入口
- 在两个引擎(OpenClaw + Hermes)的最后一个 section 加「术语」条目
- sidebar.js i18n 新增 glossary 键(11 语言)
- 之前只能从 dashboard quick-actions 进入,现在 sidebar 永久可达
## 4. 顺手 bug 修复
- gateway.js 文件末尾历史残留的多余 `}` (line 348) syntax 错误,删除
- 与之前 hermes/cron.js 同类问题,本次改 ⓘ 时被 node --check 暴露
## 累计变动
- 10 个文件修改
- 7 个新 i18n 键(11 语言)
- Build OK
This commit is contained in:
@@ -88,10 +88,19 @@ function toRawString(e) {
|
||||
return String(e)
|
||||
}
|
||||
|
||||
// 不同错误类型默认对应的行动按钮(label 走 i18n,route 直接跳转)
|
||||
const DEFAULT_ACTIONS = {
|
||||
gatewayDown: { labelKey: 'common.errorAction.startGateway', route: '/services' },
|
||||
cmdMissing: { labelKey: 'common.errorAction.openSettings', route: '/settings' },
|
||||
permission: { labelKey: 'common.errorAction.openSettings', route: '/settings' },
|
||||
auth: { labelKey: 'common.errorAction.checkApiKey', route: '/models' },
|
||||
// network / timeout / busy / rateLimit / notFound / generic:不给默认 action(重试由用户自己控制)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} e - 原始错误(Error / string / Tauri Result)
|
||||
* @param {string} [context] - 操作上下文文案(如 t('channels.saveFailed'))
|
||||
* @returns {{ message: string, hint: string, raw: string }}
|
||||
* @returns {{ message: string, hint: string, raw: string, action?: { label, route?, handler? } }}
|
||||
*/
|
||||
export function humanizeError(e, context) {
|
||||
const raw = toRawString(e).trim()
|
||||
@@ -111,8 +120,14 @@ export function humanizeError(e, context) {
|
||||
|
||||
const message = ctx || t(`common.error.${kind}`)
|
||||
const hint = t(`common.errorHint.${kind}`)
|
||||
const result = { message, hint, raw: rawTruncated, kind }
|
||||
|
||||
return { message, hint, raw: rawTruncated }
|
||||
const defaultAction = DEFAULT_ACTIONS[kind]
|
||||
if (defaultAction) {
|
||||
result.action = { label: t(defaultAction.labelKey), route: defaultAction.route }
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user