feat: 本次提交更新内容如下

自动点赞列表构建完成
This commit is contained in:
2025-07-21 17:47:22 +08:00
parent 94f61085ca
commit 5f9ffadc37
15 changed files with 2500 additions and 81 deletions

173
nkebao/src/api/autoLike.ts Normal file
View File

@@ -0,0 +1,173 @@
import { request } from "./request";
import {
LikeTask,
CreateLikeTaskData,
UpdateLikeTaskData,
LikeRecord,
ApiResponse,
PaginatedResponse,
} from "@/types/auto-like";
// 获取自动点赞任务列表
export async function fetchAutoLikeTasks(): Promise<LikeTask[]> {
try {
const res = await request<ApiResponse<PaginatedResponse<LikeTask>>>({
url: "/v1/workbench/list",
method: "GET",
params: {
type: 1,
page: 1,
limit: 100,
},
});
if (res.code === 200 && res.data) {
return res.data.list || [];
}
return [];
} catch (error) {
console.error("获取自动点赞任务失败:", error);
return [];
}
}
// 获取单个任务详情
export async function fetchAutoLikeTaskDetail(
id: string
): Promise<LikeTask | null> {
try {
console.log(`Fetching task detail for id: ${id}`);
const res = await request<any>({
url: "/v1/workbench/detail",
method: "GET",
params: { id },
});
console.log("Task detail API response:", res);
if (res.code === 200) {
if (res.data) {
if (typeof res.data === "object") {
return res.data;
} else {
console.error(
"Task detail API response data is not an object:",
res.data
);
return null;
}
} else {
console.error("Task detail API response missing data field:", res);
return null;
}
}
console.error("Task detail API error:", res.msg || "Unknown error");
return null;
} catch (error) {
console.error("获取任务详情失败:", error);
return null;
}
}
// 创建自动点赞任务
export async function createAutoLikeTask(
data: CreateLikeTaskData
): Promise<ApiResponse> {
return request({
url: "/v1/workbench/create",
method: "POST",
data: {
...data,
type: 1, // 自动点赞类型
},
});
}
// 更新自动点赞任务
export async function updateAutoLikeTask(
data: UpdateLikeTaskData
): Promise<ApiResponse> {
return request({
url: "/v1/workbench/update",
method: "POST",
data: {
...data,
type: 1, // 自动点赞类型
},
});
}
// 删除自动点赞任务
export async function deleteAutoLikeTask(id: string): Promise<ApiResponse> {
return request({
url: "/v1/workbench/delete",
method: "DELETE",
params: { id },
});
}
// 切换任务状态
export async function toggleAutoLikeTask(
id: string,
status: string
): Promise<ApiResponse> {
return request({
url: "/v1/workbench/update-status",
method: "POST",
data: { id, status },
});
}
// 复制自动点赞任务
export async function copyAutoLikeTask(id: string): Promise<ApiResponse> {
return request({
url: "/v1/workbench/copy",
method: "POST",
data: { id },
});
}
// 获取点赞记录
export async function fetchLikeRecords(
workbenchId: string,
page: number = 1,
limit: number = 20,
keyword?: string
): Promise<PaginatedResponse<LikeRecord>> {
try {
const params: any = {
workbenchId,
page: page.toString(),
limit: limit.toString(),
};
if (keyword) {
params.keyword = keyword;
}
const res = await request<ApiResponse<PaginatedResponse<LikeRecord>>>({
url: "/v1/workbench/records",
method: "GET",
params,
});
if (res.code === 200 && res.data) {
return res.data;
}
return {
list: [],
total: 0,
page: 1,
limit: 20,
};
} catch (error) {
console.error("获取点赞记录失败:", error);
return {
list: [],
total: 0,
page: 1,
limit: 20,
};
}
}