feat: 新增CWD评论系统前后端代码及文档
refactor: 移除旧版评论系统代码并重构为Vue3前端 docs: 更新后端配置文档说明 fix: 修复评论提交频率限制和邮件通知逻辑 style: 格式化代码并优化样式 test: 添加Vitest测试配置 build: 更新依赖项和构建配置 chore: 清理无用文件和缓存
This commit is contained in:
65
cwd-comments-admin/src/api/admin.ts
Normal file
65
cwd-comments-admin/src/api/admin.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { get, post, put, del } from './http';
|
||||
|
||||
export type AdminLoginResponse = {
|
||||
data: {
|
||||
key: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type CommentItem = {
|
||||
id: number;
|
||||
pubDate: string;
|
||||
author: string;
|
||||
email: string;
|
||||
postSlug: string;
|
||||
url: string | null;
|
||||
ipAddress: string | null;
|
||||
contentText: string;
|
||||
contentHtml: string;
|
||||
status: string;
|
||||
};
|
||||
|
||||
export type CommentListResponse = {
|
||||
data: CommentItem[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type AdminEmailResponse = {
|
||||
email: string | null;
|
||||
};
|
||||
|
||||
export async function loginAdmin(name: string, password: string): Promise<string> {
|
||||
const res = await post<AdminLoginResponse>('/admin/login', { name, password });
|
||||
const key = res.data.key;
|
||||
localStorage.setItem('cwd_admin_token', key);
|
||||
return key;
|
||||
}
|
||||
|
||||
export function logoutAdmin(): void {
|
||||
localStorage.removeItem('cwd_admin_token');
|
||||
}
|
||||
|
||||
export function fetchComments(page: number): Promise<CommentListResponse> {
|
||||
return get<CommentListResponse>(`/admin/comments/list?page=${page}`);
|
||||
}
|
||||
|
||||
export function deleteComment(id: number): Promise<{ message: string }> {
|
||||
return del<{ message: string }>(`/admin/comments/delete?id=${id}`);
|
||||
}
|
||||
|
||||
export function updateCommentStatus(id: number, status: string): Promise<{ message: string }> {
|
||||
return put<{ message: string }>(`/admin/comments/status?id=${id}&status=${encodeURIComponent(status)}`);
|
||||
}
|
||||
|
||||
export function fetchAdminEmail(): Promise<AdminEmailResponse> {
|
||||
return get<AdminEmailResponse>('/admin/settings/email');
|
||||
}
|
||||
|
||||
export function saveAdminEmail(email: string): Promise<{ message: string }> {
|
||||
return put<{ message: string }>('/admin/settings/email', { email });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user