fix(后管): 状态列认得新分的 check_code,不再一律掉回「无法判定」

现网证据:uid=1 的 proxy 行库里已是 channel_busy(15:51 用户自己点检测写的),
后管却显示「无法判定」——数据对、界面不认识这个码。今天后端把青果检测从"无条件
假通过"改成真提取分档后,码集扩到 ok/channel_busy/invalid_key/forbidden/rate_limited/
insufficient_balance/tunnel_unverified/provider_error/网络超时族,前端只认旧几档就会
把"等一会儿就好"和"密钥坏了"混成同一个黄标。

档位:channel_busy→待释放(青,可重试族);rate_limited/timeout/network_error/
server_error→各自青档;insufficient_balance→欠费(现网 21 行原本吊在 failed 上,
改成按码认);tunnel_unverified→链接缺账密;invalid_key/forbidden/bad_request/
provider_error→红;**「无法判定」只留给空码/未知码**,unknown 留「未检测」
(那是后端 upsert 初值=从没问过,不是问不出)。句子一律取后端 check_message 原文,
前端不再按码自己拼措辞。行级汇总同样分族:逐格全属可重试才叫「可重试」。

判据:单元 9→19 支(含逐码档位表)+新增 mount 10 支;变异验证删掉 channel_busy
一行→单元 4 红+挂载 2 红。本面 node --test 1872/0、vitest 12 文件 68/0、tsc rc=0。
source-pin 台账按该尺子自带开关重生成(只多这一支文件)。
This commit is contained in:
2026-11-02 16:20:08 +08:00
parent 2cbd99ed4f
commit e26a157037
5 changed files with 653 additions and 55 deletions
@@ -16,8 +16,11 @@ import {
import {
PROXY_MODULE_KEY,
llmSourceLabel,
moduleStatusBand,
proxyDisplayText,
proxySourceLabel,
rowDetailLines,
rowStatusBand,
} from './user-secret-model.ts'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
@@ -55,48 +58,20 @@ const STATUS_OPTIONS = [
{ value: 'passed', label: '检测通过' },
{ value: 'failed', label: '检测失败' },
{ value: 'incomplete', label: '未配齐' },
{ value: 'error', label: '无法判定' },
// 后端的行级值仍是 error:这一档现在既可能是「问不出结论」,也可能是「通道还没释放、等一会再点」,
// 界面按码把后者补成「可重试」(见 user-secret-model.ts 的档位表),筛选项就得把两档都点名。
{ value: 'error', label: '无法判定/可重试' },
{ value: 'unknown', label: '未检测' },
]
/** 行级状态药丸:三类都检测通过才显示「检测通过」。 */
function rowStatusMeta(status: string) {
switch (status) {
case 'passed':
return { label: '检测通过', tone: 'is-allowed' }
case 'failed':
return { label: '检测失败', tone: 'is-blocked' }
case 'incomplete':
return { label: '未配齐', tone: 'is-warn' }
case 'error':
return { label: '无法判定', tone: 'is-warn' }
default:
return { label: '未检测', tone: 'is-unknown' }
}
}
/** 单格状态药丸:未配置时统一灰色;欠费单独标识。 */
function moduleStatusMeta(module: AdminUserSecretModule | undefined) {
if (!module || !module.exists) {
return { label: '未配置', tone: 'is-unknown' }
}
switch (module.checkStatus) {
case 'passed':
return { label: '通过', tone: 'is-allowed' }
case 'failed':
if (module.checkCode === 'insufficient_balance') {
return { label: '欠费', tone: 'is-warn' }
}
return { label: '失败', tone: 'is-blocked' }
case 'error':
return { label: '无法判定', tone: 'is-warn' }
default:
return { label: '未检测', tone: 'is-unknown' }
}
}
/* 状态药丸的档位表在 `user-secret-model.ts`(唯一出处,页面不带第二张表):
行级传整行而不是 `row.status`——后端把 failed/incomplete 都判掉之后就只剩一个「error」,
这一行到底是「查不出」还是「等青果释放」只有逐格的 `check_code` 说得清。 */
/**
* 单格悬停详情:后端下发的**脱敏值** + 锁定说明 + 检测消息 + 检测时间 + 耗时。
* 单格悬停详情:后端下发的**脱敏值** + 锁定说明 + **检测结果原文 `check_message`** + 检测时间 + 耗时。
* 运维要判「是欠费还是被自己的采集占着」,靠的就是这句后端原文——档名只是扫一眼用的短词,
* 前端一律不按码自己拼句子。
* ⚠ 只读 `masked`:`full` 在后台侧恒空(2026-11-02 `SecretMasking.maskProxy` 收口),
* 这里不做任何「masked 空就回落原文」的兜底,也不给复制整条链接的旁路。
*/
@@ -108,7 +83,9 @@ function moduleTooltip(module: AdminUserSecretModule | undefined) {
parts.push(isProxyModule(module) ? `代理地址(已脱敏,不含 key/pwd):${display}` : `密钥:${display}`)
}
if (module.locked) parts.push('已由后台代填并锁定:客户端不可修改或清空,改代理需重新填写账密')
if (module.checkMessage) parts.push(module.checkMessage)
// 后端的这句话就是给人看的结论,原样透出(不动一个字、不按码另拼一句)
const message = String(module.checkMessage || '').trim()
if (message) parts.push(message)
if (module.checkedAt) parts.push(`检测时间:${formatDateTime(module.checkedAt)}`)
if (module.checkLatencyMs != null) parts.push(`耗时:${module.checkLatencyMs}ms`)
return parts.join(';') || '暂无检测记录'
@@ -126,9 +103,15 @@ function groupTextOf(row: AdminUserSecretRow) {
return '—'
}
/**
* 行级悬停详情:后端的行级摘要 + 逐格的 `check_message` 原文 + 更新时间。
* 行级状态一旦补成「可重试」,管理员得能立刻看出是哪一格在等、后端原话怎么说;
* 逐格那句一律取后端下发文本(`rowDetailLines` 只搬运、不改写、不另拼一句)。
*/
function rowStatusTooltip(row: AdminUserSecretRow) {
const parts: string[] = []
if (row.statusMessage) parts.push(row.statusMessage)
parts.push(...rowDetailLines(row))
if (row.updatedAt) parts.push(`最近更新:${formatDateTime(row.updatedAt)}`)
return parts.join(';') || '暂无检测记录'
}
@@ -185,7 +168,9 @@ async function check(row: AdminUserSecretRow) {
if (failed.length) {
ElMessage.warning(failed[0].checkMessage || '存在检测失败项')
} else if (errors.length) {
ElMessage.warning('部分配置本次无法判定')
// 后端这句话会区分「通道被你自己占着,等约 3 分钟」与「真的问不出结论」;
// 硬写「无法判定」等于把可重试那一族又抹回一坨(现网 uid=1 就是这个形状)。
ElMessage.warning(errors[0].checkMessage || '部分配置本次无法判定')
} else {
ElMessage.success('检测通过')
}
@@ -329,8 +314,8 @@ onMounted(load)
<span v-if="row.similarAsin?.exists" class="wh-pill is-source" title="该用户这把密钥所属渠道">
{{ llmSourceLabel(row.similarAsin.channel) }}
</span>
<span class="wh-pill" :class="moduleStatusMeta(row.similarAsin).tone" :title="moduleTooltip(row.similarAsin)">
{{ moduleStatusMeta(row.similarAsin).label }}
<span class="wh-pill" :class="moduleStatusBand(row.similarAsin).tone" :title="moduleTooltip(row.similarAsin)">
{{ moduleStatusBand(row.similarAsin).label }}
</span>
</div>
</td>
@@ -341,8 +326,8 @@ onMounted(load)
<span v-if="row.appearancePatent?.exists" class="wh-pill is-source" title="该用户这把密钥所属渠道">
{{ llmSourceLabel(row.appearancePatent.channel) }}
</span>
<span class="wh-pill" :class="moduleStatusMeta(row.appearancePatent).tone" :title="moduleTooltip(row.appearancePatent)">
{{ moduleStatusMeta(row.appearancePatent).label }}
<span class="wh-pill" :class="moduleStatusBand(row.appearancePatent).tone" :title="moduleTooltip(row.appearancePatent)">
{{ moduleStatusBand(row.appearancePatent).label }}
</span>
</div>
</td>
@@ -354,8 +339,8 @@ onMounted(load)
<span v-if="row.proxy?.exists" class="wh-pill is-source" title="该用户代理所属供应商">
{{ proxySourceLabel(row.proxy.channel) }}
</span>
<span class="wh-pill" :class="moduleStatusMeta(row.proxy).tone" :title="moduleTooltip(row.proxy)">
{{ moduleStatusMeta(row.proxy).label }}
<span class="wh-pill" :class="moduleStatusBand(row.proxy).tone" :title="moduleTooltip(row.proxy)">
{{ moduleStatusBand(row.proxy).label }}
</span>
<span
v-if="row.proxy?.locked"
@@ -368,8 +353,8 @@ onMounted(load)
</div>
</td>
<td>
<span class="wh-pill" :class="rowStatusMeta(row.status).tone" :title="rowStatusTooltip(row)">
{{ rowStatusMeta(row.status).label }}
<span class="wh-pill" :class="rowStatusBand(row).tone" :title="rowStatusTooltip(row)">
{{ rowStatusBand(row).label }}
</span>
</td>
<td>{{ formatDateTime(row.createdAt) }}</td>
@@ -672,6 +657,13 @@ h3 {
border-color: #f0dfae;
color: #8f6d1e;
}
/* 「等一会再点」这一族(通道待释放/限流/超时/网络/上游):既不红(密钥没坏)
也不黄(不是欠费)更不是灰(不是查不出),独立一档青色——三种处置一眼分开。 */
.wh-pill.is-retry {
background: #e6f2f7;
border-color: #b6d8e6;
color: #2b6b86;
}
.wh-pill.is-unknown {
background: #f0f3f6;
border-color: #d6dee6;
@@ -1,7 +1,7 @@
/**
* 密钥管理页的纯逻辑模型(货源标签 + 代理重填)。
* 密钥管理页的纯逻辑模型(货源标签 + 代理重填 + 检测结果档位)。
*
* 两条收口都在这个文件里,页模板只调这里导出的函数,不各写各的字典:
* 三条收口都在这个文件里,页模板只调这里导出的函数,不各写各的字典:
*
* 1. **货源标签按模块分字典**(2026-11-02 修):原先 `UserSecretsPage.vue` 里是一整张
* `sourceLabel()`,把 LLM 渠道(longtaitou/t8star)与代理供应商(qingguo/jikip)混在同一个
@@ -17,6 +17,11 @@
* 由 `composeQingguoLink` 现拼;极客按其产品口径填自家提取链接。
* ⚠ 拼出来的链接是一次性写请求的载荷,**不得**回显、回填、进 tooltip、进剪贴板。
*
* 3. **检测结果按 `check_code` 分档渲染**(2026-11-02 加,见下方档位表):状态列原先只看
* `check_status`,把后端新分出来的一族「等一会再点就行」的码(`channel_busy` 等)一律显示成
* 「无法判定」,管理员分不清「被自己占着」「密钥坏了」「欠费」三种完全不同的处置。
* 码表只在这一份文件里(页面不再自带第二张表),句子一律用后端的 `check_message` 原文。
*
* 零 `@/` 别名依赖:本文件被 `node --test` 直测(那颗 runner 不认 Vite 别名)。
*/
import { composeQingguoLink } from '../../shared/utils/qingguo-link.ts'
@@ -27,6 +32,164 @@ export type ProxyProviderKey = 'qingguo' | 'jikip'
/** 代理模块 key(与后端 `UserSecretModule.PROXY.key()` 同值):写请求的路径段与「这一格是代理」的判据。 */
export const PROXY_MODULE_KEY = 'proxy'
/* ------------------------------------------------------------------ *
* 检测结果的渲染档位(2026-11-02 加,起因是现网 uid=1 的 proxy 行)
*
* 后端 `UserApiSecretCheckService` 把青果检测从「无条件假通过」改成真提取后**按供应商返回码分档**,
* 于是 `check_code` 成了这一格到底怎么了的最细信号;而界面当时只认 `check_status` 三档
* (passed/failed/error),`error` 一律写成「无法判定」——`channel_busy`(青果通道被自己的采集
* 占着,等约 3 分钟就能重试)因此被显示成「查不出」,管理员既看不出「等一会就行」,
* 也分不清它和「密钥坏了」「欠费」是三种完全不同的处置。
*
* 所以现在**按码建表、按状态兜底**:
* - 认得的码 ⇒ 各有自己的档位(可重试这一族另给独立配色,既不红也不黄);
* - 「无法判定」只留给真正没有结论的情况(空码/这表里没有的码 + `check_status=error`);
* - `check_status=unknown`(后端 upsert 后的初值,等于「从没检测过」)仍是「未检测」,
* 不许冒充「无法判定」——那是两件事,前者点一次检测就有答案,后者点了也还是没答案。
*
* ⚠ 措辞的权威在后端:给人看的那句中文在 `check_message` 里,界面只出**档名**(一个词),
* 绝不按码自己拼句子;句子通过 `moduleTooltip`/行级 tooltip 原样透出。
* ------------------------------------------------------------------ */
/** 药丸配色档位,对应 `UserSecretsPage.vue` 里 `.wh-pill.is-*` 那套样式类。 */
export type StatusTone = 'is-allowed' | 'is-blocked' | 'is-warn' | 'is-retry' | 'is-unknown'
/** 一个渲染档位:档名 + 配色。档名是给管理员扫一眼用的短词,不是解释句。 */
export interface StatusBand {
label: string
tone: StatusTone
}
/** 单格「没配」与「没检测」是两档,但都用灰色:都不代表密钥本身有问题。 */
export const NOT_CONFIGURED_BAND: StatusBand = { label: '未配置', tone: 'is-unknown' }
export const NOT_CHECKED_BAND: StatusBand = { label: '未检测', tone: 'is-unknown' }
/** 真的问不出结论(空码/未知码 + `check_status=error`)才落到这一档。 */
export const INDETERMINATE_BAND: StatusBand = { label: '无法判定', tone: 'is-warn' }
/** 后端 `STATUS_PASSED`(或码 `ok`):唯一可以当成「这项配好了」的一档。 */
export const PASSED_BAND: StatusBand = { label: '通过', tone: 'is-allowed' }
/** 后端新增了一档、前端还没登记码名时的兜底:按状态给个不撒谎的词,不当场判死。 */
const GENERIC_FAILED_BAND: StatusBand = { label: '失败', tone: 'is-blocked' }
/** 后端 `UserApiSecretCheckService` 的 `CODE_*` 全集(2026-11-02 逐条对着源码登记)。 */
const CHECK_CODE_BANDS: Record<string, StatusBand> = {
ok: PASSED_BAND,
/** 通道被自己的采集占着:等释放后重点一次,密钥没坏——这一档就是本次要修的错渲染。 */
channel_busy: { label: '待释放', tone: 'is-retry' },
rate_limited: { label: '限流重试', tone: 'is-retry' },
timeout: { label: '超时重试', tone: 'is-retry' },
/** 传输层失败:后端两个分支都给这个码(提取接口不可达=failed、探测异常=error),都可重试。 */
network_error: { label: '网络重试', tone: 'is-retry' },
server_error: { label: '上游重试', tone: 'is-retry' },
/** 欠费(现网 21 行):修之前就只有 `check_status=failed` 这一条路径认得它,改后按码认、不再吊在状态上。 */
insufficient_balance: { label: '欠费', tone: 'is-warn' },
/** 提取成功但链接里组不出可验连的地址(没带 key/pwd):要用户重填,不是「查不出」。 */
tunnel_unverified: { label: '链接缺账密', tone: 'is-warn' },
invalid_key: { label: '密钥失效', tone: 'is-blocked' },
forbidden: { label: '鉴权被拒', tone: 'is-blocked' },
bad_request: { label: '参数被拒', tone: 'is-blocked' },
provider_error: { label: '供应商报错', tone: 'is-blocked' },
}
/** 行级档位:后端 `UserApiSecretService` 按 failed > incomplete > passed > error > unknown 聚合,界面不重排这个优先级。 */
const ROW_STATUS_BANDS: Record<string, StatusBand> = {
passed: { label: '检测通过', tone: 'is-allowed' },
failed: { label: '检测失败', tone: 'is-blocked' },
incomplete: { label: '未配齐', tone: 'is-warn' },
error: INDETERMINATE_BAND,
}
/** 行级「可重试」:仅当整行的问题**只**出在可重试那一族码上时替换掉「无法判定」(后端给不了这一档,前端按格子的码补)。 */
const ROW_RETRY_BAND: StatusBand = { label: '可重试', tone: 'is-retry' }
/** 单模块的可比较形状(不引 `@/api/*`:本文件要能被零别名的 `node --test` 直测)。 */
interface CheckModuleLike {
exists?: boolean | null
moduleLabel?: string | null
checkStatus?: string | null
checkCode?: string | null
checkMessage?: string | null
}
/** 一行的可比较形状:只用到行状态 + 三个格子。 */
interface SecretRowLike {
status?: string | null
similarAsin?: CheckModuleLike | null
appearancePatent?: CheckModuleLike | null
proxy?: CheckModuleLike | null
}
/** 按归一后的键查档位表:空键与表里没有的键都返回 null(调用方兜底,绝不硬认一档)。 */
function bandOf(table: Record<string, StatusBand>, raw: unknown): StatusBand | null {
const key = normalizeKey(raw)
if (!key || !Object.prototype.hasOwnProperty.call(table, key)) return null
return table[key] ?? null
}
/** 码 → 档位;空码或这表里没有的码返回 null(由调用方按状态兜底,不硬认一档)。 */
export function checkCodeBand(code: string | null | undefined): StatusBand | null {
return bandOf(CHECK_CODE_BANDS, code)
}
/** 这一档是不是「等一等再点」那一族(可重试):配色与行级补档都读这一个判据,不散落码名。 */
export function isRetryBand(band: StatusBand | null | undefined): boolean {
return band?.tone === 'is-retry'
}
/**
* 单格状态药丸:先看是否已配置,再看 `check_status=passed`,然后**按 `check_code` 分档**,
* 都不认才按状态兜底。
*/
export function moduleStatusBand(module: CheckModuleLike | null | undefined): StatusBand {
if (!module || !module.exists) return NOT_CONFIGURED_BAND
const status = normalizeKey(module.checkStatus)
if (status === 'passed') return PASSED_BAND
const band = checkCodeBand(module.checkCode)
if (band) return band
if (status === 'error') return INDETERMINATE_BAND
if (status === 'failed') return GENERIC_FAILED_BAND
// ''/unknown/后端下一版新增的状态值:宁可说「未检测」,也不替后端编造一个结论
return NOT_CHECKED_BAND
}
/** 行级状态药丸:后端聚合成 `error` 时,若这一行**没有结论的格子全是可重试那一族**,补成「可重试」。 */
export function rowStatusBand(row: SecretRowLike | null | undefined): StatusBand {
const status = normalizeKey(row?.status)
if (status === 'error' && awaitsRetryOnly(row)) return ROW_RETRY_BAND
// 行级 `unknown`=后端还没问过(不是「问了问不出」),留「未检测」这一档,与筛选项里那一行同词
return bandOf(ROW_STATUS_BANDS, status) ?? NOT_CHECKED_BAND
}
/**
* 这一行是不是「点一次就有答案」:后端把 error 之上的 failed/incomplete 都判掉了才轮到 error,
* 所以这里只需再确认剩下那些没通过的格子都落在可重试档——混进一格「链接缺账密」就不算可重试,
* 那一格不会自己好,把整行说成「可重试」等于让管理员一直等。
*/
function awaitsRetryOnly(row: SecretRowLike | null | undefined): boolean {
const pending = modulesOf(row).filter(
(module) => Boolean(module?.exists) && normalizeKey(module?.checkStatus) !== 'passed',
)
return pending.length > 0 && pending.every((module) => isRetryBand(moduleStatusBand(module)))
}
/**
* 行级 tooltip 的明细:逐格把**后端原文** `check_message` 抄出来(运维判「是欠费还是被自己占着」就靠这句)。
* 前端不拼句子、不改一个字;没检测过的格子没有这句话,自然不出现。
*/
export function rowDetailLines(row: SecretRowLike | null | undefined): string[] {
return modulesOf(row)
.filter((module) => Boolean(module?.exists))
.map((module) => {
const message = String(module?.checkMessage ?? '').trim()
if (!message) return ''
const label = String(module?.moduleLabel ?? '').trim()
return label ? `${label}:${message}` : message
})
.filter(Boolean)
}
function modulesOf(row: SecretRowLike | null | undefined): CheckModuleLike[] {
return [row?.similarAsin, row?.appearancePatent, row?.proxy].filter(Boolean) as CheckModuleLike[]
}
/** 后端 `ProxyProvider.DEFAULT`=极客:新建默认极客,青果手动切(2026-10-30 拍板)。 */
export const DEFAULT_PROXY_PROVIDER: ProxyProviderKey = 'jikip'