Compare commits
270 Commits
1d4b4decf3
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 19b32414ac | |||
| f742df9f20 | |||
| fe479262e6 | |||
| 3184d6696d | |||
| bbadc445af | |||
| 9991aaaf7d | |||
| 067e7e5ba3 | |||
| 98476d0d47 | |||
| 66946c2391 | |||
| 0a769fa8d3 | |||
| b20f0bb44a | |||
| 08b1f3f7f8 | |||
| 6685491fcb | |||
| 085c285446 | |||
| 9eb42fe16a | |||
| 0f81034eab | |||
| 4261103e31 | |||
| c59296da72 | |||
| a2aeae9974 | |||
| 427f22e0b4 | |||
| a4744570e1 | |||
| 6034a7a961 | |||
| b88432d8a9 | |||
| 3702c83c60 | |||
| 380792aa82 | |||
| 22771a7aea | |||
| 2de2714d00 | |||
| 3a24674c9d | |||
| 9999bba223 | |||
| f96d5118da | |||
| 81869f75d0 | |||
| 9b23b4934d | |||
| acd61aa1d2 | |||
| 5bdc125b18 | |||
| 51c41b238a | |||
| 132c19d51f | |||
| e903bc1845 | |||
| d69780cbc1 | |||
| 9220bbdc82 | |||
| c6f70a0b11 | |||
| ce3502be9a | |||
| 4f759b996c | |||
| 8757fb21ad | |||
| bcdf7faf13 | |||
| aeaa7f64f4 | |||
| 23e326df19 | |||
| 8453091630 | |||
| b030ce392c | |||
| 77bfd4cf1b | |||
| 472a7e001b | |||
| 4de78adfc7 | |||
| 96afb685c2 | |||
| 83e9bbe71a | |||
| 1524099d3b | |||
| bd6f2cdc91 | |||
| 84c664c795 | |||
| 917884aa6d | |||
| b5578561df | |||
| 1105320354 | |||
| 8ac9fafb7b | |||
| 2a8bdd7d29 | |||
| 24272a910c | |||
| f4bde32f83 | |||
| 885fa813db | |||
| ea9dca3faf | |||
| 7f76a96264 | |||
| 0c4354fc1e | |||
| 8b0cde4a51 | |||
| c15f0ce229 | |||
| 6ccf7f2bb3 | |||
| ae250ea182 | |||
| d850c46f46 | |||
| 2a0cc86572 | |||
| 164b9b83fa | |||
| 0f375dcd04 | |||
| b59663ebdb | |||
| 6dc33ea725 | |||
| b4e97823f4 | |||
| d25c91f6da | |||
| 20ee73349e | |||
| d28461d3d3 | |||
| 56fe32e8e9 | |||
| 283921df0c | |||
| 2078e9efde | |||
| 7299166e96 | |||
| 80060912ca | |||
| ee613db05b | |||
| dc3e7f3b37 | |||
| db71803430 | |||
| 848fef3b03 | |||
| 5c7a310ee7 | |||
| 764eeb2914 | |||
| 0f8b37e279 | |||
| 71b19e4f69 | |||
| aff6c88a7d | |||
| 3279b779e6 | |||
| 9d7da26c26 | |||
| 47fc0e0850 | |||
| cac5b8ae7d | |||
| 7067d5380d | |||
| 61ab844e5d | |||
| e621deea58 | |||
| 61c361222d | |||
| 8413cd335e | |||
| 5aab38cfa9 | |||
| 8c81546aa7 | |||
| 79eb7a7f16 | |||
| a5e390750b | |||
| c9ecae6e6d | |||
| 7b853a605e | |||
| 3bccc97698 | |||
| 9b6f00a2dc | |||
| 301e3c5ecb | |||
| d680a0beca | |||
| 2a4598216a | |||
| dca5d6f554 | |||
| 3cbaf06583 | |||
| 562e81df81 | |||
| 9e3f28079b | |||
| 8b4f7a3a6b | |||
| 9f869b2e81 | |||
| 46a334004a | |||
| ee3ff6fe8c | |||
| 4506253989 | |||
| 6818f9777b | |||
| d0aa93759d | |||
| e175e85973 | |||
| 91cf5dfaf7 | |||
| b9b66bcb0b | |||
| 84a4bc38b5 | |||
| dea9891e19 | |||
| 7a117187b7 | |||
| 5d5330d0c9 | |||
| 700e7c8518 | |||
| 1c3395869e | |||
| ab6e49b5e2 | |||
| 9c8926068d | |||
| edc1772683 | |||
| 45d0989ada | |||
| 55f4f17480 | |||
| 85f8ebc3c7 | |||
| 402447af70 | |||
| 8d8c88a5f3 | |||
| 47278ee425 | |||
| 36e110d27c | |||
| 05e5c35539 | |||
| 796ec2130f | |||
| edeffc26c4 | |||
| ff859d25bc | |||
| 6ce995f19e | |||
| 53e176ba7c | |||
| a429191edd | |||
| 334ed2cadd | |||
| 10d73994f5 | |||
| 64e94458c9 | |||
| f5f40cd2ea | |||
| ad33b7d54c | |||
| a940cd227f | |||
| 4d008608b1 | |||
| f7b206474d | |||
| faa08a6138 | |||
| 5390503f7a | |||
| ef78608a64 | |||
| a17d8edc9e | |||
| 691b29da7e | |||
| 7a69210967 | |||
| c00f8c6e1c | |||
| bfd8ceac52 | |||
| 3dec8d41ed | |||
| e1767faff5 | |||
| 2a2e276c32 | |||
| 3cfca462ce | |||
| f218766a55 | |||
| a5bd4011e2 | |||
| 6f85f17c58 | |||
| 9b4404d027 | |||
| cec863af89 | |||
| bd0c0a0810 | |||
| 7ce6ff64cc | |||
| 9acb221152 | |||
| 264db52b84 | |||
| 83f1ecf952 | |||
| 0512359b21 | |||
| 434e4bf037 | |||
| a94e59d434 | |||
| 7c7712e7f3 | |||
| b36c52e4d0 | |||
| 6919108043 | |||
| 61ec324b2f | |||
| 48b961f0b2 | |||
| 89a69d651e | |||
| 62e92003f2 | |||
| c461210b12 | |||
| cc22600a07 | |||
| a10aa6bda3 | |||
| eeff73d322 | |||
| 609ad396a6 | |||
| b231a67dd7 | |||
| 56b916f2fe | |||
| b321ea6f45 | |||
| 847f8a224a | |||
| 09a34a2856 | |||
| 00f45cc20f | |||
| e71fa7fa83 | |||
| c8cd75cf6c | |||
| fee4df5bf6 | |||
| b9d23d5936 | |||
| 51401de2d5 | |||
| 34f730d403 | |||
| 66621d8a16 | |||
| 43240b9a10 | |||
| 6444c17edc | |||
| a04c1f3cf6 | |||
| 13fd426133 | |||
| f43ed6f116 | |||
| 37f51df37d | |||
| 0114a5b7a7 | |||
| e26a157037 | |||
| 2cbd99ed4f | |||
| 7e64c12dd6 | |||
| 7f5437d012 | |||
| 8f206a6019 | |||
| 96b090dfd5 | |||
| 0a467793ac | |||
| 0dfd385c4c | |||
| 35ce0f0f40 | |||
| 6a9dc34713 | |||
| 3f827cc9af | |||
| faae355bcf | |||
| 91d36327f9 | |||
| a4e4456b50 | |||
| 1c179e0f2e | |||
| 7469c710d7 | |||
| 7459177bb4 | |||
| 2c2cb23943 | |||
| b13d795731 | |||
| 6fe5c8c8d0 | |||
| 5c283a79fc | |||
| ffb043c24f | |||
| d2cc7b1299 | |||
| c7b035dce9 | |||
| 1c0cc350be | |||
| 43ae12f722 | |||
| 79b04afdd9 | |||
| 457af3607f | |||
| eaab173ae9 | |||
| 4d38781005 | |||
| 39c01ada44 | |||
| 8b7d5d4a40 | |||
| 217f5eec62 | |||
| ef0bc51fa2 | |||
| 0586df2df0 | |||
| 62a1b50067 | |||
| c4fc9784e8 | |||
| 0e2af88184 | |||
| b3d90d2161 | |||
| 632efa6a8e | |||
| 46774fffed | |||
| 9df044621f | |||
| 437d75db52 | |||
| 88d737a7f0 | |||
| e08b5369d7 | |||
| 07f973d9df | |||
| f3445c21c8 | |||
| e0abd33ed4 | |||
| b8abdc1eec | |||
| 915a573439 | |||
| 2163c6b585 | |||
| 9e5529ef59 | |||
| a3f765c458 |
@@ -14,6 +14,8 @@ backend-java/target/
|
||||
backend-java/data/
|
||||
backend-java/*.log
|
||||
backend-java/logs/
|
||||
# 会话级诊断脚本残渣(2026-11-03 瘦身审计 BD-8:_diag_keyword_sync.py 有误提交风险)
|
||||
backend-java/tmp/
|
||||
backend-java/src/main/resources/application-local.yml
|
||||
backend-java/.idea/
|
||||
backend-java/*.iml
|
||||
@@ -140,6 +142,11 @@ data/logs/
|
||||
# 生产库转储永不再入库(本体只留 backend-java/data/,那里已被忽略)
|
||||
backend-java/src/main/resources/db/aiimage.sql
|
||||
|
||||
# ===== 文档与参考资料不入库(2026-11-19 用户拍板:docs/reference 及非源码内容不提交,只留本地;
|
||||
# 取代上面「规划文档入库」的 2026-10-04 口径——当前实测本仓 0 支 docs/md 跟踪件)=====
|
||||
/docs/
|
||||
/reference/
|
||||
|
||||
# 打包前由 scripts/_git_stamp.py write 生成,随 jar 进 BOOT-INF/classes/;
|
||||
# 入库会变成"孤儿构建产物"(10-07 那笔 target/classes 里的 V148 就是这个形状造成的宕机)
|
||||
backend-java/src/main/resources/git.properties
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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<string, unknown> = {
|
||||
'/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<HTMLElement>(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<string>()
|
||||
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([])
|
||||
})
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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,
|
||||
@@ -499,6 +502,32 @@ const server = createServer((req, res) => {
|
||||
},
|
||||
})
|
||||
}
|
||||
if (url === '/api/admin/user-secrets/balances') {
|
||||
// 余额侧写夹具(POST):两把密钥同渠道 ⇒ 界面折叠成一行;代理给「你的套餐」形状
|
||||
const llmCell = (moduleKey, moduleLabel, over = {}) => ({
|
||||
moduleKey, moduleLabel,
|
||||
channel: 'longtaitou', channelLabel: '龙抬头',
|
||||
available: true, balance: '88.888882', availableBalance: '85.288882', frozen: '3.6',
|
||||
unit: 'CREDIT', message: null, checkedAt: '2026-11-05T10:30:00', ...over,
|
||||
})
|
||||
return json(res, {
|
||||
success: true,
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
userId: 1,
|
||||
llm: [
|
||||
llmCell('appearance-patent', '外观专利密钥'),
|
||||
llmCell('similar-asin', '货源查询密钥'),
|
||||
],
|
||||
proxy: { available: true, surplus: '1234', balance: '56', scope: 'user', message: null },
|
||||
},
|
||||
],
|
||||
deniedUserIds: [],
|
||||
timedOutUserIds: [],
|
||||
},
|
||||
})
|
||||
}
|
||||
if (url === '/api/admin/shop-manage-groups') {
|
||||
return json(res, { success: true, data: { items: [] } })
|
||||
}
|
||||
@@ -563,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}`))
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
import { useGlobalErrorReporting } from '@/shared/api/error-report'
|
||||
|
||||
// 浏览器级错误兜底接线(S1-F2/AC-16):脚本级崩溃与没人接的 Promise 都进同一条上报路,
|
||||
// 卸载出口由该 composable 的 onBeforeUnmount 摘掉——根组件不卸载时它就是应用级单例。
|
||||
useGlobalErrorReporting()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
import { http, unwrap } from '@/api/http'
|
||||
|
||||
/**
|
||||
* 大档分片阈值与片大小(AC-11):后管这一侧只有这一个出口,阈值由片大小派生。
|
||||
*
|
||||
* ⚠ 同族的 8MB 数还另有两处:用户端上传出口一处、桌面客户端分片入口一处。两边是各自
|
||||
* 独立的构建根(各自的 `@` 别名与 tsconfig include),客户端是 Python 打包物 ⇒
|
||||
* 没有共享包就合不成同一个字面量(P3-5 的边界,已登记)。
|
||||
*/
|
||||
export const CHUNK_UPLOAD_PART_SIZE = 8 * 1024 * 1024
|
||||
export const CHUNK_UPLOAD_THRESHOLD = CHUNK_UPLOAD_PART_SIZE
|
||||
|
||||
/** 每片重试次数(不含首次):单片 502/超时不该让 512MB 从 0 再来。 */
|
||||
const PART_RETRY_LIMIT = 2
|
||||
|
||||
/**
|
||||
* 逐片超时(P2-8):预算只看**这一片**有多大——60s 保底 + 每 MB 30s(8MB 片=300s)。
|
||||
* 过去按整包体积算(120s + MB×15s),512MB 包里的一个 8MB 片能拿到 128 分钟,
|
||||
* 慢链路真卡死时没人知道,进度条还会一直爬。
|
||||
*/
|
||||
export function partTimeoutOf(partBytes: number): number {
|
||||
return 60_000 + Math.ceil(partBytes / (1024 * 1024)) * 30_000
|
||||
}
|
||||
|
||||
/** 会话登记/查询只发元数据,固定预算即可;失败要快快回来,别陪整包一起放大。 */
|
||||
const REQUEST_TIMEOUT_MS = 60_000
|
||||
/** 只有拼装这一步真随整包体积走:服务端要读全部分片、复算 sha256。 */
|
||||
const COMPLETE_TIMEOUT_MS = 600_000
|
||||
|
||||
function partUrl(uploadId: string, index: number): string {
|
||||
return `/api/files/chunk/${encodeURIComponent(uploadId)}/part/${index}`
|
||||
}
|
||||
|
||||
/** 分片会话跨尝试/刷新续用:同一文件身份复用 upload_id,服务端没回收就从已达片号继续(P2-7)。 */
|
||||
interface StoredChunkSession {
|
||||
uploadId: string;
|
||||
size: number;
|
||||
lastModified: number;
|
||||
}
|
||||
|
||||
const CHUNK_SESSION_PREFIX = 'shufu:admin:chunk:'
|
||||
|
||||
function lastModifiedOf(file: Blob): number {
|
||||
const value = (file as File).lastModified
|
||||
return typeof value === 'number' && Number.isFinite(value) ? value : 0
|
||||
}
|
||||
|
||||
/** 会话键:文件名+体积+修改时间,三者同一条上传才算同一个件。 */
|
||||
export function chunkSessionKeyOf(fileName: string, file: Blob): string {
|
||||
return `${CHUNK_SESSION_PREFIX}${fileName}:${file.size}:${lastModifiedOf(file)}`
|
||||
}
|
||||
|
||||
function readStoredSession(key: string, file: Blob): string {
|
||||
if (typeof localStorage === 'undefined') return ''
|
||||
try {
|
||||
const raw = localStorage.getItem(key)
|
||||
if (!raw) return ''
|
||||
const parsed = JSON.parse(raw) as StoredChunkSession
|
||||
return parsed.size === file.size && parsed.lastModified === lastModifiedOf(file) ? parsed.uploadId : ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function writeStoredSession(key: string, file: Blob, uploadId: string): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify({
|
||||
uploadId, size: file.size, lastModified: lastModifiedOf(file),
|
||||
} satisfies StoredChunkSession))
|
||||
} catch {
|
||||
// 存储不可用(隐私模式/配额满)只影响跨刷新续传,不影响本次上传
|
||||
}
|
||||
}
|
||||
|
||||
function clearStoredSession(key: string): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
try {
|
||||
localStorage.removeItem(key)
|
||||
} catch {
|
||||
// 同上:清不掉只会让下次多问一次 status
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端对「这个会话还在不在」的三种答复:还在(附带已到片号)/确实没了/问不出来。
|
||||
* 第三态是 P2-7 与 P1-11 的共同判据——过去它被当成"没会话",瞬态抖动=整包作废。
|
||||
*/
|
||||
type ProbeOutcome
|
||||
= { state: 'ok'; parts: number[] }
|
||||
| { state: 'gone' }
|
||||
| { state: 'transient' }
|
||||
|
||||
/** 后端回收会话的原文案(ChunkedUploadService.readMeta);BusinessException 不带 code ⇒ HTTP 200 出。 */
|
||||
function messageSaysSessionGone(text: unknown): boolean {
|
||||
const message = typeof text === 'string' ? text : ''
|
||||
return ['不存在', '过期'].some((marker) => message.includes(marker))
|
||||
}
|
||||
|
||||
function classifyProbe(response: unknown): ProbeOutcome {
|
||||
const status = Number((response as { status?: unknown } | null | undefined)?.status)
|
||||
if (status === 404) return { state: 'gone' }
|
||||
if (status >= 500 || status === 408 || status === 429) return { state: 'transient' }
|
||||
const body = (response as { data?: unknown } | null | undefined)?.data
|
||||
if (body && typeof body === 'object' && (body as { success?: unknown }).success === false) {
|
||||
return messageSaysSessionGone((body as { message?: unknown }).message)
|
||||
? { state: 'gone' }
|
||||
: { state: 'transient' }
|
||||
}
|
||||
const core = (unwrap<Record<string, unknown>>(body) ?? {}) as Record<string, unknown>
|
||||
const arrived = core.uploaded_parts
|
||||
return { state: 'ok', parts: Array.isArray(arrived) ? arrived.map((value) => Number(value)) : [] }
|
||||
}
|
||||
|
||||
/**
|
||||
* 探测已达片号(P2-7/与用户端 upload.ts 同一口径)。
|
||||
* validateStatus 恒真:状态码要自己判——真 404/5xx 一旦被拦截器折成 Error 就分不出原因了;
|
||||
* 能走到 catch 的就只剩网络层失败与超时,铁定瞬态。
|
||||
*/
|
||||
async function probeUploadedParts(uploadId: string): Promise<ProbeOutcome> {
|
||||
try {
|
||||
const response = await http.get(
|
||||
`/api/files/chunk/${encodeURIComponent(uploadId)}`,
|
||||
{ validateStatus: () => true },
|
||||
)
|
||||
return classifyProbe(response)
|
||||
} catch (error) {
|
||||
const status = (error as { response?: { status?: unknown } } | null | undefined)?.response?.status
|
||||
if (status === 404) return { state: 'gone' }
|
||||
if (messageSaysSessionGone((error as { message?: unknown } | null | undefined)?.message)) {
|
||||
return { state: 'gone' }
|
||||
}
|
||||
return { state: 'transient' }
|
||||
}
|
||||
}
|
||||
|
||||
/** 后管大档上传(版本包/教程包共用):会话续用 → GET 已达片号 → 逐片 POST → complete。 */
|
||||
export async function uploadFileInChunks(
|
||||
file: Blob,
|
||||
fileName: string,
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const totalParts = Math.max(1, Math.ceil(file.size / CHUNK_UPLOAD_PART_SIZE))
|
||||
const sessionKey = chunkSessionKeyOf(fileName, file)
|
||||
let uploadId = readStoredSession(sessionKey, file)
|
||||
const arrived = new Set<number>()
|
||||
if (uploadId) {
|
||||
const probed = await probeUploadedParts(uploadId)
|
||||
if (probed.state === 'gone') {
|
||||
// 服务端确实说会话没了(404/「不存在或已过期」):清掉重开,否则这个件每次都在同一个死会话上失败。
|
||||
clearStoredSession(sessionKey)
|
||||
uploadId = ''
|
||||
} else if (probed.state === 'ok') {
|
||||
probed.parts.forEach((index) => arrived.add(index))
|
||||
}
|
||||
// transient:片号未知但会话还在 ⇒ 照原会话逐片重传(后端同片覆盖,幂等),不重开 init。
|
||||
}
|
||||
if (!uploadId) {
|
||||
const initResponse = await http.post('/api/files/chunk/init', null, {
|
||||
params: { fileName, totalParts, totalBytes: file.size },
|
||||
timeout: REQUEST_TIMEOUT_MS,
|
||||
})
|
||||
const init = (unwrap(initResponse.data) ?? {}) as Record<string, unknown>
|
||||
uploadId = String(init.upload_id ?? '')
|
||||
if (!uploadId) {
|
||||
throw new Error('后端未返回分片会话,请重试')
|
||||
}
|
||||
writeStoredSession(sessionKey, file, uploadId)
|
||||
}
|
||||
|
||||
for (let index = 0; index < totalParts; index += 1) {
|
||||
if (arrived.has(index)) {
|
||||
continue
|
||||
}
|
||||
const blob = file.slice(index * CHUNK_UPLOAD_PART_SIZE,
|
||||
Math.min(file.size, (index + 1) * CHUNK_UPLOAD_PART_SIZE))
|
||||
let lastError: unknown = null
|
||||
for (let attempt = 0; attempt <= PART_RETRY_LIMIT; attempt += 1) {
|
||||
const form = new FormData()
|
||||
form.append('file', blob, `part-${index}`)
|
||||
try {
|
||||
const partResponse = await http.post(partUrl(uploadId, index), form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: partTimeoutOf(blob.size),
|
||||
onUploadProgress: (event) => {
|
||||
if (!onProgress) return
|
||||
const perPart = Math.round(((index + (event.loaded || 0) / Math.max(blob.size, 1)) / totalParts) * 100)
|
||||
onProgress(Math.min(perPart, 99))
|
||||
},
|
||||
})
|
||||
unwrap(partResponse.data)
|
||||
arrived.add(index)
|
||||
lastError = null
|
||||
break
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
}
|
||||
if (lastError) {
|
||||
// 不 DELETE(P2-7):会话连同已达片号留在服务端(后端 24h 过期回收兜底),
|
||||
// 下一次点开同一个文件就从断点接着传——这才是"续传"两个字的本义。
|
||||
throw lastError instanceof Error ? lastError : new Error('分片上传失败')
|
||||
}
|
||||
}
|
||||
|
||||
const completeResponse = await http.post(
|
||||
`/api/files/chunk/${encodeURIComponent(uploadId)}/complete`, null, { timeout: COMPLETE_TIMEOUT_MS })
|
||||
clearStoredSession(sessionKey)
|
||||
if (onProgress) onProgress(100)
|
||||
return (unwrap(completeResponse.data) ?? {}) as Record<string, unknown>
|
||||
}
|
||||
@@ -15,6 +15,8 @@ export interface CompanyItem {
|
||||
remark: string | null
|
||||
createdAt: string | null
|
||||
updatedAt: string | null
|
||||
/** 所属平台(V206):'amazon'|'jd';后端恒带值(列 NOT NULL DEFAULT 'amazon'),旧负载缺省不渲染。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
/** 新建/改名的表单草稿。 */
|
||||
@@ -22,6 +24,8 @@ export interface CompanyDraft {
|
||||
companyName: string
|
||||
status?: number
|
||||
remark?: string | null
|
||||
/** 所属平台(V206):新建必带(页面从平台 tab 取),编辑显式下发,缺省后端不动。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
export function text(value: unknown): string {
|
||||
@@ -48,5 +52,6 @@ export function toCompanyPayload(draft: CompanyDraft): Record<string, unknown> {
|
||||
const payload: Record<string, unknown> = { companyName: text(draft.companyName).trim() }
|
||||
if (typeof draft.status === 'number') payload.status = draft.status
|
||||
payload.remark = trimmedOrNull(draft.remark)
|
||||
if (draft.platform) payload.platform = draft.platform
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export function toCompanyItem(raw: unknown): CompanyItem | null {
|
||||
const r = raw as Record<string, unknown>
|
||||
const id = numberOrNull(r.id)
|
||||
if (id === null) return null
|
||||
return {
|
||||
const item: CompanyItem = {
|
||||
id,
|
||||
companyName: text(r.company_name),
|
||||
// status 列 NOT NULL,取不到就是链路异常;未知一律按停用,不把异常状态当启用。
|
||||
@@ -27,6 +27,10 @@ export function toCompanyItem(raw: unknown): CompanyItem | null {
|
||||
createdAt: trimmedOrNull(r.created_at),
|
||||
updatedAt: trimmedOrNull(r.updated_at),
|
||||
}
|
||||
// platform 后端恒带(列 NOT NULL);旧负载/测试桩缺省就不渲染该键,字段形状与 users-model 一致。
|
||||
const platform = text(r.platform)
|
||||
if (platform) item.platform = platform
|
||||
return item
|
||||
}
|
||||
|
||||
/** 解析 GET /api/admin/companies:接受 data 为数组或 {items:[...]},success=false 抛后端文案。 */
|
||||
|
||||
@@ -4,8 +4,10 @@ import { toCompanyPayload, type CompanyDraft, type CompanyItem } from './compani
|
||||
|
||||
/** 公司目录(设计文档 §2.3)。GET 的可见范围由后端收窄:超管全部、公司内 admin 只自己公司。 */
|
||||
|
||||
export async function fetchCompanies(): Promise<CompanyItem[]> {
|
||||
const { data } = await http.get('/api/admin/companies')
|
||||
export async function fetchCompanies(platform?: string): Promise<CompanyItem[]> {
|
||||
const { data } = await http.get('/api/admin/companies', {
|
||||
params: platform ? { platform } : {},
|
||||
})
|
||||
return parseCompanyList(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,20 @@ import { unwrap } from './envelope'
|
||||
export interface AdminUserSecretModule {
|
||||
moduleKey: string
|
||||
moduleLabel: string
|
||||
/**
|
||||
* 货源:按模块分域,后端 `UserSecretModule.channelOrDefault` 已归一——
|
||||
* LLM 行为渠道(longtaitou/t8star),代理行为供应商(qingguo/jikip)。
|
||||
* ⚠ 界面不得用一张合表渲染这两域(代理行贴出「龙抬头」就是这么来的),
|
||||
* 走 `user-secret-model.ts` 的 `moduleSourceLabel`。
|
||||
*/
|
||||
channel?: string | null
|
||||
/** 脱敏值:代理列为 `scheme://host`,不含提取链接里的 key/pwd。 */
|
||||
masked: string
|
||||
/** 完整明文值:仅代理列有值(后端对密钥列不下发明文)。 */
|
||||
/**
|
||||
* 完整明文值:后台侧**恒为空**(2026-11-02 `SecretMasking.maskProxy` 收口,代理链接里带着账密)。
|
||||
* 字段保留只为接口兼容;界面**不得**读它、更不得拿它做"masked 空就回落原文"的兜底,
|
||||
* 也不许有任何复制/导出整条链接的旁路。
|
||||
*/
|
||||
full: string
|
||||
exists: boolean
|
||||
/** 是否由后台代填并锁定:锁定时客户端不可修改或清空。 */
|
||||
@@ -51,6 +63,53 @@ export interface GroupOption {
|
||||
groupName: string
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM 一格的余额(**人民币口径**,后端取龙抬头 `credits` 块)。
|
||||
* 与 `AdminProxyBalanceCell` 是两套语义:这里的 `balance` 是钱、单位 CREDIT(=⚡=人民币),
|
||||
* 代理那边的 `surplus` 是「次」。界面不得用一张函数渲染两域(同 `channel` 那张表的教训)。
|
||||
*/
|
||||
export interface AdminLlmBalanceCell {
|
||||
moduleKey: string
|
||||
moduleLabel: string
|
||||
channel: string
|
||||
channelLabel: string
|
||||
available: boolean
|
||||
/** 上游原样小数串(未取整);available=false 时为 null。 */
|
||||
balance: string | null
|
||||
availableBalance: string | null
|
||||
frozen: string | null
|
||||
/** 恒为 CREDIT;不是这个值就按「认不出口径」处理,不猜。 */
|
||||
unit: string | null
|
||||
message: string | null
|
||||
checkedAt: string | null
|
||||
}
|
||||
|
||||
/** 代理余量一格:jikip 套餐口径(`surplus`=IP 次数、`scope`=谁的池子)。青果为 scope=none。 */
|
||||
export interface AdminProxyBalanceCell {
|
||||
available: boolean
|
||||
surplus: string | null
|
||||
balance: string | null
|
||||
/** user=该用户自己的套餐;platform=平台池子(不是这个用户的钱);none=查不了。 */
|
||||
scope: string | null
|
||||
message: string | null
|
||||
low?: boolean
|
||||
lowReason?: string | null
|
||||
}
|
||||
|
||||
export interface AdminUserSecretBalanceItem {
|
||||
userId: number
|
||||
llm: AdminLlmBalanceCell[]
|
||||
proxy: AdminProxyBalanceCell
|
||||
}
|
||||
|
||||
export interface AdminUserSecretBalances {
|
||||
items: AdminUserSecretBalanceItem[]
|
||||
/** 被数据权限剔出、本次没查的用户(不静默少给数)。 */
|
||||
deniedUserIds?: number[]
|
||||
/** 超出整请求时间预算、这轮没取到数的用户。 */
|
||||
timedOutUserIds?: number[]
|
||||
}
|
||||
|
||||
export interface UserSecretQuery {
|
||||
keyword?: string
|
||||
checkStatus?: string
|
||||
@@ -75,6 +134,23 @@ export async function fetchUserSecretList(params: UserSecretQuery): Promise<Admi
|
||||
return unwrap<AdminUserSecretPage>(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新本页用户的余额侧写:POST /api/admin/user-secrets/balances。
|
||||
*
|
||||
* 实时打上游、不落库,所以服务端带三条护栏(单次 ≤20 个用户、固定并发、整请求 10s 预算),
|
||||
* 客户端的超时必须**长于**服务端预算,否则服务端还在取数、这边先报错,
|
||||
* 界面就会把「查得慢」显示成「查不到」(与铁律 10「前端超时不得短于服务端预算」同形)。
|
||||
*/
|
||||
export async function fetchAdminSecretBalances(
|
||||
userIds: number[],
|
||||
companyId?: number | null,
|
||||
): Promise<AdminUserSecretBalances> {
|
||||
const body: Record<string, unknown> = { userIds }
|
||||
if (companyId != null) body.company_id = companyId
|
||||
const { data } = await http.post('/api/admin/user-secrets/balances', body, { timeout: 30_000 })
|
||||
return unwrap<AdminUserSecretBalances>(data)
|
||||
}
|
||||
|
||||
/** 立即检测该用户全部已配置项:POST /api/admin/user-secrets/{userId}/check
|
||||
* 逐模块检测(每项最多「首查 + 传输层失败重试一次」,最坏约 31s/项),故放宽超时到 180s。 */
|
||||
export async function checkUserSecret(userId: number) {
|
||||
@@ -98,13 +174,22 @@ export async function deleteUserSecret(userId: number): Promise<void> {
|
||||
unwrap<unknown>(data)
|
||||
}
|
||||
|
||||
/** 代填并锁定该用户某模块配置(当前仅代理):PUT /api/admin/user-secrets/{userId}/modules/{moduleKey} */
|
||||
/**
|
||||
* 代填并锁定该用户某模块配置(当前仅代理):PUT /api/admin/user-secrets/{userId}/modules/{moduleKey}
|
||||
* `value` 是**一次性写载荷**(代理为现拼的提取链接,带着 key/pwd):调用方不得把它渲染回界面、
|
||||
* 不得打进日志;`channel` 是同一单的货源(代理=供应商 key),后端据此选解析分支——
|
||||
* 不给则由后端按链接域名识别,识别不出回落默认供应商,会静默换执行方,所以本面一律显式带上。
|
||||
*/
|
||||
export async function saveUserSecretModule(
|
||||
userId: number,
|
||||
moduleKey: string,
|
||||
value: string,
|
||||
channel?: string,
|
||||
): Promise<AdminUserSecretModule> {
|
||||
const { data } = await http.put(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`, { value })
|
||||
const { data } = await http.put(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`, {
|
||||
value,
|
||||
...(channel ? { channel } : {}),
|
||||
})
|
||||
return unwrap<AdminUserSecretModule>(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** 用户管理列表/分页 DTO(任务 41):纯逻辑,无框架依赖,与 Java AdminUserController 对齐。 */
|
||||
import type { AdminUser } from '../types/admin'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
|
||||
export const USER_PAGE_DEFAULT_SIZE = 10
|
||||
export const USER_PAGE_MIN_PAGE = 1
|
||||
@@ -18,6 +19,8 @@ export interface UserListParams {
|
||||
/** 公司 tab 的当前公司;由页面从 store 传入,**不住在 UserFilterState 里**
|
||||
* (normalizeUserPageParams 白名单构造会把它丢掉,取值口只认 fetchUserList 的原始入参)。 */
|
||||
companyId?: number | null
|
||||
/** 平台 tab 的当前平台(V206);同 companyId 形状:白名单构造不收,从原始入参读。 */
|
||||
platform?: PlatformTabId
|
||||
}
|
||||
|
||||
/** 序列化到 GET /api/admin/users 的查询参数(Java snake_case)。 */
|
||||
@@ -30,6 +33,7 @@ export interface UserListQuery {
|
||||
admin_id?: number
|
||||
role?: string
|
||||
company_id?: number
|
||||
platform?: string
|
||||
}
|
||||
|
||||
/** 用户列表项即 AdminUser(与 Java AdminUserItemVo 字段对齐)。 */
|
||||
|
||||
@@ -18,6 +18,10 @@ export function toAdminUserItem(raw: unknown): AdminUser | null {
|
||||
const id = numberOrNull(r.id)
|
||||
if (id === null) return null
|
||||
const item: AdminUser = { id, username: text(r.username), role: text(r.role) }
|
||||
const quota = numberOrNull(r.jd_publish_quota)
|
||||
if (quota !== null) item.jdPublishQuota = quota
|
||||
const platform = text(r.platform)
|
||||
if (platform) item.platform = platform
|
||||
if (typeof r.is_admin === 'boolean') item.isAdmin = r.is_admin
|
||||
const createdById = numberOrNull(r.created_by_id)
|
||||
if (createdById !== null) item.createdById = createdById
|
||||
|
||||
@@ -15,6 +15,8 @@ export async function fetchUserList(params: Partial<UserListParams> = {}): Promi
|
||||
// normalizeUserPageParams 是白名单构造(只点名 page/pageSize/keyword/createdById/adminId/role),
|
||||
// 公司值必须从原始 params 读:写成 normalized.companyId 会 TS 绿、运行时恒 undefined。
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
// 平台值(V206)同 companyId 形状:白名单构造不收,只认原始入参。
|
||||
if (params.platform) query.platform = params.platform
|
||||
const { data } = await http.get('/api/admin/users', { params: query })
|
||||
return parseUserPage(data)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
batch: {
|
||||
verb: string
|
||||
count: number
|
||||
disabled: boolean
|
||||
progress: string
|
||||
result: { failures: ReadonlyArray<{ id: number | string; label: string; reason: string }> } | null
|
||||
submit: () => Promise<void>
|
||||
clearSelection: () => void
|
||||
}
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="batch-delete-actions">
|
||||
<button class="btn btn-danger batch-delete-button" type="button" :disabled="batch.disabled || !batch.count" @click="batch.submit">
|
||||
{{ batch.progress ? `正在${batch.verb} ${batch.progress}` : `批量${batch.verb}(${batch.count})` }}
|
||||
</button>
|
||||
<button v-if="batch.count" class="btn btn-sm batch-clear-button" type="button" :disabled="batch.disabled" @click="batch.clearSelection">清除勾选</button>
|
||||
<details v-if="batch.result?.failures.length" class="batch-delete-failures">
|
||||
<summary>查看失败原因({{ batch.result.failures.length }} 条)</summary>
|
||||
<ul>
|
||||
<li v-for="failure in batch.result.failures" :key="failure.id">{{ failure.label }}:{{ failure.reason }}</li>
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.batch-delete-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
|
||||
.batch-delete-actions button {
|
||||
min-height: 34px;
|
||||
padding: 5px 12px;
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 9px;
|
||||
background: #fff;
|
||||
color: var(--admin-text);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.batch-delete-actions .batch-delete-button { color: #fff; background: #b35f6a; border-color: #b35f6a; }
|
||||
.batch-delete-button:hover:not(:disabled) { background: #a34f5b; }
|
||||
.batch-clear-button:hover:not(:disabled) { background: #edf5fb; }
|
||||
.batch-delete-actions button:focus-visible { outline: 2px solid var(--admin-primary); outline-offset: 2px; }
|
||||
.batch-delete-actions button:disabled { cursor: not-allowed; opacity: 0.55; }
|
||||
.batch-delete-failures { max-width: 520px; color: #9f3845; overflow-wrap: anywhere; }
|
||||
.batch-delete-failures ul { max-height: 180px; overflow: auto; margin: 4px 0; padding-left: 20px; }
|
||||
</style>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
label: string
|
||||
checked: boolean
|
||||
disabled: boolean
|
||||
partial?: boolean
|
||||
}>()
|
||||
|
||||
defineEmits<{ change: [] }>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<input class="batch-delete-checkbox" type="checkbox" :aria-label="label" :title="label"
|
||||
:checked="checked" :disabled="disabled" :indeterminate="partial ?? false" @change.stop="$emit('change')" @click.stop />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.batch-delete-checkbox { width: 15px; height: 15px; vertical-align: middle; cursor: pointer; accent-color: #b33a2e; }
|
||||
.batch-delete-checkbox:disabled { cursor: not-allowed; }
|
||||
</style>
|
||||
@@ -2,6 +2,11 @@
|
||||
/** 旧版风格分页(像素复刻 admin.html .pagination)+ 每页条数下拉(10/20/50/100)。
|
||||
* props: total / page / pageSize / sizes(默认 10/20/50/100) / showTotal(默认 true) / jump(默认 true)。 */
|
||||
import { computed, ref } from 'vue'
|
||||
// 每页条数下拉 2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的弹层是浏览器直角
|
||||
// 原生物,全站分页条都有这一处 ⇒ 换 el-select(EP 圆角面板)。组件内局部导入,不与全局
|
||||
// 注册表耦合:任何挂载测试单独 mount 本组件都能正确渲染(不依赖外部 app.use)。
|
||||
// 样式已在 plugins/element.ts 里按组件全局引过,这里不重复引。
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -34,8 +39,7 @@ function goJump() {
|
||||
go(Math.min(Math.max(n, 1), totalPages.value))
|
||||
}
|
||||
|
||||
function onSizeChange(event: Event) {
|
||||
const value = Number((event.target as HTMLSelectElement).value)
|
||||
function onSizeChange(value: number) {
|
||||
if (Number.isFinite(value) && value > 0) emit('size-change', value)
|
||||
}
|
||||
</script>
|
||||
@@ -43,9 +47,16 @@ function onSizeChange(event: Event) {
|
||||
<template>
|
||||
<div class="old-pagination">
|
||||
<span v-if="showTotal" class="page-total">共 {{ total }} 条</span>
|
||||
<select class="page-size-select" :value="pageSize" @change="onSizeChange">
|
||||
<option v-for="size in sizes" :key="size" :value="size">{{ size }}条/页</option>
|
||||
</select>
|
||||
<!-- el-select 出厂宽度 100%(--el-select-width),进 flex 行会横涨 ⇒ 类里钉位宽。 -->
|
||||
<el-select
|
||||
class="page-size-select"
|
||||
:model-value="pageSize"
|
||||
size="small"
|
||||
aria-label="每页条数"
|
||||
@change="onSizeChange"
|
||||
>
|
||||
<el-option v-for="size in sizes" :key="size" :value="size" :label="`${size}条/页`" />
|
||||
</el-select>
|
||||
<button type="button" :disabled="page <= 1" @click="go(page - 1)">上一页</button>
|
||||
<span class="page-cur">第 {{ page }} / {{ totalPages }} 页</span>
|
||||
<button type="button" :disabled="page >= totalPages" @click="go(page + 1)">下一页</button>
|
||||
@@ -92,15 +103,22 @@ function onSizeChange(event: Event) {
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
/* 每页条数下拉:与原分页条同尺寸(30px 高、8px 圆角、#cbd9e6 描边、#f8fbfd 浅底)。
|
||||
外形走 .el-select__wrapper(EP 的结构类,scoped 需 :deep 穿透)。 */
|
||||
.page-size-select {
|
||||
width: 104px;
|
||||
}
|
||||
.page-size-select :deep(.el-select__wrapper) {
|
||||
min-height: 30px;
|
||||
padding: 3px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
box-shadow: 0 0 0 1px #cbd9e6 inset;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
line-height: 22px;
|
||||
}
|
||||
.page-size-select :deep(.el-select__wrapper:hover) {
|
||||
box-shadow: 0 0 0 1px #9fb7cd inset;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
|
||||
@@ -10,7 +10,28 @@ import { userNotice } from '../api/user-notice.ts'
|
||||
/** 失败条上那个按钮的字样:必须是「重试」而不是一句「知道了」——撤入口同时得是出口。 */
|
||||
export const LOAD_FAILURE_RETRY_LABEL = '重试'
|
||||
|
||||
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。 */
|
||||
/** 网络层失败(请求没到服务器就断了)给用户的中文提示。2026-11-21 线上实录:用户代理
|
||||
* 链路抖动成批掐断 TLS 连接(当天全服 29 条「连接未完成即断」记录全部来自该用户的两个
|
||||
* 出口 IP),axios 拿到英文 "Network Error" 按 userNotice 口径被滤空 ⇒ 界面只剩页面
|
||||
* 兜底文案,用户看不出是网络问题、更不知道该重试还是该找人。这里显式补一句。 */
|
||||
export const NETWORK_FAILURE_DETAIL = '网络连接中断,请检查网络后重试'
|
||||
|
||||
/** axios 错误且没有 response = 网络层失败(连接被掐断/超时/DNS),服务端根本没回话。
|
||||
* 只认 axios 形状(code 为网络错误码,或带 config+isAxiosError 标记);普通 Error 没有
|
||||
* response 不算(走原有 message 解析)。 */
|
||||
function isNetworkLevelError(error: unknown): boolean {
|
||||
if (!error || typeof error !== 'object') return false
|
||||
const record = error as Record<string, unknown>
|
||||
if (record.response !== undefined) return false
|
||||
const code = typeof record.code === 'string' ? record.code : ''
|
||||
if (code === 'ECONNABORTED' || code === 'ERR_NETWORK' || code === 'ETIMEDOUT' || code === 'ECONNRESET') {
|
||||
return true
|
||||
}
|
||||
return record.isAxiosError === true && record.config !== undefined
|
||||
}
|
||||
|
||||
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。
|
||||
* 例外:axios 网络层失败(无 response)不算「取不到原因」,给中文网络提示。 */
|
||||
export function failureDetail(error: unknown): string {
|
||||
const data = (error as { response?: { data?: unknown } } | undefined)?.response?.data
|
||||
if (data && typeof data === 'object') {
|
||||
@@ -20,6 +41,7 @@ export function failureDetail(error: unknown): string {
|
||||
if (typeof value === 'string' && value.trim()) return userNotice(value, '')
|
||||
}
|
||||
}
|
||||
if (isNetworkLevelError(error)) return NETWORK_FAILURE_DETAIL
|
||||
if (error instanceof Error && error.message.trim()) return userNotice(error.message, '')
|
||||
if (typeof error === 'string' && error.trim()) return userNotice(error, '')
|
||||
return ''
|
||||
|
||||
@@ -60,4 +60,12 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
|
||||
// 「无效的菜单权限项」。写侧(编辑/删除/重排)不带参数——归属由那一行的 id 与操作者公司共同判定,
|
||||
// 跨公司写后端 403(见 docs/ops/menu-company-tree-design-2026-10-06.md §5)。
|
||||
{ menuKey: 'admin_columns', apiFiles: ['src/pages/account/menu-manage-api.ts'], pageFiles: ['src/pages/account/MenusPage.vue'] },
|
||||
// 外观专利无侵权数据(2026-11-10 v1.3):出表成功自动同步的只读明细,归属物化在行 company_id 列
|
||||
// (V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', apiFiles: ['src/pages/patent/appearance-patent-clean-api.ts'], pageFiles: ['src/pages/patent/AppearancePatentCleanItemsPage.vue'] },
|
||||
// 京东数据库(2026-11-14 v1.4)已于 2026-11-16 退出注册表(用户定案「删除掉公司 tab,参考品牌
|
||||
// 数据库」=品牌库 2026-10-06 先例同形):数据全平台公共(行 company_id 只剩"哪家公司客户端
|
||||
// 同步的"来源标记),摘的不只是 tab——页面/api 的 company_id 发送口与后端读侧 company_id 谓词
|
||||
// (superAdminScopedCompanyId)同窗一起摘。反向钉在 tests/company-tab-wiring.test.ts 的
|
||||
// 「公司维度不得回流」清单里,再加回来必须先推翻这条定案。
|
||||
]
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/** 平台 tab 口径的唯一清单(2026-11-16 用户定案「亚马逊/京东不混一起」)。
|
||||
* 仿 company-scope.ts 的形状:单独成文件而不是塞进 routes.ts——护栏用例要从这里
|
||||
* 反读清单与注册表对撞,放在一起会成环。 */
|
||||
|
||||
export type PlatformTabId = 'amazon' | 'jd'
|
||||
|
||||
export interface PlatformTabDef {
|
||||
id: PlatformTabId
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 侧边栏顶部平台 tab 的固定顺序:亚马逊在前(存量主体),京东在后。 */
|
||||
export const PLATFORM_TABS: readonly PlatformTabDef[] = [
|
||||
{ id: 'amazon', label: '亚马逊' },
|
||||
{ id: 'jd', label: '京东' },
|
||||
]
|
||||
|
||||
/** 京东侧独占菜单的 menuKey 唯一清单(与 routes.ts 的 menuKey 逐字一致,用例钉住)。
|
||||
* 2026-11-17 晚:分类管理子菜单(admin_jd_category_manage,V204)随「京东分类管理并到
|
||||
* 京东数据库分类编辑里」用户口径整体下线(页/路由/菜单行 V208 删),key 从清单摘除。
|
||||
* 后续京东新页面上线把 key 加进这里即可,清单外的 key(含店铺管理/生成记录等
|
||||
* 存量页)一律归亚马逊或双侧清单。
|
||||
* ⚠ 本清单只收后台(admin)侧 key——护栏用例要求每条都在 routes.ts 登记 menuKey;
|
||||
* 桌面端(app)京东菜单走 {@link JD_APP_MENU_KEYS}(无 admin 路由,不进侧边栏)。 */
|
||||
export const JD_MENU_KEYS: readonly string[] = [
|
||||
'admin_jd_database',
|
||||
]
|
||||
|
||||
/** 桌面端(app)京东菜单的 column_key 清单(V209,2026-11-17 用户口径「前台的京东少了」):
|
||||
* 组行 jd_tools(京东工具台)+两工具子行 jd-collect(京东店铺数据采集)/jd-publish(京东商品上架),
|
||||
* 与用户端 permissionKeys 逐字一致。app 菜单不进后管侧边栏与 routes.ts 路由表,故与
|
||||
* {@link JD_MENU_KEYS} 分列——判定出口 {@link platformsOfMenuKey} 两份同认。
|
||||
* 后续用户端京东新工具上线把 column_key 加进这里即可。 */
|
||||
export const JD_APP_MENU_KEYS: readonly string[] = [
|
||||
'jd_tools',
|
||||
'jd-collect',
|
||||
'jd-publish',
|
||||
]
|
||||
|
||||
/** 双侧共用账号管理页面:用户、分组、公司与菜单权限配置。
|
||||
* 密钥管理/密钥用量统计按 2026-11-18 截图口径收回亚马逊侧。 */
|
||||
export const BOTH_PLATFORM_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
'admin_columns',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属清单(唯一判定出口):京东独占(后台或桌面端清单)→ ['jd'];
|
||||
* 双侧清单 → ['amazon','jd'];其余(未知 key 在内)默认亚马逊。 */
|
||||
export function platformsOfMenuKey(key: string): PlatformTabId[] {
|
||||
if (JD_MENU_KEYS.includes(key) || JD_APP_MENU_KEYS.includes(key)) return ['jd']
|
||||
if (BOTH_PLATFORM_MENU_KEYS.includes(key)) return ['amazon', 'jd']
|
||||
return ['amazon']
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用「按平台过滤菜单树」(唯一算法出口,2026-11-17 用户口径「授权树也按平台收」):
|
||||
* 叶子按 {@link platformsOfMenuKey} 是否包含当前平台留下;分组节点自身的 key 不参与
|
||||
* 平台判定,按「有存活的子项」决定去留——否则京东侧「账号与权限」这类混合分组会被整组误剪。
|
||||
* 两个消费方必须同形:侧边栏(platform-menu-filter.ts)与账号弹窗的授权树
|
||||
* (UserMenuAuthTree.vue),改判定规则只改这一处。
|
||||
*/
|
||||
export function filterMenuTreeNodesByPlatform<T extends { key?: string; children?: T[] }>(
|
||||
nodes: readonly T[] | null | undefined,
|
||||
platform: PlatformTabId,
|
||||
): T[] {
|
||||
const filtered: T[] = []
|
||||
for (const node of nodes || []) {
|
||||
const children = filterMenuTreeNodesByPlatform(node.children, platform)
|
||||
if (children.length > 0) {
|
||||
filtered.push({ ...node, children })
|
||||
continue
|
||||
}
|
||||
if ((node.children || []).length > 0) continue
|
||||
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { joinAdminPath } from '@/config/app'
|
||||
import { pageTitleOf, topbarUserOf } from '@/layout/topbar-model'
|
||||
import { groupKeysForActive, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { allGroupKeys, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { filterMenuTreeByPlatform, allowedPlatformsForUser } from '@/layout/platform-menu-filter'
|
||||
import { PLATFORM_TABS, platformsOfMenuKey } from '@/config/platform-scope'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { firstVisiblePath } from '@/router/helpers'
|
||||
import {
|
||||
EMPTY_MENU_DESCRIPTION,
|
||||
EMPTY_MENU_TITLE,
|
||||
@@ -31,8 +35,33 @@ const router = useRouter()
|
||||
const session = useAdminSessionStore()
|
||||
|
||||
const activePath = computed(() => route.path)
|
||||
const menuEntries = computed(() => toSidebarEntries(session.menuTree))
|
||||
const openedKeys = computed(() => groupKeysForActive(menuEntries.value, route.path))
|
||||
const platformTab = usePlatformTabStore()
|
||||
// 平台 tab(亚马逊/京东,2026-11-16「不混」定案)只做显示分组:准入仍是 session.menuTree
|
||||
// (后端按权限裁剪)+路由守卫,这里只把当前用户已被授权的菜单按平台分侧展示。
|
||||
const menuEntries = computed(() =>
|
||||
toSidebarEntries(filterMenuTreeByPlatform(session.menuTree, platformTab.active)),
|
||||
)
|
||||
// 平台锁定(2026-11-18 用户口径「隔离下除站点超管外,京东用户只看京东菜单、亚马逊看不了」):
|
||||
// tab 可见性 = 站点超管随菜单树分布;其余用户锁 users.platform 那一侧(后端下发树已按平台
|
||||
// 裁剪,这里再把 tab 收敛到本人平台,单侧时 tab 条整个隐藏)。
|
||||
const allowedTabIds = computed(() => allowedPlatformsForUser(session.menuTree, session.user))
|
||||
const visibleTabDefs = computed(() => PLATFORM_TABS.filter((tab) => allowedTabIds.value.includes(tab.id)))
|
||||
const showPlatformTabs = computed(() => allowedTabIds.value.length > 1)
|
||||
// 父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。el-menu 的 default-openeds
|
||||
// 只在挂载时读一次,平台 tab 切换/菜单树刷新导致 entries 变化后新分组不会自动展开,
|
||||
// 这里在 entries 变更渲染完成后按当下值命令式补开;用户手动收起的组在 entries 不变期间
|
||||
// 保持收起(watch 不重触发)。读当下 computed 而非触发时快照:快速连切 tab 时不补开已
|
||||
// 离开渲染树的旧分组(el-menu 的 open 对未注册 index 会抛)。
|
||||
const menuRef = ref<{ open: (index: string) => void } | null>(null)
|
||||
const openedKeys = computed(() => allGroupKeys(menuEntries.value))
|
||||
watch(openedKeys, async () => {
|
||||
await nextTick()
|
||||
const menu = menuRef.value
|
||||
if (!menu) return
|
||||
for (const key of openedKeys.value) {
|
||||
menu.open(key)
|
||||
}
|
||||
}, { immediate: true })
|
||||
const emptyMenu = computed(() => shouldShowEmptyMenu(menuEntries.value.length > 0, session.loading, session.initialized))
|
||||
const pageTitle = computed(() => pageTitleOf(route.meta.title))
|
||||
const userVm = computed(() => topbarUserOf(session.user))
|
||||
@@ -45,6 +74,52 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 直达 URL/面包屑跳到另一平台的页面时,tab 指示自动跟过去(与侧边栏保持一致)。
|
||||
// 双侧清单里的页面(账号域三页)两个 tab 都算归属:当前 tab 已含它就不动。
|
||||
// 跟随目标只在允许集(allowedTabIds)里找:被平台锁定的侧不会成为落点。
|
||||
watch(
|
||||
() => route.meta.menuKey as string | undefined,
|
||||
(menuKey) => {
|
||||
if (!menuKey) return
|
||||
const owners = platformsOfMenuKey(menuKey)
|
||||
if (owners.includes(platformTab.active)) return
|
||||
const target = owners.find((platform) => allowedTabIds.value.includes(platform))
|
||||
if (target && target !== platformTab.active) {
|
||||
platformTab.setActive(target)
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 平台锁定的归位(2026-11-18):会话就位/菜单树刷新后允许集收敛时,把残留的另一侧 tab
|
||||
// (超管在同一浏览器切过,localStorage 落的值)归位本人平台;当前页若在被禁侧一并跳回
|
||||
// 该侧第一可见页。切 tab 的跳转复用下面 platformTab.active 的 watch(active 被 syncToAllowed
|
||||
// 改写后同链路生效)。
|
||||
watch(
|
||||
allowedTabIds,
|
||||
(allowed) => {
|
||||
if (!session.user) return
|
||||
platformTab.syncToAllowed(allowed)
|
||||
const menuKey = route.meta.menuKey as string | undefined
|
||||
if (!menuKey || platformsOfMenuKey(menuKey).includes(platformTab.active)) return
|
||||
const first = firstVisiblePath(filterMenuTreeByPlatform(session.menuTree, platformTab.active))
|
||||
if (first) void router.replace(first)
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 切到另一侧 tab 时当前页多半不在那边:跳到该侧第一个可见页;该侧为空(tab 不可见)则不动。
|
||||
// 双侧清单里的页面(账号域三页)切 tab 不跳转——页面自己按当前平台过滤数据。
|
||||
watch(
|
||||
() => platformTab.active,
|
||||
(tab) => {
|
||||
const menuKey = route.meta.menuKey as string | undefined
|
||||
if (!menuKey || platformsOfMenuKey(menuKey).includes(tab)) return
|
||||
const first = firstVisiblePath(filterMenuTreeByPlatform(session.menuTree, tab))
|
||||
if (first) void router.replace(first)
|
||||
},
|
||||
)
|
||||
|
||||
async function signOut() {
|
||||
try {
|
||||
await runLogout({
|
||||
@@ -77,8 +152,21 @@ async function signOut() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav v-if="showPlatformTabs" class="admin-platform-tabs" role="tablist" aria-label="按平台切换菜单">
|
||||
<button
|
||||
v-for="tab in visibleTabDefs"
|
||||
:key="tab.id"
|
||||
type="button"
|
||||
role="tab"
|
||||
class="admin-platform-tab"
|
||||
:class="{ 'is-active': tab.id === platformTab.active }"
|
||||
:aria-selected="tab.id === platformTab.active"
|
||||
@click="platformTab.setActive(tab.id)"
|
||||
>{{ tab.label }}</button>
|
||||
</nav>
|
||||
|
||||
<el-scrollbar class="admin-menu-scroll">
|
||||
<el-menu :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
|
||||
<el-menu ref="menuRef" :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
|
||||
<template v-for="entry in menuEntries" :key="entry.key">
|
||||
<el-sub-menu v-if="entry.kind === 'group'" :index="entry.key">
|
||||
<template #title>
|
||||
|
||||
@@ -7,17 +7,18 @@ import { useRoute } from 'vue-router'
|
||||
import { COMPANY_STATUS_ACTIVE } from '@/api/companies-dto'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { companyTabAppliesTo, companyTabInitFailureMessage } from '@/layout/company-tab-model'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
|
||||
const route = useRoute()
|
||||
const tab = useCompanyTabStore()
|
||||
const session = useAdminSessionStore()
|
||||
const platformTab = usePlatformTabStore()
|
||||
const tabs = computed(() => tab.companies.filter((c) => c.status === COMPANY_STATUS_ACTIVE))
|
||||
const show = computed(() => tab.visibleForOperator && companyTabAppliesTo(route.meta.menuKey))
|
||||
|
||||
watch(() => session.isSuperAdmin, (v) => {
|
||||
if (!v) return
|
||||
function ensureLoaded() {
|
||||
// 2026-10-05 修复轮 1:改前这里是 `void tab.initialize()`,store 里也只有 try/finally ⇒
|
||||
// GET /companies 抛错时异常变成 unhandled rejection(全仓 src 无 errorHandler/unhandledrejection 兜底),
|
||||
// 现场只剩"tab 条没画出来",Task 13 人工清单第一项无从判断是权限问题还是接口挂了。
|
||||
@@ -29,7 +30,20 @@ watch(() => session.isSuperAdmin, (v) => {
|
||||
console.warn('[company-tab] 公司目录没取到,tab 条不渲染', error)
|
||||
showAdminFeedback(companyTabInitFailureMessage(error), 'warning')
|
||||
})
|
||||
}
|
||||
|
||||
watch(() => session.isSuperAdmin, (v) => {
|
||||
if (!v) return
|
||||
ensureLoaded()
|
||||
}, { immediate: true })
|
||||
|
||||
// 平台 tab 切换=公司目录换一份(V206 平台分侧;2026-11-17 用户口径「亚马逊侧别再挂京东-团队,
|
||||
// 京东侧同理」):store 按 loadedPlatform 对撞早退,切了台必然重拉。非超管目录恒空不发请求,
|
||||
// 这里同样按超管闸早退。
|
||||
watch(() => platformTab.active, () => {
|
||||
if (!session.isSuperAdmin) return
|
||||
ensureLoaded()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -34,11 +34,11 @@ export function toSidebarEntries(nodes: AdminMenuNode[] | null | undefined): Sid
|
||||
return entries
|
||||
}
|
||||
|
||||
/** 计算需默认展开的分组 key:分组下含当前激活路由子项时返回该分组 key。 */
|
||||
export function groupKeysForActive(entries: SidebarEntry[], activeRoute: string): string[] {
|
||||
/** 计算需默认展开的分组 key:父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。 */
|
||||
export function allGroupKeys(entries: SidebarEntry[]): string[] {
|
||||
const keys: string[] = []
|
||||
for (const entry of entries) {
|
||||
if (entry.kind === 'group' && entry.children.some((child) => child.route === activeRoute)) {
|
||||
if (entry.kind === 'group') {
|
||||
keys.push(entry.key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
|
||||
steps: ['上传教程压缩包', '到工具台核对下载', '清理历史包'],
|
||||
},
|
||||
admin_workbench_client_package: {
|
||||
text: '上传新的工作台客户端 ZIP 包后即刻生效:客户端从 /api/workbench-client/version/latest 自动检测版本并升级;服务端会复算 sha256 供客户端校验。确认旧包不再需要后再删除。',
|
||||
text: '上传新的工作台客户端 ZIP 包后即刻生效;服务端会复算 sha256 供客户端校验。确认旧包不再需要后再删除。',
|
||||
steps: ['填写版本号并上传 ZIP', '核对版本与 sha256', '清理历史包'],
|
||||
},
|
||||
digital_human_version: {
|
||||
@@ -117,6 +117,16 @@ export const OPERATION_GUIDES: Record<string, OperationGuideData> = {
|
||||
text: '按账号、业务、状态、店铺和创建时间筛出客户端任务,点任务查看明细与分组结果;顶部汇总卡给当前在跑与疑似卡住的总量。',
|
||||
steps: ['按条件筛任务', '查看任务明细', '核对汇总卡'],
|
||||
},
|
||||
admin_appearance_patent_clean_items: {
|
||||
text: '本页只读:出表成功后「结论=无侵权」的明细自动同步到这里,按分公司隔离分页展示;支持任务号/ASIN/国家/同步日期筛选,下载原表请到任务中心取结果文件。',
|
||||
steps: ['筛选记录', '核对结论明细', '到任务中心下载原表'],
|
||||
},
|
||||
admin_jd_database: {
|
||||
// 2026-11-17 分类管理子菜单并入本页(用户口径「京东分类管理并到京东数据库分类编辑里」,
|
||||
// 原 admin_jd_category_manage 条目随之摘除):分类建/改名/删在工具栏「分类管理」。
|
||||
text: '本页只读:客户端采集的京东店铺商品自动同步到这里(同店铺同商品只保留最新一次),按分公司隔离分页展示;点行查看全部属性与图片;分类的新建/改名/删除在工具栏「分类管理」,给商品归类先勾选再「批量编辑分类」。',
|
||||
steps: ['筛选商品记录', '查看属性与图片明细', '用「分类管理」维护分类并批量归类'],
|
||||
},
|
||||
}
|
||||
|
||||
/** 全部有独立/兜底提示的后台业务菜单 key。 */
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { AdminMenuNode, AdminUser } from '../types/admin'
|
||||
import { isSuperAdminRole } from '../types/admin.ts'
|
||||
import { PLATFORM_TABS, filterMenuTreeNodesByPlatform } from '../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
import { firstVisiblePath } from '../router/helpers.ts'
|
||||
|
||||
/**
|
||||
* 按平台 tab 过滤后端菜单树(2026-11-16「亚马逊/京东不混」):**只做显示分组,不做鉴权**——
|
||||
* 准入仍由 session.menuTree(后端按权限裁剪)与路由守卫负责,这里只是把当前用户已被授权的
|
||||
* 菜单按平台分到两个 tab 下展示。
|
||||
* 规则与算法在 {@link filterMenuTreeNodesByPlatform}(2026-11-17 起唯一出口,账号弹窗授权树
|
||||
* 同用一份);本壳只钉侧边栏专属的两条:节点的 key/name/route/children 形状原样透传(浅拷贝
|
||||
* 不改写),toSidebarEntries、groupKeysForActive 与面包屑都不受影响。
|
||||
*/
|
||||
export function filterMenuTreeByPlatform(
|
||||
nodes: AdminMenuNode[] | null | undefined,
|
||||
platform: PlatformTabId,
|
||||
): AdminMenuNode[] {
|
||||
return filterMenuTreeNodesByPlatform(nodes, platform)
|
||||
}
|
||||
|
||||
/** 当前用户在哪些平台下至少有一个可点页面(tab 显示依据);顺序固定随 PLATFORM_TABS。
|
||||
* 「可点」沿用 firstVisiblePath 这一把尺子(有 route 即可点),不另写第二处判定。 */
|
||||
export function visiblePlatformsFor(nodes: AdminMenuNode[] | null | undefined): PlatformTabId[] {
|
||||
return PLATFORM_TABS
|
||||
.filter((tab) => firstVisiblePath(filterMenuTreeByPlatform(nodes, tab.id)) !== '')
|
||||
.map((tab) => tab.id)
|
||||
}
|
||||
|
||||
/** 登录用户可用的平台 tab(2026-11-18 用户口径「隔离下除站点超管外,京东用户只看京东菜单、
|
||||
* 亚马逊看不了」):站点超管不限侧、沿用菜单树分布;其余用户锁 users.platform 那一侧
|
||||
* (未知/缺省按亚马逊存量口径,与后端 AdminMenuPlatformScope.normalize 同形),与「菜单树
|
||||
* 该侧有可点页面」求交——交集空则仍回落单侧(管理角色必有双侧账号域页,交集实际非空;
|
||||
* 宁可锁死自己平台也不放开被禁侧)。会话未就位(user 为空)时按可见分布,锁定的收窄
|
||||
* 由 AdminLayout 的 watch 在 user 就位后再做。 */
|
||||
export function allowedPlatformsForUser(
|
||||
nodes: AdminMenuNode[] | null | undefined,
|
||||
user: Pick<AdminUser, 'role' | 'platform'> | null | undefined,
|
||||
): PlatformTabId[] {
|
||||
const visible = visiblePlatformsFor(nodes)
|
||||
if (!user || isSuperAdminRole(user.role)) return visible
|
||||
const own: PlatformTabId = user.platform === 'jd' ? 'jd' : 'amazon'
|
||||
const allowed = visible.filter((id) => id === own)
|
||||
return allowed.length > 0 ? allowed : [own]
|
||||
}
|
||||
@@ -1,14 +1,36 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import { installElement } from '@/plugins/element'
|
||||
import { reportClientError } from '@/shared/api/error-report'
|
||||
import '@/styles/main.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
|
||||
// 全局错误兜底(S1-F2/AC-16):渲染期异常、未捕获 Promise、脚本级崩溃三类都必须
|
||||
// 可见 + 上报,否则线上白屏只剩浏览器 console,运维永远没有现场。
|
||||
// 出口分两处,各按自己的时机生效:
|
||||
// - Vue 渲染/生命周期异常:挂在这里的 app.config.errorHandler(必须早于 mount,
|
||||
// 首屏就崩也不漏);
|
||||
// - window error 与 unhandledrejection:由 App.vue setup 调 useGlobalErrorReporting()
|
||||
// 接线,卸载出口在 onBeforeUnmount 里摘监听与提示定时器(只定义不接线等于没接)。
|
||||
// 上报本体(内存环 + 脱敏 + sendBeacon)在 @/shared/api/error-report。
|
||||
function installGlobalError(app: ReturnType<typeof createApp>): void {
|
||||
app.config.errorHandler = (error, _instance, info) => {
|
||||
reportClientError({
|
||||
kind: 'vue-render',
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack ?? '' : String(error),
|
||||
route: router.currentRoute.value.fullPath,
|
||||
ts: Date.now(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Element Plus 改为按需注册(见 src/plugins/element.ts);全局中文语言包改由
|
||||
// App.vue 的 <el-config-provider :locale="zhCn"> 提供,不要再在这里 use(ElementPlus)。
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
installElement(app)
|
||||
installGlobalError(app)
|
||||
app.mount('#app')
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
/** 公司管理(设计文档 §2.3):列表 + 新建 + 改名/启停。
|
||||
* 可见范围由后端收窄(超管全部、公司内 admin 只自己公司);写操作仅超管,这里隐藏入口只是配合,
|
||||
* 真正的把关在 CompanyController,页面不得当作权限边界。 */
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '@/api/companies-dto'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { refreshCompanyDirectory } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import CompanyEditorDialog from './CompanyEditorDialog.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
// 平台 tab(V206):公司列表按当前平台过滤,新建默认落当前平台。
|
||||
const platformTab = usePlatformTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<CompanyItem[]>([])
|
||||
@@ -38,7 +42,7 @@ async function loadCompanies() {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
rows.value = await fetchCompanies()
|
||||
rows.value = await fetchCompanies(platformTab.active)
|
||||
} catch (error) {
|
||||
loadFailure.value = error instanceof Error ? error.message : '公司列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
@@ -57,6 +61,24 @@ function openEdit(company: CompanyItem) {
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
// 保存成功后:本页列表照常重拉,共享公司目录(tab 条)强制重拉一份。
|
||||
// 本页不参与公司隔离(控制方 2026-10-06「公司管理不要有 tab」)⇒ 走 store 的具名出口
|
||||
// refreshCompanyDirectory,而不是自己持一份 company-tab store(后者形状与「给这页上了 tab」
|
||||
// 分不开,company-config-entry-super-only 的 pageFiles 分母会当场红)。
|
||||
// 重拉失败不弹新提示(§12 第 5 条未批的界面暴露):tab 条保留旧名单,下一次切平台 tab / 重进页面会再试。
|
||||
async function onCompaniesSaved() {
|
||||
await loadCompanies()
|
||||
refreshCompanyDirectory().catch((error: unknown) => {
|
||||
console.warn('[company-tab] 公司保存后目录重拉失败', error)
|
||||
})
|
||||
}
|
||||
|
||||
// 切平台 tab(V206)= 重新取数:公司归属按平台分列,两 tab 各看各的公司。
|
||||
watch(() => platformTab.active, () => {
|
||||
page.value = 1
|
||||
void loadCompanies()
|
||||
})
|
||||
|
||||
onMounted(loadCompanies)
|
||||
</script>
|
||||
|
||||
@@ -127,7 +149,7 @@ onMounted(loadCompanies)
|
||||
/>
|
||||
</section>
|
||||
|
||||
<CompanyEditorDialog v-model="editorVisible" :company="editingCompany" @saved="loadCompanies" />
|
||||
<CompanyEditorDialog v-model="editorVisible" :company="editingCompany" :platform="platformTab.active" @saved="onCompaniesSaved" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { createCompany, updateCompany } from '@/api/companies'
|
||||
import {
|
||||
COMPANY_NAME_MAX_LENGTH,
|
||||
@@ -12,11 +13,13 @@ import {
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { actionableErrorText } from '@/components/admin-feedback'
|
||||
|
||||
/** 新建/编辑公司(改名 + 启停 + 备注);写操作仅超管可用,权限由后端把关。 */
|
||||
const props = defineProps<{ modelValue: boolean; company: CompanyItem | null }>()
|
||||
/** 新建/编辑公司(改名 + 启停 + 备注);写操作仅超管可用,权限由后端把关。
|
||||
* 所属平台不设手选(2026-11-17 用户口径「有京东就不需要亚马逊了,亚马逊那边也是」):
|
||||
* 平台跟随当前平台 tab——新建取当前 tab(props.platform),编辑保持行值原样下发。 */
|
||||
const props = defineProps<{ modelValue: boolean; company: CompanyItem | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
|
||||
|
||||
const form = ref<CompanyDraft>({ companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '' })
|
||||
const form = ref<CompanyDraft>({ companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '', platform: 'amazon' })
|
||||
const errorText = ref('')
|
||||
const busy = ref(false)
|
||||
|
||||
@@ -25,8 +28,13 @@ watch(
|
||||
(open) => {
|
||||
if (!open) return
|
||||
form.value = props.company
|
||||
? { companyName: props.company.companyName, status: props.company.status, remark: props.company.remark || '' }
|
||||
: { companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '' }
|
||||
? {
|
||||
companyName: props.company.companyName,
|
||||
status: props.company.status,
|
||||
remark: props.company.remark || '',
|
||||
platform: props.company.platform === 'jd' ? 'jd' : 'amazon',
|
||||
}
|
||||
: { companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '', platform: props.platform ?? 'amazon' }
|
||||
errorText.value = ''
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { submitCreateUser } from './user-create-adapter'
|
||||
import {
|
||||
createEmptyCreateUserForm,
|
||||
@@ -28,6 +29,8 @@ const props = defineProps<{
|
||||
operatorCompanyId?: number | null
|
||||
/** 当前公司 tab:这次建号落在哪家,就决定能建哪些角色。 */
|
||||
activeCompanyId?: number | null
|
||||
/** 当前平台 tab(V206):新号落当前平台(跟随所在 tab,弹窗不再手选——2026-11-17 用户口径)。 */
|
||||
platform?: PlatformTabId
|
||||
}>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
|
||||
|
||||
@@ -71,6 +74,8 @@ watch(
|
||||
form.expiresAt = ''
|
||||
// 预填当前 tab:跨公司时角色本来就只剩公司超管,而那一例必须带公司
|
||||
form.companyId = props.activeCompanyId ?? null
|
||||
// 预填当前平台 tab(V206):京东侧建的号默认归京东,亚马逊侧默认亚马逊。
|
||||
form.platform = props.platform ?? 'amazon'
|
||||
errors.username = undefined
|
||||
errors.password = undefined
|
||||
errors.companyId = undefined
|
||||
@@ -173,7 +178,9 @@ async function create(): Promise<void> {
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
|
||||
<div class="auth-tree-box">
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" />
|
||||
<!-- 授权树按账号平台收(2026-11-17 用户口径):京东 tab 只给京东侧菜单。
|
||||
平台不再手选(跟随当前 tab),树收窄的判定出口不变。 -->
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" :platform="form.platform" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import type { AdminUser } from '@/types/admin'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { mayCarryOwnExpiry } from './user-create-model'
|
||||
import { fillEditUserForm, validateEditUserForm, type EditUserForm, type EditUserFormErrors } from './user-edit-model'
|
||||
import { submitEditUser } from './user-edit-adapter'
|
||||
@@ -10,11 +11,12 @@ import { actionableErrorText } from '@/components/admin-feedback'
|
||||
import UserMenuAuthTree from './UserMenuAuthTree.vue'
|
||||
|
||||
/** companyId 由 UsersPage 把 companyTab.requestCompanyId 透传进来(本页的用户列表本来就由它筛 ⇒ 目标账号的公司
|
||||
* 就是 tab 选中的那家);弹窗自己不读 store,公司 tab 的取值口只留在页面组件那一处。 */
|
||||
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean; companyId?: number | null }>()
|
||||
* 就是 tab 选中的那家);弹窗自己不读 store,公司 tab 的取值口只留在页面组件那一处。
|
||||
* platform(V206)同理由页面透传:决定上架上限是否参与校验/下发(仅京东侧)。 */
|
||||
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean; companyId?: number | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'updated'): void }>()
|
||||
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '' })
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '', jdPublishQuota: 5000, platform: 'amazon' })
|
||||
const errors = reactive<EditUserFormErrors>({})
|
||||
const busy = ref(false)
|
||||
const loadingAuth = ref(false)
|
||||
@@ -22,6 +24,9 @@ const loadingAuth = ref(false)
|
||||
const authReady = ref(false)
|
||||
/** 公司超管目标:角色单选隐藏(请求体也不带 role),只允许改密码/到期时间/菜单。 */
|
||||
const targetIsCompanySuperAdmin = computed(() => (props.user?.role || '').trim().toLowerCase() === 'company_super_admin')
|
||||
/** 上架上限只属京东口径(用户 2026-11-17:「只要在京东这边用户编辑里加就行,不需要在亚马逊那边」):
|
||||
* 亚马逊侧隐藏该项,且校验与下发都不带 quota——字段留后端不动。 */
|
||||
const includeQuota = computed(() => props.platform === 'jd')
|
||||
/** 公司超管目标的角色单选是隐藏的(改完仍是 company_super_admin),到期时间照旧可改;
|
||||
* 管理员改成普通账号时这一项消失,保存按「清空」下发(见 user-edit-model 的 roleAfter)。 */
|
||||
const expiryEditable = computed(() =>
|
||||
@@ -40,6 +45,9 @@ watch(
|
||||
form.columnIds = []
|
||||
form.originalRole = base.originalRole
|
||||
form.expiresAt = base.expiresAt
|
||||
form.jdPublishQuota = base.jdPublishQuota
|
||||
form.platform = base.platform
|
||||
errors.jdPublishQuota = undefined
|
||||
errors.password = undefined
|
||||
authReady.value = false
|
||||
void refreshAuth()
|
||||
@@ -71,12 +79,12 @@ async function save(): Promise<void> {
|
||||
showAdminFeedback('菜单权限尚未加载完成,请稍后重试', 'error')
|
||||
return
|
||||
}
|
||||
const { valid, errors: errs } = validateEditUserForm(form)
|
||||
const { valid, errors: errs } = validateEditUserForm(form, { includeQuota: includeQuota.value })
|
||||
Object.assign(errors, errs)
|
||||
if (!valid) return
|
||||
busy.value = true
|
||||
try {
|
||||
await submitEditUser(form)
|
||||
await submitEditUser(form, { includeQuota: includeQuota.value })
|
||||
showAdminFeedback('更新成功', 'success')
|
||||
emit('updated')
|
||||
close()
|
||||
@@ -130,12 +138,17 @@ async function save(): Promise<void> {
|
||||
style="width: 240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="includeQuota && (targetIsCompanySuperAdmin || form.role === 'admin')" label="京东上架额度(0 表示不限)" :error="errors.jdPublishQuota">
|
||||
<el-input-number v-model="form.jdPublishQuota" :min="0" :max="2147483647" :precision="0" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="props.user && props.user.creatorUsername" label="所属管理员">
|
||||
<el-input :model-value="props.user.creatorUsername" readonly />
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
|
||||
<div class="auth-tree-box">
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" />
|
||||
<!-- 授权树按账号平台收(2026-11-17 用户口径):京东档账号不再整树混发亚马逊菜单。
|
||||
平台不再手选(跟随当前平台 tab,编辑取行值),树收窄的判定出口不变。 -->
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" :platform="form.platform" />
|
||||
<div v-if="loadingAuth" class="auth-loading">菜单权限加载中…</div>
|
||||
<div v-else-if="!authReady" class="auth-loading auth-loading-error">
|
||||
菜单权限加载失败,保存已禁用;请关闭后重试
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import type { AdminUser } from '@/types/admin'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import {
|
||||
eligibleGroupLeaders,
|
||||
eligibleGroupMembers,
|
||||
groupMemberCandidateHint,
|
||||
validateShopGroupForm,
|
||||
@@ -13,25 +15,43 @@ import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { actionableErrorText } from '@/components/admin-feedback'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const props = defineProps<{ modelValue: boolean; group: ShopGroupItem | null; operatorSuper?: boolean }>()
|
||||
const props = defineProps<{ modelValue: boolean; group: ShopGroupItem | null; operatorSuper?: boolean; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const groupName = ref('')
|
||||
/** 所属平台(V206):不设手选(2026-11-17 用户口径「有京东就不需要亚马逊了,亚马逊那边也是」)——
|
||||
* 新建取当前平台 tab(props.platform),编辑保持分组原值,值仍随保存下发。 */
|
||||
const groupPlatform = ref<PlatformTabId>('amazon')
|
||||
const memberIds = ref<number[]>([])
|
||||
const errorText = ref('')
|
||||
const busy = ref(false)
|
||||
const users = ref<AdminUser[]>([])
|
||||
|
||||
/** 组长:新建=当前登录用户;编辑=分组原组长(不可改,只读展示)。 */
|
||||
const leaderUserId = computed<number | null>(() =>
|
||||
props.group ? (props.group.leaderUserId ?? null) : (session.user?.id ?? null),
|
||||
)
|
||||
const leaderUsername = computed<string>(() =>
|
||||
props.group ? (props.group.leaderUsername || '') : (session.user?.username || '当前登录用户'),
|
||||
)
|
||||
/**
|
||||
* 组长:新建默认当前登录用户,站点超管可下拉改选(2026-11-18 用户口径,后端 validateLeaderOperator
|
||||
* 对站点超管放行任意 createdById、只要求组长与操作者同公司);编辑=分组原组长(后端更新载荷不收
|
||||
* 组长,不可改);非站点超管新建时后端强制组长=操作者本人,同样只读展示。
|
||||
*/
|
||||
const leaderUserId = ref<number | null>(null)
|
||||
/** 只有「新建 + 站点超管」出组长下拉;其余场景只读回显。 */
|
||||
const canPickLeader = computed(() => !props.group && !!props.operatorSuper)
|
||||
const operatorRole = computed<string>(() => session.user?.role || '')
|
||||
|
||||
const leaderUsername = computed<string>(() => {
|
||||
const picked = leaderUserId.value != null
|
||||
? users.value.find((u) => u.id === leaderUserId.value)
|
||||
: null
|
||||
if (picked) return picked.username
|
||||
if (props.group) return props.group.leaderUsername || ''
|
||||
return session.user?.username || '当前登录用户'
|
||||
})
|
||||
|
||||
/** 组长候选:与组员同池(本公司账号),排除公司超管;站点超管仅保留操作者本人。 */
|
||||
const leaderCandidates = computed(() =>
|
||||
eligibleGroupLeaders(users.value, operatorRole.value, session.user?.id ?? null),
|
||||
)
|
||||
|
||||
/** 组员候选:按组长归属过滤(超管全量、非超管仅本组长创建的普通账号)。 */
|
||||
const memberCandidates = computed(() =>
|
||||
eligibleGroupMembers(users.value, leaderUserId.value, operatorRole.value),
|
||||
@@ -48,16 +68,30 @@ watch(
|
||||
if (props.group) {
|
||||
groupName.value = props.group.name
|
||||
memberIds.value = props.group.memberUserIds ?? []
|
||||
groupPlatform.value = props.group.platform === 'jd' ? 'jd' : 'amazon'
|
||||
// 编辑保持原值口径:历史行可能没有 leaderUserId(旧负载),回落 null 而不是当前登录人,
|
||||
// 否则组员候选过滤会跟着悄悄变。
|
||||
leaderUserId.value = props.group.leaderUserId ?? null
|
||||
} else {
|
||||
groupPlatform.value = props.platform ?? 'amazon'
|
||||
leaderUserId.value = session.user?.id ?? null
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// 组长改选后,若该人已被选为组员要立刻摘掉——后端「组长不能作为组员重复加入分组」会打回。
|
||||
watch(leaderUserId, (id) => {
|
||||
if (id == null) return
|
||||
memberIds.value = memberIds.value.filter((v) => v !== id)
|
||||
})
|
||||
|
||||
async function loadCandidates(): Promise<void> {
|
||||
try {
|
||||
// 对齐 admin.js loadUserOptions:page=1&page_size=999 全量拉取,避免归属过滤漏人。
|
||||
// company_id 必带:不带时后端对站点超管返回全平台账号,别家公司的人就会出现在本公司分组的候选里。
|
||||
// 取的是**组长自己那家**(当前登录用户),不是公司 tab——新建时组长就是操作者本人,
|
||||
// 按 tab 取人会在超管停在别家 tab 时列出那家的人,保存时被后端"只能添加组长本公司的账号"打回。
|
||||
// 取操作者自己那家,不是公司 tab——组长候选与组员候选同池,后端要求组长与操作者同公司
|
||||
// (ensureLeaderSharesOperatorCompany),按 tab 取人会在超管停在别家 tab 时列出保存必被
|
||||
// 打回的人("只能添加组长本公司的账号")。
|
||||
const page = await fetchUserList({ page: 1, pageSize: 999, companyId: session.user?.companyId ?? null })
|
||||
users.value = page.items
|
||||
} catch (error) {
|
||||
@@ -76,16 +110,16 @@ async function save(): Promise<void> {
|
||||
busy.value = true
|
||||
try {
|
||||
if (props.group) {
|
||||
await updateShopGroup(props.group.id, groupName.value, memberIds.value)
|
||||
await updateShopGroup(props.group.id, groupName.value, memberIds.value, groupPlatform.value)
|
||||
showAdminFeedback('更新成功', 'success')
|
||||
} else {
|
||||
// 对齐 admin:组长恒为当前登录用户,提交 createdBy=当前用户 id。
|
||||
const operatorId = session.user?.id ?? 0
|
||||
if (!operatorId) {
|
||||
showAdminFeedback('无法获取当前登录用户,请重新登录', 'error')
|
||||
// 组长默认当前登录用户;站点超管可改选本公司其他账号(createdById=所选组长)。
|
||||
const leaderId = leaderUserId.value ?? 0
|
||||
if (!leaderId) {
|
||||
showAdminFeedback('无法获取组长账号,请重新登录', 'error')
|
||||
return
|
||||
}
|
||||
await createShopGroup(groupName.value, memberIds.value, operatorId)
|
||||
await createShopGroup(groupName.value, memberIds.value, leaderId, groupPlatform.value)
|
||||
showAdminFeedback('创建成功', 'success')
|
||||
}
|
||||
emit('saved')
|
||||
@@ -114,7 +148,16 @@ onMounted(loadCandidates)
|
||||
<el-input v-model="groupName" placeholder="请输入分组名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="组长">
|
||||
<el-input :model-value="leaderUsername" readonly placeholder="当前登录用户" />
|
||||
<el-select
|
||||
v-if="canPickLeader"
|
||||
v-model="leaderUserId"
|
||||
filterable
|
||||
placeholder="选择组长(默认当前登录用户)"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="u in leaderCandidates" :key="u.id" :label="u.username" :value="u.id" />
|
||||
</el-select>
|
||||
<el-input v-else :model-value="leaderUsername" readonly placeholder="当前登录用户" />
|
||||
</el-form-item>
|
||||
<el-form-item label="组员">
|
||||
<el-select
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 分组管理页 · 像素复刻旧版 admin.html panel-group-manage(自绘:顶部数据权限分组摘要 chips + 分组列表表格 + 新建分组;全量无分页同旧版)。
|
||||
* script 逻辑沿用现有 Vue 实现;编辑器保留现有组件。 */
|
||||
@@ -6,6 +10,7 @@ import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { deleteShopGroup, fetchShopGroups } from './shop-group-api'
|
||||
import type { ShopGroupItem } from './shop-group-model'
|
||||
@@ -16,6 +21,8 @@ import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
// 平台 tab(V206):分组列表按当前平台过滤,新建默认落当前平台。
|
||||
const platformTab = usePlatformTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<ShopGroupItem[]>([])
|
||||
@@ -48,22 +55,34 @@ function canEditOf(group: ShopGroupItem): boolean {
|
||||
return currentUserId.value != null && group.leaderUserId != null && currentUserId.value === group.leaderUserId
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function loadGroups() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
rows.value = await fetchShopGroups(companyTab.requestCompanyId)
|
||||
const items = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = items
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '数据权限分组加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 切公司 = 重新取数(G1 的 pageFiles 断言盯着这一条)。
|
||||
watch(() => companyTab.activeId, () => void loadGroups())
|
||||
|
||||
// 切平台 tab(V206)= 重新取数:分组归属按平台分列,两 tab 各看各的分组。
|
||||
watch(() => platformTab.active, () => {
|
||||
page.value = 1
|
||||
void loadGroups()
|
||||
})
|
||||
|
||||
function openCreate() {
|
||||
editingGroup.value = null
|
||||
editorVisible.value = true
|
||||
@@ -75,11 +94,24 @@ function openEdit(group: ShopGroupItem) {
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => pagedGroups.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.name,
|
||||
deleteOne: (id) => deleteShopGroup(id),
|
||||
refresh: loadGroups,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => [companyTab.activeId, platformTab.active, currentUserId.value],
|
||||
precheck: (row) => canEditOf(row) ? undefined : '无权删除此分组',
|
||||
})
|
||||
|
||||
async function removeGroup(group: ShopGroupItem) {
|
||||
if (batch.busy) return
|
||||
const ok = await openAdminConfirm({ message: `确定删除分组“${group.name}”吗?`, danger: true })
|
||||
if (!ok) return
|
||||
try {
|
||||
await deleteShopGroup(group.id)
|
||||
batch.removeFromSelection(group.id)
|
||||
ElMessage.success('删除成功')
|
||||
await loadGroups()
|
||||
} catch (error) {
|
||||
@@ -110,10 +142,15 @@ onMounted(loadGroups)
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 58px">序号</th>
|
||||
<th style="width: 16%">分组名称</th>
|
||||
<th style="width: 12%">组长</th>
|
||||
@@ -126,7 +163,11 @@ onMounted(loadGroups)
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="filteredRows.length">
|
||||
<tr v-for="(group, index) in pagedGroups" :key="group.id">
|
||||
<tr v-for="(group, index) in pagedGroups" :key="group.id" :class="{ 'batch-selected': batch.isSelected(group) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(group) || `选择 ${batch.label(group)}`" :checked="batch.isSelected(group)"
|
||||
:disabled="batch.disabled || !!batch.reason(group)" @change="batch.toggle(group)" />
|
||||
</td>
|
||||
<td>{{ index + 1 }}</td>
|
||||
<td>{{ group.name }}</td>
|
||||
<td>{{ group.leaderUsername || '-' }}</td>
|
||||
@@ -142,17 +183,17 @@ onMounted(loadGroups)
|
||||
<td class="ops-cell">
|
||||
<template v-if="canEditOf(group)">
|
||||
<button class="btn btn-sm" type="button" @click="openEdit(group)">编辑</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="removeGroup(group)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeGroup(group)">删除</button>
|
||||
</template>
|
||||
<span v-else class="member-none">-</span>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
|
||||
<td colspan="9" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -164,6 +205,7 @@ onMounted(loadGroups)
|
||||
v-model="editorVisible"
|
||||
:group="editingGroup"
|
||||
:operator-super="isSuperAdmin"
|
||||
:platform="platformTab.active"
|
||||
@saved="loadGroups"
|
||||
/>
|
||||
</div>
|
||||
@@ -218,8 +260,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -233,12 +274,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 菜单权限配置页 · 像素复刻旧版 admin.html panel-columns(自绘:面板头+新增菜单、拖拽手柄 ⠿、树形缩进+└、旧式表格、全量无分页同旧版)。
|
||||
* script 逻辑沿用现有 Vue 实现(拖拽分组/落点/重排保存、弹窗表单)。 */
|
||||
@@ -6,6 +10,8 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { filterMenuTreeNodesByPlatform } from '@/config/platform-scope'
|
||||
import { createMenu, deleteMenu, loadMenuManageTree, reorderMenus, updateMenu } from './menu-manage-api'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
@@ -31,11 +37,22 @@ import {
|
||||
interface MenuRow extends MenuManageNode {
|
||||
depth: number
|
||||
}
|
||||
interface PlatformMenuNode extends MenuManageNode {
|
||||
key: string
|
||||
children?: PlatformMenuNode[]
|
||||
}
|
||||
|
||||
const companyTab = useCompanyTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<MenuManageNode[]>([])
|
||||
const platformTab = usePlatformTabStore()
|
||||
// 菜单字典保留全树;显示与父级候选先分平台,再展平分页,避免京东项被亚马逊菜单挤到后页。
|
||||
const visibleMenuTree = computed(() => {
|
||||
const withKeys = (nodes: MenuManageNode[]): PlatformMenuNode[] =>
|
||||
nodes.map((node) => ({ ...node, key: node.columnKey, children: withKeys(node.children || []) }))
|
||||
return filterMenuTreeNodesByPlatform(withKeys(rows.value), platformTab.active)
|
||||
})
|
||||
/** 筛选:菜单名称/类型(用户要求账户域子菜单补筛选条件)。 */
|
||||
const filterName = ref('')
|
||||
const filterType = ref('')
|
||||
@@ -63,14 +80,14 @@ const menuRows = computed<MenuRow[]>(() => {
|
||||
if (node.children?.length) walk(node.children, depth + 1)
|
||||
}
|
||||
}
|
||||
walk(rows.value, 0)
|
||||
walk(visibleMenuTree.value, 0)
|
||||
return out
|
||||
})
|
||||
const createVisible = ref(false)
|
||||
const saving = ref(false)
|
||||
const editingNode = ref<MenuManageNode | null>(null)
|
||||
const menuForm = reactive<MenuManageForm>(createMenuForm(null, 0))
|
||||
const parentOptions = computed(() => menuParentCandidates(rows.value, menuForm.menuType))
|
||||
const parentOptions = computed(() => menuParentCandidates(visibleMenuTree.value, menuForm.menuType))
|
||||
const dialogTitle = computed(() => (editingNode.value ? '编辑菜单' : '新增菜单'))
|
||||
/** 节点 id -> 名称,供「上级菜单」列展示。 */
|
||||
const nameById = computed(() => {
|
||||
@@ -87,16 +104,22 @@ function parentNameOf(node: MenuManageNode): string {
|
||||
return nameById.value.get(node.parentId) ?? `#${node.parentId}`
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function loadMenus() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
rows.value = await loadMenuManageTree(companyTab.requestCompanyId)
|
||||
const items = await loadMenuManageTree(companyTab.requestCompanyId)
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = items
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '菜单列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +137,7 @@ function openEdit(node: MenuManageNode) {
|
||||
|
||||
/** 菜单类型切换时:当前父菜单不属于新类型则重置为根。 */
|
||||
function onMenuTypeChange(): void {
|
||||
const candidates = menuParentCandidates(rows.value, menuForm.menuType)
|
||||
const candidates = menuParentCandidates(visibleMenuTree.value, menuForm.menuType)
|
||||
if (menuForm.parentId != null && !candidates.some((node) => node.id === menuForm.parentId)) {
|
||||
menuForm.parentId = null
|
||||
}
|
||||
@@ -195,7 +218,19 @@ async function saveMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => pagedMenuRows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.name,
|
||||
deleteOne: (id) => deleteMenu(id),
|
||||
refresh: loadMenus,
|
||||
blocked: () => loading.value || !!loadFailure.value || saving.value,
|
||||
scope: () => [companyTab.activeId, platformTab.active],
|
||||
precheck: (row) => menuDeleteReason(row),
|
||||
})
|
||||
|
||||
async function removeMenu(node: MenuManageNode) {
|
||||
if (batch.busy) return
|
||||
const reason = menuDeleteReason(node)
|
||||
if (reason) {
|
||||
ElMessage.warning(reason)
|
||||
@@ -205,6 +240,7 @@ async function removeMenu(node: MenuManageNode) {
|
||||
if (!(await openAdminConfirm({ message: `确定删除菜单“${node.name}”吗?`, danger: true }))) return
|
||||
try {
|
||||
await deleteMenu(node.id)
|
||||
batch.removeFromSelection(node.id)
|
||||
ElMessage.success('删除成功')
|
||||
await loadMenus()
|
||||
} catch (error) {
|
||||
@@ -215,6 +251,7 @@ async function removeMenu(node: MenuManageNode) {
|
||||
/** 切公司:菜单名称/类型是客户端筛选(在 filteredMenuRows 上筛,不进请求),留着上一家填的值
|
||||
* 就是拿别家的字符串去筛新一家那一套树 ⇒ 首屏「暂无匹配菜单」而输入框里还显示着它;页码回 1
|
||||
* 是因为新一家的行数不同。末尾的 void loadMenus() 才是本页唯一的数据出口。 */
|
||||
watch(() => platformTab.active, () => { filterName.value = ''; filterType.value = ''; page.value = 1; createVisible.value = false })
|
||||
watch(() => companyTab.activeId, () => { filterName.value = ''; filterType.value = ''; page.value = 1; void loadMenus() })
|
||||
|
||||
onMounted(loadMenus)
|
||||
@@ -236,19 +273,28 @@ onMounted(loadMenus)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 160px">
|
||||
<label>菜单类型</label>
|
||||
<select v-model="filterType">
|
||||
<option value="">全部</option>
|
||||
<option value="admin">后台</option>
|
||||
<option value="app">软件</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板)。
|
||||
「全部」保留为空值首行=空串不按类型筛(与旧原生下拉同语义);model 是空串时
|
||||
EP 不显示 label 而走 placeholder,所以 placeholder 同文案,观感与改前一致。 -->
|
||||
<el-select v-model="filterType" class="admin-filter" placeholder="全部" aria-label="筛选菜单类型">
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="后台" value="admin" />
|
||||
<el-option label="软件" value="app" />
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadMenus" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll columns-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th class="column-drag-cell"><span class="visually-hidden">排序</span></th>
|
||||
<th style="width: 60px">ID</th>
|
||||
<th style="width: 200px">菜单名称</th>
|
||||
@@ -264,10 +310,14 @@ onMounted(loadMenus)
|
||||
<tr
|
||||
v-for="row in pagedMenuRows"
|
||||
:key="row.id"
|
||||
:class="{ 'is-column-dragging': dragState?.id === row.id }"
|
||||
:class="{ 'batch-selected': batch.isSelected(row), 'is-column-dragging': dragState?.id === row.id }"
|
||||
@dragover="onDragOver($event, row)"
|
||||
@drop="onDrop($event, row)"
|
||||
>
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td class="column-drag-cell">
|
||||
<span
|
||||
class="column-drag-handle"
|
||||
@@ -292,7 +342,7 @@ onMounted(loadMenus)
|
||||
<button
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="menuDeleteReason(row) !== undefined"
|
||||
:disabled="batch.busy || menuDeleteReason(row) !== undefined"
|
||||
:title="menuDeleteReason(row) || undefined"
|
||||
@click="removeMenu(row)"
|
||||
>
|
||||
@@ -302,10 +352,10 @@ onMounted(loadMenus)
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">{{ filterName || filterType ? '暂无匹配菜单' : '暂无菜单,请先在上方新增' }}</td>
|
||||
<td colspan="9" class="empty-tip">{{ filterName || filterType ? '暂无匹配菜单' : '暂无菜单,请先在上方新增' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -398,8 +448,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -413,12 +462,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { saveUserSecretModule } from '@/api/user-secrets'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { actionableErrorText } from '@/components/admin-feedback'
|
||||
import {
|
||||
PROXY_MODULE_KEY,
|
||||
buildProxyEntryPayload,
|
||||
emptyProxyEntryDraft,
|
||||
validateProxyEntry,
|
||||
type ProxyEntryDraft,
|
||||
} from './user-secret-model.ts'
|
||||
|
||||
/**
|
||||
* 后台代填/改代理(2026-11-02 脱敏后重做的交互)。
|
||||
*
|
||||
* 旧交互是 `window.prompt` 预填 `row.proxy.full` 整条提取链接——后端把这条读路套上
|
||||
* `SecretMasking.maskProxy` 之后 `full` 恒空,预填必然是空的,照旧保存等于把空串顶上去、
|
||||
* 或让管理员去别处翻原文。现在收**账密**、链接在本机现拼现发:
|
||||
* - 青果:填 Authkey + Authpwd,`composeQingguoLink` 拼(青果产品页没有可复制的链接);
|
||||
* - 极客:填极客自己的提取链接(它有可复制的链接)。
|
||||
* 拼好的链接是一次性写载荷,只进 PUT 请求体:不回显、不回填、不进 tooltip、不给复制/导出旁路;
|
||||
* 保存成功即清空输入位,重开必然要从头再填(这是脱敏的应然后果,界面直接把它说出来)。
|
||||
*/
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
userId: number | null
|
||||
username: string
|
||||
/** 后端已登记的供应商(只是预选中的单选框,不是凭据)。 */
|
||||
provider?: string | null
|
||||
locked?: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
|
||||
|
||||
const draft = reactive<ProxyEntryDraft>(emptyProxyEntryDraft())
|
||||
const errorText = ref('')
|
||||
const busy = ref(false)
|
||||
|
||||
function resetDraft() {
|
||||
Object.assign(draft, emptyProxyEntryDraft(props.provider))
|
||||
errorText.value = ''
|
||||
}
|
||||
|
||||
// 开与关都重刷:关的时候把已经打进内存的账密/链接抹掉,不留到下一次。
|
||||
watch(() => props.modelValue, resetDraft)
|
||||
|
||||
function close() {
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (props.userId == null) return
|
||||
errorText.value = validateProxyEntry(draft)
|
||||
if (errorText.value) return
|
||||
const payload = buildProxyEntryPayload(draft)
|
||||
if (!payload) {
|
||||
errorText.value = '代理配置不完整,请重新填写'
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
try {
|
||||
await saveUserSecretModule(props.userId, PROXY_MODULE_KEY, payload.value, payload.channel)
|
||||
showAdminFeedback(props.locked ? '已更新锁定代理' : '已代填并锁定代理', 'success')
|
||||
emit('saved')
|
||||
close()
|
||||
} catch (error) {
|
||||
// 文案以接口返回的 message 为准,前端不解释后端状态码
|
||||
errorText.value = actionableErrorText(error)
|
||||
showAdminFeedback(errorText.value, 'error')
|
||||
} finally {
|
||||
busy.value = false
|
||||
Object.assign(draft, { authkey: '', authpwd: '', link: '' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="modelValue" class="modal-mask" @click.self="close">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="proxy-entry-title">
|
||||
<h3 id="proxy-entry-title">{{ locked ? '改代理' : '代填代理' }}</h3>
|
||||
<p class="modal-note">
|
||||
为「{{ username || '该用户' }}」写入代理。出于凭据保护,后台不再下发已存的提取链接原文,
|
||||
这里每次都重新填写;保存后界面只显示脱敏后的地址(不含 key/pwd)。
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label>代理供应商</label>
|
||||
<div class="radio-row">
|
||||
<label class="radio-item">
|
||||
<input v-model="draft.provider" type="radio" value="qingguo" />
|
||||
<span>青果</span>
|
||||
</label>
|
||||
<label class="radio-item">
|
||||
<input v-model="draft.provider" type="radio" value="jikip" />
|
||||
<span>极客</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="draft.provider === 'qingguo'">
|
||||
<div class="form-group">
|
||||
<label>Authkey</label>
|
||||
<input v-model="draft.authkey" type="text" autocomplete="off" placeholder="青果产品页的 Authkey" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Authpwd</label>
|
||||
<input v-model="draft.authpwd" type="password" autocomplete="new-password" placeholder="青果产品页的 Authpwd" />
|
||||
<span class="field-hint">青果只填 Authkey 会被判鉴权拒绝,两把都要填。</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="form-group">
|
||||
<label>极客提取链接</label>
|
||||
<input
|
||||
v-model="draft.link"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
placeholder="https://api.jikip.com/ip-get?..."
|
||||
/>
|
||||
<span class="field-hint">极客有可复制的提取链接,整条粘贴进来即可。</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<p v-if="errorText" class="modal-error">{{ errorText }}</p>
|
||||
<div class="modal-actions">
|
||||
<button class="btn" type="button" :disabled="busy" @click="save">
|
||||
{{ busy ? '保存中…' : '保存' }}
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" :disabled="busy" @click="close">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 与密钥列表页同一视觉语言(本页不用 el-* 标签:新增 el-* 要同步改按需注册表)。 */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(520px, 100%);
|
||||
max-height: 84vh;
|
||||
padding: 22px 24px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
overflow-y: auto;
|
||||
color: #24384d;
|
||||
font-family: inherit;
|
||||
}
|
||||
.modal h3 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
}
|
||||
.modal-note {
|
||||
margin: 0 0 14px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.65;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input[type='text'],
|
||||
.form-group input[type='password'] {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.radio-row {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
}
|
||||
.radio-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 500;
|
||||
color: #24384d;
|
||||
}
|
||||
.field-hint {
|
||||
color: #7d8fa1;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.modal-error {
|
||||
margin: 0 0 10px;
|
||||
color: #b04a5a;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-ghost {
|
||||
background: #ffffff;
|
||||
border-color: #c7d7e5;
|
||||
color: #4f78a5;
|
||||
}
|
||||
</style>
|
||||
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||
import { filterMenuTreeNodesByPlatform } from '../../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
import type { MenuOptionNode } from './user-menu-auth'
|
||||
import { compactDirectGrantIds } from './user-menu-auth'
|
||||
import { compactDirectGrantIds, pruneCheckedIdsToTree } from './user-menu-auth'
|
||||
import { fetchGrantableMenus } from './user-menu-auth-api'
|
||||
|
||||
const props = defineProps<{ checked?: number[]; companyId?: number | null }>()
|
||||
const props = defineProps<{ checked?: number[]; companyId?: number | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:checked', ids: number[]): void
|
||||
(e: 'load', ok: boolean): void
|
||||
@@ -17,9 +19,16 @@ const appTree = ref<{ setCheckedKeys(keys: unknown[]): void; getCheckedKeys(): u
|
||||
const data = ref<MenuOptionNode[]>([])
|
||||
const loaded = ref(false)
|
||||
|
||||
/**
|
||||
* 按平台过滤后的可见树(2026-11-17 用户口径「授权树也按平台收,选京东就去掉亚马逊的」):
|
||||
* 平台缺省按亚马逊(历史调用形状)。过滤算法与侧边栏同源(platform-scope 唯一出口),
|
||||
* 叶子按 menuKey 判定——京东侧=「京东数据库+双侧账号域三件+桌面端京东工具台三件」。
|
||||
*/
|
||||
const visibleData = computed(() => filterMenuTreeNodesByPlatform(data.value, props.platform ?? 'amazon'))
|
||||
|
||||
/** 两种一级分类…(与 API menuType 分区一致):后台(admin) / 桌面端(app)。 */
|
||||
const adminNodes = computed(() => data.value.filter((node) => node.type === 'admin'))
|
||||
const appNodes = computed(() => data.value.filter((node) => node.type === 'app'))
|
||||
const adminNodes = computed(() => visibleData.value.filter((node) => node.type === 'admin'))
|
||||
const appNodes = computed(() => visibleData.value.filter((node) => node.type === 'app'))
|
||||
|
||||
function applyChecked(): void {
|
||||
const ids = Array.isArray(props.checked) ? props.checked.filter((id) => typeof id === 'number' && id > 0) : []
|
||||
@@ -37,7 +46,8 @@ function onCheck(): void {
|
||||
// 提交前压缩为最小直接授权集:父级已勾选时后代不再重复提交(后端按“父级授权
|
||||
// 展开全部后代”判断权限,与旧 admin.html 勾父清后代语义一致),
|
||||
// 并剔除置灰的祖先分组(派生勾选,操作者无权授予)。
|
||||
emit('update:checked', compactDirectGrantIds(ids, data.value))
|
||||
// 压缩按「可见树」算:另一侧菜单不在树上,其历史勾选天然进不来。
|
||||
emit('update:checked', compactDirectGrantIds(ids, visibleData.value))
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
@@ -49,12 +59,26 @@ async function load(): Promise<void> {
|
||||
// 渲染完成后再应用已勾选 id,否则作用在空 store 上导致已授权不回显。
|
||||
await nextTick()
|
||||
applyChecked()
|
||||
// 首屏就把勾选集收敛进可见树:编辑一个混档账号(既有亚马逊又有京东授权)时,
|
||||
// 打开弹窗那一刻就该按当前平台剪掉另一侧,而不是等用户点一下树才剪。
|
||||
pruneChecked()
|
||||
} catch {
|
||||
loaded.value = false
|
||||
emit('load', false)
|
||||
}
|
||||
}
|
||||
|
||||
/** 平台切换/首屏后把勾选集收敛进可见树:被过滤掉的另一侧勾选不再随表单提交,
|
||||
* 否则「京东档账号保存后仍带亚马逊授权」会把平台分侧静默架空。集合没变就不发
|
||||
* update 事件(避免与父级 v-model 循环互刷)。 */
|
||||
function pruneChecked(): void {
|
||||
const pruned = pruneCheckedIdsToTree(props.checked, visibleData.value)
|
||||
const current = Array.isArray(props.checked) ? props.checked : []
|
||||
if (pruned.length !== current.length || pruned.some((id, index) => id !== current[index])) {
|
||||
emit('update:checked', pruned)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
watch(
|
||||
() => props.checked,
|
||||
@@ -62,6 +86,16 @@ watch(
|
||||
if (loaded.value) applyChecked()
|
||||
},
|
||||
)
|
||||
/** 平台翻档:可见树整棵换,勾选集同步收敛到新树并回显(被剪掉的勾选以 emit 形式
|
||||
* 落回表单,父级拿到的是纯当前平台的授权集)。 */
|
||||
watch(
|
||||
() => props.platform,
|
||||
() => {
|
||||
if (!loaded.value) return
|
||||
pruneChecked()
|
||||
void nextTick().then(applyChecked)
|
||||
},
|
||||
)
|
||||
/** 公司换了要整棵重取:勾选集里存的是 column id,别家同名菜单是另一份 id(V149 每公司一套树),
|
||||
* 拿别家的树勾出来的 id 提交会被后端判「无效的菜单权限项」,而已授权项也因为 id 不在这棵树上勾不上。 */
|
||||
watch(
|
||||
|
||||
@@ -151,10 +151,14 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" v-if="isSuperAdmin && groupOptions.length" style="min-width: 170px">
|
||||
<label>分组</label>
|
||||
<select v-model="groupFilter">
|
||||
<option :value="null">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="group.id">{{ group.groupName }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板),组多时可搜。
|
||||
「全部分组」的值仍是 null(下游 groupId 照旧 `|| undefined`),空档时由
|
||||
placeholder 显示同一句文案。 -->
|
||||
<el-select v-model="groupFilter" class="admin-filter" filterable placeholder="全部分组" aria-label="筛选分组">
|
||||
<el-option label="全部分组" :value="null" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
@@ -290,8 +294,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -305,12 +308,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
/* 像素复刻旧版 admin.html 面板风格(与店铺密钥页同一视觉语言)。 */
|
||||
.user-secrets-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.secrets-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.secrets-filter-row {
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 18px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-ghost {
|
||||
background: #ffffff;
|
||||
border-color: #c7d7e5;
|
||||
color: #4f78a5;
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn-ghost:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.secrets-table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.secrets-table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
min-width: 1440px;
|
||||
}
|
||||
.secrets-table-scroll th,
|
||||
.secrets-table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.secrets-table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.secrets-table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.secrets-table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.user-name {
|
||||
color: #24384d;
|
||||
font-weight: 600;
|
||||
/* 用户名(含中文)可完整换行展示,不截断 */
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.creator-name {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.module-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
/* 代理列:脱敏地址独占一行,状态药丸另起一行(列宽按最长药丸文案留的,不按整条链接) */
|
||||
.module-cell--stack {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
.module-cell .mono-mask {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
/* 代理列只显示后端脱敏后的 scheme://host(短串,单行足够)。
|
||||
这里**不许**再出现"允许折行展示完整明文 + user-select:all"那套样式:
|
||||
它等于给整条带 key/pwd 的链接做了一键全选复制的旁路(2026-11-02 脱敏收口时一并拆掉)。 */
|
||||
.mono-mask {
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 12.5px;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.empty-value {
|
||||
color: #a7b4c1;
|
||||
}
|
||||
/* 余额列:数字按等宽数位对齐(两行叠着看差值才不用竖着对),超长进 title。 */
|
||||
.balance-line {
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 12.5px;
|
||||
color: #2f4256;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.empty-tip {
|
||||
color: #8293a5;
|
||||
text-align: center;
|
||||
}
|
||||
.wh-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
cursor: help;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.wh-pill.is-source {
|
||||
background: #eef2fb;
|
||||
border-color: #ccd8f2;
|
||||
color: #3d5a99;
|
||||
font-weight: 600;
|
||||
}
|
||||
.wh-pill.is-allowed {
|
||||
background: #e8f6ee;
|
||||
border-color: #b9e0c9;
|
||||
color: #2f7d52;
|
||||
}
|
||||
.wh-pill.is-blocked {
|
||||
background: #fdecef;
|
||||
border-color: #f2c4cd;
|
||||
color: #b04a5a;
|
||||
}
|
||||
.wh-pill.is-warn {
|
||||
background: #fdf6e3;
|
||||
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;
|
||||
color: #6b7d8f;
|
||||
}
|
||||
.wh-pill.is-locked {
|
||||
background: #f0ecfb;
|
||||
border-color: #d5caf0;
|
||||
color: #5b4a96;
|
||||
}
|
||||
.module-cell-pills {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
@@ -1,18 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import ProxyEntryDialog from './ProxyEntryDialog.vue'
|
||||
import {
|
||||
checkUserSecret,
|
||||
clearUserSecretModule,
|
||||
deleteUserSecret,
|
||||
fetchAdminSecretBalances,
|
||||
fetchUserSecretList,
|
||||
saveUserSecretModule,
|
||||
type AdminUserSecretBalanceItem,
|
||||
type AdminUserSecretModule,
|
||||
type AdminUserSecretRow,
|
||||
type GroupOption,
|
||||
} from '@/api/user-secrets'
|
||||
import {
|
||||
PROXY_MODULE_KEY,
|
||||
llmBalanceLines,
|
||||
llmSourceLabel,
|
||||
moduleStatusBand,
|
||||
proxyBalanceLine,
|
||||
proxyDisplayText,
|
||||
proxySourceLabel,
|
||||
rowDetailLines,
|
||||
rowStatusBand,
|
||||
} from './user-secret-model.ts'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
@@ -37,8 +54,18 @@ const groupFilter = ref<number | null>(null)
|
||||
const groupOptions = ref<GroupOption[]>([])
|
||||
/** 正在检测的行 userId,用于按钮 loading 态。 */
|
||||
const checkingId = ref<number | null>(null)
|
||||
/** 正在代填/解锁代理的行 userId,避免重复点击。 */
|
||||
/** 正在解锁代理的行 userId,避免重复点击(代填在弹窗里自己管 busy)。 */
|
||||
const proxyBusyId = ref<number | null>(null)
|
||||
/** 代填/改代理弹窗的目标行(脱敏后没有原文可预填,只能重填账密)。 */
|
||||
const proxyDialog = ref<{ userId: number; username: string; provider: string | null; locked: boolean } | null>(null)
|
||||
|
||||
/** 余额侧写(实时查上游、不落库):按 userId 存,列表接口本身不带这些数。 */
|
||||
const balances = ref<Record<number, AdminUserSecretBalanceItem>>({})
|
||||
const balanceLoading = ref(false)
|
||||
/** 本轮「没取到」的原因(越权剔除/上游未应答/请求失败):进工具行悬停,不弹全局打扰。 */
|
||||
const balanceNotice = ref('')
|
||||
/** 服务端单次上限 20 个用户;超出会被当场拒,所以这里按批顺取(并发留给服务端那个线程池)。 */
|
||||
const BALANCE_BATCH = 20
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
@@ -47,58 +74,44 @@ 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' }
|
||||
}
|
||||
}
|
||||
/* 状态药丸的档位表在 `user-secret-model.ts`(唯一出处,页面不带第二张表):
|
||||
行级传整行而不是 `row.status`——后端把 failed/incomplete 都判掉之后就只剩一个「error」,
|
||||
这一行到底是「查不出」还是「等青果释放」只有逐格的 `check_code` 说得清。 */
|
||||
|
||||
/** 单格状态药丸:未配置时统一灰色;欠费单独标识。 */
|
||||
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' }
|
||||
}
|
||||
}
|
||||
|
||||
/** 单格悬停详情:完整值(代理为全量地址)+ 锁定说明 + 检测消息 + 检测时间 + 耗时。 */
|
||||
/**
|
||||
* 单格悬停详情:后端下发的**脱敏值** + 锁定说明 + **检测结果原文 `check_message`** + 检测时间 + 耗时。
|
||||
* 运维要判「是欠费还是被自己的采集占着」,靠的就是这句后端原文——档名只是扫一眼用的短词,
|
||||
* 前端一律不按码自己拼句子。
|
||||
* ⚠ 只读 `masked`:`full` 在后台侧恒空(2026-11-02 `SecretMasking.maskProxy` 收口),
|
||||
* 这里不做任何「masked 空就回落原文」的兜底,也不给复制整条链接的旁路。
|
||||
*/
|
||||
function moduleTooltip(module: AdminUserSecretModule | undefined) {
|
||||
if (!module || !module.exists) return '未配置'
|
||||
const parts: string[] = []
|
||||
if (module.full) parts.push(module.full)
|
||||
if (module.locked) parts.push('已由后台代填并锁定:客户端不可修改或清空')
|
||||
if (module.checkMessage) parts.push(module.checkMessage)
|
||||
const display = String(module.masked || '').trim()
|
||||
if (display) {
|
||||
parts.push(isProxyModule(module) ? `代理地址(已脱敏,不含 key/pwd):${display}` : `密钥:${display}`)
|
||||
}
|
||||
if (module.locked) parts.push('已由后台代填并锁定:客户端不可修改或清空,改代理需重新填写账密')
|
||||
// 后端的这句话就是给人看的结论,原样透出(不动一个字、不按码另拼一句)
|
||||
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(';') || '暂无检测记录'
|
||||
}
|
||||
|
||||
/** 该格是不是代理模块:按后端下发的 moduleKey 判,货源标签与文案都走这一条口径。 */
|
||||
function isProxyModule(module: AdminUserSecretModule) {
|
||||
return String(module.moduleKey || '').trim().toLowerCase() === PROXY_MODULE_KEY
|
||||
}
|
||||
|
||||
/** 分组列文案:优先分组名;未建分组的用户回退展示所属主管,便于判断归属。 */
|
||||
function groupTextOf(row: AdminUserSecretRow) {
|
||||
if (row.groups?.length) return row.groups.join('、')
|
||||
@@ -106,14 +119,23 @@ 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(';') || '暂无检测记录'
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
@@ -125,17 +147,71 @@ async function load() {
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
})
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result?.items || []
|
||||
total.value = Number(result?.total || 0)
|
||||
groupOptions.value = result?.groupOptions || []
|
||||
void loadBalances()
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取本页用户的余额:列表已经画完,这两列随后填(余额要实时打上游,不能让它在列表主数据前占位)。
|
||||
*
|
||||
* 失败只影响这两列并留一句说明——不 `showAdminFeedback`、不把整页判成加载失败:
|
||||
* 一次上游抖动就红整页,管理员会以为密钥数据本身出了问题。
|
||||
*/
|
||||
async function loadBalances() {
|
||||
const ids = rows.value.map((row) => row.userId)
|
||||
balances.value = {}
|
||||
balanceNotice.value = ''
|
||||
if (!ids.length) return
|
||||
balanceLoading.value = true
|
||||
try {
|
||||
const merged: Record<number, AdminUserSecretBalanceItem> = {}
|
||||
let denied = 0
|
||||
let timedOut = 0
|
||||
for (let start = 0; start < ids.length; start += BALANCE_BATCH) {
|
||||
const batch = ids.slice(start, start + BALANCE_BATCH)
|
||||
const result = await fetchAdminSecretBalances(batch, companyTab.requestCompanyId)
|
||||
for (const item of result?.items || []) {
|
||||
if (item && item.userId != null) merged[Number(item.userId)] = item
|
||||
}
|
||||
denied += result?.deniedUserIds?.length || 0
|
||||
timedOut += result?.timedOutUserIds?.length || 0
|
||||
}
|
||||
balances.value = merged
|
||||
const notices: string[] = []
|
||||
if (denied) notices.push(`${denied} 个用户不在当前数据权限内,本轮未查`)
|
||||
if (timedOut) notices.push(`${timedOut} 个用户本轮上游未应答(不是余额为 0)`)
|
||||
balanceNotice.value = notices.join(';')
|
||||
} catch (error) {
|
||||
balanceNotice.value = error instanceof Error ? error.message : '余额本轮没取到(不是余额为 0)'
|
||||
} finally {
|
||||
balanceLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 某行的 LLM 余额行(按渠道折叠);没取到时给一格占位而不是空白。 */
|
||||
function llmLinesOf(userId: number) {
|
||||
const lines = llmBalanceLines(balances.value[userId]?.llm, balanceLoading.value)
|
||||
return lines.length ? lines : [{ text: '—', title: balanceNotice.value || '本轮没取到数(不是余额为 0)' }]
|
||||
}
|
||||
|
||||
function proxyLineOf(userId: number) {
|
||||
const item = balances.value[userId]
|
||||
if (item?.proxy) return proxyBalanceLine(item.proxy, false)
|
||||
return balanceLoading.value
|
||||
? { text: '查询中…', title: '余额按实时查询,不落库' }
|
||||
: { text: '—', title: balanceNotice.value || '本轮没取到数(不是余量为 0)' }
|
||||
}
|
||||
|
||||
// 切公司 = 重新取数。不重取的页 = tab 在那页上是假的(G1 的 pageFiles 断言盯着这条)。
|
||||
watch(() => companyTab.activeId, () => void load())
|
||||
|
||||
@@ -165,7 +241,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('检测通过')
|
||||
}
|
||||
@@ -178,11 +256,25 @@ async function check(row: AdminUserSecretRow) {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.userId,
|
||||
rowLabel: (row) => row.username || `UID ${row.userId}`,
|
||||
deleteOne: (id) => deleteUserSecret(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
consequence: '将清空这些用户的全部密钥与代理配置;后台锁定的代理也会一并清除并解锁,用户需要重新配置。',
|
||||
verb: '清空',
|
||||
})
|
||||
|
||||
async function remove(row: AdminUserSecretRow) {
|
||||
if (batch.busy) return
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
if (!(await openAdminConfirm({ message: `确定清空「${who}」的全部密钥与代理配置吗?后台锁定的代理会一并清除并解锁,该用户需要重新配置。`, danger: true }))) return
|
||||
try {
|
||||
await deleteUserSecret(row.userId)
|
||||
batch.removeFromSelection(row.userId)
|
||||
ElMessage.success('已清空')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -190,38 +282,33 @@ async function remove(row: AdminUserSecretRow) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 代填并锁定代理:写入后客户端只能查看,修改/清空会被服务端拒绝。 */
|
||||
async function fillProxy(row: AdminUserSecretRow) {
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
const value = window.prompt(
|
||||
`代填「${who}」的代理地址(保存后客户端不可修改或清空,如需变更先解锁):`,
|
||||
row.proxy?.full || '',
|
||||
)
|
||||
if (value == null) return
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) {
|
||||
ElMessage.warning('代理地址不能为空')
|
||||
return
|
||||
}
|
||||
proxyBusyId.value = row.userId
|
||||
try {
|
||||
await saveUserSecretModule(row.userId, 'proxy', trimmed)
|
||||
ElMessage.success(row.proxy?.locked ? '已更新锁定代理' : '已代填并锁定代理')
|
||||
load()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error ? error.message : '代填失败', 'error')
|
||||
} finally {
|
||||
proxyBusyId.value = null
|
||||
/**
|
||||
* 打开代填/改代理弹窗。
|
||||
* ⚠ 不预填任何已有值:后台侧 `full` 恒空(代理链接里带着 key/pwd,2026-11-02 收口后不再下发),
|
||||
* 所以这一单的语义就是「重新填账密」,界面上也没有把原文取回来的旁路。
|
||||
*/
|
||||
function openProxyDialog(row: AdminUserSecretRow) {
|
||||
proxyDialog.value = {
|
||||
userId: row.userId,
|
||||
username: row.username || `UID ${row.userId}`,
|
||||
provider: row.proxy?.channel ?? null,
|
||||
locked: Boolean(row.proxy?.locked),
|
||||
}
|
||||
}
|
||||
|
||||
/** 弹窗保存成功:关掉并重新取数(列表只拿脱敏值,不参与拼装)。 */
|
||||
function onProxySaved() {
|
||||
proxyDialog.value = null
|
||||
load()
|
||||
}
|
||||
|
||||
/** 解锁代理:清空后台代填值,该用户恢复自行配置。 */
|
||||
async function unlockProxy(row: AdminUserSecretRow) {
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
if (!(await openAdminConfirm({ message: `确定解除「${who}」的代理锁定吗?解锁后当前后台代理值会被清空,客户端恢复自行配置。`, danger: true }))) return
|
||||
proxyBusyId.value = row.userId
|
||||
try {
|
||||
await clearUserSecretModule(row.userId, 'proxy')
|
||||
await clearUserSecretModule(row.userId, PROXY_MODULE_KEY)
|
||||
ElMessage.success('已解锁')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -260,37 +347,60 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 170px">
|
||||
<label>状态(三项都通过才算通过)</label>
|
||||
<select v-model="statusFilter">
|
||||
<option v-for="option in STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板)。
|
||||
「全部状态」仍是 STATUS_OPTIONS 里的空串档(下游 checkStatus 照旧传 ''→undefined);
|
||||
model 为空串时 EP 走 placeholder 显示,故 placeholder 与首档同文案。 -->
|
||||
<el-select v-model="statusFilter" class="admin-filter" placeholder="全部状态" aria-label="筛选密钥状态">
|
||||
<el-option v-for="option in STATUS_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" v-if="isSuperAdmin && groupOptions.length" style="min-width: 170px">
|
||||
<label>分组</label>
|
||||
<select v-model="groupFilter">
|
||||
<option :value="null">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="group.id">{{ group.groupName }}</option>
|
||||
</select>
|
||||
<!-- 同上(2026-11-17 换 el-select):分组可能很多 ⇒ 保留 filterable 可搜。
|
||||
「全部分组」的值仍是 null(下游 groupId 照旧 `|| undefined`),空档时由
|
||||
placeholder 显示同一句文案。 -->
|
||||
<el-select v-model="groupFilter" class="admin-filter" filterable placeholder="全部分组" aria-label="筛选分组">
|
||||
<el-option label="全部分组" :value="null" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
<div class="filter-actions">
|
||||
<button class="btn" type="button" @click="search">查询</button>
|
||||
<button class="btn btn-ghost" type="button" @click="reset">重置</button>
|
||||
<button
|
||||
class="btn btn-ghost"
|
||||
type="button"
|
||||
:disabled="balanceLoading || !rows.length"
|
||||
:title="balanceNotice || '余额是实时查上游、不落库;这两列没取到时显示 —,不是 0'"
|
||||
@click="loadBalances"
|
||||
>
|
||||
{{ balanceLoading ? '余额查询中…' : '刷新余额' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="secrets-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 58px">序号</th>
|
||||
<th style="width: 260px">用户</th>
|
||||
<th v-if="isSuperAdmin" style="width: 130px">分组</th>
|
||||
<th style="width: 230px">货源查询密钥</th>
|
||||
<th style="width: 230px">外观专利密钥</th>
|
||||
<th style="width: 170px">LLM 余额</th>
|
||||
<th style="width: 380px">代理设置</th>
|
||||
<th style="width: 160px">代理余量</th>
|
||||
<th style="width: 130px">状态</th>
|
||||
<th style="width: 170px">创建时间</th>
|
||||
<th style="width: 170px">更新时间</th>
|
||||
@@ -299,7 +409,11 @@ onMounted(load)
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="(row, index) in rows" :key="row.userId">
|
||||
<tr v-for="(row, index) in rows" :key="row.userId" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
|
||||
<td>
|
||||
<span class="user-name">{{ row.username || '—' }}</span>
|
||||
@@ -311,8 +425,11 @@ onMounted(load)
|
||||
<div class="module-cell">
|
||||
<span v-if="row.similarAsin?.exists" class="mono-mask" :title="moduleTooltip(row.similarAsin)">{{ row.similarAsin.masked }}</span>
|
||||
<span v-else class="empty-value">未配置</span>
|
||||
<span class="wh-pill" :class="moduleStatusMeta(row.similarAsin).tone" :title="moduleTooltip(row.similarAsin)">
|
||||
{{ moduleStatusMeta(row.similarAsin).label }}
|
||||
<span v-if="row.similarAsin?.exists" class="wh-pill is-source" title="该用户这把密钥所属渠道">
|
||||
{{ llmSourceLabel(row.similarAsin.channel) }}
|
||||
</span>
|
||||
<span class="wh-pill" :class="moduleStatusBand(row.similarAsin).tone" :title="moduleTooltip(row.similarAsin)">
|
||||
{{ moduleStatusBand(row.similarAsin).label }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
@@ -320,18 +437,34 @@ onMounted(load)
|
||||
<div class="module-cell">
|
||||
<span v-if="row.appearancePatent?.exists" class="mono-mask" :title="moduleTooltip(row.appearancePatent)">{{ row.appearancePatent.masked }}</span>
|
||||
<span v-else class="empty-value">未配置</span>
|
||||
<span class="wh-pill" :class="moduleStatusMeta(row.appearancePatent).tone" :title="moduleTooltip(row.appearancePatent)">
|
||||
{{ moduleStatusMeta(row.appearancePatent).label }}
|
||||
<span v-if="row.appearancePatent?.exists" class="wh-pill is-source" title="该用户这把密钥所属渠道">
|
||||
{{ llmSourceLabel(row.appearancePatent.channel) }}
|
||||
</span>
|
||||
<span class="wh-pill" :class="moduleStatusBand(row.appearancePatent).tone" :title="moduleTooltip(row.appearancePatent)">
|
||||
{{ moduleStatusBand(row.appearancePatent).label }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="module-cell module-cell--stack">
|
||||
<span v-if="row.proxy?.exists" class="mono-mask mono-full" :title="moduleTooltip(row.proxy)">{{ row.proxy.full || row.proxy.masked }}</span>
|
||||
<span
|
||||
v-for="(line, lineIndex) in llmLinesOf(row.userId)"
|
||||
:key="`llm-${lineIndex}`"
|
||||
class="balance-line"
|
||||
:title="line.title"
|
||||
>{{ line.text }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="module-cell module-cell--stack">
|
||||
<span v-if="row.proxy?.exists" class="mono-mask" :title="moduleTooltip(row.proxy)">{{ proxyDisplayText(row.proxy) }}</span>
|
||||
<span v-else class="empty-value">未配置</span>
|
||||
<span class="module-cell-pills">
|
||||
<span class="wh-pill" :class="moduleStatusMeta(row.proxy).tone" :title="moduleTooltip(row.proxy)">
|
||||
{{ moduleStatusMeta(row.proxy).label }}
|
||||
<span v-if="row.proxy?.exists" class="wh-pill is-source" title="该用户代理所属供应商">
|
||||
{{ proxySourceLabel(row.proxy.channel) }}
|
||||
</span>
|
||||
<span class="wh-pill" :class="moduleStatusBand(row.proxy).tone" :title="moduleTooltip(row.proxy)">
|
||||
{{ moduleStatusBand(row.proxy).label }}
|
||||
</span>
|
||||
<span
|
||||
v-if="row.proxy?.locked"
|
||||
@@ -344,8 +477,15 @@ onMounted(load)
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="wh-pill" :class="rowStatusMeta(row.status).tone" :title="rowStatusTooltip(row)">
|
||||
{{ rowStatusMeta(row.status).label }}
|
||||
<div class="module-cell module-cell--stack">
|
||||
<span class="balance-line" :title="proxyLineOf(row.userId).title">
|
||||
{{ proxyLineOf(row.userId).text }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="wh-pill" :class="rowStatusBand(row).tone" :title="rowStatusTooltip(row)">
|
||||
{{ rowStatusBand(row).label }}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ formatDateTime(row.createdAt) }}</td>
|
||||
@@ -362,8 +502,7 @@ onMounted(load)
|
||||
<button
|
||||
class="btn btn-sm btn-ghost"
|
||||
type="button"
|
||||
:disabled="proxyBusyId === row.userId"
|
||||
@click="fillProxy(row)"
|
||||
@click="openProxyDialog(row)"
|
||||
>
|
||||
{{ row.proxy?.locked ? '改代理' : '代填代理' }}
|
||||
</button>
|
||||
@@ -376,286 +515,32 @@ onMounted(load)
|
||||
>
|
||||
解锁
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">清空</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">清空</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isSuperAdmin ? 13 : 12" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">{{ keyword || statusFilter || groupFilter ? '暂无匹配记录' : '暂无用户密钥记录' }}</td>
|
||||
<td :colspan="isSuperAdmin ? 13 : 12" class="empty-tip">{{ keyword || statusFilter || groupFilter ? '暂无匹配记录' : '暂无用户密钥记录' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||||
</section>
|
||||
|
||||
<ProxyEntryDialog
|
||||
:model-value="proxyDialog != null"
|
||||
:user-id="proxyDialog?.userId ?? null"
|
||||
:username="proxyDialog?.username ?? ''"
|
||||
:provider="proxyDialog?.provider ?? null"
|
||||
:locked="Boolean(proxyDialog?.locked)"
|
||||
@update:model-value="(open: boolean) => { if (!open) proxyDialog = null }"
|
||||
@saved="onProxySaved"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html 面板风格(与店铺密钥页同一视觉语言)。 */
|
||||
.user-secrets-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.secrets-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.secrets-filter-row {
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 18px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-ghost {
|
||||
background: #ffffff;
|
||||
border-color: #c7d7e5;
|
||||
color: #4f78a5;
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn-ghost:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.secrets-table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.secrets-table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
min-width: 1440px;
|
||||
}
|
||||
.secrets-table-scroll th,
|
||||
.secrets-table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.secrets-table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.secrets-table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.secrets-table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.user-name {
|
||||
color: #24384d;
|
||||
font-weight: 600;
|
||||
/* 用户名(含中文)可完整换行展示,不截断 */
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.creator-name {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.module-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
/* 代理列:完整地址独占一行,状态药丸另起一行,避免长地址被药丸挤压折行 */
|
||||
.module-cell--stack {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
.module-cell .mono-mask {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
/* 代理列展示完整明文:允许折行显示,不截断、不省略 */
|
||||
.module-cell .mono-full {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: visible;
|
||||
text-overflow: clip;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.45;
|
||||
cursor: text;
|
||||
user-select: all;
|
||||
}
|
||||
.mono-mask {
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 12.5px;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.empty-value {
|
||||
color: #a7b4c1;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.empty-tip {
|
||||
color: #8293a5;
|
||||
text-align: center;
|
||||
}
|
||||
.wh-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
cursor: help;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.wh-pill.is-allowed {
|
||||
background: #e8f6ee;
|
||||
border-color: #b9e0c9;
|
||||
color: #2f7d52;
|
||||
}
|
||||
.wh-pill.is-blocked {
|
||||
background: #fdecef;
|
||||
border-color: #f2c4cd;
|
||||
color: #b04a5a;
|
||||
}
|
||||
.wh-pill.is-warn {
|
||||
background: #fdf6e3;
|
||||
border-color: #f0dfae;
|
||||
color: #8f6d1e;
|
||||
}
|
||||
.wh-pill.is-unknown {
|
||||
background: #f0f3f6;
|
||||
border-color: #d6dee6;
|
||||
color: #6b7d8f;
|
||||
}
|
||||
.wh-pill.is-locked {
|
||||
background: #f0ecfb;
|
||||
border-color: #d5caf0;
|
||||
color: #5b4a96;
|
||||
}
|
||||
.module-cell-pills {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./UserSecretsPage.css"></style>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 用户管理页 · 像素复刻旧版 admin.html panel-users(自绘:panel-box + 页头按钮 + 筛选 form-row + 旧式表格/分页 + 原生 confirm 删除)。
|
||||
* script 逻辑沿用现有 Vue 实现;创建/编辑弹窗保留现有组件(含用户菜单权限树)。 */
|
||||
@@ -8,6 +11,7 @@ import type { AdminUser } from '@/types/admin'
|
||||
import { roleLabel } from '@/types/admin'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { deleteUser, fetchUserList, setUserDisabled } from '@/api/users'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { createUserFilterState, toUserListParams, type UserFilterState } from './users-filter'
|
||||
@@ -22,11 +26,18 @@ import EditUserDialog from './EditUserDialog.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
// 平台 tab(V206):账号域三页两 tab 共用本组件,列表/新建/编辑都按当前平台收放。
|
||||
const platformTab = usePlatformTabStore()
|
||||
/** 京东侧标记:上架上限列与编辑入口只在京东 tab 显示(用户口径「不需要在亚马逊那边」)。 */
|
||||
const isJdSide = computed(() => platformTab.active === 'jd')
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
// 用户列表竞态门(S1-F4):快速切公司/翻页只让最后一次响应落地
|
||||
const gate = createLatestRequestGate()
|
||||
const rows = ref<AdminUser[]>([])
|
||||
const total = ref(0)
|
||||
/** 所属管理员候选(来自列表响应的 admins),供超管筛选下拉使用。 */
|
||||
@@ -62,17 +73,26 @@ function editableOf(row: AdminUser): boolean {
|
||||
return editableBy(row.role, operatorRole.value)
|
||||
}
|
||||
|
||||
/** 列表请求参数 = 用户填的筛选态 + 当前公司。公司值每次现取、不写进 filters:
|
||||
* 它由上方 tab 决定而不是用户填的筛选项,住进 filters 就等于多出第二个取值口径(Store 之外再长一个)。 */
|
||||
/** 上架上限列文案(仅京东侧渲染该列):null=旧数据未配('-'),0=不限,其余为具体条数。 */
|
||||
function quotaCellText(row: AdminUser): string {
|
||||
if (row.jdPublishQuota == null) return '-'
|
||||
return row.jdPublishQuota === 0 ? '不限' : String(row.jdPublishQuota)
|
||||
}
|
||||
|
||||
/** 列表请求参数 = 用户填的筛选态 + 当前公司 + 当前平台。公司/平台值每次现取、不写进 filters:
|
||||
* 它们由上方 tab 决定而不是用户填的筛选项,住进 filters 就等于多出第二个取值口径(Store 之外再长一个)。 */
|
||||
function listParams() {
|
||||
return { ...toUserListParams(filters), companyId: companyTab.requestCompanyId }
|
||||
return { ...toUserListParams(filters), companyId: companyTab.requestCompanyId, platform: platformTab.active }
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
// S1-F4:快速切公司/翻页时旧响应可能后返回并覆盖新结果——回写前必须过竞态门
|
||||
const token = gate.begin()
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const page = await fetchUserList(listParams())
|
||||
if (!gate.isCurrent(token)) return
|
||||
rows.value = page.items
|
||||
total.value = page.total
|
||||
if (Array.isArray(page.admins)) admins.value = page.admins
|
||||
@@ -81,14 +101,16 @@ async function loadUsers() {
|
||||
if (last > 0 && filters.page > last) {
|
||||
filters.page = last
|
||||
const retried = await fetchUserList(listParams())
|
||||
if (!gate.isCurrent(token)) return
|
||||
rows.value = retried.items
|
||||
total.value = retried.total
|
||||
}
|
||||
} catch (error) {
|
||||
if (!gate.isCurrent(token)) return
|
||||
loadError.value = error instanceof Error ? error.message : '用户列表加载失败'
|
||||
showAdminFeedback(loadError.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (gate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +125,19 @@ function search() {
|
||||
void loadUsers()
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.username,
|
||||
deleteOne: (id) => deleteUser(id),
|
||||
refresh: loadUsers,
|
||||
blocked: () => loading.value || !!loadError.value,
|
||||
scope: () => [companyTab.activeId, platformTab.active, currentUserId.value],
|
||||
precheck: (row) => deleteBlockReason(row, currentUserId.value),
|
||||
})
|
||||
|
||||
async function removeUser(row: AdminUser) {
|
||||
if (batch.busy) return
|
||||
const reason = deleteBlockReason(row, currentUserId.value)
|
||||
if (reason) {
|
||||
ElMessage.warning(reason)
|
||||
@@ -113,6 +147,7 @@ async function removeUser(row: AdminUser) {
|
||||
if (!(await openAdminConfirm({ message: deleteConfirmMessage(row), danger: true }))) return
|
||||
try {
|
||||
await deleteUser(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
await loadUsers()
|
||||
} catch (error) {
|
||||
@@ -163,18 +198,32 @@ function goJump() {
|
||||
// ② 用户名全平台唯一(V143 的唯一索引),留着上一家填的关键字去筛新一家 ⇒ 必然空页,而输入框还显示着那个值。
|
||||
watch(() => companyTab.activeId, () => { filters.createdByAdminId = null; filters.keyword = ''; filters.page = 1; void loadUsers() })
|
||||
|
||||
// 切平台 tab(V206)= 同样的重取数:列表按平台过滤,候选/关键字跨平台无意义,一并清掉;
|
||||
// 建「公司超级管理员」的公司候选也按平台换一份(2026-11-17:京东 tab 下不能还选到亚马逊公司)。
|
||||
watch(() => platformTab.active, () => {
|
||||
filters.createdByAdminId = null
|
||||
filters.keyword = ''
|
||||
filters.page = 1
|
||||
void loadUsers()
|
||||
loadCompanyOptions()
|
||||
})
|
||||
|
||||
// 公司目录仅站点超管拉取(建「公司超级管理员」时选公司用);非超管不发这个请求,后端 403 兜底。
|
||||
// 按当前平台 tab 过滤(V206)——公司本身已按平台分侧,候选下拉跟着 tab 走。
|
||||
function loadCompanyOptions() {
|
||||
if (!isSuperAdmin.value) return
|
||||
void fetchCompanies(platformTab.active)
|
||||
.then((items) => {
|
||||
companyOptions.value = items.map((c) => ({ id: c.id, companyName: c.companyName }))
|
||||
})
|
||||
.catch(() => {
|
||||
companyOptions.value = []
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadUsers()
|
||||
// 公司目录仅站点超管拉取(建「公司超级管理员」时选公司用);非超管不发这个请求,后端 403 兜底
|
||||
if (isSuperAdmin.value) {
|
||||
void fetchCompanies()
|
||||
.then((items) => {
|
||||
companyOptions.value = items.map((c) => ({ id: c.id, companyName: c.companyName }))
|
||||
})
|
||||
.catch(() => {
|
||||
companyOptions.value = []
|
||||
})
|
||||
}
|
||||
loadCompanyOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -215,15 +264,21 @@ onMounted(() => {
|
||||
<button class="btn btn-sm btn-secondary" type="button" @click="retry">重试</button>
|
||||
</div>
|
||||
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll user-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 70px">ID</th>
|
||||
<th style="width: 180px">用户名</th>
|
||||
<th style="width: 140px">角色</th>
|
||||
<th style="width: 160px">所属管理员</th>
|
||||
<th style="width: 160px">到期时间</th>
|
||||
<th v-if="isJdSide" style="width: 110px">上架上限</th>
|
||||
<th style="width: 90px">状态</th>
|
||||
<th style="width: 180px">创建时间</th>
|
||||
<th style="width: 180px">更新时间</th>
|
||||
@@ -232,7 +287,11 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ row.id }}</td>
|
||||
<td>{{ row.username }}</td>
|
||||
<td>{{ roleLabel(row.role) }}</td>
|
||||
@@ -240,6 +299,7 @@ onMounted(() => {
|
||||
<td :class="{ 'expiry-cell-expired': formatExpiryCell(row).expired }">
|
||||
{{ formatExpiryCell(row).text }}
|
||||
</td>
|
||||
<td v-if="isJdSide">{{ quotaCellText(row) }}</td>
|
||||
<td class="status-cell" :class="{ 'status-cell-disabled': !!row.disabledAt }" :title="row.disabledAt ? `停用于 ${row.disabledAt}` : undefined">
|
||||
{{ disabledBadgeText(row) }}
|
||||
</td>
|
||||
@@ -267,7 +327,7 @@ onMounted(() => {
|
||||
<button
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="deleteBlockReason(row, currentUserId) !== undefined"
|
||||
:disabled="batch.busy || deleteBlockReason(row, currentUserId) !== undefined"
|
||||
:title="deleteBlockReason(row, currentUserId) || undefined"
|
||||
@click="removeUser(row)"
|
||||
>
|
||||
@@ -277,10 +337,10 @@ onMounted(() => {
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isJdSide ? 11 : 10" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="9" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
<td :colspan="isJdSide ? 11 : 10" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -297,9 +357,10 @@ onMounted(() => {
|
||||
:company-options="companyOptions"
|
||||
:operator-company-id="operatorCompanyId"
|
||||
:active-company-id="companyTab.requestCompanyId"
|
||||
:platform="platformTab.active"
|
||||
@created="loadUsers"
|
||||
/>
|
||||
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" :company-id="companyTab.requestCompanyId" @updated="loadUsers" />
|
||||
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" :company-id="companyTab.requestCompanyId" :platform="platformTab.active" @updated="loadUsers" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -354,8 +415,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -369,12 +429,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -11,22 +11,33 @@ import {
|
||||
|
||||
export const SHOP_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
|
||||
|
||||
export async function fetchShopGroups(companyId?: number | null): Promise<ShopGroupItem[]> {
|
||||
const { data } = await http.get<unknown>(SHOP_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })
|
||||
/** 列表:company_id 收公司口径(钉住的取值口),platform 收平台 tab 口径(V206),都缺省就不发。 */
|
||||
export async function fetchShopGroups(companyId?: number | null, platform?: string): Promise<ShopGroupItem[]> {
|
||||
const { data } = await http.get<unknown>(SHOP_GROUPS_ENDPOINT, {
|
||||
params: {
|
||||
...(companyId != null ? { company_id: companyId } : {}),
|
||||
...(platform ? { platform } : {}),
|
||||
},
|
||||
})
|
||||
return parseShopGroupList(data)
|
||||
}
|
||||
|
||||
/** 新建分组:POST /api/admin/shop-manages/groups(创建人 = 组长 = 当前操作者)。 */
|
||||
export async function createShopGroup(name: string, memberUserIds: number[], createdById: number): Promise<ShopGroupItem> {
|
||||
const { data } = await http.post<unknown>(SHOP_GROUPS_ENDPOINT, toShopGroupCreatePayload(name, memberUserIds, createdById))
|
||||
export async function createShopGroup(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
createdById: number,
|
||||
platform?: string,
|
||||
): Promise<ShopGroupItem> {
|
||||
const { data } = await http.post<unknown>(SHOP_GROUPS_ENDPOINT, toShopGroupCreatePayload(name, memberUserIds, createdById, platform))
|
||||
const created = parseShopGroupItem(unwrap<unknown>(data))
|
||||
if (!created) throw new Error('创建分组响应异常:缺少分组数据')
|
||||
return created
|
||||
}
|
||||
|
||||
/** 更新分组:PUT /api/admin/shop-manages/groups/{id}。 */
|
||||
export async function updateShopGroup(id: number, name: string, memberUserIds: number[]): Promise<ShopGroupItem> {
|
||||
const { data } = await http.put<unknown>(`${SHOP_GROUPS_ENDPOINT}/${id}`, toShopGroupUpdatePayload(name, memberUserIds))
|
||||
export async function updateShopGroup(id: number, name: string, memberUserIds: number[], platform?: string): Promise<ShopGroupItem> {
|
||||
const { data } = await http.put<unknown>(`${SHOP_GROUPS_ENDPOINT}/${id}`, toShopGroupUpdatePayload(name, memberUserIds, platform))
|
||||
const updated = parseShopGroupItem(unwrap<unknown>(data))
|
||||
if (!updated) throw new Error('更新分组响应异常:缺少分组数据')
|
||||
return updated
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface ShopGroupItem {
|
||||
memberUserIds?: number[]
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
/** 所属平台(V206):'amazon'|'jd';旧负载缺省不渲染该键。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
export interface ShopGroupFormErrors {
|
||||
@@ -53,6 +55,8 @@ export function parseShopGroupItem(raw: unknown): ShopGroupItem | null {
|
||||
if (createdAt) item.createdAt = createdAt
|
||||
const updatedAt = text(record.updatedAt ?? record.updated_at)
|
||||
if (updatedAt) item.updatedAt = updatedAt
|
||||
const platform = text(record.platform)
|
||||
if (platform) item.platform = platform
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -79,18 +83,34 @@ export function validateShopGroupForm(name: string): ShopGroupFormErrors {
|
||||
return errors
|
||||
}
|
||||
|
||||
/** 创建载荷:groupName + 成员 + 创建人(= 组长,当前操作者)。 */
|
||||
/** 创建载荷:groupName + 成员 + 创建人(= 组长,当前操作者)+ 所属平台(V206,缺省不下发)。 */
|
||||
export function toShopGroupCreatePayload(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
createdById: number,
|
||||
): { groupName: string; memberUserIds: number[]; createdById: number } {
|
||||
return { groupName: text(name), memberUserIds: dedupeIds(memberUserIds), createdById }
|
||||
platform?: string,
|
||||
): { groupName: string; memberUserIds: number[]; createdById: number; platform?: string } {
|
||||
const payload: { groupName: string; memberUserIds: number[]; createdById: number; platform?: string } = {
|
||||
groupName: text(name),
|
||||
memberUserIds: dedupeIds(memberUserIds),
|
||||
createdById,
|
||||
}
|
||||
if (platform) payload.platform = platform
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 更新载荷:groupName + 成员(组长/创建人不可改)。 */
|
||||
export function toShopGroupUpdatePayload(name: string, memberUserIds: number[]): { groupName: string; memberUserIds: number[] } {
|
||||
return { groupName: text(name), memberUserIds: dedupeIds(memberUserIds) }
|
||||
/** 更新载荷:groupName + 成员 + 所属平台(V206;组长/创建人不可改)。 */
|
||||
export function toShopGroupUpdatePayload(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
platform?: string,
|
||||
): { groupName: string; memberUserIds: number[]; platform?: string } {
|
||||
const payload: { groupName: string; memberUserIds: number[]; platform?: string } = {
|
||||
groupName: text(name),
|
||||
memberUserIds: dedupeIds(memberUserIds),
|
||||
}
|
||||
if (platform) payload.platform = platform
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 组员候选用户(对齐 admin.js getEligibleShopManageGroupUsers 的过滤语义)。 */
|
||||
@@ -135,6 +155,30 @@ export function eligibleGroupMembers(
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 组长候选(2026-11-18 用户口径「新建分组组长要能下拉选」):
|
||||
* - 公司超管永不领衔——与组员「超级管理员不属于任何分组」同源,它是本公司最高账号;
|
||||
* - 站点超管只保留操作者本人(admin 保持「自己领衔建组」的既有能力,其余站点超管不进候选);
|
||||
* - 管理员与普通账号均可领衔(普通账号当组长有既有文案背书:「当前账号只能作为组长使用」)。
|
||||
*
|
||||
* 后端契约:站点超管走 `validateLeaderOperator` 放行通道,可给任意 `createdById` 建组,
|
||||
* 但组长必须与操作者同公司(`ensureLeaderSharesOperatorCompany`)——候选池天然同公司(按操作者
|
||||
* companyId 拉取),不会列出后端要打回的人。非超管操作者不出下拉(后端强制组长=操作者本人)。
|
||||
*/
|
||||
export function eligibleGroupLeaders(
|
||||
users: GroupMemberCandidateUser[],
|
||||
operatorRole: string,
|
||||
operatorId: number | null,
|
||||
): GroupMemberCandidateUser[] {
|
||||
const operatorKey = operatorId != null && operatorId > 0 ? String(operatorId) : ''
|
||||
const operatorIsSiteSuper = isSuperAdminRole(operatorRole)
|
||||
return users.filter((u) => {
|
||||
if (!isGroupIneligibleRole(u.role)) return true
|
||||
// 两档超管默认不领衔;站点超管只保留操作者本人这一个例外。
|
||||
return operatorIsSiteSuper && String(u.id) === operatorKey
|
||||
})
|
||||
}
|
||||
|
||||
/** 组员候选帮助文案(对齐 admin.js:3179-3182)。 */
|
||||
export function groupMemberCandidateHint(candidateCount: number, operatorRole: string): string {
|
||||
if (candidateCount > 0) return '可添加当前组长创建的普通员工账号'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/** 新建用户表单模型(任务 45):纯逻辑,镜像 Java AdminUserCreateRequest 字段与后端校验。 */
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
|
||||
export const CREATE_USERNAME_MIN_LEN = 2
|
||||
export const CREATE_PASSWORD_MIN_LEN = 6
|
||||
@@ -21,6 +22,8 @@ export interface CreateUserForm {
|
||||
expiresAt: string
|
||||
/** 所属公司 id:仅 role=company_super_admin 时由站点超管必选(2026-10-05 需求)。 */
|
||||
companyId?: number | null
|
||||
/** 所属平台(V206):弹窗打开时预填当前平台 tab(不设手选——2026-11-17 用户口径)。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export interface CreateUserFormErrors {
|
||||
@@ -43,10 +46,12 @@ export interface CreateUserPayload {
|
||||
* 反向钉(company-user-create.test.ts)唯一豁免的例外:公司超管必须落指定公司,
|
||||
* 否则会静默落操作者自己的公司(公司 1),用户需求就是给别家公司开超管。 */
|
||||
companyId?: number
|
||||
/** 所属平台(V206):恒下发(预填当前平台 tab),缺省后端落 amazon。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export function createEmptyCreateUserForm(): CreateUserForm {
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, expiresAt: '', companyId: null }
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, expiresAt: '', companyId: null, platform: 'amazon' }
|
||||
}
|
||||
|
||||
/** 未知/空白/超管角色归一:admin/company_super_admin/normal 白名单,其余归 normal。 */
|
||||
@@ -147,6 +152,7 @@ export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
|
||||
password: form.password || '',
|
||||
role,
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
platform: form.platform,
|
||||
}
|
||||
if (payload.role === 'normal' && form.createdBy != null) {
|
||||
payload.createdById = form.createdBy
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
toEditUserUpdateRequest,
|
||||
validateEditUserForm,
|
||||
type EditUserForm,
|
||||
type EditUserFormOptions,
|
||||
} from './user-edit-model'
|
||||
|
||||
/** Java AdminUserController.updateUser 端点前缀。 */
|
||||
@@ -12,12 +13,13 @@ export const EDIT_USER_ENDPOINT = '/api/admin/user'
|
||||
|
||||
/**
|
||||
* 提交编辑用户:先校验(不通过抛首条错误),再序列化 PUT;http/后端失败交由调用方提示。
|
||||
* options.includeQuota=false(亚马逊侧)不下发上架上限——校验与序列化同口径。
|
||||
*/
|
||||
export async function submitEditUser(form: EditUserForm): Promise<void> {
|
||||
const { valid, errors } = validateEditUserForm(form)
|
||||
export async function submitEditUser(form: EditUserForm, options: EditUserFormOptions = {}): Promise<void> {
|
||||
const { valid, errors } = validateEditUserForm(form, options)
|
||||
if (!valid) {
|
||||
throw new Error(Object.values(errors)[0] || '编辑用户表单校验未通过')
|
||||
}
|
||||
const { data } = await http.put<unknown>(`${EDIT_USER_ENDPOINT}/${form.uid}`, toEditUserUpdateRequest(form))
|
||||
const { data } = await http.put<unknown>(`${EDIT_USER_ENDPOINT}/${form.uid}`, toEditUserUpdateRequest(form, options))
|
||||
unwrap<unknown>(data)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/** 编辑用户表单回填模型(任务 47):从用户行回填可编辑表单,镜像 Java AdminUserUpdateRequest。 */
|
||||
import type { AdminUser } from '../../types/admin'
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
import { CREATE_PASSWORD_MIN_LEN, mayCarryOwnExpiry } from './user-create-model.ts'
|
||||
|
||||
/** 编辑可选角色:站点/公司超管不可改,未知归 normal;后端只收 admin|normal。 */
|
||||
export type EditUserRole = 'normal' | 'admin'
|
||||
|
||||
export interface EditUserForm {
|
||||
jdPublishQuota: number
|
||||
uid: number
|
||||
/** 仅展示用,后端不支持改用户名。 */
|
||||
username: string
|
||||
@@ -18,9 +20,12 @@ export interface EditUserForm {
|
||||
originalRole: string
|
||||
/** 到期时间(yyyy-MM-dd HH:mm:ss);空串 = 永不过期。null = 后端本来就无到期。 */
|
||||
expiresAt: string
|
||||
/** 所属平台(V206):编辑回填行值(不设手选——2026-11-17 用户口径),未知/缺省归亚马逊(存量默认)。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export interface EditUserFormErrors {
|
||||
jdPublishQuota?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
@@ -28,10 +33,13 @@ export interface EditUserFormErrors {
|
||||
export interface EditUserUpdateRequest {
|
||||
/** 目标是公司超管时不携带(防止表单把公司超管误降级);站点超管改其密码/到期时间即可。 */
|
||||
role?: EditUserRole
|
||||
jdPublishQuota?: number
|
||||
columnIds: number[]
|
||||
password?: string
|
||||
/** 到期时间:空串=清除(恢复永不过期),有值=改期;总是下发(与后端"传了就更新"对齐)。 */
|
||||
expiresAt: string
|
||||
/** 所属平台(V206):总是下发(编辑保持行值原样,后端显式才落)。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
/** 行角色 → 可编辑角色:仅 admin 映射 admin,其余(含 unknown)归 normal。 */
|
||||
@@ -71,22 +79,38 @@ export function fillEditUserForm(user: AdminUser): EditUserForm {
|
||||
const role = typeof user.role === 'string' ? user.role.trim() : ''
|
||||
return {
|
||||
uid: user.id,
|
||||
jdPublishQuota: user.jdPublishQuota ?? 5000,
|
||||
username: user.username || '',
|
||||
password: '',
|
||||
role: editRoleOf(role),
|
||||
columnIds: [],
|
||||
originalRole: role,
|
||||
expiresAt: normalizeExpiryForPicker(user.expiresAt),
|
||||
platform: user.platform === 'jd' ? 'jd' : 'amazon',
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑表单校验选项:includeQuota=false(亚马逊侧)跳过上架上限校验——该项不下发。 */
|
||||
export interface EditUserFormOptions {
|
||||
/** 是否参与上架上限(jd_publish_quota)的校验与下发;缺省 true(京东侧)。 */
|
||||
includeQuota?: boolean
|
||||
}
|
||||
|
||||
/** 编辑表单校验:密码可留空(不改),非空时须达到最小长度。 */
|
||||
export function validateEditUserForm(form: EditUserForm): { valid: boolean; errors: EditUserFormErrors } {
|
||||
export function validateEditUserForm(
|
||||
form: EditUserForm,
|
||||
options: EditUserFormOptions = {},
|
||||
): { valid: boolean; errors: EditUserFormErrors } {
|
||||
const errors: EditUserFormErrors = {}
|
||||
const password = form.password || ''
|
||||
if (password && password.length < CREATE_PASSWORD_MIN_LEN) {
|
||||
errors.password = `密码至少${CREATE_PASSWORD_MIN_LEN}个字符,留空则不修改`
|
||||
}
|
||||
if (options.includeQuota !== false &&
|
||||
(form.role === 'admin' || form.originalRole === 'company_super_admin') &&
|
||||
(!Number.isInteger(form.jdPublishQuota) || form.jdPublishQuota < 0 || form.jdPublishQuota > 2147483647)) {
|
||||
errors.jdPublishQuota = '请输入 0 至 2147483647 的整数'
|
||||
}
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
@@ -96,8 +120,11 @@ export function validateEditUserForm(form: EditUserForm): { valid: boolean; erro
|
||||
* <p>expiresAt 按「改完之后的角色」决定:目标角色不能带自己的到期时间时发空串=清空
|
||||
* (后端 400 闸门只拦「有值」,空串走既有的清除分支)。公司超管目标不带 role,
|
||||
* 它的 roleAfter 就是 company_super_admin,续费那条空串不会被误当成清空。</p>
|
||||
*
|
||||
* <p>options.includeQuota=false(亚马逊侧编辑)不下发 jdPublishQuota——上架上限是京东
|
||||
* 口径,亚马逊侧不显示也不改它(用户口径 2026-11-17);platform 恒下发(单选恒渲染)。</p>
|
||||
*/
|
||||
export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateRequest {
|
||||
export function toEditUserUpdateRequest(form: EditUserForm, options: EditUserFormOptions = {}): EditUserUpdateRequest {
|
||||
const originalRole = (form.originalRole || '').trim().toLowerCase()
|
||||
if (originalRole === 'super_admin') {
|
||||
throw new Error('不能修改超级管理员')
|
||||
@@ -110,10 +137,14 @@ export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateReque
|
||||
const request: EditUserUpdateRequest = {
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
expiresAt: mayCarryOwnExpiry(roleAfter) ? (form.expiresAt || '').trim() : '',
|
||||
platform: form.platform,
|
||||
}
|
||||
if (keepsRole) {
|
||||
request.role = nextRole
|
||||
}
|
||||
if (options.includeQuota !== false && (roleAfter === 'admin' || roleAfter === 'company_super_admin')) {
|
||||
request.jdPublishQuota = form.jdPublishQuota
|
||||
}
|
||||
const password = form.password || ''
|
||||
if (password) request.password = password
|
||||
return request
|
||||
|
||||
@@ -146,3 +146,24 @@ export function compactDirectGrantIds(checkedIds: unknown, tree: MenuOptionNode[
|
||||
walk(tree, false)
|
||||
return ids.filter((id) => !ungrantable.has(id) && !coveredByAncestor.has(id))
|
||||
}
|
||||
|
||||
/**
|
||||
* 把勾选集收敛到「可见树」内(2026-11-17 用户口径「授权树按平台收」的另一半):
|
||||
* 授权树按平台过滤后,另一侧的已勾 id 在树上不可见、也不再属于这棵树——它们必须
|
||||
* 从表单勾选集里剔除,否则「京东档账号」保存后仍携带整批亚马逊菜单授权(侧边栏
|
||||
* 亚马逊 tab 照样全亮,平台分侧被静默架空)。纯函数:入参不动,返回去重升序交集。
|
||||
*/
|
||||
export function pruneCheckedIdsToTree(checkedIds: unknown, visibleTree: MenuOptionNode[]): number[] {
|
||||
const ids = normalizeMenuIds(checkedIds)
|
||||
if (ids.length === 0) return []
|
||||
if (visibleTree.length === 0) return []
|
||||
const visible = new Set<number>()
|
||||
const walk = (nodes: MenuOptionNode[]): void => {
|
||||
for (const node of nodes) {
|
||||
visible.add(node.id)
|
||||
if (node.children?.length) walk(node.children)
|
||||
}
|
||||
}
|
||||
walk(visibleTree)
|
||||
return ids.filter((id) => visible.has(id))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,463 @@
|
||||
/**
|
||||
* 密钥管理页的纯逻辑模型(货源标签 + 代理重填 + 检测结果档位)。
|
||||
*
|
||||
* 四条收口都在这个文件里,页模板只调这里导出的函数,不各写各的字典:
|
||||
*
|
||||
* 1. **货源标签按模块分字典**(2026-11-02 修):原先 `UserSecretsPage.vue` 里是一整张
|
||||
* `sourceLabel()`,把 LLM 渠道(longtaitou/t8star)与代理供应商(qingguo/jikip)混在同一个
|
||||
* switch 上,于是「按值匹配」的字典会把它认识的**任何**值贴到**任何**列上——代理行因此能长出
|
||||
* 「龙抬头」这种标签。后端 VO 的 `channel` 本来就是按模块归一的(`UserSecretModule.channelOrDefault`
|
||||
* 代理走 `ProxyProvider`、密钥走 `LlmChannel`),所以错标只会来自前端这张合表。
|
||||
* 现在两张表互不相通:代理列只认供应商、密钥列只认渠道,跨域的值一律落到「—」而不是被硬认下来。
|
||||
*
|
||||
* 2. **代理列不再显示、也不再回传原文**(2026-11-02 后端 `SecretMasking.maskProxy` 收口):
|
||||
* `AdminUserSecretModuleVo.full` 后台侧恒为空,界面只读 `masked`(`scheme://host`,不含
|
||||
* key/pwd)。因此原先「代填/改代理」用 `window.prompt` 预填整条链接的交互已失效
|
||||
* (预填必然是空的,保存还会把空串顶上去)——改成重新填账密:青果填 Authkey/Authpwd、
|
||||
* 由 `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'
|
||||
|
||||
export type LlmChannelKey = 'longtaitou' | 't8star'
|
||||
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'
|
||||
|
||||
/** 认不出的货源一律这个占位,不许回退成"某个具体渠道名"(那正是错标的来源)。 */
|
||||
export const UNKNOWN_SOURCE_LABEL = '—'
|
||||
|
||||
const LLM_CHANNEL_LABELS: Record<LlmChannelKey, string> = {
|
||||
longtaitou: '龙抬头',
|
||||
t8star: '贞贞',
|
||||
}
|
||||
|
||||
const PROXY_PROVIDER_LABELS: Record<ProxyProviderKey, string> = {
|
||||
qingguo: '青果',
|
||||
jikip: '极客',
|
||||
}
|
||||
|
||||
function normalizeKey(raw: unknown): string {
|
||||
return String(raw ?? '').trim().toLowerCase()
|
||||
}
|
||||
|
||||
function known<T extends string>(table: Record<T, string>, raw: unknown): string | null {
|
||||
const key = normalizeKey(raw)
|
||||
return Object.prototype.hasOwnProperty.call(table, key)
|
||||
? table[key as T]
|
||||
: null
|
||||
}
|
||||
|
||||
/** LLM 密钥列的渠道名:只查 LLM 字典,代理供应商的值在这里认不出。 */
|
||||
export function llmSourceLabel(channel: string | null | undefined): string {
|
||||
return known(LLM_CHANNEL_LABELS, channel) ?? UNKNOWN_SOURCE_LABEL
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理列的供应商名:只查供应商字典。
|
||||
* 传进 LLM 渠道值(`longtaitou`/`t8star`)必须返回占位——这条是"代理行贴龙抬头"的直接判据。
|
||||
*/
|
||||
export function proxySourceLabel(channel: string | null | undefined): string {
|
||||
return known(PROXY_PROVIDER_LABELS, channel) ?? UNKNOWN_SOURCE_LABEL
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一为可选供应商;未知值不猜,返回 null 让调用方保持原选择。
|
||||
*/
|
||||
export function asProxyProvider(raw: unknown): ProxyProviderKey | null {
|
||||
const key = normalizeKey(raw)
|
||||
return key === 'qingguo' || key === 'jikip' ? key : null
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理列的唯一显示文本:后端下发的 `masked`(青果形状 `https://overseas.proxy.qg.net`)。
|
||||
* 刻意**不读** `full`,也不做任何"masked 空就回落到原文"的兜底——回落等于把脱敏前的行为留在界面里。
|
||||
*/
|
||||
export function proxyDisplayText(module: { masked?: string | null } | null | undefined): string {
|
||||
const masked = String(module?.masked ?? '').trim()
|
||||
return masked || UNKNOWN_SOURCE_LABEL
|
||||
}
|
||||
|
||||
/** 代填/改代理的表单草稿:青果用前三个字段,极客用 `link`。 */
|
||||
export interface ProxyEntryDraft {
|
||||
provider: ProxyProviderKey
|
||||
authkey: string
|
||||
authpwd: string
|
||||
link: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 空草稿:`provider` 用后端已登记的那一列预置(只是选中的单选框,不是凭据),
|
||||
* 三个输入位**一律空**——脱敏后没有任何原文可回填。
|
||||
*/
|
||||
export function emptyProxyEntryDraft(currentProvider?: string | null): ProxyEntryDraft {
|
||||
return {
|
||||
provider: asProxyProvider(currentProvider) ?? DEFAULT_PROXY_PROVIDER,
|
||||
authkey: '',
|
||||
authpwd: '',
|
||||
link: '',
|
||||
}
|
||||
}
|
||||
|
||||
/** 与后端 `PROXY_FORMAT_HINT` 同一句口径:本函数只做前置提示,真判仍在服务端。 */
|
||||
const PROXY_LINK_FORMAT_HINT =
|
||||
'代理地址格式不正确,请填写 http://host:port 形式的代理地址,或代理服务商的提取链接(https://...)'
|
||||
|
||||
/** http(s) + 有主机名:镜像后端 `validateProxyValue`,不在前端扩大判死范围。 */
|
||||
function isHttpUrl(raw: string): boolean {
|
||||
try {
|
||||
const parsed = new URL(raw)
|
||||
return (parsed.protocol === 'http:' || parsed.protocol === 'https:') && Boolean(parsed.hostname)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验草稿,返回给界面显示的文案(空串=可以提交)。
|
||||
* 点名"缺哪把":缺 pwd 时青果回 `API_AUTH_DENY`,所以两把都得填,不能只填 key 就当配好了。
|
||||
*/
|
||||
export function validateProxyEntry(draft: ProxyEntryDraft): string {
|
||||
if (!asProxyProvider(draft.provider)) return '请选择代理供应商'
|
||||
if (draft.provider === 'qingguo') {
|
||||
if (!String(draft.authkey || '').trim()) return '请填写青果 Authkey'
|
||||
if (!String(draft.authpwd || '').trim()) return '请填写青果 Authpwd(只填 Authkey 青果会判鉴权拒绝)'
|
||||
return ''
|
||||
}
|
||||
const link = String(draft.link || '').trim()
|
||||
if (!link) return '请填写极客提取链接'
|
||||
if (!isHttpUrl(link)) return PROXY_LINK_FORMAT_HINT
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装 PUT `/api/admin/user-secrets/{userId}/modules/proxy` 的请求体。
|
||||
* 不合法返回 null(调用方不得把 null 顶上去,更不得拿旧值凑数)。
|
||||
*/
|
||||
export function buildProxyEntryPayload(
|
||||
draft: ProxyEntryDraft,
|
||||
): { value: string; channel: ProxyProviderKey } | null {
|
||||
if (validateProxyEntry(draft)) return null
|
||||
if (draft.provider === 'qingguo') {
|
||||
return { value: composeQingguoLink(draft.authkey, draft.authpwd), channel: 'qingguo' }
|
||||
}
|
||||
return { value: String(draft.link || '').trim(), channel: 'jikip' }
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 余额侧写(2026-11-05 B83):第四处收口,仍守「两张字典互不相通」那一条。
|
||||
*
|
||||
* LLM 那格的单位是**钱**(人民币=龙抬头站内 ⚡,后端只取 `credits` 块),
|
||||
* 代理那格的 `surplus` 是**次数**、`scope` 说这份量属于谁的池子。
|
||||
* 两者都叫「余额」,混用一张函数就会读出「极客 ¥34」这种既不像钱也不像次的数——
|
||||
* 所以这里各写各的,跨域字段一个都不读,认不出来一律 `—`(同货源标签那条判据)。
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 后端 credits 块登记的单位;不是这个值就说明口径换了,宁可不显示也不猜。 */
|
||||
export const LLM_BALANCE_UNIT = 'CREDIT'
|
||||
|
||||
interface LlmBalanceLike {
|
||||
moduleKey?: string | null
|
||||
moduleLabel?: string | null
|
||||
channel?: string | null
|
||||
channelLabel?: string | null
|
||||
available?: boolean | null
|
||||
balance?: string | null
|
||||
availableBalance?: string | null
|
||||
frozen?: string | null
|
||||
unit?: string | null
|
||||
message?: string | null
|
||||
checkedAt?: string | null
|
||||
}
|
||||
|
||||
interface ProxyBalanceLike {
|
||||
available?: boolean | null
|
||||
surplus?: string | null
|
||||
balance?: string | null
|
||||
scope?: string | null
|
||||
message?: string | null
|
||||
}
|
||||
|
||||
/** 一行的显示内容:`text` 进格子,`title` 进悬停(整句原因与取数时刻都在那儿)。 */
|
||||
export interface BalanceLine {
|
||||
text: string
|
||||
title: string
|
||||
}
|
||||
|
||||
const BALANCE_PLACEHOLDER: BalanceLine = { text: UNKNOWN_SOURCE_LABEL, title: '本轮没取到数(不是余额为 0)' }
|
||||
const BALANCE_PENDING: BalanceLine = { text: '查询中…', title: '余额按实时查询,不落库' }
|
||||
|
||||
/** 人民币读数:解析不出数字时原样回显,不返回 `¥0`(一格 0 会被读成「没钱了」)。 */
|
||||
export function formatYuan(raw: string | null | undefined): string {
|
||||
const text = String(raw ?? '').trim()
|
||||
if (!text) return ''
|
||||
const value = Number(text.replace(/,/g, ''))
|
||||
if (!Number.isFinite(value)) return text
|
||||
return `¥${value.toFixed(2)}`
|
||||
}
|
||||
|
||||
function llmDetail(cell: LlmBalanceLike): string {
|
||||
const parts: string[] = []
|
||||
if (cell.moduleLabel) parts.push(String(cell.moduleLabel))
|
||||
const total = formatYuan(cell.balance)
|
||||
const usable = formatYuan(cell.availableBalance)
|
||||
const frozen = formatYuan(cell.frozen)
|
||||
if (total) parts.push(`总 ${total}`)
|
||||
if (usable) parts.push(`可用 ${usable}`)
|
||||
if (frozen) parts.push(`预冻结 ${frozen}`)
|
||||
if (cell.checkedAt) parts.push(`取数于 ${String(cell.checkedAt).replace('T', ' ').slice(0, 16)}`)
|
||||
const message = String(cell.message ?? '').trim()
|
||||
if (message) parts.push(message)
|
||||
return parts.join(';') || '暂无余额信息'
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM 余额列:一把密钥一行,前缀是**渠道名**(钱挂在渠道账户上,不在模块上)。
|
||||
*
|
||||
* `pending=true` ⇒ 这一轮还在取数;取到但不合格(单位不是 CREDIT/available=false)
|
||||
* 一律走占位与后端原文,不显示金额。
|
||||
*/
|
||||
export function llmBalanceLine(cell: LlmBalanceLike | null | undefined, pending = false): BalanceLine {
|
||||
if (pending && !cell) return BALANCE_PENDING
|
||||
if (!cell) return BALANCE_PLACEHOLDER
|
||||
const label = known(LLM_CHANNEL_LABELS, cell.channel) ?? UNKNOWN_SOURCE_LABEL
|
||||
// 渠道认不出(LLM 列被喂了供应商名这类跨域值)时整格给占位:宁可什么都不显示,
|
||||
// 也不让一个不知道属于谁的数字或句子进界面(同货源标签那张表「跨域一律 —」的判据)
|
||||
if (label === UNKNOWN_SOURCE_LABEL) {
|
||||
return { text: UNKNOWN_SOURCE_LABEL, title: `${llmDetail(cell)}|渠道值认不出,未显示金额` }
|
||||
}
|
||||
if (!cell.available || String(cell.unit ?? '').trim().toUpperCase() !== LLM_BALANCE_UNIT) {
|
||||
const message = String(cell.message ?? '').trim()
|
||||
return { text: message ? `${label} 查不到` : `${label} ${UNKNOWN_SOURCE_LABEL}`, title: llmDetail(cell) }
|
||||
}
|
||||
const total = formatYuan(cell.balance)
|
||||
if (!total) return { text: `${label} ${UNKNOWN_SOURCE_LABEL}`, title: llmDetail(cell) }
|
||||
return { text: `${label} ${total}`, title: llmDetail(cell) }
|
||||
}
|
||||
|
||||
/**
|
||||
* LLM 余额列的整格内容:**按渠道折叠**,一个渠道一行。
|
||||
*
|
||||
* 钱挂在渠道账户上、不挂在模块上:两把密钥(外观专利/货源查询)都在龙抬头时,
|
||||
* 上游回的是同一个余额——排两遍会读成「这个账户有两笔钱」。折叠后 title 里仍留每一把的原文,
|
||||
* 运维要判「是哪把密钥的渠道」看得回来。
|
||||
*/
|
||||
export function llmBalanceLines(
|
||||
cells: Array<LlmBalanceLike | null | undefined> | null | undefined,
|
||||
pending = false,
|
||||
): BalanceLine[] {
|
||||
const list = (cells ?? []).filter((cell): cell is LlmBalanceLike => Boolean(cell))
|
||||
if (!list.length) return pending ? [BALANCE_PENDING] : []
|
||||
const grouped = new Map<string, BalanceLine>()
|
||||
for (const cell of list) {
|
||||
const key = normalizeKey(cell.channel) || 'unknown'
|
||||
const line = llmBalanceLine(cell, pending)
|
||||
const hit = grouped.get(key)
|
||||
grouped.set(key, hit ? { text: hit.text, title: `${hit.title}|${line.title}` } : line)
|
||||
}
|
||||
return [...grouped.values()]
|
||||
}
|
||||
|
||||
/** 代理池子的归属说法:platform 那份是**平台的钱**,绝不允许被读成这个用户的余量。 */
|
||||
const PROXY_SCOPE_LABELS: Record<string, string> = {
|
||||
user: '你的套餐',
|
||||
platform: '平台池',
|
||||
none: '查不了',
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理余量列:极客给「剩余 IP 次数」(单位是次、不是钱);青果按 scope=none 说查不了。
|
||||
* `scope` 认不出来时不硬认(回落「来源未标注」并保留原值进 title 供运维核)。
|
||||
*/
|
||||
export function proxyBalanceLine(cell: ProxyBalanceLike | null | undefined, pending = false): BalanceLine {
|
||||
if (pending && !cell) return BALANCE_PENDING
|
||||
if (!cell) return BALANCE_PLACEHOLDER
|
||||
const scopeKey = normalizeKey(cell.scope)
|
||||
const scopeLabel = Object.prototype.hasOwnProperty.call(PROXY_SCOPE_LABELS, scopeKey)
|
||||
? PROXY_SCOPE_LABELS[scopeKey]
|
||||
: '来源未标注'
|
||||
const message = String(cell.message ?? '').trim()
|
||||
const detailParts = [`${scopeLabel}`]
|
||||
const surplus = String(cell.surplus ?? '').trim()
|
||||
const amount = String(cell.balance ?? '').trim()
|
||||
if (surplus) detailParts.push(`剩余 IP ${surplus}`)
|
||||
if (amount) detailParts.push(`账户余额 ${amount}`)
|
||||
if (message) detailParts.push(message)
|
||||
const title = detailParts.join(';') || '暂无余量信息'
|
||||
if (!cell.available) {
|
||||
// 后端那句原文(「青果不提供余量查询…」「上游未在预算内应答…」)全在 title 里;
|
||||
// 格子只说「查不了」——留 `—` 会被读成「这人没配代理」,那是另一件事。
|
||||
return { text: message ? '查不了' : `${scopeLabel} ${UNKNOWN_SOURCE_LABEL}`, title }
|
||||
}
|
||||
// 次数就是次数:这里不套 ¥ 符号、不换算,读数带「次」把单位写在格子里
|
||||
return { text: `${scopeLabel} ${surplus || UNKNOWN_SOURCE_LABEL} 次`, title }
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 品牌数据库(不符合ASIN)页 · 像素复刻旧版 admin.html panel-invalid-asin-data(自绘:面板头+新增、筛选、旧式表格/分页、原生 confirm 删除)。
|
||||
* 全平台一份黑名单:分组是行上的归类标签,对任何角色都不构成可见性边界(2026-10-07 定档)。
|
||||
@@ -130,11 +133,22 @@ async function submit() {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.dataValue,
|
||||
deleteOne: (id) => deleteInvalidAsin(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
})
|
||||
|
||||
async function remove(row: InvalidAsinItem) {
|
||||
if (batch.busy) return
|
||||
// 对齐旧版:原生 confirm。
|
||||
if (!(await openAdminConfirm({ message: invalidAsinDeleteText(row), danger: true }))) return
|
||||
try {
|
||||
await deleteInvalidAsin(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -157,17 +171,17 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<div class="form-row invalid-filter-row">
|
||||
<div class="form-group" style="min-width: 200px">
|
||||
<label>ASIN</label>
|
||||
<input v-model="filter.dataValue" type="text" placeholder="输入 ASIN" @keyup.enter="apply" />
|
||||
<div class="form-group">
|
||||
<label for="invalid-asin-filter">ASIN</label>
|
||||
<input id="invalid-asin-filter" v-model="filter.dataValue" type="text" placeholder="输入 ASIN" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 200px">
|
||||
<label>品牌</label>
|
||||
<input v-model="filter.brand" type="text" placeholder="输入品牌" @keyup.enter="apply" />
|
||||
<div class="form-group">
|
||||
<label for="invalid-brand-filter">品牌</label>
|
||||
<input id="invalid-brand-filter" v-model="filter.brand" type="text" placeholder="输入品牌" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 180px">
|
||||
<label>分组</label>
|
||||
<el-select v-model="filter.groupId" class="admin-filter" filterable clearable placeholder="全部分组">
|
||||
<div class="form-group">
|
||||
<label for="invalid-group-filter">分组</label>
|
||||
<el-select id="invalid-group-filter" v-model="filter.groupId" class="admin-filter" filterable clearable placeholder="全部分组">
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
@@ -175,10 +189,15 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll invalid-asin-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 70px">ID</th>
|
||||
<th style="width: 170px">ASIN</th>
|
||||
<th style="width: 150px">品牌</th>
|
||||
@@ -191,7 +210,11 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ row.id }}</td>
|
||||
<td class="mono-cell">{{ row.dataValue }}</td>
|
||||
<td>{{ row.brand || '—' }}</td>
|
||||
@@ -205,15 +228,15 @@ onMounted(() => {
|
||||
<td>{{ formatDateTime(row.updatedAt) }}</td>
|
||||
<td class="ops-cell">
|
||||
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">暂无数据</td>
|
||||
<td colspan="9" class="empty-tip">暂无数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -270,7 +293,7 @@ h3 {
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
@@ -285,13 +308,17 @@ h3 {
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.invalid-filter-row > .form-group {
|
||||
flex: 0 1 190px;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -305,12 +332,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
/* 像素复刻旧版 admin.html panel-dedupe-total-data(蓝白末层样式)。 */
|
||||
.dedupe-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.form-box,
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.dedupe-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-panel-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.dedupe-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.dedupe-filter-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-filter-row .form-group {
|
||||
min-width: 0;
|
||||
}
|
||||
.dedupe-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.dedupe-filter-date-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-filter-date-row .form-group {
|
||||
flex: 0 0 200px;
|
||||
min-width: 0;
|
||||
}
|
||||
.dedupe-filter-date-row .dedupe-filter-actions {
|
||||
margin-left: auto;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
|
||||
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="file"] {
|
||||
background: #ffffff;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.dedupe-table-scroll > table {
|
||||
min-width: 900px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.mono-cell {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(560px, 100%);
|
||||
max-height: 84vh;
|
||||
padding: 22px 24px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.modal .form-group {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.progress-wrap {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.progress-text {
|
||||
font-size: 12.5px;
|
||||
color: #5b6f83;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.dedupe-export-wait-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.dedupe-export-wait {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 22px 28px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.request-spinner {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
flex: none;
|
||||
border: 3px solid #d5e3ef;
|
||||
border-top-color: #5f85ad;
|
||||
border-radius: 50%;
|
||||
animation: dedupe-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes dedupe-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.dedupe-export-wait-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
}
|
||||
.dedupe-export-wait-detail {
|
||||
margin-top: 4px;
|
||||
font-size: 12.5px;
|
||||
color: #5b6f83;
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 数据去重总数据(registry) · 像素复刻旧版 admin.html panel-dedupe-total-data(自绘:分组摘要 + 双行筛选 + 旧式表格/分页 + 编辑/导入弹窗 + 导出等待遮罩)。
|
||||
* script 逻辑沿用现有 Vue 实现(查询/编辑/删除/导入轮询/导出秒表)。 */
|
||||
@@ -70,6 +74,10 @@ const editSaving = ref(false)
|
||||
const editTarget = ref<DedupeTotalItem | null>(null)
|
||||
const editValue = ref('')
|
||||
const editGroupId = ref<number | null>(null)
|
||||
/** 弹窗分组下拉的清空回填值:EP 的 el-select 默认清空写 undefined,会破 editGroupId/importGroupId
|
||||
* 的 `number | null` 契约(下游 saveEdit/importValid 按假值判「未选」、updateDedupeTotal 的入参是 number)
|
||||
* ⇒ 清空一律钉回 null,与旧原生 select 空行(value=null)同语义。 */
|
||||
const nullOnClear = (): null => null
|
||||
|
||||
type ImportMode = 'add' | 'delete'
|
||||
const importVisible = ref(false)
|
||||
@@ -103,13 +111,17 @@ function stopExportWait(): void {
|
||||
exportWaitVisible.value = false
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchDedupeTotalList(
|
||||
toDedupeListParams(filter, page.value, pageSize.value, pendingCursor, companyTab.requestCompanyId),
|
||||
)
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
@@ -117,10 +129,11 @@ async function load(): Promise<void> {
|
||||
pageCursor.value = result.nextLastId ?? null
|
||||
pendingCursor = null
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = loadFailureMessage(error, '去重数据加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,11 +201,23 @@ async function saveEdit(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.dataValue,
|
||||
deleteOne: (id) => deleteDedupeTotal(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
})
|
||||
|
||||
async function removeRow(row: DedupeTotalItem): Promise<void> {
|
||||
if (batch.busy) return
|
||||
// 对齐旧版:浏览器原生 confirm 确认后删除。
|
||||
if (!(await openAdminConfirm({ message: `确定删除总数据“${row.dataValue}”吗?`, danger: true }))) return
|
||||
try {
|
||||
await deleteDedupeTotal(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
await load()
|
||||
} catch (error) {
|
||||
@@ -373,10 +398,14 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in ASIN_COUNTRY_CODES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 与亚马逊面同壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发参数仍是空串=不限);
|
||||
EP 把 '' 当空值 ⇒ 闭壳显示 placeholder,因此同时钉 placeholder="全部国家",视觉不变。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in ASIN_COUNTRY_CODES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="dedupe-filter-actions">
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
@@ -400,10 +429,15 @@ onUnmounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll dedupe-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th>ID</th>
|
||||
<th>ASIN</th>
|
||||
<th>国家</th>
|
||||
@@ -416,7 +450,11 @@ onUnmounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ row.id }}</td>
|
||||
<td class="mono-cell">{{ row.dataValue }}</td>
|
||||
<td>{{ asinCountryLabel(row.country || '') }}</td>
|
||||
@@ -426,15 +464,15 @@ onUnmounted(() => {
|
||||
<td>{{ formatDateTime(row.updatedAt) }}</td>
|
||||
<td class="ops-cell">
|
||||
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeRow(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">暂无总数据</td>
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无总数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -452,10 +490,23 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<select v-model="editGroupId" :disabled="lockedGroupId != null">
|
||||
<option disabled :value="null">请选择分组</option>
|
||||
<option v-for="group in groups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物 ⇒ el-select。
|
||||
「未选」语义:原写法是 disabled 的空行(:value="null",选中后不可回退),这里改成
|
||||
placeholder="请选择分组" + clearable,并用 :value-on-clear 把清空值钉回 null
|
||||
(理由见上方 nullOnClear 注释:EP 默认回 undefined 会破 number | null 契约)。
|
||||
值域仍是 null 或分组 id(number),下游 editGroupId 的假值判断与入参形状不变;
|
||||
非超管单分组时照旧锁定展示(:disabled 与护栏测试钉住的写法一致)。 -->
|
||||
<el-select
|
||||
v-model="editGroupId"
|
||||
class="admin-filter"
|
||||
placeholder="请选择分组"
|
||||
clearable
|
||||
:value-on-clear="nullOnClear"
|
||||
:disabled="lockedGroupId != null"
|
||||
aria-label="编辑分组"
|
||||
>
|
||||
<el-option v-for="group in groups" :key="group.id" :label="group.name" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button class="btn" type="button" :disabled="editSaving" @click="saveEdit">保存</button>
|
||||
@@ -473,10 +524,20 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<select v-model="importGroupId" :disabled="importRunning || lockedGroupId != null">
|
||||
<option disabled :value="null">请选择分组</option>
|
||||
<option v-for="group in groups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物 ⇒ el-select。
|
||||
与编辑弹窗同款「未选」处理(placeholder + clearable + 清空钉回 null),
|
||||
导入锁定条件(importRunning 或单分组)照旧挂在 :disabled 上。 -->
|
||||
<el-select
|
||||
v-model="importGroupId"
|
||||
class="admin-filter"
|
||||
placeholder="请选择分组"
|
||||
clearable
|
||||
:value-on-clear="nullOnClear"
|
||||
:disabled="importRunning || lockedGroupId != null"
|
||||
aria-label="导入分组"
|
||||
>
|
||||
<el-option v-for="group in groups" :key="group.id" :label="group.name" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-if="importProgress" class="progress-wrap">
|
||||
<div class="progress-text">{{ importProgress }}</div>
|
||||
@@ -510,354 +571,4 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html panel-dedupe-total-data(蓝白末层样式)。 */
|
||||
.dedupe-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.form-box,
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.dedupe-panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-panel-head h3 {
|
||||
margin: 0;
|
||||
}
|
||||
.dedupe-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.dedupe-filter-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-filter-row .form-group {
|
||||
min-width: 0;
|
||||
}
|
||||
.dedupe-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.dedupe-filter-date-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.dedupe-filter-date-row .form-group {
|
||||
flex: 0 0 200px;
|
||||
min-width: 0;
|
||||
}
|
||||
.dedupe-filter-date-row .dedupe-filter-actions {
|
||||
margin-left: auto;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="file"] {
|
||||
background: #ffffff;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.dedupe-table-scroll > table {
|
||||
min-width: 900px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.mono-cell {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(560px, 100%);
|
||||
max-height: 84vh;
|
||||
padding: 22px 24px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
overflow-y: auto;
|
||||
}
|
||||
.modal .form-group {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.progress-wrap {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.progress-text {
|
||||
font-size: 12.5px;
|
||||
color: #5b6f83;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.dedupe-export-wait-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.dedupe-export-wait {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 22px 28px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.request-spinner {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
flex: none;
|
||||
border: 3px solid #d5e3ef;
|
||||
border-top-color: #5f85ad;
|
||||
border-radius: 50%;
|
||||
animation: dedupe-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes dedupe-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.dedupe-export-wait-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
}
|
||||
.dedupe-export-wait-detail {
|
||||
margin-top: 4px;
|
||||
font-size: 12.5px;
|
||||
color: #5b6f83;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./DedupeRegistryPage.css"></style>
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
/* 像素复刻旧版 admin.html panel-product-categories(蓝白末层)。 */
|
||||
.category-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.category-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.category-head-tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.category-keyword {
|
||||
width: 240px;
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.category-keyword:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.category-keyword:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.category-table-scroll > table {
|
||||
/* table-layout:fixed 下,没写宽度的列在容器变窄时第一个被压到 0(10-06 截图:层级路径只剩一个字、
|
||||
备注只剩破折号)。承重的是 thead 里 8 列全部显式 px 定宽;这个下限与它们成对维护,
|
||||
数值由 tests/align-product-category.test.ts 从 markup 现算比对,改列宽要同时改这里。 */
|
||||
min-width: 1262px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.tree-name-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 24px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tree-indent {
|
||||
flex: 0 0 auto;
|
||||
display: inline-block;
|
||||
}
|
||||
.tree-node-mark {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: var(--admin-primary-soft, #e7f0f8);
|
||||
color: var(--admin-primary-strong, #2f5d8b);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
flex: none;
|
||||
transition: background 0.12s ease, color 0.12s ease;
|
||||
}
|
||||
.tree-node-mark:not(.is-leaf):hover {
|
||||
background: var(--admin-primary-strong, #2f5d8b);
|
||||
color: #ffffff;
|
||||
}
|
||||
.tree-node-mark.is-leaf {
|
||||
background: transparent;
|
||||
cursor: default;
|
||||
}
|
||||
.node-name {
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.selected-flag {
|
||||
padding: 1px 8px;
|
||||
border-radius: 999px;
|
||||
background: #e7f0f8;
|
||||
color: #2f5d8b;
|
||||
font-size: 11px;
|
||||
}
|
||||
.category-tag {
|
||||
padding: 2px 8px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #c2d5e6;
|
||||
background: #e7f0f8;
|
||||
color: #2f5d8b;
|
||||
font-size: 12px;
|
||||
}
|
||||
.category-tag.is-custom {
|
||||
border-color: #bcd9c6;
|
||||
background: #eef7f0;
|
||||
color: #3d7158;
|
||||
}
|
||||
.category-path-value {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.node-desc {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 320px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.dim {
|
||||
color: #8293a5;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.load-more-row td {
|
||||
background: #fbfdfe;
|
||||
}
|
||||
.load-more-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.loaded-count {
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
/** 商品类目 · 像素复刻旧版 admin.html panel-product-categories(自绘:面板头搜索框组+新增类目 同行、原生树表格[+/−]折叠+懒加载「加载更多 已加载 x/y」、搜索态旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(懒加载树/编辑删除/导出/弹窗)。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
@@ -257,7 +260,21 @@ function canDelete(node: ProductCategoryNode | null): boolean {
|
||||
return !(node.childCount > 0 || (Array.isArray(node.children) && node.children.some((child) => !isCategoryLoadMoreNode(child))))
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => searching.value ? searchRows.value : treeRows.value.map(({ node }) => node),
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.path || row.name,
|
||||
deleteOne: async (id) => {
|
||||
await deleteProductCategory(id)
|
||||
if (selected.value?.id === id) selected.value = null
|
||||
},
|
||||
refresh: () => searching.value ? runSearch(1) : loadTree(),
|
||||
blocked: () => loading.value || searchLoading.value || saving.value,
|
||||
precheck: (row) => canDelete(row) ? undefined : '存在子类目,不能删除',
|
||||
})
|
||||
|
||||
async function removeCategory(node: ProductCategoryNode): Promise<void> {
|
||||
if (batch.busy) return
|
||||
if (!canDelete(node)) {
|
||||
ElMessage.warning('存在子类目,不能删除')
|
||||
return
|
||||
@@ -266,6 +283,7 @@ async function removeCategory(node: ProductCategoryNode): Promise<void> {
|
||||
if (!(await openAdminConfirm({ message: `确定删除“${node.name}”?`, danger: true }))) return
|
||||
try {
|
||||
await deleteProductCategory(node.id)
|
||||
batch.removeFromSelection(node.id)
|
||||
ElMessage.success('已删除')
|
||||
if (selected.value?.id === node.id) selected.value = null
|
||||
if (searching.value) void runSearch(1)
|
||||
@@ -318,7 +336,7 @@ onMounted(loadTree)
|
||||
<section class="panel-box">
|
||||
<div class="category-head">
|
||||
<h3>商品类目</h3>
|
||||
<div class="category-head-tools">
|
||||
<div class="category-head-tools admin-header-controls">
|
||||
<input v-model="keyword" type="text" placeholder="搜索类目名称、编码或备注" class="category-keyword" @keyup.enter="apply" />
|
||||
<button class="btn btn-sm" type="button" @click="apply">搜索</button>
|
||||
<button class="btn btn-sm btn-secondary" type="button" @click="reset">清空</button>
|
||||
@@ -329,10 +347,15 @@ onMounted(loadTree)
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadTree" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll category-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col" style="width: 38px">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 220px">类目</th>
|
||||
<th style="width: 230px">层级路径</th>
|
||||
<th style="width: 66px">排序</th>
|
||||
@@ -347,7 +370,7 @@ onMounted(loadTree)
|
||||
<template v-if="treeRows.length">
|
||||
<template v-for="row in treeRows" :key="String(row.node.id)">
|
||||
<tr v-if="isCategoryLoadMoreNode(row.node)" class="load-more-row">
|
||||
<td colspan="8">
|
||||
<td colspan="9">
|
||||
<div class="load-more-cell">
|
||||
<span class="tree-indent" :style="{ width: `${(row.depth + 1) * 24}px` }"></span>
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="moreLoading(row.node)" @click="loadMoreChildren(row.node)">
|
||||
@@ -357,7 +380,11 @@ onMounted(loadTree)
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<tr v-else :class="{ 'batch-selected': batch.isSelected(row.node) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row.node) || `选择 ${batch.label(row.node)}`" :checked="batch.isSelected(row.node)"
|
||||
:disabled="batch.disabled || !!batch.reason(row.node)" @change="batch.toggle(row.node)" />
|
||||
</td>
|
||||
<td>
|
||||
<div class="tree-name-cell" @click="onNodeClick(row.node)">
|
||||
<span class="tree-indent" :style="{ width: `${row.depth * 24}px` }"></span>
|
||||
@@ -393,7 +420,7 @@ onMounted(loadTree)
|
||||
<button
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="!canDelete(row.node)"
|
||||
:disabled="batch.busy || !canDelete(row.node)"
|
||||
:title="!canDelete(row.node) ? '存在子类目,不能删除' : undefined"
|
||||
@click="removeCategory(row.node)"
|
||||
>
|
||||
@@ -404,15 +431,19 @@ onMounted(loadTree)
|
||||
</template>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">暂无商品类目</td>
|
||||
<td colspan="9" class="empty-tip">暂无商品类目</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody v-else>
|
||||
<template v-if="searchRows.length">
|
||||
<tr v-for="row in searchRows" :key="row.id">
|
||||
<tr v-for="row in searchRows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td><strong class="node-name">{{ row.name }}</strong></td>
|
||||
<td><span class="category-path-value" :title="row.path || row.name">{{ row.path || row.name }}</span></td>
|
||||
<td>{{ row.sortOrder ?? '—' }}</td>
|
||||
@@ -430,7 +461,7 @@ onMounted(loadTree)
|
||||
<button
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="!canDelete(row)"
|
||||
:disabled="batch.busy || !canDelete(row)"
|
||||
:title="!canDelete(row) ? '存在子类目,不能删除' : undefined"
|
||||
@click="removeCategory(row)"
|
||||
>
|
||||
@@ -440,10 +471,10 @@ onMounted(loadTree)
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="searchLoading">
|
||||
<td colspan="8" class="empty-tip">搜索中...</td>
|
||||
<td colspan="9" class="empty-tip">搜索中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">暂无搜索结果</td>
|
||||
<td colspan="9" class="empty-tip">暂无搜索结果</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -483,292 +514,4 @@ onMounted(loadTree)
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html panel-product-categories(蓝白末层)。 */
|
||||
.category-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.category-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.category-head-tools {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.category-keyword {
|
||||
width: 240px;
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.category-keyword:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.category-keyword:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.category-table-scroll > table {
|
||||
/* table-layout:fixed 下,没写宽度的列在容器变窄时第一个被压到 0(10-06 截图:层级路径只剩一个字、
|
||||
备注只剩破折号)。承重的是 thead 里 8 列全部显式 px 定宽;这个下限与它们成对维护,
|
||||
数值由 tests/align-product-category.test.ts 从 markup 现算比对,改列宽要同时改这里。 */
|
||||
min-width: 1224px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.tree-name-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 24px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tree-indent {
|
||||
flex: 0 0 auto;
|
||||
display: inline-block;
|
||||
}
|
||||
.tree-node-mark {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: var(--admin-primary-soft, #e7f0f8);
|
||||
color: var(--admin-primary-strong, #2f5d8b);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
flex: none;
|
||||
transition: background 0.12s ease, color 0.12s ease;
|
||||
}
|
||||
.tree-node-mark:not(.is-leaf):hover {
|
||||
background: var(--admin-primary-strong, #2f5d8b);
|
||||
color: #ffffff;
|
||||
}
|
||||
.tree-node-mark.is-leaf {
|
||||
background: transparent;
|
||||
cursor: default;
|
||||
}
|
||||
.node-name {
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.selected-flag {
|
||||
padding: 1px 8px;
|
||||
border-radius: 999px;
|
||||
background: #e7f0f8;
|
||||
color: #2f5d8b;
|
||||
font-size: 11px;
|
||||
}
|
||||
.category-tag {
|
||||
padding: 2px 8px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #c2d5e6;
|
||||
background: #e7f0f8;
|
||||
color: #2f5d8b;
|
||||
font-size: 12px;
|
||||
}
|
||||
.category-tag.is-custom {
|
||||
border-color: #bcd9c6;
|
||||
background: #eef7f0;
|
||||
color: #3d7158;
|
||||
}
|
||||
.category-path-value {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.node-desc {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 320px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.dim {
|
||||
color: #8293a5;
|
||||
}
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.load-more-row td {
|
||||
background: #fbfdfe;
|
||||
}
|
||||
.load-more-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.loaded-count {
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./ProductCategoryPage.css"></style>
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
/* 像素复刻旧版 admin.html panel-query-asin(蓝白末层)。 */
|
||||
.query-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.query-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.query-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.query-filter-row > .form-group {
|
||||
flex: 1 1 140px;
|
||||
min-width: 0;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
|
||||
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.query-asin-table-scroll > table {
|
||||
min-width: 860px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.table-scroll td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.asin-cell {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
margin: -3px 0 -3px -7px;
|
||||
padding: 3px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1.5;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
}
|
||||
.asin-cell:hover {
|
||||
border-color: #c7d7e5;
|
||||
background: #eef4fa;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.asin-empty {
|
||||
color: #8b9aaa;
|
||||
}
|
||||
.asin-col-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
/* 与最低价 ASIN 同形:列宽已从 9% 改成 140px 下限,再补 wrap 兜住文案变长的情况,
|
||||
让"超宽"从"按钮静默消失"退化成"多占一行"。 */
|
||||
flex-wrap: wrap;
|
||||
background: #ffffff;
|
||||
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.drawer-tip {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.import-tip {
|
||||
margin: 6px 0 0;
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
/** 查询 ASIN · 像素复刻旧版 admin.html panel-query-asin(自绘:面板头操作组、筛选+导出 XLSX、原生 rowspan 表格+可复制 ASIN、旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(新增级联/配置抽屉/导入轮询/导出)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -71,13 +75,37 @@ function normalizeAsinInput(country: string): void {
|
||||
}
|
||||
|
||||
|
||||
// 同一家店铺部分站点删除成功后,重试只发未完成的站点。
|
||||
const pendingCountries = new WeakMap<QueryAsinItem, Set<(typeof QUERY_ASIN_COUNTRIES)[number]>>()
|
||||
|
||||
async function deleteShopCountries(item: QueryAsinItem, isCurrent: () => boolean = () => true) {
|
||||
const pending = pendingCountries.get(item) ?? new Set(QUERY_ASIN_COUNTRIES.filter((country) => asinOf(item, country)))
|
||||
pendingCountries.set(item, pending)
|
||||
for (const country of pending) {
|
||||
if (!isCurrent()) throw new Error('列表范围已切换,店铺剩余站点未删除')
|
||||
await deleteQueryAsinCountryAsin(item.id, country)
|
||||
pending.delete(country)
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.groupName ? `${row.shopName}(${row.groupName})` : row.shopName,
|
||||
deleteOne: (_id, row, isCurrent) => deleteShopCountries(row, isCurrent),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
consequence: '将删除所选店铺全部站点的 ASIN 配置,此操作不可恢复。',
|
||||
})
|
||||
|
||||
async function removeShopAsin(item: QueryAsinItem) {
|
||||
if (batch.busy) return
|
||||
// 删除该店铺全部站点的 ASIN 配置(逐国调用现有端点)。
|
||||
if (!(await openAdminConfirm({ message: `确定删除店铺“${item.shopName}”的全部站点 ASIN 配置吗?`, danger: true }))) return
|
||||
try {
|
||||
for (const country of QUERY_ASIN_COUNTRIES) {
|
||||
if (asinOf(item, country)) await deleteQueryAsinCountryAsin(item.id, country)
|
||||
}
|
||||
await deleteShopCountries(item)
|
||||
batch.removeFromSelection(item.id)
|
||||
ElMessage.success('已删除')
|
||||
await load()
|
||||
} catch (error) {
|
||||
@@ -300,7 +328,10 @@ async function loadGroups() {
|
||||
}
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
@@ -313,14 +344,16 @@ async function load() {
|
||||
country: filter.country || undefined,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
page.value = result.page
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '数据加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,10 +420,14 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in QUERY_ASIN_COUNTRIES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(与上面分组同一套 admin-filter 壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发仍是空串=不限);
|
||||
EP 把 '' 视作空值 ⇒ 闭壳走 placeholder,因此同步钉 placeholder="全部国家" 保持文案。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in QUERY_ASIN_COUNTRIES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ASIN</label>
|
||||
@@ -401,10 +438,15 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll query-asin-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 6%">序号</th>
|
||||
<th v-if="isSuperAdmin" style="width: 13%">分组</th>
|
||||
<th style="width: 15%">店铺名</th>
|
||||
@@ -417,8 +459,12 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="displayRows.length">
|
||||
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`">
|
||||
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`" :class="{ 'batch-selected': batch.isSelected(row.item) }">
|
||||
<template v-if="row.isFirst">
|
||||
<td class="batch-delete-cell" :rowspan="row.rowspan">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row.item) || `选择 ${batch.label(row.item)}`" :checked="batch.isSelected(row.item)"
|
||||
:disabled="batch.disabled || !!batch.reason(row.item)" @change="batch.toggle(row.item)" />
|
||||
</td>
|
||||
<td :rowspan="row.rowspan">{{ row.rowNo }}</td>
|
||||
<td v-if="isSuperAdmin" :rowspan="row.rowspan">{{ row.item.groupName || '—' }}</td>
|
||||
<td :rowspan="row.rowspan">{{ row.item.shopName }}</td>
|
||||
@@ -435,16 +481,16 @@ onMounted(() => {
|
||||
<td :rowspan="row.rowspan">{{ formatDateTime(row.item.updatedAt) }}</td>
|
||||
<td :rowspan="row.rowspan" class="asin-col-actions">
|
||||
<button class="btn btn-sm" type="button" @click="openConfig(row.item as QueryAsinItem)">配置</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="removeShopAsin(row.item as QueryAsinItem)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeShopAsin(row.item as QueryAsinItem)">删除</button>
|
||||
</td>
|
||||
</template>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">暂无数据</td>
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -527,278 +573,4 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html panel-query-asin(蓝白末层)。 */
|
||||
.query-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.query-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.query-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.query-filter-row > .form-group {
|
||||
flex: 1 1 140px;
|
||||
min-width: 0;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.query-asin-table-scroll > table {
|
||||
min-width: 860px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.table-scroll td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.asin-cell {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
margin: -3px 0 -3px -7px;
|
||||
padding: 3px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1.5;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
}
|
||||
.asin-cell:hover {
|
||||
border-color: #c7d7e5;
|
||||
background: #eef4fa;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.asin-empty {
|
||||
color: #8b9aaa;
|
||||
}
|
||||
.asin-col-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
/* 与最低价 ASIN 同形:列宽已从 9% 改成 140px 下限,再补 wrap 兜住文案变长的情况,
|
||||
让"超宽"从"按钮静默消失"退化成"多占一行"。 */
|
||||
flex-wrap: wrap;
|
||||
background: #ffffff;
|
||||
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.drawer-tip {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.import-tip {
|
||||
margin: 6px 0 0;
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./QueryAsinPage.css"></style>
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
/* 像素复刻旧版 admin.html panel-skip-price-asin(蓝白末层)。 */
|
||||
.skip-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.skip-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.skip-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.skip-filter-row > .form-group {
|
||||
flex: 1 1 130px;
|
||||
min-width: 0;
|
||||
}
|
||||
.skip-filter-row .form-group.price-range {
|
||||
flex: 1 1 220px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
|
||||
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.price-range-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
.price-range-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.price-range-row .range-sep {
|
||||
color: #8293a5;
|
||||
flex: none;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.skip-price-asin-table-scroll > table {
|
||||
min-width: 900px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.table-scroll td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.asin-cell {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
margin: -3px 0 -3px -7px;
|
||||
padding: 3px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1.5;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
}
|
||||
.asin-cell:hover {
|
||||
border-color: #c7d7e5;
|
||||
background: #eef4fa;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.asin-empty {
|
||||
color: #8b9aaa;
|
||||
}
|
||||
.price-cell {
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.asin-col-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
/* 列宽已从 9% 改成 140px 下限(两字按钮 53×2 + gap 8 + td 左右 padding 24 = 138)。
|
||||
百分比会跟着容器一起缩,配上 justify-content:flex-end 后溢出翻到左侧,
|
||||
"配置"整颗被吃掉而"删除"看着完好——2026-10-08 那单截图就是这个形状。 */
|
||||
flex-wrap: wrap;
|
||||
background: #ffffff;
|
||||
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.drawer-tip {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.country-cell {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
.import-tip {
|
||||
margin: 6px 0 0;
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
/** 最低价 ASIN(跳过跟价)· 像素复刻旧版 admin.html panel-skip-price-asin(自绘:面板头操作组、筛选(分组/店铺/国家/ASIN/最低价≥≤)+导出 XLSX、原生 rowspan 表格、旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(新增级联+最低价、配置抽屉双列、导入轮询、导出)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
@@ -225,7 +229,19 @@ async function saveConfig(): Promise<void> {
|
||||
}
|
||||
|
||||
// ---- 整条删除 ----
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.groupName ? `${row.shopName}(${row.groupName})` : row.shopName,
|
||||
deleteOne: (id) => deleteSkipPriceAsin(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
consequence: '将删除所选店铺全部站点的最低价 ASIN 配置,此操作不可恢复。',
|
||||
})
|
||||
|
||||
async function removeRow(item: SkipPriceItem): Promise<void> {
|
||||
if (batch.busy) return
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定删除「${item.shopName}」${item.groupName ? `(${item.groupName})` : ''}全部站点的最低价 ASIN 配置吗?`,
|
||||
@@ -237,6 +253,7 @@ async function removeRow(item: SkipPriceItem): Promise<void> {
|
||||
}
|
||||
try {
|
||||
await deleteSkipPriceAsin(item.id)
|
||||
batch.removeFromSelection(item.id)
|
||||
ElMessage.success('删除成功')
|
||||
// 删除后当前页若已空且非首页,回退一页避免展示空页。
|
||||
if (rows.value.length === 1 && page.value > 1) {
|
||||
@@ -353,19 +370,24 @@ async function loadGroups() {
|
||||
}
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchSkipPriceList(toSkipPriceParams(filter, page.value, pageSize.value, companyTab.requestCompanyId))
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
page.value = result.page
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '数据加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,10 +454,14 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in COUNTRIES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(与上面分组同一套 admin-filter 壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发仍是空串=不限);
|
||||
EP 把 '' 视作空值 ⇒ 闭壳走 placeholder,因此同步钉 placeholder="全部国家" 保持文案。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in COUNTRIES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ASIN</label>
|
||||
@@ -454,10 +480,15 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll skip-price-asin-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 6%">序号</th>
|
||||
<th v-if="isSuperAdmin" style="width: 13%">分组</th>
|
||||
<th style="width: 15%">店铺名</th>
|
||||
@@ -471,8 +502,12 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="displayRows.length">
|
||||
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`">
|
||||
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`" :class="{ 'batch-selected': batch.isSelected(row.item) }">
|
||||
<template v-if="row.isFirst">
|
||||
<td class="batch-delete-cell" :rowspan="row.rowspan">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row.item) || `选择 ${batch.label(row.item)}`" :checked="batch.isSelected(row.item)"
|
||||
:disabled="batch.disabled || !!batch.reason(row.item)" @change="batch.toggle(row.item)" />
|
||||
</td>
|
||||
<td :rowspan="row.rowspan">{{ row.rowNo }}</td>
|
||||
<td v-if="isSuperAdmin" :rowspan="row.rowspan">{{ row.item.groupName || '—' }}</td>
|
||||
<td :rowspan="row.rowspan">{{ row.item.shopName }}</td>
|
||||
@@ -490,16 +525,16 @@ onMounted(() => {
|
||||
<td :rowspan="row.rowspan">{{ formatDateTime(row.item.updatedAt) }}</td>
|
||||
<td :rowspan="row.rowspan" class="asin-col-actions">
|
||||
<button class="btn btn-sm" type="button" @click="openConfig(row.item as SkipPriceItem)">配置</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row.item as SkipPriceItem)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeRow(row.item as SkipPriceItem)">删除</button>
|
||||
</td>
|
||||
</template>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无数据</td>
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">暂无数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -588,306 +623,4 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html panel-skip-price-asin(蓝白末层)。 */
|
||||
.skip-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.skip-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.skip-head-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.skip-filter-row > .form-group {
|
||||
flex: 1 1 130px;
|
||||
min-width: 0;
|
||||
}
|
||||
.skip-filter-row .form-group.price-range {
|
||||
flex: 1 1 220px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.price-range-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
.price-range-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.price-range-row .range-sep {
|
||||
color: #8293a5;
|
||||
flex: none;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
.skip-price-asin-table-scroll > table {
|
||||
min-width: 900px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.table-scroll td {
|
||||
vertical-align: top;
|
||||
}
|
||||
.asin-cell {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
margin: -3px 0 -3px -7px;
|
||||
padding: 3px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font-size: 13.5px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1.5;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
}
|
||||
.asin-cell:hover {
|
||||
border-color: #c7d7e5;
|
||||
background: #eef4fa;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.asin-empty {
|
||||
color: #8b9aaa;
|
||||
}
|
||||
.price-cell {
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.asin-col-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
/* 列宽已从 9% 改成 140px 下限(两字按钮 53×2 + gap 8 + td 左右 padding 24 = 138)。
|
||||
百分比会跟着容器一起缩,配上 justify-content:flex-end 后溢出翻到左侧,
|
||||
"配置"整颗被吃掉而"删除"看着完好——2026-10-08 那单截图就是这个形状。 */
|
||||
flex-wrap: wrap;
|
||||
background: #ffffff;
|
||||
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.pagination button {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.page-jump input {
|
||||
width: 56px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.drawer-tip {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.country-cell {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
.import-tip {
|
||||
margin: 6px 0 0;
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./SkipPricePage.css"></style>
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
<script setup lang="ts">
|
||||
/** 批量编辑分类对话框(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
* 京东数据库页勾选商品(翻页累计,由页面持有勾选集)→ 本对话框选目标分类或移出分类 →
|
||||
* 一次批量归类。归属写「本组」的归属行(biz_jd_product_group_assign,V203 一组一商品一行),
|
||||
* 归类不置人工编辑锁(采集照常更新价格/库存)。本组无分类时只有提示不给提交
|
||||
* (移出对未分类行是无谓操作),引导去工具栏「分类管理」新建(2026-11-17 独立页并回本页)。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { batchAssignJdProductGroup, type JdProductGroup } from './jd-product-api.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 当前数据权限分组(归类的落点组;V203 同一商品在其他组可另归一类)。 */
|
||||
ownerGroupId: number
|
||||
ownerGroupName: string
|
||||
/** 当前分组的分类选项(含商品数徽标;由页面在打开时刷新)。 */
|
||||
categories: JdProductGroup[]
|
||||
/** 页面持有的勾选集(跨页累计),展开成 id 数组传入。 */
|
||||
selectedIds: number[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', updated: number, targetName: string | null): void }>()
|
||||
|
||||
/** 选中的目标分类 id;0=移出分类(回到未分类)。 */
|
||||
const pickedId = ref(0)
|
||||
const assigning = ref(false)
|
||||
const errorText = ref('')
|
||||
|
||||
const picked = computed(() => props.categories.find((group) => group.id === pickedId.value) || null)
|
||||
const confirmText = computed(() => (picked.value ? `归入「${picked.value.name}」` : '移出分类'))
|
||||
/** 提交条件:有勾选、未在提交中,且选了目标分类(pickedId>0)或选了移出(pickedId=0,
|
||||
* 但本组得有分类可移——全组无分类时移出是无谓操作,整对话框只留提示)。 */
|
||||
const canSubmit = computed(() => props.selectedIds.length > 0 && !assigning.value
|
||||
&& (picked.value ? true : props.categories.length > 0))
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
pickedId.value = 0
|
||||
errorText.value = ''
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (!canSubmit.value) return
|
||||
const target = picked.value
|
||||
assigning.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
// target null=移出分类(groupId 传 null,后端只解挂本组归属行)。
|
||||
const updated = await batchAssignJdProductGroup(
|
||||
props.selectedIds,
|
||||
target ? target.id : null,
|
||||
props.ownerGroupId,
|
||||
)
|
||||
emit('done', updated, target ? target.name : null)
|
||||
emit('close')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '批量归类失败'
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="batch-modal">
|
||||
<div class="modal-head">
|
||||
<h3>批量编辑分类<span v-if="ownerGroupName" class="modal-sub">· {{ ownerGroupName }}</span></h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
已勾选 {{ selectedIds.length }} 个商品(翻页累计)。选目标分类后确认;
|
||||
归类只记在分类归属上,不影响采集对价格/库存的更新。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<div v-if="!categories.length" class="batch-empty">本组暂无分类,先用工具栏「分类管理」新建一个</div>
|
||||
<ul v-else class="option-list">
|
||||
<li
|
||||
v-for="group in categories"
|
||||
:key="group.id"
|
||||
class="option-row"
|
||||
:class="{ active: pickedId === group.id }"
|
||||
@click="pickedId = group.id"
|
||||
>
|
||||
<span class="option-radio" aria-hidden="true"></span>
|
||||
<span class="option-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="option-meta">{{ group.productCount }}</span>
|
||||
</li>
|
||||
<li class="option-row option-detach" :class="{ active: pickedId === 0 }" @click="pickedId = 0">
|
||||
<span class="option-radio" aria-hidden="true"></span>
|
||||
<span class="option-name">移出分类</span>
|
||||
<span class="option-meta">回到未分类</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
|
||||
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
|
||||
{{ assigning ? '提交中...' : confirmText }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.batch-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(430px, 100%);
|
||||
max-height: 80vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.modal-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-sub {
|
||||
margin-left: 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.modal-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.modal-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-tip {
|
||||
margin: 8px 0 10px;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.batch-empty {
|
||||
padding: 26px 12px;
|
||||
border: 1px dashed #cbd9e6;
|
||||
border-radius: 10px;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
.option-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #e7eef5;
|
||||
}
|
||||
.option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 8px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.option-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 点亮=归类目标:与旧弹窗左栏同款左缘蓝条。 */
|
||||
.option-row.active {
|
||||
background: #e8f1fa;
|
||||
box-shadow: inset 3px 0 0 #4f78a5;
|
||||
}
|
||||
.option-radio {
|
||||
flex: none;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 1.6px solid #9fb7cd;
|
||||
border-radius: 50%;
|
||||
background: #ffffff;
|
||||
}
|
||||
.option-row.active .option-radio {
|
||||
border-color: #4f78a5;
|
||||
background: radial-gradient(circle, #4f78a5 0 4px, #ffffff 4.6px);
|
||||
}
|
||||
.option-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.option-detach .option-name {
|
||||
color: #a04432;
|
||||
}
|
||||
.option-meta {
|
||||
flex: none;
|
||||
min-width: 22px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #eef4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.option-detach .option-meta {
|
||||
background: transparent;
|
||||
color: #8293a5;
|
||||
}
|
||||
.modal-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,639 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
/** 分类管理对话框(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里,
|
||||
* 做一个搜索和添加 删除 编辑 分类名称即可」):原 V204 独立子菜单页(JdCategoryManagerPage)
|
||||
* 整体并入本对话框,从京东数据库页工具栏「分类管理」打开。
|
||||
* 职责不变:当前数据权限分组的分类建/改名/删除+新增的名称搜索;商品归类不在这里
|
||||
* (去「批量编辑分类」)。列表状态自管理(写操作后自刷新并 emit changed 让父页刷筛选下拉)。
|
||||
* 权限口径(V203)不变:本组管理员/公司超管/平台超管可写(editable);同组普通号
|
||||
* 只读可看(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。
|
||||
* 2026-11-17 晚用户口径「admin 权限最大」:京东侧还没有任何数据权限分组时(平台闸
|
||||
* 上线后 jd 档组全空),平台超管在本弹窗空态直建第一个京东档分组(组长=自己),
|
||||
* 建完 emit group-created 让父页重取作用域,当前分组翻到新组后接着就能建分类,
|
||||
* 不再死在「你还不属于任何数据权限分组」。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
fetchJdProductGroups,
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import { createShopGroup } from '../account/shop-group-api.ts'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 当前数据权限分组(分类的作用域;<=0=不属于任何分组,只留空态)。 */
|
||||
ownerGroupId: number
|
||||
ownerGroupName: string
|
||||
/** 当前分组可写(scope 的 editable):建/改名/删除控件全挂它。 */
|
||||
editable: boolean
|
||||
/** 操作者是否平台超管(scope 原样透传):只在「还没有分组」的空态开直建口子。 */
|
||||
platformSuperAdmin?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void; (event: 'group-created'): void }>()
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
|
||||
const loading = ref(false)
|
||||
/** 首屏取数失败(可见红条+重试);写操作失败走 errorText 红条(无重试语义)。 */
|
||||
const loadFailure = ref('')
|
||||
const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 搜索:按分类名称包含过滤(本地过滤,不另发请求)。 */
|
||||
const keyword = ref('')
|
||||
/** 分页(2026-11-17 用户口径「分类这也要加分页」):分类与父页「分类」下拉共用同一条全量
|
||||
* 接口(下拉必须全量,不能分页),所以这里做本地切片;搜索同样是本地过滤 ⇒ 分页与搜索
|
||||
* 同源,不会出现「先 limit 再过滤」那种翻页永久漏项。每页 6 行:实测 8 行在 700px 高的
|
||||
* 视口里会顶出列表内滚动条(滚动条与页码条并存很难看),6 行矮屏也一屏放得下。 */
|
||||
const PAGE_SIZE = 6
|
||||
const pageNo = ref(1)
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
/** 改名:正在编辑的分类 id 与草稿名。 */
|
||||
const editingId = ref(0)
|
||||
const editingName = ref('')
|
||||
const saving = ref(false)
|
||||
|
||||
const canCreate = computed(() => props.editable && createName.value.trim().length > 0 && !creating.value && !saving.value)
|
||||
/** 搜索命中(名称包含,大小写不敏感;空关键字=全量)。 */
|
||||
const filteredGroups = computed(() => {
|
||||
const kw = keyword.value.trim().toLowerCase()
|
||||
if (!kw) return groups.value
|
||||
return groups.value.filter((group) => group.name.toLowerCase().includes(kw))
|
||||
})
|
||||
/** 总页数(至少 1 页:空列表时页码条不渲染,但钳制逻辑要有个有效上界)。 */
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(filteredGroups.value.length / PAGE_SIZE)))
|
||||
/** 当前页的行(在搜索命中集上切片)。 */
|
||||
const pagedGroups = computed(() => {
|
||||
const start = (pageNo.value - 1) * PAGE_SIZE
|
||||
return filteredGroups.value.slice(start, start + PAGE_SIZE)
|
||||
})
|
||||
/** 只有超过一页才出页码条:一屏装得下时不白占一行。 */
|
||||
const showPager = computed(() => filteredGroups.value.length > PAGE_SIZE)
|
||||
|
||||
/** 翻页:页码钳在 [1, totalPages](删除/搜索后越界不会翻到空白页)。 */
|
||||
function goPage(target: number): void {
|
||||
pageNo.value = Math.min(Math.max(1, target), totalPages.value)
|
||||
}
|
||||
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。
|
||||
* 平台超管的「还没有分组」空态不走这里——模板换成直建分组的表单(canBootstrapGroup)。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
|
||||
if (!groups.value.length) {
|
||||
return props.editable ? '本组暂无分类,先新建一个' : '本组暂无分类'
|
||||
}
|
||||
return '没有匹配的分类'
|
||||
})
|
||||
|
||||
/** 空态直建分组的口子(2026-11-17 用户口径「admin 权限最大」):平台超管 + 还没有任何
|
||||
* 可见分组时才开。组员/翻档等完整分组管理仍归「分组管理」页,这里只解决「从 0 到 1」。 */
|
||||
const canBootstrapGroup = computed(() => props.platformSuperAdmin === true && props.ownerGroupId <= 0)
|
||||
/** 直建表单:只收名称;组长=当前操作者,platform 恒 'jd'(京东侧作用域只认 jd 档)。 */
|
||||
const newGroupName = ref('')
|
||||
const creatingGroup = ref(false)
|
||||
const canCreateGroup = computed(() =>
|
||||
canBootstrapGroup.value && newGroupName.value.trim().length > 0 && !creatingGroup.value)
|
||||
|
||||
/** 平台超管空态直建第一个京东档分组:走分组管理同一条 POST(shop-manages/groups),
|
||||
* 组长=当前操作者、组员先空。成功后 emit group-created 让父页整条作用域重取——
|
||||
* ownerGroupId 翻到新组后由下方 watch 接手按新组重取分类,操作者接着就能建分类。 */
|
||||
async function submitCreateGroup(): Promise<void> {
|
||||
const name = newGroupName.value.trim()
|
||||
if (!name || creatingGroup.value || !canBootstrapGroup.value) return
|
||||
const operatorId = session.user?.id ?? 0
|
||||
if (!operatorId) {
|
||||
errorText.value = '无法获取当前登录用户,请重新登录'
|
||||
return
|
||||
}
|
||||
creatingGroup.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createShopGroup(name, [], operatorId, 'jd')
|
||||
newGroupName.value = ''
|
||||
showAdminFeedback(`已新建京东档分组「${name}」`, 'success')
|
||||
emit('group-created')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分组失败'
|
||||
} finally {
|
||||
creatingGroup.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
if (props.ownerGroupId <= 0) {
|
||||
groups.value = []
|
||||
loading.value = false
|
||||
loadFailure.value = ''
|
||||
errorText.value = ''
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
groups.value = await fetchJdProductGroups(props.ownerGroupId)
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '分类列表加载失败')
|
||||
groups.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitCreate(): Promise<void> {
|
||||
const name = createName.value.trim()
|
||||
if (!name || creating.value || !props.editable) return
|
||||
creating.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0, ownerGroupId: props.ownerGroupId })
|
||||
createName.value = ''
|
||||
keyword.value = ''
|
||||
showAdminFeedback(`已新建分类「${name}」`, 'success')
|
||||
emit('changed')
|
||||
await loadGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分类失败'
|
||||
} finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startRename(group: JdProductGroup): void {
|
||||
editingId.value = group.id
|
||||
editingName.value = group.name
|
||||
errorText.value = ''
|
||||
}
|
||||
|
||||
function cancelRename(): void {
|
||||
editingId.value = 0
|
||||
editingName.value = ''
|
||||
}
|
||||
|
||||
async function submitRename(group: JdProductGroup): Promise<void> {
|
||||
const name = editingName.value.trim()
|
||||
if (!name || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||
groups.value = groups.value.map((item) => (item.id === group.id ? { ...item, name } : item))
|
||||
cancelRename()
|
||||
showAdminFeedback(`已把分类改名为「${name}」`, 'success')
|
||||
emit('changed')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除分类不删商品:只解挂本组归属行(商品回到未分类),后端 JdProductGroupService.delete。 */
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => pagedGroups.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.name,
|
||||
deleteOne: (id) => deleteJdProductGroup(id),
|
||||
refresh: async (outcome) => {
|
||||
if (outcome.deleted.length) emit('changed')
|
||||
await loadGroups()
|
||||
},
|
||||
blocked: () => !props.visible || !props.editable || loading.value || saving.value || creating.value || !!editingId.value || !!loadFailure.value,
|
||||
scope: () => [props.visible, props.ownerGroupId, props.editable],
|
||||
consequence: '分类下的商品将回到未分类,商品本身不会被删除。',
|
||||
})
|
||||
|
||||
async function removeGroup(group: JdProductGroup): Promise<void> {
|
||||
if (batch.busy) return
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?删除后该分类下 ${group.productCount} 个商品回到未分类。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok || saving.value) return
|
||||
saving.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await deleteJdProductGroup(group.id)
|
||||
batch.removeFromSelection(group.id)
|
||||
showAdminFeedback(`已删除分类「${group.name}」`, 'success')
|
||||
emit('changed')
|
||||
await loadGroups()
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '删除分类失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
keyword.value = ''
|
||||
errorText.value = ''
|
||||
loadFailure.value = ''
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
newGroupName.value = ''
|
||||
pageNo.value = 1
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
// immediate:对话框可能以 visible=true 直接挂载(测试/复用场景),这时也要首取。
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 建组成功后父页重取作用域会把 ownerGroupId 翻到新组:按新组重取分类列表,
|
||||
* 操作者不用关弹窗重开就能接着建分类。 */
|
||||
watch(
|
||||
() => props.ownerGroupId,
|
||||
(next, prev) => {
|
||||
if (next > 0 && next !== prev) void loadGroups()
|
||||
},
|
||||
)
|
||||
|
||||
/** 改关键字回第一页(命中集变了,停在旧页码会落在空白处)。 */
|
||||
watch(keyword, () => {
|
||||
pageNo.value = 1
|
||||
})
|
||||
/** 命中集变少(删掉最后一条/搜索收窄)后把越界页码钳回最后一页。 */
|
||||
watch(totalPages, (pages) => {
|
||||
if (pageNo.value > pages) pageNo.value = pages
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="manage-modal">
|
||||
<div class="modal-head">
|
||||
<h3>分类管理</h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
|
||||
<div class="manage-bar">
|
||||
<input v-model="keyword" class="search-input" type="text" placeholder="搜索分类名称" aria-label="搜索分类名称" />
|
||||
<div v-if="editable" class="group-create">
|
||||
<input v-model="createName" type="text" placeholder="输入新分类名称" aria-label="新分类名称" @keyup.enter="submitCreate" />
|
||||
<button class="btn" type="button" :disabled="batch.busy || !canCreate" @click="submitCreate">新建</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<BatchDeleteActions v-if="editable" :batch="batch" />
|
||||
|
||||
<!-- 表头(2026-11-18 用户红框口径):列表有数据时在搜索行下列出三列名,与行同构对齐;
|
||||
只读口径下行没有改名/删除按钮,操作列表头随之不渲染。 -->
|
||||
<div v-if="filteredGroups.length" class="option-head">
|
||||
<BatchDeleteCheckbox v-if="editable" label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
<span class="head-name">分类名称</span>
|
||||
<span class="head-count">商品数</span>
|
||||
<span v-if="editable" class="head-actions">操作</span>
|
||||
</div>
|
||||
|
||||
<ul class="option-list">
|
||||
<template v-if="filteredGroups.length">
|
||||
<li v-for="group in pagedGroups" :key="group.id" class="option-row" :class="{ 'batch-selected': batch.isSelected(group) }">
|
||||
<BatchDeleteCheckbox v-if="editable" :label="batch.reason(group) || `选择 ${batch.label(group)}`" :checked="batch.isSelected(group)"
|
||||
:disabled="batch.disabled || !!batch.reason(group)" @change="batch.toggle(group)" />
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" class="rename-input" type="text" aria-label="分类新名称" @keyup.enter="submitRename(group)" />
|
||||
<span class="row-actions">
|
||||
<button class="btn btn-sm" type="button" :disabled="saving" @click="submitRename(group)">保存</button>
|
||||
<button class="btn btn-sm btn-secondary" type="button" @click="cancelRename">取消</button>
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="option-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="option-meta" title="该分类下的商品数">{{ group.productCount }}</span>
|
||||
<span v-if="editable" class="row-actions">
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="saving || batch.busy" @click="startRename(group)">改名</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="saving || batch.busy" @click="removeGroup(group)">删除</button>
|
||||
</span>
|
||||
</template>
|
||||
</li>
|
||||
</template>
|
||||
<li v-else-if="loading" class="manage-empty">加载中...</li>
|
||||
<li v-else class="manage-empty">
|
||||
<template v-if="canBootstrapGroup">
|
||||
<div class="group-bootstrap">
|
||||
<input
|
||||
v-model="newGroupName"
|
||||
class="search-input"
|
||||
type="text"
|
||||
placeholder="输入分组名称"
|
||||
aria-label="新分组名称"
|
||||
@keyup.enter="submitCreateGroup"
|
||||
/>
|
||||
<button class="btn" type="button" :disabled="!canCreateGroup" @click="submitCreateGroup">新建分组</button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>{{ emptyListText }}</template>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="showPager" class="manage-pager">
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo <= 1" @click="goPage(pageNo - 1)">上一页</button>
|
||||
<span class="pager-text">第 {{ pageNo }} / {{ totalPages }} 页 · 共 {{ filteredGroups.length }} 个分类</span>
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo >= totalPages" @click="goPage(pageNo + 1)">下一页</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.manage-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* 2026-11-17 用户口径「宽度不需要那么宽」「红框大小就够了」:垂直排列后每行拉满,
|
||||
480/420 都显空荡;按用户红框量到约 340px(全局 main.css 有 `* { box-sizing: border-box }`,
|
||||
这个 width 就是含内边距与边框的总宽)。行内容(名称+商品数徽标+改名/删除)与页码条
|
||||
在 340−42=298px 可用宽度里仍放得下,不会挤换行。 */
|
||||
width: min(340px, 100%);
|
||||
max-height: 80vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.modal-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.modal-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
/* 2026-11-17 用户口径演变:「垂直排阿」→ 弹窗收窄到 340px 后「弄成一排呗」:
|
||||
搜索框、新分类名输入、新建按钮合回一行。340−42=298px 可用宽度:新建按钮约 56
|
||||
+两处 gap 16。实测按比例分(flex 1:1.75)会偏移(搜索 122/新建输入只剩 105,
|
||||
7 字占位 115px 被截),改成搜索定宽 108px(6 字占位 102px 放得下),新建行吃剩余
|
||||
(298−108−16=174,输入约 118px,占位完整)。 */
|
||||
.manage-bar {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.search-input,
|
||||
.group-create input {
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.search-input:hover,
|
||||
.group-create input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.search-input:focus,
|
||||
.group-create input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.search-input {
|
||||
flex: 0 0 108px;
|
||||
min-width: 0;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
/* 表头与行同形(同 gap、同左右内边距),列名只是淡色小字不抢行内容;
|
||||
商品数列吃与徽标一致的 min-width/内边距,操作列同 rows 的 margin-left:auto 靠右。 */
|
||||
.option-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 6px 8px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 12px;
|
||||
color: #8293a5;
|
||||
}
|
||||
.head-name {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
.head-count {
|
||||
flex: none;
|
||||
min-width: 22px;
|
||||
padding: 0 7px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.head-actions {
|
||||
flex: none;
|
||||
margin-left: auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.option-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border-top: 1px solid #e7eef5;
|
||||
}
|
||||
.option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 9px 8px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.option-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 名称不占剩余空间:它只包住自己的文字,数量徽标紧贴其后。
|
||||
剩余空间全部让给 row-actions 的 margin-left:auto(有操作时按钮仍靠右)。
|
||||
写回 flex:1 会让名称把空白吃满、把号码顶到行尾(2026-11-17 用户反馈「0 和名称离的有点远」)。 */
|
||||
.option-name {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.option-meta {
|
||||
flex: none;
|
||||
min-width: 22px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #eef4fa;
|
||||
color: #4e6479;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.row-actions {
|
||||
flex: none;
|
||||
margin-left: auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.manage-empty {
|
||||
padding: 30px 12px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
list-style: none;
|
||||
}
|
||||
/* 平台超管空态直建分组:只有输入行(引导语/组长说明等小字 2026-11-17 用户口径「小字不需要」删除)。 */
|
||||
.group-bootstrap {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.group-bootstrap .search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
.manage-pager {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pager-text {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rename-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 32px;
|
||||
padding: 4px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.rename-input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.modal-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 36px;
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 28px;
|
||||
padding: 3px 10px;
|
||||
font-size: 12.5px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.btn-sm:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
/* 危险动作与全站 .btn-danger 同形(实心红渐变+白字)。 */
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,845 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东数据库页左侧栏(v1.6 蓝图 Phase 2,additive——页面接线随 Phase 5):
|
||||
* 双 Tab=商品目录(京麦授权类目真树+计数徽标+展开折叠+树外兜底组)/
|
||||
* 店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
|
||||
*
|
||||
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
|
||||
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换、树展开/折叠与新建输入框。
|
||||
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
|
||||
* 「点节点 → 子树展开 IN 过滤」的命中集合同源),树上对不上的历史行归「树外兜底」组
|
||||
* (点兜底行=单名等值旧形状,path 空数组交给页面回落)。 */
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import {
|
||||
jdCategoryCountTree,
|
||||
type JdCategoryCountedNode,
|
||||
} from './jd-category-tree.ts'
|
||||
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
|
||||
categoryOptions: JdProductCategoryOption[]
|
||||
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标;v1.7 每行可带
|
||||
* shops 店铺名单——铺开渲染店铺行点选过滤,空分类也常驻「添加店铺」入口)。 */
|
||||
categories: JdProductGroup[]
|
||||
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行、分类/店铺行的
|
||||
* hover 改名/删除与「添加店铺」入口;「分类管理」入口对所有人渲染(同组普通号只读可看,
|
||||
* V203,写控件由对话框分档)。 */
|
||||
editable: boolean
|
||||
/** 当前类目选中(name+完整名称路径;树外历史名 path 为空数组;null=全部商品)。 */
|
||||
selectedCategory?: { name: string; path: string[] } | null
|
||||
/** 当前分类选中 id(null=全部分类)。 */
|
||||
selectedGroupId?: number | null
|
||||
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
|
||||
selectedShopName?: string | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 选类目:树内节点带完整路径(页面按子树展开类目名集合 IN 下发);树外兜底名
|
||||
* path=[](序列化回落单名等值);null=「全部商品」清选重查。 */
|
||||
(event: 'select-category', value: { name: string; path: string[] } | null): void
|
||||
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
|
||||
(event: 'select-group', id: number | null): void
|
||||
/** 选店铺(v1.7 名单点选):分类+店铺名成对下发(点店铺=该分类归属 ∩ 该店铺,
|
||||
* 精确 eq);再点已选中的=emit null(只清店铺筛选,分类选中保留)。 */
|
||||
(event: 'select-shop', value: { groupId: number; shopName: string } | null): void
|
||||
/** 新建分类(可写档):页面调 createJdProductGroup 落当前分组,成功后刷新,
|
||||
* 侧栏数据随 props 流回(本组件不感知成功/失败,输入框提交即清)。 */
|
||||
(event: 'create-category', name: string): void
|
||||
/** 分类行内改名(可写档 hover ✎):分类 id+新名,API 调用与刷新在页面。 */
|
||||
(event: 'rename-category', category: JdProductGroup, name: string): void
|
||||
/** 分类行内删除(可写档 hover ✕):页面二次确认后调 deleteJdProductGroup。 */
|
||||
(event: 'delete-category', category: JdProductGroup): void
|
||||
/** 店铺行内改名(可写档 hover ✎):分类、老名、新名(同分类查重 409 由后端拒)。 */
|
||||
(event: 'rename-shop', category: JdProductGroup, oldName: string, newName: string): void
|
||||
/** 店铺行内移除(可写档 hover ✕):页面调 removeJdGroupShop。 */
|
||||
(event: 'remove-shop', category: JdProductGroup, shopName: string): void
|
||||
/** 打开添加店铺弹窗(可写档「+ 添加店铺」行):弹窗与提交在页面。 */
|
||||
(event: 'add-shops', category: JdProductGroup): void
|
||||
/** 打开分类管理对话框(建/改名/删+搜索,V204 并入的既有组件)。 */
|
||||
(event: 'manage-categories'): void
|
||||
}>()
|
||||
|
||||
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
|
||||
const activeTab = ref<'catalog' | 'custom'>('catalog')
|
||||
|
||||
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
|
||||
|
||||
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
|
||||
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
|
||||
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
|
||||
const totalCount = computed(() =>
|
||||
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
|
||||
|
||||
/** 展开态:按路径串('/' 连接)记,含树外兜底组头。出厂(无记忆)一级默认展开(二级可见);
|
||||
* v1.7 树增强:展开态持久化 localStorage `jd_db_cat_expand`(切页/重进不丢),损坏/不存在
|
||||
* =按出厂态(宁可重展一级也不冒充用户记忆)。 */
|
||||
const EXPAND_STORAGE_KEY = 'jd_db_cat_expand'
|
||||
|
||||
/** 读展开记忆:合法字符串数组才采信;返回「键集+是否有记忆」两个值——空数组 `[]` 是
|
||||
* 用户主动「全部收起」的合法记忆,不得与「没存过」混为一谈(混了=全收起被重置成
|
||||
* 一级展开,用户意图被吞)。坏形状/不可读回无记忆。 */
|
||||
function loadExpandedKeys(): { keys: Set<string>; stored: boolean } {
|
||||
try {
|
||||
const raw = localStorage.getItem(EXPAND_STORAGE_KEY)
|
||||
if (raw === null) return { keys: new Set(), stored: false }
|
||||
const parsed: unknown = JSON.parse(raw)
|
||||
if (!Array.isArray(parsed)) return { keys: new Set(), stored: false }
|
||||
return { keys: new Set(parsed.filter((value): value is string => typeof value === 'string')), stored: true }
|
||||
} catch {
|
||||
return { keys: new Set(), stored: false }
|
||||
}
|
||||
}
|
||||
|
||||
const initialExpand = loadExpandedKeys()
|
||||
const expanded = ref<Set<string>>(initialExpand.keys)
|
||||
const expandKey = (path: string[]): string => path.join('/')
|
||||
|
||||
function persistExpanded(): void {
|
||||
try {
|
||||
localStorage.setItem(EXPAND_STORAGE_KEY, JSON.stringify([...expanded.value]))
|
||||
} catch {
|
||||
// 存储不可写(隐私模式/配额满)=展开态只活在本会话,树功能不受影响。
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否有持久化记忆:有(哪怕空集=全收起)=尊重记忆(不再补一级展开);无=树根到达时
|
||||
* 补一级默认展开。注意 setup 时树数据通常还没到(页面先 scope 后列表),「一级默认展开」
|
||||
* 必须挂树根 watch 而不是 init 直接遍历(旧写法 roots 为空什么也没加=默认展开从未真正生效)。 */
|
||||
let hasStoredExpand = initialExpand.stored
|
||||
|
||||
watch(
|
||||
() => counted.value.roots,
|
||||
(roots) => {
|
||||
if (hasStoredExpand) return
|
||||
const next = new Set(expanded.value)
|
||||
for (const root of roots) next.add(expandKey([root.name]))
|
||||
// 补过一次就置位:之后类目重取不再补默认(用户中途收起的一级行不被重取展开回去)。
|
||||
hasStoredExpand = true
|
||||
if (next.size !== expanded.value.size) {
|
||||
expanded.value = next
|
||||
persistExpanded()
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
|
||||
|
||||
interface FlatNode {
|
||||
node: JdCategoryCountedNode
|
||||
path: string[]
|
||||
depth: number
|
||||
}
|
||||
|
||||
const flatTree = computed<FlatNode[]>(() => {
|
||||
const out: FlatNode[] = []
|
||||
const walk = (nodes: JdCategoryCountedNode[], depth: number, prefix: string[]): void => {
|
||||
for (const node of nodes) {
|
||||
const path = [...prefix, node.name]
|
||||
out.push({ node, path, depth })
|
||||
if (node.children.length && expanded.value.has(expandKey(path))) {
|
||||
walk(node.children, depth + 1, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(counted.value.roots, 0, [])
|
||||
return out
|
||||
})
|
||||
|
||||
function toggleExpand(path: string[]): void {
|
||||
const key = expandKey(path)
|
||||
const next = new Set(expanded.value)
|
||||
if (next.has(key)) next.delete(key)
|
||||
else next.add(key)
|
||||
expanded.value = next
|
||||
persistExpanded()
|
||||
}
|
||||
|
||||
/** 全部展开(v1.7 树增强):把每个有子级的节点 path 全收进展开集(深树一次到底)。 */
|
||||
function expandAll(): void {
|
||||
const next = new Set<string>()
|
||||
const walk = (nodes: JdCategoryCountedNode[], prefix: string[]): void => {
|
||||
for (const node of nodes) {
|
||||
const path = [...prefix, node.name]
|
||||
if (node.children.length) {
|
||||
next.add(expandKey(path))
|
||||
walk(node.children, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(counted.value.roots, [])
|
||||
expanded.value = next
|
||||
hasStoredExpand = true
|
||||
persistExpanded()
|
||||
}
|
||||
|
||||
/** 全部收起:清空展开集(一级也收,用户主动点了收起就是要全收)。 */
|
||||
function collapseAll(): void {
|
||||
expanded.value = new Set()
|
||||
hasStoredExpand = true
|
||||
persistExpanded()
|
||||
}
|
||||
|
||||
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
|
||||
function pickNode(node: FlatNode): void {
|
||||
if (node.node.children.length && !expanded.value.has(expandKey(node.path))) {
|
||||
toggleExpand(node.path)
|
||||
}
|
||||
emit('select-category', { name: node.node.name, path: node.path })
|
||||
}
|
||||
|
||||
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见,并把选中行
|
||||
* 滚进视口(v1.7 树增强;jsdom 无 scrollIntoView 自动跳过——测试不需要真滚)。
|
||||
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
|
||||
watch(
|
||||
() => props.selectedCategory,
|
||||
(selected) => {
|
||||
if (!selected || !selected.path.length) return
|
||||
const next = new Set(expanded.value)
|
||||
for (let i = 1; i < selected.path.length; i++) {
|
||||
next.add(expandKey(selected.path.slice(0, i)))
|
||||
}
|
||||
if (next.size !== expanded.value.size) {
|
||||
expanded.value = next
|
||||
persistExpanded()
|
||||
}
|
||||
void nextTick(() => {
|
||||
const picked = document.querySelector('.jd-side-tree .jd-side-row.selected')
|
||||
if (picked && typeof picked.scrollIntoView === 'function') {
|
||||
picked.scrollIntoView({ block: 'nearest' })
|
||||
}
|
||||
})
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
const isSelectedNode = (node: FlatNode): boolean => {
|
||||
const selected = props.selectedCategory
|
||||
if (!selected || selected.path.length !== node.path.length) return false
|
||||
return selected.path.every((name, index) => name === node.path[index])
|
||||
}
|
||||
|
||||
// ---------------- 树外兜底组(树上对不上的历史行,单名等值出口) ----------------
|
||||
|
||||
const extraOpen = ref(true)
|
||||
|
||||
function pickExtra(name: string): void {
|
||||
// 树外名不进树:path 空数组=页面按「无路径」序列化(单名等值旧形状,不静默丢筛选)。
|
||||
emit('select-category', { name, path: [] })
|
||||
}
|
||||
|
||||
const isSelectedExtra = (name: string): boolean => {
|
||||
const selected = props.selectedCategory
|
||||
return !!selected && selected.path.length === 0 && selected.name === name
|
||||
}
|
||||
|
||||
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
|
||||
|
||||
function pickGroup(group: JdProductGroup): void {
|
||||
// 再点已选中的=清选(回全部分类),与旧「全部分类」下拉行的语义等价。
|
||||
// 店铺筛选随分类清选一起走(店铺名单挂在分类下,分类清了店铺筛选无意义——页面同清)。
|
||||
emit('select-group', props.selectedGroupId === group.id ? null : group.id)
|
||||
}
|
||||
|
||||
const newCategoryName = ref('')
|
||||
|
||||
function submitCreate(): void {
|
||||
const name = newCategoryName.value.trim()
|
||||
if (!name) return
|
||||
emit('create-category', name)
|
||||
newCategoryName.value = ''
|
||||
}
|
||||
|
||||
// ---------------- 店铺名单(v1.7 F6 完整对齐原型:分类下挂店铺名单) ----------------
|
||||
|
||||
/** 名单铺开渲染(2026-11-22 原型对齐:分类→店铺名单→「+ 添加店铺」直接可见)。
|
||||
* 旧折叠版把入口藏在展开区里,且箭头只在已有名单时才出 ⇒ 空分类永远加不进
|
||||
* 第一个店铺(死锁);铺开后名单与入口常驻,空分类直接可加。 */
|
||||
|
||||
function pickShop(group: JdProductGroup, shopName: string): void {
|
||||
const picked = props.selectedGroupId === group.id && props.selectedShopName === shopName
|
||||
emit('select-shop', picked ? null : { groupId: group.id, shopName })
|
||||
}
|
||||
|
||||
// 行内改名(分类与店铺同构):点 hover ✎ 进编辑形态,Enter/✓ 提交、✕ 取消。
|
||||
const renamingCategory = ref<number | null>(null)
|
||||
const renameCategoryDraft = ref('')
|
||||
const renamingShop = ref<{ categoryId: number; name: string } | null>(null)
|
||||
const renameShopDraft = ref('')
|
||||
|
||||
function startRenameCategory(group: JdProductGroup): void {
|
||||
cancelShopRename()
|
||||
renamingCategory.value = group.id
|
||||
renameCategoryDraft.value = group.name
|
||||
}
|
||||
|
||||
function submitRenameCategory(group: JdProductGroup): void {
|
||||
const name = renameCategoryDraft.value.trim()
|
||||
cancelRenameCategory()
|
||||
// 空名/未改动不 emit(静默收编辑态,不白发请求)。
|
||||
if (!name || name === group.name) return
|
||||
emit('rename-category', group, name)
|
||||
}
|
||||
|
||||
function cancelRenameCategory(): void {
|
||||
renamingCategory.value = null
|
||||
renameCategoryDraft.value = ''
|
||||
}
|
||||
|
||||
function startRenameShop(group: JdProductGroup, shopName: string): void {
|
||||
cancelRenameCategory()
|
||||
renamingShop.value = { categoryId: group.id, name: shopName }
|
||||
renameShopDraft.value = shopName
|
||||
}
|
||||
|
||||
function submitRenameShop(group: JdProductGroup): void {
|
||||
const entry = renamingShop.value
|
||||
if (!entry) return
|
||||
const name = renameShopDraft.value.trim()
|
||||
cancelShopRename()
|
||||
if (!name || name === entry.name) return
|
||||
emit('rename-shop', group, entry.name, name)
|
||||
}
|
||||
|
||||
function cancelShopRename(): void {
|
||||
renamingShop.value = null
|
||||
renameShopDraft.value = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="jd-sidebar" aria-label="商品目录与店铺分类">
|
||||
<div class="jd-sidebar-tabs" role="tablist">
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="activeTab === 'catalog'"
|
||||
class="jd-sidebar-tab"
|
||||
:class="{ active: activeTab === 'catalog' }"
|
||||
@click="activeTab = 'catalog'"
|
||||
>商品目录</button>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
:aria-selected="activeTab === 'custom'"
|
||||
class="jd-sidebar-tab"
|
||||
:class="{ active: activeTab === 'custom' }"
|
||||
@click="activeTab = 'custom'"
|
||||
>店铺分类</button>
|
||||
</div>
|
||||
|
||||
<!-- 商品目录:全部商品 + 京麦授权类目树(计数徽标)+ 树外兜底组 -->
|
||||
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-row jd-side-all"
|
||||
:class="{ selected: !selectedCategory }"
|
||||
@click="emit('select-category', null)"
|
||||
>
|
||||
<span class="jd-side-name">全部商品</span>
|
||||
<span class="jd-side-count">{{ totalCount }}</span>
|
||||
</button>
|
||||
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。 -->
|
||||
<div v-if="flatTree.length" class="jd-side-tree-ops">
|
||||
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
|
||||
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
|
||||
</div>
|
||||
<div class="jd-side-tree">
|
||||
<button
|
||||
v-for="flat in flatTree"
|
||||
:key="flat.path.join('/')"
|
||||
type="button"
|
||||
class="jd-side-row"
|
||||
:class="[`depth-${flat.depth}`, { selected: isSelectedNode(flat) }]"
|
||||
:title="flat.path.join(' / ')"
|
||||
@click="pickNode(flat)"
|
||||
>
|
||||
<span
|
||||
v-if="flat.node.children.length"
|
||||
class="jd-side-arrow"
|
||||
:class="{ open: expanded.has(flat.path.join('/')) }"
|
||||
role="button"
|
||||
:aria-label="`展开或收起 ${flat.node.name}`"
|
||||
@click.stop="toggleExpand(flat.path)"
|
||||
>▸</span>
|
||||
<span v-else class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ flat.node.name }}</span>
|
||||
<span class="jd-side-count">{{ flat.node.count }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="counted.extra.length" class="jd-side-extra">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-row jd-side-extra-head"
|
||||
:aria-expanded="extraOpen"
|
||||
@click="extraOpen = !extraOpen"
|
||||
>
|
||||
<span class="jd-side-name">树外兜底</span>
|
||||
<span class="jd-side-count">{{ counted.extraTotal }}</span>
|
||||
</button>
|
||||
<template v-if="extraOpen">
|
||||
<button
|
||||
v-for="row in counted.extra"
|
||||
:key="row.name"
|
||||
type="button"
|
||||
class="jd-side-row depth-1"
|
||||
:class="{ selected: isSelectedExtra(row.name) }"
|
||||
:title="row.name"
|
||||
@click="pickExtra(row.name)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ row.name }}</span>
|
||||
<span class="jd-side-count">{{ row.productCount }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 店铺分类:新建分类(可写档)+ 分类管理入口(所有人)置顶(2026-11-21 用户口径
|
||||
「换一下位置」,红框块挪到 Tab 正下方),分类平铺随其后。 -->
|
||||
<div v-show="activeTab === 'custom'" class="jd-sidebar-body jd-side-custom">
|
||||
<div v-if="editable" class="jd-side-create">
|
||||
<input
|
||||
v-model="newCategoryName"
|
||||
type="text"
|
||||
placeholder="新分类名称"
|
||||
aria-label="新分类名称"
|
||||
@keyup.enter="submitCreate"
|
||||
/>
|
||||
<button type="button" :disabled="!newCategoryName.trim()" @click="submitCreate">新建分类</button>
|
||||
</div>
|
||||
<button type="button" class="jd-side-manage" @click="emit('manage-categories')">分类管理</button>
|
||||
|
||||
<template v-if="categories.length">
|
||||
<!-- 分类行(div role=button,行内要嵌 hover 操作按钮——button 嵌 button 非法 HTML):
|
||||
铺开形态(2026-11-22 原型对齐)无折叠箭头;可写档 hover 出改名/删除;
|
||||
名单店铺行与「添加店铺」入口直接铺在分类行下。 -->
|
||||
<template v-for="cat in categories" :key="cat.id">
|
||||
<div
|
||||
class="jd-side-row jd-side-cat"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:class="{ selected: selectedGroupId === cat.id }"
|
||||
:title="cat.name"
|
||||
@click="pickGroup(cat)"
|
||||
@keydown.enter="pickGroup(cat)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ cat.name }}</span>
|
||||
<span class="jd-side-count">{{ cat.productCount }}</span>
|
||||
<span v-if="editable" class="jd-side-ops">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op"
|
||||
:aria-label="`改名分类 ${cat.name}`"
|
||||
title="改名"
|
||||
@click.stop="startRenameCategory(cat)"
|
||||
>✎</button>
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op jd-side-op-danger"
|
||||
:aria-label="`删除分类 ${cat.name}`"
|
||||
title="删除"
|
||||
@click.stop="emit('delete-category', cat)"
|
||||
>✕</button>
|
||||
</span>
|
||||
</div>
|
||||
<!-- 分类行内改名(编辑形态替换该行):Enter/✓ 提交(空名/未改动静默收起)。 -->
|
||||
<div v-if="renamingCategory === cat.id" class="jd-side-inline-edit">
|
||||
<input
|
||||
v-model="renameCategoryDraft"
|
||||
type="text"
|
||||
:aria-label="`修改分类名称(原:${cat.name})`"
|
||||
@keyup.enter="submitRenameCategory(cat)"
|
||||
/>
|
||||
<button type="button" :aria-label="`确认改名分类 ${cat.name}`" @click.stop="submitRenameCategory(cat)">✓</button>
|
||||
<button type="button" aria-label="取消改名" @click.stop="cancelRenameCategory()">✕</button>
|
||||
</div>
|
||||
<!-- 铺开的店铺名单(v1.7 铺开形态):点店铺=分类+店铺成对过滤;可写档 hover 改名/移除;
|
||||
名单尾「+ 添加店铺」入口常驻(空分类也能加第一个店)开页面级弹窗。 -->
|
||||
<template v-for="shop in (cat.shops ?? [])" :key="`${cat.id}:${shop}`">
|
||||
<div
|
||||
class="jd-side-row jd-side-shop depth-1"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:class="{ selected: selectedGroupId === cat.id && selectedShopName === shop }"
|
||||
:title="shop"
|
||||
@click="pickShop(cat, shop)"
|
||||
@keydown.enter="pickShop(cat, shop)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">{{ shop }}</span>
|
||||
<span v-if="editable" class="jd-side-ops">
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op"
|
||||
:aria-label="`改名店铺 ${shop}`"
|
||||
title="改名"
|
||||
@click.stop="startRenameShop(cat, shop)"
|
||||
>✎</button>
|
||||
<button
|
||||
type="button"
|
||||
class="jd-side-op jd-side-op-danger"
|
||||
:aria-label="`移除店铺 ${shop}`"
|
||||
title="移除"
|
||||
@click.stop="emit('remove-shop', cat, shop)"
|
||||
>✕</button>
|
||||
</span>
|
||||
</div>
|
||||
<!-- 店铺行内改名(编辑形态替换该行)。 -->
|
||||
<div v-if="renamingShop && renamingShop.categoryId === cat.id" class="jd-side-inline-edit jd-side-shop-edit depth-1">
|
||||
<input
|
||||
v-model="renameShopDraft"
|
||||
type="text"
|
||||
:aria-label="`修改店铺名称(原:${renamingShop.name})`"
|
||||
@keyup.enter="submitRenameShop(cat)"
|
||||
/>
|
||||
<button type="button" :aria-label="`确认改名店铺 ${renamingShop.name}`" @click.stop="submitRenameShop(cat)">✓</button>
|
||||
<button type="button" aria-label="取消改名" @click.stop="cancelShopRename()">✕</button>
|
||||
</div>
|
||||
</template>
|
||||
<button
|
||||
v-if="editable"
|
||||
type="button"
|
||||
class="jd-side-row jd-side-shop-add depth-1"
|
||||
@click="emit('add-shops', cat)"
|
||||
>
|
||||
<span class="jd-side-leaf-dot" />
|
||||
<span class="jd-side-name">+ 添加店铺</span>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.jd-sidebar {
|
||||
width: 232px;
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
/* 左右高度对齐(2026-11-21 用户口径):侧栏外框随主面板拉满(页面容器已改 stretch),
|
||||
自身转纵向 flex——Tab 行固定、滚动区吃剩余高度,第三张截图红框那截空白带消失。 */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
.jd-sidebar-tabs {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.jd-sidebar-tab {
|
||||
flex: 1;
|
||||
padding: 10px 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.jd-sidebar-tab.active {
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
box-shadow: inset 0 -2px 0 #409eff;
|
||||
}
|
||||
|
||||
.jd-sidebar-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* 等高对齐下的滚动区:放弃 640px 上限(上限会让宽屏侧栏短于主面板=又不对齐),
|
||||
flex 吃满侧栏剩余高度,树/分类超出时内部滚动。窄屏(≤980px)侧栏整行摆放时
|
||||
恢复上限,防树全展开把整页拉长(断点与页面装配层一致)。 */
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 6px;
|
||||
/* 滚动带常驻(2026-11-21 用户口径「这边还要个进度条」,红框指树右缘滚动带):
|
||||
Win 新版 Chrome/Edge 的 fluent overlay 滚动条不悬停不显形,长类目树看不出可滚;
|
||||
标准属性(Chrome/Edge/Firefox 通用)+自绘 webkit 滚动条兜旧版,无溢出时不占位。 */
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #bccfe1 transparent;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-thumb {
|
||||
background: #bccfe1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.jd-sidebar-body::-webkit-scrollbar-thumb:hover {
|
||||
background: #9fb7cd;
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
.jd-sidebar-body {
|
||||
max-height: 480px;
|
||||
}
|
||||
}
|
||||
|
||||
.jd-side-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
padding: 6px 8px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.jd-side-row:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.jd-side-row.selected {
|
||||
background: #ecf5ff;
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.jd-side-row.depth-1 { padding-left: 22px; }
|
||||
.jd-side-row.depth-2 { padding-left: 36px; }
|
||||
.jd-side-row.depth-3 { padding-left: 50px; }
|
||||
|
||||
.jd-side-arrow {
|
||||
width: 14px;
|
||||
flex-shrink: 0;
|
||||
color: #909399;
|
||||
transition: transform 0.15s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-side-arrow.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.jd-side-leaf-dot {
|
||||
width: 14px;
|
||||
flex-shrink: 0;
|
||||
text-align: center;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
|
||||
.jd-side-leaf-dot::before {
|
||||
content: '·';
|
||||
}
|
||||
|
||||
.jd-side-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.jd-side-count {
|
||||
flex-shrink: 0;
|
||||
min-width: 24px;
|
||||
text-align: right;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
background: #f0f2f5;
|
||||
border-radius: 10px;
|
||||
padding: 1px 7px;
|
||||
}
|
||||
|
||||
.jd-side-row.selected .jd-side-count {
|
||||
color: #409eff;
|
||||
background: #d9ecff;
|
||||
}
|
||||
|
||||
/* 树顶展开/收起操作行(v1.7 树增强):弱化小按钮,不与树行抢视觉。 */
|
||||
.jd-side-tree-ops {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
padding: 0 4px 4px;
|
||||
}
|
||||
|
||||
.jd-side-tree-ops button {
|
||||
padding: 2px 8px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-side-tree-ops button:hover {
|
||||
color: #409eff;
|
||||
border-color: #c6e2ff;
|
||||
}
|
||||
|
||||
.jd-side-extra {
|
||||
margin-top: 4px;
|
||||
border-top: 1px dashed #e4e7ed;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.jd-side-extra-head {
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.jd-side-empty {
|
||||
margin: 8px 4px;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.jd-side-create {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
/* 置顶档(2026-11-21 换位):贴 Tab 行下方,分隔虚线随位置挪到「分类管理」与列表之间。 */
|
||||
margin-top: 4px;
|
||||
padding: 6px 4px;
|
||||
}
|
||||
|
||||
.jd-side-create input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.jd-side-create button {
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.jd-side-create button:disabled {
|
||||
color: #c0c4cc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.jd-side-manage {
|
||||
margin-top: 0;
|
||||
margin-bottom: 4px;
|
||||
padding: 6px 8px;
|
||||
border: none;
|
||||
/* 置顶档:虚线分隔「控制块 ↔ 分类列表」。 */
|
||||
border-bottom: 1px dashed #e4e7ed;
|
||||
background: transparent;
|
||||
color: #606266;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.jd-side-manage:hover {
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
/* 店铺名单(v1.7 F6):分类行 hover 操作钮(改名/删除)、店铺行缩进、行内改名编辑形态、
|
||||
「+ 添加店铺」入口。行本体是 div role=button(行内嵌操作按钮,button 嵌 button 非法)。 */
|
||||
.jd-side-row.jd-side-cat,
|
||||
.jd-side-row.jd-side-shop {
|
||||
cursor: pointer;
|
||||
}
|
||||
/* hover 操作钮:默认藏,行 hover 时浮出(占位 0 宽,不挤名字/徽标布局)。 */
|
||||
.jd-side-ops {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
flex-shrink: 0;
|
||||
width: 0;
|
||||
overflow: hidden;
|
||||
transition: width 120ms ease;
|
||||
}
|
||||
.jd-side-row:hover .jd-side-ops,
|
||||
.jd-side-row:focus-within .jd-side-ops {
|
||||
width: 36px;
|
||||
}
|
||||
.jd-side-op {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
color: #909399;
|
||||
font-size: 11px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.jd-side-op:hover {
|
||||
background: #e6edf4;
|
||||
color: #409eff;
|
||||
}
|
||||
.jd-side-op-danger:hover {
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
}
|
||||
/* 行内改名编辑形态:替换该行的紧凑输入行(Enter/✓ 提交、✕ 取消)。 */
|
||||
.jd-side-inline-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 8px;
|
||||
}
|
||||
.jd-side-inline-edit.jd-side-shop-edit {
|
||||
padding-left: 22px;
|
||||
}
|
||||
.jd-side-inline-edit input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #9fc3e8;
|
||||
border-radius: 6px;
|
||||
font-size: 12.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.jd-side-inline-edit input:focus {
|
||||
box-shadow: 0 0 0 2px rgba(95, 133, 173, 0.18);
|
||||
}
|
||||
.jd-side-inline-edit button {
|
||||
width: 22px;
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #409eff;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.jd-side-inline-edit button:last-child {
|
||||
color: #909399;
|
||||
}
|
||||
/* 「+ 添加店铺」入口:名单尾部的弱化行(虚线上缘分隔),可写档才渲染(v-if 在模板)。 */
|
||||
.jd-side-shop-add {
|
||||
color: #409eff;
|
||||
border-top: 1px dashed #e4e7ed;
|
||||
border-radius: 0;
|
||||
}
|
||||
.jd-side-shop-add:hover {
|
||||
color: #2f7cd6;
|
||||
background: #f0f7ff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,911 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东公共商品库(v1.6 蓝图 Phase 5 重写装配:侧栏+卡片网格+居中详情弹窗)。
|
||||
* V203(2026-11-16 用户口径):分类按「数据权限分组」隔离——不同组看不到彼此的分类,
|
||||
* 能看多组的人用「分组」下拉切换当前组(只有一组时锁定显示)。
|
||||
* 2026-11-17 用户口径:店铺分类弹窗下线,工具栏「归入分类」——勾选商品(翻页累计记忆)
|
||||
* 后选目标分类归入或取消归属;建/改名/删分类收进侧栏「分类管理」对话框(带名称搜索)。
|
||||
* v1.7(2026-11-21 对齐原型《商品数据商城》):
|
||||
* ① 搜索合并——顶部单搜索框(商品编码 OR 标题,OR 语义在后端 SQL;旧两框退役),
|
||||
* Enter 查询、× 清除即查;
|
||||
* ② 筛选收弹层——「筛选」按钮下方浮层(价格区间+同步起止+重置/应用),分组下拉与
|
||||
* 归属三档保留顶部(v1.6 用户口径的两件保留不动);
|
||||
* ③ 筛选回显条——主面板顶部条件芯片(类目/分类/店铺/价格/同步区间+共 N 条+清除筛选,
|
||||
* 清除保留分组作用域),无激活筛选不渲染;
|
||||
* ④ 顶部分页——「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/下一页/末页+档位
|
||||
* 50/100/200/500/1000(与后端 MAX_PAGE_SIZE=1000 逐字同步),底部 OldPagination 从本页
|
||||
* 撤下(组件本体不动,他页在用);
|
||||
* ⑤ 底部已选条——主面板底部常驻「已选 N 件」悬浮条(能勾选的档才渲染);
|
||||
* ⑥ CSV 导出+已下载角标已下线(2026-11-21 用户拍板「删除掉」导出按钮):随按钮一并
|
||||
* 摘除 onExportCsv/exportJdProductsCsv/downloadedIds 记忆与卡片「已下载」角标;后端
|
||||
* /export 端点暂留,下一 jar 发版窗再收。 */
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import {
|
||||
batchAssignJdProductGroup,
|
||||
createJdProductGroup,
|
||||
deleteJdProductGroup,
|
||||
deleteJdProducts,
|
||||
fetchJdCategoryScope,
|
||||
fetchJdProductCategories,
|
||||
fetchJdProductGroups,
|
||||
fetchJdProductList,
|
||||
removeJdGroupShop,
|
||||
renameJdGroupShop,
|
||||
updateJdProductGroup,
|
||||
type JdCategoryGroupOption,
|
||||
type JdProductCategoryOption,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import {
|
||||
createJdProductFilterState,
|
||||
finitePriceOrNull,
|
||||
jdProductFilterActive,
|
||||
JD_PRODUCT_PAGE_SIZE_OPTIONS,
|
||||
} from './jd-product-filter.ts'
|
||||
import { JD_PRODUCT_DEFAULT_SIZE, type JdProductItem } from './jd-product-model.ts'
|
||||
import JdCategorySidebar from './JdCategorySidebar.vue'
|
||||
import JdProductCard from './JdProductCard.vue'
|
||||
import JdProductDetailModal from './JdProductDetailModal.vue'
|
||||
import JdProductEditDrawer from './JdProductEditDrawer.vue'
|
||||
import JdBatchAssignDialog from './JdBatchAssignDialog.vue'
|
||||
import JdCategoryManageDialog from './JdCategoryManageDialog.vue'
|
||||
import JdShopPickerDialog from './JdShopPickerDialog.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { isAdminRole, isCompanySuperAdminRole } from '@/types/admin'
|
||||
import { orderedPair } from '@/utils/datetime'
|
||||
|
||||
/** 写权限口径(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」):
|
||||
* 商品行写(编辑/删除/批量删除/传图)对管理员级(超级管理员/公司超级管理员/admin 档)渲染,
|
||||
* 普通账号只读(后端 requireJdProductWrite 同口径兜底);分类写(建/改名/删除、归类)
|
||||
* 由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管),与本档无关。 */
|
||||
const session = useAdminSessionStore()
|
||||
const canWriteProducts = computed(() => isAdminRole(session.user?.role))
|
||||
/** 分组筛选(同日用户口径「超管可以有分组筛选,管理员及以下则没有」):顶部「分组」控件
|
||||
* (下拉+单组锁定芯片)只对超管档(超级管理员/公司超级管理员)渲染;管理员及以下
|
||||
* 不出现,其分类面固定落在作用域默认分组上。 */
|
||||
const canFilterGroup = computed(() => session.isSuperAdmin || isCompanySuperAdminRole(session.user?.role))
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<JdProductItem[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
/** 每页条数默认 50(v1.6 Phase 1 新契约),档位 50/100/200/500/1000(v1.7)收敛在 filter 层单一出处。 */
|
||||
const pageSize = ref(JD_PRODUCT_DEFAULT_SIZE)
|
||||
const filter = reactive(createJdProductFilterState())
|
||||
/** 分类作用域(V203):可见分组 + 每组可写标记。失败静默回空作用域(分类面全空但商品照常)。 */
|
||||
const categoryScope = ref<JdCategoryGroupOption[]>([])
|
||||
const scopeDefaultGroupId = ref(0)
|
||||
/** 操作者是否平台超管(scope 原样透传):京东侧还没有任何分组时,分类管理弹窗
|
||||
* 靠它给平台超管开「直接新建数据权限分组」的口子(2026-11-17 用户口径「admin 权限最大」),
|
||||
* 其余角色维持空态指路,不在分类管理里建组。 */
|
||||
const scopeSuperAdmin = ref(false)
|
||||
/** 当前分组(数据权限分组 id):分类列/分类筛选/分类管理的共同作用域。 */
|
||||
const ownerGroupId = ref(0)
|
||||
/** 当前分组的分类选项(按 ownerGroupId 取,切组即换;侧栏店铺分类 Tab 与归类对话框共用)。 */
|
||||
const groupOptions = ref<JdProductGroup[]>([])
|
||||
/** 类目计数行(京麦末级类目+商品数):侧栏商品目录树的徽标数据源;失败静默回空。 */
|
||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||
const detailItem = ref<JdProductItem | null>(null)
|
||||
const detailVisible = ref(false)
|
||||
/** 归类对话框(2026-17 替代下线的店铺分类弹窗,工具栏「归入分类」打开)。 */
|
||||
const batchEditVisible = ref(false)
|
||||
/** 分类管理对话框(2026-11-17 第二刀:独立子菜单页并进来,建/改名/删+搜索)。 */
|
||||
const manageVisible = ref(false)
|
||||
/** 行级编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除」):入口随操作列
|
||||
* 下线收进详情弹窗顶部动作区(Modal emit edit),删除走 removeOne 同一条链。 */
|
||||
const editItem = ref<JdProductItem | null>(null)
|
||||
const editVisible = ref(false)
|
||||
|
||||
/** 筛选弹层(v1.7 对齐原型):「筛选」按钮下方浮层,价格区间+同步起止+重置/应用。 */
|
||||
const filterPopVisible = ref(false)
|
||||
|
||||
/** 当前分组的下拉项(带 editable)——分类写入口与侧栏新建分类行的可写档都读它。 */
|
||||
const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
|
||||
categoryScope.value.find((group) => group.id === ownerGroupId.value) || null)
|
||||
const currentGroupName = computed(() => currentGroupOption.value?.name || '')
|
||||
/** 分类可管理(建/改名/删除/归类):本组管理员、公司超管、平台超管(后端 scope 判)。 */
|
||||
const canManageCategories = computed(() => currentGroupOption.value?.editable === true)
|
||||
/** 勾选面(卡片勾选框+工具栏全选/批量动作)服务两类写:批量删除(管理员级)+
|
||||
* 归类/取消归属(本组可写分类的管理员也要勾)。2026-11-17 弹窗下线后管理员失去
|
||||
* 弹窗右栏的勾选面 ⇒ 勾选面对「本组可写」放开,否则本组管理员没有归类入口。 */
|
||||
const hasSelection = computed(() => canWriteProducts.value || canManageCategories.value)
|
||||
/** 分组下拉只在能看多组时才渲染;只有一组(含无可见组)时按锁定态展示。 */
|
||||
const canSwitchGroup = computed(() => categoryScope.value.length > 1)
|
||||
|
||||
/** 侧栏选中回显:类目(name+完整名称路径;树外名 path 空数组)与分类 id。 */
|
||||
const selectedCategoryInfo = computed(() =>
|
||||
filter.category ? { name: filter.category, path: filter.categoryPath ?? [] } : null)
|
||||
const selectedGroupIdNum = computed(() => {
|
||||
const id = Number.parseInt(filter.groupId, 10)
|
||||
return Number.isFinite(id) && id > 0 ? id : null
|
||||
})
|
||||
|
||||
/** 是否有任一激活筛选条件(回显条渲染判据;分组作用域不在判定里)。 */
|
||||
const filterActive = computed(() => jdProductFilterActive(filter))
|
||||
|
||||
/** 回显条芯片(v1.7 对齐原型):类目/分类/店铺/价格区间/同步区间/归属档,各带人话前缀;
|
||||
* 归属三档只回显偏离出厂默认(全部)的档位——默认档不是激活筛选。 */
|
||||
const activeFilterChips = computed(() => {
|
||||
const chips: { key: string; label: string }[] = []
|
||||
const keyword = (filter.keyword || '').trim()
|
||||
if (keyword) chips.push({ key: 'keyword', label: `搜索:${keyword}` })
|
||||
if ((filter.category || '').trim()) chips.push({ key: 'category', label: `类目:${filter.category}` })
|
||||
const shopName = (filter.shopName || '').trim()
|
||||
if (shopName) chips.push({ key: 'shop', label: `店铺:${shopName}` })
|
||||
if ((filter.groupId || '').trim()) {
|
||||
const group = groupOptions.value.find((option) => String(option.id) === filter.groupId)
|
||||
chips.push({ key: 'group', label: `分类:${group?.name || filter.groupId}` })
|
||||
}
|
||||
if (filter.classified === 'classified') chips.push({ key: 'classified', label: '已分类' })
|
||||
else if (filter.classified === '') chips.push({ key: 'classified', label: '全部分类状态' })
|
||||
const minPrice = finitePriceOrNull(filter.minPrice)
|
||||
const maxPrice = finitePriceOrNull(filter.maxPrice)
|
||||
if (minPrice != null || maxPrice != null) {
|
||||
chips.push({ key: 'price', label: `价格:${minPrice ?? ''} ~ ${maxPrice ?? ''}` })
|
||||
}
|
||||
if (filter.syncedFrom || filter.syncedTo) {
|
||||
chips.push({ key: 'synced', label: `同步:${filter.syncedFrom || '…'} ~ ${filter.syncedTo || '…'}` })
|
||||
}
|
||||
return chips
|
||||
})
|
||||
|
||||
/** 侧栏选类目:树内节点带完整路径(序列化按子树展开 IN 下发)、树外兜底名 path 空=
|
||||
* 单名等值旧形状;null=「全部商品」清选重查。选中即查(回第一页)。 */
|
||||
function onSelectCategory(value: { name: string; path: string[] } | null): void {
|
||||
filter.category = value?.name || ''
|
||||
filter.categoryPath = value?.path ?? []
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 侧栏选分类:id 或 null(清选,与旧「全部分类」下拉行同语义)。选中即查。 */
|
||||
function onSelectGroup(id: number | null): void {
|
||||
filter.groupId = id ? String(id) : ''
|
||||
// 店铺筛选挂在分类下(v1.7 名单维度):分类清选时店铺筛选一起清,否则发一条
|
||||
// 「分类不限 ∩ 店铺=X」的孤儿谓词(店铺全平台 DISTINCT,会命中别组分类下的同名店)。
|
||||
filter.shopName = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
// ---------------- 店铺名单(v1.7 F6:侧栏展开/点店铺过滤/行内改名移除/添加店铺弹窗) ----------------
|
||||
|
||||
/** 添加店铺弹窗的目标分类(名单挂在分类下;null=弹窗关着)。 */
|
||||
const addShopsTarget = ref<JdProductGroup | null>(null)
|
||||
const addShopsVisible = ref(false)
|
||||
|
||||
/** 侧栏点店铺行:分类+店铺成对下发(精确 eq);null=清店铺筛选(分类选中保留)。 */
|
||||
function onSelectShop(value: { groupId: number; shopName: string } | null): void {
|
||||
if (!value) {
|
||||
filter.shopName = ''
|
||||
apply()
|
||||
return
|
||||
}
|
||||
filter.groupId = String(value.groupId)
|
||||
filter.shopName = value.shopName
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 侧栏分类行内改名:成功后刷新分类(侧栏随 props 流回);失败弹后端中文文案(409 重名等)。 */
|
||||
async function onRenameCategory(category: JdProductGroup, name: string): Promise<void> {
|
||||
try {
|
||||
await updateJdProductGroup(category.id, { name, sortOrder: category.sortOrder })
|
||||
showAdminFeedback(`已把分类「${category.name}」改名为「${name}」`, 'success')
|
||||
await loadGroupOptions()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '改名失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** 侧栏分类行内删除:二次确认(点名只解挂归属、商品保留)→ 删除 → 若当前筛选停在该
|
||||
* 分类(含其店铺行)则清分类筛选,分类列表与行集都重取。 */
|
||||
async function onDeleteCategory(category: JdProductGroup): Promise<void> {
|
||||
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${category.name}」吗?只删除该分类的归属关系(${category.productCount} 个商品回到未分类),商品本身保留在公共库;分类下的店铺名单一并删除。此操作不可恢复。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok) return
|
||||
try {
|
||||
await deleteJdProductGroup(category.id)
|
||||
showAdminFeedback(`已删除分类「${category.name}」`, 'success')
|
||||
if (filter.groupId === String(category.id)) {
|
||||
filter.groupId = ''
|
||||
filter.shopName = ''
|
||||
}
|
||||
await loadGroupOptions()
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '删除分类失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** 店铺行内改名:成功后刷新名单;若当前筛选正停在这个店(同分类)则把筛选词同步成新名。 */
|
||||
async function onRenameShop(category: JdProductGroup, oldName: string, newName: string): Promise<void> {
|
||||
try {
|
||||
await renameJdGroupShop(category.id, oldName, newName)
|
||||
showAdminFeedback(`已把店铺「${oldName}」改名为「${newName}」`, 'success')
|
||||
if (filter.groupId === String(category.id) && filter.shopName === oldName) {
|
||||
filter.shopName = newName
|
||||
await load()
|
||||
}
|
||||
await loadGroupOptions()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '改名失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** 店铺行内移除(可重做——再加回名单即可,不设二次确认);筛选正停在它身上则清店铺筛选。 */
|
||||
async function onRemoveShop(category: JdProductGroup, shopName: string): Promise<void> {
|
||||
try {
|
||||
await removeJdGroupShop(category.id, shopName)
|
||||
showAdminFeedback(`已把「${shopName}」移出「${category.name}」的名单`, 'success')
|
||||
if (filter.groupId === String(category.id) && filter.shopName === shopName) {
|
||||
filter.shopName = ''
|
||||
await load()
|
||||
}
|
||||
await loadGroupOptions()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '移除失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开添加店铺弹窗(侧栏「+ 添加店铺」行;名单写闸 editable 在侧栏已分档,后端同闸兜底)。 */
|
||||
function openAddShops(category: JdProductGroup): void {
|
||||
addShopsTarget.value = category
|
||||
addShopsVisible.value = true
|
||||
}
|
||||
|
||||
/** 添加店铺成功:回执=实际新增行数(幂等跳过不计)。只刷新名单(侧栏店铺行随 props
|
||||
* 流回)——名单是筛选器的候选面,不动商品行集,行集谓词 shop_name 无需重查。 */
|
||||
async function onShopsAdded(added: number, categoryName: string): Promise<void> {
|
||||
showAdminFeedback(
|
||||
added > 0 ? `已把 ${added} 个店铺加进「${categoryName}」` : '所选店铺都已在名单里,没有新增',
|
||||
'success',
|
||||
)
|
||||
await loadGroupOptions()
|
||||
}
|
||||
|
||||
/** 侧栏新建分类(可写档):落当前分组,成功后刷新分类(侧栏徽标随 props 流回)。 */
|
||||
async function onCreateCategory(name: string): Promise<void> {
|
||||
try {
|
||||
await createJdProductGroup({ name, sortOrder: 0, ownerGroupId: ownerGroupId.value })
|
||||
showAdminFeedback(`已创建分类「${name}」`, 'success')
|
||||
await loadGroupOptions()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '创建分类失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampJdSyncedRange(): void {
|
||||
const [s, e] = orderedPair(filter.syncedFrom, filter.syncedTo)
|
||||
filter.syncedFrom = s
|
||||
filter.syncedTo = e
|
||||
}
|
||||
|
||||
function toggleFilterPopover(): void {
|
||||
filterPopVisible.value = !filterPopVisible.value
|
||||
}
|
||||
|
||||
/** 清除搜索词(× 即查):空词不重发(首屏没搜过就别白发一条)。 */
|
||||
function clearKeyword(): void {
|
||||
if (!filter.keyword) return
|
||||
filter.keyword = ''
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 弹层「应用」:价格倒挡先在门口挡住(后端同文案兜底),过了才关弹层查询。 */
|
||||
function applyFromPopover(): void {
|
||||
const minPrice = finitePriceOrNull(filter.minPrice)
|
||||
const maxPrice = finitePriceOrNull(filter.maxPrice)
|
||||
if (minPrice != null && maxPrice != null && minPrice > maxPrice) {
|
||||
showAdminFeedback('价格区间最小值不能大于最大值', 'error')
|
||||
return
|
||||
}
|
||||
filterPopVisible.value = false
|
||||
apply()
|
||||
}
|
||||
|
||||
/** 弹层「重置」:筛选面回出厂空态并查询(与回显条「清除筛选」同一条链,保留分组作用域)。 */
|
||||
function resetFromPopover(): void {
|
||||
filterPopVisible.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
/** 作用域 → 分组列表 → 该组分类:失败一律静默降级(分类只是筛选/归类面,不拦首屏行集)。 */
|
||||
async function loadCategoryScope(): Promise<void> {
|
||||
try {
|
||||
const scope = await fetchJdCategoryScope()
|
||||
categoryScope.value = scope.groups
|
||||
scopeDefaultGroupId.value = scope.defaultGroupId ?? 0
|
||||
scopeSuperAdmin.value = scope.platformSuperAdmin === true
|
||||
} catch {
|
||||
categoryScope.value = []
|
||||
scopeDefaultGroupId.value = 0
|
||||
scopeSuperAdmin.value = false
|
||||
}
|
||||
// 当前分组:保留用户已选(仍可见时),否则回默认(可见组第一项)。
|
||||
const keep = categoryScope.value.some((group) => group.id === ownerGroupId.value)
|
||||
if (!keep) ownerGroupId.value = scopeDefaultGroupId.value
|
||||
await loadGroupOptions()
|
||||
}
|
||||
|
||||
/** 当前分组的分类选项:按 ownerGroupId 取(跨组不可见);失败静默回空下拉。 */
|
||||
async function loadGroupOptions(): Promise<void> {
|
||||
try {
|
||||
groupOptions.value = await fetchJdProductGroups(ownerGroupId.value)
|
||||
} catch {
|
||||
groupOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 类目计数行同分组口径:失败静默回空(侧栏只剩「全部商品」行),不拦首屏行集。 */
|
||||
async function loadCategoryOptions(): Promise<void> {
|
||||
try {
|
||||
categoryOptions.value = await fetchJdProductCategories()
|
||||
} catch {
|
||||
categoryOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。
|
||||
* 勾选集是按商品 id 记的(跨页累计),切组不清——归类的落点组随 ownerGroupId 走,
|
||||
* 误跨组批量归类由归类对话框里的组名标注防住。 */
|
||||
async function changeOwnerGroup(next: number): Promise<void> {
|
||||
if (next === ownerGroupId.value) return
|
||||
ownerGroupId.value = next
|
||||
filter.groupId = ''
|
||||
await loadGroupOptions()
|
||||
page.value = 1
|
||||
await load()
|
||||
}
|
||||
|
||||
/** 打开归类对话框:先刷一遍当前组分类(商品数徽标要新鲜),再亮对话框。 */
|
||||
async function openBatchEdit(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
batchEditVisible.value = true
|
||||
}
|
||||
|
||||
/** 工具栏「取消归属」=批量解挂(groupId null,后端只解挂本组归属行):
|
||||
* 与归类对话框的「移出分类」同一端点同语义;归类可重做(再归入即可)故不设二次确认。 */
|
||||
async function detachSelected(): Promise<void> {
|
||||
const ids = [...selectedIds.value]
|
||||
if (!ids.length || assigning.value) return
|
||||
assigning.value = true
|
||||
try {
|
||||
const updated = await batchAssignJdProductGroup(ids, null, ownerGroupId.value)
|
||||
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
|
||||
selectedIds.value = new Set()
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '移出分类失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
} finally {
|
||||
assigning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开分类管理(对话框自取列表);入口对所有人渲染——同组普通号只读可看(V203),
|
||||
* 写控件由对话框按 editable 分档。 */
|
||||
function openManage(): void {
|
||||
manageVisible.value = true
|
||||
}
|
||||
|
||||
/** 分类管理里有写操作(建/改/删):刷一遍侧栏分类与商品数徽标。 */
|
||||
async function onManaged(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类管理里新建了第一个数据权限分组(平台超管空态直建,2026-11-17 用户口径「admin
|
||||
* 权限最大」):整条作用域重取——新组会进可见集并把「当前分组」翻过去,侧栏分类、
|
||||
* 弹窗内分类列表随之按新组取,操作者接着就能建分类,不用关弹窗再开一遍。
|
||||
*/
|
||||
async function onGroupCreated(): Promise<void> {
|
||||
await loadCategoryScope()
|
||||
}
|
||||
|
||||
/** 归类完成(对话框已关):清勾选+重取列表(行集分组变了)。
|
||||
* 移出分类 targetName 为 null;updated 是后端实际写入/解挂的归属行数。 */
|
||||
async function onBatchAssigned(updated: number, targetName: string | null): Promise<void> {
|
||||
showAdminFeedback(
|
||||
targetName ? `已把 ${updated} 个商品归入「${targetName}」` : `已把 ${updated} 个商品移出分类`,
|
||||
'success',
|
||||
)
|
||||
selectedIds.value = new Set()
|
||||
await load()
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchJdProductList({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
keyword: filter.keyword,
|
||||
category: filter.category,
|
||||
categoryPath: filter.categoryPath,
|
||||
shopName: filter.shopName,
|
||||
groupId: filter.groupId,
|
||||
classified: filter.classified,
|
||||
minPrice: filter.minPrice,
|
||||
maxPrice: filter.maxPrice,
|
||||
ownerGroupId: ownerGroupId.value,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
})
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
// 勾选跨页记忆(2026-11-17 用户口径「支持勾选翻页也要记住」):翻页/重取/改筛选都
|
||||
// 不清勾选集——归类与批量删除都按累计 id 提交,操作前的确认弹窗点名数量;
|
||||
// 「清除勾选」按钮同日用户口径删除,勾选只在批量操作成功后自动清。
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '京东商品列表加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 重置:筛选面回出厂空态(搜索词/类目/店铺/价格/日期随 filter 回空=侧栏高亮自动清,
|
||||
* 归属三档回默认全部档('')),回第一页重取;分组作用域(ownerGroupId)不在 filter 里,
|
||||
* 天然保留(AC-4)。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createJdProductFilterState())
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function changePage(next: number): void {
|
||||
if (next < 1 || next > totalPages.value) return
|
||||
page.value = next
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 顶部分页(v1.7 对齐原型):首/末页按钮复用 changePage 的边界检查(越界页码静默忽略)。 */
|
||||
function goFirstPage(): void {
|
||||
changePage(1)
|
||||
}
|
||||
|
||||
function goLastPage(): void {
|
||||
changePage(totalPages.value)
|
||||
}
|
||||
|
||||
function changeSize(size: number) {
|
||||
pageSize.value = size
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function openDetail(item: JdProductItem): void {
|
||||
detailItem.value = item
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
function closeDetail(): void {
|
||||
detailVisible.value = false
|
||||
detailItem.value = null
|
||||
}
|
||||
|
||||
/** 商品编码一键复制(卡片 ⧉,@click.stop 防冒泡开详情):剪贴板不可用(非安全上下文)时弹失败文案。 */
|
||||
async function copyProductCode(row: JdProductItem): Promise<void> {
|
||||
const code = row.productCode
|
||||
if (!code) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(code)
|
||||
showAdminFeedback(`已复制 ${code}`, 'success')
|
||||
} catch {
|
||||
showAdminFeedback('复制失败,请手动选择复制', 'error')
|
||||
}
|
||||
}
|
||||
|
||||
/** 详情弹窗顶部「编辑/删除」(Modal emit):先关弹窗再走既有链,与旧操作列同源。 */
|
||||
function onDetailEdit(): void {
|
||||
const item = detailItem.value
|
||||
closeDetail()
|
||||
if (item) openEdit(item)
|
||||
}
|
||||
|
||||
function onDetailRemove(): void {
|
||||
const item = detailItem.value
|
||||
closeDetail()
|
||||
if (item) void removeOne(item)
|
||||
}
|
||||
|
||||
function openEdit(item: JdProductItem): void {
|
||||
editItem.value = item
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
function closeEdit(): void {
|
||||
editVisible.value = false
|
||||
editItem.value = null
|
||||
}
|
||||
|
||||
/** 编辑保存成功:刷新列表(该行已置人工编辑锁,标题/价格等即时可见且不再被采集覆盖)。 */
|
||||
async function onEditSaved(): Promise<void> {
|
||||
await load()
|
||||
}
|
||||
|
||||
// ---------------- 删除(先删桶、全成功才删库行,语义在后端 JdProductDeleteService) ----------------
|
||||
|
||||
/** 勾选集(按商品 id,跨页累计记忆,2026-11-17 用户口径)。翻页/重取不清;显式出口
|
||||
* 曾是工具栏「清除勾选」,同日用户口径「清除勾选这个按钮删除」后只剩批量动作
|
||||
* 成功后自动清。 */
|
||||
const selectedIds = ref<Set<number>>(new Set())
|
||||
const deleting = ref(false)
|
||||
/** 归类/取消归属进行中(对话框提交与工具栏「取消归属」共用一颗互斥灯)。 */
|
||||
const assigning = ref(false)
|
||||
|
||||
const selectedCount = computed(() => selectedIds.value.size)
|
||||
|
||||
function toggleSelect(row: JdProductItem, checked: boolean): void {
|
||||
const next = new Set(selectedIds.value)
|
||||
if (checked) next.add(row.id)
|
||||
else next.delete(row.id)
|
||||
selectedIds.value = next
|
||||
}
|
||||
|
||||
/** 工具栏「全选本页/取消本页」:按当前页行集增删勾选(跨页累计集里其他页的行不动)。 */
|
||||
function selectPage(): void {
|
||||
const next = new Set(selectedIds.value)
|
||||
for (const row of rows.value) next.add(row.id)
|
||||
selectedIds.value = next
|
||||
}
|
||||
|
||||
function unselectPage(): void {
|
||||
const next = new Set(selectedIds.value)
|
||||
for (const row of rows.value) next.delete(row.id)
|
||||
selectedIds.value = next
|
||||
}
|
||||
|
||||
/** 单行删除入口(详情弹窗顶部动作):确认弹窗点名商品编码与「桶内图片一并删除」。 */
|
||||
async function removeOne(row: JdProductItem): Promise<void> {
|
||||
await removeMany([row.id], `确定删除商品「${row.productCode || row.title}」吗?`)
|
||||
}
|
||||
|
||||
/** 批量删除入口(工具栏按钮):按累计勾选 id 直删(跨页的行也在内),确认弹窗点名总数。 */
|
||||
async function removeSelected(): Promise<void> {
|
||||
await removeMany([...selectedIds.value], `确定批量删除选中的 ${selectedIds.value.size} 个商品吗?`)
|
||||
}
|
||||
|
||||
/** 删除主流程:二次确认 → 先删桶、全成功才删库行(后端保证)→ 刷新列表并清勾选。 */
|
||||
async function removeMany(ids: number[], message: string): Promise<void> {
|
||||
if (!ids.length || deleting.value) return
|
||||
const ok = await openAdminConfirm({ title: '删除京东商品', message: `${message}删除后该商品的 SKU、图片登记与 jd-products 桶内图片文件一并删除(被其他商品共用的图片会保留);此操作不可恢复。`, confirmText: '确认删除', danger: true })
|
||||
if (!ok) return
|
||||
deleting.value = true
|
||||
try {
|
||||
const receipt = await deleteJdProducts(ids)
|
||||
showAdminFeedback(`已删除 ${receipt.deleted} 个商品,清理 ${receipt.objectsDeleted} 个图片文件` +
|
||||
(receipt.objectsKept ? `(${receipt.objectsKept} 个共用图片保留)` : ''), 'success')
|
||||
selectedIds.value = new Set()
|
||||
if (ids.length >= rows.value.length && page.value > 1) page.value -= 1
|
||||
await load()
|
||||
} catch (error) {
|
||||
const text = error instanceof Error && error.message ? error.message : '删除失败,请稍后重试'
|
||||
showAdminFeedback(text, 'error')
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 先解析作用域再取列表:首屏的 owner_group_id 必须与分类侧栏同一个组(铁律 30 同形——
|
||||
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
||||
await loadCategoryScope()
|
||||
void loadCategoryOptions()
|
||||
await load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="jd-database-view">
|
||||
<!-- 顶部通栏面板(2026-11-21 用户口径「放到上面筛选框」红框整体上移+同日 v1.7 对齐
|
||||
原型):单搜索框+筛选弹层+分组下拉+归属三档住通栏整行;批量按钮条随筛选行
|
||||
留在顶部通栏(红框上移口径不动)。主面板只剩回显条+卡片网格+分页条+已选条。 -->
|
||||
<section class="panel-box jd-top-panel">
|
||||
<div class="jd-filter-row">
|
||||
<!-- 合并搜索(v1.7 对齐原型):一个框同时搜商品编码与标题(OR 语义在后端 SQL,
|
||||
前端不拆词);Enter 查询;有词时出 × 清除按钮(清除即查)。 -->
|
||||
<div class="jd-search-wrap">
|
||||
<input
|
||||
v-model="filter.keyword"
|
||||
class="jd-search-input"
|
||||
type="text"
|
||||
placeholder="搜索商品编码或标题"
|
||||
aria-label="搜索商品"
|
||||
@keyup.enter="apply"
|
||||
/>
|
||||
<button
|
||||
v-if="filter.keyword"
|
||||
class="jd-search-clear"
|
||||
type="button"
|
||||
aria-label="清除搜索"
|
||||
@click="clearKeyword"
|
||||
>×</button>
|
||||
</div>
|
||||
<!-- 筛选弹层(v1.7 对齐原型):低频条件(价格区间+同步起止)收进按钮下方浮层,
|
||||
重置/应用在浮层底部;常驻的分组下拉与归属三档留在搜索行(v1.6 用户口径保留件)。 -->
|
||||
<div class="jd-filter-anchor">
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
type="button"
|
||||
:class="{ 'jd-filter-open': filterPopVisible }"
|
||||
@click="toggleFilterPopover"
|
||||
>筛选</button>
|
||||
<div v-if="filterPopVisible" class="jd-filter-popover">
|
||||
<div class="jd-pop-row">
|
||||
<label>价格区间</label>
|
||||
<div class="jd-pop-fields">
|
||||
<!-- 价格输入用 text+inputmode(不用 type=number):Vue 的 v-model 对
|
||||
type=number 会 looseToNumber 把 state 写成数字,filter 契约(字符串
|
||||
进、序列化层转 number)就断了;数字合法性由 finitePriceOrNull 在
|
||||
序列化口收口,倒挡校验在「应用」门口。 -->
|
||||
<input
|
||||
v-model="filter.minPrice"
|
||||
type="text"
|
||||
inputmode="decimal"
|
||||
placeholder="最低价"
|
||||
aria-label="最低价格"
|
||||
/>
|
||||
<span class="jd-pop-sep">~</span>
|
||||
<input
|
||||
v-model="filter.maxPrice"
|
||||
type="text"
|
||||
inputmode="decimal"
|
||||
placeholder="最高价"
|
||||
aria-label="最高价格"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jd-pop-row">
|
||||
<label>同步日期</label>
|
||||
<div class="jd-pop-fields">
|
||||
<input
|
||||
v-model="filter.syncedFrom"
|
||||
type="date"
|
||||
:max="filter.syncedTo"
|
||||
aria-label="同步开始日期"
|
||||
@change="clampJdSyncedRange"
|
||||
/>
|
||||
<span class="jd-pop-sep">~</span>
|
||||
<input
|
||||
v-model="filter.syncedTo"
|
||||
type="date"
|
||||
:min="filter.syncedFrom"
|
||||
aria-label="同步结束日期"
|
||||
@change="clampJdSyncedRange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jd-pop-actions">
|
||||
<button class="btn btn-secondary" type="button" @click="resetFromPopover">重置</button>
|
||||
<button class="btn" type="button" @click="applyFromPopover">应用</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="canFilterGroup && categoryScope.length" class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 当前分组(V203):超管档(平台/公司超管)专属——2026-11-17 用户口径
|
||||
「超管可以有分组筛选,管理员及以下则没有」,本控件对管理员及以下整块不渲染
|
||||
(其分类面固定落在作用域默认分组)。能看多组的人下拉切换;只有一组时锁定显示组名。
|
||||
分组是侧栏分类/分类筛选/分类管理的作用域,不是筛选条件 ⇒ 放在筛选行也只是占位,
|
||||
「重置」不清它(挂载测试钉住)。 -->
|
||||
<el-select
|
||||
v-if="canSwitchGroup"
|
||||
:model-value="ownerGroupId"
|
||||
class="admin-filter"
|
||||
filterable
|
||||
aria-label="当前分组"
|
||||
@change="changeOwnerGroup"
|
||||
>
|
||||
<el-option v-for="group in categoryScope" :key="group.id" :value="group.id" :label="group.label" />
|
||||
</el-select>
|
||||
<span v-else class="jd-group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
|
||||
</div>
|
||||
<!-- 归属三档快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」;2026-11-18
|
||||
「加个全部选项」恢复全量档;2026-11-21「默认改成全部」出厂默认卡 '';
|
||||
2026-11-22「文字也要改一下 默认全部」placeholder 同步改「全部」):
|
||||
已分类=当前分组下有分类(V203 归属表,与侧栏分类选中同形);三档下拉、
|
||||
出厂默认=「全部」(value=''),首屏即查当前分组全部商品(序列化不下发
|
||||
classified 参数,后端 required=false 跳过谓词);选中即查(回第一页);
|
||||
「重置」也回全部档。⚠ el-select 对 '' 值按空值处理(useSelect 的
|
||||
hasModelValue 把 '' 算空)⇒ 界面显示的是本 placeholder 而非「全部」选项的
|
||||
label,placeholder 文案必须与默认档同词「全部」;写回「未分类」=首屏
|
||||
灰字撒谎(逻辑已查全量、界面谎称卡未分类)。 -->
|
||||
<el-select
|
||||
v-model="filter.classified"
|
||||
class="admin-filter"
|
||||
placeholder="全部"
|
||||
aria-label="筛选分类状态"
|
||||
@change="apply"
|
||||
>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="已分类" value="classified" />
|
||||
<el-option label="未分类" value="ungrouped" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏(v1.6 重排,2026-11-21 按原型再调;同日红框整体上移,随筛选行住顶部
|
||||
通栏):全选本页/取消本页|删除商品|归入分类/取消归属(分类写档)——删除商品
|
||||
按原型并入按钮组(不再 margin-left:auto 推到行尾,原型里它紧跟「取消本页」);
|
||||
行级编辑/删除入口随操作列下线收进详情弹窗顶部动作区;勾选 0 时批量动作置灰
|
||||
(与旧批量删除同款常显口径)。列表加载失败条随行集住主面板,不随筛选上移。 -->
|
||||
<div v-if="hasSelection" class="jd-toolbar">
|
||||
<button class="btn btn-secondary" type="button" :disabled="!rows.length" @click="selectPage">全选本页</button>
|
||||
<button class="btn btn-secondary" type="button" :disabled="!selectedCount" @click="unselectPage">取消本页</button>
|
||||
<button
|
||||
v-if="canWriteProducts"
|
||||
class="btn btn-danger jd-delete-btn"
|
||||
type="button"
|
||||
:disabled="deleting || !selectedCount"
|
||||
@click="removeSelected"
|
||||
>
|
||||
{{ deleting ? '删除中...' : `删除商品(${selectedCount})` }}
|
||||
</button>
|
||||
<template v-if="canManageCategories">
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
type="button"
|
||||
:disabled="!selectedCount"
|
||||
@click="openBatchEdit"
|
||||
>归入分类</button>
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
type="button"
|
||||
:disabled="assigning || !selectedCount"
|
||||
@click="detachSelected"
|
||||
>取消归属</button>
|
||||
</template>
|
||||
</div>
|
||||
<!-- 商品行写对管理员级(超管+管理员)开放,普通账号看到只读提示;分类写由当前分组
|
||||
editable 决定(本组管理员/公司超管/平台超管),分类维护入口=侧栏「分类管理」
|
||||
(只读可看,写控件按 editable 分档)。 -->
|
||||
<span v-if="!canWriteProducts" class="jd-readonly-tip">只读:编辑/删除需超级管理员或管理员;分类在左侧「分类管理」查看与维护</span>
|
||||
</section>
|
||||
|
||||
<div class="jd-body">
|
||||
<!-- 左侧栏(v1.6 → v1.7 名单维度):商品目录(京麦授权类目树+计数徽标+树外兜底)/
|
||||
店铺分类(分类平铺+店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+
|
||||
分类管理入口)。取数在页面,侧栏纯展示。 -->
|
||||
<JdCategorySidebar
|
||||
:category-options="categoryOptions"
|
||||
:categories="groupOptions"
|
||||
:editable="canManageCategories"
|
||||
:selected-category="selectedCategoryInfo"
|
||||
:selected-group-id="selectedGroupIdNum"
|
||||
:selected-shop-name="filter.shopName"
|
||||
@select-category="onSelectCategory"
|
||||
@select-group="onSelectGroup"
|
||||
@select-shop="onSelectShop"
|
||||
@create-category="onCreateCategory"
|
||||
@rename-category="onRenameCategory"
|
||||
@delete-category="onDeleteCategory"
|
||||
@rename-shop="onRenameShop"
|
||||
@remove-shop="onRemoveShop"
|
||||
@add-shops="openAddShops"
|
||||
@manage-categories="openManage"
|
||||
/>
|
||||
|
||||
<section class="panel-box jd-main-panel">
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
|
||||
<!-- 筛选回显条(v1.7 F5 对齐原型):有激活筛选才渲染;芯片按当前筛选态逐条回显,
|
||||
「共 N 条」给行集规模,「清除筛选」回出厂空态(保留分组作用域,AC-4)。 -->
|
||||
<div v-if="filterActive" class="jd-filter-chips">
|
||||
<span v-for="chip in activeFilterChips" :key="chip.key" class="jd-chip">{{ chip.label }}</span>
|
||||
<span class="jd-chip-total">共 {{ total }} 条</span>
|
||||
<button class="jd-chip-clear" type="button" @click="reset">清除筛选</button>
|
||||
</div>
|
||||
|
||||
<!-- 卡片网格(v1.6):商城款式;卡片整体点击=开详情弹窗,勾选/复制 @click.stop 防冒泡。 -->
|
||||
<div class="jd-card-grid">
|
||||
<template v-if="rows.length">
|
||||
<JdProductCard
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
:item="row"
|
||||
:selected="selectedIds.has(row.id)"
|
||||
:selectable="hasSelection"
|
||||
@toggle-select="(checked: boolean) => toggleSelect(row, checked)"
|
||||
@open="openDetail(row)"
|
||||
@copy="copyProductCode(row)"
|
||||
/>
|
||||
</template>
|
||||
<div v-else-if="loading" class="jd-empty-tip">加载中...</div>
|
||||
<div v-else class="jd-empty-tip">暂无京东商品数据</div>
|
||||
</div>
|
||||
|
||||
<!-- 顶部分页条(v1.7 F4 对齐原型):「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/
|
||||
下一页/末页+每页条数档位(50/100/200/500/1000,与后端上限逐字同步)。
|
||||
本页底部 OldPagination 随 v1.7 撤下(组件本体不动,他页在用)。 -->
|
||||
<div class="jd-page-bar">
|
||||
<span class="jd-page-info">第 {{ page }} / {{ totalPages }} 页 · 共 {{ total }} 条</span>
|
||||
<div class="jd-page-btns">
|
||||
<button class="jd-page-btn" type="button" :disabled="page <= 1" @click="goFirstPage">首页</button>
|
||||
<button class="jd-page-btn" type="button" :disabled="page <= 1" @click="changePage(page - 1)">上一页</button>
|
||||
<button class="jd-page-btn" type="button" aria-label="刷新列表" @click="load">刷新</button>
|
||||
<button class="jd-page-btn" type="button" :disabled="page >= totalPages" @click="changePage(page + 1)">下一页</button>
|
||||
<button class="jd-page-btn" type="button" :disabled="page >= totalPages" @click="goLastPage">末页</button>
|
||||
</div>
|
||||
<el-select
|
||||
class="page-size-select"
|
||||
:model-value="pageSize"
|
||||
aria-label="每页条数"
|
||||
@change="changeSize"
|
||||
>
|
||||
<el-option
|
||||
v-for="size in JD_PRODUCT_PAGE_SIZE_OPTIONS"
|
||||
:key="size"
|
||||
:value="size"
|
||||
:label="`${size}条/页`"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<!-- 底部已选条(v1.7 F7 骨架):常驻悬浮(不随勾选数显隐);只对有勾选面的档渲染
|
||||
(普通员工没有勾选框,已选恒 0 无意义)。 -->
|
||||
<div v-if="hasSelection" class="jd-select-bar">已选 {{ selectedCount }} 件</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<JdBatchAssignDialog
|
||||
:visible="batchEditVisible"
|
||||
:owner-group-id="ownerGroupId"
|
||||
:owner-group-name="currentGroupName"
|
||||
:categories="groupOptions"
|
||||
:selected-ids="[...selectedIds]"
|
||||
@close="batchEditVisible = false"
|
||||
@done="onBatchAssigned"
|
||||
/>
|
||||
<!-- 添加店铺弹窗(v1.7 F6):侧栏「+ 添加店铺」行打开,弹窗自取候选(available)
|
||||
与批量提交,done 回执带新增行数给页面刷名单。 -->
|
||||
<JdShopPickerDialog
|
||||
:visible="addShopsVisible"
|
||||
:category-id="addShopsTarget?.id ?? 0"
|
||||
:category-name="addShopsTarget?.name ?? ''"
|
||||
@close="addShopsVisible = false"
|
||||
@done="onShopsAdded"
|
||||
/>
|
||||
<JdCategoryManageDialog
|
||||
:visible="manageVisible"
|
||||
:owner-group-id="ownerGroupId"
|
||||
:owner-group-name="currentGroupName"
|
||||
:editable="canManageCategories"
|
||||
:platform-super-admin="scopeSuperAdmin"
|
||||
@close="manageVisible = false"
|
||||
@changed="onManaged"
|
||||
@group-created="onGroupCreated"
|
||||
/>
|
||||
<JdProductDetailModal
|
||||
:item="detailItem"
|
||||
:visible="detailVisible"
|
||||
:can-write="canWriteProducts"
|
||||
@close="closeDetail"
|
||||
@edit="onDetailEdit"
|
||||
@remove="onDetailRemove"
|
||||
/>
|
||||
<JdProductEditDrawer
|
||||
:item="editItem"
|
||||
:visible="editVisible"
|
||||
@close="closeEdit"
|
||||
@saved="onEditSaved"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped src="./jd-database-page.css"></style>
|
||||
@@ -0,0 +1,263 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品卡片(v1.6 蓝图 Phase 3;v1.7 Phase 4 对齐原型交互):
|
||||
* 主图(无图占位)/店铺徽标/标题/价格区间/商品编码+复制/采集日期/勾选框,
|
||||
* 字段映射与现表格「商品信息」列逐字段同源(价格走 jdPriceRange、日期走 formatDateTime)。
|
||||
*
|
||||
* v1.7 交互增强(F7/F1):点图片区=切换勾选(可勾选档;不可勾选档点图照常开详情)、
|
||||
* 图片 hover 出「点击选择/点击取消」提示胶囊。(右上角「已下载」角标随 CSV 导出功能
|
||||
* 整体下线,2026-11-21 用户拍板「删除掉」导出按钮。)
|
||||
*
|
||||
* 2026-11-21 用户口径「这边改成分类名称就可以 自己分类的那个名称就可以」:图底条从
|
||||
* 店铺名改显归属分类名(groupName,后端 fillGroupNames 按当前分组补)——没归入分类的
|
||||
* 出「未分类」,条常驻渲染;店铺名不再上卡(详情弹窗仍可看)。
|
||||
*
|
||||
* 纯展示组件:入参=item+选中态+可勾选档;出事件=切换勾选、打开详情、
|
||||
* 复制编码。卡片整体点击=开详情;勾选与复制 @click.stop 防冒泡(与现表格行
|
||||
* @click.stop 同形)。healthScore 徽标随图渲染(现表格同款「信息分」),null 不渲染。 */
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { jdPriceRange, type JdProductItem } from './jd-product-model.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 列表行(解析层归一后的 JdProductItem)。 */
|
||||
item: JdProductItem
|
||||
/** 勾选态(页面持有,跨页累计记忆)。 */
|
||||
selected?: boolean
|
||||
/** 可勾选档:管理员级/本组可写分类账号才渲染勾选框(页面按 canWriteProducts∨canManageCategories 投影)。 */
|
||||
selectable?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 勾选切换(checked 来自 checkbox 原生 change 或点图片区)。 */
|
||||
(event: 'toggle-select', checked: boolean): void
|
||||
/** 打开详情(卡片整体点击;详情弹窗/抽屉由页面渲染)。 */
|
||||
(event: 'open'): void
|
||||
/** 复制商品编码(剪贴板与回执文案在页面,与现表格 copyText 同一条链)。 */
|
||||
(event: 'copy'): void
|
||||
}>()
|
||||
|
||||
const priceText = (): string => jdPriceRange(props.item) || '-'
|
||||
|
||||
/** 点图片区(v1.7 F7):可勾选档=切换勾选并阻止冒泡(点图不得误开详情);
|
||||
* 不可勾选档不拦不停,click 冒泡到卡片整体=照常开详情。 */
|
||||
function onFigureClick(event: MouseEvent): void {
|
||||
if (!props.selectable) return
|
||||
event.stopPropagation()
|
||||
emit('toggle-select', !props.selected)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="jd-card" :class="{ selected: props.selected }" @click="emit('open')">
|
||||
<label v-if="props.selectable" class="jd-card-check" @click.stop>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="props.selected"
|
||||
aria-label="勾选商品"
|
||||
@change="emit('toggle-select', ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</label>
|
||||
<div
|
||||
class="jd-card-figure"
|
||||
:class="{ 'jd-card-figure-pick': props.selectable }"
|
||||
@click="onFigureClick"
|
||||
>
|
||||
<img v-if="props.item.mainImageUrl" class="jd-card-thumb" :src="props.item.mainImageUrl" alt="" loading="lazy" />
|
||||
<span v-else class="jd-card-thumb jd-card-thumb-empty">无图</span>
|
||||
<!-- 右上角徽标:信息分(随图渲染,null 不出)。 -->
|
||||
<span class="jd-card-badges">
|
||||
<span v-if="props.item.healthScore !== null" class="jd-card-health">信息分 {{ props.item.healthScore }}</span>
|
||||
</span>
|
||||
<!-- hover 提示胶囊(v1.7):可勾选档才出,随选中态换文案。 -->
|
||||
<span v-if="props.selectable" class="jd-card-hover-tip">{{ props.selected ? '点击取消' : '点击选择' }}</span>
|
||||
<span class="jd-card-category" :title="props.item.groupName || '未分类'">{{ props.item.groupName || '未分类' }}</span>
|
||||
</div>
|
||||
<div class="jd-card-body">
|
||||
<div class="jd-card-title" :title="props.item.title">{{ props.item.title || '-' }}</div>
|
||||
<div class="jd-card-price">{{ priceText() }}</div>
|
||||
<div class="jd-card-meta">
|
||||
<span class="jd-card-code" :title="props.item.productCode">商品编码:{{ props.item.productCode || '-' }}</span>
|
||||
<button
|
||||
v-if="props.item.productCode"
|
||||
class="jd-card-copy"
|
||||
type="button"
|
||||
title="复制商品编码"
|
||||
@click.stop="emit('copy')"
|
||||
>⧉</button>
|
||||
</div>
|
||||
<div class="jd-card-date">采集:{{ formatDateTime(props.item.syncedAt || '') }}</div>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.jd-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #fff;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: box-shadow 0.15s, border-color 0.15s;
|
||||
}
|
||||
|
||||
.jd-card:hover {
|
||||
border-color: #c6e2ff;
|
||||
box-shadow: 0 2px 12px rgba(64, 158, 255, 0.12);
|
||||
}
|
||||
|
||||
.jd-card.selected {
|
||||
border-color: #409eff;
|
||||
box-shadow: 0 0 0 1px #409eff inset;
|
||||
}
|
||||
|
||||
.jd-card-check {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
z-index: 2;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-card-check input {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-card-figure {
|
||||
position: relative;
|
||||
aspect-ratio: 1 / 1;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
/* 可勾选档的图片区才是「点图切换勾选」热区;不可勾选档不加该类(点图冒泡开详情)。 */
|
||||
.jd-card-figure.jd-card-figure-pick {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-card-thumb {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.jd-card-thumb-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #c0c4cc;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* 右上角徽标容器:信息分徽标随图渲染(原「已下载」角标槽位随导出功能退役,容器保留)。 */
|
||||
.jd-card-badges {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 4px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.jd-card-health {
|
||||
background: rgba(255, 255, 255, 0.92);
|
||||
color: #e6a23c;
|
||||
font-size: 12px;
|
||||
border-radius: 10px;
|
||||
padding: 1px 8px;
|
||||
}
|
||||
|
||||
/* hover 提示胶囊:默认透明,图片区 hover 浮出(遮罩感=胶囊带半透明底)。 */
|
||||
.jd-card-hover-tip {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
padding: 4px 12px;
|
||||
border-radius: 999px;
|
||||
background: rgba(48, 49, 51, 0.66);
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.jd-card-figure-pick:hover .jd-card-hover-tip {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.jd-card-category {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
background: rgba(48, 49, 51, 0.62);
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
padding: 3px 8px;
|
||||
}
|
||||
|
||||
.jd-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 10px 12px 12px;
|
||||
}
|
||||
|
||||
.jd-card-title {
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
min-height: 2.8em;
|
||||
}
|
||||
|
||||
.jd-card-price {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.jd-card-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.jd-card-code {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.jd-card-copy {
|
||||
flex-shrink: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
color: #409eff;
|
||||
font-size: 13px;
|
||||
padding: 0 2px;
|
||||
}
|
||||
|
||||
.jd-card-date {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,636 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品详情内容块(v1.6 蓝图 Phase 4,从 JdProductDetailDrawer 原样抽出):
|
||||
* 数据自取(fetchJdProductDetail,失败条内可重试)+ hero「左图右信息」(2026-11-16 客户口径
|
||||
* 「详情页样式和京麦商品详情一样」)+ attrGroups 分块表格(解析失败回 attrJsonRaw 原文)+
|
||||
* SKU 矩阵 + 图片三区(MAIN/ATTR/DETAIL,attr 图按 attrName 归并)+ 自绘放大预览。
|
||||
*
|
||||
* Drawer(侧滑薄壳)与 Modal(居中弹窗壳)共用本组件:壳只管 chrome(遮罩/标题/关闭/
|
||||
* 动作按钮),内容与取数全在这里——两条壳的行为由同一份实现保证等价。模板与类名照搬
|
||||
* 旧抽屉(.detail-hero/.hero-main/.hero-info 等被页面 mount 测试逐字钉住,不得改名)。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { fetchJdProductDetail } from './jd-product-api.ts'
|
||||
import type {
|
||||
JdProductImage,
|
||||
JdProductItem,
|
||||
JdProductAttrGroup,
|
||||
JdProductSku,
|
||||
} from './jd-product-model.ts'
|
||||
import { jdPriceRange, jdSkuDimensions, jdSkuSummary } from './jd-product-model.ts'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
item: JdProductItem | null
|
||||
visible: boolean
|
||||
}>()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const attrGroups = ref<JdProductAttrGroup[]>([])
|
||||
const images = ref<JdProductImage[]>([])
|
||||
const skus = ref<JdProductSku[]>([])
|
||||
const attrJsonRaw = ref('')
|
||||
|
||||
/** SKU 矩阵维度(京麦「颜色 / 尺码」两列)与表头汇总。 */
|
||||
const skuDimensions = computed(() => jdSkuDimensions(skus.value))
|
||||
const skuSummary = computed(() => jdSkuSummary(skus.value))
|
||||
|
||||
function skuAttrValue(sku: JdProductSku, dimension: string): string {
|
||||
return sku.saleAttrs.find((attr) => attr.name === dimension)?.value || '-'
|
||||
}
|
||||
|
||||
/** 图片三区:MAIN / ATTR / DETAIL;未知类型归 DETAIL 之外的「其他」,不丢。 */
|
||||
const mainImages = computed(() => images.value.filter((image) => image.imageType === 'MAIN'))
|
||||
|
||||
/** 顶部画廊:左侧主图大图+缩略图切换(MAIN 档),右侧关键信息。 */
|
||||
const galleryImages = computed(() => mainImages.value)
|
||||
const activeImageUrl = ref('')
|
||||
|
||||
function switchGallery(image: JdProductImage): void {
|
||||
activeImageUrl.value = image.url
|
||||
}
|
||||
const attrImageGroups = computed(() => {
|
||||
const buckets = new Map<string, JdProductImage[]>()
|
||||
for (const image of images.value) {
|
||||
if (image.imageType !== 'ATTR') continue
|
||||
const key = image.attrName || '属性图'
|
||||
const bucket = buckets.get(key)
|
||||
if (bucket) bucket.push(image)
|
||||
else buckets.set(key, [image])
|
||||
}
|
||||
return [...buckets.entries()].map(([attrName, list]) => ({ attrName, list }))
|
||||
})
|
||||
const detailImages = computed(() => images.value.filter((image) => image.imageType === 'DETAIL'))
|
||||
const otherImages = computed(() =>
|
||||
images.value.filter((image) => image.imageType !== 'MAIN' && image.imageType !== 'ATTR' && image.imageType !== 'DETAIL'),
|
||||
)
|
||||
|
||||
/** 放大预览:点缩略图弹自绘 modal-mask,原图可新标签打开。 */
|
||||
const previewVisible = ref(false)
|
||||
const previewUrl = ref('')
|
||||
|
||||
function openPreview(url: string): void {
|
||||
previewUrl.value = url
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
async function loadDetail(): Promise<void> {
|
||||
const item = props.item
|
||||
if (!item) return
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
attrGroups.value = []
|
||||
images.value = []
|
||||
skus.value = []
|
||||
attrJsonRaw.value = ''
|
||||
try {
|
||||
const detail = await fetchJdProductDetail(item.id)
|
||||
attrGroups.value = detail.attrGroups
|
||||
images.value = detail.images
|
||||
skus.value = detail.skus
|
||||
attrJsonRaw.value = detail.attrJsonRaw
|
||||
activeImageUrl.value = detail.images.find((image) => image.imageType === 'MAIN')?.url || ''
|
||||
if (!detail.attrGroups.length && detail.attrJsonRaw) {
|
||||
// 结构化解析失败但原文在:兜底展示原文,不静默吞
|
||||
loadFailure.value = ''
|
||||
}
|
||||
} catch (error) {
|
||||
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开/换行即取数。immediate 必须带:两条壳都把本组件放在 `v-if="visible"` 的遮罩里,
|
||||
* 关闭时整组件卸载——重挂载(visible 已是 true)没有"变更"可触发,非 immediate 的
|
||||
* watch 永远不跑=弹窗永远停在加载中(2026-11-21 薄壳化实测真红)。 */
|
||||
watch(
|
||||
() => [props.visible, props.item?.id] as const,
|
||||
([visible]) => {
|
||||
previewVisible.value = false
|
||||
previewUrl.value = ''
|
||||
activeImageUrl.value = ''
|
||||
if (visible && props.item) void loadDetail()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function dash(value: string | number | null | undefined): string {
|
||||
const text = value === null || value === undefined ? '' : String(value).trim()
|
||||
return text || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 根节点随 visible 显隐:壳(Drawer/Modal)关闭时预览浮层必须一起摘掉,
|
||||
不能留在 fixed 蒙层里挡住整屏(旧抽屉的 v-if 边界原样搬移)。 -->
|
||||
<div v-if="visible" class="detail-content">
|
||||
<div v-if="loadFailure" class="drawer-failure">
|
||||
<span>{{ loadFailure }}</span>
|
||||
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
|
||||
</div>
|
||||
<p v-else-if="loading" class="drawer-tip">加载中...</p>
|
||||
|
||||
<template v-else>
|
||||
<!-- 顶部「左图右信息」(2026-11-16 客户口径「详情页的样式要和京麦商品详情一样的布局样式」):
|
||||
左侧主图大图+缩略图切换,右侧关键信息;属性/SKU/详情图等区块保持下方。 -->
|
||||
<section class="detail-block">
|
||||
<div class="detail-hero">
|
||||
<div class="hero-gallery">
|
||||
<img
|
||||
v-if="activeImageUrl"
|
||||
class="hero-main"
|
||||
:src="activeImageUrl"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(activeImageUrl)"
|
||||
/>
|
||||
<div v-else class="hero-empty">无图</div>
|
||||
<div v-if="galleryImages.length > 1" class="hero-thumbs">
|
||||
<img
|
||||
v-for="image in galleryImages"
|
||||
:key="image.id"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
loading="lazy"
|
||||
:class="{ active: image.url === activeImageUrl }"
|
||||
title="切换主图"
|
||||
@click="switchGallery(image)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<dl class="hero-info">
|
||||
<div class="info-item info-item-wide hero-title">
|
||||
<dt>标题</dt>
|
||||
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
|
||||
</div>
|
||||
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
|
||||
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
|
||||
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
|
||||
<div class="info-item"><dt>信息分</dt><dd>{{ dash(item?.healthScore) }}</dd></div>
|
||||
<div class="info-item"><dt>SKU 数</dt><dd>{{ dash(item?.skuCount) }}</dd></div>
|
||||
<div class="info-item"><dt>商品编码</dt><dd>{{ dash(item?.productCode) }}</dd></div>
|
||||
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.itemNum) }}</dd></div>
|
||||
<div class="info-item"><dt>SKU</dt><dd>{{ dash(item?.skuId) }}</dd></div>
|
||||
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
|
||||
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
|
||||
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
|
||||
<div class="info-item info-item-wide"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
|
||||
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
|
||||
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
|
||||
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
|
||||
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="attrGroups.length" class="detail-block">
|
||||
<h4>属性与设置(按京麦 Tab 分组)</h4>
|
||||
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
|
||||
<h5>{{ group.groupName }}</h5>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
|
||||
<th>{{ attr.label || attr.key || '-' }}</th>
|
||||
<td>{{ attr.value || '-' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-else-if="attrJsonRaw" class="detail-block">
|
||||
<h4>属性(原始 JSON)</h4>
|
||||
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>销售属性 / SKU 矩阵</h4>
|
||||
<template v-if="skus.length">
|
||||
<p class="sku-summary">{{ skuSummary }}</p>
|
||||
<div class="sku-table-wrap">
|
||||
<table class="sku-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>序号</th>
|
||||
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
|
||||
<th>京东价</th>
|
||||
<th>库存</th>
|
||||
<th>SKU ID</th>
|
||||
<th>SKU 名称</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(sku, index) in skus" :key="sku.skuId">
|
||||
<td>{{ sku.skuSeq || index + 1 }}</td>
|
||||
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
|
||||
<td>{{ sku.price ? `¥${sku.price}` : '-' }}</td>
|
||||
<td>{{ dash(sku.stock) }}</td>
|
||||
<td class="sku-id">{{ sku.skuId }}</td>
|
||||
<td :title="sku.skuName">{{ dash(sku.skuName) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>主图</h4>
|
||||
<div v-if="mainImages.length" class="image-grid">
|
||||
<img
|
||||
v-for="image in mainImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无主图</p>
|
||||
</section>
|
||||
|
||||
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
|
||||
<h4>属性图 · {{ bucket.attrName }}</h4>
|
||||
<div class="image-grid">
|
||||
<img
|
||||
v-for="image in bucket.list"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>详情图</h4>
|
||||
<div v-if="detailImages.length" class="image-grid">
|
||||
<img
|
||||
v-for="image in detailImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无详情图</p>
|
||||
</section>
|
||||
|
||||
<section v-if="otherImages.length" class="detail-block">
|
||||
<h4>其他图</h4>
|
||||
<div class="image-grid">
|
||||
<img
|
||||
v-for="image in otherImages"
|
||||
:key="image.url"
|
||||
:src="image.url"
|
||||
alt=""
|
||||
title="点击放大预览"
|
||||
@click="openPreview(image.url)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<div v-if="previewVisible" class="modal-mask" @click.self="previewVisible = false">
|
||||
<div class="preview-modal">
|
||||
<div class="preview-head">
|
||||
<h3>图片预览</h3>
|
||||
<button class="drawer-close" type="button" aria-label="关闭" @click="previewVisible = false">×</button>
|
||||
</div>
|
||||
<img class="preview-image" :src="previewUrl" alt="" />
|
||||
<div class="preview-foot">
|
||||
<a :href="previewUrl" target="_blank" rel="noopener">新标签打开原图</a>
|
||||
<button class="btn btn-secondary" type="button" @click="previewVisible = false">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.detail-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.drawer-tip {
|
||||
margin: 0;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.drawer-failure {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.detail-block h4 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 650;
|
||||
color: #4e6479;
|
||||
}
|
||||
/* 顶部「左图右信息」(京麦详情布局):左侧主图大图+缩略图切换,右侧关键信息网格。 */
|
||||
.detail-hero {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
.hero-gallery {
|
||||
flex: 0 0 300px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
.hero-main {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 10px;
|
||||
background: #f2f7fb;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.hero-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
border: 1px dashed #c7d7e5;
|
||||
border-radius: 10px;
|
||||
background: #f8fbfd;
|
||||
color: #8293a5;
|
||||
font-size: 13px;
|
||||
}
|
||||
.hero-thumbs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.hero-thumbs img {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.hero-thumbs img.active {
|
||||
outline: 2px solid #2f5d8b;
|
||||
opacity: 1;
|
||||
}
|
||||
.hero-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px 16px;
|
||||
margin: 0;
|
||||
}
|
||||
.hero-info dt {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.hero-info dd {
|
||||
margin: 0;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.hero-title dd {
|
||||
font-size: 14.5px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
white-space: normal;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.detail-hero {
|
||||
flex-direction: column;
|
||||
}
|
||||
.hero-gallery {
|
||||
flex-basis: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.info-item {
|
||||
min-width: 0;
|
||||
}
|
||||
.info-item-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.info-item dt {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.info-item dd {
|
||||
margin: 0;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.attr-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.attr-group h5 {
|
||||
margin: 0 0 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.attr-group table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.attr-group th,
|
||||
.attr-group td {
|
||||
padding: 7px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.attr-group th {
|
||||
width: 180px;
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.attr-group tr:last-child th,
|
||||
.attr-group tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.attr-raw {
|
||||
margin: 0;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 12px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.sku-summary {
|
||||
margin: 0 0 8px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.sku-table-wrap {
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.sku-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sku-table th,
|
||||
.sku-table td {
|
||||
padding: 7px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
text-align: left;
|
||||
color: #24384d;
|
||||
}
|
||||
.sku-table th {
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sku-table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.sku-table .sku-id {
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
color: #4e6479;
|
||||
}
|
||||
.image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.image-grid img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 8px;
|
||||
background: #f2f7fb;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.preview-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(880px, 100%);
|
||||
max-height: 88vh;
|
||||
padding: 16px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.preview-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.preview-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: #24384d;
|
||||
}
|
||||
.preview-image {
|
||||
display: block;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 68vh;
|
||||
margin: 12px 0;
|
||||
object-fit: contain;
|
||||
background: #f2f7fb;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.preview-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.preview-foot a {
|
||||
color: #2f5d8b;
|
||||
font-size: 13px;
|
||||
}
|
||||
.drawer-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.drawer-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border-radius: 9px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border: 1px solid #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,150 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品详情居中弹窗(v1.6 蓝图 Phase 4,additive——页面接线随 Phase 5):
|
||||
* 居中大弹窗壳(设计稿款式):顶部标题+「编辑/删除」动作(按写权限档渲染)+关闭,
|
||||
* 内容区=JdProductDetailContent 共享块(hero 左图右信息/属性分组/SKU 矩阵/图片三区/
|
||||
* 放大预览,数据自取)。壳不发请求、不碰业务链——编辑/删除 emit 给页面接既有链
|
||||
* (EditDrawer 与 removeOne),与现表格行操作同源。 */
|
||||
import JdProductDetailContent from './JdProductDetailContent.vue'
|
||||
import type { JdProductItem } from './jd-product-model.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 详情行(来自列表行集;内容块按 item.id 自取详情)。 */
|
||||
item: JdProductItem | null
|
||||
visible: boolean
|
||||
/** 写权限档(isAdminRole 投影):可写档顶部渲染「编辑/删除」,普通账号只读无动作。 */
|
||||
canWrite?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 关闭弹窗(mask 自身点击/右上 ×)。 */
|
||||
(event: 'close'): void
|
||||
/** 编辑(页面开 JdProductEditDrawer 既有链)。 */
|
||||
(event: 'edit'): void
|
||||
/** 删除(页面走 removeOne 既有链:确认弹窗→先桶后库)。 */
|
||||
(event: 'remove'): void
|
||||
}>()
|
||||
|
||||
const title = (): string =>
|
||||
`商品详情${props.item?.productCode ? ` · ${props.item.productCode}` : ''}`
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="props.visible" class="jd-modal-mask" @click.self="emit('close')">
|
||||
<div class="jd-modal" role="dialog" aria-label="商品详情">
|
||||
<header class="jd-modal-head">
|
||||
<h3>{{ title() }}</h3>
|
||||
<div v-if="props.canWrite" class="jd-modal-actions">
|
||||
<button class="jd-modal-btn" type="button" @click="emit('edit')">编辑</button>
|
||||
<button class="jd-modal-btn jd-modal-btn-danger" type="button" @click="emit('remove')">删除</button>
|
||||
</div>
|
||||
<button class="jd-modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</header>
|
||||
<div class="jd-modal-body">
|
||||
<JdProductDetailContent :item="props.item" :visible="props.visible" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.jd-modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.jd-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(1080px, 100%);
|
||||
max-height: 90vh;
|
||||
background: #ffffff;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.jd-modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
border-bottom: 1px solid #dbe5ee;
|
||||
}
|
||||
|
||||
.jd-modal-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.jd-modal-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.jd-modal-btn {
|
||||
min-height: 32px;
|
||||
padding: 4px 14px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #2f5d8b;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-modal-btn:hover {
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
|
||||
.jd-modal-btn-danger {
|
||||
color: #a04432;
|
||||
border-color: #f0c9c2;
|
||||
}
|
||||
|
||||
.jd-modal-btn-danger:hover {
|
||||
background: #fdf1ef;
|
||||
border-color: #e0a79c;
|
||||
}
|
||||
|
||||
.jd-modal-close {
|
||||
flex-shrink: 0;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jd-modal-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
|
||||
.jd-modal-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 16px 20px 28px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,616 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除;编辑的话
|
||||
* 这里面都是可以编辑的」):详情抽屉的可编辑版——基本信息/属性与设置/SKU 矩阵(价格、
|
||||
* 库存)/图片(标删)四块。形状照 JdProductDetailDrawer(自绘 drawer + 分块 + attr-group
|
||||
* 表格 + image-grid,零 element-plus)。
|
||||
* 保存语义在后端 JdProductUpdateService(PUT /api/admin/jd-products/{id}):主字段全量提交
|
||||
* +可选块(attrGroups 重建 attr_json 的 tabs 段、skus 按 skuId 改价格库存、deleteImageIds
|
||||
* 删图——先删桶、共用对象保留)。保存即置人工编辑锁 manual_locked=1:后续采集不再覆盖该行,
|
||||
* 底部常驻提示点名这件事。
|
||||
* V203(2026-11-16):分类<b>不在本抽屉编辑</b>(分类按数据权限分组隔离,归属存
|
||||
* biz_jd_product_group_assign,归类只走「店铺分类」弹窗)——原「分类」下拉与 groupId 负载已下线,
|
||||
* 避免写遗留的 biz_jd_product.group_id 列造成「界面改了、列表分组没变」。
|
||||
* 图片区拆在 JdProductImageManager 子组件(2026-11-16:× 右上角标删+替换/新增本地图,
|
||||
* B109-01 落地;标删集合经 update:deleteIds 上抛进保存负载,上传立即生效由子组件自理)。
|
||||
* 京东时间/信息分/商品编码只读。
|
||||
* 数据自取 fetchJdProductDetail 回填,保存成功用返回的刷新详情直接回填并 emit('saved')。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
fetchJdProductDetail,
|
||||
updateJdProduct,
|
||||
} from './jd-product-api.ts'
|
||||
import JdProductImageManager from './JdProductImageManager.vue'
|
||||
import type {
|
||||
JdProductAttrEntry,
|
||||
JdProductAttrGroup,
|
||||
JdProductImage,
|
||||
JdProductItem,
|
||||
JdProductSku,
|
||||
} from './jd-product-model.ts'
|
||||
import { jdSkuDimensions } from './jd-product-model.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
|
||||
const props = defineProps<{
|
||||
item: JdProductItem | null
|
||||
visible: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'saved'): void }>()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const saving = ref(false)
|
||||
/** 保存失败红条(后端校验/业务文案原样展示,如价格倒挂、SKU 行不存在)。 */
|
||||
const saveError = ref('')
|
||||
|
||||
// ---------------- 草稿(基本信息 + 属性 + SKU + 删图标记) ----------------
|
||||
|
||||
interface DraftAttrGroup {
|
||||
groupName: string
|
||||
attrs: JdProductAttrEntry[]
|
||||
}
|
||||
|
||||
const form = ref({
|
||||
title: '',
|
||||
brand: '',
|
||||
categoryPath: '',
|
||||
itemNum: '',
|
||||
priceMin: '',
|
||||
priceMax: '',
|
||||
stockTotal: '' as string,
|
||||
saleStatus: '',
|
||||
})
|
||||
const draftAttrGroups = ref<DraftAttrGroup[]>([])
|
||||
const draftSkus = ref<JdProductSku[]>([])
|
||||
const images = ref<JdProductImage[]>([])
|
||||
/** 图片子组件上抛的标删行 id(保存时一次提交 deleteImageIds)。 */
|
||||
const managerDeleteIds = ref<number[]>([])
|
||||
/** attr_json 解析失败(attrJsonRaw 兜底行):属性块禁用,防保存把原文形状弄丢。 */
|
||||
const attrJsonRaw = ref('')
|
||||
|
||||
const skuDimensions = computed(() => jdSkuDimensions(draftSkus.value))
|
||||
|
||||
function skuAttrValue(sku: JdProductSku, dimension: string): string {
|
||||
return sku.saleAttrs.find((attr) => attr.name === dimension)?.value || '-'
|
||||
}
|
||||
|
||||
function removeAttrRow(group: DraftAttrGroup, index: number): void {
|
||||
group.attrs.splice(index, 1)
|
||||
}
|
||||
|
||||
// ---------------- 取数与保存 ----------------
|
||||
|
||||
async function loadDetail(): Promise<void> {
|
||||
const item = props.item
|
||||
if (!item) return
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
saveError.value = ''
|
||||
try {
|
||||
const detail = await fetchJdProductDetail(item.id)
|
||||
const row = detail.item
|
||||
form.value = {
|
||||
title: row.title,
|
||||
brand: row.brand,
|
||||
categoryPath: row.categoryPath,
|
||||
itemNum: row.itemNum,
|
||||
priceMin: row.priceMin,
|
||||
priceMax: row.priceMax,
|
||||
stockTotal: row.stockTotal === null ? '' : String(row.stockTotal),
|
||||
saleStatus: row.saleStatus,
|
||||
}
|
||||
// 深拷贝草稿:直接改副本,保存前才拼负载。
|
||||
draftAttrGroups.value = detail.attrGroups.map((group: JdProductAttrGroup) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({ ...attr })),
|
||||
}))
|
||||
draftSkus.value = detail.skus.map((sku) => ({ ...sku }))
|
||||
images.value = detail.images
|
||||
managerDeleteIds.value = []
|
||||
attrJsonRaw.value = detail.attrJsonRaw
|
||||
} catch (error) {
|
||||
loadFailure.value = requestErrorMessage(error) || '商品详情加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
/** 保存:主字段全量 + 有改动的可选块。前端先拦「标题为空」(后端 @NotBlank 同判),失败红条。 */
|
||||
async function save(): Promise<void> {
|
||||
if (!props.item || saving.value) return
|
||||
saveError.value = ''
|
||||
if (!form.value.title.trim()) {
|
||||
saveError.value = '标题不能为空'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const detail = await updateJdProduct(props.item.id, {
|
||||
title: form.value.title.trim(),
|
||||
brand: form.value.brand.trim() || null,
|
||||
categoryPath: form.value.categoryPath.trim() || null,
|
||||
itemNum: form.value.itemNum.trim() || null,
|
||||
priceMin: form.value.priceMin.trim() || null,
|
||||
priceMax: form.value.priceMax.trim() || null,
|
||||
stockTotal: form.value.stockTotal.trim() === '' ? null : Number(form.value.stockTotal),
|
||||
saleStatus: form.value.saleStatus.trim() || null,
|
||||
// 属性块:原文兜底行(解析失败)不提交,防保存把解析不出的原文形状弄丢。
|
||||
attrGroups: attrJsonRaw.value
|
||||
? null
|
||||
: draftAttrGroups.value.map((group) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({
|
||||
key: attr.key,
|
||||
label: attr.label,
|
||||
value: attr.value,
|
||||
})),
|
||||
})),
|
||||
skus: draftSkus.value.length
|
||||
? draftSkus.value.map((sku) => ({
|
||||
skuId: sku.skuId,
|
||||
price: sku.price || null,
|
||||
stock: sku.stock,
|
||||
}))
|
||||
: null,
|
||||
deleteImageIds: managerDeleteIds.value.length ? [...managerDeleteIds.value] : null,
|
||||
})
|
||||
// 保存成功:用返回的刷新详情直接回填(图片行集已扣掉删掉的行、计数已刷新)。
|
||||
form.value.title = detail.item.title
|
||||
form.value.brand = detail.item.brand
|
||||
form.value.categoryPath = detail.item.categoryPath
|
||||
form.value.itemNum = detail.item.itemNum
|
||||
form.value.priceMin = detail.item.priceMin
|
||||
form.value.priceMax = detail.item.priceMax
|
||||
form.value.stockTotal = detail.item.stockTotal === null ? '' : String(detail.item.stockTotal)
|
||||
form.value.saleStatus = detail.item.saleStatus
|
||||
draftAttrGroups.value = detail.attrGroups.map((group) => ({
|
||||
groupName: group.groupName,
|
||||
attrs: group.attrs.map((attr) => ({ ...attr })),
|
||||
}))
|
||||
draftSkus.value = detail.skus.map((sku) => ({ ...sku }))
|
||||
images.value = detail.images
|
||||
managerDeleteIds.value = []
|
||||
showAdminFeedback('已保存,该商品已转为人工维护(采集不再覆盖)', 'success')
|
||||
emit('saved')
|
||||
} catch (error) {
|
||||
saveError.value = requestErrorMessage(error) || '保存失败,请稍后重试'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.visible, props.item?.id] as const,
|
||||
([visible]) => {
|
||||
if (visible && props.item) void loadDetail()
|
||||
},
|
||||
)
|
||||
|
||||
function dash(value: string | number | null | undefined): string {
|
||||
const text = value === null || value === undefined ? '' : String(value).trim()
|
||||
return text || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="drawer-mask" @click.self="close">
|
||||
<aside class="drawer">
|
||||
<header class="drawer-head">
|
||||
<h3>编辑商品{{ item?.productCode ? ` · ${item.productCode}` : '' }}</h3>
|
||||
<button class="drawer-close" type="button" aria-label="关闭" @click="close">×</button>
|
||||
</header>
|
||||
|
||||
<div class="drawer-body">
|
||||
<div v-if="loadFailure" class="drawer-failure">
|
||||
<span>{{ loadFailure }}</span>
|
||||
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
|
||||
</div>
|
||||
<p v-else-if="loading" class="drawer-tip">加载中...</p>
|
||||
|
||||
<template v-else>
|
||||
<section class="detail-block">
|
||||
<h4>基本信息</h4>
|
||||
<div class="edit-grid">
|
||||
<div class="edit-item edit-item-wide">
|
||||
<label>标题</label>
|
||||
<input v-model="form.title" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>品牌</label>
|
||||
<input v-model="form.brand" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>类目</label>
|
||||
<input v-model="form.categoryPath" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>货号(系统生成=行号,可改)</label>
|
||||
<input v-model="form.itemNum" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>状态</label>
|
||||
<input v-model="form.saleStatus" type="text" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>价格下限</label>
|
||||
<input v-model="form.priceMin" type="text" inputmode="decimal" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>价格上限</label>
|
||||
<input v-model="form.priceMax" type="text" inputmode="decimal" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>总库存</label>
|
||||
<input v-model="form.stockTotal" type="text" inputmode="numeric" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>商品编码(只读)</label>
|
||||
<input type="text" :value="dash(item?.productCode)" readonly class="readonly" />
|
||||
</div>
|
||||
<div class="edit-item">
|
||||
<label>信息分(只读)</label>
|
||||
<input type="text" :value="dash(item?.healthScore)" readonly class="readonly" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="draftAttrGroups.length" class="detail-block">
|
||||
<h4>属性与设置(键值可改,行可删)</h4>
|
||||
<div v-for="group in draftAttrGroups" :key="group.groupName" class="attr-group">
|
||||
<h5>{{ group.groupName }}</h5>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
|
||||
<th>{{ attr.label || attr.key || '-' }}</th>
|
||||
<td><input v-model="attr.value" type="text" class="attr-input" /></td>
|
||||
<td class="attr-remove-cell">
|
||||
<button class="attr-remove" type="button" title="删除该属性行" @click="removeAttrRow(group, index)">删</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<p v-else-if="attrJsonRaw" class="drawer-tip">属性原文解析失败(原始 JSON 兜底),属性区不可编辑以防丢失原文;可照常改基本信息。</p>
|
||||
<p v-else class="drawer-tip">暂无属性</p>
|
||||
|
||||
<section class="detail-block">
|
||||
<h4>SKU 矩阵(京东价 / 库存可改)</h4>
|
||||
<template v-if="draftSkus.length">
|
||||
<div class="sku-table-wrap">
|
||||
<table class="sku-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
|
||||
<th>京东价</th>
|
||||
<th>库存</th>
|
||||
<th>SKU ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="sku in draftSkus" :key="sku.skuId">
|
||||
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
|
||||
<td><input v-model="sku.price" type="text" inputmode="decimal" class="sku-input" /></td>
|
||||
<td>
|
||||
<input
|
||||
:value="sku.stock === null ? '' : String(sku.stock)"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
class="sku-input"
|
||||
@input="sku.stock = ($event.target as HTMLInputElement).value === '' ? null : Number(($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
</td>
|
||||
<td class="sku-id">{{ sku.skuId }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
|
||||
</section>
|
||||
|
||||
<JdProductImageManager
|
||||
:product-id="item?.id ?? 0"
|
||||
:images="images"
|
||||
:disabled="loading"
|
||||
@update:images="images = $event"
|
||||
@update:delete-ids="managerDeleteIds = $event"
|
||||
@saved="emit('saved')"
|
||||
/>
|
||||
|
||||
<div v-if="saveError" class="drawer-failure">{{ saveError }}</div>
|
||||
<p class="save-hint">保存后该商品转为人工维护,后续采集不再覆盖它的数据(含本单重爬);删除的图片文件一并从存储桶清理(共用的保留);替换 / 新增图片立即生效并同样置锁。</p>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<footer class="drawer-foot">
|
||||
<button class="btn btn-secondary" type="button" :disabled="saving" @click="close">取消</button>
|
||||
<button class="btn" type="button" :disabled="saving || loading" @click="save">
|
||||
{{ saving ? '保存中...' : '保存' }}
|
||||
</button>
|
||||
</footer>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.drawer-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2600;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
.drawer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(920px, 100%);
|
||||
height: 100%;
|
||||
background: #ffffff;
|
||||
box-shadow: -18px 0 40px rgba(39, 67, 94, 0.18);
|
||||
}
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #dbe5ee;
|
||||
}
|
||||
.drawer-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.drawer-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.drawer-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 16px 20px 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.drawer-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
border-top: 1px solid #dbe5ee;
|
||||
background: #f8fbfd;
|
||||
}
|
||||
.drawer-tip {
|
||||
margin: 0;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.drawer-failure {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.detail-block h4 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 650;
|
||||
color: #4e6479;
|
||||
}
|
||||
.edit-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px 16px;
|
||||
}
|
||||
.edit-item {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
.edit-item-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.edit-item label {
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
}
|
||||
.edit-item input,
|
||||
.edit-item select {
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.edit-item input:focus,
|
||||
.edit-item select:focus {
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.edit-item input.readonly {
|
||||
background: #f2f7fb;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.attr-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.attr-group h5 {
|
||||
margin: 0 0 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.attr-group table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.attr-group th,
|
||||
.attr-group td {
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.attr-group th {
|
||||
width: 180px;
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.attr-group tr:last-child th,
|
||||
.attr-group tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.attr-input {
|
||||
width: 100%;
|
||||
min-height: 32px;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 7px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.attr-input:focus {
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.attr-remove-cell {
|
||||
width: 44px;
|
||||
text-align: center;
|
||||
}
|
||||
.attr-remove {
|
||||
border: 1px solid #e4b3a8;
|
||||
border-radius: 6px;
|
||||
background: #ffffff;
|
||||
color: #a04432;
|
||||
font-size: 12px;
|
||||
padding: 3px 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.attr-remove:hover {
|
||||
background: #fdf1ef;
|
||||
}
|
||||
.sku-table-wrap {
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.sku-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sku-table th,
|
||||
.sku-table td {
|
||||
padding: 6px 10px;
|
||||
border-bottom: 1px solid #e7eef5;
|
||||
text-align: left;
|
||||
color: #24384d;
|
||||
}
|
||||
.sku-table th {
|
||||
background: #f2f7fb;
|
||||
color: #4e6479;
|
||||
font-weight: 600;
|
||||
}
|
||||
.sku-table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.sku-input {
|
||||
width: 110px;
|
||||
min-height: 32px;
|
||||
padding: 5px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 7px;
|
||||
background: #ffffff;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.sku-input:focus {
|
||||
border-color: #5f85ad;
|
||||
}
|
||||
.sku-id {
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
color: #4e6479;
|
||||
}
|
||||
.save-hint {
|
||||
margin: 0;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #cfe3f5;
|
||||
border-radius: 10px;
|
||||
background: #eef5fc;
|
||||
color: #3b6d99;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border-radius: 9px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border: 1px solid #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn:not(.btn-secondary) {
|
||||
border: 1px solid #4f78a5;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn:not(.btn-secondary):hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,300 @@
|
||||
<script setup lang="ts">
|
||||
/** 京东商品编辑抽屉「图片区」子组件(2026-11-16 从 JdProductEditDrawer 拆出:编辑抽屉
|
||||
* 856 行超后管 800 报警线,图片区自洽成件——× 右上角标删+hover 替换+新增主图,
|
||||
* B109-01 落地,2026-11-16 客户口径「删除做成打叉的 icon 放图右上角,也要支持编辑
|
||||
* 替换本地的图」)。
|
||||
*
|
||||
* 交互语义:× 标删=前端标记、随父级「保存」一并提交(deleteImageIds 上抛);替换/新增
|
||||
* =multipart 立即生效(服务端置锁+刷投影),上传成功用返回详情回填本区并上抛 saved。
|
||||
* objectKey 由服务端按上传字节 sha256 内容寻址生成(铁律 32),前端不自造 key。
|
||||
* 形状照 JdProductEditDrawer 原图片区(image-grid + image-cell,零 element-plus)。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { uploadJdProductImage } from './jd-product-api.ts'
|
||||
import type { JdProductImage } from './jd-product-model.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
|
||||
const props = defineProps<{
|
||||
productId: number
|
||||
images: JdProductImage[]
|
||||
/** 父级 loading 中禁上传入口。 */
|
||||
disabled: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(event: 'update:images', images: JdProductImage[]): void
|
||||
(event: 'update:deleteIds', ids: number[]): void
|
||||
(event: 'saved'): void
|
||||
}>()
|
||||
|
||||
/** 标删的图片行 id(前端只标记,父级保存时一次提交 deleteImageIds)。 */
|
||||
const deleteImageIds = ref<Set<number>>(new Set())
|
||||
|
||||
function toggleDeleteImage(image: JdProductImage): void {
|
||||
const next = new Set(deleteImageIds.value)
|
||||
if (next.has(image.id)) next.delete(image.id)
|
||||
else next.add(image.id)
|
||||
deleteImageIds.value = next
|
||||
emit('update:deleteIds', [...next])
|
||||
}
|
||||
|
||||
// ---------------- 图片上传/替换(立即生效,与标删的「保存时生效」不同) ----------------
|
||||
|
||||
/** 文件选择上下文:null=新增主图;有值=替换该登记行(档位继承原行,后端语义)。 */
|
||||
const pendingReplaceImageId = ref<number | null>(null)
|
||||
const fileInputRef = ref<HTMLInputElement | null>(null)
|
||||
/** 上传中的图行 id(0=新增上传中);上传期间防重复点。 */
|
||||
const uploadingImageId = ref<number | null>(null)
|
||||
const uploadError = ref('')
|
||||
|
||||
function pickImage(replaceImageId: number | null): void {
|
||||
if (uploadingImageId.value !== null || props.disabled) return
|
||||
uploadError.value = ''
|
||||
pendingReplaceImageId.value = replaceImageId
|
||||
// 同选一张图也要重触发 change:先清值再弹窗。
|
||||
if (fileInputRef.value) {
|
||||
fileInputRef.value.value = ''
|
||||
fileInputRef.value.click()
|
||||
}
|
||||
}
|
||||
|
||||
async function onFileChosen(event: Event): Promise<void> {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
if (!file || props.disabled) return
|
||||
uploadingImageId.value = pendingReplaceImageId.value ?? 0
|
||||
try {
|
||||
const detail = await uploadJdProductImage(props.productId, file, pendingReplaceImageId.value
|
||||
? { replaceImageId: pendingReplaceImageId.value }
|
||||
: { imageType: 'MAIN' })
|
||||
// 立即生效:用返回详情回填图片区(标删集合里已不存在的行 id 由 images watch 清理)。
|
||||
emit('update:images', detail.images)
|
||||
showAdminFeedback(pendingReplaceImageId.value ? '图片已替换(该商品已转为人工维护)' : '图片已新增(该商品已转为人工维护)', 'success')
|
||||
emit('saved')
|
||||
} catch (error) {
|
||||
uploadError.value = requestErrorMessage(error) || '图片上传失败,请稍后重试'
|
||||
} finally {
|
||||
uploadingImageId.value = null
|
||||
pendingReplaceImageId.value = null
|
||||
input.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
/** 换商品打开时标删集合必须清零(父级 loadDetail 换 item.id)。 */
|
||||
watch(() => props.productId, () => {
|
||||
deleteImageIds.value = new Set()
|
||||
emit('update:deleteIds', [])
|
||||
})
|
||||
|
||||
/** 行集变化时清掉已不存在的标删 id(保存删行回填/上传回填两路共用;不清理的话
|
||||
* 下次保存会把已删的 id 再提交一遍=后端按「图片不存在」整笔拒绝)。 */
|
||||
watch(() => props.images, (images) => {
|
||||
const live = new Set(images.map((image) => image.id))
|
||||
const next = new Set([...deleteImageIds.value].filter((id) => live.has(id)))
|
||||
if (next.size !== deleteImageIds.value.size) {
|
||||
deleteImageIds.value = next
|
||||
emit('update:deleteIds', [...next])
|
||||
}
|
||||
})
|
||||
|
||||
const markedCount = computed(() => deleteImageIds.value.size)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="detail-block">
|
||||
<div class="image-head">
|
||||
<h4>图片(右上角 × 标记删除,保存时一并删除;替换 / 新增立即生效)</h4>
|
||||
<button class="btn-add-image" type="button" :disabled="uploadingImageId !== null || disabled" @click="pickImage(null)">
|
||||
{{ uploadingImageId === 0 ? '上传中...' : '+ 新增主图' }}
|
||||
</button>
|
||||
</div>
|
||||
<input ref="fileInputRef" type="file" accept="image/jpeg,image/png,image/webp,image/gif" hidden @change="onFileChosen" />
|
||||
<div v-if="images.length" class="image-grid">
|
||||
<div
|
||||
v-for="image in images"
|
||||
:key="`${image.id}-${image.url}`"
|
||||
class="image-cell"
|
||||
:class="{ marked: deleteImageIds.has(image.id) }"
|
||||
>
|
||||
<img
|
||||
:src="image.url"
|
||||
alt=""
|
||||
loading="lazy"
|
||||
:class="{ dimmed: deleteImageIds.has(image.id) || uploadingImageId === image.id }"
|
||||
/>
|
||||
<!-- 右上角 × 删除标记(京麦样式,2026-11-16 客户口径):点 × 标记,再点撤销。 -->
|
||||
<button
|
||||
class="image-x"
|
||||
type="button"
|
||||
:title="deleteImageIds.has(image.id) ? '撤销删除标记' : '标记删除(保存时一并删除)'"
|
||||
@click="toggleDeleteImage(image)"
|
||||
>×</button>
|
||||
<!-- 标删遮罩(整格可点撤销),未标删时 hover 底部出现「替换」条。 -->
|
||||
<button
|
||||
v-if="deleteImageIds.has(image.id)"
|
||||
class="image-marked-mask"
|
||||
type="button"
|
||||
title="点击撤销删除标记"
|
||||
@click="toggleDeleteImage(image)"
|
||||
>已标记删除 · 点击撤销</button>
|
||||
<button
|
||||
v-else
|
||||
class="image-replace"
|
||||
type="button"
|
||||
:disabled="uploadingImageId !== null"
|
||||
@click="pickImage(image.id)"
|
||||
>{{ uploadingImageId === image.id ? '上传中...' : '替换' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="drawer-tip">暂无图片(可点右上「+ 新增主图」上传本地图)</p>
|
||||
<p v-if="uploadError" class="drawer-failure">{{ uploadError }}</p>
|
||||
<p v-if="markedCount" class="delete-count">已标记删除 {{ markedCount }} 张,保存后剩余 {{ images.length - markedCount }} 张</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.image-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.image-head h4 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 650;
|
||||
color: #4e6479;
|
||||
}
|
||||
.btn-add-image {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #95b1cb;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #2f5d8b;
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.btn-add-image:hover {
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-add-image:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.image-cell {
|
||||
position: relative;
|
||||
}
|
||||
.image-cell img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
object-fit: cover;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 8px;
|
||||
background: #f2f7fb;
|
||||
}
|
||||
.image-cell img.dimmed {
|
||||
opacity: 0.35;
|
||||
}
|
||||
.image-cell.marked img {
|
||||
outline: 2px solid #d08a7b;
|
||||
}
|
||||
/* 右上角 × 删除标记(京麦样式):hover 格子时出现;已标删常显。 */
|
||||
.image-x {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(38, 50, 63, 0.72);
|
||||
color: #ffffff;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.image-cell:hover .image-x,
|
||||
.image-cell.marked .image-x {
|
||||
display: flex;
|
||||
}
|
||||
.image-x:hover {
|
||||
background: #a04432;
|
||||
}
|
||||
/* 标删态:整格遮罩可点撤销。 */
|
||||
.image-marked-mask {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 6px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: rgba(160, 68, 50, 0.32);
|
||||
color: #ffffff;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
cursor: pointer;
|
||||
}
|
||||
.image-marked-mask:hover {
|
||||
background: rgba(160, 68, 50, 0.5);
|
||||
}
|
||||
/* hover 底部替换条(京麦替换入口);上传中常显。 */
|
||||
.image-replace {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 26px;
|
||||
border: none;
|
||||
border-radius: 0 0 8px 8px;
|
||||
background: rgba(38, 50, 63, 0.72);
|
||||
color: #ffffff;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.image-cell:hover .image-replace {
|
||||
display: flex;
|
||||
}
|
||||
.image-cell .image-replace:disabled {
|
||||
display: flex;
|
||||
background: rgba(38, 50, 63, 0.55);
|
||||
cursor: wait;
|
||||
}
|
||||
.image-replace:hover {
|
||||
background: #2f5d8b;
|
||||
}
|
||||
.delete-count {
|
||||
margin: 10px 0 0;
|
||||
color: #a04432;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.drawer-tip {
|
||||
margin: 0;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.drawer-failure {
|
||||
margin: 10px 0 0;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,439 @@
|
||||
<script setup lang="ts">
|
||||
/** 添加店铺弹窗(v1.7 F6 对齐原型《商品数据商城》的「店铺名单维度」):
|
||||
* 侧栏店铺分类 Tab 展开某分类后的「+ 添加店铺」行打开。候选=服务端
|
||||
* fetchJdAvailableShops(biz_jd_product.shop_name DISTINCT,关键词包含匹配+排除本分类
|
||||
* 已有名单,limit ≤ 200——商品行 shop_name 是京麦店铺全名,与名单来源同源);
|
||||
* 勾选候选+手输自定义项(不在候选里的新店名)合并成一个待添加清单,一次批量提交
|
||||
* (服务侧 trim/去重/上限 100,INSERT IGNORE 幂等跳过已存在行,回执=实际新增行数)。
|
||||
* 结构复制 JdBatchAssignDialog(modal-mask+modal-head/tip/foot 同款皮肤)。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { addJdGroupShops, fetchJdAvailableShops } from './jd-product-api.ts'
|
||||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 目标分类(名单挂在分类下)。 */
|
||||
categoryId: number
|
||||
categoryName: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', added: number, categoryName: string): void }>()
|
||||
|
||||
/** 候选搜索(关键词输入后手动点「搜索」或 Enter 触发——不随输入逐键打后端)。 */
|
||||
const keyword = ref('')
|
||||
const candidates = ref<string[]>([])
|
||||
const searching = ref(false)
|
||||
const searched = ref(false)
|
||||
/** 待添加清单(勾选的候选+手输自定义项,Set 保序去重)。 */
|
||||
const pending = ref<string[]>([])
|
||||
/** 手输自定义项输入框。 */
|
||||
const customName = ref('')
|
||||
const submitting = ref(false)
|
||||
const errorText = ref('')
|
||||
|
||||
/** 批量上限与服务端 JdGroupShopService.MAX_ADD_SHOPS 同值(文案点名 100)。 */
|
||||
const MAX_ADD_SHOPS = 100
|
||||
|
||||
const canSubmit = computed(() => pending.value.length > 0 && !submitting.value)
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
keyword.value = ''
|
||||
candidates.value = []
|
||||
searched.value = false
|
||||
pending.value = []
|
||||
customName.value = ''
|
||||
errorText.value = ''
|
||||
// 打开即拉一次空关键词候选(让用户不输词也有东西可勾)。
|
||||
void search()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
async function search(): Promise<void> {
|
||||
searching.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
candidates.value = await fetchJdAvailableShops(keyword.value, props.categoryId)
|
||||
searched.value = true
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '候选店铺加载失败'
|
||||
} finally {
|
||||
searching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCandidate(name: string): void {
|
||||
const index = pending.value.indexOf(name)
|
||||
if (index >= 0) pending.value = pending.value.filter((item) => item !== name)
|
||||
else pending.value = [...pending.value, name]
|
||||
}
|
||||
|
||||
/** 手输自定义项:空白不收;与待添加清单重复不收(静默忽略——清单里已有就是同一个)。 */
|
||||
function addCustom(): void {
|
||||
const name = customName.value.trim()
|
||||
if (!name) return
|
||||
if (!pending.value.includes(name)) pending.value = [...pending.value, name]
|
||||
customName.value = ''
|
||||
}
|
||||
|
||||
function removePending(name: string): void {
|
||||
pending.value = pending.value.filter((item) => item !== name)
|
||||
}
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (!canSubmit.value) return
|
||||
submitting.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
const added = await addJdGroupShops(props.categoryId, pending.value)
|
||||
emit('done', added, props.categoryName)
|
||||
emit('close')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '添加店铺失败'
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||||
<div class="shop-picker-modal">
|
||||
<div class="modal-head">
|
||||
<h3>添加店铺<span v-if="categoryName" class="modal-sub">· {{ categoryName }}</span></h3>
|
||||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||||
</div>
|
||||
<p class="modal-tip">
|
||||
从已采集商品的店铺里勾选,或手动输入名单里还没有的店铺名;
|
||||
一次最多添加 {{ MAX_ADD_SHOPS }} 个,已有的会自动跳过。
|
||||
</p>
|
||||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||||
|
||||
<!-- 候选搜索:关键词包含匹配(服务端 DISTINCT+like),Enter 或按钮触发。 -->
|
||||
<div class="shop-search">
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
placeholder="搜索店铺名"
|
||||
aria-label="候选店铺关键词"
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
<button type="button" :disabled="searching" @click="search">{{ searching ? '搜索中...' : '搜索' }}</button>
|
||||
</div>
|
||||
|
||||
<ul class="shop-candidate-list">
|
||||
<li v-if="searching" class="shop-list-tip">搜索中...</li>
|
||||
<li v-else-if="!candidates.length && searched" class="shop-list-tip">没有可添加的候选店铺(已采商品的店铺都在名单里了,试试手动输入)</li>
|
||||
<li
|
||||
v-for="name in candidates"
|
||||
:key="name"
|
||||
class="shop-candidate-row"
|
||||
:class="{ active: pending.includes(name) }"
|
||||
:title="name"
|
||||
@click="toggleCandidate(name)"
|
||||
>
|
||||
<span class="shop-check" aria-hidden="true"></span>
|
||||
<span class="shop-name">{{ name }}</span>
|
||||
<span v-if="pending.includes(name)" class="shop-picked-tag">已选</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- 手输自定义项+待添加清单(chips 可移除)。 -->
|
||||
<div class="shop-custom">
|
||||
<input
|
||||
v-model="customName"
|
||||
type="text"
|
||||
placeholder="手动输入店铺名(自定义)"
|
||||
aria-label="自定义店铺名"
|
||||
@keyup.enter="addCustom"
|
||||
/>
|
||||
<button type="button" :disabled="!customName.trim() || pending.length >= MAX_ADD_SHOPS" @click="addCustom">加入</button>
|
||||
</div>
|
||||
<div v-if="pending.length" class="shop-pending">
|
||||
<span v-for="name in pending" :key="name" class="shop-chip">
|
||||
{{ name }}
|
||||
<button type="button" :aria-label="`移除待添加 ${name}`" @click="removePending(name)">×</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
|
||||
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
|
||||
{{ submitting ? '提交中...' : `添加(${pending.length})` }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2800;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
background: rgba(45, 66, 86, 0.36);
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
.shop-picker-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(460px, 100%);
|
||||
max-height: 80vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||||
}
|
||||
.modal-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.modal-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-sub {
|
||||
margin-left: 6px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.modal-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 9px;
|
||||
background: none;
|
||||
color: #5b6f83;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.modal-close:hover {
|
||||
border-color: #cbd9e6;
|
||||
background: #eef4fa;
|
||||
color: #24384d;
|
||||
}
|
||||
.modal-tip {
|
||||
margin: 8px 0 10px;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.group-error {
|
||||
margin: 0 0 8px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #f0c9c2;
|
||||
border-radius: 10px;
|
||||
background: #fdf1ef;
|
||||
color: #a04432;
|
||||
font-size: 13px;
|
||||
}
|
||||
.shop-search {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.shop-search input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.shop-search input:focus {
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.shop-search button {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.shop-search button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.shop-candidate-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
margin: 0 0 10px;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border: 1px solid #e7eef5;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.shop-candidate-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 9px 10px;
|
||||
border-bottom: 1px solid #eef3f8;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.shop-candidate-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.shop-candidate-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.shop-candidate-row.active {
|
||||
background: #e8f1fa;
|
||||
box-shadow: inset 3px 0 0 #4f78a5;
|
||||
}
|
||||
.shop-check {
|
||||
flex: none;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 1.6px solid #9fb7cd;
|
||||
border-radius: 4px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.shop-candidate-row.active .shop-check {
|
||||
border-color: #4f78a5;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
box-shadow: inset 0 0 0 2.4px #ffffff;
|
||||
}
|
||||
.shop-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #24384d;
|
||||
}
|
||||
.shop-picked-tag {
|
||||
flex: none;
|
||||
padding: 1px 7px;
|
||||
border-radius: 9px;
|
||||
background: #d9ecff;
|
||||
color: #2f5d8b;
|
||||
font-size: 12px;
|
||||
}
|
||||
.shop-list-tip {
|
||||
padding: 22px 12px;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
text-align: center;
|
||||
}
|
||||
.shop-custom {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.shop-custom input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
}
|
||||
.shop-custom input:focus {
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.shop-custom button {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.shop-custom button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.shop-pending {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.shop-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 6px 3px 10px;
|
||||
border-radius: 999px;
|
||||
background: #e8f1f9;
|
||||
color: #3d5a77;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.shop-chip button {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: #c9dcea;
|
||||
color: #3d5a77;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.shop-chip button:hover {
|
||||
background: #b3cde4;
|
||||
}
|
||||
.modal-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 38px;
|
||||
padding: 7px 16px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,447 @@
|
||||
/* 京东数据库页样式(v1.6 蓝图 Phase 5 重写装配 → v1.7 对齐原型):顶部通栏(搜索行+
|
||||
工具栏)+横排体(左侧栏类目树/分类平铺+主面板:回显条+卡片网格+分页条+已选条)。
|
||||
旧自绘表格样式随操作列/表格退役整体摘除;列表字段映射收进 JdProductCard scoped 样式,
|
||||
本文件只管页面装配层。
|
||||
2026-11-21 用户口径四件:①面板删标题行(筛选往上摆,原型顶栏直接开始);
|
||||
②筛选行收窄字段宽让归属三档并入一行;③左右高度对齐——stretch 让侧栏随主面板拉满;
|
||||
④「放到上面筛选框」红框整体上移——筛选行+批量按钮条离开主面板、提到页面最顶
|
||||
(提示条正下方、通栏整行),外层改纵向排:顶部通栏在上,侧栏+主面板横排在下。
|
||||
v1.7(同日对齐原型《商品数据商城》)追加五件:合并搜索框(× 清除)、筛选按钮下方
|
||||
absolute 浮层(价格区间+同步起止+重置/应用)、筛选回显条(条件芯片+共 N 条+
|
||||
清除筛选)、自绘顶部分页条(OldPagination 从本页撤下)、底部已选条(sticky 悬浮)。 */
|
||||
.jd-database-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
/* ④红框整体上移:外层由「侧栏+主面板」横排改纵向——顶部通栏面板在上,
|
||||
侧栏+主面板的横排体(.jd-body)在下。间距与全局密度规则对齐取 10px
|
||||
(.admin-content > [class$="-view"] 本来就会压掉 16px,别靠覆盖链猜)。 */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
/* 顶部通栏面板:筛选行+批量按钮条整行铺开(面板盒皮肤复用 .panel-box)。 */
|
||||
.jd-top-panel {
|
||||
min-width: 0;
|
||||
}
|
||||
/* 侧栏+主面板横排体(原 .jd-database-view 的横排形状整体挪进来):
|
||||
左右高度对齐——stretch 让侧栏随主面板拉到同高,侧栏内部滚动区吃剩余高度。 */
|
||||
.jd-body {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
/* 主面板在「侧栏+主区」横排体(.jd-body)里吃掉剩余宽度;窄屏(侧栏 232px 起占位)
|
||||
允许整行折行由 .jd-body 的 flex-wrap 兜住,面板自身保持弹性收缩。 */
|
||||
.jd-main-panel {
|
||||
flex: 1 1 480px;
|
||||
min-width: 0;
|
||||
}
|
||||
.jd-filter-row {
|
||||
/* 可换行流式布局:固定网格在窄面板下最小宽超出容器,把尾部的归属下拉挤出面板右缘。
|
||||
flex-wrap 让放不下的项自然折行。v1.7 起内容=搜索框+筛选弹层锚点+分组+归属三档。 */
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: flex-end;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.jd-filter-row .form-group {
|
||||
/* 「分组」表单组(label+下拉/锁定芯片):固定宽不再吃 flex(搜索框独占主弹性,
|
||||
分组收窄到内容宽)。 */
|
||||
flex: 0 1 auto;
|
||||
min-width: 150px;
|
||||
max-width: 220px;
|
||||
}
|
||||
/* 合并搜索框(v1.7 对齐原型):吃掉搜索行的主弹性;relative 壳给 × 清除按钮定位。 */
|
||||
.jd-search-wrap {
|
||||
position: relative;
|
||||
flex: 1 1 260px;
|
||||
min-width: 220px;
|
||||
max-width: 420px;
|
||||
}
|
||||
.jd-search-input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
/* 34px 与筛选行两个 el-select.admin-filter(main.css 密度规则 250 行)同高——
|
||||
2026-11-21 用户口径「高度不一样」:搜索框原来是 42px 旧档,行内三件参差。 */
|
||||
min-height: 34px;
|
||||
padding: 5px 34px 5px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.jd-search-input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.jd-search-input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.jd-search-clear {
|
||||
position: absolute;
|
||||
right: 6px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: #dbe7f1;
|
||||
color: #5b6f83;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
transition: background 120ms ease, color 120ms ease;
|
||||
}
|
||||
.jd-search-clear:hover {
|
||||
background: #c7d9e8;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
/* 筛选弹层锚点:relative 给浮层「按钮下方 absolute」定位(v1.7 对齐原型)。 */
|
||||
.jd-filter-anchor {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
/* 筛选按钮激活态(弹层开着时描一圈主色,提示当前条件挂在它下面)。 */
|
||||
.jd-filter-anchor .jd-filter-open {
|
||||
border-color: #5f85ad;
|
||||
color: #2f5d8b;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.jd-filter-popover {
|
||||
position: absolute;
|
||||
top: calc(100% + 8px);
|
||||
left: 0;
|
||||
z-index: 30;
|
||||
width: 300px;
|
||||
padding: 14px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 12px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 18px 42px -22px rgba(39, 67, 94, 0.45);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.jd-pop-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.jd-pop-row > label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.jd-pop-fields {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.jd-pop-fields input {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
min-height: 36px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.jd-pop-fields input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.jd-pop-sep {
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.jd-pop-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
.jd-pop-actions .btn {
|
||||
min-height: 34px;
|
||||
padding: 5px 14px;
|
||||
}
|
||||
/* 筛选回显条(v1.7 F5):条件芯片+共 N 条+清除筛选;无激活筛选不渲染(v-if 在模板)。 */
|
||||
.jd-filter-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 10px;
|
||||
margin-bottom: 12px;
|
||||
border: 1px solid #e3ecf4;
|
||||
border-radius: 9px;
|
||||
background: #f6fafd;
|
||||
}
|
||||
.jd-chip {
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
background: #e8f1f9;
|
||||
color: #3d5a77;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-chip-total {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-chip-clear {
|
||||
margin-left: auto;
|
||||
padding: 2px 6px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #4f78a5;
|
||||
font-size: 12.5px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-chip-clear:hover {
|
||||
color: #2f5d8b;
|
||||
}
|
||||
/* 顶部分页条(v1.7 F4):页码信息+五键+档位下拉;OldPagination 从本页撤下后的替身。 */
|
||||
.jd-page-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.jd-page-info {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.jd-page-btns {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.jd-page-btn {
|
||||
min-height: 32px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
|
||||
}
|
||||
.jd-page-btn:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
}
|
||||
.jd-page-btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
/* 档位下拉:42px 外壳由全局 .el-select.admin-filter 皮肤出——这里只补宽度与左侧外距。
|
||||
.page-size-select 定位类保留(旧分页条的定位约定,测试与人工定位都认它)。 */
|
||||
.jd-page-bar > .el-select.admin-filter,
|
||||
.jd-page-bar > .page-size-select {
|
||||
width: 120px;
|
||||
margin-left: auto;
|
||||
}
|
||||
/* 底部已选条(v1.7 F7 骨架):主面板底部 sticky 悬浮,滚动到列表深处也看得见勾选规模。 */
|
||||
.jd-select-bar {
|
||||
position: sticky;
|
||||
bottom: 8px;
|
||||
z-index: 10;
|
||||
margin-top: 12px;
|
||||
padding: 9px 16px;
|
||||
border: 1px solid #cfdff0;
|
||||
border-radius: 10px;
|
||||
background: #eef6fd;
|
||||
color: #2f5d8b;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 -6px 18px -14px rgba(39, 67, 94, 0.5);
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
/* 归属三档下拉(分类状态快筛):42px 外壳、9px 圆角、#cbd9e6 描边与 focus ring 都由
|
||||
全局 .el-select.admin-filter 皮肤(main.css)出——与亚马逊面同一套。收窄到 150px
|
||||
并进筛选行主体(2026-11-21「往上摆」:不再单独折一行);用直接子级选择器,
|
||||
别误伤「分组」表单组里嵌的同款下拉(那个跟 form-group 走宽)。 */
|
||||
.jd-filter-row > .el-select.admin-filter {
|
||||
width: 150px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
/* 工具栏(v1.6 重排,2026-11-21 按原型调序;同日红框整体上移随筛选行住顶部通栏面板):
|
||||
全选本页/取消本页|删除商品|归入分类/取消归属。删除商品并入按钮组(原型里紧跟
|
||||
「取消本页」),不再推到行尾;顶部面板里位于筛选行下、(主面板的)卡片网格上一行,
|
||||
通栏整行放得下不再折行。它在顶部面板是最后一行,底边距归零不吃面板内边距。 */
|
||||
.jd-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
.jd-top-panel .jd-toolbar {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.jd-toolbar .btn {
|
||||
min-height: 34px;
|
||||
padding: 5px 14px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
/* 危险动作(删除商品):与全站 .btn-danger 同形——实心红渐变+白字。 */
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
/* 非超管只读提示(2026-11-16 写权限收窄):工具栏下方的一句话说明,不冒充可点按钮。 */
|
||||
.jd-readonly-tip {
|
||||
display: block;
|
||||
color: #8293a5;
|
||||
font-size: 12.5px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.jd-top-panel .jd-readonly-tip {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片,
|
||||
与同排 el-select 同高同壳(42px/9px 圆角),"一组锁定"和"多组下拉"两种形态占位一致。 */
|
||||
.jd-group-locked {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 42px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 9px;
|
||||
background: #f1f6fb;
|
||||
color: #4e6479;
|
||||
font-size: 13.5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
/* 卡片网格(v1.6):自适应列数的商城款式;窄屏最小 170px 保住编码行不折断。 */
|
||||
.jd-card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: 14px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.jd-empty-tip {
|
||||
grid-column: 1 / -1;
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
border: 1px dashed #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
/* 窄屏:侧栏收回横排体(.jd-body)顶部整行(树/分类平铺横向铺开高度可控),主面板
|
||||
落在下面;顶部通栏面板本就是整行,不受影响。 */
|
||||
@media (max-width: 980px) {
|
||||
.jd-body {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.jd-body > :first-child {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
/** 京东数据库查询适配(v1.4 Phase 5 → v1.7 对齐原型):GET /api/admin/jd-products +
|
||||
* 删除(DELETE /{id} + POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
|
||||
* CSV 导出已下线(2026-11-21 用户拍板「删除掉」导出按钮,exportJdProductsCsv 同步摘除;
|
||||
* 后端 POST /export 端点暂留,下一 jar 发版窗再收)。
|
||||
* 公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」):全页零公司维度——
|
||||
* 只读列表与类目下拉的 company_id 发送口已随公司 tab 摘除(后端读侧谓词同窗撤,重上时
|
||||
* 从 git 历史找回),详情/编辑/删除/分组管理本就不带;行 company_id 列仍是同步来源标记、
|
||||
* 随详情下发。反向钉在 company-tab-wiring「公司维度不得回流」清单。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
toJdProductListParams,
|
||||
type JdProductListParams,
|
||||
} from './jd-product-filter.ts'
|
||||
import {
|
||||
parseJdProductDetail,
|
||||
parseJdProductPage,
|
||||
type JdProductPageResult,
|
||||
} from './jd-product-model.ts'
|
||||
|
||||
export const JD_PRODUCT_ENDPOINT = '/api/admin/jd-products'
|
||||
export const JD_PRODUCT_GROUP_ENDPOINT = '/api/admin/jd-product-groups'
|
||||
|
||||
export async function fetchJdProductList(
|
||||
params: JdProductListParams,
|
||||
): Promise<JdProductPageResult> {
|
||||
const query = toJdProductListParams(
|
||||
{
|
||||
keyword: params.keyword ?? '',
|
||||
category: params.category ?? '',
|
||||
categoryPath: params.categoryPath ?? [],
|
||||
shopName: params.shopName ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
|
||||
minPrice: params.minPrice ?? '',
|
||||
maxPrice: params.maxPrice ?? '',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
},
|
||||
params.page,
|
||||
params.pageSize,
|
||||
params.ownerGroupId ?? null,
|
||||
)
|
||||
// category 多值(父级展开集合)必须序列化成重复 `category=a&category=b`:axios 默认
|
||||
// 给数组加 `[]` 后缀,后端 @RequestParam("category") List<String> 认不到。
|
||||
// indexes:false = 无括号无下标的重复键(axios 1.x 官方口径)。
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, {
|
||||
params: query,
|
||||
paramsSerializer: { indexes: false },
|
||||
})
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
|
||||
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。
|
||||
* 公共库无公司维度,按 id 直取;分类字段按「当前分组」(owner_group_id)取(V203)。 */
|
||||
export async function fetchJdProductDetail(
|
||||
id: number,
|
||||
ownerGroupId?: number | null,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const params = typeof ownerGroupId === 'number' && ownerGroupId > 0
|
||||
? { owner_group_id: ownerGroupId }
|
||||
: undefined
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, { params })
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
/** 删除回执(后端 JdProductDeleteVo):三个对象计数分开报——真删的、共用的、前缀外不敢动的。 */
|
||||
export interface JdProductDeleteResult {
|
||||
deleted: number
|
||||
imagesDeleted: number
|
||||
objectsDeleted: number
|
||||
objectsKept: number
|
||||
objectsSkipped: number
|
||||
}
|
||||
|
||||
/** 删除是先删桶、全成功才删库行(后端 JdProductDeleteService);失败文案原样抛给页面。
|
||||
* 公共库写侧无公司维度(2026-11-15 用户定案)。 */
|
||||
export async function deleteJdProducts(
|
||||
ids: number[],
|
||||
): Promise<JdProductDeleteResult> {
|
||||
if (ids.length === 1) {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_ENDPOINT}/${ids[0]}`)
|
||||
return unwrap<JdProductDeleteResult>(data)
|
||||
}
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-delete`, { ids })
|
||||
return unwrap<JdProductDeleteResult>(data)
|
||||
}
|
||||
|
||||
/** 编辑提交负载(PUT /api/admin/jd-products/{id} body,后端 JdProductUpdateRequest):
|
||||
* 主字段全量提交;attrGroups/skus/deleteImageIds 可选——null=不修改该块
|
||||
* (后端对 null 块零触碰)。分类不在本负载里(V203:分类按数据权限分组归属存
|
||||
* biz_jd_product_group_assign,编辑面不写 group_id,归类只走列表页「批量编辑分类」)。 */
|
||||
export interface JdProductUpdatePayload {
|
||||
title: string
|
||||
brand: string | null
|
||||
categoryPath: string | null
|
||||
itemNum: string | null
|
||||
priceMin: string | null
|
||||
priceMax: string | null
|
||||
stockTotal: number | null
|
||||
saleStatus: string | null
|
||||
attrGroups: { groupName: string; attrs: { key: string; label: string; value: string }[] }[] | null
|
||||
skus: { skuId: string; price: string | null; stock: number | null }[] | null
|
||||
deleteImageIds: number[] | null
|
||||
}
|
||||
|
||||
/** 编辑保存(PUT):主字段保存即置人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);
|
||||
* 失败文案原样抛给抽屉红条。公共库写侧无公司维度。返回刷新后的详情(与
|
||||
* fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
||||
export async function updateJdProduct(
|
||||
id: number,
|
||||
payload: JdProductUpdatePayload,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload)
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
/** 图片上传参数(POST /{id}/images multipart):replaceImageId 有值=替换该登记行
|
||||
* (后端继承原行档位,imageType/attrName 忽略);缺省=新增(imageType=MAIN/DETAIL,
|
||||
* ATTR 需带 attrName)。objectKey 由服务端按上传字节 sha256 内容寻址生成(铁律 32),
|
||||
* 前端不自造 key。返回刷新后的详情(与 fetchJdProductDetail 同一信封)。 */
|
||||
export interface JdProductImageUploadParams {
|
||||
replaceImageId?: number
|
||||
imageType?: 'MAIN' | 'ATTR' | 'DETAIL'
|
||||
attrName?: string
|
||||
}
|
||||
|
||||
/** 上传/替换商品图片(multipart 后端中转):上传/替换即生效(服务端立即落库并置
|
||||
* 人工编辑锁),与「删图保存时批量生效」不同。失败文案原样抛给抽屉。 */
|
||||
export async function uploadJdProductImage(
|
||||
id: number,
|
||||
file: File,
|
||||
params: JdProductImageUploadParams,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const body = new FormData()
|
||||
body.append('file', file)
|
||||
if (params.replaceImageId != null) {
|
||||
body.append('replace_image_id', String(params.replaceImageId))
|
||||
}
|
||||
if (params.imageType) body.append('image_type', params.imageType)
|
||||
if (params.attrName) body.append('attr_name', params.attrName)
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}/images`, body, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
/** 分组行(GET 列表返回:[{id,name,ownerGroupId,sortOrder,productCount,shops}])。
|
||||
* shops=该分类下的店铺名单(v1.7 V214 店铺名单维度,后端列表响应每行带;可选字段——
|
||||
* 旧夹具/消费方不传按空名单处理,Phase 3 侧栏名单交互读它)。 */
|
||||
export interface JdProductGroup {
|
||||
id: number
|
||||
name: string
|
||||
ownerGroupId: number
|
||||
sortOrder: number
|
||||
productCount: number
|
||||
shops?: string[]
|
||||
}
|
||||
|
||||
/** 分组管理的写入负载(POST / PUT body:{name, sortOrder, ownerGroupId?})。 */
|
||||
export interface JdProductGroupPayload {
|
||||
name: string
|
||||
sortOrder: number
|
||||
/** 新建时归属的数据权限分组(缺省=操作者自己带的组,后端 requireWritableGroup 收敛)。 */
|
||||
ownerGroupId?: number | null
|
||||
}
|
||||
|
||||
/** 「当前分组」下拉的一项(GET /scope 的 groups[],V203):editable=本账号对该组分类可写
|
||||
* (建/改名/删除/归类)。跨组长的组名由后端拼进 label(2026-11-21 用户口径「不是选公司
|
||||
* 是选超管/管理员」:前缀=组长账号名),前端不解析公司/组长字段。 */
|
||||
export interface JdCategoryGroupOption {
|
||||
id: number
|
||||
name: string
|
||||
label: string
|
||||
editable: boolean
|
||||
}
|
||||
|
||||
/** 分类作用域回执(GET /api/admin/jd-product-groups/scope):分组下拉 + 平台超管标记。 */
|
||||
export interface JdCategoryScope {
|
||||
platformSuperAdmin: boolean
|
||||
defaultGroupId: number | null
|
||||
groups: JdCategoryGroupOption[]
|
||||
}
|
||||
|
||||
/** 分组信封是 `{code, message, data}` 三段式:code 非 0 =业务失败,message 是中文文案
|
||||
* (重名等),用 errorTextOf 取出来抛给界面展示(unwrap 只认 success=false,不认 code)。 */
|
||||
function groupDataOf<T>(payload: unknown): T {
|
||||
const record = payload && typeof payload === 'object' ? (payload as Record<string, unknown>) : null
|
||||
if (record && typeof record.code === 'number' && record.code !== 0) {
|
||||
throw new Error(errorTextOf(payload))
|
||||
}
|
||||
return unwrap<T>(payload)
|
||||
}
|
||||
|
||||
function numberOr(value: unknown, fallback: number): number {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
|
||||
}
|
||||
|
||||
/** 分组下拉/管理列表:按「当前分组」(owner_group_id)取该组的分类(V203,跨组不可见);
|
||||
* 缺省=后端按作用域默认分组取。失败由页面自己兜(分类只是筛选项,不拦首屏行集)。 */
|
||||
export async function fetchJdProductGroups(ownerGroupId?: number | null): Promise<JdProductGroup[]> {
|
||||
const params = typeof ownerGroupId === 'number' && ownerGroupId > 0
|
||||
? { owner_group_id: ownerGroupId }
|
||||
: undefined
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT, { params })
|
||||
const core = unwrap<unknown>(data)
|
||||
if (!Array.isArray(core)) return []
|
||||
const out: JdProductGroup[] = []
|
||||
for (const raw of core) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOr(record.id, 0)
|
||||
if (id <= 0) continue
|
||||
// 店铺名单(v1.7 V214):后端按店名升序给数组;前端只滤空白不重排(排序语义在服务端)。
|
||||
const shops = Array.isArray(record.shops)
|
||||
? record.shops
|
||||
.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
|
||||
.map((shop) => shop.trim())
|
||||
: []
|
||||
out.push({
|
||||
id,
|
||||
name: typeof record.name === 'string' ? record.name.trim() : '',
|
||||
ownerGroupId: numberOr(record.ownerGroupId ?? record.owner_group_id, 0),
|
||||
sortOrder: numberOr(record.sortOrder ?? record.sort_order, 0),
|
||||
productCount: numberOr(record.productCount ?? record.product_count, 0),
|
||||
shops,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 分类作用域(GET /scope):本账号可见的数据权限分组 + 每组可写标记。
|
||||
* 页面用它渲染「分组」下拉并按 editable 渲染分类写入口;失败由页面自己兜(回空作用域=
|
||||
* 分类列全空、分类管理页提示不属于任何分组,但商品列表照常可用)。 */
|
||||
export async function fetchJdCategoryScope(): Promise<JdCategoryScope> {
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/scope`)
|
||||
const core = groupDataOf<unknown>(data)
|
||||
const record = core && typeof core === 'object' ? (core as Record<string, unknown>) : {}
|
||||
const rawGroups = Array.isArray(record.groups) ? record.groups : []
|
||||
const groups: JdCategoryGroupOption[] = []
|
||||
for (const raw of rawGroups) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const row = raw as Record<string, unknown>
|
||||
const id = numberOr(row.id, 0)
|
||||
if (id <= 0) continue
|
||||
const name = typeof row.name === 'string' ? row.name.trim() : ''
|
||||
groups.push({
|
||||
id,
|
||||
name,
|
||||
label: typeof row.label === 'string' && row.label.trim() ? row.label.trim() : name,
|
||||
editable: row.editable === true,
|
||||
})
|
||||
}
|
||||
return {
|
||||
platformSuperAdmin: record.platformSuperAdmin === true || record.platform_super_admin === true,
|
||||
defaultGroupId: numberOr(record.defaultGroupId ?? record.default_group_id, 0) || null,
|
||||
groups,
|
||||
}
|
||||
}
|
||||
|
||||
/** 类目下拉选项(GET /categories 返回 [{name, productCount}],name=京麦末级类目即
|
||||
* 落库的 category_path;等值过滤)。失败由页面自己兜(类目只是筛选项,不拦首屏行集)。 */
|
||||
export interface JdProductCategoryOption {
|
||||
name: string
|
||||
productCount: number
|
||||
}
|
||||
|
||||
export async function fetchJdProductCategories(): Promise<JdProductCategoryOption[]> {
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/categories`)
|
||||
const core = unwrap<unknown>(data)
|
||||
if (!Array.isArray(core)) return []
|
||||
const out: JdProductCategoryOption[] = []
|
||||
for (const raw of core) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const record = raw as Record<string, unknown>
|
||||
const name = typeof record.name === 'string' ? record.name.trim() : ''
|
||||
if (!name) continue
|
||||
out.push({ name, productCount: numberOr(record.productCount ?? record.product_count, 0) })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 新建分类(归属当前分组,V203):ownerGroupId 缺省=后端取操作者自己带的组;
|
||||
* 同一分组内重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||
export async function createJdProductGroup(
|
||||
payload: JdProductGroupPayload,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
if (typeof payload.ownerGroupId === 'number' && payload.ownerGroupId > 0) {
|
||||
body.ownerGroupId = payload.ownerGroupId
|
||||
}
|
||||
const { data } = await http.post<unknown>(JD_PRODUCT_GROUP_ENDPOINT, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
|
||||
/** 改名/改排序;业务失败文案同上。 */
|
||||
export async function updateJdProductGroup(
|
||||
id: number,
|
||||
payload: JdProductGroupPayload,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
|
||||
/** 删除分组;业务失败文案同上。 */
|
||||
export async function deleteJdProductGroup(id: number): Promise<void> {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`)
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
/** 批量人工归类(2026-11-17 起唯一入口=京东数据库页工具栏「批量编辑分类」;
|
||||
* 旧「店铺分类弹窗+工具栏移除分类」已随同日口径下线):勾选商品行(跨页累计)
|
||||
* → 归入当前分组(ownerGroupId)的指定分类或移出分类(V203:归属写
|
||||
* biz_jd_product_group_assign 的 (product_id, owner_group_id) 一行,同一商品各组可各自归类)。
|
||||
* groupId 传 null=移出本组分类;返回实际写入/解挂的归属行数。
|
||||
* 归类<b>不再置人工编辑锁</b>(2026-11-16 用户拍板):分类不在商品行上,采集冲不掉它。
|
||||
* 业务失败(分类不存在/不属于当前分组)把中文文案抛回,对话框红条原样展示。 */
|
||||
export async function batchAssignJdProductGroup(
|
||||
ids: number[],
|
||||
groupId: number | null,
|
||||
ownerGroupId: number,
|
||||
): Promise<number> {
|
||||
const body: Record<string, unknown> = { ids, groupId, ownerGroupId }
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-assign-group`, body)
|
||||
return groupDataOf<number>(data)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 店铺名单(v1.7 F6,V214)
|
||||
|
||||
/** 名单行形状=纯店名字符串(GET /{id}/shops 返回 shop_name 升序数组)。 */
|
||||
|
||||
/** 某分类的店铺名单(服务端已升序;前端只滤空白不重排)。失败文案原样抛给调用方。 */
|
||||
export async function fetchJdGroupShops(categoryId: number): Promise<string[]> {
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`)
|
||||
const core = groupDataOf<unknown>(data)
|
||||
return Array.isArray(core)
|
||||
? core
|
||||
.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
|
||||
.map((shop) => shop.trim())
|
||||
: []
|
||||
}
|
||||
|
||||
/** 批量添加店铺到分类名单(弹窗勾选候选+手输自定义项合并下发):服务侧 trim/去空/
|
||||
* 去重/上限 100,INSERT IGNORE 幂等跳过已存在行;返回实际新增行数(全重复=0 不报错)。 */
|
||||
export async function addJdGroupShops(categoryId: number, shopNames: string[]): Promise<number> {
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, { shopNames })
|
||||
return groupDataOf<number>(data)
|
||||
}
|
||||
|
||||
/** 移除分类名单里的店铺(删 (分类, 店铺名) 那一行);该分类下不存在时后端按业务错误拒绝。 */
|
||||
export async function removeJdGroupShop(categoryId: number, shopName: string): Promise<void> {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, {
|
||||
params: { shop_name: shopName },
|
||||
})
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
/** 改名分类名单里的店铺:老名必须在该名单里,新名同分类查重 409;
|
||||
* 名单改名只更新名单表(商品归类不带店铺维,无原型 assignment 同步链)。 */
|
||||
export async function renameJdGroupShop(categoryId: number, oldName: string, newName: string): Promise<void> {
|
||||
const { data } = await http.patch<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops/rename`, {
|
||||
oldName,
|
||||
newName,
|
||||
})
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
/** 可添加的店铺候选(biz_jd_product.shop_name DISTINCT +关键词包含匹配+排除指定分类
|
||||
* 已有名单;limit ≤ 200 服务侧钳制)。商品是全平台公共的,候选同样全平台去重。 */
|
||||
export async function fetchJdAvailableShops(
|
||||
keyword: string,
|
||||
excludeCategoryId?: number | null,
|
||||
limit?: number,
|
||||
): Promise<string[]> {
|
||||
const params: Record<string, unknown> = {}
|
||||
const trimmed = (keyword || '').trim()
|
||||
if (trimmed) params.keyword = trimmed
|
||||
if (typeof excludeCategoryId === 'number' && excludeCategoryId > 0) {
|
||||
params.exclude_category_id = excludeCategoryId
|
||||
}
|
||||
if (typeof limit === 'number' && limit > 0) params.limit = limit
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/shops/available`, { params })
|
||||
const core = groupDataOf<unknown>(data)
|
||||
return Array.isArray(core)
|
||||
? core.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
|
||||
: []
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/** 京东数据库页筛选纯函数(v1.7 对齐原型《商品数据商城》):合并搜索/类目/店铺/分组/
|
||||
* 归属三档/价格区间/同步起止 + snake 分页参数。
|
||||
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 50、上限 1000——v1.7
|
||||
* 与后端 JdProductQueryService.MAX_PAGE_SIZE 逐字同步放宽,契约测试钉着这两个数)、
|
||||
* `keyword`(v1.7 合并搜索:后端 `product_code LIKE OR title LIKE`,OR 语义在 SQL 段;
|
||||
* 旧 `product_code`/`title_keyword` 两参数后端保留兼容但前端停发)、`shop_name`
|
||||
* (v1.7 店铺名单点选,精确 eq)、`min_price`/`max_price`(v1.7 价格区间:商品区间完全
|
||||
* 落在筛选区间内)、`category`(京麦末级类目等值过滤,2026-11-15 增)、
|
||||
* `group_id`(当前分组下的分类 id)、`owner_group_id`(当前数据权限分组,V203)、
|
||||
* `synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
|
||||
* 商品状态筛选与 json/txt/CSV 导出均从前端下线(CSV v1.7 曾恢复,2026-11-21 用户拍板
|
||||
* 「删除掉」导出按钮,exportJdProductsCsv 同步摘除)。
|
||||
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
|
||||
* 最大 999_900 档在 10×1000 时为 9_999_000,Number.MAX_SAFE_INTEGER 也顶不出去。
|
||||
* 纯逻辑,node --test 直测。
|
||||
* 公司维已整页摘除(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」):归一化构造器
|
||||
* 与入参类型都不认识 company_id——读侧发送口已随公司 tab 撤下(品牌库 2026-10-06 先例同形)。
|
||||
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
|
||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
|
||||
|
||||
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 1000
|
||||
* (v1.7 对齐原型档位 50/100/200/500/1000,与后端 MAX_PAGE_SIZE 逐字同步——契约
|
||||
* 测试两侧钉着,改这里必须同窗改 JdProductQueryService.MAX_PAGE_SIZE)。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE = 50
|
||||
export const JD_PRODUCT_MAX_PAGE_SIZE = 1000
|
||||
/** 每页条数档位(v1.7 对齐原型:50/100/200/500/1000,原 20 档退役):页面装配层的
|
||||
* 档位选择器从这里取数,不再各写各的字面量。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE_OPTIONS = [50, 100, 200, 500, 1000] as const
|
||||
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
|
||||
export const JD_PRODUCT_MAX_PAGE = 10_000
|
||||
/** 分类状态快筛的出厂档位(2026-11-21 用户口径「默认改成全部」,推翻 11-17「默认卡在
|
||||
* 未分类上就行」;''=全部档):首屏/重置都卡它;非空档(已分类/未分类)才算激活筛选。 */
|
||||
export const JD_PRODUCT_DEFAULT_CLASSIFIED = '' as const
|
||||
|
||||
/** 价格输入 → 有限数:空白/非数字回 null(不下发,后端 BigDecimal 侧也不认脏值)。 */
|
||||
export function finitePriceOrNull(raw: string): number | null {
|
||||
const text = (raw || '').trim()
|
||||
if (!text) return null
|
||||
const value = Number(text)
|
||||
return Number.isFinite(value) ? value : null
|
||||
}
|
||||
|
||||
export interface JdProductFilterState {
|
||||
/** 合并搜索词(v1.7 对齐原型:一个框同时搜商品编码与标题,OR 语义在后端 SQL)。
|
||||
* 旧 productCode/titleKeyword 两框随 v1.7 前端下线(后端参数保留兼容在飞请求)。 */
|
||||
keyword: string
|
||||
/** 类目(京麦类目名,末级或父级;选项来自侧栏商品目录树),空串=全部类目。 */
|
||||
category: string
|
||||
/** 选中节点的名称路径(2026-11-18 一级/二级类目可选中):非空时序列化按
|
||||
* jdCategoryNamesUnder 展开为子树类目名集合下发(后端 IN);空=末级/树外行,
|
||||
* 按单名等值下发(旧形状)。 */
|
||||
categoryPath?: string[]
|
||||
/** 店铺名(v1.7 店铺名单维度:侧栏点店铺行下发,精确 eq;空串不限)。 */
|
||||
shopName: string
|
||||
/** 分类 id 文本(侧栏店铺分类 Tab 里那一行),空串=全部分类。 */
|
||||
groupId: string
|
||||
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」;2026-11-18「加个全部
|
||||
* 选项」恢复全量档;**2026-11-21 用户口径「默认改成全部」=出厂默认改卡 ''**,推翻
|
||||
* 11-17「默认卡未分类」):'classified'=已分类(当前分组下有分类),'ungrouped'=
|
||||
* 未分类,''=全部(当前分组下全部商品)。
|
||||
* 语义按 V203 归属表(当前数据权限分组)判定,与列表分类列同形;不是 11-16 撤掉的
|
||||
* 旧 grouped/ungrouped 参数(那两档读已停用的 biz_jd_product.group_id 列,后端仍拒收)。
|
||||
* ''(全部档)序列化时不带 classified 参数=后端跳过谓词查全部;脏值同走该兜底。 */
|
||||
classified?: '' | 'classified' | 'ungrouped'
|
||||
/** 价格区间下限(v1.7;空串不限,非法数字不下发)。 */
|
||||
minPrice: string
|
||||
/** 价格区间上限(v1.7;空串不限,非法数字不下发)。 */
|
||||
maxPrice: string
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedFrom: string
|
||||
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedTo: string
|
||||
}
|
||||
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
// 分类状态出厂卡「全部」(2026-11-21 用户口径「默认改成全部」,推翻 11-17「默认卡
|
||||
// 未分类」):首屏与「重置」都不带 classified 参数查全量;已分类/未分类走显式选档。
|
||||
return {
|
||||
keyword: '',
|
||||
category: '',
|
||||
categoryPath: [],
|
||||
shopName: '',
|
||||
groupId: '',
|
||||
classified: JD_PRODUCT_DEFAULT_CLASSIFIED,
|
||||
minPrice: '',
|
||||
maxPrice: '',
|
||||
syncedFrom: '',
|
||||
syncedTo: '',
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件(回显条「清除筛选」的渲染判据;分组作用域 ownerGroupId
|
||||
* 不在其中——它是作用域不是筛选条件,清除不得碰)。 */
|
||||
export function jdProductFilterActive(state: JdProductFilterState): boolean {
|
||||
if ((state.keyword || '').trim()) return true
|
||||
if ((state.category || '').trim()) return true
|
||||
if ((state.shopName || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
// 出厂默认=「全部」档(2026-11-21 用户口径),任何非空档(已分类/未分类)都算激活筛选;
|
||||
// ''/缺省不激活,否则首屏就永远处于"有筛选"状态,空结果提示会误导用户去重置没动过的筛选。
|
||||
if (state.classified) return true
|
||||
if (finitePriceOrNull(state.minPrice) != null || finitePriceOrNull(state.maxPrice) != null) return true
|
||||
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 序列化到后端的列表查询参数(snake_case,仅下发非空字段)。 */
|
||||
export interface JdProductQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
/** 合并搜索词(v1.7:后端 product_code LIKE OR title LIKE)。 */
|
||||
keyword?: string
|
||||
/** 京麦类目名集合 IN 过滤(后端 JdProductQueryService.Filter.categories,
|
||||
* 2026-11-18 一级/二级类目可选中:父级展开为子树类目名集合;末级/树外=单元素)。 */
|
||||
category?: string[]
|
||||
/** 店铺名精确过滤(v1.7 店铺名单点选;后端 eq 谓词,铁律 1/20 SQL 下推)。 */
|
||||
shop_name?: string
|
||||
/** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */
|
||||
group_id?: number
|
||||
/** 分类状态快筛(2026-11-17):true=已分类、false=未分类,缺省不下发=全部。
|
||||
* 后端按「当前分组」(owner_group_id)的归属表 EXISTS/NOT EXISTS 在 SQL 侧下推。 */
|
||||
classified?: boolean
|
||||
/** 价格区间(v1.7):商品区间完全落在筛选区间内(price_min >= X AND price_max <= Y)。 */
|
||||
min_price?: number
|
||||
max_price?: number
|
||||
/** 当前数据权限分组 id(分类列/分类筛选都按它取;V203「不同组不能看到跨组的分类」)。 */
|
||||
owner_group_id?: number
|
||||
synced_from?: string
|
||||
synced_to?: string
|
||||
}
|
||||
|
||||
/** api 模块的入参:筛选态 + 分页 + 当前分组(公共库无公司维度)。 */
|
||||
export interface JdProductListParams {
|
||||
page: number
|
||||
pageSize: number
|
||||
keyword?: string
|
||||
category?: string
|
||||
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
|
||||
categoryPath?: string[]
|
||||
shopName?: string
|
||||
groupId?: string
|
||||
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
|
||||
classified?: string
|
||||
/** 价格区间(v1.7;空串不限)。 */
|
||||
minPrice?: string
|
||||
maxPrice?: string
|
||||
/** 当前分组(数据权限分组 id):分类列/分类筛选的作用域,非筛选条件(重置不清它)。 */
|
||||
ownerGroupId?: number | null
|
||||
syncedFrom?: string
|
||||
syncedTo?: string
|
||||
}
|
||||
|
||||
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段)。
|
||||
* 旧 `product_code`/`title_keyword` v1.7 起前端停发(合并进 keyword),反钉在
|
||||
* jd-product-group.test.ts「参数面不再出现」。 */
|
||||
function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuery, 'page' | 'page_size'> {
|
||||
const query: Omit<JdProductQuery, 'page' | 'page_size'> = {}
|
||||
const keyword = (state.keyword || '').trim()
|
||||
if (keyword) query.keyword = keyword
|
||||
const category = (state.category || '').trim()
|
||||
if (category) {
|
||||
// 2026-11-18 一级/二级类目可选中:带路径=按子树展开类目名集合(后端 IN);
|
||||
// 路径失效(树外历史名)回落单名等值集合——与旧 eq 语义逐字同形。
|
||||
const expanded = state.categoryPath && state.categoryPath.length
|
||||
? jdCategoryNamesUnder(state.categoryPath)
|
||||
: null
|
||||
query.category = expanded && expanded.length ? expanded : [category]
|
||||
}
|
||||
const shopName = (state.shopName || '').trim()
|
||||
if (shopName) query.shop_name = shopName
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
// 分类状态快筛:只认两个显式档位,其余值(含脏值)按「全部」不下发——后端 classified
|
||||
// 只收 true/false/缺省,不拿脏值冒充档位。
|
||||
if (state.classified === 'classified') query.classified = true
|
||||
else if (state.classified === 'ungrouped') query.classified = false
|
||||
const minPrice = finitePriceOrNull(state.minPrice)
|
||||
if (minPrice != null) query.min_price = minPrice
|
||||
const maxPrice = finitePriceOrNull(state.maxPrice)
|
||||
if (maxPrice != null) query.max_price = maxPrice
|
||||
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
|
||||
if (syncedFrom) query.synced_from = syncedFrom
|
||||
const syncedTo = validIsoDateOrUndefined(state.syncedTo)
|
||||
if (syncedTo) query.synced_to = syncedTo
|
||||
return query
|
||||
}
|
||||
|
||||
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期/非法价格不下发,分页钳制在此单出口(不含公司维)。
|
||||
* {@code ownerGroupId} 是「当前分组」(分类列/分类筛选作用域,V203),不是筛选条件:
|
||||
* >0 时下发 `owner_group_id`,缺省/0 不下发=后端按作用域默认分组取。 */
|
||||
export function toJdProductListParams(
|
||||
state: JdProductFilterState,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
ownerGroupId?: number | null,
|
||||
): JdProductQuery {
|
||||
const safePage = Math.min(Math.max(Math.floor(page) || 1, 1), JD_PRODUCT_MAX_PAGE)
|
||||
const rawSize = Math.floor(pageSize) || JD_PRODUCT_PAGE_SIZE
|
||||
const safeSize = Math.min(Math.max(rawSize, 1), JD_PRODUCT_MAX_PAGE_SIZE)
|
||||
const query: JdProductQuery = {
|
||||
page: safePage,
|
||||
page_size: safeSize,
|
||||
...toJdProductFilterQuery(state),
|
||||
}
|
||||
if (typeof ownerGroupId === 'number' && Number.isFinite(ownerGroupId) && ownerGroupId > 0) {
|
||||
query.owner_group_id = Math.floor(ownerGroupId)
|
||||
}
|
||||
return query
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
/** 京东数据库列表查询模型(v1.4 Phase 5):解析 JdProductPageVo(camel),纯逻辑零依赖。
|
||||
* camel 为正、snake 容错(与外观专利/去重页模型同形),缺 id 弃行。
|
||||
* 纯函数、无框架依赖(envelope 只借纯 unwrap),node --test 可直测。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
/** 京东商品列表行(后端 JdProductItemVo,camel 为正)。 */
|
||||
export interface JdProductItem {
|
||||
id: number
|
||||
shopId: number | null
|
||||
shopName: string
|
||||
productCode: string
|
||||
skuId: string
|
||||
/** 货号(京麦后台「货号」列,与 SKU 不是同一个值)。 */
|
||||
itemNum: string
|
||||
/** SKU 数(京麦后台「12个SKU」列)。 */
|
||||
skuCount: number | null
|
||||
/** 信息分(京麦后台「信息分」列)。 */
|
||||
healthScore: number | null
|
||||
title: string
|
||||
brand: string
|
||||
categoryPath: string
|
||||
/** 价格区间下限(京麦 priceDetailVO.minJdPrice):后端 BigDecimal 序列化成 JSON number,
|
||||
* decimalText 数值/字符串都收——2026-11-16 实录:text() 把 number 丢成空串=生产库
|
||||
* 273/273 行 price_min 全有值而列表价格全显示「-」(用户报「价格没采集到」的真因)。 */
|
||||
priceMin: string
|
||||
/** 价格区间上限(京麦 priceDetailVO.maxJdPrice),解析口径同 priceMin。 */
|
||||
priceMax: string
|
||||
stockTotal: number | null
|
||||
/** 上架中/已下架/审核中/草稿。 */
|
||||
saleStatus: string
|
||||
listTab: string
|
||||
jdCreatedAt: string
|
||||
/** 上架时间(京麦后台「上架时间」列,与创建时间不是同一个值)。 */
|
||||
jdOnlineAt: string
|
||||
jdUpdatedAt: string
|
||||
mainImageUrl: string
|
||||
attrCount: number | null
|
||||
imageCount: number | null
|
||||
groupId: number | null
|
||||
groupName: string
|
||||
syncedAt?: string
|
||||
}
|
||||
|
||||
export interface JdProductPageResult {
|
||||
items: JdProductItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 50,v1.6 蓝图 Phase 1 新契约)。 */
|
||||
export const JD_PRODUCT_DEFAULT_SIZE = 50
|
||||
|
||||
export function emptyJdProductPage(): JdProductPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: JD_PRODUCT_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 价格区间展示:min/max 都空为 -,只空一侧给单值。输入数值/字符串都收
|
||||
* (后端 BigDecimal 序列化成 JSON number;列表行解析层之外,mount 测试 mock
|
||||
* 绕过解析层时 number 会原样进这里——对 number 直接 .trim() 抛 TypeError
|
||||
* 炸整页渲染,2026-11-16 实录),统一 decimalText 归一后再拼。 */
|
||||
export function jdPriceRange(item: Pick<JdProductItem, 'priceMin' | 'priceMax'>): string {
|
||||
const min = decimalText(item.priceMin).trim()
|
||||
const max = decimalText(item.priceMax).trim()
|
||||
if (min && max) return min === max ? min : `${min} ~ ${max}`
|
||||
return min || max || ''
|
||||
}
|
||||
|
||||
/** 解析单行;缺 id 视为无效。camel 为正、snake 容错。 */
|
||||
export function toJdProductItem(raw: unknown): JdProductItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
return {
|
||||
id,
|
||||
shopId: numberOrNull(record.shopId ?? record.shop_id),
|
||||
shopName: text(record.shopName ?? record.shop_name),
|
||||
productCode: text(record.productCode ?? record.product_code),
|
||||
skuId: text(record.skuId ?? record.sku_id),
|
||||
itemNum: text(record.itemNum ?? record.item_num),
|
||||
skuCount: numberOrNull(record.skuCount ?? record.sku_count),
|
||||
healthScore: numberOrNull(record.healthScore ?? record.health_score),
|
||||
title: text(record.title),
|
||||
brand: text(record.brand),
|
||||
categoryPath: text(record.categoryPath ?? record.category_path),
|
||||
// 价格必须走 decimalText(数值/字符串都收):后端 BigDecimal 序列化成 JSON number,
|
||||
// text() 对非字符串一律回空串=采集到的价格在解析层被丢掉(2026-11-16 生产库 273 行
|
||||
// price_min 全有值、列表全「-」实录)。与详情 SKU 价(decimalText)同一出口。
|
||||
priceMin: decimalText(record.priceMin ?? record.price_min),
|
||||
priceMax: decimalText(record.priceMax ?? record.price_max),
|
||||
stockTotal: numberOrNull(record.stockTotal ?? record.stock_total),
|
||||
saleStatus: text(record.saleStatus ?? record.sale_status),
|
||||
listTab: text(record.listTab ?? record.list_tab),
|
||||
jdCreatedAt: text(record.jdCreatedAt ?? record.jd_created_at),
|
||||
jdOnlineAt: text(record.jdOnlineAt ?? record.jd_online_at),
|
||||
jdUpdatedAt: text(record.jdUpdatedAt ?? record.jd_updated_at),
|
||||
mainImageUrl: text(record.mainImageUrl ?? record.main_image_url),
|
||||
attrCount: numberOrNull(record.attrCount ?? record.attr_count),
|
||||
imageCount: numberOrNull(record.imageCount ?? record.image_count),
|
||||
groupId: numberOrNull(record.groupId ?? record.group_id),
|
||||
groupName: text(record.groupName ?? record.group_name),
|
||||
syncedAt: text(record.syncedAt ?? record.synced_at) || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。 */
|
||||
export function parseJdProductPage(payload: unknown): JdProductPageResult {
|
||||
const out = emptyJdProductPage()
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toJdProductItem(raw))
|
||||
.filter((item): item is JdProductItem => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
|
||||
/** 详情属性块:attrGroups[{groupName, attrs:[{key,label,value}]}]。 */
|
||||
export interface JdProductAttrEntry {
|
||||
key: string
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface JdProductAttrGroup {
|
||||
groupName: string
|
||||
attrs: JdProductAttrEntry[]
|
||||
}
|
||||
|
||||
/** 详情图片:images[{id, imageType, attrName, sortNo, url, byteSize, width, height}]
|
||||
* (id=biz_jd_product_image 行号,编辑抽屉按它提交删图;旧后端不带 id 时按缺 0 弃行口径不拦展示)。 */
|
||||
export interface JdProductImage {
|
||||
id: number
|
||||
imageType: string
|
||||
attrName: string
|
||||
sortNo: number
|
||||
url: string
|
||||
byteSize: number | null
|
||||
width: number | null
|
||||
height: number | null
|
||||
}
|
||||
|
||||
/** 销售属性组合的一项(颜色=上衣 / 尺码=S,京麦详情页「销售属性」)。 */
|
||||
export interface JdProductSkuAttr {
|
||||
name: string
|
||||
value: string
|
||||
}
|
||||
|
||||
/** 详情 SKU 行(后端 JdProductDetailVo.SkuVo,V198;京麦 12 行矩阵的一行)。 */
|
||||
export interface JdProductSku {
|
||||
skuId: string
|
||||
skuName: string
|
||||
/** 商家自定义序号(京麦 skuSeq)。 */
|
||||
skuSeq: string
|
||||
/** 京东价(后端 BigDecimal,前端按文本展示,不做金额运算)。 */
|
||||
price: string
|
||||
stock: number | null
|
||||
saleAttrs: JdProductSkuAttr[]
|
||||
sortNo: number
|
||||
}
|
||||
|
||||
export interface JdProductDetail {
|
||||
item: JdProductItem
|
||||
attrGroups: JdProductAttrGroup[]
|
||||
images: JdProductImage[]
|
||||
/** SKU 矩阵(京麦详情页「销售属性」区,V198;旧数据为空数组)。 */
|
||||
skus: JdProductSku[]
|
||||
/** attrGroups 解析失败时的原始 JSON 兜底(界面原样展示,不静默吞)。 */
|
||||
attrJsonRaw: string
|
||||
}
|
||||
|
||||
/** 归一化 attrGroups(camel/snake 同级容错),非法项跳过、块名缺省归「属性」。 */
|
||||
function toAttrGroups(raw: unknown): JdProductAttrGroup[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
const out: JdProductAttrGroup[] = []
|
||||
for (const groupRaw of raw) {
|
||||
if (!groupRaw || typeof groupRaw !== 'object') continue
|
||||
const group = groupRaw as Record<string, unknown>
|
||||
const groupName = text(group.groupName ?? group.group_name) || '属性'
|
||||
const attrsRaw = group.attrs
|
||||
if (!Array.isArray(attrsRaw)) continue
|
||||
const attrs: JdProductAttrEntry[] = []
|
||||
for (const attrRaw of attrsRaw) {
|
||||
if (!attrRaw || typeof attrRaw !== 'object') continue
|
||||
const attr = attrRaw as Record<string, unknown>
|
||||
attrs.push({
|
||||
key: text(attr.key),
|
||||
label: text(attr.label),
|
||||
value: text(attr.value),
|
||||
})
|
||||
}
|
||||
out.push({ groupName, attrs })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 归一化 images;缺 url 弃行(界面没有可展示/可打开的目标),sortNo 缺省 0。 */
|
||||
function toImages(raw: unknown): JdProductImage[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
const out: JdProductImage[] = []
|
||||
for (const imageRaw of raw) {
|
||||
if (!imageRaw || typeof imageRaw !== 'object') continue
|
||||
const image = imageRaw as Record<string, unknown>
|
||||
const url = text(image.url)
|
||||
if (!url) continue
|
||||
out.push({
|
||||
id: numberOrNull(image.id) ?? 0,
|
||||
imageType: text(image.imageType ?? image.image_type),
|
||||
attrName: text(image.attrName ?? image.attr_name),
|
||||
sortNo: numberOrNull(image.sortNo ?? image.sort_no) ?? 0,
|
||||
url,
|
||||
byteSize: numberOrNull(image.byteSize ?? image.byte_size),
|
||||
width: numberOrNull(image.width),
|
||||
height: numberOrNull(image.height),
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 数值/字符串都收(后端 BigDecimal 序列化成 JSON number),去尾零后展示:
|
||||
* 京麦详情页写 `162`,不给 `162.00`;数字形状之外的原文照原样回(不吞异常值)。 */
|
||||
function decimalText(value: unknown): string {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
return String(Math.round(value * 100) / 100)
|
||||
}
|
||||
const raw = text(value)
|
||||
if (!/^\d+(?:\.\d+)?$/.test(raw)) return raw
|
||||
return String(Math.round(Number(raw) * 100) / 100)
|
||||
}
|
||||
|
||||
/** 归一化 SKU 矩阵(camel/snake 容错);缺 skuId 弃行(京麦每一行都以 skuId 为身份)。 */
|
||||
function toSkus(raw: unknown): JdProductSku[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
const out: JdProductSku[] = []
|
||||
for (const skuRaw of raw) {
|
||||
if (!skuRaw || typeof skuRaw !== 'object') continue
|
||||
const sku = skuRaw as Record<string, unknown>
|
||||
const skuId = text(sku.skuId ?? sku.sku_id)
|
||||
if (!skuId) continue
|
||||
const saleAttrs: JdProductSkuAttr[] = []
|
||||
const attrsRaw = sku.saleAttrs ?? sku.sale_attrs
|
||||
if (Array.isArray(attrsRaw)) {
|
||||
for (const attrRaw of attrsRaw) {
|
||||
if (!attrRaw || typeof attrRaw !== 'object') continue
|
||||
const attr = attrRaw as Record<string, unknown>
|
||||
const value = text(attr.value)
|
||||
if (!value) continue
|
||||
saleAttrs.push({ name: text(attr.name) || '属性', value })
|
||||
}
|
||||
}
|
||||
out.push({
|
||||
skuId,
|
||||
skuName: text(sku.skuName ?? sku.sku_name),
|
||||
skuSeq: text(sku.skuSeq ?? sku.sku_seq),
|
||||
price: decimalText(sku.price),
|
||||
stock: numberOrNull(sku.stock),
|
||||
saleAttrs,
|
||||
sortNo: numberOrNull(sku.sortNo ?? sku.sort_no) ?? 0,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** 销售属性维度名(按首次出现顺序):京麦详情页「颜色 / 尺码」两列。 */
|
||||
export function jdSkuDimensions(skus: JdProductSku[]): string[] {
|
||||
const order: string[] = []
|
||||
for (const sku of skus) {
|
||||
for (const attr of sku.saleAttrs) {
|
||||
if (!order.includes(attr.name)) order.push(attr.name)
|
||||
}
|
||||
}
|
||||
return order
|
||||
}
|
||||
|
||||
/** SKU 矩阵汇总:`12 个 SKU · ¥162 ~ ¥168 · 库存 2400`(缺项不硬凑)。 */
|
||||
export function jdSkuSummary(skus: JdProductSku[]): string {
|
||||
if (!skus.length) return ''
|
||||
const prices = skus
|
||||
.map((sku) => Number(sku.price))
|
||||
.filter((value) => Number.isFinite(value) && value > 0)
|
||||
const priceText = prices.length
|
||||
? Math.min(...prices) === Math.max(...prices)
|
||||
? `¥${Math.min(...prices)}`
|
||||
: `¥${Math.min(...prices)} ~ ¥${Math.max(...prices)}`
|
||||
: ''
|
||||
const stocks = skus.map((sku) => sku.stock).filter((value): value is number => typeof value === 'number')
|
||||
const stockText = stocks.length ? `库存 ${stocks.reduce((sum, value) => sum + value, 0)}` : ''
|
||||
return [`${skus.length} 个 SKU`, priceText, stockText].filter(Boolean).join(' · ')
|
||||
}
|
||||
|
||||
/** 解析详情负载(信封或已解包 VO);attrGroups 解析不出时回 attrJsonRaw 原文兜底。 */
|
||||
export function parseJdProductDetail(payload: unknown): JdProductDetail {
|
||||
const core = unwrap<unknown>(payload)
|
||||
const record = core && typeof core === 'object' ? (core as Record<string, unknown>) : {}
|
||||
const item = toJdProductItem(record) ?? {
|
||||
id: 0,
|
||||
shopId: null,
|
||||
shopName: '',
|
||||
productCode: '',
|
||||
skuId: '',
|
||||
itemNum: '',
|
||||
skuCount: null,
|
||||
healthScore: null,
|
||||
title: '',
|
||||
brand: '',
|
||||
categoryPath: '',
|
||||
priceMin: '',
|
||||
priceMax: '',
|
||||
stockTotal: null,
|
||||
saleStatus: '',
|
||||
listTab: '',
|
||||
jdCreatedAt: '',
|
||||
jdOnlineAt: '',
|
||||
jdUpdatedAt: '',
|
||||
mainImageUrl: '',
|
||||
attrCount: null,
|
||||
imageCount: null,
|
||||
groupId: null,
|
||||
groupName: '',
|
||||
}
|
||||
const attrGroups = toAttrGroups(record.attrGroups ?? record.attr_groups)
|
||||
const attrJsonRaw = typeof record.attrJsonRaw === 'string'
|
||||
? record.attrJsonRaw
|
||||
: typeof record.attr_json_raw === 'string' ? record.attr_json_raw : ''
|
||||
return {
|
||||
item,
|
||||
attrGroups,
|
||||
images: toImages(record.images),
|
||||
skus: toSkus(record.skus),
|
||||
attrJsonRaw,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 外观专利数据库 · 明细分页表(2026-11-11 晚间按客户口径恢复「昨天那个格式」:
|
||||
* 「不是这种格式 你就按照昨天那个格式」——撤掉一主管一卡视图,恢复只读明细表;
|
||||
* 「添加个管理员 跟导出数据就可以」——表上加「管理员」列(后端读侧现算:主管/公司超管=自己,
|
||||
* 普通账户=创建人,读不到为空展示 -,不猜名),筛选行加「导出」(与「去重数据库」页同款:
|
||||
* 当前过滤面+公司 tab 全量出 xlsx,不传 supervisor_user_id——传了会走按主管分支并忽略任务号/ASIN);
|
||||
* 「任务号/ASIN 两个筛选框恢复」(后端能力一直在,之前产品决定下过架,客户要「一目了然」选数据);
|
||||
* 分组(主管)下拉保留「选中即查」。数据按 ASIN 累计:同 ASIN 只保留一条(V192 唯一键,
|
||||
* 重复检测更新那条),不同 ASIN 同品牌全保留——页面只管展示,累计语义在后端同步链。
|
||||
* 主管卡片视图与卡片级删除按钮从页面下架(客户下午反馈数据疑似被误删,删除入口先撤;
|
||||
* 后端 /supervisors 两接口保留不动)。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import {
|
||||
exportAppearancePatentCleanList,
|
||||
fetchAppearancePatentCleanList,
|
||||
fetchDedupeTotalGroups,
|
||||
type DedupeGroupOption,
|
||||
} from './appearance-patent-clean-api.ts'
|
||||
import type { AppearancePatentCleanItem } from './appearance-patent-clean-model.ts'
|
||||
import { cleanItemReasonTooltip } from './appearance-patent-clean-model.ts'
|
||||
import { createAppearancePatentCleanFilterState } from './appearance-patent-clean-filter.ts'
|
||||
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const companyTab = useCompanyTabStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<AppearancePatentCleanItem[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
|
||||
const exporting = ref(false)
|
||||
/** 同步台账是累计数据,日期初值故意留空(默认当天会让首屏只剩今天同步的行);见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive(createAppearancePatentCleanFilterState())
|
||||
/** 分组(主管)下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
||||
const groupOptions = ref<DedupeGroupOption[]>([])
|
||||
/** min/max 挡不住手输,落值后把倒挂的起止交换回来。 */
|
||||
function clampDatePair(): void {
|
||||
const [s, e] = orderedPair(filter.startDate, filter.endDate)
|
||||
filter.startDate = s
|
||||
filter.endDate = e
|
||||
}
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
/** 分组选项与去重页/店铺管理同源(GET /shop-manages/groups);失败静默回空——分组只是筛选项,
|
||||
* 不该让它把首屏行集一起拖死(列表失败有自己的 LoadFailureBar)。 */
|
||||
async function loadGroupOptions(): Promise<void> {
|
||||
try {
|
||||
groupOptions.value = await fetchDedupeTotalGroups(companyTab.requestCompanyId)
|
||||
} catch {
|
||||
groupOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchAppearancePatentCleanList({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
taskId: filter.taskId,
|
||||
asin: filter.asin,
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
} catch (error) {
|
||||
loadFailure.value = loadFailureMessage(error, '无侵权数据加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出与页签同一过滤面(含公司 tab 与分组),服务端全量出 xlsx;成功后浏览器落盘,失败弹可读文案。
|
||||
* 不传 supervisor_user_id:按主管分支会忽略任务号/ASIN 参数,「按当前筛选导出」必须走明细分支。 */
|
||||
async function exportAll(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
try {
|
||||
const result = await exportAppearancePatentCleanList({
|
||||
taskId: filter.taskId,
|
||||
asin: filter.asin,
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
const url = URL.createObjectURL(result.blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = result.filename
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
showAdminFeedback(`已导出 ${result.filename}`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 重置(对齐店铺数据记录页样式):筛选面回出厂空态,回第一页重取。 */
|
||||
function reset(): void {
|
||||
Object.assign(filter, createAppearancePatentCleanFilterState())
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function changePage(next: number): void {
|
||||
if (next < 1 || next > totalPages.value) return
|
||||
page.value = next
|
||||
void load()
|
||||
}
|
||||
|
||||
function changeSize(size: number) {
|
||||
pageSize.value = size
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
// 切公司 = 重新取数:任务号/ASIN/分组是上一家选中的值,在新一家的行集里筛不出东西,必须一起清,
|
||||
// 分组选项也按新公司重取(选项集是公司隔离的)。
|
||||
watch(() => companyTab.activeId, () => { filter.taskId = ''; filter.asin = ''; filter.groupId = ''; page.value = 1; void loadGroupOptions(); void load() })
|
||||
|
||||
onMounted(() => {
|
||||
void loadGroupOptions()
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="clean-items-view">
|
||||
<section class="panel-box">
|
||||
<div class="clean-panel-head">
|
||||
<h3>外观专利数据库</h3>
|
||||
</div>
|
||||
|
||||
<div class="clean-filter-row">
|
||||
<div class="form-group">
|
||||
<label>任务号</label>
|
||||
<input v-model="filter.taskId" type="text" placeholder="输入任务号" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ASIN</label>
|
||||
<input v-model="filter.asin" type="text" placeholder="输入 ASIN" @keyup.enter="apply" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<!-- 下拉 2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的弹层是浏览器直角
|
||||
原生物 ⇒ 换 el-select(admin-filter 同壳 42px/9px,弹层 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(与旧原生下拉同语义,查询参数仍是空串)。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in ASIN_COUNTRY_CODES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 分组(主管)选中即查:选完立刻按该主管过滤刷新(回第一页),不必再点查询。
|
||||
value 保持字符串形状(下游按字符串比对/透传)。 -->
|
||||
<el-select v-model="filter.groupId" class="admin-filter" aria-label="筛选分组" @change="apply">
|
||||
<el-option label="全部分组" value="" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步开始日期</label>
|
||||
<input v-model="filter.startDate" type="date" :max="filter.endDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步结束日期</label>
|
||||
<input v-model="filter.endDate" type="date" :min="filter.startDate" @change="clampDatePair" />
|
||||
</div>
|
||||
<div class="clean-filter-actions">
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
<button class="btn btn-export" type="button" :disabled="exporting" @click="exportAll">
|
||||
{{ exporting ? '导出中...' : '导出' }}
|
||||
</button>
|
||||
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="clean-toolbar">
|
||||
<span class="clean-summary">共 {{ total }} 条无侵权数据</span>
|
||||
</div>
|
||||
<div class="table-scroll clean-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 90px">任务号</th>
|
||||
<th style="width: 110px">管理员</th>
|
||||
<th>ASIN</th>
|
||||
<th style="width: 64px">国家</th>
|
||||
<th>SKU</th>
|
||||
<th>品牌</th>
|
||||
<th style="width: 90px">价格</th>
|
||||
<th>标题</th>
|
||||
<th style="width: 130px">结论</th>
|
||||
<th style="width: 170px">同步时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<td>{{ row.taskId ?? '-' }}</td>
|
||||
<td :title="row.supervisorName || ''">{{ row.supervisorName || '-' }}</td>
|
||||
<td class="mono-cell">{{ row.asin || '-' }}</td>
|
||||
<td>{{ asinCountryLabel(row.country || '') }}</td>
|
||||
<td class="mono-cell">{{ row.sku || '-' }}</td>
|
||||
<td>{{ row.brand || '-' }}</td>
|
||||
<td>{{ row.price || '-' }}</td>
|
||||
<td class="title-cell" :title="row.title">{{ row.title || '-' }}</td>
|
||||
<td class="conclusion-cell" :title="cleanItemReasonTooltip(row)">{{ row.conclusion || '-' }}</td>
|
||||
<td>{{ formatDateTime(row.syncedAt || '') }}</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="10" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="10" class="empty-tip">暂无无侵权数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<OldPagination :total="total" :page="page" :page-size="pageSize" @change="changePage" @size-change="changeSize" />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻参照「去重数据库」页(panel-box + 自绘表格 + 旧式分页),只读无操作列。
|
||||
2026-11-11 晚间恢复明细表形态(客户「按照昨天那个格式」),表头第二列=管理员。 */
|
||||
.clean-items-view {
|
||||
font-family: inherit;
|
||||
color: var(--c-text, #24384d);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 16px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.clean-panel-head h3 {
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
.clean-filter-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, minmax(150px, 1fr)) auto;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.clean-filter-row .form-group {
|
||||
min-width: 0;
|
||||
}
|
||||
.clean-filter-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.form-group input[type="date"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.clean-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.clean-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #dbe5ee;
|
||||
border-radius: 10px;
|
||||
background: #ffffff;
|
||||
}
|
||||
.table-scroll table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
/* 同步时间列=`YYYY-MM-DD HH:mm:ss` 固定 19 字符,13.5px 下实测约 133px;全局 `* { box-sizing: border-box }`
|
||||
把 24px 左右内边距算进列宽,旧的 150px 只剩 126px 内容宽 ⇒ 末尾被 ellipsis 吃掉(客户 2026-11-12
|
||||
反馈「日期显示不全」)。170px 与店铺管理/跳过价格等页的时间列同值(内容宽 146px,留 13px 余量);
|
||||
表 min-width 同步 +20px,其余列的可用宽度与改前一致。 */
|
||||
.clean-table-scroll > table {
|
||||
min-width: 1060px;
|
||||
}
|
||||
.table-scroll th,
|
||||
.table-scroll td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
border-bottom: 1px solid #e0e8ef;
|
||||
vertical-align: middle;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll th {
|
||||
background: #edf4fa;
|
||||
color: #4e6479;
|
||||
border-bottom-color: #d5e1eb;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
.table-scroll tbody tr:hover td {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.table-scroll tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.mono-cell {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.title-cell {
|
||||
max-width: 260px;
|
||||
}
|
||||
.conclusion-cell {
|
||||
max-width: 130px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
/** 外观专利无侵权数据列表查询适配(v1.3 AC-5):GET /api/admin/appearance-patent-clean-items。
|
||||
* 只读页+导出(2026-11-11 客户需求「数据得导出来」):公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。
|
||||
* 2026-11-11 晚间恢复明细表:主管聚合(/supervisors)与按主管删除的前端发送口随卡片视图一并
|
||||
* 下架(客户「不是这种格式 按照昨天那个格式」+删除入口先撤);后端两接口保留,要恢复时
|
||||
* 从 git 历史(e1767faf)找回。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
toAppearancePatentCleanExportParams,
|
||||
toAppearancePatentCleanListParams,
|
||||
type AppearancePatentCleanExportParams,
|
||||
type AppearancePatentCleanExportQuery,
|
||||
type AppearancePatentCleanListParams,
|
||||
} from './appearance-patent-clean-filter.ts'
|
||||
import {
|
||||
parseAppearancePatentCleanPage,
|
||||
type AppearancePatentCleanPageResult,
|
||||
} from './appearance-patent-clean-model.ts'
|
||||
|
||||
export const APPEARANCE_PATENT_CLEAN_ENDPOINT = '/api/admin/appearance-patent-clean-items'
|
||||
|
||||
export async function fetchAppearancePatentCleanList(
|
||||
params: AppearancePatentCleanListParams,
|
||||
): Promise<AppearancePatentCleanPageResult> {
|
||||
const query = toAppearancePatentCleanListParams(
|
||||
{
|
||||
taskId: params.taskId ?? '',
|
||||
asin: params.asin ?? '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
},
|
||||
params.page,
|
||||
params.pageSize,
|
||||
)
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const { data } = await http.get<unknown>(APPEARANCE_PATENT_CLEAN_ENDPOINT, { params: query })
|
||||
return parseAppearancePatentCleanPage(data)
|
||||
}
|
||||
|
||||
export interface AppearancePatentCleanExportResult {
|
||||
blob: Blob
|
||||
filename: string
|
||||
}
|
||||
|
||||
/** 从 Content-Disposition 取 filename*(UTF-8 轨,后端 DownloadHeaderUtil 双轨口径),取不到回退常量名。 */
|
||||
function exportFilenameOf(disposition: unknown): string {
|
||||
const raw = typeof disposition === 'string' ? disposition : ''
|
||||
const star = /filename\*=(?:UTF-8'')?([^;]+)/i.exec(raw)
|
||||
if (star?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) || '外观专利数据库.xlsx'
|
||||
} catch {
|
||||
// 编码坏的 filename* 当作没有,走 ASCII 轨或常量名
|
||||
}
|
||||
}
|
||||
const plain = /filename="([^"]+)"/i.exec(raw)
|
||||
return plain?.[1] || '外观专利数据库.xlsx'
|
||||
}
|
||||
|
||||
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
|
||||
export async function exportAppearancePatentCleanList(
|
||||
params: AppearancePatentCleanExportParams,
|
||||
): Promise<AppearancePatentCleanExportResult> {
|
||||
const query: AppearancePatentCleanExportQuery = toAppearancePatentCleanExportParams({
|
||||
taskId: params.taskId ?? '',
|
||||
asin: params.asin ?? '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
})
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const response = await http.get<Blob>(`${APPEARANCE_PATENT_CLEAN_ENDPOINT}/export`, {
|
||||
params: query,
|
||||
responseType: 'blob',
|
||||
timeout: 120_000,
|
||||
})
|
||||
const disposition = response.headers?.['content-disposition']
|
||||
if (!disposition) {
|
||||
// 没有附件头=服务端回了业务错误信封(HTTP 200 + JSON),把 blob 文本解回错误文案抛给页面
|
||||
const blob = response.data
|
||||
let payload: unknown = null
|
||||
if (blob && typeof blob.text === 'function') {
|
||||
const text = await blob.text()
|
||||
try {
|
||||
payload = JSON.parse(text)
|
||||
} catch {
|
||||
payload = text
|
||||
}
|
||||
}
|
||||
throw new Error(errorTextOf(payload))
|
||||
}
|
||||
return { blob: response.data, filename: exportFilenameOf(disposition) }
|
||||
}
|
||||
|
||||
/** 分组(主管)下拉选项:复用既有 GET /shop-manages/groups(与去重页/店铺管理共用同一分组集,
|
||||
* 不下新端点)。2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」——
|
||||
* 选项是分组管理里那一行(DedupeGroupOption {id, name, leaderUserId}),选中后以 group_id
|
||||
* 走本文件 list/export 同一过滤面。 */
|
||||
export { fetchDedupeTotalGroups } from '../asin/dedupe-total-api.ts'
|
||||
export type { DedupeGroupOption } from '../asin/dedupe-total-api.ts'
|
||||
@@ -0,0 +1,138 @@
|
||||
/** 外观专利无侵权数据页筛选纯函数(v1.3 AC-5):任务号/ASIN/国家/分组/起止时间 + snake 分页参数。
|
||||
* 产出与后端 §3.2 参数归一逐字对撞:`page`/`page_size`(默认 10、上限 100)、`task_id`、
|
||||
* `asin`、`country`、`group_id`、`start_date`/`end_date`(ISO yyyy-MM-dd;空白不下发)。
|
||||
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
|
||||
* 最大 999_900,Number.MAX_SAFE_INTEGER 也不会把乘积顶出安全整数。纯逻辑,node --test 直测。
|
||||
* 公司维不在这里:归一化构造器不认识 company_id(同 asin-filter 惯例),由 api 发送口从
|
||||
* 原始入参自己下传——取值口由 company-tab-wiring 护栏的发送行钉看守。
|
||||
* 分组语义(2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」):下拉选项是
|
||||
* 分组管理里那一行(biz_shop_manage_group),group_id 下发后服务端解析「组长本人+名下子账户」
|
||||
* 整集 SQL 下推;表上「管理员」列与它同源(组长行=自己,子账户行=创建人)。 */
|
||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||
|
||||
/** 每页条数默认 10(蓝图 §3.2),上限 100。 */
|
||||
export const APPEARANCE_PATENT_CLEAN_PAGE_SIZE = 10
|
||||
export const APPEARANCE_PATENT_CLEAN_MAX_PAGE_SIZE = 100
|
||||
/** 页码上限:与后端 AppearancePatentCleanItemQueryService.MAX_PAGE(CR-18 先例)同值,两侧不漂。 */
|
||||
export const APPEARANCE_PATENT_CLEAN_MAX_PAGE = 10_000
|
||||
|
||||
export interface AppearancePatentCleanFilterState {
|
||||
/** 任务号(纯数字文本,空串不限)。 */
|
||||
taskId: string
|
||||
/** ASIN 前缀。 */
|
||||
asin: string
|
||||
/** 国家代码,空串=全部。 */
|
||||
country: string
|
||||
/** 分组 id 文本(分组管理里那一行,组长即该组主管),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
startDate: string
|
||||
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
endDate: string
|
||||
}
|
||||
|
||||
export function createAppearancePatentCleanFilterState(): AppearancePatentCleanFilterState {
|
||||
return { taskId: '', asin: '', country: '', groupId: '', startDate: '', endDate: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
export function appearancePatentCleanFilterActive(state: AppearancePatentCleanFilterState): boolean {
|
||||
if ((state.taskId || '').trim()) return true
|
||||
if ((state.asin || '').trim()) return true
|
||||
if ((state.country || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
if (validIsoDateOrUndefined(state.startDate) || validIsoDateOrUndefined(state.endDate)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 序列化到后端的查询参数(snake_case,仅下发非空字段)。 */
|
||||
export interface AppearancePatentCleanQuery {
|
||||
page: number
|
||||
page_size: number
|
||||
task_id?: number
|
||||
asin?: string
|
||||
country?: string
|
||||
group_id?: number
|
||||
start_date?: string
|
||||
end_date?: string
|
||||
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** 导出查询参数:与列表同一过滤面、无分页(全量导出由服务侧 EXPORT_MAX_ROWS 上限兜住)。 */
|
||||
export interface AppearancePatentCleanExportQuery {
|
||||
task_id?: number
|
||||
asin?: string
|
||||
country?: string
|
||||
group_id?: number
|
||||
start_date?: string
|
||||
end_date?: string
|
||||
/** 公司 tab 同列表口径:白名单构造不点名,由 api 发送口下传。 */
|
||||
company_id?: number
|
||||
}
|
||||
|
||||
/** api 模块的入参:筛选态 + 分页 + 公司值(camel)。 */
|
||||
export interface AppearancePatentCleanListParams {
|
||||
page: number
|
||||
pageSize: number
|
||||
taskId?: string
|
||||
asin?: string
|
||||
country?: string
|
||||
groupId?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** api 导出入口的入参:筛选态 + 公司值(camel,无分页)。 */
|
||||
export interface AppearancePatentCleanExportParams {
|
||||
taskId?: string
|
||||
asin?: string
|
||||
country?: string
|
||||
groupId?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段);列表与导出共用这一个取值口,
|
||||
* 「导出的过滤面和页签看到的永远同源」由这条单出口保证,不出现两处各算各的。 */
|
||||
function toAppearancePatentCleanFilterQuery(state: AppearancePatentCleanFilterState): AppearancePatentCleanExportQuery {
|
||||
const query: AppearancePatentCleanExportQuery = {}
|
||||
const taskId = Number.parseInt((state.taskId || '').trim(), 10)
|
||||
if (Number.isFinite(taskId) && taskId > 0) query.task_id = taskId
|
||||
const asin = (state.asin || '').trim()
|
||||
if (asin) query.asin = asin
|
||||
const country = (state.country || '').trim()
|
||||
if (country) query.country = country
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
const startDate = validIsoDateOrUndefined(state.startDate)
|
||||
if (startDate) query.start_date = startDate
|
||||
const endDate = validIsoDateOrUndefined(state.endDate)
|
||||
if (endDate) query.end_date = endDate
|
||||
return query
|
||||
}
|
||||
|
||||
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期不下发,分页钳制在此单出口(不含公司维)。 */
|
||||
export function toAppearancePatentCleanListParams(
|
||||
state: AppearancePatentCleanFilterState,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
): AppearancePatentCleanQuery {
|
||||
const safePage = Math.min(Math.max(Math.floor(page) || 1, 1), APPEARANCE_PATENT_CLEAN_MAX_PAGE)
|
||||
const rawSize = Math.floor(pageSize) || APPEARANCE_PATENT_CLEAN_PAGE_SIZE
|
||||
const safeSize = Math.min(Math.max(rawSize, 1), APPEARANCE_PATENT_CLEAN_MAX_PAGE_SIZE)
|
||||
return {
|
||||
page: safePage,
|
||||
page_size: safeSize,
|
||||
...toAppearancePatentCleanFilterQuery(state),
|
||||
}
|
||||
}
|
||||
|
||||
/** 过滤态 → 导出查询参数(无分页;归一规则与列表逐字同源)。 */
|
||||
export function toAppearancePatentCleanExportParams(
|
||||
state: AppearancePatentCleanFilterState,
|
||||
): AppearancePatentCleanExportQuery {
|
||||
return toAppearancePatentCleanFilterQuery(state)
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/** 外观专利无侵权数据列表查询模型(v1.3 AC-5):解析 AppearancePatentCleanItemPageVo(camel),纯逻辑。
|
||||
* 行值是同步服务从 chunk payload 原样落的,读侧只搬运不加工(与后端 toVo 同一口径)。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
export interface AppearancePatentCleanItem {
|
||||
id: number
|
||||
resultId: number | null
|
||||
taskId: number | null
|
||||
userId: number | null
|
||||
/** 管理员列(表头「管理员」,客户 2026-11-11 口径;后端读侧现算:主管/公司超管=自己,普通账户=创建人,读不到为空 → 界面展示 -)。 */
|
||||
supervisorName: string
|
||||
companyId: number | null
|
||||
rowNo: number | null
|
||||
asin: string
|
||||
country: string
|
||||
sku: string
|
||||
brand: string
|
||||
price: string
|
||||
title: string
|
||||
imageUrl: string
|
||||
itemUrl: string
|
||||
conclusion: string
|
||||
titleReason: string
|
||||
appearanceReason: string
|
||||
patentReason: string
|
||||
sourceFilename: string
|
||||
syncedAt?: string
|
||||
}
|
||||
|
||||
export interface AppearancePatentCleanPageResult {
|
||||
items: AppearancePatentCleanItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 前端首屏默认容量:与后端 PageDefaults.CLEAN_ITEMS_PAGE_SIZE(蓝图 §3.2 默认 10)同值。 */
|
||||
export const APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE = 10
|
||||
|
||||
export function emptyAppearancePatentCleanPage(): AppearancePatentCleanPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
/** 结论列悬停提示=三因原文拼装(2026-11-11 随明细表恢复回归;3cfca462 曾随结论徽章一起退役)。 */
|
||||
export function cleanItemReasonTooltip(item: AppearancePatentCleanItem): string {
|
||||
const parts: string[] = []
|
||||
if (item.titleReason) parts.push(`标题:${item.titleReason}`)
|
||||
if (item.appearanceReason) parts.push(`外观:${item.appearanceReason}`)
|
||||
if (item.patentReason) parts.push(`专利:${item.patentReason}`)
|
||||
return parts.join('\n')
|
||||
}
|
||||
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 解析单行明细;缺 id 视为无效。camel 为正、snake 容错(与去重页模型同形)。 */
|
||||
export function toAppearancePatentCleanItem(raw: unknown): AppearancePatentCleanItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
return {
|
||||
id,
|
||||
resultId: numberOrNull(record.resultId ?? record.result_id),
|
||||
taskId: numberOrNull(record.taskId ?? record.task_id),
|
||||
userId: numberOrNull(record.userId ?? record.user_id),
|
||||
supervisorName: text(record.supervisorName ?? record.supervisor_name),
|
||||
companyId: numberOrNull(record.companyId ?? record.company_id),
|
||||
rowNo: numberOrNull(record.rowNo ?? record.row_no),
|
||||
asin: text(record.asin),
|
||||
country: text(record.country),
|
||||
sku: text(record.sku),
|
||||
brand: text(record.brand),
|
||||
price: text(record.price),
|
||||
title: text(record.title),
|
||||
imageUrl: text(record.imageUrl ?? record.image_url),
|
||||
itemUrl: text(record.itemUrl ?? record.item_url),
|
||||
conclusion: text(record.conclusion),
|
||||
titleReason: text(record.titleReason ?? record.title_reason),
|
||||
appearanceReason: text(record.appearanceReason ?? record.appearance_reason),
|
||||
patentReason: text(record.patentReason ?? record.patent_reason),
|
||||
sourceFilename: text(record.sourceFilename ?? record.source_filename),
|
||||
syncedAt: text(record.syncedAt ?? record.synced_at) || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
/** 归一化分页负载(信封或已解包 VO)为前端结果;缺省字段回默认。无 keyset 游标(蓝图 Out of Scope)。 */
|
||||
export function parseAppearancePatentCleanPage(payload: unknown): AppearancePatentCleanPageResult {
|
||||
const out = emptyAppearancePatentCleanPage()
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toAppearancePatentCleanItem(raw))
|
||||
.filter((item): item is AppearancePatentCleanItem => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
/** 日志管理页:桌面客户端 / 麦象采集机上报的日志浏览(仅超管)。
|
||||
* 支持来源/用户/日期筛选,尾部内容查看(自动滚到底、可向前加载更早内容)、
|
||||
* 完整下载、删除;「采集配置」可调全量/精选模式(全局默认 + 终端覆盖)。 */
|
||||
@@ -6,6 +9,7 @@ import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { formatDateTime, orderedPair, todayDateInput } from '@/utils/datetime'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { fetchHistoryUserOptions } from './history-api.ts'
|
||||
import type { HistoryUserOption } from './history-user-option.ts'
|
||||
@@ -57,6 +61,8 @@ const companyTab = useCompanyTabStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
// 设备日志列表竞态门(S1-F4)
|
||||
const gate = createLatestRequestGate()
|
||||
const rows = ref<DeviceLogFileRow[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
@@ -79,6 +85,8 @@ const retentionDays = ref(7)
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
async function load() {
|
||||
// S1-F4:快速切公司/改筛选时旧响应可能晚到——回写前必须过竞态门
|
||||
const token = gate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
@@ -91,14 +99,16 @@ async function load() {
|
||||
pageSize: pageSize.value,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
if (!gate.isCurrent(token)) return
|
||||
rows.value = result?.items || []
|
||||
total.value = Number(result?.total || 0)
|
||||
if (result?.retentionDays) retentionDays.value = result.retentionDays
|
||||
} catch (error) {
|
||||
if (!gate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '日志列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (gate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,10 +194,23 @@ function loadMore() {
|
||||
loadContent(false)
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.fileName,
|
||||
deleteOne: (id) => deleteDeviceLogFile(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
consequence: '将删除所选云端日志,此操作不可恢复。',
|
||||
})
|
||||
|
||||
async function remove(row: DeviceLogFileRow) {
|
||||
if (batch.busy) return
|
||||
if (!(await openAdminConfirm({ message: `确认删除「${row.fileName}」(${row.deviceName || row.deviceId})的云端日志?删除后不可恢复。`, danger: true }))) return
|
||||
try {
|
||||
await deleteDeviceLogFile(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -214,6 +237,11 @@ function modeLabel(mode: string): string {
|
||||
return mode === 'selected' ? '精选' : '全量'
|
||||
}
|
||||
|
||||
/** 终端覆盖下拉的显示文案(el-option 需要显式 label,文案与旧原生 <option> 逐字一致)。 */
|
||||
function deviceOptionLabel(device: DeviceLogDevice): string {
|
||||
return `${sourceLabel(device.source)} · ${device.deviceName || device.deviceId}(${device.deviceId})`
|
||||
}
|
||||
|
||||
async function openConfig() {
|
||||
configVisible.value = true
|
||||
await loadConfig()
|
||||
@@ -294,16 +322,20 @@ onMounted(() => {
|
||||
<div class="form-row logs-filter-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>来源</label>
|
||||
<select v-model="sourceFilter">
|
||||
<option v-for="option in SOURCE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部来源」保留为空值首行(value 语义不变,查询参数仍是空串)。 -->
|
||||
<el-select v-model="sourceFilter" class="admin-filter" aria-label="来源">
|
||||
<el-option v-for="option in SOURCE_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 180px">
|
||||
<label>指定用户</label>
|
||||
<select v-model="uidFilter" :disabled="usersLoading">
|
||||
<option value="">全部用户</option>
|
||||
<option v-for="u in userOptions" :key="u.id" :value="String(u.id)">{{ u.username }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部用户」保留为空值首行;用户值仍是 String(id)(下游按字符串判空、落库前再转数字)。 -->
|
||||
<el-select v-model="uidFilter" class="admin-filter" filterable aria-label="指定用户" :disabled="usersLoading">
|
||||
<el-option label="全部用户" value="" />
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.username" :value="String(u.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>日志日期(起)</label>
|
||||
@@ -323,10 +355,15 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="logs-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 110px">来源</th>
|
||||
<th style="width: 200px">用户</th>
|
||||
<th style="width: 230px">文件名</th>
|
||||
@@ -339,7 +376,11 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>
|
||||
<span class="source-pill" :class="row.source === 'maixiang' ? 'is-maixiang' : 'is-client'">
|
||||
{{ sourceLabel(row.source) }}
|
||||
@@ -360,15 +401,15 @@ onMounted(() => {
|
||||
<td class="ops-cell">
|
||||
<button class="btn btn-sm" type="button" @click="openViewer(row)">查看</button>
|
||||
<a class="btn btn-sm btn-ghost dl-link" :href="deviceLogDownloadUrl(row.id)" download>下载</a>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">
|
||||
<td colspan="9" class="empty-tip">
|
||||
{{ sourceFilter || uidFilter ? '暂无匹配日志' : '暂无日志上报(客户端/采集机上报后自动出现在这里)' }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -418,15 +459,21 @@ onMounted(() => {
|
||||
<div class="config-block">
|
||||
<h4>终端覆盖</h4>
|
||||
<div class="override-add">
|
||||
<select v-model="newOverrideKey" class="override-select">
|
||||
<option value="">选择终端(最近上报的设备)</option>
|
||||
<option v-for="device in devices" :key="`${device.source}|${device.deviceId}`" :value="`${device.source}|${device.deviceId}`">
|
||||
{{ sourceLabel(device.source) }} · {{ device.deviceName || device.deviceId }}({{ device.deviceId }})
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="newOverrideMode">
|
||||
<option v-for="option in MODE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
value 仍是 `${source}|${deviceId}` 与 'full'/'selected' 常量,逐字保留(addOverride
|
||||
按 '|' 切分、后端按 mode 常量解析,值形状一动就错单)。 -->
|
||||
<el-select v-model="newOverrideKey" class="admin-filter override-select" filterable aria-label="选择终端">
|
||||
<el-option label="选择终端(最近上报的设备)" value="" />
|
||||
<el-option
|
||||
v-for="device in devices"
|
||||
:key="`${device.source}|${device.deviceId}`"
|
||||
:label="deviceOptionLabel(device)"
|
||||
:value="`${device.source}|${device.deviceId}`"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select v-model="newOverrideMode" class="admin-filter override-mode" aria-label="覆盖模式">
|
||||
<el-option v-for="option in MODE_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
<button class="btn btn-sm" type="button" @click="addOverride">添加/更新覆盖</button>
|
||||
</div>
|
||||
<table class="override-table">
|
||||
@@ -522,8 +569,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -536,8 +582,7 @@ h3 {
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
@@ -736,21 +781,15 @@ td {
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.override-add select {
|
||||
min-height: 38px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
}
|
||||
/* 只管布局:外壳皮肤(42px/9 圆角/#f8fbfd/focus ring)由全局 .admin-filter 提供,
|
||||
这里不再重复描边(旧 `.override-add select` 那段原生下拉皮肤已随 el-select 删除)。 */
|
||||
.override-select {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.override-mode {
|
||||
flex: 0 0 140px;
|
||||
}
|
||||
.override-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
/** 数字人版本管理页 · 像素复刻旧版 admin.html panel-digital-human-version(自绘:面板头+上传、三态状态色、最新★、操作矩阵、数字页码分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(确认文案/上传进度/下载取链接);确认走原生 confirm 对齐旧版。 */
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
@@ -182,13 +185,25 @@ async function download(row: DigitalHumanVersion) {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => pagedItems.value,
|
||||
rowId: (row) => row.version,
|
||||
rowLabel: (row) => row.version,
|
||||
deleteOne: (id) => deleteDigitalHumanVersion(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || confirming.value != null || !!loadFailure.value,
|
||||
precheck: (row) => canDelete(row) ? undefined : '不能删除当前最新版本',
|
||||
})
|
||||
|
||||
async function remove(row: DigitalHumanVersion) {
|
||||
if (batch.busy) return
|
||||
const text = digitalHumanDeleteConfirmText(row.version)
|
||||
if (!text) return
|
||||
if (!(await openAdminConfirm({ message: text, danger: true }))) return
|
||||
confirming.value = row.version
|
||||
try {
|
||||
await deleteDigitalHumanVersion(row.version)
|
||||
batch.removeFromSelection(row.version)
|
||||
ElMessage.success('删除成功')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -214,17 +229,22 @@ onMounted(load)
|
||||
<section class="panel-box">
|
||||
<div class="dh-head">
|
||||
<h3>版本列表</h3>
|
||||
<div class="dh-head-tools">
|
||||
<div class="dh-head-tools admin-header-controls">
|
||||
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="dh-keyword" />
|
||||
<button class="btn" type="button" @click="uploadVisible = true">上传新版本</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll digital-human-version-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 80px">版本号</th>
|
||||
<th style="width: 60px">状态</th>
|
||||
<th style="width: 60px">最新</th>
|
||||
@@ -237,7 +257,11 @@ onMounted(load)
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="pagedItems.length">
|
||||
<tr v-for="row in pagedItems" :key="row.version + row.id">
|
||||
<tr v-for="row in pagedItems" :key="row.version + row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td><span class="mono-cell">{{ row.version }}</span></td>
|
||||
<td>
|
||||
<span class="st-pill" :class="`is-${statusOf(row).tag}`">{{ statusOf(row).text }}</span>
|
||||
@@ -261,15 +285,15 @@ onMounted(load)
|
||||
设为最新
|
||||
</button>
|
||||
<button v-if="canSetLatestDigitalHumanVersion(row.status)" class="btn btn-sm btn-secondary" type="button" :disabled="downloadingVersion === row.version" @click="download(row)">下载</button>
|
||||
<button v-if="canDelete(row)" class="btn btn-sm btn-danger" type="button" :disabled="confirming === row.version" @click="remove(row)">删除</button>
|
||||
<button v-if="canDelete(row)" class="btn btn-sm btn-danger" type="button" :disabled="batch.busy || confirming === row.version" @click="remove(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="8" class="empty-tip">加载中...</td>
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="8" class="empty-tip">{{ versionKeyword ? '暂无匹配版本' : '暂无版本记录' }}</td>
|
||||
<td colspan="9" class="empty-tip">{{ versionKeyword ? '暂无匹配版本' : '暂无版本记录' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -146,10 +146,12 @@ onMounted(() => {
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>指定用户</label>
|
||||
<select v-model="filter.userId" :disabled="userLoading">
|
||||
<option value="">全部用户</option>
|
||||
<option v-for="u in userOptions" :key="u.id" :value="String(u.id)">{{ u.username }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部用户」保留为空值首行;用户值仍是 String(id)(查询前再 Number() 转数字)。 -->
|
||||
<el-select v-model="filter.userId" class="admin-filter" filterable aria-label="指定用户" :disabled="userLoading">
|
||||
<el-option label="全部用户" value="" />
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.username" :value="String(u.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>开始时间</label>
|
||||
@@ -294,8 +296,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -309,12 +310,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -9,6 +9,7 @@ import { fetchSoftwareVersions, uploadSoftwareVersion, deleteSoftwareVersions }
|
||||
import type { SoftwareVersionItem } from './version-dto.ts'
|
||||
import { isNonEmptyVersion } from './version-dto.ts'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
@@ -62,7 +63,7 @@ async function removeSelected() {
|
||||
selectedIds.value = new Set()
|
||||
await load()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
|
||||
showAdminFeedback(loadFailureMessage(error, '删除失败'), 'error')
|
||||
}
|
||||
}
|
||||
async function removeOne(row: SoftwareVersionItem) {
|
||||
@@ -73,7 +74,7 @@ async function removeOne(row: SoftwareVersionItem) {
|
||||
selectedIds.value = new Set([...selectedIds.value].filter((id) => id !== row.id))
|
||||
await load()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
|
||||
showAdminFeedback(loadFailureMessage(error, '删除失败'), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ async function load() {
|
||||
try {
|
||||
items.value = (await fetchSoftwareVersions()).items
|
||||
} catch (error) {
|
||||
loadFailure.value = error instanceof Error ? error.message : '版本列表加载失败'
|
||||
loadFailure.value = loadFailureMessage(error, '版本列表加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -146,7 +147,8 @@ async function submitUpload() {
|
||||
uploadPercent.value = 0
|
||||
load()
|
||||
} catch (error) {
|
||||
uploadMsg.value = error instanceof Error ? error.message : '上传失败'
|
||||
// P2-10:api/http 拦截器不 sanitize,error.message 可能是英文异常原文——界面只吃中文出口,原文进 console。
|
||||
uploadMsg.value = loadFailureMessage(error, '上传失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
@@ -160,7 +162,7 @@ onMounted(load)
|
||||
<section class="panel-box">
|
||||
<div class="version-head">
|
||||
<h3>版本列表</h3>
|
||||
<div class="version-head-tools">
|
||||
<div class="version-head-tools admin-header-controls">
|
||||
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="version-keyword" />
|
||||
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
|
||||
<button class="btn" type="button" @click="openUpload">上传新版本</button>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { fetchTutorialPackages, uploadTutorialPackage, deleteTutorialPackages }
|
||||
import { formatFileSize } from './tutorial-model.ts'
|
||||
import type { TutorialPackageItem } from './tutorial-dto.ts'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
@@ -119,7 +120,7 @@ async function removeSelected() {
|
||||
selectedIds.value = new Set()
|
||||
await load()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
|
||||
showAdminFeedback(loadFailureMessage(error, '删除失败'), 'error')
|
||||
}
|
||||
}
|
||||
async function removeOne(row: TutorialPackageItem) {
|
||||
@@ -130,7 +131,7 @@ async function removeOne(row: TutorialPackageItem) {
|
||||
selectedIds.value = new Set([...selectedIds.value].filter((id) => id !== row.id))
|
||||
await load()
|
||||
} catch (error) {
|
||||
showAdminFeedback(error instanceof Error ? error.message : '删除失败', 'error')
|
||||
showAdminFeedback(loadFailureMessage(error, '删除失败'), 'error')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +150,7 @@ async function load() {
|
||||
try {
|
||||
items.value = (await fetchTutorialPackages()).items
|
||||
} catch (error) {
|
||||
loadFailure.value = error instanceof Error ? error.message : '教程包列表加载失败'
|
||||
loadFailure.value = loadFailureMessage(error, '教程包列表加载失败')
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -198,7 +199,8 @@ async function submitUpload() {
|
||||
uploadPercent.value = 0
|
||||
load()
|
||||
} catch (error) {
|
||||
uploadMsg.value = error instanceof Error ? error.message : '上传失败'
|
||||
// P2-10:api/http 拦截器不 sanitize,error.message 可能是英文异常原文——界面只吃中文出口,原文进 console。
|
||||
uploadMsg.value = loadFailureMessage(error, '上传失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
@@ -212,7 +214,7 @@ onMounted(load)
|
||||
<section class="panel-box">
|
||||
<div class="tutorial-head">
|
||||
<h3>教程包列表</h3>
|
||||
<div class="tutorial-head-tools">
|
||||
<div class="tutorial-head-tools admin-header-controls">
|
||||
<input v-model="keyword" type="text" placeholder="搜索文件名" class="tutorial-keyword" />
|
||||
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
|
||||
<button class="btn" type="button" @click="openUpload">上传教程包</button>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 数富AI工作台客户端包管理页:上传 ZIP → 直传 MinIO → 服务端复算 sha256 落库;
|
||||
* 客户端从 /api/workbench-client/version/latest 自动检测并按最新上传升级。
|
||||
/** 数富AI工作台客户端包管理页:上传 ZIP → 直传 MinIO → 服务端复算 sha256 落库。
|
||||
* 列表默认按上传时间倒序,第一条即当前生效版本;删除最新包后自动回落到上一版。 */
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -129,7 +128,7 @@ async function submitUpload() {
|
||||
return
|
||||
}
|
||||
if (!isValidWorkbenchClientVersion(newVersion.value)) {
|
||||
uploadMsg.value = `版本号不能超过 ${WORKBENCH_CLIENT_VERSION_MAX_LENGTH} 个字符`
|
||||
uploadMsg.value = '版本号必须是纯数字 x.y.z 格式(如 1.0.113),不能带 v 前缀或其他后缀'
|
||||
return
|
||||
}
|
||||
if (!pickedFile.value) {
|
||||
@@ -171,13 +170,13 @@ onMounted(load)
|
||||
<section class="panel-box">
|
||||
<div class="workbench-head">
|
||||
<h3>客户端包列表</h3>
|
||||
<div class="workbench-head-tools">
|
||||
<div class="workbench-head-tools admin-header-controls">
|
||||
<input v-model="keyword" type="text" placeholder="搜索版本号或文件名" class="workbench-keyword" />
|
||||
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
|
||||
<button class="btn" type="button" @click="openUpload">上传客户端包</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="page-hint">客户端更新检查接口:<code>/api/workbench-client/version/latest</code>;最新上传的一条即当前生效版本。</p>
|
||||
<p class="page-hint">最新上传的一条即当前生效版本。</p>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="table-scroll workbench-table-scroll">
|
||||
@@ -242,8 +241,8 @@ onMounted(load)
|
||||
<p class="upload-desc">上传数富AI工作台客户端 ZIP 包后,客户端会从公开版本接口自动检测到新版本并升级;服务端会复算 sha256 供客户端校验。</p>
|
||||
<el-form label-width="110px">
|
||||
<el-form-item label="版本号" required>
|
||||
<el-input v-model="newVersion" :placeholder="`例如:1.0.0(最长 ${WORKBENCH_CLIENT_VERSION_MAX_LENGTH} 字符)`" :maxlength="WORKBENCH_CLIENT_VERSION_MAX_LENGTH" />
|
||||
<p class="zip-hint">客户端按版本号判断是否需要升级,必填</p>
|
||||
<el-input v-model="newVersion" :placeholder="`例如:1.0.113(纯数字 x.y.z,最长 ${WORKBENCH_CLIENT_VERSION_MAX_LENGTH} 字符)`" :maxlength="WORKBENCH_CLIENT_VERSION_MAX_LENGTH" />
|
||||
<p class="zip-hint">客户端按版本号判断是否需要升级,必填;不要带 v 前缀</p>
|
||||
</el-form-item>
|
||||
<el-form-item label="ZIP 压缩包" required>
|
||||
<el-upload :auto-upload="false" :limit="1" accept=".zip" :on-change="(file: any) => onFileChange(file.raw)" :on-remove="() => (pickedFile = null)">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** 教程包接口适配(教程管理页):列表 / 直传预签名 / 确认 / 删除。 */
|
||||
import axios from 'axios'
|
||||
import { http, unwrap } from '@/api/http'
|
||||
import { CHUNK_UPLOAD_THRESHOLD, uploadFileInChunks } from '@/api/chunk-upload'
|
||||
import { parseTutorialPackageList, parseTutorialPackageUpload } from './tutorial-model.ts'
|
||||
import type { TutorialPackageItem, TutorialPackageList } from './tutorial-dto.ts'
|
||||
|
||||
@@ -43,10 +44,15 @@ export async function requestTutorialPresign(fileName: string, version = ''): Pr
|
||||
}
|
||||
|
||||
/** 第三步:直传完成后通知后端校验对象并写入记录(data.item 为新记录行)。 */
|
||||
export async function confirmTutorialPackage(objectKey: string, fileName: string, version = ''): Promise<TutorialPackageItem | null> {
|
||||
const { data } = await http.post<unknown>(TUTORIAL_CONFIRM_ENDPOINT, null, {
|
||||
params: { object_key: objectKey, file_name: fileName, version },
|
||||
})
|
||||
export async function confirmTutorialPackage(
|
||||
objectKey: string,
|
||||
fileName: string,
|
||||
version = '',
|
||||
fileKey = '',
|
||||
): Promise<TutorialPackageItem | null> {
|
||||
const params: Record<string, string> = { object_key: objectKey, file_name: fileName, version }
|
||||
if (fileKey) params.file_key = fileKey
|
||||
const { data } = await http.post<unknown>(TUTORIAL_CONFIRM_ENDPOINT, null, { params })
|
||||
return parseTutorialPackageUpload(data)
|
||||
}
|
||||
|
||||
@@ -68,6 +74,11 @@ export async function uploadTutorialPackage(
|
||||
version = '',
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<TutorialPackageItem | null> {
|
||||
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
||||
const uploaded = await uploadFileInChunks(file, fileName, onProgress)
|
||||
const fileKey = String(uploaded.fileKey ?? uploaded.file_key ?? '')
|
||||
return confirmTutorialPackage(String(uploaded.objectKey ?? ''), fileName, version, fileKey)
|
||||
}
|
||||
const target = await requestTutorialPresign(fileName, version)
|
||||
await directPut.put(target.uploadUrl, file, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** 软件版本列表加载适配(任务 127):GET /api/admin/versions。 */
|
||||
import axios from 'axios'
|
||||
import { http, unwrap } from '@/api/http'
|
||||
import { CHUNK_UPLOAD_THRESHOLD, uploadFileInChunks } from '@/api/chunk-upload'
|
||||
import { parseSoftwareVersionList, parseSoftwareVersionUpload } from './version-model.ts'
|
||||
import type { SoftwareVersionItem, SoftwareVersionList } from './version-dto.ts'
|
||||
|
||||
@@ -45,9 +46,14 @@ export async function requestSoftwareVersionPresign(version: string): Promise<So
|
||||
}
|
||||
}
|
||||
|
||||
/** 第三步:直传完成后通知后端校验对象并写入版本记录(data.item 为新版本行)。 */
|
||||
export async function confirmSoftwareVersion(version: string): Promise<SoftwareVersionItem | null> {
|
||||
const { data } = await http.post<unknown>(SOFTWARE_VERSION_CONFIRM_ENDPOINT, null, { params: { version } })
|
||||
/**
|
||||
* 第三步:上传完成后通知后端校验并写入版本记录(data.item 为新版本行)。
|
||||
* 分片通道把拼装件留在 Java 临时目录,服务端按 file_key 搬进 client 桶后再落库。
|
||||
*/
|
||||
export async function confirmSoftwareVersion(version: string, fileKey = ''): Promise<SoftwareVersionItem | null> {
|
||||
const params: Record<string, string> = { version }
|
||||
if (fileKey) params.file_key = fileKey
|
||||
const { data } = await http.post<unknown>(SOFTWARE_VERSION_CONFIRM_ENDPOINT, null, { params })
|
||||
return parseSoftwareVersionUpload(data)
|
||||
}
|
||||
|
||||
@@ -69,6 +75,12 @@ export async function uploadSoftwareVersion(
|
||||
_filename = '',
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<SoftwareVersionUploadResult> {
|
||||
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
||||
const uploaded = await uploadFileInChunks(file, `${version}.zip`, onProgress)
|
||||
const fileKey = String(uploaded.fileKey ?? uploaded.file_key ?? '')
|
||||
const item = await confirmSoftwareVersion(version, fileKey)
|
||||
return { version, fileUrl: item?.fileUrl || String(uploaded.url ?? ''), item }
|
||||
}
|
||||
const target = await requestSoftwareVersionPresign(version)
|
||||
await directPut.put(target.uploadUrl, file, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** 工作台客户端包接口适配:列表 / 直传预签名 / 确认 / 删除。 */
|
||||
/** 工作台客户端包接口适配:列表 / 直传预签名 / 分片上传 / 确认 / 删除。 */
|
||||
import axios from 'axios'
|
||||
import { http, unwrap } from '@/api/http'
|
||||
import {
|
||||
@@ -12,13 +12,26 @@ export const WORKBENCH_CLIENT_PACKAGE_ENDPOINT = '/api/admin/workbench-client/pa
|
||||
export const WORKBENCH_CLIENT_PRESIGN_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/presign`
|
||||
export const WORKBENCH_CLIENT_CONFIRM_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/confirm`
|
||||
export const WORKBENCH_CLIENT_DELETE_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/delete`
|
||||
|
||||
/** 客户端自动更新契约(后管页面不直接调用):GET 返回 {version,file_url,sha256,...}。 */
|
||||
export const WORKBENCH_CLIENT_PUBLIC_LATEST_ENDPOINT = '/api/workbench-client/version/latest'
|
||||
/** 分片通道(S1-F3/AC-17):init/complete/abort 在工作台端点,分片体走通用 /api/files/chunk。 */
|
||||
export const WORKBENCH_CLIENT_CHUNK_INIT_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/chunk/init`
|
||||
export const WORKBENCH_CLIENT_CHUNK_COMPLETE_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/chunk/complete`
|
||||
export const WORKBENCH_CLIENT_CHUNK_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/chunk`
|
||||
/** confirm 失败的补偿清理:只删"已转存未登记"的对象(已登记后端拒绝)。 */
|
||||
export const WORKBENCH_CLIENT_UNCONFIRMED_OBJECT_ENDPOINT = `${WORKBENCH_CLIENT_PACKAGE_ENDPOINT}/object`
|
||||
export const FILES_CHUNK_ENDPOINT = '/api/files/chunk'
|
||||
|
||||
/** MinIO 直传专用实例:不带 cookie、不挂 401 跳登录拦截器;大 zip 给足超时。 */
|
||||
const directPut = axios.create({ timeout: 600_000, withCredentials: false })
|
||||
|
||||
/** 单片大小:8MB——93MB 包 ≈ 12 片,一片失败只重传 8MB,不再从 0 重来。 */
|
||||
export const UPLOAD_PART_SIZE = 8 * 1024 * 1024
|
||||
|
||||
/** ≤64MB 仍走单次预签名直传(链路最短);再大改分片(S1-F3)。 */
|
||||
export const DIRECT_PUT_MAX_BYTES = 64 * 1024 * 1024
|
||||
|
||||
/** 每片重试次数(不含首次):弱网下一片抖一下不必整单作废。 */
|
||||
const PART_RETRY_LIMIT = 2
|
||||
|
||||
export async function fetchWorkbenchClientPackages(): Promise<WorkbenchClientPackageList> {
|
||||
const { data } = await http.get<unknown>(WORKBENCH_CLIENT_PACKAGES_ENDPOINT)
|
||||
return parseWorkbenchClientPackageList(data)
|
||||
@@ -70,6 +83,35 @@ export async function confirmWorkbenchClientPackage(
|
||||
return parseWorkbenchClientPackageUpload(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* confirm 失败后的补偿清理:删除"已转存但未登记"的对象。
|
||||
* 后端对已登记对象会拒绝清理(防止误删线上正在用的包),失败不覆盖原始错误。
|
||||
* 返回是否确实清理成功——调用方据此决定报错文案是"可重传"还是"先刷新核对"。
|
||||
*/
|
||||
async function deleteUnconfirmedPackageObject(objectKey: string): Promise<boolean> {
|
||||
try {
|
||||
await http.delete(WORKBENCH_CLIENT_UNCONFIRMED_OBJECT_ENDPOINT, {
|
||||
params: { object_key: objectKey },
|
||||
})
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* confirm 失败后的补偿清理(分片链):删会话 + 尽力删未登记对象。
|
||||
*/
|
||||
async function cleanupUnconfirmedPackage(uploadId: string, objectKey: string): Promise<void> {
|
||||
try {
|
||||
await http.delete(`${WORKBENCH_CLIENT_CHUNK_ENDPOINT}/${encodeURIComponent(uploadId)}`, {
|
||||
params: objectKey ? { object_key: objectKey } : {},
|
||||
})
|
||||
} catch {
|
||||
// 尽力而为:清理失败只说明残留等人工处置,不能替原始错误改口
|
||||
}
|
||||
}
|
||||
|
||||
/** 按 id 批量删除客户端包(后端会顺带清理无引用对象的 MinIO 包体);返回实际删除行数。 */
|
||||
export async function deleteWorkbenchClientPackages(ids: number[]): Promise<number> {
|
||||
if (!ids.length) return 0
|
||||
@@ -78,17 +120,12 @@ export async function deleteWorkbenchClientPackages(ids: number[]): Promise<numb
|
||||
return typeof core.deleted === 'number' ? core.deleted : ids.length
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传客户端包(浏览器直传):presign 申请 → 直接 PUT 到 MinIO client 桶(不走 Java 中转)
|
||||
* → confirm 由服务端复算 sha256 落库。onProgress 回传 0-100 上传进度。
|
||||
*/
|
||||
export async function uploadWorkbenchClientPackage(
|
||||
/** 单次预签名 PUT 直传(≤DIRECT_PUT_MAX_BYTES 的短链路)。 */
|
||||
async function directPutUpload(
|
||||
file: Blob,
|
||||
fileName: string,
|
||||
version: string,
|
||||
target: WorkbenchClientUploadTarget,
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<WorkbenchClientPackageItem | null> {
|
||||
const target = await requestWorkbenchClientPresign(fileName, version)
|
||||
): Promise<void> {
|
||||
await directPut.put(target.uploadUrl, file, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
onUploadProgress: (event) => {
|
||||
@@ -97,11 +134,114 @@ export async function uploadWorkbenchClientPackage(
|
||||
onProgress(total > 0 ? Math.min(Math.round((event.loaded / total) * 100), 100) : 0)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 分片上传(S1-F3/AC-17):整包切成 partSize 片逐片 POST,每片独立重试;
|
||||
* 开传前先查已到片号——上一次断掉的会话可以直接续传(后端保留 24h)。
|
||||
* 这一问失败不静默按「全缺」重传:93MB 的包问不到续传点就说明链路已经不对了,
|
||||
* 当场报错让人重来,也比闷头把整包再传一遍便宜。
|
||||
*/
|
||||
async function chunkedUpload(
|
||||
file: Blob,
|
||||
uploadId: string,
|
||||
totalParts: number,
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<void> {
|
||||
const { data } = await http.get<unknown>(`${FILES_CHUNK_ENDPOINT}/${encodeURIComponent(uploadId)}`)
|
||||
const core = (unwrap(data) ?? {}) as Record<string, unknown>
|
||||
const done = new Set<number>(
|
||||
(Array.isArray(core.uploaded_parts) ? core.uploaded_parts : []).map((index) => Number(index)),
|
||||
)
|
||||
const report = (partial: number) => {
|
||||
if (!onProgress) return
|
||||
const loaded = done.size * UPLOAD_PART_SIZE + partial
|
||||
onProgress(Math.min(Math.round((loaded / file.size) * 100), 99))
|
||||
}
|
||||
for (let index = 0; index < totalParts; index += 1) {
|
||||
if (done.has(index)) {
|
||||
report(0)
|
||||
continue
|
||||
}
|
||||
const blob = file.slice(index * UPLOAD_PART_SIZE, Math.min(file.size, (index + 1) * UPLOAD_PART_SIZE))
|
||||
let lastError: unknown = null
|
||||
for (let attempt = 0; attempt <= PART_RETRY_LIMIT; attempt += 1) {
|
||||
const form = new FormData()
|
||||
form.append('file', blob, `part-${index}`)
|
||||
try {
|
||||
await http.post(`${FILES_CHUNK_ENDPOINT}/${encodeURIComponent(uploadId)}/part/${index}`, form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: 300_000,
|
||||
onUploadProgress: (event) => report(Math.min(event.loaded || 0, blob.size)),
|
||||
})
|
||||
done.add(index)
|
||||
lastError = null
|
||||
break
|
||||
} catch (error) {
|
||||
lastError = error
|
||||
}
|
||||
}
|
||||
if (lastError) {
|
||||
throw lastError instanceof Error ? lastError : new Error(`第 ${index} 片上传失败`)
|
||||
}
|
||||
}
|
||||
if (onProgress) onProgress(100)
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传客户端包:≤64MB 走浏览器直传预签名 PUT;大包走后端分片通道(每片可重试/续传,
|
||||
* 服务端拼装后转存 client 桶)。两条链最后都收敛到 confirm:服务端复算 sha256、
|
||||
* 凭据扫描、版本唯一性登记。confirm 失败清理未登记对象,不留孤儿。
|
||||
*/
|
||||
export async function uploadWorkbenchClientPackage(
|
||||
file: Blob,
|
||||
fileName: string,
|
||||
version: string,
|
||||
onProgress?: (percent: number) => void,
|
||||
): Promise<WorkbenchClientPackageItem | null> {
|
||||
if (file.size <= DIRECT_PUT_MAX_BYTES) {
|
||||
const target = await requestWorkbenchClientPresign(fileName, version)
|
||||
await directPutUpload(file, target, onProgress)
|
||||
try {
|
||||
return await confirmWorkbenchClientPackage(target.objectKey, target.fileName, target.version)
|
||||
} catch (error) {
|
||||
// confirm 失败先 cleanup 未登记对象再报错;服务端若已登记会拒绝清理(CR-08 幂等窗口),
|
||||
// 那种情况保留原错误文案引导"先刷新列表",不冒充已处置。
|
||||
const cleaned = await deleteUnconfirmedPackageObject(target.objectKey)
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
if (cleaned) {
|
||||
throw new Error(`安装包已上传但登记未完成(${reason})。未登记对象已清理,可直接重新上传。`)
|
||||
}
|
||||
throw new Error(`安装包已上传,但确认未完成(${reason})。请先刷新列表确认,不要立即重复上传。`)
|
||||
}
|
||||
}
|
||||
const totalParts = Math.max(1, Math.ceil(file.size / UPLOAD_PART_SIZE))
|
||||
const { data } = await http.post<unknown>(WORKBENCH_CLIENT_CHUNK_INIT_ENDPOINT, null, {
|
||||
params: { file_name: fileName, version, total_parts: totalParts, total_bytes: file.size },
|
||||
})
|
||||
const core = (unwrap(data) ?? {}) as Record<string, unknown>
|
||||
const uploadId = typeof core.upload_id === 'string' ? core.upload_id : ''
|
||||
const objectKey = typeof core.object_key === 'string' ? core.object_key : ''
|
||||
if (!uploadId || !objectKey) {
|
||||
throw new Error('后端未返回分片会话,请重试')
|
||||
}
|
||||
const confirmedName = typeof core.file_name === 'string' ? core.file_name : fileName
|
||||
const confirmedVersion = typeof core.version === 'string' ? core.version : version
|
||||
let assembled = false
|
||||
try {
|
||||
return await confirmWorkbenchClientPackage(target.objectKey, target.fileName, target.version)
|
||||
await chunkedUpload(file, uploadId, totalParts, onProgress)
|
||||
await http.post(WORKBENCH_CLIENT_CHUNK_COMPLETE_ENDPOINT, null, {
|
||||
params: { upload_id: uploadId, object_key: objectKey, file_name: confirmedName, version: confirmedVersion },
|
||||
timeout: 600_000,
|
||||
})
|
||||
assembled = true
|
||||
return await confirmWorkbenchClientPackage(objectKey, confirmedName, confirmedVersion)
|
||||
} catch (error) {
|
||||
// 对象已经 PUT 成功,confirm 失败不等于上传失败;引导管理员先刷新列表,避免重复上传
|
||||
await cleanupUnconfirmedPackage(uploadId, objectKey)
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(`安装包已上传,但确认未完成(${reason})。请先刷新列表确认,不要立即重复上传。`)
|
||||
if (assembled) {
|
||||
throw new Error(`安装包已转存但登记未完成(${reason})。未登记对象已清理,可直接重新上传。`)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,15 @@ export function parseWorkbenchClientPackageUpload(payload: unknown): WorkbenchCl
|
||||
return item ? toWorkbenchClientPackageItem(item) : null
|
||||
}
|
||||
|
||||
/** 版本号必填且不超过后端列宽;客户端要靠它比较是否需要升级。 */
|
||||
/**
|
||||
* 版本号必填、纯数字 x.y.z、且不超过后端列宽。
|
||||
* 客户端按数字逐段比较,v 前缀/两段/后缀会让严格解析器判非法 ⇒ 检查更新永远回「已是最新」。
|
||||
*/
|
||||
export function isValidWorkbenchClientVersion(value: string): boolean {
|
||||
const normalized = typeof value === 'string' ? value.trim() : ''
|
||||
return normalized.length > 0 && normalized.length <= WORKBENCH_CLIENT_VERSION_MAX_LENGTH
|
||||
return normalized.length > 0
|
||||
&& normalized.length <= WORKBENCH_CLIENT_VERSION_MAX_LENGTH
|
||||
&& /^\d+\.\d+\.\d+$/.test(normalized)
|
||||
}
|
||||
|
||||
/** 字节数展示:0=未知展示为 -,其余按 KB/MB/GB 人性化。 */
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 店铺密钥管理页 · 像素复刻旧版 admin.html panel-shop-keys(自绘:面板头+新增店铺密钥、序号列、令牌掩码、白名单状态药丸+悬停详情、旧式分页)。
|
||||
* script 逻辑沿用现有 Vue 实现(编辑留空令牌=沿用);弹窗保留现有组件。 */
|
||||
@@ -57,7 +61,10 @@ function whitelistTooltip(row: ShopKeyItem): string {
|
||||
return parts.join('\n')
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
@@ -69,14 +76,16 @@ async function load() {
|
||||
whitelistStatus: filter.whitelistStatus || undefined,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
page.value = result.page
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '密钥列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,11 +160,23 @@ async function submit() {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.ziniaoAccountName,
|
||||
deleteOne: (id) => deleteShopKey(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
})
|
||||
|
||||
async function remove(row: ShopKeyItem) {
|
||||
if (batch.busy) return
|
||||
// 对齐旧版:原生 confirm。
|
||||
if (!(await openAdminConfirm({ message: `确定删除店铺密钥“${row.ziniaoAccountName}”吗?`, danger: true }))) return
|
||||
try {
|
||||
await deleteShopKey(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -226,12 +247,17 @@ onMounted(load)
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="shop-key-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<!-- 刚性列(序号/两个时间/操作)给准 px,文本列收到"能 ellipsis 但不白占"的宽度:
|
||||
原来 1538px 在 ~1280 的内容区里放不下,"操作"整列要横向滚动才看得见。 -->
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 52px">序号</th>
|
||||
<th style="width: 110px">备注名</th>
|
||||
<th style="width: 140px">紫鸟账号名称</th>
|
||||
@@ -245,7 +271,11 @@ onMounted(load)
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="(row, index) in rows" :key="row.id">
|
||||
<tr v-for="(row, index) in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
|
||||
<td>{{ row.remarkName || '—' }}</td>
|
||||
<td>{{ row.ziniaoAccountName }}</td>
|
||||
@@ -280,15 +310,15 @@ onMounted(load)
|
||||
>
|
||||
{{ checkingId === row.id ? '检测中…' : '检测白名单' }}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
<td colspan="10" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="9" class="empty-tip">{{ anyFilterActive ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
|
||||
<td colspan="10" class="empty-tip">{{ anyFilterActive ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
/** 店铺管理页 · 像素复刻旧版 admin.html panel-shop-manage(自绘:面板头+新增店铺、筛选、密码列 ******+眼睛实时读明文、旧式表格/分页、原生 confirm 删除)。
|
||||
* script 逻辑沿用现有 Vue 实现(凭证明文 dialog/编辑弹窗/分组筛选)。 */
|
||||
@@ -87,7 +91,10 @@ async function loadGroups() {
|
||||
}
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
@@ -98,14 +105,16 @@ async function load() {
|
||||
shopName: filter.shopName.trim() || undefined,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
page.value = result.page
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '店铺列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,11 +208,23 @@ async function showCredential(row: ShopSummary) {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.shopName,
|
||||
deleteOne: (id) => deleteShopManage(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value,
|
||||
scope: () => companyTab.activeId,
|
||||
})
|
||||
|
||||
async function remove(row: ShopSummary) {
|
||||
if (batch.busy) return
|
||||
// 对齐旧版:原生 confirm。
|
||||
if (!(await openAdminConfirm({ message: `确定删除店铺“${row.shopName}”吗?`, danger: true }))) return
|
||||
try {
|
||||
await deleteShopManage(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
} catch (error) {
|
||||
@@ -249,10 +270,15 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="table-scroll shop-manage-table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 58px">序号</th>
|
||||
<th v-if="isSuperAdmin" style="width: 120px">分组</th>
|
||||
<th style="width: 150px">店铺名</th>
|
||||
@@ -267,7 +293,11 @@ onMounted(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-if="rows.length">
|
||||
<tr v-for="(row, index) in rows" :key="row.id">
|
||||
<tr v-for="(row, index) in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
|
||||
<td v-if="isSuperAdmin" data-text :title="row.groupName || '—'">{{ row.groupName || '—' }}</td>
|
||||
<td :title="row.shopName">{{ row.shopName }}</td>
|
||||
@@ -290,15 +320,15 @@ onMounted(() => {
|
||||
<td class="ops-cell">
|
||||
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
|
||||
<button class="btn btn-sm btn-secondary" type="button" @click="showCredential(row)">凭证</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isSuperAdmin ? 11 : 10" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">暂无店铺</td>
|
||||
<td :colspan="isSuperAdmin ? 11 : 10" class="empty-tip">暂无店铺</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -379,17 +379,19 @@ onUnmounted(() => {
|
||||
<label>账号</label>
|
||||
<input v-model="filter.username" type="text" placeholder="模糊搜索账号名" @keyup.enter="search" />
|
||||
</div>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select
|
||||
(与下方店铺筛选同形,挂全局 admin-filter 皮肤)。 -->
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>业务</label>
|
||||
<select v-model="filter.moduleType">
|
||||
<option v-for="option in MODULE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.moduleType" class="admin-filter" aria-label="筛选业务">
|
||||
<el-option v-for="option in MODULE_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 130px">
|
||||
<label>状态</label>
|
||||
<select v-model="filter.status">
|
||||
<option v-for="option in TASK_STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.status" class="admin-filter" aria-label="筛选任务状态">
|
||||
<el-option v-for="option in TASK_STATUS_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group shop-filter">
|
||||
<label>店铺</label>
|
||||
@@ -447,9 +449,11 @@ onUnmounted(() => {
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>状态</label>
|
||||
<select v-model="variantFilter.status">
|
||||
<option v-for="option in VARIANT_STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
value 原样透传('0'~'3' 是字符串,后端按值比对)。 -->
|
||||
<el-select v-model="variantFilter.status" class="admin-filter" aria-label="筛选变体状态">
|
||||
<el-option v-for="option in VARIANT_STATUS_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
@@ -689,8 +693,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -703,8 +706,7 @@ h3 {
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
/**
|
||||
* 品牌Gating库管理页(独立菜单 admin_brand_gating,V174 恢复)。
|
||||
* 数据源 /api/admin/brand-gating(biz_brand_gating,全平台共享,不随公司 Tab 收窄)。
|
||||
@@ -191,7 +194,18 @@ async function toggleStatus(row: BrandGatingRow): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => rows.value,
|
||||
rowId: (row) => row.id,
|
||||
rowLabel: (row) => row.brand || `ID ${row.id}`,
|
||||
deleteOne: (id) => deleteBrandGating(id),
|
||||
refresh: () => Promise.all([loadPage(), loadStats()]),
|
||||
blocked: () => pageLoading.value || busyRowId.value !== 0 || !!loadError.value,
|
||||
consequence: '删除后可能影响已有数据,此操作不可恢复。',
|
||||
})
|
||||
|
||||
async function removeRow(row: BrandGatingRow): Promise<void> {
|
||||
if (batch.busy) return
|
||||
const confirmed = await openAdminConfirm({ danger: true,
|
||||
targetName: row.brand,
|
||||
message: `确认删除 ID=${row.id} 的「${row.brand}」Gating记录?此操作可能影响已有数据。`,
|
||||
@@ -200,6 +214,7 @@ async function removeRow(row: BrandGatingRow): Promise<void> {
|
||||
busyRowId.value = row.id
|
||||
try {
|
||||
await deleteBrandGating(row.id)
|
||||
batch.removeFromSelection(row.id)
|
||||
feedback('已删除', 'success')
|
||||
const nextPage = rows.value.length === 1 && page.value > 1 ? page.value - 1 : page.value
|
||||
await Promise.all([loadPage(nextPage), loadStats()])
|
||||
@@ -253,15 +268,16 @@ onMounted(() => {
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>国家</span>
|
||||
<select v-model="form.country">
|
||||
<option v-for="country in GATING_COUNTRIES" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。 -->
|
||||
<el-select v-model="form.country" class="admin-filter" aria-label="表单国家">
|
||||
<el-option v-for="country in GATING_COUNTRIES" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>类型</span>
|
||||
<select v-model="form.gatingType">
|
||||
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
|
||||
</select>
|
||||
<el-select v-model="form.gatingType" class="admin-filter" aria-label="表单类型">
|
||||
<el-option v-for="type in typeOptions" :key="type" :value="type" :label="type" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>ASIN</span>
|
||||
@@ -302,33 +318,40 @@ onMounted(() => {
|
||||
<div class="g-panel-body">
|
||||
<div class="g-filters">
|
||||
<input v-model="filter.keyword" placeholder="搜索品牌 / ASIN" @keyup.enter="query" />
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<select v-model="filter.gatingType">
|
||||
<option value="">全部类型</option>
|
||||
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
|
||||
</select>
|
||||
<select v-model="filter.status">
|
||||
<option value="">全部状态</option>
|
||||
<option value="1">生效</option>
|
||||
<option value="0">已解除</option>
|
||||
</select>
|
||||
<select v-model="filter.source">
|
||||
<option value="">全部来源</option>
|
||||
<option v-for="source in GATING_SOURCES" :key="source" :value="source">{{ sourceText(source) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留、status 的 '1'/'0' 仍是字符串(后端按值比对)。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" style="width: 132px" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="country in countryOptions" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.gatingType" class="admin-filter" style="width: 132px" aria-label="筛选类型">
|
||||
<el-option value="" label="全部类型" />
|
||||
<el-option v-for="type in typeOptions" :key="type" :value="type" :label="type" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.status" class="admin-filter" style="width: 132px" aria-label="筛选状态">
|
||||
<el-option value="" label="全部状态" />
|
||||
<el-option value="1" label="生效" />
|
||||
<el-option value="0" label="已解除" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.source" class="admin-filter" style="width: 132px" aria-label="筛选来源">
|
||||
<el-option value="" label="全部来源" />
|
||||
<el-option v-for="source in GATING_SOURCES" :key="source" :value="source" :label="sourceText(source)" />
|
||||
</el-select>
|
||||
<button class="g-btn g-btn-primary" type="button" @click="query">查询</button>
|
||||
<button class="g-btn g-btn-ghost" type="button" @click="resetFilter">重置</button>
|
||||
</div>
|
||||
|
||||
<LoadFailureBar v-if="loadError" :message="loadError" @retry="loadPage()" />
|
||||
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
<div class="g-table-wrap" v-loading="pageLoading">
|
||||
<table v-if="rows.length" class="g-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="batch-delete-cell" scope="col">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
</th>
|
||||
<th style="width: 64px">ID</th>
|
||||
<th>品牌</th>
|
||||
<th>ASIN</th>
|
||||
@@ -343,7 +366,11 @@ onMounted(() => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rows" :key="row.id">
|
||||
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
|
||||
<td class="batch-delete-cell">
|
||||
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
</td>
|
||||
<td class="g-dim">{{ row.id }}</td>
|
||||
<td class="g-strong">{{ row.brand }}</td>
|
||||
<td class="g-mono">{{ row.asin || '—' }}</td>
|
||||
@@ -372,7 +399,7 @@ onMounted(() => {
|
||||
<button
|
||||
class="g-btn g-btn-sm g-btn-danger"
|
||||
type="button"
|
||||
:disabled="busyRowId === row.id"
|
||||
:disabled="batch.busy || busyRowId === row.id"
|
||||
@click="removeRow(row)"
|
||||
>
|
||||
删除
|
||||
@@ -522,10 +549,9 @@ onMounted(() => {
|
||||
.g-field-wide {
|
||||
grid-column: span 2;
|
||||
}
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter,这里只留原生输入框。 */
|
||||
.g-field input,
|
||||
.g-field select,
|
||||
.g-filters input,
|
||||
.g-filters select {
|
||||
.g-filters input {
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
@@ -538,13 +564,28 @@ onMounted(() => {
|
||||
outline: none;
|
||||
}
|
||||
.g-field input:focus,
|
||||
.g-field select:focus,
|
||||
.g-filters input:focus,
|
||||
.g-filters select:focus {
|
||||
.g-filters input:focus {
|
||||
border-color: var(--g-primary);
|
||||
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
background: #fff;
|
||||
}
|
||||
/* 本页表单/筛选行是 34px 紧凑档(输入框与 `.g-btn` 同为 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会在同一行里高出一截,
|
||||
与旁边的输入框错位 ⇒ 在本页把壳压回本地档位(scoped 下 :deep 穿透 EP 内部结构)。 */
|
||||
.g-field :deep(.el-select__wrapper),
|
||||
.g-filters :deep(.el-select__wrapper) {
|
||||
min-height: 34px;
|
||||
padding: 0 10px;
|
||||
border-radius: 7px;
|
||||
background: #fbfcfe;
|
||||
box-shadow: 0 0 0 1px #d7dce5 inset;
|
||||
font-size: 13px;
|
||||
}
|
||||
.g-field :deep(.el-select__wrapper.is-focused),
|
||||
.g-filters :deep(.el-select__wrapper.is-focused) {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 1px var(--g-primary) inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.g-form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
@@ -580,9 +621,6 @@ onMounted(() => {
|
||||
.g-filters input {
|
||||
width: 190px;
|
||||
}
|
||||
.g-filters select {
|
||||
width: 132px;
|
||||
}
|
||||
|
||||
.g-btn {
|
||||
height: 34px;
|
||||
|
||||
@@ -9,7 +9,16 @@ import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import type { DuplicateItem, DuplicateOccurrence, DuplicateMetrics, DuplicateShop } from './duplicate-model.ts'
|
||||
import { fetchDuplicateConsole, fetchDuplicateLedger, requestDuplicateExportBlob, type LedgerSortKey } from './duplicate-console-api.ts'
|
||||
import { aggregateDrawerRows, drawerSummaryOf, dupWithinGroup, indexShopGroups, type DrawerAggRow, type DrawerSummary, type ShopGroups } from './duplicate-console-logic.ts'
|
||||
import {
|
||||
aggregateDrawerRows,
|
||||
drawerSummaryOf,
|
||||
indexShopGroups,
|
||||
itemBrandOf,
|
||||
type DrawerAggRow,
|
||||
type DrawerSummary,
|
||||
type ShopGroups,
|
||||
} from './duplicate-console-logic.ts'
|
||||
import { useDuplicateMatrix } from './duplicate-matrix-window.ts'
|
||||
import type { DuplicateConsole, LedgerRow } from './duplicate-console-model.ts'
|
||||
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import { orderedPair } from '@/utils/datetime'
|
||||
@@ -73,7 +82,8 @@ function toast(msg: string) {
|
||||
const overview = computed(() => consoleData.value?.overview ?? null)
|
||||
const summary = computed<DuplicateMetrics | null>(() => overview.value?.summary ?? null)
|
||||
const shops = computed(() => overview.value?.shops ?? [])
|
||||
const dupItems = computed(() => consoleData.value?.dup ?? [])
|
||||
/** 当前撞款行窗口:服务端按 page/page_size(+dup_group) 切好的一窗(B60),页面不再自切全集。 */
|
||||
const dupItems = computed<DuplicateItem[]>(() => consoleData.value?.dup ?? [])
|
||||
const groupStats = computed(() => consoleData.value?.groups ?? [])
|
||||
|
||||
const countryOptions = computed<string[]>(() => {
|
||||
@@ -118,26 +128,32 @@ function selectedGroupMembers(): string[] {
|
||||
|
||||
const groupChips = computed(() => groupStats.value.filter((group) => group.shopCount >= 2))
|
||||
|
||||
/** 当前撞款行集:全局=撞款全集;分组=组内成员撞款子集;均按 ASIN 升序(reference 台账顺序)。 */
|
||||
const dupRows = computed<DuplicateItem[]>(() => {
|
||||
const rows = scope.value === 'global' ? dupItems.value : dupWithinGroup(dupItems.value, selectedGroupMembers())
|
||||
return [...rows].sort((a, b) => a.asin.localeCompare(b.asin))
|
||||
})
|
||||
|
||||
/** 矩阵列:分组范围=该组成员店;全店=全部可见店铺(按上架量降序)。 */
|
||||
const matrixShops = computed<string[]>(() => {
|
||||
if (scope.value === 'group') return selectedGroupMembers()
|
||||
return orderedShops.value.map((shop) => shop.shopName)
|
||||
})
|
||||
|
||||
const activeGroupStat = computed(() => groupStats.value.find((group) => group.name === selectedGroup.value) || null)
|
||||
/** 撞款 Tab 计数:全店范围取后端权威 total_dup(防后端截断计数偏小);分组范围取组内子集长度。 */
|
||||
const totalDupCount = computed(() => (scope.value === 'global' ? (consoleData.value?.totalDup ?? dupRows.value.length) : dupRows.value.length))
|
||||
/** 撞款行总数:服务端在本页 + 本范围(全局或所选分组)内未分页的计数,翻页控件与 KPI 共用。 */
|
||||
const totalDupCount = computed(() => consoleData.value?.totalDup ?? 0)
|
||||
|
||||
function itemBrand(item: DuplicateItem): string {
|
||||
for (const occ of item.occurrences || []) if (occ.brand) return occ.brand
|
||||
return ''
|
||||
}
|
||||
/** 撞款矩阵的行窗 + 列窗 + 格子视图(B60):状态与算法在 `duplicate-matrix-window.ts`,翻页动作交回这里。 */
|
||||
const {
|
||||
matrixPage,
|
||||
matrixPageSize,
|
||||
columnPage,
|
||||
columnWindowTotal,
|
||||
matrixAllColumns,
|
||||
matrixShops,
|
||||
matrixView,
|
||||
matrixHint,
|
||||
goMatrixPage,
|
||||
changeMatrixSize,
|
||||
goColumnPage,
|
||||
resetMatrixWindows,
|
||||
} = useDuplicateMatrix({
|
||||
rows: dupItems,
|
||||
groupMembers: computed(() => selectedGroupMembers()),
|
||||
groupScoped: computed(() => scope.value === 'group'),
|
||||
selectedGroup,
|
||||
reload: () => void loadConsole(),
|
||||
dataVersion: consoleData,
|
||||
})
|
||||
|
||||
|
||||
// ---- 撞款视图分页(分布/矩阵/撞款详情/抽屉明细;10/20/50/100 可选) ----
|
||||
@@ -147,16 +163,7 @@ const distPageSize = ref(10)
|
||||
const pagedDistBars = computed(() =>
|
||||
storeDistribution.value.list.slice((distPage.value - 1) * distPageSize.value, distPage.value * distPageSize.value),
|
||||
)
|
||||
const matrixPage = ref(1)
|
||||
const matrixPageSize = ref(10)
|
||||
const matrixRows = computed(() =>
|
||||
dupRows.value.slice((matrixPage.value - 1) * matrixPageSize.value, matrixPage.value * matrixPageSize.value),
|
||||
)
|
||||
const dupCardPage = ref(1)
|
||||
const dupCardPageSize = ref(10)
|
||||
const dupCardRows = computed(() =>
|
||||
dupRows.value.slice((dupCardPage.value - 1) * dupCardPageSize.value, dupCardPage.value * dupCardPageSize.value),
|
||||
)
|
||||
|
||||
const drawerPage = ref(1)
|
||||
const drawerPageSize = ref(10)
|
||||
const drawerRows = computed(() =>
|
||||
@@ -168,46 +175,15 @@ const groupStatsPageSize = ref(10)
|
||||
const pagedGroupStats = computed(() =>
|
||||
groupStats.value.slice((groupStatsPage.value - 1) * groupStatsPageSize.value, groupStatsPage.value * groupStatsPageSize.value),
|
||||
)
|
||||
watch([dupRows, drawerOccurrences, groupStats], () => {
|
||||
matrixPage.value = Math.min(matrixPage.value, Math.max(1, Math.ceil(dupRows.value.length / matrixPageSize.value)))
|
||||
dupCardPage.value = Math.min(dupCardPage.value, Math.max(1, Math.ceil(dupRows.value.length / dupCardPageSize.value)))
|
||||
watch([drawerOccurrences, groupStats], () => {
|
||||
drawerPage.value = 1
|
||||
groupStatsPage.value = Math.min(groupStatsPage.value, Math.max(1, Math.ceil(groupStats.value.length / groupStatsPageSize.value)))
|
||||
})
|
||||
|
||||
const matrixHint = computed(() =>
|
||||
scope.value === 'global'
|
||||
? '行 = 全店撞款ASIN,列 = 全部店铺;有数字表示该店在售此 ASIN,点击行可看上架时间明细'
|
||||
: selectedGroup.value
|
||||
? `行 = 分组「${selectedGroup.value}」内的撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN`
|
||||
: '行 = 分组内撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN',
|
||||
)
|
||||
|
||||
/* ----- 矩阵单元格辅助 ----- */
|
||||
function shopKey(name: string): string {
|
||||
return (name || '').trim().toLowerCase()
|
||||
}
|
||||
function cellOccurrences(item: DuplicateItem, shop: string): DuplicateOccurrence[] {
|
||||
const key = shopKey(shop)
|
||||
return (item.occurrences || []).filter((occ) => shopKey(occ.shopName) === key)
|
||||
}
|
||||
function cellCount(item: DuplicateItem, shop: string): number {
|
||||
return cellOccurrences(item, shop).length
|
||||
}
|
||||
function cellCountryDots(item: DuplicateItem, shop: string): string[] {
|
||||
const codes = new Set<string>()
|
||||
for (const occ of cellOccurrences(item, shop)) if (occ.country) codes.add(occ.country.toUpperCase())
|
||||
return [...codes]
|
||||
}
|
||||
function cellCountryCount(item: DuplicateItem, shop: string, code: string): number {
|
||||
return cellOccurrences(item, shop).filter((occ) => (occ.country || '').toUpperCase() === code).length
|
||||
}
|
||||
function cellTitle(item: DuplicateItem, shop: string): string {
|
||||
const count = cellCount(item, shop)
|
||||
if (!count) return `${shop} 无此 ASIN`
|
||||
const sites = cellCountryDots(item, shop).map((code) => `${asinCountryLabel(code)} ${cellCountryCount(item, shop, code)}条`).join('、')
|
||||
return `${shop} 在售 ${count} 条 · ${sites}`
|
||||
}
|
||||
|
||||
function activeFilterParams() {
|
||||
return { asin: filter.asin.trim(), shopName: filter.shop.trim(), group: filter.group.trim(), country: filter.country, site: '', dateFrom: filter.dateFrom, dateTo: filter.dateTo }
|
||||
@@ -217,7 +193,13 @@ async function loadConsole() {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
consoleData.value = await fetchDuplicateConsole({ view: '', ...activeFilterParams() }, companyTab.requestCompanyId)
|
||||
consoleData.value = await fetchDuplicateConsole(
|
||||
{ view: '', ...activeFilterParams() },
|
||||
companyTab.requestCompanyId,
|
||||
matrixPage.value,
|
||||
matrixPageSize.value,
|
||||
scope.value === 'group' ? selectedGroup.value : '',
|
||||
)
|
||||
shopGroups.value = indexShopGroups(orderedShops.value)
|
||||
if (groupStats.value.length && !groupStats.value.some((group) => group.name === selectedGroup.value)) {
|
||||
selectedGroup.value = groupChips.value[0] ? groupChips.value[0].name : ''
|
||||
@@ -270,6 +252,7 @@ function resetQuery() {
|
||||
scope.value = 'global'
|
||||
selectedGroup.value = ''
|
||||
activeTab.value = 'dup'
|
||||
resetMatrixWindows()
|
||||
applyQuery()
|
||||
toast('筛选已重置')
|
||||
}
|
||||
@@ -280,8 +263,21 @@ function switchTab(tab: Tab) {
|
||||
}
|
||||
|
||||
function switchScope(next: Scope) {
|
||||
if (scope.value === next) return
|
||||
scope.value = next
|
||||
if (next === 'group' && !selectedGroup.value && groupChips.value.length) selectedGroup.value = groupChips.value[0].name
|
||||
// 行范围换了(全局 ↔ 组内),服务端裁出来的那一窗也就换了 ⇒ 重新请一窗。
|
||||
resetMatrixWindows()
|
||||
void loadConsole()
|
||||
}
|
||||
|
||||
/** 分组 chip:选中即换行范围,与 switchScope 同一条出口(不再在客户端重裁一遍全集)。 */
|
||||
function selectGroup(name: string) {
|
||||
if (selectedGroup.value === name && scope.value === 'group') return
|
||||
scope.value = 'group'
|
||||
selectedGroup.value = name
|
||||
resetMatrixWindows()
|
||||
void loadConsole()
|
||||
}
|
||||
|
||||
async function reAnalyze() {
|
||||
@@ -338,7 +334,7 @@ function openDrawer(asin: string, brand: string, dupFlag: boolean, occurrences:
|
||||
}
|
||||
|
||||
function openDupDrawer(item: DuplicateItem) {
|
||||
openDrawer(item.asin, itemBrand(item), item.shopCount >= 2, item.occurrences)
|
||||
openDrawer(item.asin, itemBrandOf(item), item.shopCount >= 2, item.occurrences)
|
||||
}
|
||||
|
||||
function openLedgerDrawer(row: LedgerRow) {
|
||||
@@ -451,24 +447,26 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>店铺</label>
|
||||
<select v-model="filter.shop">
|
||||
<option value="">全部店铺</option>
|
||||
<option v-for="shop in orderedShops" :key="shop.shopName" :value="shop.shopName">{{ shop.shopName }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留,候选值原样透传。 -->
|
||||
<el-select v-model="filter.shop" class="admin-filter" filterable style="width: 150px" aria-label="筛选店铺">
|
||||
<el-option value="" label="全部店铺" />
|
||||
<el-option v-for="shop in orderedShops" :key="shop.shopName" :value="shop.shopName" :label="shop.shopName" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-if="isSuper" class="f-group">
|
||||
<label>分组</label>
|
||||
<select v-model="filter.group">
|
||||
<option value="">全部分组</option>
|
||||
<option v-for="group in groupStats" :key="group.name" :value="group.name">{{ group.name }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.group" class="admin-filter" filterable style="width: 150px" aria-label="筛选分组">
|
||||
<el-option value="" label="全部分组" />
|
||||
<el-option v-for="group in groupStats" :key="group.name" :value="group.name" :label="group.name" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>国家 / 站点</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in countryOptions" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.country" class="admin-filter" style="width: 150px" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="code in countryOptions" :key="code" :value="code" :label="asinCountryLabel(code)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>上架时间开始</label>
|
||||
@@ -553,7 +551,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<div v-if="scope === 'group'" class="group-chips">
|
||||
<template v-if="groupChips.length">
|
||||
<button v-for="group in groupChips" :key="group.name" type="button" class="g-chip" :class="{ active: selectedGroup === group.name, dup: group.dupCount > 0 }" @click="selectedGroup = group.name">
|
||||
<button v-for="group in groupChips" :key="group.name" type="button" class="g-chip" :class="{ active: selectedGroup === group.name, dup: group.dupCount > 0 }" @click="selectGroup(group.name)">
|
||||
{{ group.name }} <span class="g-count">{{ group.shopCount }}店 · {{ group.dupCount }}撞款</span>
|
||||
</button>
|
||||
</template>
|
||||
@@ -568,9 +566,16 @@ onMounted(() => {
|
||||
<div class="gs-item" :class="{ warn: activeGroupStat.dupCount > 0 }"><div class="gs-v">{{ activeGroupStat.dupCount }}</div><div class="gs-l">组内撞款ASIN</div></div>
|
||||
</div>
|
||||
|
||||
<div class="section-title">撞款覆盖矩阵 <span class="hint">{{ matrixHint }}</span></div>
|
||||
<div class="section-title">
|
||||
撞款覆盖矩阵 <span class="hint">{{ matrixHint }}</span>
|
||||
<span v-if="columnWindowTotal > 1" class="col-window">
|
||||
<button type="button" class="link-btn" :disabled="columnPage <= 1" @click="goColumnPage(-1)">‹ 上一窗列</button>
|
||||
列 {{ columnPage }}/{{ columnWindowTotal }}(共 {{ matrixAllColumns.length }} 列)
|
||||
<button type="button" class="link-btn" :disabled="columnPage >= columnWindowTotal" @click="goColumnPage(1)">下一窗列 ›</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="matrix-wrap">
|
||||
<table v-if="dupRows.length" class="matrix">
|
||||
<table v-if="dupItems.length" class="matrix">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ASIN</th>
|
||||
@@ -579,13 +584,13 @@ onMounted(() => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in matrixRows" :key="item.asin" @click="openDupDrawer(item)">
|
||||
<td><span class="asin-code">{{ item.asin }}</span></td>
|
||||
<td><span class="m-brand">{{ itemBrand(item) || '—' }}</span></td>
|
||||
<td v-for="shop in matrixShops" :key="shop" style="text-align:center">
|
||||
<div class="m-cell" :class="{ empty: cellCount(item, shop) === 0 }" :title="cellTitle(item, shop)">
|
||||
{{ cellCount(item, shop) || '' }}
|
||||
<span class="dots"><span v-for="code in cellCountryDots(item, shop)" :key="code" class="m-dot" :style="{ background: siteColor(code) }"></span></span>
|
||||
<tr v-for="row in matrixView" :key="row.asin" @click="openDupDrawer(row.item)">
|
||||
<td><span class="asin-code">{{ row.asin }}</span></td>
|
||||
<td><span class="m-brand">{{ row.brand }}</span></td>
|
||||
<td v-for="(cell, index) in row.cells" :key="matrixShops[index]" style="text-align:center">
|
||||
<div class="m-cell" :class="{ empty: cell.count === 0 }" :title="cell.title">
|
||||
{{ cell.count || '' }}
|
||||
<span class="dots"><span v-for="code in cell.dots" :key="code" class="m-dot" :style="{ background: siteColor(code) }"></span></span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -596,15 +601,15 @@ onMounted(() => {
|
||||
调整筛选条件或切换到其他分组查看
|
||||
</div>
|
||||
</div>
|
||||
<OldPagination :total="dupRows.length" :page="matrixPage" :page-size="matrixPageSize" @change="matrixPage = $event" @size-change="(s: number) => { matrixPageSize = s; matrixPage = 1 }" />
|
||||
<OldPagination :total="totalDupCount" :page="matrixPage" :page-size="matrixPageSize" @change="goMatrixPage" @size-change="changeMatrixSize" />
|
||||
|
||||
<div class="section-title" style="margin-top:24px">撞款详情 <span class="hint">同一 ASIN 在多家店铺的上架时间明细</span></div>
|
||||
<div v-if="dupRows.length" class="dup-grid">
|
||||
<div v-for="item in dupCardRows" :key="item.asin" class="dup-card">
|
||||
<div v-if="dupItems.length" class="dup-grid">
|
||||
<div v-for="item in dupItems" :key="item.asin" class="dup-card">
|
||||
<div class="dup-head">
|
||||
<span class="asin-code">{{ item.asin }}</span>
|
||||
<span class="badge dup">{{ item.shopCount }}店在售</span>
|
||||
<span class="d-brand">{{ itemBrand(item) || '未知品牌' }}</span>
|
||||
<span class="d-brand">{{ itemBrandOf(item) || '未知品牌' }}</span>
|
||||
<button class="link-btn" type="button" @click="openDupDrawer(item)">查看明细</button>
|
||||
</div>
|
||||
<div class="dup-body">
|
||||
@@ -620,8 +625,8 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="dup-empty">当前范围下没有撞款ASIN</div>
|
||||
<OldPagination :total="dupRows.length" :page="dupCardPage" :page-size="dupCardPageSize" @change="dupCardPage = $event" @size-change="(s: number) => { dupCardPageSize = s; dupCardPage = 1 }" />
|
||||
<div class="dup-total">共 <b>{{ dupRows.length }}</b> 条{{ scope === 'group' && selectedGroup ? `分组「${selectedGroup}」组内撞款ASIN` : '全店撞款ASIN' }}</div>
|
||||
<OldPagination :total="totalDupCount" :page="matrixPage" :page-size="matrixPageSize" @change="goMatrixPage" @size-change="changeMatrixSize" />
|
||||
<div class="dup-total">共 <b>{{ dupItems.length }}</b> 条{{ scope === 'group' && selectedGroup ? `分组「${selectedGroup}」组内撞款ASIN` : '全店撞款ASIN' }}</div>
|
||||
</template>
|
||||
|
||||
<!-- ============ 全部ASIN台账 ============ -->
|
||||
@@ -771,7 +776,8 @@ onMounted(() => {
|
||||
.dup-ref .mono { font-family: var(--mono); }
|
||||
.dup-ref button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
|
||||
.dup-ref button:disabled { opacity: 0.55; cursor: not-allowed; }
|
||||
.dup-ref input, .dup-ref select { font-family: inherit; font-size: 13px; color: var(--text); }
|
||||
/* 原生 select 已换 el-select(2026-11-17)⇒ 选择器里不再列 select。 */
|
||||
.dup-ref input { font-family: inherit; font-size: 13px; color: var(--text); }
|
||||
.dup-ref a { color: var(--primary); text-decoration: none; }
|
||||
.dup-ref .dim-cell { color: var(--text3); }
|
||||
.dup-ref .num-cell { font-variant-numeric: tabular-nums; }
|
||||
@@ -798,14 +804,27 @@ onMounted(() => {
|
||||
.dup-ref .filter-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
|
||||
.dup-ref .f-group { display: flex; flex-direction: column; gap: 6px; }
|
||||
.dup-ref .f-group label { font-size: 12px; color: var(--text2); }
|
||||
.dup-ref .f-group input, .dup-ref .f-group select {
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter。
|
||||
本页 style 块不是 scoped,`.f-group input` 会连带命中 el-select 内层的
|
||||
`input.el-select__input`(EP 自己的边框/背景会被这套规则压掉,控件变成框里套框)
|
||||
⇒ 必须显式排除。 */
|
||||
.dup-ref .f-group input:not(.el-select__input) {
|
||||
width: 170px;
|
||||
height: 34px; border: 1px solid var(--border-strong); border-radius: 7px; padding: 0 10px; background: #FBFCFE; outline: none;
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
.dup-ref .f-group input:focus, .dup-ref .f-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12); background: #fff; }
|
||||
.dup-ref .f-group input { width: 170px; }
|
||||
.dup-ref .f-group select { width: 150px; cursor: pointer; }
|
||||
.dup-ref .f-group input:not(.el-select__input):focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12); background: #fff; }
|
||||
.dup-ref .f-group input[type="date"] { width: 150px; }
|
||||
/* 本页筛选行是 34px 紧凑档(输入框与 `.btn` 同为 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会与同行输入框错位
|
||||
⇒ 在本页把壳压回本地档位;本页 style 不 scoped,EP 内部结构可直接选中。 */
|
||||
.dup-ref .f-group .el-select__wrapper {
|
||||
min-height: 34px; padding: 0 10px; border-radius: 7px;
|
||||
background: #FBFCFE; box-shadow: 0 0 0 1px var(--border-strong) inset; font-size: 13px;
|
||||
}
|
||||
.dup-ref .f-group .el-select__wrapper.is-focused {
|
||||
background: #fff; box-shadow: 0 0 0 1px var(--primary) inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.dup-ref .btn {
|
||||
height: 34px; border-radius: 7px; padding: 0 16px; font-size: 13px; font-weight: 600;
|
||||
display: inline-flex; align-items: center; gap: 6px; transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
@@ -885,6 +904,9 @@ onMounted(() => {
|
||||
.dup-ref .section-title { font-size: 14px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
|
||||
.dup-ref .section-title .hint { font-size: 11px; font-weight: 400; color: var(--text3); }
|
||||
.dup-ref .matrix-wrap { overflow-x: auto; overflow-y: auto; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); max-height: 480px; }
|
||||
/* 列窗口控件:与 section-title 同行,只在看得到第二窗列时出现。 */
|
||||
.dup-ref .col-window { margin-left: 12px; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
|
||||
.dup-ref .col-window .link-btn:disabled { color: var(--text3); cursor: not-allowed; }
|
||||
.dup-ref table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--surface); }
|
||||
.dup-ref table.matrix th {
|
||||
background: #F7F9FC; color: var(--text2); font-size: 12px; font-weight: 600; padding: 10px 12px;
|
||||
|
||||
@@ -185,19 +185,21 @@ onMounted(() => {
|
||||
<div class="kw-panel-head">筛选条件</div>
|
||||
<div class="kw-panel-body">
|
||||
<div class="kw-filters">
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留。 -->
|
||||
<label class="kw-field">
|
||||
<span>使用者</span>
|
||||
<select v-model="filter.user">
|
||||
<option value="">全部使用者</option>
|
||||
<option v-for="user in userOptions" :key="user" :value="user">{{ user }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.user" class="admin-filter" filterable aria-label="筛选使用者">
|
||||
<el-option value="" label="全部使用者" />
|
||||
<el-option v-for="user in userOptions" :key="user" :value="user" :label="user" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="kw-field">
|
||||
<span>国家</span>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="country in countryOptions" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="kw-field kw-field-wide">
|
||||
<span>关键词</span>
|
||||
@@ -205,10 +207,10 @@ onMounted(() => {
|
||||
</label>
|
||||
<label class="kw-field">
|
||||
<span>场景</span>
|
||||
<select v-model="filter.scene">
|
||||
<option value="">全部场景</option>
|
||||
<option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene">{{ scene }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.scene" class="admin-filter" aria-label="筛选场景">
|
||||
<el-option value="" label="全部场景" />
|
||||
<el-option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene" :label="scene" />
|
||||
</el-select>
|
||||
</label>
|
||||
<div class="kw-actions">
|
||||
<button class="kw-btn kw-btn-primary" type="button" @click="query">查询</button>
|
||||
@@ -405,8 +407,8 @@ onMounted(() => {
|
||||
font-size: 12px;
|
||||
color: #5a6474;
|
||||
}
|
||||
.kw-field input,
|
||||
.kw-field select {
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter,这里只留原生输入框。 */
|
||||
.kw-field input {
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid #d7dce5;
|
||||
@@ -417,12 +419,26 @@ onMounted(() => {
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
.kw-field input:focus,
|
||||
.kw-field select:focus {
|
||||
.kw-field input:focus {
|
||||
border-color: #2e5be6;
|
||||
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
background: #fff;
|
||||
}
|
||||
/* 本页筛选行是 34px 紧凑档(关键词输入框 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会与同行输入框错位
|
||||
⇒ 在本页把壳压回本地档位(scoped 下 :deep 穿透 EP 内部结构)。 */
|
||||
.kw-field :deep(.el-select__wrapper) {
|
||||
min-height: 34px;
|
||||
padding: 0 10px;
|
||||
border-radius: 7px;
|
||||
background: #fbfcfe;
|
||||
box-shadow: 0 0 0 1px #d7dce5 inset;
|
||||
font-size: 13px;
|
||||
}
|
||||
.kw-field :deep(.el-select__wrapper.is-focused) {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 1px #2e5be6 inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.kw-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
/* 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(蓝白末层)。 */
|
||||
.sd-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.form-box,
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.sd-filter-title {
|
||||
margin: 0 0 14px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
color: #40586e;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 18px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.sd-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.sd-toolbar-main {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.sd-toolbar-side {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.sd-select-all {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
font-size: 13px;
|
||||
color: #5b6f83;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sd-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sd-shop-pager {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.sd-shop-pager button,
|
||||
.pagination button,
|
||||
.jump-btn {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sd-shop-pager button:hover:not(:disabled),
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.sd-shop-pager button:disabled,
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.sd-shop-pager input,
|
||||
.page-jump input {
|
||||
width: 52px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.shop-card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 14px;
|
||||
}
|
||||
.sd-card {
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 12px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
overflow: hidden;
|
||||
}
|
||||
.sd-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e6edf4;
|
||||
}
|
||||
.sd-shop-name {
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
}
|
||||
.sd-card-select-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 16px 0;
|
||||
}
|
||||
.shop-card-task-no {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
color: #24384d;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sd-card-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 6px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sd-card-label {
|
||||
flex: none;
|
||||
width: 52px;
|
||||
color: #8293a5;
|
||||
}
|
||||
.sd-card-value {
|
||||
color: #40586e;
|
||||
min-width: 0;
|
||||
}
|
||||
.sd-card-file {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.sd-card-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 6px 16px 14px;
|
||||
}
|
||||
.st-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
border: 1px solid transparent;
|
||||
white-space: nowrap;
|
||||
flex: none;
|
||||
}
|
||||
.st-pill.is-success {
|
||||
color: #3d7158;
|
||||
background: #e8f2eb;
|
||||
border-color: #bdd7c5;
|
||||
}
|
||||
.st-pill.is-failed {
|
||||
color: #91474f;
|
||||
background: #f8ebeb;
|
||||
border-color: #e4c2c5;
|
||||
}
|
||||
.st-pill.is-cancelled {
|
||||
color: #5b6f83;
|
||||
background: #f1f6fa;
|
||||
border-color: #d6e2ec;
|
||||
}
|
||||
.st-pill.is-pending,
|
||||
.st-pill.is-running {
|
||||
color: #8a6d3b;
|
||||
background: #fbf4ea;
|
||||
border-color: #e7d3ae;
|
||||
}
|
||||
.country-chip {
|
||||
padding: 1px 8px;
|
||||
margin-right: 4px;
|
||||
border-radius: 999px;
|
||||
background: #eef4fa;
|
||||
color: #40586e;
|
||||
font-size: 12px;
|
||||
}
|
||||
.dim {
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.sd-progress-hint {
|
||||
margin: 10px 0 0;
|
||||
text-align: center;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.empty-tip {
|
||||
grid-column: 1 / -1;
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
@media (max-width: 1400px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 1100px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
|
||||
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
|
||||
import { useRowSelection } from '@/utils/use-row-selection'
|
||||
import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 店铺数据记录页 · 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(自绘:form-box 筛选[h4 筛选条件] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 每店卡片网格 + 旧式分页(店铺级+卡片级 9/页))。
|
||||
* script 逻辑沿用现有 Vue 实现(批量打包/删除结果文件[保留]/权限授权)。 */
|
||||
@@ -129,19 +133,24 @@ function toFilter(): ShopDataFilter {
|
||||
}
|
||||
}
|
||||
|
||||
const batchListGate = createLatestRequestGate()
|
||||
|
||||
async function load() {
|
||||
const token = batchListGate.begin()
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchShopDataTaskList(toFilter(), page.value, pageSize.value, companyTab.requestCompanyId)
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
groups.value = result.items
|
||||
totalShops.value = result.total
|
||||
page.value = result.page
|
||||
} catch (error) {
|
||||
if (!batchListGate.isCurrent(token)) return
|
||||
loadFailure.value = error instanceof Error ? error.message : '店铺数据记录加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (batchListGate.isCurrent(token)) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,12 +265,26 @@ async function downloadBatch() {
|
||||
}
|
||||
}
|
||||
|
||||
const batch = useRowSelection({
|
||||
pageRows: () => pagedResultRows.value,
|
||||
rowId: (row) => row.resultId,
|
||||
rowLabel: (row) => `${row.shopName || '店铺'}(${row.filename || row.taskNo || row.resultId})`,
|
||||
deleteOne: (id) => deleteShopDataResultHistory(id),
|
||||
refresh: load,
|
||||
blocked: () => loading.value || !!loadFailure.value || !!deletingKey.value,
|
||||
scope: () => companyTab.activeId,
|
||||
precheck: (row) => isTerminalStatus(row.status) && row.resultId ? undefined : '仅终态数据记录可删除',
|
||||
consequence: '店铺数据文件及对应记录将一起删除,此操作不可恢复。',
|
||||
})
|
||||
|
||||
async function removeRowByRow(row: ShopDataResultRow) {
|
||||
if (batch.busy) return
|
||||
// 管理端真删:删除该店这条店铺数据记录(累计档 + 文件 + 明细),前台任务记录仍保留但文件不可再下载
|
||||
if (!(await openAdminConfirm({ message: `确认删除店铺“${row.shopName}”这条店铺数据记录及其数据文件?此操作不可恢复。`, danger: true }))) return
|
||||
deletingKey.value = row.resultId
|
||||
try {
|
||||
await deleteShopDataResultHistory(row.resultId)
|
||||
batch.removeFromSelection(row.resultId)
|
||||
ElMessage.success('删除成功')
|
||||
await load()
|
||||
} catch (error) {
|
||||
@@ -334,10 +357,11 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 130px">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部</option>
|
||||
<option v-for="code in ['UK', 'DE', 'FR', 'ES', 'IT']" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option value="" label="全部" />
|
||||
<el-option v-for="code in ['UK', 'DE', 'FR', 'ES', 'IT']" :key="code" :value="code" :label="asinCountryLabel(code)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>创建开始</label>
|
||||
@@ -370,14 +394,25 @@ onMounted(load)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sd-toolbar">
|
||||
<label class="sd-select-all">
|
||||
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
|
||||
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
|
||||
全选本页可删除记录
|
||||
</label>
|
||||
<BatchDeleteActions :batch="batch" />
|
||||
</div>
|
||||
<div v-loading="loading" class="shop-card-grid">
|
||||
<template v-if="allResultRows.length">
|
||||
<article
|
||||
v-for="row in pagedResultRows"
|
||||
:key="row.resultId || `${row.taskNo}-${row.filename}`"
|
||||
class="sd-card"
|
||||
:class="{ 'batch-selected': batch.isSelected(row) }"
|
||||
>
|
||||
<header class="sd-card-head">
|
||||
<BatchDeleteCheckbox v-if="!batch.reason(row)" :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
|
||||
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
|
||||
<span class="sd-shop-name" :title="row.shopName || '-'">{{ row.shopName || '-' }}</span>
|
||||
</header>
|
||||
<div class="sd-card-select-row">
|
||||
@@ -417,7 +452,7 @@ onMounted(load)
|
||||
v-if="isTerminalStatus(row.status) && !!row.resultId"
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="deletingKey === row.resultId"
|
||||
:disabled="batch.busy || deletingKey === row.resultId"
|
||||
@click="removeRowByRow(row)"
|
||||
>
|
||||
{{ deletingKey === row.resultId ? '删除中...' : '删除' }}
|
||||
@@ -461,357 +496,4 @@ onMounted(load)
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(蓝白末层)。 */
|
||||
.sd-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.form-box,
|
||||
.panel-box {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 20px 22px 24px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(145deg, #ffffff, #f9fbfd);
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 650;
|
||||
color: #24384d;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
.sd-filter-title {
|
||||
margin: 0 0 14px;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
color: #40586e;
|
||||
}
|
||||
.form-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 14px 18px;
|
||||
}
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.form-group label {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
min-height: 42px;
|
||||
padding: 9px 18px;
|
||||
border: 1px solid #4f78a5;
|
||||
border-radius: 9px;
|
||||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||||
color: #ffffff;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
|
||||
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #7094ba, #5d83ac);
|
||||
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
|
||||
}
|
||||
.btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.btn-secondary {
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
border-color: #c7d7e5;
|
||||
}
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
color: #2f5d8b;
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #c06d77, #b35f6a);
|
||||
border-color: #b35f6a;
|
||||
}
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: linear-gradient(135deg, #cb7c84, #b96570);
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 12px;
|
||||
}
|
||||
.sd-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.sd-toolbar-main {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.sd-toolbar-side {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.sd-select-all {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
font-size: 13px;
|
||||
color: #5b6f83;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sd-summary {
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sd-shop-pager {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.sd-shop-pager button,
|
||||
.pagination button,
|
||||
.jump-btn {
|
||||
min-height: 30px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #c7d7e5;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
color: #5b6f83;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sd-shop-pager button:hover:not(:disabled),
|
||||
.pagination button:hover:not(:disabled) {
|
||||
background: #edf5fb;
|
||||
border-color: #95b1cb;
|
||||
color: #2f5d8b;
|
||||
}
|
||||
.sd-shop-pager button:disabled,
|
||||
.pagination button:disabled {
|
||||
background: #eef3f7;
|
||||
color: #9baaba;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.sd-shop-pager input,
|
||||
.page-jump input {
|
||||
width: 52px;
|
||||
min-height: 30px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.shop-card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 14px;
|
||||
}
|
||||
.sd-card {
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 12px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
|
||||
overflow: hidden;
|
||||
}
|
||||
.sd-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e6edf4;
|
||||
}
|
||||
.sd-shop-name {
|
||||
font-weight: 600;
|
||||
color: #24384d;
|
||||
}
|
||||
.sd-card-select-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 16px 0;
|
||||
}
|
||||
.shop-card-task-no {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
color: #24384d;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.sd-card-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 6px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sd-card-label {
|
||||
flex: none;
|
||||
width: 52px;
|
||||
color: #8293a5;
|
||||
}
|
||||
.sd-card-value {
|
||||
color: #40586e;
|
||||
min-width: 0;
|
||||
}
|
||||
.sd-card-file {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.sd-card-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 6px 16px 14px;
|
||||
}
|
||||
.st-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
border: 1px solid transparent;
|
||||
white-space: nowrap;
|
||||
flex: none;
|
||||
}
|
||||
.st-pill.is-success {
|
||||
color: #3d7158;
|
||||
background: #e8f2eb;
|
||||
border-color: #bdd7c5;
|
||||
}
|
||||
.st-pill.is-failed {
|
||||
color: #91474f;
|
||||
background: #f8ebeb;
|
||||
border-color: #e4c2c5;
|
||||
}
|
||||
.st-pill.is-cancelled {
|
||||
color: #5b6f83;
|
||||
background: #f1f6fa;
|
||||
border-color: #d6e2ec;
|
||||
}
|
||||
.st-pill.is-pending,
|
||||
.st-pill.is-running {
|
||||
color: #8a6d3b;
|
||||
background: #fbf4ea;
|
||||
border-color: #e7d3ae;
|
||||
}
|
||||
.country-chip {
|
||||
padding: 1px 8px;
|
||||
margin-right: 4px;
|
||||
border-radius: 999px;
|
||||
background: #eef4fa;
|
||||
color: #40586e;
|
||||
font-size: 12px;
|
||||
}
|
||||
.dim {
|
||||
color: #8293a5;
|
||||
font-size: 12px;
|
||||
}
|
||||
.sd-progress-hint {
|
||||
margin: 10px 0 0;
|
||||
text-align: center;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.empty-tip {
|
||||
grid-column: 1 / -1;
|
||||
padding: 44px 24px;
|
||||
text-align: center;
|
||||
color: #8293a5;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
color: #5b6f83;
|
||||
font-size: 13px;
|
||||
}
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
@media (max-width: 1400px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 1100px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.shop-card-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<style scoped src="./ShopDataTasksPage.css"></style>
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
|
||||
export const DUPLICATE_CHECK_ENDPOINT = '/api/admin/shop-data-crawl'
|
||||
|
||||
/** console 端点吃 asin/shop_name/group/country/site/date_from/date_to;多余分页参数后端忽略。 */
|
||||
/** console 端点吃 asin/shop_name/group/country/site/date_from/date_to(行窗口的 page/page_size/dup_group 由调用方另传)。 */
|
||||
function toConsoleQuery(filter: DuplicateFilter): Record<string, string> {
|
||||
const query: Record<string, string> = {}
|
||||
const asin = (filter.asin || '').trim()
|
||||
@@ -32,14 +32,25 @@ function toConsoleQuery(filter: DuplicateFilter): Record<string, string> {
|
||||
|
||||
export type LedgerSortKey = 'asin' | 'brand' | 'store_count' | 'record_count' | 'earliest' | 'latest'
|
||||
|
||||
/** 加载撞款控制台快照:GET /duplicate-check-console。 */
|
||||
/**
|
||||
* 加载撞款控制台快照:GET /duplicate-check-console。
|
||||
*
|
||||
* 行窗口(B60):`page`/`pageSize` 决定返回的 `dup` 是这一窗,`dupGroup` 非空时行集先按
|
||||
* 该分组成员裁剪(组内 ≥2 店才算撞款)。三者都是**服务端**口径——矩阵与详情卡片共用同一窗口,
|
||||
* 页面不再自己从全集里切片(那需要后端把整份撞款数组发回来,正是 B60 要收掉的那件事)。
|
||||
*/
|
||||
export async function fetchDuplicateConsole(
|
||||
filter: DuplicateFilter,
|
||||
companyId?: number | null,
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
dupGroup = '',
|
||||
): Promise<DuplicateConsole> {
|
||||
// toConsoleQuery 是白名单构造(只点名 asin/shop_name/group/country/site/date_*),
|
||||
// 公司值只许落在本函数自己的 companyId 形参上。
|
||||
const query: Record<string, string | number> = toConsoleQuery(filter)
|
||||
const query: Record<string, string | number> = { ...toConsoleQuery(filter), page, page_size: pageSize }
|
||||
const group = (dupGroup || '').trim()
|
||||
if (group) query.dup_group = group
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(`${DUPLICATE_CHECK_ENDPOINT}/duplicate-check-console`, { params: query })
|
||||
return parseDuplicateConsole(data)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** 撞款控制台视图派生(分组索引 / 组内撞款子集 / 店铺列并集):纯逻辑。 */
|
||||
/** 撞款控制台视图派生(分组索引 / 店铺列并集 / 矩阵格子预聚合):纯逻辑。 */
|
||||
import type { DuplicateItem, DuplicateOccurrence, DuplicateShop } from './duplicate-model.ts'
|
||||
|
||||
export interface ShopGroups {
|
||||
@@ -41,27 +41,6 @@ export function indexShopGroups(shops: DuplicateShop[]): ShopGroups {
|
||||
return { members, shopGroupNames }
|
||||
}
|
||||
|
||||
/** 仅在指定成员店铺(展示名)内保留 occurrences;重算 shop_count,返回 ≥2 店的撞款子集。 */
|
||||
export function dupWithinGroup(items: DuplicateItem[], memberShops: string[]): DuplicateItem[] {
|
||||
const memberKeys = new Set<string>()
|
||||
for (const shop of memberShops || []) memberKeys.add(shopKey(shop))
|
||||
const result: DuplicateItem[] = []
|
||||
for (const item of items || []) {
|
||||
const kept: DuplicateOccurrence[] = []
|
||||
const shops = new Set<string>()
|
||||
for (const occ of item.occurrences || []) {
|
||||
if (memberKeys.has(shopKey(occ.shopName))) {
|
||||
kept.push(occ)
|
||||
shops.add(occ.shopName || '')
|
||||
}
|
||||
}
|
||||
if (kept.length > 0 && shops.size >= 2) {
|
||||
result.push({ asin: item.asin, shopCount: shops.size, recordCount: kept.length, occurrences: kept })
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** 撞款行涉及店铺的并集列(出现顺序去重);memberShops 非空时仅取交集成员的子集顺序。 */
|
||||
export function storeColumnsOf(items: DuplicateItem[], memberShops: string[] = []): string[] {
|
||||
const restricted = new Set(memberShops.map((shop) => shopKey(shop)))
|
||||
@@ -90,6 +69,74 @@ export function storeColumnsOf(items: DuplicateItem[], memberShops: string[] = [
|
||||
return order
|
||||
}
|
||||
|
||||
/** 矩阵一格:该店在售此 ASIN 的条数 + 站点(国家)分布。 */
|
||||
export interface MatrixCell {
|
||||
count: number
|
||||
sites: { code: string; count: number }[]
|
||||
}
|
||||
|
||||
/** 空格的单份实例:模板每格都要拿一个,不能每格 new 一个对象。 */
|
||||
export const EMPTY_MATRIX_CELL: MatrixCell = { count: 0, sites: [] }
|
||||
|
||||
function cellKey(asin: string, shop: string): string {
|
||||
// 用 \u0000 拼键:ASIN 与店铺名都可打印,任何可见分隔符都可能出现在店铺名里(那样就会串格)。
|
||||
return `${(asin || '').trim()}\u0000${shopKey(shop)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 撞款矩阵的格子集合:把 rows×columns 一次算完(B60 的「预聚合」)。
|
||||
*
|
||||
* <p>原形状是每格现算:`cellCount`/`cellCountryDots`/`cellTitle` 各自把该行 occurrences 全 filter
|
||||
* 一遍,一格 4~6 次、50 行 × 200 列就是每帧上万次整行扫描,勾选/翻页都要重付。这里每行只按
|
||||
* 店铺分桶一次(O(occurrences)),之后一格一次 Map 取值。
|
||||
*
|
||||
* 只给 `columns` 里点名的列建格:不在列集内的 occurrence 直接不装桶,列窗口收窄时开销跟着降。
|
||||
*/
|
||||
export function buildMatrixCells(items: DuplicateItem[], columns: string[]): Map<string, MatrixCell> {
|
||||
const cells = new Map<string, MatrixCell>()
|
||||
const wanted = new Set<string>()
|
||||
for (const column of columns || []) wanted.add(shopKey(column))
|
||||
if (!wanted.size) return cells
|
||||
for (const item of items || []) {
|
||||
const buckets = new Map<string, DuplicateOccurrence[]>()
|
||||
const siteCounts = new Map<string, Map<string, number>>()
|
||||
for (const occ of item.occurrences || []) {
|
||||
const key = shopKey(occ.shopName)
|
||||
if (!wanted.has(key)) continue
|
||||
const bucket = buckets.get(key)
|
||||
if (bucket) bucket.push(occ)
|
||||
else buckets.set(key, [occ])
|
||||
const code = (occ.country || '').trim().toUpperCase()
|
||||
if (!code) continue
|
||||
let counts = siteCounts.get(key)
|
||||
if (!counts) {
|
||||
counts = new Map<string, number>()
|
||||
siteCounts.set(key, counts)
|
||||
}
|
||||
counts.set(code, (counts.get(code) || 0) + 1)
|
||||
}
|
||||
for (const [key, occurrences] of buckets) {
|
||||
const codes = siteCounts.get(key)
|
||||
cells.set(cellKey(item.asin, key), {
|
||||
count: occurrences.length,
|
||||
sites: codes ? [...codes].map(([code, count]) => ({ code, count })) : [],
|
||||
})
|
||||
}
|
||||
}
|
||||
return cells
|
||||
}
|
||||
|
||||
/** 取一格;没有格子时返回同一份空对象(模板里 `cellOf(...).count` 要能直接读)。 */
|
||||
export function matrixCellOf(cells: Map<string, MatrixCell>, asin: string, shop: string): MatrixCell {
|
||||
return cells.get(cellKey(asin, shop)) || EMPTY_MATRIX_CELL
|
||||
}
|
||||
|
||||
/** 一个撞款 ASIN 的品牌:取第一条带品牌的上架记录,全空就是"未知品牌"(页面自己决定怎么显示)。 */
|
||||
export function itemBrandOf(item: DuplicateItem): string {
|
||||
for (const occ of item.occurrences || []) if (occ.brand) return occ.brand
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 明细抽屉聚合行:店铺×站点聚合(对齐 reference 抽屉的 店铺/分组/站点/上架时间(升序堆叠)/次数)。 */
|
||||
export interface DrawerAggRow {
|
||||
shopName: string
|
||||
|
||||
@@ -18,12 +18,19 @@ export interface ConsoleGroupStat {
|
||||
dupCount: number
|
||||
}
|
||||
|
||||
/** 撞款控制台单次快照:总览(指标/店铺分布) + 撞款全集 + 分组统计。 */
|
||||
/**
|
||||
* 撞款控制台单次快照:总览(指标/店铺分布) + 撞款**行窗口** + 分组统计。
|
||||
*
|
||||
* `dup` 是服务端按 page/pageSize 切出来的一窗(B60),`totalDup` 是该范围内未分页的总数;
|
||||
* 两者不是同一个口径,页面分页器读 totalDup、列表读 dup。
|
||||
*/
|
||||
export interface DuplicateConsole {
|
||||
overview: DuplicateOverview
|
||||
dup: DuplicateItem[]
|
||||
groups: ConsoleGroupStat[]
|
||||
totalDup: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 台账单行(含 occurrences,供明细抽屉还原每店上架时间线)。 */
|
||||
@@ -87,7 +94,14 @@ export function parseDuplicateConsole(payload: unknown): DuplicateConsole {
|
||||
const groups = Array.isArray(record.groups)
|
||||
? record.groups.map((raw) => parseConsoleGroup(raw)).filter((group): group is ConsoleGroupStat => group !== null)
|
||||
: []
|
||||
return { overview, dup, groups, totalDup: count(record.total_dup ?? record.totalDup) }
|
||||
return {
|
||||
overview,
|
||||
dup,
|
||||
groups,
|
||||
totalDup: count(record.total_dup ?? record.totalDup),
|
||||
page: count(record.page) || 1,
|
||||
pageSize: count(record.page_size ?? record.pageSize),
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析单条台账行。 */
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* 撞款覆盖矩阵的「行窗 + 列窗」组合式(B60 从 DuplicateCheckPage.vue 拆出)。
|
||||
*
|
||||
* 为什么单独立一支:那一屏矩阵原本是每格现算——`cellCount / cellCountryDots / cellTitle`
|
||||
* 各自把该行 occurrences 全 filter 一遍(一格 4~6 次),而且整份撞款全集一次性铺成
|
||||
* 「全部行 × 全部列」的 DOM。收口后行由服务端切窗、列在本模块切窗,格子的文案与
|
||||
* 国家点一次算完、空格按列共享同一份视图。这些状态(列游标、行游标、三份 computed)
|
||||
* 是一件事,留在页面里会把本页推到可读性基线之外,也更难单测。
|
||||
*
|
||||
* 纯逻辑部分(分桶、取列)在 `duplicate-console-logic.ts`,本文件只做"窗口"这一层,
|
||||
* 数据从页面注入,不认识 store。
|
||||
*/
|
||||
import { computed, ref, watch, type ComputedRef, type Ref } from 'vue'
|
||||
import { buildMatrixCells, itemBrandOf, matrixCellOf, storeColumnsOf } from './duplicate-console-logic.ts'
|
||||
import { asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import type { DuplicateItem } from './duplicate-model.ts'
|
||||
|
||||
/**
|
||||
* 列窗口上限(B60「限制列数」)。一窗 40 列 × 最多 100 行=单帧最多 4,000 格;
|
||||
* 不封顶时 200 列 × 100 行=2 万格 DOM,任何一次勾选/翻页都要重排。
|
||||
* 列没被裁掉,只是切成窗口(`goColumnPage`),所以信息一条不丢。
|
||||
*/
|
||||
export const MATRIX_COLUMN_WINDOW = 40
|
||||
|
||||
/** 模板只读这一份:数字、国家点、悬浮说明都在这里算完。 */
|
||||
export interface MatrixCellView {
|
||||
count: number
|
||||
dots: string[]
|
||||
title: string
|
||||
}
|
||||
|
||||
/** 一行矩阵视图:行对象本身(点开抽屉要用)+ 品牌 + 本窗每一格。 */
|
||||
export interface MatrixRowView {
|
||||
item: DuplicateItem
|
||||
asin: string
|
||||
brand: string
|
||||
cells: MatrixCellView[]
|
||||
}
|
||||
|
||||
export interface MatrixWindowSource {
|
||||
/** 当前行窗(服务端切好的那一窗)。 */
|
||||
rows: ComputedRef<DuplicateItem[]>
|
||||
/** 列范围的第二正本=分组页签选中的组员(非分组范围给空数组)。 */
|
||||
groupMembers: ComputedRef<string[]>
|
||||
/** 分组范围与否:决定列要不要与组员取交集。 */
|
||||
groupScoped: Ref<boolean> | ComputedRef<boolean>
|
||||
/** 选中的分组名(只用于矩阵那行说明文案,让"看到的是什么范围"写在屏上)。 */
|
||||
selectedGroup: Ref<string> | ComputedRef<string>
|
||||
/** 行窗换页/换档都要重新请一窗(服务端切,页面不再从全集里自切)。 */
|
||||
reload: () => void
|
||||
/** 数据到达的版本号(一般是 consoleData 本身):新数据 ⇒ 旧游标已指向不存在的位置。 */
|
||||
dataVersion: Ref<unknown>
|
||||
}
|
||||
|
||||
/** 空格共用同一份 dots(模板只读不写,共享数组不会被改)。 */
|
||||
const NO_DOTS: string[] = []
|
||||
|
||||
export function useDuplicateMatrix(source: MatrixWindowSource) {
|
||||
const matrixPage = ref(1)
|
||||
const matrixPageSize = ref(10)
|
||||
const columnPage = ref(1)
|
||||
|
||||
/** 本页行里真出现过的店铺=矩阵该配的列(分组范围再与组员取交集)。 */
|
||||
const matrixAllColumns = computed<string[]>(() =>
|
||||
storeColumnsOf(source.rows.value, source.groupScoped.value ? source.groupMembers.value : []),
|
||||
)
|
||||
|
||||
const columnWindowTotal = computed(() =>
|
||||
Math.max(1, Math.ceil(matrixAllColumns.value.length / MATRIX_COLUMN_WINDOW)),
|
||||
)
|
||||
|
||||
/** 矩阵列:按窗口切(超出部分用列窗口控件翻)。 */
|
||||
const matrixShops = computed<string[]>(() => {
|
||||
const start = Math.max(0, (columnPage.value - 1) * MATRIX_COLUMN_WINDOW)
|
||||
return matrixAllColumns.value.slice(start, start + MATRIX_COLUMN_WINDOW)
|
||||
})
|
||||
|
||||
/** 一次把「本窗行 × 本窗列」全部算完,模板只读不算。 */
|
||||
const matrixCells = computed(() => buildMatrixCells(source.rows.value, matrixShops.value))
|
||||
|
||||
function cellView(shop: string, cell: ReturnType<typeof matrixCellOf>): MatrixCellView {
|
||||
const sites = cell.sites.map((site) => `${asinCountryLabel(site.code)} ${site.count}条`).join('、')
|
||||
return {
|
||||
count: cell.count,
|
||||
dots: cell.sites.map((site) => site.code),
|
||||
title: sites ? `${shop} 在售 ${cell.count} 条 · ${sites}` : `${shop} 在售 ${cell.count} 条`,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每列一份「本格为空」的视图,整列复用同一对象。
|
||||
*
|
||||
* <p>矩阵里绝大多数格是空的(一个 ASIN 只在几家店在售,列却是几十上百家店)。原先一格
|
||||
* 一条 `无此 ASIN` 文案,50 行 × 200 列=1 万条字符串;按列准备一次之后行数再多也不
|
||||
* 乘上去——这条才是"每格现算"剩下的那半开销。
|
||||
*/
|
||||
const emptyColumnViews = computed<MatrixCellView[]>(() =>
|
||||
matrixShops.value.map((shop) => ({ count: 0, dots: NO_DOTS, title: `${shop} 无此 ASIN` })),
|
||||
)
|
||||
|
||||
const matrixView = computed<MatrixRowView[]>(() => {
|
||||
const cells = matrixCells.value
|
||||
const blanks = emptyColumnViews.value
|
||||
return source.rows.value.map((item) => ({
|
||||
item,
|
||||
asin: item.asin,
|
||||
brand: itemBrandOf(item) || '—',
|
||||
cells: matrixShops.value.map((shop, index) => {
|
||||
const cell = matrixCellOf(cells, item.asin, shop)
|
||||
return cell.count ? cellView(shop, cell) : blanks[index]
|
||||
}),
|
||||
}))
|
||||
})
|
||||
|
||||
/** 屏上那行说明:把"行/列各是什么范围"写清楚,尤其分组范围是服务端裁过行的那一窗。 */
|
||||
const matrixHint = computed(() =>
|
||||
source.groupScoped.value
|
||||
? source.selectedGroup.value
|
||||
? `行 = 分组「${source.selectedGroup.value}」内的撞款ASIN(服务端裁行+分页),列 = 组内在售店铺;有数字表示组内该店在售此 ASIN`
|
||||
: '行 = 分组内撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN'
|
||||
: '行 = 本页撞款ASIN(服务端分页),列 = 本页撞款涉及店铺;有数字表示该店在售此 ASIN,点击行可看上架时间明细',
|
||||
)
|
||||
|
||||
/** 行窗口翻页:同一页重复点不重新请(翻页控件的当前页也会触发 change)。 */
|
||||
function goMatrixPage(page: number): void {
|
||||
if (page === matrixPage.value) return
|
||||
matrixPage.value = page
|
||||
source.reload()
|
||||
}
|
||||
|
||||
function changeMatrixSize(size: number): void {
|
||||
matrixPageSize.value = size
|
||||
matrixPage.value = 1
|
||||
source.reload()
|
||||
}
|
||||
|
||||
/** 列窗口翻页:行不动,只把看得见的店铺换一窗。 */
|
||||
function goColumnPage(step: number): void {
|
||||
const next = columnPage.value + step
|
||||
if (next < 1 || next > columnWindowTotal.value) return
|
||||
columnPage.value = next
|
||||
}
|
||||
|
||||
/** 换了行范围(全局 ↔ 组内、换分组、重置筛选):两个游标都回到第一窗。 */
|
||||
function resetMatrixWindows(): void {
|
||||
matrixPage.value = 1
|
||||
columnPage.value = 1
|
||||
}
|
||||
|
||||
watch(source.dataVersion, () => {
|
||||
columnPage.value = Math.min(columnPage.value, columnWindowTotal.value)
|
||||
})
|
||||
|
||||
return {
|
||||
MATRIX_COLUMN_WINDOW,
|
||||
matrixPage,
|
||||
matrixPageSize,
|
||||
columnPage,
|
||||
columnWindowTotal,
|
||||
matrixAllColumns,
|
||||
matrixShops,
|
||||
matrixView,
|
||||
matrixHint,
|
||||
goMatrixPage,
|
||||
changeMatrixSize,
|
||||
goColumnPage,
|
||||
resetMatrixWindows,
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,12 @@ 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') },
|
||||
{ path: 'patent-center/clean-items', menuKey: 'admin_appearance_patent_clean_items', title: '外观专利数据库', companyScoped: true, load: () => import('@/pages/patent/AppearancePatentCleanItemsPage.vue') },
|
||||
// 京东数据库 2026-11-16 退出公司 tab(参考品牌数据库先例):数据全平台公共,不按公司取数。
|
||||
// 2026-11-17 第二刀:V204 独立「京东分类管理」子菜单页(jd-center/categories)整体并入
|
||||
// 本页工具栏「分类管理」对话框(JdCategoryManageDialog),路由与菜单行(V208 删 V204 行)
|
||||
// 一并下线——用户口径「京东分类管理并到京东数据库分类编辑里」。
|
||||
{ path: 'jd-center/database', menuKey: 'admin_jd_database', title: '京东数据库', companyScoped: false, load: () => import('@/pages/jd/JdDatabasePage.vue') },
|
||||
]
|
||||
|
||||
export function routeOf(page: AdminPageDef): RouteRecordRaw {
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 后管浏览器错误上报(S1-F2/AC-16)。
|
||||
*
|
||||
* 之前渲染崩溃/未捕获 Promise 只进 console,线上白屏没有现场。这里做三件事:
|
||||
* 1. 屏上可见:右下角弹一条纯 DOM 提示(不依赖 element-plus,错误可能正是它引起的);
|
||||
* 2. 内存环:最近 20 条留痕(同用户端口径),便于现场排查;
|
||||
* 3. sendBeacon 上报服务端 `/api/admin/client-errors`(WARN 落日志)。
|
||||
*
|
||||
* 三类错误各有出口:Vue 渲染期异常由 `main.ts` 的 `app.config.errorHandler` 接(挂载前就要生效),
|
||||
* `window error` 与未捕获 Promise 由 `useGlobalErrorReporting()` 接——它必须在根组件 setup 里调用,
|
||||
* 卸载出口挂在 `onBeforeUnmount`:入口级注册点只定义不接线等于没接。
|
||||
*
|
||||
* 凭据零容忍:payload 只有 kind/message/stack/route/ts,**绝不**读取或携带本地登录令牌
|
||||
* 或任何请求头凭据原文(AC-1 同一把尺;预签名 URL 也当一次性凭据对待,不进上报)。
|
||||
*/
|
||||
import { onBeforeUnmount } from 'vue'
|
||||
|
||||
const REPORT_ENDPOINT = '/api/admin/client-errors'
|
||||
const RING_LIMIT = 20
|
||||
/** 风暴保护:同一原因 30s 内只弹一次屏、上报次数也设上限,日志不许被一种错误刷爆。 */
|
||||
const DEDUPE_WINDOW_MS = 30_000
|
||||
const MAX_STACK_CHARS = 2000
|
||||
|
||||
export interface ClientErrorPayload {
|
||||
kind: string
|
||||
message: string
|
||||
stack?: string
|
||||
route?: string
|
||||
ts?: number
|
||||
}
|
||||
|
||||
const ring: ClientErrorPayload[] = []
|
||||
const recent = new Map<string, number>()
|
||||
/** 屏上提示的一次性摘除定时器:全部登记,卸载时逐个 clearTimeout,不留没人收的尾巴。 */
|
||||
const toastTimers = new Set<number>()
|
||||
|
||||
function sanitize(text: string): string {
|
||||
// 兜底脱敏:堆栈/消息里若混进凭据一律打码——Bearer 值、JWT 三段式(登录令牌的形状),
|
||||
// 以及 query 里疑似 token/key/secret 的取值。上报通道绝不外带任何凭据原文。
|
||||
return text
|
||||
.replace(/(Bearer\s+)[A-Za-z0-9\-._~+/=]{8,}/gi, '$1***')
|
||||
.replace(/[A-Za-z0-9\-_]{10,}\.[A-Za-z0-9\-_]{10,}\.[A-Za-z0-9\-_]{8,}/g, '***')
|
||||
.replace(/([?&](?:token|key|secret|signature|expires)=)[^&\s"']+/gi, '$1***')
|
||||
}
|
||||
|
||||
function fingerprint(payload: ClientErrorPayload): string {
|
||||
return `${payload.kind}|${(payload.message || '').slice(0, 120)}`
|
||||
}
|
||||
|
||||
function showOnce(payload: ClientErrorPayload): void {
|
||||
if (typeof document === 'undefined') return
|
||||
const now = Date.now()
|
||||
const last = recent.get(fingerprint(payload)) ?? 0
|
||||
if (now - last < DEDUPE_WINDOW_MS) return
|
||||
recent.set(fingerprint(payload), now)
|
||||
const toast = document.createElement('div')
|
||||
toast.setAttribute('role', 'alert')
|
||||
toast.textContent = `页面出错了:${(payload.message || '未知错误').slice(0, 120)}(已记录,刷新可恢复;反复出现请联系支持)`
|
||||
toast.setAttribute(
|
||||
'style',
|
||||
'position:fixed;right:16px;bottom:16px;z-index:99999;max-width:420px;padding:10px 14px;'
|
||||
+ 'background:#b3261e;color:#fff;border-radius:8px;font-size:13px;box-shadow:0 4px 16px rgba(0,0,0,.3)',
|
||||
)
|
||||
document.body.appendChild(toast)
|
||||
const timer = window.setTimeout(() => {
|
||||
toast.remove()
|
||||
toastTimers.delete(timer)
|
||||
}, 8000)
|
||||
toastTimers.add(timer)
|
||||
}
|
||||
|
||||
export function reportClientError(payload: ClientErrorPayload): void {
|
||||
const entry: ClientErrorPayload = {
|
||||
kind: payload.kind || 'unknown',
|
||||
message: sanitize(String(payload.message ?? '')).slice(0, MAX_STACK_CHARS),
|
||||
stack: sanitize(String(payload.stack ?? '')).slice(0, MAX_STACK_CHARS),
|
||||
route: payload.route ?? (typeof location !== 'undefined' ? location.pathname : ''),
|
||||
ts: payload.ts ?? Date.now(),
|
||||
}
|
||||
ring.push(entry)
|
||||
if (ring.length > RING_LIMIT) ring.shift()
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[client-error]', entry)
|
||||
showOnce(entry)
|
||||
try {
|
||||
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
||||
navigator.sendBeacon(REPORT_ENDPOINT, new Blob([JSON.stringify(entry)], { type: 'application/json' }))
|
||||
}
|
||||
} catch {
|
||||
// 上报失败只丢现场,不许把错误处理本身炸掉
|
||||
}
|
||||
}
|
||||
|
||||
/** 最近 N 条内存环(只读快照,排查用)。 */
|
||||
export function recentClientErrors(): ClientErrorPayload[] {
|
||||
return ring.slice()
|
||||
}
|
||||
|
||||
function handleWindowRejection(event: PromiseRejectionEvent): void {
|
||||
reportClientError({
|
||||
kind: 'unhandled-rejection',
|
||||
message: String(event.reason ?? ''),
|
||||
stack: event.reason instanceof Error ? event.reason.stack ?? '' : '',
|
||||
route: typeof location === 'undefined' ? '' : location.pathname,
|
||||
ts: Date.now(),
|
||||
})
|
||||
}
|
||||
|
||||
function handleWindowError(event: ErrorEvent): void {
|
||||
reportClientError({
|
||||
kind: 'window-error',
|
||||
message: event.message || (event.error instanceof Error ? event.error.message : ''),
|
||||
stack: event.error instanceof Error ? event.error.stack ?? '' : '',
|
||||
route: typeof location === 'undefined' ? '' : location.pathname,
|
||||
ts: Date.now(),
|
||||
})
|
||||
}
|
||||
|
||||
let browserEventsInstalled = false
|
||||
|
||||
/** 卸载出口:摘掉两个 window 监听 + 清掉所有还在倒计时的提示定时器。 */
|
||||
export function disposeGlobalErrorReporting(): void {
|
||||
if (typeof window === 'undefined') return
|
||||
window.removeEventListener('unhandledrejection', handleWindowRejection)
|
||||
window.removeEventListener('error', handleWindowError)
|
||||
for (const timer of toastTimers) window.clearTimeout(timer)
|
||||
toastTimers.clear()
|
||||
browserEventsInstalled = false
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器级兜底接线(必须由根组件 setup 调用一次):脚本级崩溃与没人接的 Promise
|
||||
* 都收进同一条上报路;卸载配对走 onBeforeUnmount,与用户端 App.vue 的 dispose 口径一致。
|
||||
*/
|
||||
export function useGlobalErrorReporting(): void {
|
||||
if (typeof window === 'undefined' || browserEventsInstalled) return
|
||||
browserEventsInstalled = true
|
||||
window.addEventListener('unhandledrejection', handleWindowRejection)
|
||||
window.addEventListener('error', handleWindowError)
|
||||
onBeforeUnmount(disposeGlobalErrorReporting)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 青果提取链接的拼装(后管侧镜像)。
|
||||
*
|
||||
* 正本在**用户端那棵前端树**的同名文件 `src/shared/utils/qingguo-link.ts`。两棵前端树各自独立构建
|
||||
* (各自的 vite root 与 tsconfig include),跨树 import 会把用户端拖进后管的产物图(本仓
|
||||
* `src/config/workspace.ts` 的边界尺子也判这种耦合为违规),所以这里按**同名同形**镜像一份,
|
||||
* 而不是另起一套新逻辑:口径只有一条
|
||||
* `https://overseas.proxy.qg.net/get?key=<Authkey>&pwd=<Authpwd>`
|
||||
* 改这一条 URL 时必须两边同改(用户端那份有 `node --test` 判据钉着)。
|
||||
*
|
||||
* 业务背景(2026-10-31 用户口径、2026-11-02 后台脱敏收口):青果**没有**可填的提取链接,
|
||||
* 产品页只给 Authkey / Authpwd 两个值;后台「代填/改代理」因此改成收这两个值、在这里拼,
|
||||
* 界面上任何时候都不再把拼好的链接回显或留档(链接里带着 pwd)。
|
||||
*
|
||||
* ⚠ 本文件保持**零依赖**:`node --test` 不认 Vite 的 `@/` 别名,带别名的模块进不了
|
||||
* `tests/*.test.ts`,这条拼装规则就没法被用例钉住。
|
||||
*/
|
||||
export const QINGGUO_EXTRACT_URL = 'https://overseas.proxy.qg.net/get'
|
||||
|
||||
export function composeQingguoLink(account: string, password: string): string {
|
||||
const key = (account || '').trim()
|
||||
if (!key) return ''
|
||||
const pwd = (password || '').trim()
|
||||
const query = `key=${encodeURIComponent(key)}` + (pwd ? `&pwd=${encodeURIComponent(pwd)}` : '')
|
||||
return `${QINGGUO_EXTRACT_URL}?${query}`
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import { defineStore } from 'pinia'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import type { CompanyItem } from '@/api/companies-dto'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { firstSelectableCompanyId, companyIdForRequest } from '@/layout/company-tab-model'
|
||||
|
||||
/** 公司 tab 的状态。成员 user ids **不在这里缓存**——每次请求交后端解析,
|
||||
@@ -12,6 +14,11 @@ export const useCompanyTabStore = defineStore('company-tab', {
|
||||
activeId: null as number | null,
|
||||
loading: false,
|
||||
loaded: false,
|
||||
/** 当前这份目录是按哪个平台 tab 拉的(V206 平台分侧,2026-11-17 用户口径「公司 tab
|
||||
* 条也按平台分侧,两边各看各的公司」)。空串=还没按平台拉过。早退闸拿它对撞当前
|
||||
* tab:一致才免拉,平台切了就重拉一份;`fetchCompanies` 失败时不翻转它,旧清单
|
||||
* (可能过时)继续顶着,下一次切台/重进页面会再试。 */
|
||||
loadedPlatform: '' as PlatformTabId | '',
|
||||
/** GET /companies 失败时的原因。**只住 store 与 console,不在模板里渲染**——
|
||||
* §12 第 5 条没批任何新的用户可见提示,接口暴露禁令高于"失败可见"。
|
||||
* 取不到目录时 loaded 保持 false ⇒ visibleForOperator 为 false ⇒ tab 条整体不画(fail-closed,观感与改前一致)。 */
|
||||
@@ -35,15 +42,27 @@ export const useCompanyTabStore = defineStore('company-tab', {
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async initialize() {
|
||||
/** 拉公司目录(按当前平台 tab 过滤,后端 GET /api/admin/companies?platform=…)。
|
||||
* `force`=绕开「该平台已拉过」的早退闸(公司编辑弹窗翻档/启停后的 refresh 用),
|
||||
* 旧清单保留到成功那刻再整份替换,取数期间 tab 条不闪空。 */
|
||||
async initialize(options?: { force?: boolean }) {
|
||||
const session = useAdminSessionStore()
|
||||
if (this.loaded || this.loading || !session.isSuperAdmin) return
|
||||
const platform = usePlatformTabStore().active
|
||||
const alreadyLoadedForThisPlatform = this.loaded && this.loadedPlatform === platform
|
||||
if ((!options?.force && alreadyLoadedForThisPlatform) || this.loading || !session.isSuperAdmin) return
|
||||
this.loading = true
|
||||
// 失败后 loaded 仍是 false ⇒ 下一次 watch 命中超管会重试;重试前先清掉旧原因,免得留着一条已经翻篇的错误。
|
||||
this.error = ''
|
||||
try {
|
||||
this.companies = await fetchCompanies()
|
||||
this.activeId = firstSelectableCompanyId(this.companies)
|
||||
const companies = await fetchCompanies(platform)
|
||||
this.companies = companies
|
||||
this.loadedPlatform = platform
|
||||
// 换台重拉后旧选中未必还在新清单里(跨平台公司不重叠):还在就保住(别的页可能正按它取数),
|
||||
// 不在就回落「id 最小的启用公司」。force 重拉同平台时,选中公司仍在 ⇒ 选中不跳。
|
||||
const stillListed = this.activeId !== null && companies.some((c) => c.id === this.activeId)
|
||||
if (!stillListed) {
|
||||
this.activeId = firstSelectableCompanyId(companies)
|
||||
}
|
||||
this.loaded = true
|
||||
} catch (error) {
|
||||
// 2026-10-05 修复轮 1:改前只有 try/finally ⇒ GET /companies 抛错时零痕迹(loaded 永远 false、
|
||||
@@ -57,8 +76,25 @@ export const useCompanyTabStore = defineStore('company-tab', {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
/** 公司目录被编辑(公司管理翻档/启停/改名)后的强制重拉:不受 loadedPlatform 早退闸
|
||||
* 限制。失败语义与 initialize 同口径(error + rethrow),调用方自行决定要不要提示。 */
|
||||
async refresh() {
|
||||
await this.initialize({ force: true })
|
||||
},
|
||||
setActiveId(id: number) {
|
||||
this.activeId = id
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
/** 公司目录失效通知:公司管理页保存(新建/改名/启停/翻档)之后调这里,让全站 tab 条重拉一份。
|
||||
*
|
||||
* 为什么是 store 里的具名出口而不是让页面自己持一份 store:公司管理页**不参与公司隔离**
|
||||
* (控制方 2026-10-06「公司管理不要有 tab」),它要的不是 tab 状态,只是「别让 18 个页面的
|
||||
* tab 条端着旧名单」这一个动作。页面里一旦出现 `useCompanyTabStore()`,形状就和「给这页上了
|
||||
* tab」分不开——company-config-entry-super-only 的 pageFiles 分母会当场红(2026-11-17 实测:
|
||||
* ee613db0 给这页加了保存后重拉,正是踩在这条上)。
|
||||
* 失败语义同 refresh:error 落 store 再 rethrow,调用方决定要不要提示。 */
|
||||
export function refreshCompanyDirectory(): Promise<void> {
|
||||
return useCompanyTabStore().refresh()
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user