refactor(群推任务): 统一API接口参数和响应处理
重构群推任务相关API接口,将参数改为对象形式并统一响应处理 更新任务状态切换接口,添加type参数区分任务类型 修改字段名maxPushPerDay为maxPerDay保持一致性 使用Toast组件替代window.alert进行提示
This commit is contained in:
@@ -35,8 +35,8 @@ export function deleteAutoLikeTask(id: string): Promise<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 切换任务状态
|
// 切换任务状态
|
||||||
export function toggleAutoLikeTask(id: string, status: string): Promise<any> {
|
export function toggleAutoLikeTask(data): Promise<any> {
|
||||||
return request("/v1/workbench/update-status", { id, status }, "POST");
|
return request("/v1/workbench/update-status", { ...data, type: 1 }, "POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制自动点赞任务
|
// 复制自动点赞任务
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ export interface GroupPushTask {
|
|||||||
createTime: string;
|
createTime: string;
|
||||||
creator: string;
|
creator: string;
|
||||||
pushInterval: number;
|
pushInterval: number;
|
||||||
maxPushPerDay: number;
|
maxPerDay: number;
|
||||||
timeRange: { start: string; end: string };
|
startTime: string; // 允许推送的开始时间
|
||||||
|
endTime: string; // 允许推送的结束时间
|
||||||
messageType: "text" | "image" | "video" | "link";
|
messageType: "text" | "image" | "video" | "link";
|
||||||
messageContent: string;
|
messageContent: string;
|
||||||
targetTags: string[];
|
targetTags: string[];
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ const Detail: React.FC = () => {
|
|||||||
<div>
|
<div>
|
||||||
<SettingOutlined /> <b>基本设置</b>
|
<SettingOutlined /> <b>基本设置</b>
|
||||||
<div>推送间隔:{task.pushInterval} 秒</div>
|
<div>推送间隔:{task.pushInterval} 秒</div>
|
||||||
<div>每日最大推送数:{task.maxPushPerDay} 条</div>
|
<div>每日最大推送数:{task.maxPerDay} 条</div>
|
||||||
<div>
|
<div>
|
||||||
执行时间段:{task.timeRange.start} - {task.timeRange.end}
|
执行时间段:{task.timeRange.start} - {task.timeRange.end}
|
||||||
</div>
|
</div>
|
||||||
@@ -221,12 +221,10 @@ const Detail: React.FC = () => {
|
|||||||
<div>
|
<div>
|
||||||
<CalendarOutlined /> <b>执行进度</b>
|
<CalendarOutlined /> <b>执行进度</b>
|
||||||
<div>
|
<div>
|
||||||
今日已推送:{task.pushCount} / {task.maxPushPerDay}
|
今日已推送:{task.pushCount} / {task.maxPerDay}
|
||||||
</div>
|
</div>
|
||||||
<Progress
|
<Progress
|
||||||
percent={Math.round(
|
percent={Math.round((task.pushCount / task.maxPerDay) * 100)}
|
||||||
(task.pushCount / task.maxPushPerDay) * 100,
|
|
||||||
)}
|
|
||||||
size="small"
|
size="small"
|
||||||
/>
|
/>
|
||||||
{task.targetTags.length > 0 && (
|
{task.targetTags.length > 0 && (
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { Button } from "antd";
|
import { Button } from "antd";
|
||||||
|
import { Toast } from "antd-mobile";
|
||||||
import { createGroupPushTask } from "./index.api";
|
import { createGroupPushTask } from "./index.api";
|
||||||
import Layout from "@/components/Layout/Layout";
|
import Layout from "@/components/Layout/Layout";
|
||||||
import StepIndicator from "@/components/StepIndicator";
|
import StepIndicator from "@/components/StepIndicator";
|
||||||
@@ -95,7 +96,7 @@ const NewGroupPush: React.FC = () => {
|
|||||||
name: formData.name,
|
name: formData.name,
|
||||||
startTime: formData.startTime, // 允许推送的开始时间
|
startTime: formData.startTime, // 允许推送的开始时间
|
||||||
endTime: formData.endTime, // 允许推送的结束时间
|
endTime: formData.endTime, // 允许推送的结束时间
|
||||||
maxPushPerDay: formData.maxPerDay,
|
maxPerDay: formData.maxPerDay,
|
||||||
pushOrder: formData.pushOrder,
|
pushOrder: formData.pushOrder,
|
||||||
isLoop: formData.isLoop, // 0: 否, 1: 是
|
isLoop: formData.isLoop, // 0: 否, 1: 是
|
||||||
pushType: formData.pushType, // 0: 定时推送, 1: 立即推送
|
pushType: formData.pushType, // 0: 定时推送, 1: 立即推送
|
||||||
@@ -121,19 +122,20 @@ const NewGroupPush: React.FC = () => {
|
|||||||
// 调用创建或更新 API
|
// 调用创建或更新 API
|
||||||
if (id) {
|
if (id) {
|
||||||
// 更新逻辑将在这里实现
|
// 更新逻辑将在这里实现
|
||||||
window.alert("更新成功");
|
Toast.show({ content: "更新成功", position: "top" });
|
||||||
|
navigate("/workspace/group-push");
|
||||||
} else {
|
} else {
|
||||||
const response = await createGroupPushTask(apiData);
|
createGroupPushTask(apiData)
|
||||||
if (response.code === 200) {
|
.then(() => {
|
||||||
window.alert("创建成功");
|
Toast.show({ content: "创建成功", position: "top" });
|
||||||
navigate("/workspace/group-push");
|
navigate("/workspace/group-push");
|
||||||
} else {
|
})
|
||||||
window.alert("保存失败,请稍后重试");
|
.catch(() => {
|
||||||
}
|
Toast.show({ content: "创建失败,请稍后重试", position: "top" });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("保存失败:", error);
|
Toast.show({ content: "保存失败,请稍后重试", position: "top" });
|
||||||
window.alert("保存失败,请稍后重试");
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import request from "@/api/request";
|
import request from "@/api/request";
|
||||||
|
import { GroupPushTask } from "../detail/groupPush";
|
||||||
|
|
||||||
interface ApiResponse<T = any> {
|
interface ApiResponse<T = any> {
|
||||||
code: number;
|
code: number;
|
||||||
@@ -11,22 +12,16 @@ export async function fetchGroupPushTasks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteGroupPushTask(id: string): Promise<ApiResponse> {
|
export async function deleteGroupPushTask(id: string): Promise<ApiResponse> {
|
||||||
return request(`/v1/workspace/group-push/tasks/${id}`, {}, "DELETE");
|
return request("/v1/workbench/delete", { id }, "DELETE");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function toggleGroupPushTask(
|
// 切换任务状态
|
||||||
id: string,
|
export function toggleGroupPushTask(data): Promise<any> {
|
||||||
status: string,
|
return request("/v1/workbench/update-status", { ...data, type: 3 }, "POST");
|
||||||
): Promise<ApiResponse> {
|
|
||||||
return request(
|
|
||||||
`/v1/workspace/group-push/tasks/${id}/toggle`,
|
|
||||||
{ status },
|
|
||||||
"POST",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function copyGroupPushTask(id: string): Promise<ApiResponse> {
|
export async function copyGroupPushTask(id: string): Promise<ApiResponse> {
|
||||||
return request(`/v1/workspace/group-push/tasks/${id}/copy`, {}, "POST");
|
return request("/v1/workbench/copy", { id }, "POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createGroupPushTask(
|
export async function createGroupPushTask(
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ const GroupPush: React.FC = () => {
|
|||||||
const task = tasks.find(t => t.id === taskId);
|
const task = tasks.find(t => t.id === taskId);
|
||||||
if (!task) return;
|
if (!task) return;
|
||||||
const newStatus = task.status === 1 ? 2 : 1;
|
const newStatus = task.status === 1 ? 2 : 1;
|
||||||
await toggleGroupPushTask(taskId, String(newStatus));
|
await toggleGroupPushTask({ id: taskId, status: newStatus });
|
||||||
fetchTasks();
|
fetchTasks();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user