feat: 增加知识库 FAQ 管理页面

This commit is contained in:
zxr
2026-07-22 02:30:50 +08:00
parent 52a0346c4c
commit f2f4390ac2
4 changed files with 1309 additions and 0 deletions

154
src/api/kb/faq.ts Normal file
View File

@@ -0,0 +1,154 @@
import { request } from '@/api/request'
export type FaqStatus = 'draft' | 'published' | 'reviewed' | 'rejected'
export type FaqPriority = 'low' | 'medium' | 'high'
export type FaqScope = 'my' | 'all'
export interface KbReply<T> {
code: number
message: string
details: T
timeseq: number
}
export interface Faq {
id: number
created_at: string
updated_at: string
faq_no: string
question: string
answer: string
status: FaqStatus
priority: FaqPriority
category_id: number
sub_category: string
problem_type: string
solution: string
process_steps: string
prerequisites: string
author_id: number
author_name: string
reviewer_id: number
reviewer_name: string
reviewed_at: string | null
published_at: string | null
view_count: number
use_count: number
helpful_count: number
useless_count: number
tags: string
related_faqs: string
related_docs: string
related_links: string
detection_point_ids: string
attachments: string
keywords: string
applicable_scope: string
remarks: string
is_favorited: boolean
}
export interface FaqPage {
total: number
page: number
page_size: number
data: Faq[]
}
export interface FaqListParams {
page?: number
page_size?: number
scope?: FaqScope
keyword?: string
category_id?: number
status?: FaqStatus
priority?: FaqPriority
problem_type?: string
}
export interface FaqFormData {
question: string
answer: string
priority: FaqPriority
category_id: number
sub_category: string
problem_type: string
solution: string
process_steps: string
prerequisites: string
keywords: string
tags: string
detection_point_ids: string
applicable_scope: string
remarks: string
}
export interface UpdateFaqData extends FaqFormData {
id: number
}
export interface CategoryTreeNode {
id: number
name: string
description: string
type: 'general'
icon: string
color: string
parent_id: number
level: number
path: string
sort_order: number
status: 'active' | 'inactive'
doc_count: number
faq_count: number
children: CategoryTreeNode[]
}
export const faqStatusOptions: Array<{ label: string; value: FaqStatus }> = [
{ label: '草稿', value: 'draft' },
{ label: '待审核', value: 'published' },
{ label: '已审核', value: 'reviewed' },
{ label: '已拒绝', value: 'rejected' },
]
export const faqPriorityOptions: Array<{ label: string; value: FaqPriority }> = [
{ label: '低', value: 'low' },
{ label: '中', value: 'medium' },
{ label: '高', value: 'high' },
]
export const faqProblemTypeOptions = [
{ label: '故障', value: '故障' },
{ label: '咨询', value: '咨询' },
{ label: '请求', value: '请求' },
{ label: '其他', value: '其他' },
]
export const fetchFaqList = (params: FaqListParams) =>
request.get<KbReply<FaqPage>>('/Kb/v1/faq/list', {
params,
})
export const fetchFaqDetail = (id: number) => request.get<KbReply<Faq>>(`/Kb/v1/faq/${id}`)
export const createFaq = (data: FaqFormData) => request.post<KbReply<Faq>>('/Kb/v1/faq/create', data)
export const updateFaq = (data: UpdateFaqData) => request.post<KbReply<Faq>>('/Kb/v1/faq/update', data)
export const publishFaq = (id: number) => request.post<KbReply<string>>('/Kb/v1/faq/publish', { id })
export const deleteFaq = (id: number) => request.delete<KbReply<string>>(`/Kb/v1/faq/${id}`)
export const favoriteFaq = (id: number) =>
request.post<KbReply<unknown>>('/Kb/v1/favorite/collect', {
resource_type: 'faq',
resource_id: id,
})
export const unfavoriteFaq = (id: number) =>
request.post<KbReply<string>>('/Kb/v1/favorite/uncollect', {
resource_type: 'faq',
resource_id: id,
})
export const fetchGeneralCategoryTree = () => request.get<KbReply<CategoryTreeNode[]>>('/Kb/v1/category/tree')