feat
This commit is contained in:
@@ -1,96 +1,96 @@
|
||||
import { request } from "@/api/request";
|
||||
import { request } from '@/api/request'
|
||||
|
||||
/** 文档状态 */
|
||||
export type DocumentStatus = 'draft' | 'published' | 'reviewed' | 'rejected';
|
||||
export type DocumentStatus = 'draft' | 'published' | 'reviewed' | 'rejected'
|
||||
|
||||
/** 文档类型 */
|
||||
export type DocumentType = 'common' | 'guide' | 'solution' | 'troubleshoot' | 'process' | 'technical';
|
||||
export type DocumentType = 'common' | 'guide' | 'solution' | 'troubleshoot' | 'process' | 'technical'
|
||||
|
||||
/** 文档接口类型 */
|
||||
export interface Document {
|
||||
id: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
doc_no: string;
|
||||
title: string;
|
||||
description: string;
|
||||
content: string;
|
||||
type: DocumentType;
|
||||
status: DocumentStatus;
|
||||
category_id: number;
|
||||
sub_category: string;
|
||||
author_id: number;
|
||||
author_name: string;
|
||||
reviewer_id: number;
|
||||
reviewer_name: string;
|
||||
reviewed_at: string | null;
|
||||
published_at: string | null;
|
||||
publisher_id: number;
|
||||
view_count: number;
|
||||
like_count: number;
|
||||
comment_count: number;
|
||||
download_count: number;
|
||||
version: string;
|
||||
version_notes: string;
|
||||
tags: string;
|
||||
attachments: string | null;
|
||||
related_docs: string | null;
|
||||
metadata: string | null;
|
||||
keywords: string;
|
||||
remarks: string;
|
||||
is_favorited?: boolean;
|
||||
id: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
doc_no: string
|
||||
title: string
|
||||
description: string
|
||||
content: string
|
||||
type: DocumentType
|
||||
status: DocumentStatus
|
||||
category_id: number
|
||||
sub_category: string
|
||||
author_id: number
|
||||
author_name: string
|
||||
reviewer_id: number
|
||||
reviewer_name: string
|
||||
reviewed_at: string | null
|
||||
published_at: string | null
|
||||
publisher_id: number
|
||||
view_count: number
|
||||
like_count: number
|
||||
comment_count: number
|
||||
download_count: number
|
||||
version: string
|
||||
version_notes: string
|
||||
tags: string
|
||||
attachments: string | null
|
||||
related_docs: string | null
|
||||
metadata: string | null
|
||||
keywords: string
|
||||
remarks: string
|
||||
is_favorited?: boolean
|
||||
}
|
||||
|
||||
/** API响应包装类型 */
|
||||
export interface ApiResponse<T = any> {
|
||||
code: number;
|
||||
message: string;
|
||||
data: T;
|
||||
code: number
|
||||
message: string
|
||||
data: T
|
||||
}
|
||||
|
||||
/** 分页响应类型 */
|
||||
export interface PaginatedResponse<T> {
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
data: T[];
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
data: T[]
|
||||
}
|
||||
|
||||
/** 创建文档请求参数 */
|
||||
export interface CreateDocumentParams {
|
||||
title: string;
|
||||
description?: string;
|
||||
content: string;
|
||||
type?: DocumentType;
|
||||
category_id?: number;
|
||||
sub_category?: string;
|
||||
keywords?: string;
|
||||
tags?: string;
|
||||
remarks?: string;
|
||||
title: string
|
||||
description?: string
|
||||
content: string
|
||||
type?: DocumentType
|
||||
category_id?: number
|
||||
sub_category?: string
|
||||
keywords?: string
|
||||
tags?: string
|
||||
remarks?: string
|
||||
}
|
||||
|
||||
/** 更新文档请求参数 */
|
||||
export interface UpdateDocumentParams {
|
||||
id: number;
|
||||
title?: string;
|
||||
description?: string;
|
||||
content?: string;
|
||||
type?: DocumentType;
|
||||
category_id?: number;
|
||||
sub_category?: string;
|
||||
keywords?: string;
|
||||
tags?: string;
|
||||
remarks?: string;
|
||||
id: number
|
||||
title?: string
|
||||
description?: string
|
||||
content?: string
|
||||
type?: DocumentType
|
||||
category_id?: number
|
||||
sub_category?: string
|
||||
keywords?: string
|
||||
tags?: string
|
||||
remarks?: string
|
||||
}
|
||||
|
||||
/** 获取文档列表参数 */
|
||||
export interface FetchDocumentListParams {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
keyword?: string;
|
||||
type?: DocumentType;
|
||||
status?: DocumentStatus;
|
||||
category_id?: number;
|
||||
page?: number
|
||||
page_size?: number
|
||||
keyword?: string
|
||||
type?: DocumentType
|
||||
status?: DocumentStatus
|
||||
category_id?: number
|
||||
}
|
||||
|
||||
/** 文档类型选项 */
|
||||
@@ -101,7 +101,7 @@ export const documentTypeOptions = [
|
||||
{ label: '故障排查', value: 'troubleshoot' },
|
||||
{ label: '流程规范', value: 'process' },
|
||||
{ label: '技术文档', value: 'technical' },
|
||||
];
|
||||
]
|
||||
|
||||
/** 文档状态选项 */
|
||||
export const documentStatusOptions = [
|
||||
@@ -109,7 +109,7 @@ export const documentStatusOptions = [
|
||||
{ label: '已发布', value: 'published' },
|
||||
{ label: '已审核', value: 'reviewed' },
|
||||
{ label: '未通过审核', value: 'rejected' },
|
||||
];
|
||||
]
|
||||
|
||||
/** 获取文档状态文本 */
|
||||
export const getDocumentStatusText = (status: DocumentStatus): string => {
|
||||
@@ -118,9 +118,9 @@ export const getDocumentStatusText = (status: DocumentStatus): string => {
|
||||
published: '已发布',
|
||||
reviewed: '已审核',
|
||||
rejected: '未通过审核',
|
||||
};
|
||||
return statusMap[status] || status;
|
||||
};
|
||||
}
|
||||
return statusMap[status] || status
|
||||
}
|
||||
|
||||
/** 获取文档状态颜色 */
|
||||
export const getDocumentStatusColor = (status: DocumentStatus): string => {
|
||||
@@ -129,9 +129,9 @@ export const getDocumentStatusColor = (status: DocumentStatus): string => {
|
||||
published: 'blue',
|
||||
reviewed: 'green',
|
||||
rejected: 'red',
|
||||
};
|
||||
return colorMap[status] || 'gray';
|
||||
};
|
||||
}
|
||||
return colorMap[status] || 'gray'
|
||||
}
|
||||
|
||||
/** 获取文档类型文本 */
|
||||
export const getDocumentTypeText = (type: DocumentType): string => {
|
||||
@@ -142,77 +142,76 @@ export const getDocumentTypeText = (type: DocumentType): string => {
|
||||
troubleshoot: '故障排查',
|
||||
process: '流程规范',
|
||||
technical: '技术文档',
|
||||
};
|
||||
return typeMap[type] || type;
|
||||
};
|
||||
}
|
||||
return typeMap[type] || type
|
||||
}
|
||||
|
||||
/** 创建文档 */
|
||||
export const createDocument = (data: CreateDocumentParams) => {
|
||||
return request.post<ApiResponse<Document>>("/Kb/v1/document/create", data);
|
||||
};
|
||||
return request.post<ApiResponse<Document>>('/Kb/v1/document/create', data)
|
||||
}
|
||||
|
||||
/** 更新文档 */
|
||||
export const updateDocument = (data: UpdateDocumentParams) => {
|
||||
return request.post<ApiResponse<Document>>("/Kb/v1/document/update", data);
|
||||
};
|
||||
return request.post<ApiResponse<Document>>('/Kb/v1/document/update', data)
|
||||
}
|
||||
|
||||
/** 删除文档(移入回收站) */
|
||||
export const deleteDocument = (id: number) => {
|
||||
return request.delete<ApiResponse<string>>(`/Kb/v1/document/${id}`);
|
||||
};
|
||||
return request.delete<ApiResponse<string>>(`/Kb/v1/document/${id}`)
|
||||
}
|
||||
|
||||
/** 获取文档详情 */
|
||||
export const fetchDocumentDetail = (id: number) => {
|
||||
return request.get<ApiResponse<Document>>(`/Kb/v1/document/${id}`);
|
||||
};
|
||||
return request.get<ApiResponse<Document>>(`/Kb/v1/document/${id}`)
|
||||
}
|
||||
|
||||
/** 获取文档列表 */
|
||||
export const fetchDocumentList = (params?: FetchDocumentListParams) => {
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>("/Kb/v1/document/list", { params });
|
||||
};
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>('/Kb/v1/document/list', { params })
|
||||
}
|
||||
|
||||
/** 发布文档 */
|
||||
export const publishDocument = (id: number) => {
|
||||
return request.post<ApiResponse<string>>("/Kb/v1/document/publish", { id });
|
||||
};
|
||||
return request.post<ApiResponse<string>>('/Kb/v1/document/publish', { id })
|
||||
}
|
||||
|
||||
/** 移入回收站 */
|
||||
export const moveToTrash = (resourceId: number, resourceType: string) => {
|
||||
return request.post<ApiResponse<string>>("/Kb/v1/trash/move", {
|
||||
return request.post<ApiResponse<string>>('/Kb/v1/trash/move', {
|
||||
resource_id: resourceId,
|
||||
resource_type: resourceType,
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
/** 获取我的文档列表(由我创建的所有文档) */
|
||||
export const fetchMyDocumentList = (params?: FetchDocumentListParams) => {
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>("/Kb/v1/review/publish/list", { params });
|
||||
};
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>('/Kb/v1/review/publish/list', { params })
|
||||
}
|
||||
|
||||
/** 获取已审核通过的文档列表 */
|
||||
export const fetchApprovedDocumentList = (params?: FetchDocumentListParams) => {
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>("/Kb/v1/review/approved/list", { params });
|
||||
};
|
||||
return request.get<ApiResponse<PaginatedResponse<Document>>>('/Kb/v1/review/approved/list', { params })
|
||||
}
|
||||
|
||||
/** 收藏文档 */
|
||||
export const favoriteDocument = (id: number, remarks?: string) => {
|
||||
return request.post<ApiResponse<string>>("/Kb/v1/favorite/collect", {
|
||||
return request.post<ApiResponse<string>>('/Kb/v1/favorite/collect', {
|
||||
resource_type: 'document',
|
||||
resource_id: id,
|
||||
remarks,
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
/** 取消收藏文档 */
|
||||
export const unfavoriteDocument = (id: number) => {
|
||||
return request.post<ApiResponse<string>>("/Kb/v1/favorite/uncollect", {
|
||||
return request.post<ApiResponse<string>>('/Kb/v1/favorite/uncollect', {
|
||||
resource_type: 'document',
|
||||
resource_id: id,
|
||||
});
|
||||
};
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
/** 下载文档 */
|
||||
export const downloadDocument = (id: number) => {
|
||||
return request.get<Blob>(`/Kb/v1/document/${id}/download`, { responseType: 'blob' });
|
||||
};
|
||||
return request.get<Blob>(`/Kb/v1/document/${id}/download`, { responseType: 'blob' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user