diff --git a/app/api/department-dashboard/brand-knowledge/route.test.ts b/app/api/department-dashboard/brand-knowledge/route.test.ts index 04c21448..fa5ffb46 100644 --- a/app/api/department-dashboard/brand-knowledge/route.test.ts +++ b/app/api/department-dashboard/brand-knowledge/route.test.ts @@ -215,6 +215,25 @@ describe('brand knowledge upload route', () => { expect(isSuperAdmin).toHaveBeenCalledWith('user-1') }) + test('searches knowledge type as well as title and file metadata', async () => { + await GET(new Request('http://localhost/api/department-dashboard/brand-knowledge?q=%E4%B8%BB%E5%9B%BE%E6%A8%A1%E6%9D%BF')) + + expect(prisma.brandKnowledge.findMany).toHaveBeenCalledWith(expect.objectContaining({ + where: expect.objectContaining({ + OR: expect.arrayContaining([ + { knowledgeType: { contains: '主图模板', mode: 'insensitive' } }, + ]), + }), + })) + expect(prisma.brandKnowledge.count).toHaveBeenCalledWith(expect.objectContaining({ + where: expect.objectContaining({ + OR: expect.arrayContaining([ + { knowledgeType: { contains: '主图模板', mode: 'insensitive' } }, + ]), + }), + })) + }) + test('stores ordered WebP slices and keeps the first slice as the card preview', async () => { const response = await POST(uploadRequest()) const call = (prisma.brandKnowledge.create as jest.Mock).mock.calls[0][0] diff --git a/app/api/department-dashboard/brand-knowledge/route.ts b/app/api/department-dashboard/brand-knowledge/route.ts index fefb43d3..a3212eda 100644 --- a/app/api/department-dashboard/brand-knowledge/route.ts +++ b/app/api/department-dashboard/brand-knowledge/route.ts @@ -174,6 +174,7 @@ export async function GET(request: Request) { ...(query ? { OR: [ { title: { contains: query, mode: 'insensitive' } }, + { knowledgeType: { contains: query, mode: 'insensitive' } }, { fileName: { contains: query, mode: 'insensitive' } }, { brand: { contains: query, mode: 'insensitive' } }, { productCategoryName: { contains: query, mode: 'insensitive' } }, @@ -210,6 +211,7 @@ export async function GET(request: Request) { ...(query ? { OR: [ { title: { contains: query, mode: 'insensitive' } }, + { knowledgeType: { contains: query, mode: 'insensitive' } }, { fileName: { contains: query, mode: 'insensitive' } }, { brand: { contains: query, mode: 'insensitive' } }, { productCategoryName: { contains: query, mode: 'insensitive' } }, diff --git a/components/department-dashboard/BrandKnowledgeDashboard.test.tsx b/components/department-dashboard/BrandKnowledgeDashboard.test.tsx index 4d7e02a9..72e087ea 100644 --- a/components/department-dashboard/BrandKnowledgeDashboard.test.tsx +++ b/components/department-dashboard/BrandKnowledgeDashboard.test.tsx @@ -93,6 +93,41 @@ describe('BrandKnowledgeDashboard', () => { expect(screen.getByText('没有找到与“索菲亚”匹配的知识内容')).toBeInTheDocument() }) + it('searches by knowledge type when the title uses a different template spelling', async () => { + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + json: async () => ({ + success: true, + total: 1, + data: [{ + id: 'knowledge-template-1', + title: '升降桌主图模版-索菲亚', + knowledgeType: '主图模板', + brand: '索菲亚', + productCategoryName: '书桌', + fileName: '升降桌主图模板.psd', + mimeType: 'image/vnd.adobe.photoshop', + fileSize: 1024, + downloadCount: 0, + createdAt: '2026-09-21T00:00:00.000Z', + uploadedBy: '无邪', + downloadUrl: '/api/department-dashboard/brand-knowledge/knowledge-template-1/file', + previewUrl: null, + previewImageName: null, + likeCount: 0, + isLiked: false, + isFavorited: false, + }], + }), + } as Response) + + render() + + expect(await screen.findByRole('heading', { level: 3, name: '升降桌主图模版-索菲亚' })).toBeInTheDocument() + fireEvent.change(screen.getByRole('searchbox', { name: '搜索品牌知识' }), { target: { value: '主图模板' } }) + expect(screen.getByRole('heading', { level: 3, name: '升降桌主图模版-索菲亚' })).toBeInTheDocument() + }) + it('shows uploaded knowledge with the material-library card hierarchy', async () => { global.fetch = jest.fn().mockResolvedValue({ ok: true, diff --git a/components/department-dashboard/BrandKnowledgeDashboard.tsx b/components/department-dashboard/BrandKnowledgeDashboard.tsx index d29399d9..3e8523bb 100644 --- a/components/department-dashboard/BrandKnowledgeDashboard.tsx +++ b/components/department-dashboard/BrandKnowledgeDashboard.tsx @@ -440,7 +440,7 @@ export default function BrandKnowledgeDashboard() { showToast('品牌知识已删除,原文件已保留', { variant: 'success' }) }, [showToast]) - const visibleItems = useMemo(() => { const keyword = searchKeyword.trim().toLowerCase(); return items.filter((item) => (selectedType === '全部' || item.knowledgeType === selectedType) && (!keyword || [item.id, item.title, item.fileName, item.brand, item.productCategoryName, item.uploadedBy].some((value) => value.toLowerCase().includes(keyword)))) }, [items, searchKeyword, selectedType]) + const visibleItems = useMemo(() => { const keyword = searchKeyword.trim().toLowerCase(); return items.filter((item) => (selectedType === '全部' || item.knowledgeType === selectedType) && (!keyword || [item.id, item.title, item.knowledgeType, item.fileName, item.brand, item.productCategoryName, item.uploadedBy].some((value) => value.toLowerCase().includes(keyword)))) }, [items, searchKeyword, selectedType]) const emptyMessage = useMemo(() => { if (loadError) return loadError