diff --git a/src/api/kb/document.ts b/src/api/kb/document.ts index 6fa3ffb..2ff41fc 100644 --- a/src/api/kb/document.ts +++ b/src/api/kb/document.ts @@ -177,8 +177,11 @@ export const publishDocument = (id: number) => { }; /** 移入回收站 */ -export const moveToTrash = (id: number) => { - return request.post>("/Kb/v1/trash/move", { id, type: 'document' }); +export const moveToTrash = (resourceId: number, resourceType: string) => { + return request.post>("/Kb/v1/trash/move", { + resource_id: resourceId, + resource_type: resourceType, + }); }; /** 获取我的文档列表(由我创建的所有文档) */ diff --git a/src/views/ops/pages/kb/favorite/index.vue b/src/views/ops/pages/kb/favorite/index.vue index 496df61..bd0d320 100644 --- a/src/views/ops/pages/kb/favorite/index.vue +++ b/src/views/ops/pages/kb/favorite/index.vue @@ -17,7 +17,7 @@ @@ -69,12 +69,12 @@ >
- - {{ currentResource.doc_no || '-' }} - - + {{ currentResource.title || '-' }} + + 文档 + {{ currentResource.author_name || '-' }} @@ -109,23 +109,20 @@ >
- - {{ currentFaq.faq_no || '-' }} + + {{ currentFaq.question || '-' }} + + + FAQ {{ currentFaq.status || '已发布' }} - - {{ currentFaq.question || '-' }} - - -
-
{{ currentFaq.view_count || 0 }} - - {{ currentFaq.helpful_count || 0 }} + +
@@ -178,13 +175,6 @@ const columns = computed(() => [ width: 100, align: 'center', }, - { - title: '备注', - dataIndex: 'remarks', - ellipsis: true, - tooltip: true, - width: 200, - }, { title: '收藏时间', dataIndex: 'created_at', diff --git a/src/views/ops/pages/kb/items/index.vue b/src/views/ops/pages/kb/items/index.vue index 5c9b6d4..cd64e7b 100644 --- a/src/views/ops/pages/kb/items/index.vue +++ b/src/views/ops/pages/kb/items/index.vue @@ -330,6 +330,7 @@ const searchKeyword = ref('') // 文档列表 const documentList = ref([]) +const resourceTypeMap = ref>({}) // 保存 id -> resource_type 的映射 const loading = ref(false) const page = ref(1) const pageSize = ref(20) @@ -337,6 +338,7 @@ const total = ref(0) // 当前选中的文档 const currentDocument = ref(null) +const currentResourceType = ref('document') // 外层类型:document 或 faq const isFavorited = ref(false) // 编辑状态 @@ -433,7 +435,14 @@ const fetchData = async () => { } // 处理数据:提取 resource 字段(document 和 faq 都作为文档处理) - documentList.value = rawData.map((item: any) => item.resource) + // 同时保存每个文档对应的 resource_type + documentList.value = rawData.map((item: any) => { + // 保存 id -> resource_type 的映射 + if (item.resource?.id && item.type) { + resourceTypeMap.value[item.resource.id] = item.type + } + return item.resource + }) } else { documentList.value = [] total.value = 0 @@ -494,7 +503,7 @@ const handleSelectDocument = async (doc: Document) => { Message.warning('请先保存或取消当前编辑') return } - + try { loading.value = true const res: any = await fetchDocumentDetail(doc.id) @@ -502,9 +511,17 @@ const handleSelectDocument = async (doc: Document) => { // 兼容两种响应格式:直接返回文档对象 或 { type, resource } 格式 const docData = res.details.resource || res.details currentDocument.value = docData - + // 从文档详情中获取收藏状态 isFavorited.value = docData.is_favorited || false + + // 获取 resource_type:优先从列表映射中获取(因为详情接口可能不返回外层 type) + if (resourceTypeMap.value[doc.id]) { + currentResourceType.value = resourceTypeMap.value[doc.id] + } else if (res.details.type) { + // 备用:从详情响应中获取(注意:这可能是内层 type,如 common/guide) + currentResourceType.value = res.details.type + } } } catch (error) { console.error('获取文档详情失败:', error) @@ -517,6 +534,7 @@ const handleSelectDocument = async (doc: Document) => { // 新建文档 const handleCreate = () => { currentDocument.value = null + currentResourceType.value = 'document' // 新建时默认为 document isFavorited.value = false editForm.title = '' editForm.type = 'common' @@ -669,9 +687,9 @@ const handleDelete = () => { // 确认删除 const handleConfirmDelete = async () => { if (!currentDocument.value?.id) return - + try { - await moveToTrash(currentDocument.value.id) + await moveToTrash(currentDocument.value.id, currentResourceType.value) Message.success('删除成功,已移入回收站') deleteConfirmVisible.value = false currentDocument.value = null diff --git a/src/views/ops/pages/kb/tags/components/CategoryFormDialog.vue b/src/views/ops/pages/kb/tags/components/CategoryFormDialog.vue index dec15c8..21efd80 100644 --- a/src/views/ops/pages/kb/tags/components/CategoryFormDialog.vue +++ b/src/views/ops/pages/kb/tags/components/CategoryFormDialog.vue @@ -1,7 +1,7 @@ - + - + (() => [ field: 'keyword', label: '关键词', type: 'input', - placeholder: '请输入分类名称', + placeholder: '请输入标签名称', }, { field: 'type', - label: '分类类型', + label: '标签类型', type: 'select', - placeholder: '请选择分类类型', + placeholder: '请选择标签类型', options: [ - { label: '文档分类', value: 'document' }, - { label: 'FAQ分类', value: 'faq' }, - { label: '通用分类', value: 'general' }, + { label: '文档标签', value: 'document' }, + { label: 'FAQ标签', value: 'faq' }, + { label: '通用标签', value: 'general' }, ], allowClear: true, }, @@ -115,19 +115,19 @@ const columns = computed(() => [ align: 'center' as const, }, { - title: '分类名称', + title: '标签名称', dataIndex: 'name', ellipsis: true, tooltip: true, }, { - title: '分类描述', + title: '标签描述', dataIndex: 'description', ellipsis: true, tooltip: true, }, { - title: '分类类型', + title: '标签类型', dataIndex: 'type', slotName: 'type', width: 120, @@ -153,23 +153,23 @@ const columns = computed(() => [ }, ]) -// 当前选中的分类 +// 当前选中的标签 const editingCategory = ref(null) // 对话框可见性 const formVisible = ref(false) -// 获取分类类型标签 +// 获取标签类型标签 const getTypeLabel = (type: string) => { const typeMap: Record = { - document: '文档分类', - faq: 'FAQ分类', - general: '通用分类', + document: '文档标签', + faq: 'FAQ标签', + general: '通用标签', } return typeMap[type] || type } -// 获取分类类型颜色 +// 获取标签类型颜色 const getTypeColor = (type: string) => { const colorMap: Record = { document: 'blue', @@ -187,7 +187,7 @@ const updateTableData = () => { tableData.value = allData.value.slice(start, end) } -// 获取分类列表 +// 获取标签列表 const fetchCategories = async () => { loading.value = true @@ -217,14 +217,14 @@ const fetchCategories = async () => { pagination.value.current = 1 updateTableData() } else { - Message.error(res.message || '获取分类列表失败') + Message.error(res.message || '获取标签列表失败') allData.value = [] tableData.value = [] pagination.value.total = 0 } } catch (error) { - console.error('获取分类列表失败:', error) - Message.error('获取分类列表失败') + console.error('获取标签列表失败:', error) + Message.error('获取标签列表失败') allData.value = [] tableData.value = [] pagination.value.total = 0 @@ -271,23 +271,23 @@ const handlePageSizeChange = (pageSize: number) => { updateTableData() } -// 新增分类 +// 新增标签 const handleCreate = () => { editingCategory.value = null formVisible.value = true } -// 编辑分类 +// 编辑标签 const handleEdit = (record: Category) => { editingCategory.value = { ...record } formVisible.value = true } -// 删除分类 +// 删除标签 const handleDelete = async (record: Category) => { Modal.confirm({ title: '确认删除', - content: `确认删除分类「${record.name}」吗?`, + content: `确认删除标签「${record.name}」吗?`, onOk: async () => { try { const res: any = await deleteCategory(record.id) @@ -298,7 +298,7 @@ const handleDelete = async (record: Category) => { Message.error(res.message || '删除失败') } } catch (error) { - console.error('删除分类失败:', error) + console.error('删除标签失败:', error) Message.error('删除失败') } },