feat(appearance-patent): 外观专利数据库主管列+导出+分组筛选——后管只读页补「所属主管」读侧现算列(owner 是主管取自己、普通账户取创建人,铁律 30 读不到不猜名)、GET /export 与分页共用同一过滤面与正门出 xlsx(SXSSF,上限 5 万行超限拒)、分组筛选 group_id 按 selectUserIdsByGroupId 解析「组长本人+名下子账户」整集 SQL 下推(铁律 20,选项复用既有 GET /shop-manages/groups 不下新端点);前端加主管列/分组下拉/导出按钮(blob 落盘+业务错误信封解包),wiring 护栏补导出发送口钉与 watch token(25 处发送口);棘轮 1073→1074 一枚记名,「无侵权」白名单登记导出上限文案
This commit is contained in:
@@ -26,6 +26,8 @@ const MENU_KEY = 'admin_appearance_patent_clean_items'
|
||||
|
||||
const cleanApi = vi.hoisted(() => ({
|
||||
fetchAppearancePatentCleanList: vi.fn(),
|
||||
exportAppearancePatentCleanList: vi.fn(),
|
||||
fetchDedupeTotalGroups: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
|
||||
@@ -36,6 +38,7 @@ function row(id: number, over: Record<string, unknown> = {}) {
|
||||
resultId: 900 + id,
|
||||
taskId: 33179,
|
||||
userId: 7,
|
||||
supervisorName: `主管${id}`,
|
||||
companyId: 1,
|
||||
rowNo: id,
|
||||
asin: `B0AB8CDEF${id}`,
|
||||
@@ -64,6 +67,8 @@ beforeEach(() => {
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
// 分组(主管)选项默认空集:分组用例各自覆写
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([])
|
||||
})
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
@@ -109,6 +114,79 @@ describe('AC-5 外观专利无侵权数据页(分页列表,参照去重数
|
||||
expect(wrapper.text()).toContain('无侵权')
|
||||
})
|
||||
|
||||
it('主管列(2026-11-11 客户需求):表头就位,行值展示 supervisorName,读不到展示 -', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [row(1, { supervisorName: '主管甲' }), row(2, { supervisorName: '' })],
|
||||
total: 2,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
const headers = wrapper.findAll('thead th').map((th) => th.text())
|
||||
expect(headers).toContain('所属主管')
|
||||
expect(headers.indexOf('所属主管')).toBe(headers.indexOf('任务号') + 1, '主管列紧跟任务号之后')
|
||||
const firstRowCells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||||
expect(firstRowCells[headers.indexOf('所属主管')].text()).toBe('主管甲')
|
||||
const secondRowCells = wrapper.findAll('tbody tr')[1].findAll('td')
|
||||
expect(secondRowCells[headers.indexOf('所属主管')].text()).toBe('-', '读不到主管不猜名字,展示 -')
|
||||
})
|
||||
|
||||
it('导出按钮带当前过滤面与公司 tab 调导出接口,成功触发 blob 落盘', async () => {
|
||||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||||
const revokeObjectURL = vi.fn()
|
||||
const urlRecord = URL as unknown as Record<string, unknown>
|
||||
const origCreate = urlRecord.createObjectURL
|
||||
const origRevoke = urlRecord.revokeObjectURL
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx'], { type: 'application/vnd.ms-excel' }), filename: '外观专利数据库-20261111103000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
|
||||
const textInputs = wrapper.findAll('input[type="text"]')
|
||||
await textInputs[0].setValue('33179')
|
||||
const exportBtn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||||
expect(exportBtn).toBeTruthy()
|
||||
await exportBtn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.exportAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||||
const call = cleanApi.exportAppearancePatentCleanList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({
|
||||
taskId: '33179',
|
||||
asin: '',
|
||||
country: '',
|
||||
groupId: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
companyId: 1,
|
||||
})
|
||||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||||
expect(revokeObjectURL).toHaveBeenCalledWith('blob:mock-url')
|
||||
expect(clickSpy).toHaveBeenCalled()
|
||||
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
|
||||
} finally {
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: origCreate, configurable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: origRevoke, configurable: true })
|
||||
clickSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('导出失败把服务端业务文案弹出来,不许静默', async () => {
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.reject(new Error('无侵权数据共 90001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('超过导出上限', '失败反馈必须是服务端那句可读文案')
|
||||
// 失败后导出锁复位,按钮可再次点击
|
||||
expect(wrapper.findAll('button').find((b) => b.text() === '导出')!.text()).toBe('导出')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
const wrapper = await mountWith({ items: [row(11)], total: 42, page: 2, pageSize: 10 })
|
||||
|
||||
@@ -143,12 +221,36 @@ describe('AC-5 外观专利无侵权数据页(分页列表,参照去重数
|
||||
taskId: '33179',
|
||||
asin: 'B0AB8CDEF1',
|
||||
country: 'DE',
|
||||
groupId: '',
|
||||
startDate: '2026-11-01',
|
||||
endDate: '2026-11-09',
|
||||
page: 1,
|
||||
})
|
||||
})
|
||||
|
||||
it('分组下拉(主管=组长):选项与去重页同源,选中后 groupId 进列表请求', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([
|
||||
{ id: 7, name: '甲组', leaderUserId: 9 },
|
||||
{ id: 8, name: '乙组', leaderUserId: 10 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
|
||||
// 选项取数走的是公司隔离的同一分组集(GET /shop-manages/groups 的适配层)
|
||||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenCalledWith(1)
|
||||
|
||||
const groupSelect = wrapper.findAll('select')[1]
|
||||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts).toContain('全部分组')
|
||||
expect(optionTexts).toContain('甲组')
|
||||
expect(optionTexts).toContain('乙组')
|
||||
|
||||
await groupSelect.setValue('7')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '查询')!.trigger('click')
|
||||
await flushPromises()
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(last.groupId).toBe('7', '选中的分组 id 以 groupId 进列表过滤面(服务端解析组长+名下整集)')
|
||||
})
|
||||
|
||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
const thCount = empty.findAll('thead th').length
|
||||
@@ -166,9 +268,13 @@ describe('AC-5 外观专利无侵权数据页(分页列表,参照去重数
|
||||
})
|
||||
|
||||
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||||
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
|
||||
const textInputs = wrapper.findAll('input[type="text"]')
|
||||
await textInputs[0].setValue('33179')
|
||||
// 选上上一家公司的分组:切走后必须连同 groupId 一起清(分组的成员集是公司隔离的)
|
||||
const groupSelect = wrapper.findAll('select')[1]
|
||||
await groupSelect.setValue('7')
|
||||
const callsAfterMount = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
|
||||
useCompanyTabStore().setActiveId(2)
|
||||
@@ -179,6 +285,9 @@ describe('AC-5 外观专利无侵权数据页(分页列表,参照去重数
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(last.companyId).toBe(2)
|
||||
expect(last.taskId).toBe('', '切公司必须清掉上一家填的任务号')
|
||||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
||||
expect(last.page).toBe(1)
|
||||
// 分组选项按新公司重取(选项集公司隔离)
|
||||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenLastCalledWith(2)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user