chore(清理): 删除 10 个零引用文件并裁剪钉住它们的护栏断言

admin-frontend-vue:AdminConfirm.vue 只是 openAdminConfirm 的空壳包装(调用方走
imperative 入口);StatusPill/ModalShell/DrawerShell 与各自的 status-pill-model、
modal-model 构成孤儿岛,无任何页面 import;MaskReveal.vue 无引用点(掩码语义仍由
店铺侧 secret-mask 承担);duplicate-api.ts 是被 duplicate-console-api.ts 取代的
平行实现,DuplicateCheckPage 只用后者。frontend-vue:shared/utils/bootstrap.ts 全仓零命中。

护栏随之收口:task-248.test.ts 整支删除(8 个用例全在钉 modal-model 与两个 Shell),
task-247 去掉 status-pill-model 的 6 个用例与三个组件的钉(保留 CopyText/copy-model),
task-245 去掉 AdminConfirm.vue 的两行,task-115/117/118 去掉 duplicate-api.ts 的端点钉。
This commit is contained in:
2026-10-06 13:44:41 +08:00
parent 7887e7ee37
commit e635fa8dcd
16 changed files with 7 additions and 476 deletions
@@ -1,16 +0,0 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { openAdminConfirm } from './admin-confirm'
/**
* AdminConfirm 共享确认组件(module 13 task 245):renderless 单例承载。
* 使用:<AdminConfirm ref="confirmRef" />,需确认时 await confirmRef.open({...})。
*/
export default defineComponent({
name: 'AdminConfirm',
setup(_props, { expose }) {
expose({ open: openAdminConfirm })
return () => null
},
})
</script>
@@ -1,42 +0,0 @@
<script setup lang="ts">
import { computed } from 'vue'
import { dialogTitleOf, drawerLayoutSpec } from './modal-model'
/**
* DrawerShell 右侧抽屉容器(module 13 task 248):封装 el-drawer,统一 admin 尺寸
* 与关闭语义(遮罩/Esc),标题透传默认头部、footer 槽承接底部按钮,构成头/体/脚三段。
*/
const props = withDefaults(
defineProps<{ modelValue: boolean; title?: string; subtitle?: string; width?: string | number }>(),
{ title: '', subtitle: '', width: drawerLayoutSpec().width },
)
const emit = defineEmits<{ (e: 'update:modelValue', value: boolean): void }>()
const visible = computed({
get: () => props.modelValue,
set: (v: boolean) => emit('update:modelValue', v),
})
const spec = computed(() => drawerLayoutSpec())
const head = computed(() => dialogTitleOf({ title: props.title, subtitle: props.subtitle }))
</script>
<template>
<el-drawer
v-model="visible"
:size="width"
:title="head.title"
:close-on-click-modal="spec.maskClosable"
:close-on-press-escape="spec.escClosable"
class="admin-drawer-shell"
>
<p v-if="head.subtitle" class="admin-drawer-subtitle">{{ head.subtitle }}</p>
<slot />
<template #footer>
<slot name="footer" />
</template>
</el-drawer>
</template>
<style scoped>
.admin-drawer-subtitle { margin: 0 0 12px; color: var(--admin-muted); font-size: 13px; }
</style>
@@ -1,81 +0,0 @@
<script setup lang="ts">
import { onBeforeUnmount, ref, watch } from 'vue'
import { secretPlaceholder } from '@/pages/shop/secret-mask'
/**
* MaskReveal 掩码揭示(module 13 task 247):默认以店铺 secret-mask 掩码占位展示,
* 点击切换时向父组件发 reveal 事件取明文(以 value prop 回填);短时后自动收回。
*/
const props = withDefaults(defineProps<{ value?: string; revealMs?: number }>(), {
value: '',
revealMs: 5000,
})
const emit = defineEmits<{ (e: 'reveal'): void }>()
const revealed = ref(false)
let timer: ReturnType<typeof setTimeout> | null = null
function clearTimer(): void {
if (timer) {
clearTimeout(timer)
timer = null
}
}
function show(): void {
revealed.value = true
emit('reveal')
clearTimer()
timer = setTimeout(() => {
revealed.value = false
}, props.revealMs)
}
function hide(): void {
clearTimer()
revealed.value = false
}
function toggle(): void {
if (revealed.value) hide()
else show()
}
watch(
() => props.value,
(v) => {
if (!v) revealed.value = false
},
)
onBeforeUnmount(clearTimer)
</script>
<template>
<span class="mask-reveal">
<span class="mask-reveal-text">{{ revealed && value ? value : secretPlaceholder() }}</span>
<button
type="button"
class="mask-reveal-toggle"
:aria-label="revealed ? '隐藏' : '显示'"
@click="toggle"
>
{{ revealed ? '隐藏' : '显示' }}
</button>
</span>
</template>
<style scoped>
.mask-reveal { display: inline-flex; align-items: center; gap: 6px; }
.mask-reveal-text { font-variant-numeric: tabular-nums; }
.mask-reveal-toggle {
border: 1px solid #cbd9e6;
border-radius: 6px;
background: #fff;
color: #5b6f83;
font-size: 12px;
padding: 1px 8px;
cursor: pointer;
}
.mask-reveal-toggle:hover { color: #2f5d8b; border-color: #95b1cb; background: #edf5fb; }
</style>
@@ -1,42 +0,0 @@
<script setup lang="ts">
import { computed } from 'vue'
import { dialogTitleOf, modalLayoutSpec } from './modal-model'
/**
* ModalShell 居中模态容器(module 13 task 248):封装 el-dialog,统一 admin 尺寸/圆角
* 与关闭语义,标题透传给 Element 默认头部;body 用默认槽、操作区走 footer 槽。
*/
const props = withDefaults(
defineProps<{ modelValue: boolean; title?: string; subtitle?: string; width?: string | number }>(),
{ title: '', subtitle: '', width: modalLayoutSpec().width },
)
const emit = defineEmits<{ (e: 'update:modelValue', value: boolean): void }>()
const visible = computed({
get: () => props.modelValue,
set: (v: boolean) => emit('update:modelValue', v),
})
const spec = computed(() => modalLayoutSpec())
const head = computed(() => dialogTitleOf({ title: props.title, subtitle: props.subtitle }))
</script>
<template>
<el-dialog
v-model="visible"
:width="width"
:title="head.title"
:close-on-click-modal="spec.maskClosable"
:close-on-press-escape="spec.escClosable"
class="admin-modal-shell"
>
<p v-if="head.subtitle" class="admin-modal-subtitle">{{ head.subtitle }}</p>
<slot />
<template #footer>
<slot name="footer" />
</template>
</el-dialog>
</template>
<style scoped>
.admin-modal-subtitle { margin: 0 0 12px; color: var(--admin-muted); font-size: 13px; }
</style>
@@ -1,25 +0,0 @@
<script setup lang="ts">
import { computed } from 'vue'
import { pillToneStyle, type PillTone } from './status-pill-model'
const props = withDefaults(defineProps<{ text: string; tone?: PillTone }>(), { tone: 'info' })
const style = computed(() => pillToneStyle(props.tone))
</script>
<template>
<span class="status-pill" :style="{ color: style.text, background: style.bg }">{{ text }}</span>
</template>
<style scoped>
.status-pill {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 62px;
padding: 2px 10px;
border-radius: 999px;
font-size: 12px;
line-height: 1.7;
white-space: nowrap;
}
</style>
@@ -2,7 +2,7 @@
* 二次确认模型(module 13 task 245):文案/按钮键规则对齐 admin-interactions.js ——
* 优先显式 message,否则由行名拼接「确认删除“X”吗?此操作可能影响已有数据。」;
* danger(删除/清空/删除导入类)默认标题「删除前确认」、确认键「确认删除」。
* 纯逻辑、无 UI 依赖,便于单测;打开入口见 admin-confirm.ts / AdminConfirm.vue。
* 纯逻辑、无 UI 依赖,便于单测;打开入口见 admin-confirm.ts。
*/
export const ADMIN_CONFIRM = {
dangerTitle: '删除前确认',
@@ -1,30 +0,0 @@
/**
* 模态/抽屉布局模型(module 13 task 248):统一两种承载容器的尺寸与关闭语义,
* 对齐 admin.html —— 居中 modal width min(920px,100vw-48)、radius14;右侧 drawer
* width min(460px,100%);遮罩点击与 Esc 均关闭。页面接入统一尺寸与头/脚槽。
*/
export const ADMIN_MODAL_WIDTH = 'min(920px, 100vw - 48px)'
export const ADMIN_DRAWER_WIDTH = 'min(460px, 100%)'
export const ADMIN_MODAL_RADIUS = 14
export interface AdminContainerSpec {
width: string
radius?: number
maskClosable: boolean
escClosable: boolean
}
export function modalLayoutSpec(): AdminContainerSpec {
return { width: ADMIN_MODAL_WIDTH, radius: ADMIN_MODAL_RADIUS, maskClosable: true, escClosable: true }
}
export function drawerLayoutSpec(): AdminContainerSpec {
return { width: ADMIN_DRAWER_WIDTH, maskClosable: true, escClosable: true }
}
/** 页面头标题归一:空/空白标题兜底「操作」,副标题去空白后无则省略。 */
export function dialogTitleOf(opts: { title?: string; subtitle?: string }): { title: string; subtitle?: string } {
const title = opts.title?.trim()
const subtitle = opts.subtitle?.trim()
return { title: title || '操作', ...(subtitle ? { subtitle } : {}) }
}
@@ -1,37 +0,0 @@
/**
* 状态药丸配色/分类模型(module 13 task 247):统一 admin.html 的三态语义色
* (success 绿 / danger 红 / warning 琥珀 / info 蓝 / primary 深蓝),供视频任务、
* 店铺数据任务、数字人版本等页面复用;未知文本回落 info。
*/
export type PillTone = 'success' | 'danger' | 'warning' | 'info' | 'primary'
export interface PillToneStyle {
text: string
bg: string
}
export const PILL_TONES: Record<PillTone, PillToneStyle> = {
success: { text: '#4e806d', bg: '#e6f6ec' },
danger: { text: '#b35f6a', bg: '#fdecec' },
warning: { text: '#a8793e', bg: '#fdf0dc' },
info: { text: '#4f78a5', bg: '#e7f0f8' },
primary: { text: '#2f5d8b', bg: '#e6f0f8' },
}
/** 取某 tone 的配色;未知 tone 回退 info(不抛错)。 */
export function pillToneStyle(tone: PillTone): PillToneStyle {
return PILL_TONES[tone] ?? PILL_TONES.info
}
const SUCCESS_PATTERN = /success|succeed|已发布|发布|成功|正常|可用/
const DANGER_PATTERN = /fail|error|已废弃|失败|不可用|异常/
const WARNING_PATTERN = /running|pending|waiting|进行|处理中|草稿|待执行|待/
/** 由状态文本(中英文)归类语义 tone。 */
export function statusTone(raw: string): PillTone {
const s = (raw || '').toLowerCase()
if (SUCCESS_PATTERN.test(s)) return 'success'
if (DANGER_PATTERN.test(s)) return 'danger'
if (WARNING_PATTERN.test(s)) return 'warning'
return 'info'
}
@@ -1,43 +0,0 @@
/** 店铺数据重复检查适配(任务 115-119):/api/admin/shop-data-crawl/duplicate-check-* 系列端点。 */
import { http } from '@/api/http'
import {
parseDuplicateDetailPage,
parseDuplicateItemsPage,
parseDuplicateOverview,
type DuplicateOverview,
} from './duplicate-model.ts'
import { toDuplicateItemsQuery, type DuplicateFilter } from './duplicate-filter.ts'
export const DUPLICATE_CHECK_ENDPOINT = '/api/admin/shop-data-crawl'
/** 加载撞款总览(可选 force=1 触发同步重扫)。 */
export async function fetchDuplicateOverview(force = false): Promise<DuplicateOverview> {
const { data } = await http.get<unknown>(`${DUPLICATE_CHECK_ENDPOINT}/duplicate-check-overview`, {
params: force ? { force: '1' } : undefined,
})
return parseDuplicateOverview(data)
}
/** 加载撞款明细分页列表:GET /duplicate-check-items。 */
export async function fetchDuplicateItems(
filter: DuplicateFilter,
page: number,
pageSize: number,
): Promise<ReturnType<typeof parseDuplicateItemsPage>> {
const { data } = await http.get<unknown>(`${DUPLICATE_CHECK_ENDPOINT}/duplicate-check-items`, {
params: toDuplicateItemsQuery(filter, page, pageSize),
})
return parseDuplicateItemsPage(data)
}
/** 加载撞款详情卡片分页:GET /duplicate-check-detail。 */
export async function fetchDuplicateDetail(
filter: DuplicateFilter,
page: number,
pageSize: number,
): Promise<ReturnType<typeof parseDuplicateDetailPage>> {
const { data } = await http.get<unknown>(`${DUPLICATE_CHECK_ENDPOINT}/duplicate-check-detail`, {
params: toDuplicateItemsQuery(filter, page, pageSize),
})
return parseDuplicateDetailPage(data)
}
+1 -4
View File
@@ -80,10 +80,7 @@ test('test_task_115_duplicate_overview_invalid_input_rejected', () => {
})
test('test_task_115_duplicate_overview_dependency_failure_returns_actionable_message', () => {
// 依赖失败/加载走 adapter:GET /api/admin/shop-data-crawl/duplicate-check-overview。
const api = readSource('src/pages/tasks/duplicate-api.ts')
assert.match(api, /\/duplicate-check-overview/)
assert.match(api, /fetchDuplicateOverview/)
// 依赖失败:总览解析保持纯逻辑,不在模型层发 HTTP。
const model = readSource('src/pages/tasks/duplicate-model.ts')
assert.equal(/axios|http\./.test(model), false, '总览解析保持纯逻辑')
})
+1 -4
View File
@@ -75,10 +75,7 @@ test('test_task_117_duplicate_items_invalid_input_rejected', () => {
})
test('test_task_117_duplicate_items_dependency_failure_returns_actionable_message', () => {
// 依赖失败/加载走 adapter:GET /duplicate-check-items + 解析。
const api = readSource('src/pages/tasks/duplicate-api.ts')
assert.match(api, /\/duplicate-check-items/)
assert.match(api, /fetchDuplicateItems/)
// 依赖失败:明细解析保持纯逻辑,不在模型层发 HTTP。
const model = readSource('src/pages/tasks/duplicate-model.ts')
assert.equal(/axios|http\./.test(model), false, '明细解析保持纯逻辑')
})
+1 -4
View File
@@ -72,10 +72,7 @@ test('test_task_118_duplicate_detail_invalid_input_rejected', () => {
})
test('test_task_118_duplicate_detail_dependency_failure_returns_actionable_message', () => {
// 依赖失败/加载走 adapter:GET /duplicate-check-detail。
const api = readSource('src/pages/tasks/duplicate-api.ts')
assert.match(api, /\/duplicate-check-detail/)
assert.match(api, /fetchDuplicateDetail/)
// 依赖失败:详情解析保持纯逻辑,不在模型层发 HTTP。
const model = readSource('src/pages/tasks/duplicate-model.ts')
assert.equal(/axios|http\./.test(model), false, '详情解析保持纯逻辑')
})
+1 -3
View File
@@ -73,14 +73,12 @@ test('test_task_245_confirm_model_invalid_input_rejected', () => {
})
test('test_task_245_confirm_component_dependency_failure_returns_actionable_message', () => {
// 依赖失败:组件/调用入口真实接入 ElMessageBox,按钮键来自模型。
// 依赖失败:调用入口真实接入 ElMessageBox,按钮键来自模型。
const imperative = readSource('src/components/admin-confirm.ts')
assert.match(imperative, /ElMessageBox\.confirm/, '打开入口需调用 ElMessageBox.confirm')
assert.match(imperative, /confirmButtonText/)
assert.match(imperative, /cancelButtonText/)
assert.match(imperative, /createConfirmPlan/)
const component = readSource('src/components/AdminConfirm.vue')
assert.match(component, /openAdminConfirm/, '组件需暴露 open 打开入口')
const model = readSource('src/components/admin-confirm-model.ts')
assert.match(model, /此操作可能影响已有数据。/)
})
+2 -54
View File
@@ -1,55 +1,9 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { pillToneStyle, PILL_TONES, statusTone, type PillTone } from '../src/components/status-pill-model.ts'
import { copyFeedback } from '../src/components/copy-model.ts'
// module 13 task 247:行内工具组件化 —— 状态药丸/复制文本/掩码揭示,供视频/店铺数据/
// 数字人版本等页面复用;掩码复用店铺中心 secret-mask 语义。
test('test_task_247_pill_model_normal_primary_path', () => {
// 正常主路径:状态文本 → 语义 tone。
assert.equal(statusTone('SUCCESS'), 'success')
assert.equal(statusTone('FAILED'), 'danger')
assert.equal(statusTone('已发布'), 'success')
assert.equal(statusTone('失败'), 'danger')
})
test('test_task_247_pill_model_normal_variant_input', () => {
// 正常变体:运行/草稿等中间态落 warning;未知回落 info。
assert.equal(statusTone('RUNNING'), 'warning')
assert.equal(statusTone('草稿'), 'warning')
assert.equal(statusTone('something-unknown'), 'info')
})
test('test_task_247_pill_model_normal_repeated_operation_is_idempotent', () => {
assert.equal(statusTone('SUCCESS'), statusTone('success'))
assert.deepEqual(pillToneStyle('success'), pillToneStyle('success'))
})
test('test_task_247_pill_model_boundary_empty_input', () => {
// 边界空:空值/未知名不崩溃。
assert.equal(statusTone(''), 'info')
assert.equal(statusTone(undefined as unknown as string), 'info')
})
test('test_task_247_pill_model_boundary_single_item', () => {
// 边界单元素:每个 tone 都有可读配色(药丸文字/底色为 admin 三态色)。
for (const tone of Object.keys(PILL_TONES) as PillTone[]) {
const s = pillToneStyle(tone)
assert.match(s.text, /^#[0-9a-f]{6}$/)
assert.match(s.bg, /^#[0-9a-f]{6}$/)
}
assert.equal(pillToneStyle('success').text, '#4e806d')
assert.equal(pillToneStyle('danger').text, '#b35f6a')
})
test('test_task_247_pill_model_invalid_input_rejected', () => {
// 异常输入:非法 tone 回退 info,不抛错;三态主色与 admin 语义一致。
assert.equal(pillToneStyle('bogus' as PillTone).text, PILL_TONES.info.text)
assert.equal(PILL_TONES.warning.text, '#a8793e')
assert.equal(PILL_TONES.info.text, '#4f78a5')
})
// module 13 task 247:行内工具组件化 —— 复制文本,供视频/店铺数据/数字人版本等页面复用。
test('test_task_247_copy_model_boundary_limit_or_missing_field', () => {
// 复制反馈:非空给「已复制 X」,空/失败给降级文案。
@@ -59,15 +13,9 @@ test('test_task_247_copy_model_boundary_limit_or_missing_field', () => {
})
test('test_task_247_components_dependency_failure_returns_actionable_message', () => {
// 依赖失败:组件真实存在且接入语义(药丸用 PILL_TONES、复制走 copyFeedback、掩码复用 secret-mask)。
assert.ok(readSource('src/components/StatusPill.vue').length > 0)
// 依赖失败:CopyText 真实存在且复制文案走 copyFeedback。
assert.ok(readSource('src/components/CopyText.vue').length > 0)
assert.ok(readSource('src/components/MaskReveal.vue').length > 0)
const copy = readSource('src/components/CopyText.vue')
assert.match(copy, /copyFeedback/)
assert.match(copy, /navigator\.clipboard/)
const mask = readSource('src/components/MaskReveal.vue')
assert.match(mask, /secret-mask|secretPlaceholder|SECRET_PLACEHOLDER/, '掩码应复用店铺 secret-mask 语义')
const pill = readSource('src/components/StatusPill.vue')
assert.match(pill, /pillToneStyle|PILL_TONES/, '药丸应使用统一配色模型')
})
-74
View File
@@ -1,74 +0,0 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import {
ADMIN_DRAWER_WIDTH,
ADMIN_MODAL_RADIUS,
ADMIN_MODAL_WIDTH,
dialogTitleOf,
drawerLayoutSpec,
modalLayoutSpec,
} from '../src/components/modal-model.ts'
// module 13 task 248:模态/抽屉容器统一 —— 居中 modal min(920px,100vw-48)、右侧 drawer
// min(460px,100%)、三段式头/体/脚与关闭语义对齐 admin,页面接入统一宽度/结构。
test('test_task_248_container_model_normal_primary_path', () => {
const modal = modalLayoutSpec()
assert.equal(modal.width, ADMIN_MODAL_WIDTH)
assert.equal(modal.radius, ADMIN_MODAL_RADIUS)
assert.equal(ADMIN_MODAL_RADIUS, 14)
const drawer = drawerLayoutSpec()
assert.equal(drawer.width, ADMIN_DRAWER_WIDTH)
})
test('test_task_248_container_model_normal_variant_input', () => {
// 正常变体:modal/drawer 都支持遮罩点击与 Esc 关闭(对齐 admin 语义)。
assert.equal(modalLayoutSpec().maskClosable, true)
assert.equal(modalLayoutSpec().escClosable, true)
assert.equal(drawerLayoutSpec().maskClosable, true)
assert.equal(drawerLayoutSpec().escClosable, true)
})
test('test_task_248_container_model_normal_repeated_operation_is_idempotent', () => {
assert.deepEqual(modalLayoutSpec(), modalLayoutSpec())
assert.deepEqual(drawerLayoutSpec(), drawerLayoutSpec())
})
test('test_task_248_container_model_boundary_empty_input', () => {
// 边界空:无标题时页头兜底「操作」;空白标题同样兜底。
assert.equal(dialogTitleOf({}).title, '操作')
assert.equal(dialogTitleOf({ title: ' ' }).title, '操作')
})
test('test_task_248_container_model_boundary_single_item', () => {
// 边界单元素:带副标题保留、去首尾空白。
const head = dialogTitleOf({ title: ' 编辑店铺 ', subtitle: ' 店铺分组/账号凭证明细 ' })
assert.equal(head.title, '编辑店铺')
assert.equal(head.subtitle, '店铺分组/账号凭证明细')
})
test('test_task_248_container_model_boundary_limit_or_missing_field', () => {
// 边界上限:宽度表达式满足 admin 尺寸口径。
assert.match(ADMIN_MODAL_WIDTH, /920px/)
assert.match(ADMIN_MODAL_WIDTH, /100vw/)
assert.match(ADMIN_DRAWER_WIDTH, /460px/)
})
test('test_task_248_modal_shell_dependency_failure_returns_actionable_message', () => {
// 依赖失败:ModalShell 真实封装 el-dialog,宽度来自模型,标题透传、带 footer 槽。
const modal = readSource('src/components/ModalShell.vue')
assert.match(modal, /el-dialog/)
assert.match(modal, /modalLayoutSpec|ADMIN_MODAL_WIDTH/)
assert.match(modal, /#footer/)
assert.ok(readSource('src/components/DrawerShell.vue').length > 0)
})
test('test_task_248_drawer_shell_dependency_failure_returns_actionable_message', () => {
const drawer = readSource('src/components/DrawerShell.vue')
assert.match(drawer, /el-drawer/)
assert.match(drawer, /drawerLayoutSpec|ADMIN_DRAWER_WIDTH/)
assert.match(drawer, /:title=|head\.title/, '标题透传到 drawer 默认头部')
assert.match(drawer, /#footer/, '提供 footer 槽以构成头/体/脚三段')
assert.match(drawer, /close-on-press-escape|close-on-click-modal/, '需配置 Esc/遮罩关闭语义')
})
@@ -1,16 +0,0 @@
export interface BootstrapState {
username?: string
userId?: string
isAdmin?: boolean
error?: string
}
declare global {
interface Window {
__BOOTSTRAP__?: BootstrapState
}
}
export function getBootstrapState(): BootstrapState {
return window.__BOOTSTRAP__ ?? {}
}