fix: 修正 FAQ 表单与分类交互
This commit is contained in:
@@ -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<T> {
|
||||
code: number
|
||||
message: string
|
||||
@@ -11,6 +15,7 @@ export interface KbReply<T> {
|
||||
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<FaqStatus, { text: string; color: string }> = {
|
||||
draft: { text: '草稿', color: 'gray' },
|
||||
published: { text: '待审核', color: 'orange' },
|
||||
reviewed: { text: '已审核', color: 'green' },
|
||||
rejected: { text: '已拒绝', color: 'red' },
|
||||
}
|
||||
|
||||
const faqPriorityMeta: Record<FaqPriority, { text: string; color: string }> = {
|
||||
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<KbReply<FaqPage>>('/Kb/v1/faq/list', {
|
||||
params,
|
||||
})
|
||||
|
||||
/** 获取 FAQ 详情。 */
|
||||
export const fetchFaqDetail = (id: number) => request.get<KbReply<Faq>>(`/Kb/v1/faq/${id}`)
|
||||
|
||||
/** 创建 FAQ 草稿。 */
|
||||
export const createFaq = (data: FaqFormData) => request.post<KbReply<Faq>>('/Kb/v1/faq/create', data)
|
||||
|
||||
/** 更新 FAQ。 */
|
||||
export const updateFaq = (data: UpdateFaqData) => request.post<KbReply<Faq>>('/Kb/v1/faq/update', data)
|
||||
|
||||
/** 提交 FAQ 审核。 */
|
||||
export const publishFaq = (id: number) => request.post<KbReply<string>>('/Kb/v1/faq/publish', { id })
|
||||
|
||||
/** 删除 FAQ 并移入回收站。 */
|
||||
export const deleteFaq = (id: number) => request.delete<KbReply<string>>(`/Kb/v1/faq/${id}`)
|
||||
|
||||
/** 收藏 FAQ。 */
|
||||
export const favoriteFaq = (id: number) =>
|
||||
request.post<KbReply<unknown>>('/Kb/v1/favorite/collect', {
|
||||
resource_type: 'faq',
|
||||
resource_id: id,
|
||||
})
|
||||
|
||||
/** 取消收藏 FAQ。 */
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user