From 5bdc125b186b8d3d037f37ad29e3527dcac155df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Fri, 20 Nov 2026 14:19:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20=E7=BB=9F=E4=B8=80=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AD=9B=E9=80=89=E6=8E=A7=E4=BB=B6=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E4=B8=8E=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../e2e/admin-control-layout.spec.ts | 58 +++++++ .../e2e/admin-menu-layout.spec.ts | 159 ++++++++++++++++++ admin-frontend-vue/playwright.config.ts | 10 +- .../scripts/mock-admin-server.mjs | 5 +- .../src/components/BatchDeleteActions.vue | 21 ++- .../src/pages/asin/AsinInvalidPage.vue | 25 +-- .../src/pages/asin/ProductCategoryPage.vue | 2 +- .../RecordsDigitalHumanVersionPage.vue | 2 +- .../records/RecordsSoftwareVersionPage.vue | 2 +- .../src/pages/records/RecordsTutorialPage.vue | 2 +- .../records/WorkbenchClientPackagePage.vue | 2 +- admin-frontend-vue/src/styles/main.css | 14 +- 12 files changed, 274 insertions(+), 28 deletions(-) create mode 100644 admin-frontend-vue/e2e/admin-control-layout.spec.ts create mode 100644 admin-frontend-vue/e2e/admin-menu-layout.spec.ts diff --git a/admin-frontend-vue/e2e/admin-control-layout.spec.ts b/admin-frontend-vue/e2e/admin-control-layout.spec.ts new file mode 100644 index 000000000..80fb9f38b --- /dev/null +++ b/admin-frontend-vue/e2e/admin-control-layout.spec.ts @@ -0,0 +1,58 @@ +import { expect, test } from '@playwright/test' + +const brandPath = '/admin-vue/asin-center/invalid' + +test('品牌数据库:单行筛选控件等高、底边对齐,窄屏可以换行', async ({ page }) => { + await page.goto(brandPath) + const filters = page.locator('.invalid-filter-row') + await expect(filters.getByRole('button', { name: '查询' })).toBeVisible() + const controls = [ + filters.getByPlaceholder('输入 ASIN'), + filters.getByPlaceholder('输入品牌'), + filters.locator('.el-select__wrapper'), + filters.getByRole('button', { name: '查询' }), + ] + const boxes = await Promise.all(controls.map((control) => control.evaluate((el) => { + const { height, bottom } = el.getBoundingClientRect() + return { height, bottom } + }))) + expect(boxes.map((box) => box.height)).toEqual([34, 34, 34, 34]) + expect(Math.max(...boxes.map((box) => box.bottom)) - Math.min(...boxes.map((box) => box.bottom))).toBeLessThan(1) + + const batchDelete = page.getByRole('button', { name: '批量删除(0)' }) + await expect(batchDelete).toBeDisabled() + const batchBox = await batchDelete.boundingBox() + const tableBox = await page.locator('.invalid-asin-table-scroll').boundingBox() + expect(batchBox?.height).toBe(34) + expect(tableBox!.y - batchBox!.y - batchBox!.height).toBeGreaterThanOrEqual(8) + + await page.setViewportSize({ width: 680, height: 900 }) + await expect.poll(async () => filters.evaluate((row) => { + const first = row.firstElementChild!.getBoundingClientRect() + const last = row.lastElementChild!.getBoundingClientRect() + return last.top >= first.bottom && last.right <= row.getBoundingClientRect().right + 1 + })).toBe(true) +}) + +test('品牌数据库:键盘搜索分组、查询和新增仍可用', async ({ page }) => { + await page.goto(brandPath) + const filters = page.locator('.invalid-filter-row') + await filters.getByPlaceholder('输入品牌').press('Tab') + const group = filters.getByRole('combobox') + await expect(group).toBeFocused() + await group.fill('测试') + await expect(page.getByRole('option', { name: '测试分组' })).toBeVisible() + await expect(page.getByRole('option', { name: '其他分组' })).not.toBeVisible() + await page.getByRole('option', { name: '测试分组' }).click() + await filters.getByPlaceholder('输入 ASIN').fill('B0INVALID1') + const queried = page.waitForRequest((req) => new URL(req.url()).pathname === '/api/admin/invalid-asin-data' && req.url().includes('group_id=1')) + await filters.getByRole('button', { name: '查询' }).click() + const params = new URL((await queried).url()).searchParams + expect(params.get('data_value')).toBe('B0INVALID1') + expect(params.get('page')).toBe('1') + await page.getByRole('button', { name: '新增', exact: true }).click() + const dialog = page.getByRole('dialog') + await expect(dialog.getByRole('button', { name: '保存' })).toBeVisible() + await dialog.getByRole('button', { name: '取消' }).click() + await expect(dialog).not.toBeVisible() +}) diff --git a/admin-frontend-vue/e2e/admin-menu-layout.spec.ts b/admin-frontend-vue/e2e/admin-menu-layout.spec.ts new file mode 100644 index 000000000..b292397c5 --- /dev/null +++ b/admin-frontend-vue/e2e/admin-menu-layout.spec.ts @@ -0,0 +1,159 @@ +import { expect, test, type Locator } from '@playwright/test' + +// 独立的可见菜单清单;不从运行时路由反推夹具,以免漏注册时测试仍然全绿。 +const shared = [ + ['admin_users', '用户管理', 'account/users', '.form-row'], + ['admin_columns', '菜单管理', 'account/menus', '.form-row'], + ['admin_group_manage', '数据权限分组', 'account/groups', '.form-row'], + ['admin_companies', '公司管理', 'account/companies', '.form-row'], +] as const +const amazon = [ + ...shared, + ['admin_user_secrets', '密钥管理', 'account/user-secrets', '.form-row'], + ['admin_user_secret_usage', '密钥用量统计', 'account/user-secret-usage', '.form-row'], + ['admin_shop_data_duplicate_check', '店铺撞款监控', 'shop-center/duplicate-check', '.filter-row'], + ['admin_brand_gating', '品牌Gating库', 'shop-center/brand-gating', '.g-filters'], + ['admin_keyword_usage', '关键词使用记录', 'shop-center/keyword-usage', '.kw-filters'], + ['admin_shop_keys', '店铺密钥管理', 'shop-center/keys', '.form-row'], + ['admin_shop_manage', '店铺管理', 'shop-center/shops', '.form-row'], + ['admin_history', '生成记录', 'records/history', '.form-row'], + ['admin_version', '软件版本管理', 'records/software-version', '.admin-header-controls'], + ['admin_tutorial', '教程管理', 'records/tutorial', '.admin-header-controls'], + ['admin_workbench_client_package', '数富AI工作台客户端包管理', 'records/workbench-client-package', '.admin-header-controls'], + ['admin_device_logs', '日志管理', 'records/device-logs', '.form-row'], + ['admin_task_center', '客户端任务管理', 'task-center/board', '.form-row'], + ['digital_human_version', '数字人版本管理', 'records/digital-human-version', '.admin-header-controls'], + ['admin_image_video_tasks', '视频任务记录', 'records/image-video-tasks', '.form-row'], + ['admin_shop_data_crawl_tasks', '店铺数据记录', 'shop-center/data-tasks', '.form-row'], + ['admin_dedupe_total_data', '数据去重总数据', 'asin-center/registry', '.dedupe-filter-row'], + ['admin_invalid_asin_data', '品牌数据库', 'asin-center/invalid', '.form-row'], + ['admin_query_asin', '查询ASIN', 'asin-center/query', '.form-row'], + ['admin_product_categories', '商品类目', 'asin-center/categories', '.admin-header-controls'], + ['admin_skip_price_asin', '最低价ASIN', 'asin-center/skip-price', '.form-row'], + ['admin_appearance_patent_clean_items', '外观专利数据库', 'patent-center/clean-items', '.clean-filter-row'], +] as const +const jdDatabase = ['admin_jd_database', '京东数据库', 'jd-center/database', '.jd-filter-row'] as const +const jd = [...shared, jdDatabase] +const allMenus = [...amazon, jdDatabase].map(([key, name, path]) => ({ key, name, route: `/${path}` })) + +const emptyPage = { items: [], total: 0 } +const fixtures: Record = { + '/api/admin/appearance-patent-clean-items': emptyPage, + '/api/admin/brand-gating': emptyPage, + '/api/admin/brand-gating/stats': { total: 0 }, + '/api/admin/companies': { items: [{ id: 1, name: '测试公司' }], total: 1 }, + '/api/admin/device-logs/files': emptyPage, + '/api/admin/history': emptyPage, + '/api/admin/image-video-tasks': emptyPage, + '/api/admin/jd-product-groups': { items: [{ id: 1, name: '测试分类' }] }, + '/api/admin/jd-product-groups/scope': { + platformSuperAdmin: true, defaultGroupId: 1, + groups: [{ id: 1, name: '测试分组', label: '测试分组', editable: true }, { id: 2, name: '其他分组', label: '其他分组', editable: true }], + }, + '/api/admin/jd-products': emptyPage, + '/api/admin/jd-products/categories': [], + '/api/admin/keyword-usage': emptyPage, + '/api/admin/keyword-usage/deletes': emptyPage, + '/api/admin/keyword-usage/overview': {}, + '/api/admin/shop-data-crawl-tasks': emptyPage, + '/api/admin/shop-keys': emptyPage, + '/api/admin/shop-manages': emptyPage, + '/api/admin/shop-manages/groups': [{ id: 1, group_name: '测试分组' }], + '/api/admin/task-center/overview': { runningTasks: 0, todayFinishedTasks: 0, stuckTasks: 0 }, + '/api/admin/task-center/shop-options': { items: ['测试店铺'] }, + '/api/admin/task-center/tasks': emptyPage, + '/api/admin/task-center/variant-tasks': emptyPage, + '/api/admin/user-secret-usage': emptyPage, + '/api/admin/versions': emptyPage, + '/api/admin/workbench-client/packages': emptyPage, + '/api/digital-human/versions': emptyPage, +} + +// 这些接口在 mock-admin-server 里已经有专门的响应,不吃通用兜底。 +const serverFixtures = new Set([ + '/api/admin/current-user', '/api/admin/notifications/summary', '/api/admin/users', + '/api/admin/permission-menus', '/api/admin/user-secrets', '/api/admin/user-secrets/balances', + '/api/admin/shop-data-crawl/duplicate-check-console', '/api/admin/shop-data-crawl/duplicate-check-ledger', + '/api/admin/tutorials', '/api/admin/invalid-asin-data', '/api/admin/invalid-asin-data/groups', + '/api/admin/dedupe-total-data', '/api/admin/query-asins', '/api/admin/product-categories/children', + '/api/admin/skip-price-asins', +]) + +async function controlDeviations(row: Locator) { + await expect(row).toBeVisible() + return row.evaluate((el) => { + const selector = 'input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"], select, .el-select__wrapper:not(.is-multiple), button:not(.btn-sm), .admin-header-controls > .btn' + const controls = Array.from(el.querySelectorAll(selector)).flatMap((control) => { + if (control.matches('.el-select__input, .el-input__inner') || control.closest('[role="listbox"], .cat-panel')) return [] + const box = control.getBoundingClientRect() + if (!box.width || !box.height) return [] + const name = control.getAttribute('placeholder') || control.textContent?.trim() || control.className + return [{ name, box }] + }) + if (!controls.length) return ['没有测到可见控件'] + const failures = controls.filter(({ box }) => Math.abs(box.height - 34) >= 1) + .map(({ name, box }) => `${name}: ${box.height}px`) + for (const [index, { name, box }] of controls.entries()) { + for (const other of controls.slice(index + 1)) { + const overlapY = Math.min(box.bottom, other.box.bottom) - Math.max(box.top, other.box.top) + if (overlapY < 17) continue + if (Math.abs(box.bottom - other.box.bottom) >= 1) failures.push(`${name} / ${other.name} 底边未对齐`) + } + } + return failures + }) +} + +for (const [platform, menus] of [['亚马逊', amazon], ['京东', jd]] as const) { + test(`${platform}:逐个点击侧栏菜单,检查筛选区外框`, async ({ page, baseURL }) => { + test.setTimeout(120_000) + const pageErrors: string[] = [] + const missingFixtures = new Set() + page.on('pageerror', (error) => pageErrors.push(error.message)) + await page.route('**/*', async (route) => { + const url = new URL(route.request().url()) + if (url.origin !== baseURL) return route.abort() + if (url.pathname === '/api/admin/current-user/menus') { + return route.fulfill({ json: { success: true, data: { items: allMenus } } }) + } + if (Object.hasOwn(fixtures, url.pathname)) { + return route.fulfill({ json: { success: true, data: fixtures[url.pathname] } }) + } + if (url.pathname.startsWith('/api/') && !serverFixtures.has(url.pathname)) { + missingFixtures.add(url.pathname) + return route.abort() + } + return route.continue() + }) + await page.goto('/admin-vue/') + await page.getByRole('tab', { name: platform }).click() + const sidebar = page.locator('.admin-menu') + await expect(sidebar.getByRole('menuitem')).toHaveCount(menus.length) + const deviations: string[] = [] + for (const [, name, path, selector] of menus) { + await test.step(name, async () => { + await sidebar.getByRole('menuitem', { name, exact: true }).click() + await expect(page).toHaveURL(new RegExp(`/admin-vue/${path}$`)) + await expect(page.locator('.admin-topbar h1')).toHaveText(name) + const content = page.locator('#admin-content') + await expect(content.locator('.load-failure-bar:visible, .page-error:visible')).toHaveCount(0) + const record = async (label: string, row: Locator) => { + const mismatches = await controlDeviations(row) + if (mismatches.length) deviations.push(`${name}${label}:${mismatches.join('、')}`) + } + await record('', content.locator(`${selector}:visible`).first()) + if (path === 'asin-center/registry') { + await record('日期导出', content.locator('.dedupe-filter-date-row')) + } + if (path === 'task-center/board') { + await content.getByRole('button', { name: /^变体采集/ }).click() + await expect(content.getByRole('heading', { name: '变体采集(麦象批量任务)' })).toBeVisible() + await record('变体采集', content.locator('.form-row:visible')) + } + }) + } + expect.soft(pageErrors).toEqual([]) + expect.soft([...missingFixtures], '逐菜单验收不能使用未登记的空响应').toEqual([]) + expect(deviations).toEqual([]) + }) +} diff --git a/admin-frontend-vue/playwright.config.ts b/admin-frontend-vue/playwright.config.ts index 549db3b3a..426a74f9e 100644 --- a/admin-frontend-vue/playwright.config.ts +++ b/admin-frontend-vue/playwright.config.ts @@ -8,6 +8,7 @@ import { defineConfig } from '@playwright/test' * 会让 playwright 直接连上那个「不是本站」的服务,整份验收测的是别人的页面。 */ const PORT = Number(process.env.E2E_PORT || 5174) +const MOCK_PORT = Number(process.env.MOCK_PORT || 18100) export default defineConfig({ testDir: './e2e', @@ -27,13 +28,14 @@ export default defineConfig({ webServer: [ { command: 'node scripts/mock-admin-server.mjs', - port: 18100, - reuseExistingServer: true, + port: MOCK_PORT, + reuseExistingServer: false, }, { - command: `set VITE_API_TARGET=http://127.0.0.1:18100&& npm run dev -- --port ${PORT} --strictPort`, + command: `npm run dev -- --host 127.0.0.1 --port ${PORT} --strictPort`, + env: { VITE_API_TARGET: `http://127.0.0.1:${MOCK_PORT}` }, port: PORT, - reuseExistingServer: true, + reuseExistingServer: false, timeout: 120_000, }, ], diff --git a/admin-frontend-vue/scripts/mock-admin-server.mjs b/admin-frontend-vue/scripts/mock-admin-server.mjs index 06b5d008f..ea37c677c 100644 --- a/admin-frontend-vue/scripts/mock-admin-server.mjs +++ b/admin-frontend-vue/scripts/mock-admin-server.mjs @@ -345,6 +345,9 @@ const server = createServer((req, res) => { ], }) } + if (url === '/api/admin/invalid-asin-data/groups') { + return json(res, { success: true, data: [{ id: 1, group_name: '测试分组' }, { id: 2, group_name: '其他分组' }] }) + } if (url === '/api/admin/invalid-asin-data') { return json(res, { success: true, @@ -589,4 +592,4 @@ const server = createServer((req, res) => { return json(res, { success: true }, 200) }) -server.listen(PORT, () => console.log(`mock admin api listening on ${PORT}`)) +server.listen(PORT, '127.0.0.1', () => console.log(`mock admin api listening on ${PORT}`)) diff --git a/admin-frontend-vue/src/components/BatchDeleteActions.vue b/admin-frontend-vue/src/components/BatchDeleteActions.vue index 71183f24e..9ceaa2089 100644 --- a/admin-frontend-vue/src/components/BatchDeleteActions.vue +++ b/admin-frontend-vue/src/components/BatchDeleteActions.vue @@ -14,10 +14,10 @@ defineProps<{