From e43ada5c7f227f20ae7a4b051cb9350d56f7099e Mon Sep 17 00:00:00 2001 From: zxr <271055687@qq.com> Date: Wed, 22 Jul 2026 02:46:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20FAQ=20=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E4=B8=8E=E5=88=86=E7=B1=BB=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/kb/faq.ts | 47 +++++++++ .../kb/faq/components/FaqDetailDrawer.vue | 41 ++------ .../pages/kb/faq/components/FaqFormDrawer.vue | 30 +++++- src/views/ops/pages/kb/faq/index.vue | 97 ++++++++++--------- 4 files changed, 130 insertions(+), 85 deletions(-) diff --git a/src/api/kb/faq.ts b/src/api/kb/faq.ts index 32a132e..a678a66 100644 --- a/src/api/kb/faq.ts +++ b/src/api/kb/faq.ts @@ -1,9 +1,13 @@ import { request } from '@/api/request' +/** FAQ 审核状态。 */ export type FaqStatus = 'draft' | 'published' | 'reviewed' | 'rejected' +/** FAQ 优先级。 */ export type FaqPriority = 'low' | 'medium' | 'high' +/** FAQ 列表可见范围。 */ export type FaqScope = 'my' | 'all' +/** 知识库服务统一响应。 */ export interface KbReply { code: number message: string @@ -11,6 +15,7 @@ export interface KbReply { timeseq: number } +/** FAQ 资源。 */ export interface Faq { id: number created_at: string @@ -48,6 +53,7 @@ export interface Faq { is_favorited: boolean } +/** FAQ 分页结果。 */ export interface FaqPage { total: number page: number @@ -55,6 +61,7 @@ export interface FaqPage { data: Faq[] } +/** FAQ 列表查询参数。 */ export interface FaqListParams { page?: number page_size?: number @@ -66,6 +73,7 @@ export interface FaqListParams { problem_type?: string } +/** FAQ 创建和编辑字段。 */ export interface FaqFormData { question: string answer: string @@ -83,10 +91,12 @@ export interface FaqFormData { remarks: string } +/** FAQ 编辑请求。 */ export interface UpdateFaqData extends FaqFormData { id: number } +/** 公共分类树节点。 */ export interface CategoryTreeNode { id: number name: string @@ -104,6 +114,7 @@ export interface CategoryTreeNode { children: CategoryTreeNode[] } +/** FAQ 状态筛选项。 */ export const faqStatusOptions: Array<{ label: string; value: FaqStatus }> = [ { label: '草稿', value: 'draft' }, { label: '待审核', value: 'published' }, @@ -111,12 +122,14 @@ export const faqStatusOptions: Array<{ label: string; value: FaqStatus }> = [ { label: '已拒绝', value: 'rejected' }, ] +/** FAQ 优先级筛选项。 */ export const faqPriorityOptions: Array<{ label: string; value: FaqPriority }> = [ { label: '低', value: 'low' }, { label: '中', value: 'medium' }, { label: '高', value: 'high' }, ] +/** 常用问题类型;接口仍允许自由字符串。 */ export const faqProblemTypeOptions = [ { label: '故障', value: '故障' }, { label: '咨询', value: '咨询' }, @@ -124,31 +137,65 @@ export const faqProblemTypeOptions = [ { label: '其他', value: '其他' }, ] +const faqStatusMeta: Record = { + draft: { text: '草稿', color: 'gray' }, + published: { text: '待审核', color: 'orange' }, + reviewed: { text: '已审核', color: 'green' }, + rejected: { text: '已拒绝', color: 'red' }, +} + +const faqPriorityMeta: Record = { + low: { text: '低', color: 'gray' }, + medium: { text: '中', color: 'blue' }, + high: { text: '高', color: 'orange' }, +} + +/** 获取 FAQ 状态文案。 */ +export const getFaqStatusText = (status: FaqStatus | string) => faqStatusMeta[status as FaqStatus]?.text || status || '-' + +/** 获取 FAQ 状态标签颜色。 */ +export const getFaqStatusColor = (status: FaqStatus | string) => faqStatusMeta[status as FaqStatus]?.color || 'gray' + +/** 获取 FAQ 优先级文案。 */ +export const getFaqPriorityText = (priority: FaqPriority | string) => faqPriorityMeta[priority as FaqPriority]?.text || priority || '-' + +/** 获取 FAQ 优先级标签颜色。 */ +export const getFaqPriorityColor = (priority: FaqPriority | string) => faqPriorityMeta[priority as FaqPriority]?.color || 'gray' + +/** 获取 FAQ 列表。 */ export const fetchFaqList = (params: FaqListParams) => request.get>('/Kb/v1/faq/list', { params, }) +/** 获取 FAQ 详情。 */ export const fetchFaqDetail = (id: number) => request.get>(`/Kb/v1/faq/${id}`) +/** 创建 FAQ 草稿。 */ export const createFaq = (data: FaqFormData) => request.post>('/Kb/v1/faq/create', data) +/** 更新 FAQ。 */ export const updateFaq = (data: UpdateFaqData) => request.post>('/Kb/v1/faq/update', data) +/** 提交 FAQ 审核。 */ export const publishFaq = (id: number) => request.post>('/Kb/v1/faq/publish', { id }) +/** 删除 FAQ 并移入回收站。 */ export const deleteFaq = (id: number) => request.delete>(`/Kb/v1/faq/${id}`) +/** 收藏 FAQ。 */ export const favoriteFaq = (id: number) => request.post>('/Kb/v1/favorite/collect', { resource_type: 'faq', resource_id: id, }) +/** 取消收藏 FAQ。 */ export const unfavoriteFaq = (id: number) => request.post>('/Kb/v1/favorite/uncollect', { resource_type: 'faq', resource_id: id, }) +/** 获取公共分类树。 */ export const fetchGeneralCategoryTree = () => request.get>('/Kb/v1/category/tree') diff --git a/src/views/ops/pages/kb/faq/components/FaqDetailDrawer.vue b/src/views/ops/pages/kb/faq/components/FaqDetailDrawer.vue index 2629626..b18cd2b 100644 --- a/src/views/ops/pages/kb/faq/components/FaqDetailDrawer.vue +++ b/src/views/ops/pages/kb/faq/components/FaqDetailDrawer.vue @@ -15,8 +15,8 @@
{{ faq.faq_no || `FAQ-${faq.id}` }}

{{ faq.question }}

- {{ statusText(faq.status) }} - {{ priorityText(faq.priority) }} + {{ getFaqStatusText(faq.status) }} + {{ getFaqPriorityText(faq.priority) }} @@ -42,7 +42,8 @@

基本信息

{{ categoryName || '-' }} - {{ problemTypeText(faq.problem_type) }} + {{ faq.sub_category || '-' }} + {{ faq.problem_type || '-' }} {{ faq.author_name || `用户 ${faq.author_id}` }} {{ formatTime(faq.updated_at) }} {{ faq.reviewer_name || '-' }} @@ -105,7 +106,7 @@