feat(admin): 为支持单删的管理列表补齐批量删除

This commit is contained in:
2026-11-20 12:08:28 +08:00
parent 132c19d51f
commit 51c41b238a
43 changed files with 2806 additions and 1948 deletions
@@ -68,6 +68,24 @@ async function mountDialog(editable = true): Promise<VueWrapper<Element>> {
return wrapper
}
it('批量删除分类:全选当前页、确认只移除分类、刷新一次;只读模式无入口', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3), group(8, '裤装', 1)])
jdApi.deleteJdProductGroup.mockResolvedValue(undefined)
const wrapper = await mountDialog()
await wrapper.get('.option-head input[type="checkbox"]').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
await flushPromises()
expect(confirmMock).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('商品本身不会被删除') }))
expect(jdApi.deleteJdProductGroup.mock.calls).toEqual([[7], [8]])
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
expect(wrapper.emitted('changed')).toHaveLength(1)
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量删除(0)')
await wrapper.setProps({ editable: false })
expect(wrapper.find('.batch-delete-actions').exists()).toBe(false)
expect(wrapper.find('.batch-delete-checkbox').exists()).toBe(false)
wrapper.unmount()
})
describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东数据库页)', () => {
it('打开即按当前分组取分类(ownerGroupId 必带);标题不带分组名(2026-11-17 用户口径「不要显示周丽娥」)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
@@ -140,7 +140,7 @@ describe('菜单权限配置页的平台隔离', () => {
])
const databaseRow = page.findAll('tbody tr')
.find((row) => row.find('.menu-name-text').text() === '京东数据库')
expect(databaseRow!.findAll('td')[4].text()).toBe('数据管理')
expect(databaseRow!.findAll('td')[5].text()).toBe('数据管理')
expect(databaseRow!.find('.column-child-mark').exists()).toBe(true)
})
@@ -0,0 +1,45 @@
import { beforeEach, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import QueryAsinPage from '@/pages/asin/QueryAsinPage.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
const api = vi.hoisted(() => ({
fetchQueryAsinList: vi.fn(),
deleteQueryAsinCountryAsin: vi.fn(),
openAdminConfirm: vi.fn(),
}))
vi.mock('@/pages/asin/query-asin-api.ts', () => ({ ...api, createQueryAsin: vi.fn(), fetchShopNamesByGroup: vi.fn() }))
vi.mock('@/pages/asin/query-asin-detail-api.ts', () => ({ ...api, updateQueryAsinCountryAsin: vi.fn() }))
vi.mock('@/pages/shop/shop-manage-api.ts', () => ({ fetchShopManageGroups: vi.fn().mockResolvedValue([]) }))
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: api.openAdminConfirm }))
beforeEach(() => {
vi.resetAllMocks()
setActivePinia(createPinia())
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
})
it('多站点店铺只占一个勾选;部分站点失败时,重试不重删成功站点', async () => {
const shop = { id: 7, shopName: '甲店', groupName: '甲组', asinDe: 'B000000001', asinUk: 'B000000002' }
api.fetchQueryAsinList.mockResolvedValue({ page: 1, total: 1, items: [shop] })
api.deleteQueryAsinCountryAsin.mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error('暂时无法删除英国站'))
api.openAdminConfirm.mockResolvedValue(true)
const wrapper = mount(QueryAsinPage, { global: { stubs: ['el-select', 'el-option', 'el-dialog', 'el-drawer', 'el-progress'] } })
await flushPromises()
expect(wrapper.findAll('tbody .batch-delete-checkbox')).toHaveLength(1)
expect(wrapper.get('tbody .batch-delete-cell').attributes('rowspan')).toBe('2')
await wrapper.get('thead .batch-delete-checkbox').setValue(true)
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.text()).toBe('批量删除(1)')
await button.trigger('click')
await flushPromises()
expect(api.openAdminConfirm).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('全部站点') }))
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK']])
expect(wrapper.get('details').text()).toContain('暂时无法删除英国站')
await button.trigger('click')
await flushPromises()
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK'], [7, 'UK']])
expect(button.text()).toBe('批量删除(0)')
wrapper.unmount()
})
@@ -28,6 +28,22 @@ const secretsApi = vi.hoisted(() => ({
}))
vi.mock('@/api/user-secrets', () => secretsApi)
const confirmBatch = vi.hoisted(() => vi.fn())
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmBatch }))
it('批量清空点名全部密钥与代理,只调用用户级清空接口', async () => {
const wrapper = await mountWith([row(7), row(8)])
confirmBatch.mockResolvedValue(true)
secretsApi.deleteUserSecret.mockResolvedValue(undefined)
await wrapper.get('thead .batch-delete-checkbox').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
await flushPromises()
expect(confirmBatch).toHaveBeenCalledWith(expect.objectContaining({ danger: true, message: expect.stringContaining('全部密钥与代理配置') }))
expect(secretsApi.deleteUserSecret.mock.calls).toEqual([[7], [8]])
expect(secretsApi.clearUserSecretModule).not.toHaveBeenCalled()
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量清空(0)')
wrapper.unmount()
})
function moduleCell(moduleKey: string, over: Record<string, unknown> = {}) {
return {
@@ -122,7 +138,7 @@ describe('余额两列接在密钥管理列表上', () => {
const headerCount = wrapper.findAll('thead th').length
const cellCount = wrapper.findAll('tbody tr')[0].findAll('td').length
expect(cellCount, '每行的 td 数必须等于表头列数').toBe(headerCount)
expect(headerCount).toBe(12)
expect(headerCount).toBe(13)
const emptyWrapper = await mountWith([])
const colspan = Number(emptyWrapper.find('tbody td').attributes('colspan'))
@@ -133,7 +149,7 @@ describe('余额两列接在密钥管理列表上', () => {
useAdminSessionStore().user = { id: 2, username: 'leader', role: 'admin' }
const wrapper = await mountWith([row(7)])
const headerCount = wrapper.findAll('thead th').length
expect(headerCount).toBe(11)
expect(headerCount).toBe(12)
expect(wrapper.findAll('tbody tr')[0].findAll('td').length).toBe(headerCount)
const emptyWrapper = await mountWith([])
@@ -21,6 +21,8 @@ const usersApi = vi.hoisted(() => ({
}))
vi.mock('@/api/users', () => usersApi)
const confirmBatch = vi.hoisted(() => vi.fn())
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmBatch }))
vi.mock('@/api/companies', () => ({ fetchCompanies: vi.fn().mockResolvedValue([]) }))
vi.mock('@/pages/account/user-menu-auth-api', () => ({ loadUserMenuAuth: vi.fn() }))
@@ -48,6 +50,45 @@ beforeEach(() => {
const session = useAdminSessionStore()
session.user = { id: 1, username: 'root', role: 'super_admin' }
usersApi.fetchUserList.mockResolvedValue(pageOf())
usersApi.deleteUser.mockReset().mockResolvedValue(undefined)
confirmBatch.mockReset().mockResolvedValue(false)
})
it('批量删除取消不发请求;部分失败只保留失败用户', async () => {
usersApi.deleteUser.mockRejectedValueOnce(new Error('无权删除此用户'))
const wrapper = mount(UsersPage)
await flushPromises()
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.attributes('disabled')).toBeDefined()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('input[aria-label="选择 存量号"]').setValue(true)
await button.trigger('click')
await flushPromises()
expect(confirmBatch).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('京东号、存量号') }))
expect(usersApi.deleteUser).not.toHaveBeenCalled()
confirmBatch.mockResolvedValue(true)
await button.trigger('click')
await flushPromises()
expect(usersApi.deleteUser.mock.calls).toEqual([[7], [8]])
expect(button.text()).toBe('批量删除(1)')
expect(wrapper.get('details').text()).toContain('京东号:无权删除此用户')
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(2)
wrapper.unmount()
})
it('确认弹窗期间切平台,旧勾选不发删除请求', async () => {
let resolveConfirm!: (ok: boolean) => void
confirmBatch.mockReturnValue(new Promise<boolean>((resolve) => { resolveConfirm = resolve }))
const wrapper = mount(UsersPage)
await flushPromises()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
usePlatformTabStore().setActive('jd')
resolveConfirm(true)
await flushPromises()
expect(usersApi.deleteUser).not.toHaveBeenCalled()
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量删除(0)')
wrapper.unmount()
})
describe('UsersPage × 平台 tab(V206)', () => {
@@ -60,8 +101,8 @@ describe('UsersPage × 平台 tab(V206)', () => {
expect(params).toHaveProperty('companyId')
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).not.toContain('上架上限')
// 亚马逊侧表头 9 列(存量表头,quota 列不渲染)
expect(headers.length).toBe(9)
// 亚马逊侧保留原有 9 列,另加 1 列批量选择。
expect(headers.length).toBe(10)
wrapper.unmount()
})
@@ -78,12 +119,11 @@ describe('UsersPage × 平台 tab(V206)', () => {
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).toContain('上架上限')
expect(headers.length).toBe(10)
expect(headers.length).toBe(11)
// quota 单元格:0=不限(存量号 8),null/缺省=-(京东号 7、没配号 10),800 原样
const quotaCells = wrapper.findAll('tbody tr').map((tr) => {
const tds = tr.findAll('td')
// 上架上限列在第 5 列(ID/用户名/角色/所属管理员/到期时间 之后)
return tds[5]?.text()
return tds[6]?.text()
})
expect(quotaCells).toEqual(['-', '不限', '800', '-'])
wrapper.unmount()