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

This commit is contained in:
笔记本里的永平
2025-07-22 19:18:05 +08:00
parent 7d382f14fd
commit 7445840fdf
6 changed files with 500 additions and 902 deletions

View File

@@ -1,4 +1,5 @@
# 基础环境变量示例
VITE_API_BASE_URL=http://www.yishi.com
# VITE_API_BASE_URL=http://www.yishi.com
VITE_API_BASE_URL=https://ckbapi.quwanzhi.com
VITE_APP_TITLE=Nkebao Base

View File

@@ -1,10 +0,0 @@
import request from "@/api/request";
// 获取设备列表
export function getDeviceList(params: {
page: number;
limit: number;
keyword?: string;
}) {
return request("/v1/devices", params, "GET");
}

View File

@@ -1,197 +0,0 @@
.popupContainer {
display: flex;
flex-direction: column;
height: 100vh;
background: #fff;
}
.popupHeader {
padding: 16px;
border-bottom: 1px solid #f0f0f0;
}
.popupTitle {
font-size: 18px;
font-weight: 600;
text-align: center;
}
.popupSearchRow {
display: flex;
align-items: center;
gap: 16px;
padding: 16px;
}
.popupSearchInputWrap {
position: relative;
flex: 1;
}
.inputIcon {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
color: #bdbdbd;
z-index: 10;
font-size: 16px;
}
.popupSearchInput {
padding-left: 36px !important;
border-radius: 12px !important;
height: 44px;
font-size: 15px;
border: 1px solid #e5e6eb !important;
background: #f8f9fa;
}
.statusSelect {
width: 128px;
height: 40px;
border-radius: 8px;
border: 1px solid #e5e6eb;
font-size: 14px;
padding: 0 12px;
background: #fff;
}
.loadingIcon {
animation: spin 1s linear infinite;
font-size: 16px;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.deviceList {
flex: 1;
overflow-y: auto;
}
.deviceListInner {
display: flex;
flex-direction: column;
gap: 12px;
padding: 16px;
}
.deviceItem {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 16px;
border-radius: 12px;
border: 1px solid #f0f0f0;
background: #fff;
cursor: pointer;
transition: background 0.2s;
&:hover {
background: #f5f6fa;
}
}
.deviceCheckbox {
margin-top: 4px;
}
.deviceInfo {
flex: 1;
}
.deviceInfoRow {
display: flex;
align-items: center;
justify-content: space-between;
}
.deviceName {
font-weight: 500;
font-size: 16px;
color: #222;
}
.statusOnline {
padding: 4px 8px;
border-radius: 12px;
background: #52c41a;
color: #fff;
font-size: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.statusOffline {
padding: 4px 8px;
border-radius: 12px;
background: #e5e6eb;
color: #888;
font-size: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.deviceInfoDetail {
font-size: 13px;
color: #888;
margin-top: 4px;
}
.usedInPlans {
font-size: 13px;
color: #fa8c16;
margin-top: 4px;
}
.loadingBox {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.loadingText {
color: #888;
font-size: 15px;
}
.emptyBox {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.emptyText {
color: #888;
font-size: 15px;
}
.popupFooter {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-top: 1px solid #f0f0f0;
background: #fff;
}
.selectedCount {
font-size: 14px;
color: #888;
}
.footerBtnGroup {
display: flex;
gap: 12px;
}
.refreshBtn {
width: 36px;
height: 36px;
}
.paginationRow {
border-top: 1px solid #f0f0f0;
padding: 16px;
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
}
.totalCount {
font-size: 14px;
color: #888;
}
.paginationControls {
display: flex;
align-items: center;
gap: 8px;
}
.pageBtn {
padding: 0 8px;
height: 32px;
min-width: 32px;
border-radius: 16px;
}
.pageInfo {
font-size: 14px;
color: #222;
margin: 0 8px;
}

View File

@@ -1,258 +0,0 @@
import React, { useState, useEffect, useCallback } from "react";
import { SearchOutlined, ReloadOutlined } from "@ant-design/icons";
import { Checkbox, Popup, Toast } from "antd-mobile";
import { Input, Button } from "antd";
import { getDeviceList } from "./api";
import style from "./index.module.scss";
interface Device {
id: string;
name: string;
imei: string;
wxid: string;
status: "online" | "offline";
usedInPlans: number;
nickname: string;
}
interface DeviceSelectionDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
selectedDevices: string[];
onSelect: (devices: string[]) => void;
}
export function DeviceSelectionDialog({
open,
onOpenChange,
selectedDevices,
onSelect,
}: DeviceSelectionDialogProps) {
const [searchQuery, setSearchQuery] = useState("");
const [statusFilter, setStatusFilter] = useState("all");
const [loading, setLoading] = useState(false);
const [devices, setDevices] = useState<Device[]>([]);
const [currentPage, setCurrentPage] = useState(1); // 新增
const [total, setTotal] = useState(0); // 新增
const pageSize = 20; // 每页条数
// 获取设备列表支持keyword和分页
const fetchDevices = useCallback(
async (keyword: string = "", page: number = 1) => {
setLoading(true);
try {
const response = await getDeviceList({
page,
limit: pageSize,
keyword: keyword.trim() || undefined,
});
if (response && Array.isArray(response.list)) {
const convertedDevices: Device[] = response.list.map(
(serverDevice: any) => ({
id: serverDevice.id.toString(),
name: serverDevice.memo || `设备 ${serverDevice.id}`,
imei: serverDevice.imei,
wxid: serverDevice.wechatId || "",
status: serverDevice.alive === 1 ? "online" : "offline",
usedInPlans: 0,
nickname: serverDevice.nickname || "",
})
);
setDevices(convertedDevices);
setTotal(response.total || 0);
}
} catch (error) {
console.error("获取设备列表失败:", error);
Toast.show({
content: "获取设备列表失败,请检查网络连接",
position: "top",
});
} finally {
setLoading(false);
}
},
[]
);
// 打开弹窗时获取第一页
useEffect(() => {
if (open) {
setCurrentPage(1);
fetchDevices("", 1);
}
}, [open, fetchDevices]);
// 搜索防抖
useEffect(() => {
if (!open) return;
const timer = setTimeout(() => {
setCurrentPage(1);
fetchDevices(searchQuery, 1);
}, 500);
return () => clearTimeout(timer);
}, [searchQuery, open, fetchDevices]);
// 翻页时重新请求
useEffect(() => {
if (!open) return;
fetchDevices(searchQuery, currentPage);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentPage]);
// 过滤设备(只保留状态过滤)
const filteredDevices = devices.filter((device) => {
const matchesStatus =
statusFilter === "all" ||
(statusFilter === "online" && device.status === "online") ||
(statusFilter === "offline" && device.status === "offline");
return matchesStatus;
});
const handleDeviceSelect = (deviceId: string) => {
if (selectedDevices.includes(deviceId)) {
onSelect(selectedDevices.filter((id) => id !== deviceId));
} else {
onSelect([...selectedDevices, deviceId]);
}
};
const totalPages = Math.max(1, Math.ceil(total / pageSize));
return (
<Popup
visible={open}
onMaskClick={() => onOpenChange(false)}
position="bottom"
bodyStyle={{ height: "100vh" }}
>
<div className={style.popupContainer}>
<div className={style.popupHeader}>
<div className={style.popupTitle}></div>
</div>
<div className={style.popupSearchRow}>
<div className={style.popupSearchInputWrap}>
<SearchOutlined className={style.inputIcon} />
<Input
placeholder="搜索设备IMEI/备注"
value={searchQuery}
onChange={(val) => setSearchQuery(val)}
className={style.popupSearchInput}
/>
</div>
<select
value={statusFilter}
onChange={(e) => setStatusFilter(e.target.value)}
className={style.statusSelect}
>
<option value="all"></option>
<option value="online">线</option>
<option value="offline">线</option>
</select>
<Button
fill="outline"
size="mini"
onClick={() => fetchDevices(searchQuery, currentPage)}
disabled={loading}
className={style.refreshBtn}
>
{loading ? (
<div className={style.loadingIcon}></div>
) : (
<ReloadOutlined />
)}
</Button>
</div>
<div className={style.deviceList}>
{loading ? (
<div className={style.loadingBox}>
<div className={style.loadingText}>...</div>
</div>
) : filteredDevices.length === 0 ? (
<div className={style.emptyBox}>
<div className={style.emptyText}></div>
</div>
) : (
<div className={style.deviceListInner}>
{filteredDevices.map((device) => (
<label key={device.id} className={style.deviceItem}>
<Checkbox
checked={selectedDevices.includes(device.id)}
onChange={() => handleDeviceSelect(device.id)}
className={style.deviceCheckbox}
/>
<div className={style.deviceInfo}>
<div className={style.deviceInfoRow}>
<span className={style.deviceName}>{device.name}</span>
<div
className={
device.status === "online"
? style.statusOnline
: style.statusOffline
}
>
{device.status === "online" ? "在线" : "离线"}
</div>
</div>
<div className={style.deviceInfoDetail}>
<div>IMEI: {device.imei}</div>
<div>: {device.wxid || "-"} </div>
<div>: {device.nickname || "-"}</div>
</div>
{device.usedInPlans > 0 && (
<div className={style.usedInPlans}>
{device.usedInPlans}
</div>
)}
</div>
</label>
))}
</div>
)}
</div>
{/* 分页栏 */}
<div className={style.paginationRow}>
<div className={style.totalCount}> {total} </div>
<div className={style.paginationControls}>
<Button
fill="none"
size="mini"
onClick={() => setCurrentPage(Math.max(1, currentPage - 1))}
disabled={currentPage === 1 || loading}
className={style.pageBtn}
>
&lt;
</Button>
<span className={style.pageInfo}>
{currentPage} / {totalPages}
</span>
<Button
fill="none"
size="mini"
onClick={() =>
setCurrentPage(Math.min(totalPages, currentPage + 1))
}
disabled={currentPage === totalPages || loading}
className={style.pageBtn}
>
&gt;
</Button>
</div>
</div>
<div className={style.popupFooter}>
<div className={style.selectedCount}>
{selectedDevices.length}
</div>
<div className={style.footerBtnGroup}>
<Button fill="outline" onClick={() => onOpenChange(false)}>
</Button>
<Button color="primary" onClick={() => onOpenChange(false)}>
{selectedDevices.length > 0 ? ` (${selectedDevices.length})` : ""}
</Button>
</div>
</div>
</div>
</Popup>
);
}

View File

@@ -1,6 +1,5 @@
import React, { useState } from "react";
import DeviceSelection from "./DeviceSelection";
import { DeviceSelectionDialog } from "./DeviceSelectionDialog";
import FriendSelection from "./FriendSelection";
import GroupSelection from "./GroupSelection";
import { Button, Space } from "antd-mobile";
@@ -29,18 +28,6 @@ export default function SelectionTest() {
onSelect={setSelectedDevices}
/>
</div>
<div>
<b>DeviceSelectionDialog</b>
<Button color="primary" onClick={() => setDeviceDialogOpen(true)}>
</Button>
<DeviceSelectionDialog
open={deviceDialogOpen}
onOpenChange={setDeviceDialogOpen}
selectedDevices={selectedDevices}
onSelect={setSelectedDevices}
/>
</div>
<div>
<b>FriendSelection</b>
<Button color="primary" onClick={() => setFriendDialogOpen(true)}>

View File

@@ -1,423 +1,498 @@
import React, { useState, useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";
import {
PlusOutlined,
MinusOutlined,
ArrowLeftOutlined,
CheckOutlined,
} from "@ant-design/icons";
import { Button, Input, Switch, message, Spin } from "antd";
import { NavBar } from "antd-mobile";
import Layout from "@/components/Layout/Layout";
import {
createAutoLikeTask,
updateAutoLikeTask,
fetchAutoLikeTaskDetail,
} from "./api";
import {
CreateLikeTaskData,
ContentType,
} from "@/pages/workspace/auto-like/record/api";
import style from "./new.module.scss";
const contentTypeLabels: Record<ContentType, string> = {
text: "文字",
image: "图片",
video: "视频",
link: "链接",
};
const steps = [
{ title: "基础设置", desc: "设置点赞规则" },
{ title: "设备选择", desc: "选择执行设备" },
{ title: "好友设置", desc: "选择目标人群" },
];
const NewAutoLike: React.FC = () => {
const navigate = useNavigate();
const { id } = useParams<{ id: string }>();
const isEditMode = !!id;
const [currentStep, setCurrentStep] = useState(1);
const [isSubmitting, setIsSubmitting] = useState(false);
const [isLoading, setIsLoading] = useState(isEditMode);
const [autoEnabled, setAutoEnabled] = useState(false);
const [formData, setFormData] = useState<CreateLikeTaskData>({
name: "",
interval: 5,
maxLikes: 200,
startTime: "08:00",
endTime: "22:00",
contentTypes: ["text", "image", "video"],
devices: [],
friends: [],
targetTags: [],
friendMaxLikes: 10,
enableFriendTags: false,
friendTags: "",
});
useEffect(() => {
if (isEditMode && id) {
fetchTaskDetail();
}
}, [id, isEditMode]);
const fetchTaskDetail = async () => {
setIsLoading(true);
try {
const taskDetail = await fetchAutoLikeTaskDetail(id!);
if (taskDetail) {
const config = (taskDetail as any).config || taskDetail;
setFormData({
name: taskDetail.name || "",
interval: config.likeInterval || config.interval || 5,
maxLikes: config.maxLikesPerDay || config.maxLikes || 200,
startTime: config.timeRange?.start || config.startTime || "08:00",
endTime: config.timeRange?.end || config.endTime || "22:00",
contentTypes: config.contentTypes || ["text", "image", "video"],
devices: config.devices || [],
friends: config.friends || [],
targetTags: config.targetTags || [],
friendMaxLikes: config.friendMaxLikes || 10,
enableFriendTags: config.enableFriendTags || false,
friendTags: config.friendTags || "",
});
setAutoEnabled(
(taskDetail as any).status === 1 ||
(taskDetail as any).status === "running"
);
}
} catch (error) {
message.error("获取任务详情失败");
navigate("/workspace/auto-like");
} finally {
setIsLoading(false);
}
};
const handleUpdateFormData = (data: Partial<CreateLikeTaskData>) => {
setFormData((prev) => ({ ...prev, ...data }));
};
const handleNext = () => setCurrentStep((prev) => Math.min(prev + 1, 3));
const handlePrev = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
const handleComplete = async () => {
if (!formData.name.trim()) {
message.warning("请输入任务名称");
return;
}
if (!formData.devices || formData.devices.length === 0) {
message.warning("请选择执行设备");
return;
}
setIsSubmitting(true);
try {
if (isEditMode && id) {
await updateAutoLikeTask({ ...formData, id });
message.success("更新成功");
} else {
await createAutoLikeTask(formData);
message.success("创建成功");
}
navigate("/workspace/auto-like");
} catch (error) {
message.error(isEditMode ? "更新失败" : "创建失败");
} finally {
setIsSubmitting(false);
}
};
// 步骤器
const renderStepIndicator = () => (
<div className={style.stepIndicatorWrapper}>
<div className={style.stepIndicator}>
{steps.map((s, i) => (
<div
key={s.title}
className={
style.stepItem +
" " +
(currentStep === i + 1
? style.stepActive
: i + 1 < currentStep
? style.stepDone
: "")
}
>
<span className={style.stepNum}>
{i + 1 < currentStep ? <CheckOutlined /> : i + 1}
</span>
<span className={style.stepTitle}>{s.title}</span>
<span className={style.stepDesc}>{s.desc}</span>
</div>
))}
</div>
<div className={style.stepProgressBarBg}>
<div
className={style.stepProgressBar}
style={{
width: `${((currentStep - 1) / (steps.length - 1)) * 100}%`,
}}
></div>
</div>
</div>
);
// 步骤1基础设置
const renderBasicSettings = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请输入任务名称"
value={formData.name}
onChange={(e) => handleUpdateFormData({ name: e.target.value })}
className={style.input}
/>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.counterRow}>
<Button
icon={<MinusOutlined />}
onClick={() =>
handleUpdateFormData({
interval: Math.max(1, formData.interval - 1),
})
}
className={style.counterBtn}
/>
<span className={style.counterValue}>{formData.interval} </span>
<Button
icon={<PlusOutlined />}
onClick={() =>
handleUpdateFormData({ interval: formData.interval + 1 })
}
className={style.counterBtn}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.counterRow}>
<Button
icon={<MinusOutlined />}
onClick={() =>
handleUpdateFormData({
maxLikes: Math.max(1, formData.maxLikes - 10),
})
}
className={style.counterBtn}
/>
<span className={style.counterValue}>{formData.maxLikes} </span>
<Button
icon={<PlusOutlined />}
onClick={() =>
handleUpdateFormData({ maxLikes: formData.maxLikes + 10 })
}
className={style.counterBtn}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.timeRow}>
<Input
type="time"
value={formData.startTime}
onChange={(e) =>
handleUpdateFormData({ startTime: e.target.value })
}
className={style.inputTime}
/>
<span className={style.timeTo}></span>
<Input
type="time"
value={formData.endTime}
onChange={(e) => handleUpdateFormData({ endTime: e.target.value })}
className={style.inputTime}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.contentTypes}>
{(["text", "image", "video"] as ContentType[]).map((type) => (
<span
key={type}
className={
formData.contentTypes.includes(type)
? style.contentTypeTagActive
: style.contentTypeTag
}
onClick={() => {
const newTypes = formData.contentTypes.includes(type)
? formData.contentTypes.filter((t) => t !== type)
: [...formData.contentTypes, type];
handleUpdateFormData({ contentTypes: newTypes });
}}
>
{contentTypeLabels[type]}
</span>
))}
</div>
</div>
<div className={style.formItem}>
<div className={style.switchRow}>
<span className={style.switchLabel}></span>
<Switch
checked={formData.enableFriendTags}
onChange={(checked) =>
handleUpdateFormData({ enableFriendTags: checked })
}
className={style.switch}
/>
</div>
{formData.enableFriendTags && (
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请输入标签"
value={formData.friendTags}
onChange={(e) =>
handleUpdateFormData({ friendTags: e.target.value })
}
className={style.input}
/>
<div className={style.counterTip}></div>
</div>
)}
</div>
<div className={style.formItem}>
<div className={style.switchRow}>
<span className={style.switchLabel}></span>
<Switch
checked={autoEnabled}
onChange={setAutoEnabled}
className={style.switch}
/>
</div>
</div>
</div>
);
// 步骤2设备选择
const renderDeviceSelection = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请选择设备"
value={formData.devices.join(", ")}
readOnly
onClick={() => message.info("这里应弹出设备选择器")}
className={style.input}
/>
{formData.devices.length > 0 && (
<div className={style.selectedTip}>
: {formData.devices.length}
</div>
)}
</div>
</div>
);
// 步骤3好友设置
const renderFriendSettings = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请选择微信好友"
value={formData.friends.join(", ")}
readOnly
onClick={() => message.info("这里应弹出好友选择器")}
className={style.input}
/>
{formData.friends.length > 0 && (
<div className={style.selectedTip}>
: {formData.friends.length}
</div>
)}
</div>
</div>
);
// 底部按钮
const renderFooterBtn = () => (
<div className={style.footerBtnBar}>
{currentStep > 1 && (
<Button onClick={handlePrev} className={style.prevBtn}>
</Button>
)}
{currentStep < 3 && (
<Button
type="primary"
onClick={handleNext}
className={style.nextBtn}
disabled={
(currentStep === 1 && !formData.name.trim()) ||
(currentStep === 2 && formData.devices.length === 0)
}
>
</Button>
)}
{currentStep === 3 && (
<Button
type="primary"
onClick={handleComplete}
loading={isSubmitting}
className={style.completeBtn}
>
{isEditMode ? "更新任务" : "创建任务"}
</Button>
)}
</div>
);
return (
<Layout
header={
<>
<NavBar
back={null}
style={{ background: "#fff" }}
left={
<div className="nav-title">
<ArrowLeftOutlined
twoToneColor="#1677ff"
onClick={() => navigate(-1)}
/>
</div>
}
>
<span className="nav-title">
{isEditMode ? "编辑自动点赞" : "新建自动点赞"}
</span>
</NavBar>
{renderStepIndicator()}
</>
}
footer={renderFooterBtn()}
>
<div className={style.formBg}>
{isLoading ? (
<div className={style.formLoading}>
<Spin />
</div>
) : (
<>
{currentStep === 1 && renderBasicSettings()}
{currentStep === 2 && renderDeviceSelection()}
{currentStep === 3 && renderFriendSettings()}
</>
)}
</div>
</Layout>
);
};
export default NewAutoLike;
import React, { useState, useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";
import {
PlusOutlined,
MinusOutlined,
ArrowLeftOutlined,
CheckOutlined,
} from "@ant-design/icons";
import {
Button,
Input,
Switch,
Spin,
Modal,
Table,
Select,
message,
} from "antd";
import Layout from "@/components/Layout/Layout";
import {
createAutoLikeTask,
updateAutoLikeTask,
fetchAutoLikeTaskDetail,
} from "./api";
import {
CreateLikeTaskData,
ContentType,
} from "@/pages/workspace/auto-like/record/api";
import style from "./new.module.scss";
const contentTypeLabels: Record<ContentType, string> = {
text: "文字",
image: "图片",
video: "视频",
link: "链接",
};
const steps = [
{ title: "基础设置", desc: "设置点赞规则" },
{ title: "设备选择", desc: "选择执行设备" },
{ title: "好友设置", desc: "选择目标人群" },
];
// 假数据(实际应从接口获取)
const mockDevices = Array.from({ length: 10 }).map((_, i) => ({
key: String(i + 1),
name: `设备${i + 1}`,
id: `dev${i + 1}`,
}));
const mockFriends = Array.from({ length: 20 }).map((_, i) => ({
key: String(i + 1),
name: `好友${i + 1}`,
id: `friend${i + 1}`,
}));
const NewAutoLike: React.FC = () => {
const navigate = useNavigate();
const { id } = useParams<{ id: string }>();
const isEditMode = !!id;
const [currentStep, setCurrentStep] = useState(1);
const [isSubmitting, setIsSubmitting] = useState(false);
const [isLoading, setIsLoading] = useState(isEditMode);
const [autoEnabled, setAutoEnabled] = useState(false);
const [formData, setFormData] = useState<CreateLikeTaskData>({
name: "",
interval: 5,
maxLikes: 200,
startTime: "08:00",
endTime: "22:00",
contentTypes: ["text", "image", "video"],
devices: [],
friends: [],
targetTags: [],
friendMaxLikes: 10,
enableFriendTags: false,
friendTags: "",
});
// 设备/好友选择弹窗
const [deviceModalOpen, setDeviceModalOpen] = useState(false);
const [friendModalOpen, setFriendModalOpen] = useState(false);
const [selectedDeviceRowKeys, setSelectedDeviceRowKeys] = useState<string[]>(
[]
);
const [selectedFriendRowKeys, setSelectedFriendRowKeys] = useState<string[]>(
[]
);
useEffect(() => {
if (isEditMode && id) {
fetchTaskDetail();
}
}, [id, isEditMode]);
const fetchTaskDetail = async () => {
setIsLoading(true);
try {
const taskDetail = await fetchAutoLikeTaskDetail(id!);
if (taskDetail) {
const config = (taskDetail as any).config || taskDetail;
setFormData({
name: taskDetail.name || "",
interval: config.likeInterval || config.interval || 5,
maxLikes: config.maxLikesPerDay || config.maxLikes || 200,
startTime: config.timeRange?.start || config.startTime || "08:00",
endTime: config.timeRange?.end || config.endTime || "22:00",
contentTypes: config.contentTypes || ["text", "image", "video"],
devices: config.devices || [],
friends: config.friends || [],
targetTags: config.targetTags || [],
friendMaxLikes: config.friendMaxLikes || 10,
enableFriendTags: config.enableFriendTags || false,
friendTags: config.friendTags || "",
});
setAutoEnabled(
(taskDetail as any).status === 1 ||
(taskDetail as any).status === "running"
);
setSelectedDeviceRowKeys(config.devices || []);
setSelectedFriendRowKeys(config.friends || []);
}
} catch (error) {
message.error("获取任务详情失败");
navigate("/workspace/auto-like");
} finally {
setIsLoading(false);
}
};
const handleUpdateFormData = (data: Partial<CreateLikeTaskData>) => {
setFormData((prev) => ({ ...prev, ...data }));
};
const handleNext = () => setCurrentStep((prev) => Math.min(prev + 1, 3));
const handlePrev = () => setCurrentStep((prev) => Math.max(prev - 1, 1));
const handleComplete = async () => {
if (!formData.name.trim()) {
message.warning("请输入任务名称");
return;
}
if (!formData.devices || formData.devices.length === 0) {
message.warning("请选择执行设备");
return;
}
setIsSubmitting(true);
try {
if (isEditMode && id) {
await updateAutoLikeTask({ ...formData, id });
message.success("更新成功");
} else {
await createAutoLikeTask(formData);
message.success("创建成功");
}
navigate("/workspace/auto-like");
} catch (error) {
message.error(isEditMode ? "更新失败" : "创建失败");
} finally {
setIsSubmitting(false);
}
};
// 步骤器
const renderStepIndicator = () => (
<div className={style.stepIndicatorWrapper}>
<div className={style.stepIndicator}>
{steps.map((s, i) => (
<div
key={s.title}
className={
style.stepItem +
" " +
(currentStep === i + 1
? style.stepActive
: i + 1 < currentStep
? style.stepDone
: "")
}
>
<span className={style.stepNum}>
{i + 1 < currentStep ? <CheckOutlined /> : i + 1}
</span>
<span className={style.stepTitle}>{s.title}</span>
<span className={style.stepDesc}>{s.desc}</span>
</div>
))}
</div>
<div className={style.stepProgressBarBg}>
<div
className={style.stepProgressBar}
style={{
width: `${((currentStep - 1) / (steps.length - 1)) * 100}%`,
}}
></div>
</div>
</div>
);
// 步骤1基础设置
const renderBasicSettings = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请输入任务名称"
value={formData.name}
onChange={(e) => handleUpdateFormData({ name: e.target.value })}
className={style.input}
/>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.counterRow}>
<Button
icon={<MinusOutlined />}
onClick={() =>
handleUpdateFormData({
interval: Math.max(1, formData.interval - 1),
})
}
className={style.counterBtn}
/>
<span className={style.counterValue}>{formData.interval} </span>
<Button
icon={<PlusOutlined />}
onClick={() =>
handleUpdateFormData({ interval: formData.interval + 1 })
}
className={style.counterBtn}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.counterRow}>
<Button
icon={<MinusOutlined />}
onClick={() =>
handleUpdateFormData({
maxLikes: Math.max(1, formData.maxLikes - 10),
})
}
className={style.counterBtn}
/>
<span className={style.counterValue}>{formData.maxLikes} </span>
<Button
icon={<PlusOutlined />}
onClick={() =>
handleUpdateFormData({ maxLikes: formData.maxLikes + 10 })
}
className={style.counterBtn}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<div className={style.timeRow}>
<Input
type="time"
value={formData.startTime}
onChange={(e) =>
handleUpdateFormData({ startTime: e.target.value })
}
className={style.inputTime}
/>
<span className={style.timeTo}></span>
<Input
type="time"
value={formData.endTime}
onChange={(e) => handleUpdateFormData({ endTime: e.target.value })}
className={style.inputTime}
/>
</div>
</div>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Select
mode="multiple"
style={{ width: "100%" }}
placeholder="请选择内容类型"
value={formData.contentTypes}
onChange={(value) => handleUpdateFormData({ contentTypes: value })}
>
{(["text", "image", "video"] as ContentType[]).map((type) => (
<Select.Option key={type} value={type}>
{contentTypeLabels[type]}
</Select.Option>
))}
</Select>
</div>
<div className={style.formItem}>
<div className={style.switchRow}>
<span className={style.switchLabel}></span>
<Switch
checked={formData.enableFriendTags}
onChange={(checked) =>
handleUpdateFormData({ enableFriendTags: checked })
}
className={style.switch}
/>
</div>
{formData.enableFriendTags && (
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Input
placeholder="请输入标签"
value={formData.friendTags}
onChange={(e) =>
handleUpdateFormData({ friendTags: e.target.value })
}
className={style.input}
/>
<div className={style.counterTip}></div>
</div>
)}
</div>
<div className={style.formItem}>
<div className={style.switchRow}>
<span className={style.switchLabel}></span>
<Switch
checked={autoEnabled}
onChange={setAutoEnabled}
className={style.switch}
/>
</div>
</div>
</div>
);
// 步骤2设备选择
const renderDeviceSelection = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Button
type="dashed"
onClick={() => setDeviceModalOpen(true)}
style={{ width: "100%", marginBottom: 12 }}
>
</Button>
<div>
{formData.devices.length > 0
? `已选设备: ${formData.devices.length}`
: "未选择设备"}
</div>
</div>
<Modal
title="选择设备"
open={deviceModalOpen}
onCancel={() => setDeviceModalOpen(false)}
onOk={() => {
handleUpdateFormData({ devices: selectedDeviceRowKeys });
setDeviceModalOpen(false);
}}
okText="确定"
cancelText="取消"
width={520}
>
<Table
rowSelection={{
type: "checkbox",
selectedRowKeys: selectedDeviceRowKeys,
onChange: (keys) => setSelectedDeviceRowKeys(keys as string[]),
}}
columns={[
{ title: "设备名称", dataIndex: "name", key: "name" },
{ title: "ID", dataIndex: "id", key: "id" },
]}
dataSource={mockDevices}
pagination={false}
rowKey="id"
size="small"
/>
</Modal>
</div>
);
// 步骤3好友设置
const renderFriendSettings = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<div className={style.formLabel}></div>
<Button
type="dashed"
onClick={() => setFriendModalOpen(true)}
style={{ width: "100%", marginBottom: 12 }}
>
</Button>
<div>
{formData.friends.length > 0
? `已选好友: ${formData.friends.length}`
: "未选择好友"}
</div>
</div>
<Modal
title="选择微信好友"
open={friendModalOpen}
onCancel={() => setFriendModalOpen(false)}
onOk={() => {
handleUpdateFormData({ friends: selectedFriendRowKeys });
setFriendModalOpen(false);
}}
okText="确定"
cancelText="取消"
width={520}
>
<Table
rowSelection={{
type: "checkbox",
selectedRowKeys: selectedFriendRowKeys,
onChange: (keys) => setSelectedFriendRowKeys(keys as string[]),
}}
columns={[
{ title: "好友昵称", dataIndex: "name", key: "name" },
{ title: "ID", dataIndex: "id", key: "id" },
]}
dataSource={mockFriends}
pagination={false}
rowKey="id"
size="small"
/>
</Modal>
</div>
);
// 底部按钮
const renderFooterBtn = () => (
<div className={style.footerBtnBar}>
{currentStep > 1 && (
<Button onClick={handlePrev} className={style.prevBtn}>
</Button>
)}
{currentStep < 3 && (
<Button
type="primary"
onClick={handleNext}
className={style.nextBtn}
disabled={
(currentStep === 1 && !formData.name.trim()) ||
(currentStep === 2 && formData.devices.length === 0)
}
>
</Button>
)}
{currentStep === 3 && (
<Button
type="primary"
onClick={handleComplete}
loading={isSubmitting}
className={style.completeBtn}
>
{isEditMode ? "更新任务" : "创建任务"}
</Button>
)}
</div>
);
return (
<Layout
header={
<>
<div className={style.headerBar}>
<Button
type="text"
icon={<ArrowLeftOutlined />}
onClick={() => navigate(-1)}
className={style.backBtn}
/>
<span className={style.title}>
{isEditMode ? "编辑自动点赞" : "新建自动点赞"}
</span>
</div>
{renderStepIndicator()}
</>
}
footer={renderFooterBtn()}
>
<div className={style.formBg}>
{isLoading ? (
<div className={style.formLoading}>
<Spin />
</div>
) : (
<>
{currentStep === 1 && renderBasicSettings()}
{currentStep === 2 && renderDeviceSelection()}
{currentStep === 3 && renderFriendSettings()}
</>
)}
</div>
</Layout>
);
};
export default NewAutoLike;