feat(admin): 后台新增「抖音码速达」配置面板

- 新增 Tab:/admin/platform-shops?tab=douyinMashida
- 面板字段:enabled / baseUrl / uid / secret / certLink / afterVerifyLink /
  afterVerifyMessage / messageType / timeoutMs / handledTopics(tags)
- 密钥脱敏:出参 secret 永远为空,输入框未编辑时对外 value 恒为 '',
  掩码不会污染后端「空串=保留原值」语义
- 顶部展示 ready 状态,未就绪时用 Alert 列出缺哪几项;
  始终展示平台侧要配的推送地址(可复制)
- baseUrl 命中本地地址时提示「当前指向本地网关桩,不会请求真实码速达」
- 把 AdminPlatformShopsPage 内联的 SecretFieldControl 抽成共享组件
  (函数体与原实现逐字节一致,8 处既有调用点参数不变)
This commit is contained in:
yml2213
2026-10-09 12:01:29 +08:00
parent 72606796b3
commit 080480f03b
9 changed files with 721 additions and 153 deletions
@@ -0,0 +1,86 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildDouyinMashidaMessageUrl,
describeMissingConfigFields,
isLocalDevBaseUrl,
} from '../src/utils/douyin-mashida.ts'
/** 固定顺序:接入开关 / 商户uid / 用户秘钥 / 兑换链接 */
const ALL_MISSING = ['接入开关', '商户uid', '用户秘钥', '兑换链接']
test('isLocalDevBaseUrl:127.0.0.1 / localhost / host.docker.internal(含端口与结尾斜杠)判为 true', () => {
assert.equal(isLocalDevBaseUrl('http://127.0.0.1:3000'), true)
assert.equal(isLocalDevBaseUrl('http://127.0.0.1:3000/'), true)
assert.equal(isLocalDevBaseUrl('http://127.0.0.1'), true)
assert.equal(isLocalDevBaseUrl('http://localhost:8080/'), true)
assert.equal(isLocalDevBaseUrl('http://localhost'), true)
assert.equal(isLocalDevBaseUrl('http://host.docker.internal:3000/'), true)
assert.equal(isLocalDevBaseUrl(' http://localhost:5173// '), true)
})
test('isLocalDevBaseUrl:线上地址 / 空串 / 非本地域名判为 false', () => {
assert.equal(isLocalDevBaseUrl('https://dy-openplatform-api.wanmahui.com'), false)
assert.equal(isLocalDevBaseUrl('https://dy-openplatform-api.wanmahui.com/'), false)
assert.equal(isLocalDevBaseUrl(''), false)
assert.equal(isLocalDevBaseUrl(' '), false)
assert.equal(isLocalDevBaseUrl('http://example.com'), false)
assert.equal(isLocalDevBaseUrl('http://notlocalhost:3000'), false)
})
test('buildDouyinMashidaMessageUrl:拼接推送地址并容忍结尾斜杠', () => {
const suffix = '/api/v1/open/douyin-mashida/message'
assert.equal(
buildDouyinMashidaMessageUrl('https://ks.khhao.com'),
`https://ks.khhao.com${suffix}`,
)
assert.equal(
buildDouyinMashidaMessageUrl('https://ks.khhao.com/'),
`https://ks.khhao.com${suffix}`,
)
assert.equal(
buildDouyinMashidaMessageUrl('http://127.0.0.1:3000//'),
`http://127.0.0.1:3000${suffix}`,
)
})
test('describeMissingConfigFields:四项齐全返回空数组', () => {
assert.deepEqual(
describeMissingConfigFields({
enabled: true,
uid: 'uid_123',
hasSecret: true,
certLink: 'https://ks.khhao.com/redeem',
}),
[],
)
})
test('describeMissingConfigFields:缺多项按固定顺序返回中文名', () => {
assert.deepEqual(
describeMissingConfigFields({ enabled: false, uid: '', hasSecret: false, certLink: '' }),
ALL_MISSING,
)
})
test('describeMissingConfigFields:缺单项只返回对应中文名', () => {
assert.deepEqual(
describeMissingConfigFields({
enabled: true,
uid: 'uid_123',
hasSecret: false,
certLink: 'https://ks.khhao.com/redeem',
}),
['用户秘钥'],
)
assert.deepEqual(
describeMissingConfigFields({
enabled: false,
uid: 'uid_123',
hasSecret: true,
certLink: ' ',
}),
['接入开关', '兑换链接'],
)
})