From 052f2bd4a57efaa8929cd5ca9ace6a2f0b1db188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sat, 24 Oct 2026 09:20:36 +0800 Subject: [PATCH] =?UTF-8?q?revert(gating):=20=E5=90=8E=E7=AE=A1=20Gating?= =?UTF-8?q?=20=E9=A1=B5=E4=B8=8E=E5=85=A5=E5=8F=A3=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除品牌Gating库页面、API/导入/模型与测试,摘掉静态路由、操作指引条目与 ops-cell 列宽登记;菜单行由 V166 移除,后端模块保留但无授权入口。 --- .../src/layout/operation-guides.ts | 4 - .../src/pages/gating/GatingPage.vue | 759 ------------------ .../src/pages/gating/gating-api.ts | 75 -- .../src/pages/gating/gating-import.ts | 66 -- .../src/pages/gating/gating-model.ts | 183 ----- admin-frontend-vue/src/router/routes.ts | 2 - .../tests/gating-import.test.ts | 58 -- admin-frontend-vue/tests/gating-model.test.ts | 99 --- .../tests/mount/gating-page.mount.test.ts | 138 ---- .../tests/ops-cell-must-wrap.test.ts | 1 - 10 files changed, 1385 deletions(-) delete mode 100644 admin-frontend-vue/src/pages/gating/GatingPage.vue delete mode 100644 admin-frontend-vue/src/pages/gating/gating-api.ts delete mode 100644 admin-frontend-vue/src/pages/gating/gating-import.ts delete mode 100644 admin-frontend-vue/src/pages/gating/gating-model.ts delete mode 100644 admin-frontend-vue/tests/gating-import.test.ts delete mode 100644 admin-frontend-vue/tests/gating-model.test.ts delete mode 100644 admin-frontend-vue/tests/mount/gating-page.mount.test.ts diff --git a/admin-frontend-vue/src/layout/operation-guides.ts b/admin-frontend-vue/src/layout/operation-guides.ts index 2b3ae7aa6..d9fb20abc 100644 --- a/admin-frontend-vue/src/layout/operation-guides.ts +++ b/admin-frontend-vue/src/layout/operation-guides.ts @@ -68,10 +68,6 @@ export const OPERATION_GUIDES: Record = { text: '店铺信息按分组管理。长商城名会自动缩略,悬停即可查看完整内容。', steps: ['选择分组', '维护店铺信息', '筛选核对结果'], }, - admin_brand_gating: { - text: '维护不符合规则的品牌(品牌Gating/类目Gating)。添加后可用筛选快速回查;云端Gating库与前端排查软件同步同一份数据,排查软件命中后会自动在此入库。', - steps: ['新增或批量导入', '筛选回查', '停用或删除'], - }, admin_shop_data_crawl_tasks: { text: '店铺数据任务按状态和时间筛选。批量操作前请核对已选任务。', steps: ['筛选任务', '检查状态', '执行批量操作'], diff --git a/admin-frontend-vue/src/pages/gating/GatingPage.vue b/admin-frontend-vue/src/pages/gating/GatingPage.vue deleted file mode 100644 index 23284e15c..000000000 --- a/admin-frontend-vue/src/pages/gating/GatingPage.vue +++ /dev/null @@ -1,759 +0,0 @@ - - - - - diff --git a/admin-frontend-vue/src/pages/gating/gating-api.ts b/admin-frontend-vue/src/pages/gating/gating-api.ts deleted file mode 100644 index 19186b799..000000000 --- a/admin-frontend-vue/src/pages/gating/gating-api.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** 品牌Gating库 API 适配:GET/POST/DELETE /api/admin/brand-gating(契约路径与字段不得擅改)。 */ -import { http } from '@/api/http' -import { unwrap } from '@/api/envelope' -import { - parseGatingPage, - parseGatingStats, - toGatingItem, - type GatingItem, - type GatingPageResult, - type GatingStats, -} from './gating-model.ts' - -export const GATING_ENDPOINT = '/api/admin/brand-gating' - -/** 列表:GET /api/admin/brand-gating?page&size&keyword&country&gatingType&status&source → { total, rows }。 */ -export async function fetchGatingPage(params: Record): Promise { - const { data } = await http.get(GATING_ENDPOINT, { params }) - return parseGatingPage(data) -} - -/** 统计:GET /api/admin/brand-gating/stats → { total, active, disabled, brands, byType, byCountry, bySource }。 */ -export async function fetchGatingStats(): Promise { - const { data } = await http.get(`${GATING_ENDPOINT}/stats`) - return parseGatingStats(data) -} - -/** 单条新增字段(驼峰);source/shopName 可缺省由后端落默认。 */ -export interface GatingCreatePayload { - brand: string - asin: string - country: string - gatingType: string - source: string - shopName: string - remark: string -} - -/** 新增:POST /api/admin/brand-gating → { added }。 */ -export async function createGating(payload: GatingCreatePayload): Promise { - const { data } = await http.post(GATING_ENDPOINT, payload) - const core = unwrap>(data) - const added = core && typeof core === 'object' ? Number((core as Record).added) : NaN - return Number.isFinite(added) ? added : 0 -} - -/** 删除:DELETE /api/admin/brand-gating/{id} → { deleted }。 */ -export async function deleteGating(id: number): Promise { - const { data } = await http.delete(`${GATING_ENDPOINT}/${id}`) - unwrap(data) -} - -/** - * 启用/停用:POST /api/admin/brand-gating/{id}/status body { status } → { updated }。 - * 停用(status=0)由后端记 disabled_at=NOW(),恢复(status=1)清空 disabled_at。 - */ -export async function updateGatingStatus(id: number, status: 0 | 1): Promise { - const { data } = await http.post(`${GATING_ENDPOINT}/${id}/status`, { status }) - unwrap(data) -} - -/** 批量导入:POST /api/admin/brand-gating/import body { text } → { added, skipped }。原始文本整段交后端解析。 */ -export async function importGatingText(text: string): Promise<{ added: number; skipped: number }> { - const { data } = await http.post(`${GATING_ENDPOINT}/import`, { text }) - const core = unwrap>(data) - const record = (core && typeof core === 'object' ? core : {}) as Record - const added = Number(record.added) - const skipped = Number(record.skipped) - return { - added: Number.isFinite(added) ? added : 0, - skipped: Number.isFinite(skipped) ? skipped : 0, - } -} - -/** 单条解析出口(供需要单取的场景复用,例如挂载测试构造数据)。 */ -export { toGatingItem, type GatingItem } diff --git a/admin-frontend-vue/src/pages/gating/gating-import.ts b/admin-frontend-vue/src/pages/gating/gating-import.ts deleted file mode 100644 index c0a276691..000000000 --- a/admin-frontend-vue/src/pages/gating/gating-import.ts +++ /dev/null @@ -1,66 +0,0 @@ -/** 批量导入文本解析(照抄桌面版 gating_web_admin.py parse_batch 的行格式与跳过规则)。 - * 纯逻辑、零依赖(tests/gating-import.test.ts 用 node --test 直连本文件)。 - * - * 口径(与桌面版 L208-223 逐条对齐): - * - 按行拆分;每行去首尾空白与 BOM(\uFEFF); - * - 空行与以 # 开头的注释行跳过; - * - 行内按中英文逗号/分号/制表符([,\t;,;])切分,各段去空白后丢掉空段; - * - 字段序:品牌(必留)、国家(缺省「全部」)、Gating类型(缺省「品牌gating」)、ASIN(缺省空)、备注(缺省空); - * 第 5 列之后的段照桌面版丢弃。 - * - * 前端只用它做导入前的行数预览;真正提交仍把原始文本整段交给后端 - * (POST /api/admin/brand-gating/import { text },去重与入库由后端按同一份规则解析)。 */ - -export interface GatingImportItem { - brand: string - country: string - gatingType: string - asin: string - remark: string -} - -export interface GatingImportParseResult { - items: GatingImportItem[] - /** 因空行/注释行/纯分隔符行被跳过的行数。 */ - skippedLines: number -} - -export const GATING_IMPORT_DEFAULT_COUNTRY = '全部' -export const GATING_IMPORT_DEFAULT_TYPE = '品牌gating' -/** 与桌面版一致的列分隔符:中英文逗号、中英文分号、制表符。 */ -const FIELD_SPLIT_RE = /[,\t;,;]/ - -/** 解析批量导入文本;永不抛错(坏行计入 skippedLines)。 */ -export function parseGatingImportText(text: string): GatingImportParseResult { - const items: GatingImportItem[] = [] - let skippedLines = 0 - const lines = String(text ?? '').split(/\r?\n/) - for (const rawLine of lines) { - const line = rawLine.trim().replace(/^\uFEFF/, '').trim() - if (!line || line.startsWith('#')) { - if (rawLine.trim()) skippedLines += 1 - continue - } - const parts = line - .split(FIELD_SPLIT_RE) - .map((part) => part.trim()) - .filter((part) => part.length > 0) - if (!parts.length) { - skippedLines += 1 - continue - } - items.push({ - brand: parts[0], - country: parts[1] ?? GATING_IMPORT_DEFAULT_COUNTRY, - gatingType: parts[2] ?? GATING_IMPORT_DEFAULT_TYPE, - asin: parts[3] ?? '', - remark: parts[4] ?? '', - }) - } - return { items, skippedLines } -} - -/** 导入完成反馈文案:新增 X 条,跳过重复 Y 条。 */ -export function gatingImportOutcomeText(added: number, skipped: number): string { - return `批量导入完成:新增 ${added} 条,跳过重复 ${skipped} 条` -} diff --git a/admin-frontend-vue/src/pages/gating/gating-model.ts b/admin-frontend-vue/src/pages/gating/gating-model.ts deleted file mode 100644 index e2b6cdb12..000000000 --- a/admin-frontend-vue/src/pages/gating/gating-model.ts +++ /dev/null @@ -1,183 +0,0 @@ -/** 品牌Gating库页面模型(biz_brand_gating 并入管理后台):类型、字典、筛选态与响应解析。 - * 纯逻辑、零依赖(tests/gating-model.test.ts 用 node --test 直连本文件,别 import 带 @ 别名/axios 的模块)。 */ - -export interface GatingItem { - id: number - brand: string - asin: string - country: string - gatingType: string - /** 1=生效 0=停用。 */ - status: number - source: string - shopName: string - remark: string - createdAt?: string - updatedAt?: string - disabledAt?: string -} - -export interface GatingPageResult { - rows: GatingItem[] - total: number -} - -/** 分组统计单行(GET stats 的 byType/byCountry/bySource)。 */ -export interface GatingNameCount { - name: string - count: number -} - -export interface GatingStats { - total: number - active: number - disabled: number - brands: number - byType: GatingNameCount[] - byCountry: GatingNameCount[] - bySource: GatingNameCount[] -} - -export interface GatingFilterState { - /** 品牌/ASIN/备注 LIKE 关键词。 */ - keyword: string - country: string - gatingType: string - /** '' = 全部;'1' 生效;'0' 停用。 */ - status: string - source: string -} - -/** 国家字典:与桌面版 gating_web_admin 下拉一致;'全部' 是表内真实取值(不限国家时用空串)。 */ -export const GATING_COUNTRIES = ['全部', '英国', '德国', '法国', '西班牙', '意大利'] as const -export const GATING_TYPES = ['品牌gating', '类目gating', '账户不符合'] as const -export const GATING_SOURCES = ['AUTO', 'MANUAL'] as const -/** 每页条数档位(默认 10,可选 20/50)。 */ -export const GATING_PAGE_SIZES = [10, 20, 50] as const -export const GATING_DEFAULT_PAGE_SIZE = 10 - -export function createGatingFilterState(): GatingFilterState { - return { keyword: '', country: '', gatingType: '', status: '', source: '' } -} - -function text(value: unknown): string { - return typeof value === 'string' ? value.trim() : '' -} - -function intOr(value: unknown, fallback: number): number { - return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback -} - -/** 解析单条记录;缺 id 视为无效。兼容 camel 与 snake 字段名。 */ -export function toGatingItem(raw: unknown): GatingItem | null { - if (!raw || typeof raw !== 'object') return null - const record = raw as Record - const id = intOr(record.id, 0) - if (id <= 0) return null - const item: GatingItem = { - id, - brand: text(record.brand), - asin: text(record.asin), - country: text(record.country), - gatingType: text(record.gatingType ?? record.gating_type), - status: intOr(record.status, 0), - source: text(record.source), - shopName: text(record.shopName ?? record.shop_name), - remark: text(record.remark), - } - const createdAt = text(record.createdAt ?? record.created_at) - const updatedAt = text(record.updatedAt ?? record.updated_at) - const disabledAt = text(record.disabledAt ?? record.disabled_at) - if (createdAt) item.createdAt = createdAt - if (updatedAt) item.updatedAt = updatedAt - if (disabledAt) item.disabledAt = disabledAt - return item -} - -/** 解析列表负载({ total, rows };rows 兼容 items 别名),空负载回空页。 */ -export function parseGatingPage(payload: unknown): GatingPageResult { - const out: GatingPageResult = { rows: [], total: 0 } - if (!payload || typeof payload !== 'object') return out - const record = payload as Record - const rawRows = Array.isArray(record.rows) ? record.rows : Array.isArray(record.items) ? record.items : [] - out.rows = rawRows - .map((raw) => toGatingItem(raw)) - .filter((item): item is GatingItem => item !== null) - out.total = intOr(record.total, out.rows.length) - return out -} - -/** 分组统计单组:数组 [{name,count}] 或桌面版遗留 dict({品牌gating: 3})都收。 */ -export function parseGatingNameCountList(raw: unknown): GatingNameCount[] { - if (Array.isArray(raw)) { - const out: GatingNameCount[] = [] - for (const item of raw) { - if (!item || typeof item !== 'object') continue - const record = item as Record - const name = text(record.name) - if (!name) continue - out.push({ name, count: intOr(record.count, 0) }) - } - return out - } - if (raw && typeof raw === 'object') { - const out: GatingNameCount[] = [] - for (const [name, count] of Object.entries(raw as Record)) { - if (!name) continue - out.push({ name, count: intOr(count, 0) }) - } - return out - } - return [] -} - -/** 解析统计负载;缺省字段回 0/空数组。 */ -export function parseGatingStats(payload: unknown): GatingStats { - const out: GatingStats = { - total: 0, - active: 0, - disabled: 0, - brands: 0, - byType: [], - byCountry: [], - bySource: [], - } - if (!payload || typeof payload !== 'object') return out - const record = payload as Record - out.total = intOr(record.total, 0) - out.active = intOr(record.active, 0) - out.disabled = intOr(record.disabled, 0) - out.brands = intOr(record.brands, 0) - out.byType = parseGatingNameCountList(record.byType ?? record.by_type) - out.byCountry = parseGatingNameCountList(record.byCountry ?? record.by_country) - out.bySource = parseGatingNameCountList(record.bySource ?? record.by_source) - return out -} - -/** 筛选态 + 分页 → 列表查询参数(page/size/keyword/country/gatingType/status/source);空白值不下发。 */ -export function toGatingListParams( - state: GatingFilterState, - page: number, - pageSize: number, -): Record { - const params: Record = { - page: page >= 1 ? Math.floor(page) : 1, - size: pageSize >= 1 ? Math.floor(pageSize) : GATING_DEFAULT_PAGE_SIZE, - } - const keyword = (state.keyword || '').trim() - const country = (state.country || '').trim() - const gatingType = (state.gatingType || '').trim() - const status = (state.status || '').trim() - const source = (state.source || '').trim() - if (keyword) params.keyword = keyword - if (country) params.country = country - if (gatingType) params.gatingType = gatingType - if (status === '1' || status === '0') params.status = status - if (source) params.source = source - return params -} - -/** 状态 → 展示文案;非 1 一律按停用。 */ -export function gatingStatusLabel(status: unknown): string { - return status === 1 ? '生效' : '停用' -} diff --git a/admin-frontend-vue/src/router/routes.ts b/admin-frontend-vue/src/router/routes.ts index 943420f0f..d531718b5 100644 --- a/admin-frontend-vue/src/router/routes.ts +++ b/admin-frontend-vue/src/router/routes.ts @@ -40,8 +40,6 @@ export const adminPages: AdminPageDef[] = [ { path: 'asin-center/query', menuKey: 'admin_query_asin', title: '查询ASIN', companyScoped: true, load: () => import('@/pages/asin/QueryAsinPage.vue') }, { path: 'asin-center/categories', menuKey: 'admin_product_categories', title: '商品类目', companyScoped: false, load: () => import('@/pages/asin/ProductCategoryPage.vue') }, { path: 'asin-center/skip-price', menuKey: 'admin_skip_price_asin', title: '最低价ASIN', companyScoped: true, load: () => import('@/pages/asin/SkipPricePage.vue') }, - // 品牌Gating库(biz_brand_gating):全平台共享表(桌面版 gating_web_admin 同源数据),不参与公司 tab。 - { path: 'asin-center/gating', menuKey: 'admin_brand_gating', title: '品牌Gating库', companyScoped: false, load: () => import('@/pages/gating/GatingPage.vue') }, ] export function routeOf(page: AdminPageDef): RouteRecordRaw { diff --git a/admin-frontend-vue/tests/gating-import.test.ts b/admin-frontend-vue/tests/gating-import.test.ts deleted file mode 100644 index 9f3ba8c9b..000000000 --- a/admin-frontend-vue/tests/gating-import.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import test from 'node:test' -import assert from 'node:assert/strict' -import { gatingImportOutcomeText, parseGatingImportText } from '../src/pages/gating/gating-import.ts' - -test('gating_import_single_field_defaults', () => { - // 桌面版口径:只给品牌 → 国家=全部、类型=品牌gating、ASIN/备注空。 - const result = parseGatingImportText('jellycat') - assert.equal(result.items.length, 1) - assert.deepEqual(result.items[0], { brand: 'jellycat', country: '全部', gatingType: '品牌gating', asin: '', remark: '' }) - assert.equal(result.skippedLines, 0) -}) - -test('gating_import_full_five_fields', () => { - const result = parseGatingImportText('tory burch,英国,品牌gating,B0ABC123,人为录入') - assert.deepEqual(result.items[0], { brand: 'tory burch', country: '英国', gatingType: '品牌gating', asin: 'B0ABC123', remark: '人为录入' }) -}) - -test('gating_import_mixed_separators_and_extra_fields_dropped', () => { - // 桌面版分隔符集合 [,\t;,;];第 5 列之后的段丢弃。 - const result = parseGatingImportText('crocs,德国;类目gating\tB0X\t备注\t多余段') - assert.deepEqual(result.items[0], { brand: 'crocs', country: '德国', gatingType: '类目gating', asin: 'B0X', remark: '备注' }) -}) - -test('gating_import_skip_blank_comment_and_separator_only_lines', () => { - const text = [ - '', - ' ', - '# 这是注释行', - ';;,', // 纯分隔符行 → 空段全被丢,整行跳过 - 'jellycat', - ].join('\n') - const result = parseGatingImportText(text) - assert.equal(result.items.length, 1) - assert.equal(result.items[0]?.brand, 'jellycat') - assert.equal(result.skippedLines, 2) // 注释行 + 纯分隔符行;纯空白行不计数 -}) - -test('gating_import_bom_and_crlf_and_empty_parts', () => { - const result = parseGatingImportText('\uFEFFcrocs,德国,,B0X\r\n,头部空段被丢') - assert.equal(result.items.length, 2) - assert.equal(result.items[0]?.brand, 'crocs') - assert.equal(result.items[0]?.country, '德国') - // 桌面版口径:空段在切分后就被丢弃,后续字段整体左移(B0X 落到类型位)——照抄不修正。 - assert.equal(result.items[0]?.gatingType, 'B0X') - assert.equal(result.items[0]?.asin, '') - assert.equal(result.items[1]?.brand, '头部空段被丢') - assert.equal(result.items[1]?.country, '全部') -}) - -test('gating_import_empty_input_never_throws', () => { - assert.deepEqual(parseGatingImportText(''), { items: [], skippedLines: 0 }) - // @ts-expect-error 纯函数要扛住脏输入(运行时防呆)。 - assert.deepEqual(parseGatingImportText(null), { items: [], skippedLines: 0 }) -}) - -test('gating_import_outcome_text', () => { - assert.equal(gatingImportOutcomeText(3, 2), '批量导入完成:新增 3 条,跳过重复 2 条') -}) diff --git a/admin-frontend-vue/tests/gating-model.test.ts b/admin-frontend-vue/tests/gating-model.test.ts deleted file mode 100644 index 1dc40a424..000000000 --- a/admin-frontend-vue/tests/gating-model.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import test from 'node:test' -import assert from 'node:assert/strict' -import { - createGatingFilterState, - gatingStatusLabel, - parseGatingNameCountList, - parseGatingPage, - parseGatingStats, - toGatingItem, - toGatingListParams, -} from '../src/pages/gating/gating-model.ts' - -test('gating_filter_normal_primary_path', () => { - // 完整筛选映射到契约查询参数(page/size/keyword/country/gatingType/status/source)。 - const state = { ...createGatingFilterState(), keyword: 'jellycat', country: '英国', gatingType: '品牌gating', status: '1', source: 'MANUAL' } - const params = toGatingListParams(state, 3, 20) - assert.equal(params.page, 3) - assert.equal(params.size, 20) - assert.equal(params.keyword, 'jellycat') - assert.equal(params.country, '英国') - assert.equal(params.gatingType, '品牌gating') - assert.equal(params.status, '1') - assert.equal(params.source, 'MANUAL') -}) - -test('gating_filter_boundary_blank_dropped', () => { - // 空筛选只带分页;非法 status(非 '0'/'1')不下发。 - const params = toGatingListParams({ ...createGatingFilterState(), status: 'all', keyword: ' ' }, 0, -5) - assert.deepEqual(params, { page: 1, size: 10 }) -}) - -test('gating_item_parse_normal_and_snake_fallback', () => { - const camel = toGatingItem({ - id: 7, brand: 'jellycat', asin: 'B0ABC123', country: '英国', gatingType: '品牌gating', - status: 1, source: 'AUTO', shopName: '店A', remark: 'r', - createdAt: '2026-01-02 03:04:05', updatedAt: '2026-01-03 03:04:05', disabledAt: null, - }) - assert.ok(camel) - assert.equal(camel.gatingType, '品牌gating') - assert.equal(camel.shopName, '店A') - assert.equal(camel.createdAt, '2026-01-02 03:04:05') - assert.equal(camel.disabledAt, undefined) - - const snake = toGatingItem({ - id: 9, gating_type: '类目gating', shop_name: '店B', - created_at: '2026-02-01 00:00:00', updated_at: '2026-02-02 00:00:00', disabled_at: '2026-02-03 00:00:00', - }) - assert.ok(snake) - assert.equal(snake.gatingType, '类目gating') - assert.equal(snake.shopName, '店B') - assert.equal(snake.disabledAt, '2026-02-03 00:00:00') -}) - -test('gating_item_parse_invalid_rows_dropped', () => { - assert.equal(toGatingItem(null), null) - assert.equal(toGatingItem({ brand: 'no-id' }), null) - const page = parseGatingPage({ total: 3, rows: [{ id: 1, brand: 'a' }, { brand: 'bad' }, 'junk', null] }) - assert.equal(page.rows.length, 1) - assert.equal(page.rows[0]?.brand, 'a') - assert.equal(page.total, 3) -}) - -test('gating_page_parse_empty_and_items_alias', () => { - assert.deepEqual(parseGatingPage(null), { rows: [], total: 0 }) - const page = parseGatingPage({ total: 1, items: [{ id: 2, brand: 'b' }] }) - assert.equal(page.rows.length, 1) - assert.equal(page.rows[0]?.id, 2) -}) - -test('gating_stats_parse_array_and_dict_forms', () => { - // 契约数组形态。 - const stats = parseGatingStats({ - total: 10, active: 8, disabled: 2, brands: 5, - byType: [{ name: '品牌gating', count: 6 }, { name: '类目gating', count: 2 }], - byCountry: [{ name: '英国', count: 4 }], - bySource: [{ name: 'AUTO', count: 7 }], - }) - assert.equal(stats.total, 10) - assert.equal(stats.brands, 5) - assert.equal(stats.byType[0]?.name, '品牌gating') - assert.equal(stats.bySource[0]?.count, 7) - // 桌面版遗留 dict 形态也要能收。 - const legacy = parseGatingStats({ total: 1, by_type: { '品牌gating': 3 }, by_country: { '全部': 1 }, by_source: { MANUAL: 1 } }) - assert.equal(legacy.byType[0]?.name, '品牌gating') - assert.equal(legacy.byType[0]?.count, 3) - assert.equal(legacy.byCountry[0]?.name, '全部') -}) - -test('gating_name_count_list_garbage_in_empty_out', () => { - assert.deepEqual(parseGatingNameCountList(null), []) - assert.deepEqual(parseGatingNameCountList('x'), []) - assert.deepEqual(parseGatingNameCountList([{ name: '', count: 1 }, { count: 2 }, 'junk']), []) -}) - -test('gating_status_label', () => { - assert.equal(gatingStatusLabel(1), '生效') - assert.equal(gatingStatusLabel(0), '停用') - assert.equal(gatingStatusLabel(undefined), '停用') -}) diff --git a/admin-frontend-vue/tests/mount/gating-page.mount.test.ts b/admin-frontend-vue/tests/mount/gating-page.mount.test.ts deleted file mode 100644 index 9cd1c0d4e..000000000 --- a/admin-frontend-vue/tests/mount/gating-page.mount.test.ts +++ /dev/null @@ -1,138 +0,0 @@ -/** - * 品牌Gating库页面挂载测试:渲染(统计卡 + 行)与两次操作载荷断言(新增、恢复生效)。 - * 跑法:`npm run test:mount`(vitest + jsdom,配置见 vitest.config.ts)。 - */ -import { beforeEach, describe, expect, it, vi } from 'vitest' -import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' - -import GatingPage from '@/pages/gating/GatingPage.vue' - -const gatingApi = vi.hoisted(() => ({ - fetchGatingPage: vi.fn(), - fetchGatingStats: vi.fn(), - createGating: vi.fn(), - deleteGating: vi.fn(), - updateGatingStatus: vi.fn(), - importGatingText: vi.fn(), -})) - -vi.mock('@/pages/gating/gating-api', () => gatingApi) - -const listPayload = { - total: 2, - rows: [ - { - id: 1, - brand: 'jellycat', - asin: 'B0ABC123', - country: '英国', - gatingType: '品牌gating', - status: 1, - source: 'AUTO', - shopName: '', - remark: '', - createdAt: '2026-01-02 03:04:05', - updatedAt: '2026-01-03 03:04:05', - }, - { - id: 2, - brand: 'crocs', - asin: '', - country: '全部', - gatingType: '类目gating', - status: 0, - source: 'MANUAL', - shopName: '店A', - remark: '人为录入', - createdAt: '2026-02-01 00:00:00', - updatedAt: '2026-02-02 00:00:00', - disabledAt: '2026-02-03 00:00:00', - }, - ], -} - -const statsPayload = { - total: 2, - active: 1, - disabled: 1, - brands: 2, - byType: [{ name: '品牌gating', count: 1 }], - byCountry: [{ name: '英国', count: 1 }], - bySource: [{ name: 'MANUAL', count: 1 }], -} - -const findButton = (wrapper: VueWrapper, label: string) => - wrapper.findAll('button').find((button) => button.text().trim() === label) - -describe('GatingPage', () => { - beforeEach(() => { - vi.clearAllMocks() - gatingApi.fetchGatingPage.mockResolvedValue(listPayload) - gatingApi.fetchGatingStats.mockResolvedValue(statsPayload) - }) - - it('渲染统计卡、筛选区与表格行', async () => { - const wrapper = mount(GatingPage) - await flushPromises() - - const text = wrapper.text() - expect(text).toContain('Gating总记录') - expect(text).toContain('去重品牌数') - expect(text).toContain('jellycat') - expect(text).toContain('crocs') - expect(text).toContain('生效') - expect(text).toContain('停用') - expect(text).toContain('按Gating类型') - expect(wrapper.findAll('tbody tr').length).toBeGreaterThanOrEqual(2) - expect(gatingApi.fetchGatingPage).toHaveBeenCalledTimes(1) - expect(gatingApi.fetchGatingStats).toHaveBeenCalledTimes(1) - }) - - it('新增弹窗提交后按驼峰字段发载荷', async () => { - const wrapper = mount(GatingPage) - await flushPromises() - gatingApi.createGating.mockResolvedValue(1) - - await findButton(wrapper, '新增')!.trigger('click') - const modal = wrapper.get('.modal') - const inputs = modal.findAll('input[type="text"]') - await inputs[0]!.setValue('jellycat') // 品牌 - await inputs[1]!.setValue('B0Z9X') // ASIN - await inputs[2]!.setValue('店A') // 店铺 - await inputs[3]!.setValue('测试备注') // 备注 - - await findButton(modal, '保存')!.trigger('click') - await flushPromises() - - expect(gatingApi.createGating).toHaveBeenCalledTimes(1) - expect(gatingApi.createGating).toHaveBeenCalledWith({ - brand: 'jellycat', - asin: 'B0Z9X', - country: '全部', - gatingType: '品牌gating', - source: 'MANUAL', - shopName: '店A', - remark: '测试备注', - }) - }) - - it('停用行点恢复 → POST status 载荷 status=1;品牌为空时新增被拦截', async () => { - const wrapper = mount(GatingPage) - await flushPromises() - - const crocsRow = wrapper - .findAll('tbody tr') - .find((row) => row.text().includes('crocs'))! - await findButton(crocsRow, '恢复')!.trigger('click') - await flushPromises() - - expect(gatingApi.updateGatingStatus).toHaveBeenCalledTimes(1) - expect(gatingApi.updateGatingStatus).toHaveBeenCalledWith(2, 1) - - // 品牌必填:空品牌提交不发请求 - await findButton(wrapper, '新增')!.trigger('click') - await findButton(wrapper.get('.modal'), '保存')!.trigger('click') - await flushPromises() - expect(gatingApi.createGating).not.toHaveBeenCalled() - }) -}) diff --git a/admin-frontend-vue/tests/ops-cell-must-wrap.test.ts b/admin-frontend-vue/tests/ops-cell-must-wrap.test.ts index b8f61bde7..f929ffd69 100644 --- a/admin-frontend-vue/tests/ops-cell-must-wrap.test.ts +++ b/admin-frontend-vue/tests/ops-cell-must-wrap.test.ts @@ -36,7 +36,6 @@ const OPS_MIN_COL_PX: Record = { 'src/pages/asin/ProductCategoryPage.vue': 138, 'src/pages/asin/QueryAsinPage.vue': 138, 'src/pages/asin/SkipPricePage.vue': 138, - 'src/pages/gating/GatingPage.vue': 138, 'src/pages/records/DeviceLogsPage.vue': 138, 'src/pages/records/RecordsDigitalHumanVersionPage.vue': 287, 'src/pages/records/RecordsSoftwareVersionPage.vue': 77,