自动点赞功能优化

This commit is contained in:
wong
2025-12-04 11:10:55 +08:00
parent 58377b4670
commit b9b1877e04
5 changed files with 170 additions and 38 deletions

View File

@@ -95,9 +95,9 @@ export default function FriendSelection({
{(selectedOptions || []).map(friend => (
<div key={friend.id} className={style.selectedListRow}>
<div className={style.selectedListRowContent}>
<Avatar src={friend.avatar} />
<Avatar src={friend.friendAvatar} />
<div className={style.selectedListRowContentText}>
<div>{friend.nickname}</div>
<div>{friend.friendName}</div>
<div>{friend.wechatId}</div>
</div>
{!readonly && (

View File

@@ -116,20 +116,38 @@ const AutoLike: React.FC = () => {
setLoading(true);
try {
const Res: any = await fetchAutoLikeTasks();
// 直接就是任务数组,无需再解包
const mappedTasks = Res?.list?.map((task: any) => ({
...task,
status: task.status || 2, // 默认为关闭状态
deviceCount: task.deviceCount || 0,
targetGroup: task.targetGroup || "全部好友",
likeInterval: task.likeInterval || 60,
maxLikesPerDay: task.maxLikesPerDay || 100,
lastLikeTime: task.lastLikeTime || "暂无",
createTime: task.createTime || "",
updateTime: task.updateTime || "",
todayLikeCount: task.todayLikeCount || 0,
totalLikeCount: task.totalLikeCount || 0,
}));
// 数据在 data.list 中
const taskList = Res?.data?.list || Res?.list || [];
const mappedTasks = taskList.map((task: any) => {
const config = task.config || {};
const friends = config.friends || [];
const devices = config.devices || [];
// 判断目标人群:如果 friends 为空或未设置,表示选择全部好友
let targetGroup = "全部好友";
if (friends.length > 0) {
targetGroup = `${friends.length} 个好友`;
}
return {
id: task.id?.toString() || "",
name: task.name || "",
status: task.status === 1 ? 1 : 2, // 1: 开启, 2: 关闭
deviceCount: devices.length,
targetGroup: targetGroup,
likeInterval: config.interval || 60,
maxLikesPerDay: config.maxLikes || 100,
lastLikeTime: task.lastLikeTime || "暂无",
createTime: task.createTime || "",
updateTime: task.updateTime || "",
todayLikeCount: config.todayLikeCount || 0,
totalLikeCount: config.totalLikeCount || 0,
// 保留原始数据
config: config,
devices: devices,
friends: friends,
};
});
setTasks(mappedTasks);
} catch (error) {
console.error("获取自动点赞任务失败:", error);
@@ -355,7 +373,7 @@ const AutoLike: React.FC = () => {
/>
<span className={style["stats-label"]}></span>
<span className={style["stats-value"]}>
{task.lastLikeTime}
{task.todayLikeCount || 0}
</span>
</div>
<div className={style["stats-item"]}>

View File

@@ -36,6 +36,7 @@ const NewAutoLike: React.FC = () => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [isLoading, setIsLoading] = useState(isEditMode);
const [autoEnabled, setAutoEnabled] = useState(false);
const [selectAllFriends, setSelectAllFriends] = useState(false);
const [formData, setFormData] = useState<CreateLikeTaskData>({
name: "",
interval: 5,
@@ -45,8 +46,8 @@ const NewAutoLike: React.FC = () => {
contentTypes: ["text", "image", "video"],
deviceGroups: [],
deviceGroupsOptions: [],
friendsGroups: [],
friendsGroupsOptions: [],
wechatFriends: [],
wechatFriendsOptions: [],
targetTags: [],
friendMaxLikes: 10,
enableFriendTags: false,
@@ -74,8 +75,8 @@ const NewAutoLike: React.FC = () => {
contentTypes: config.contentTypes || ["text", "image", "video"],
deviceGroups: config.deviceGroups || [],
deviceGroupsOptions: config.deviceGroupsOptions || [],
friendsGroups: config.friendsgroups || [],
friendsGroupsOptions: config.friendsGroupsOptions || [],
wechatFriends: config.wechatFriends || [],
wechatFriendsOptions: config.wechatFriendsOptions || [],
targetTags: config.targetTags || [],
friendMaxLikes: config.friendMaxLikes || 10,
enableFriendTags: config.enableFriendTags || false,
@@ -85,6 +86,10 @@ const NewAutoLike: React.FC = () => {
(taskDetail as any).status === 1 ||
(taskDetail as any).status === "running",
);
// 如果 wechatFriends 为空或未设置,可能表示选择了全部好友
setSelectAllFriends(
!config.wechatFriends || config.wechatFriends.length === 0
);
}
} catch (error) {
message.error("获取任务详情失败");
@@ -127,11 +132,19 @@ const NewAutoLike: React.FC = () => {
}
setIsSubmitting(true);
try {
// 如果选择了全部好友,提交时传空数组或特殊标识
const submitData = {
...formData,
wechatFriends: selectAllFriends ? [] : formData.wechatFriends,
wechatFriendsOptions: selectAllFriends ? [] : formData.wechatFriendsOptions,
selectAllFriends: selectAllFriends, // 添加标识字段
};
if (isEditMode) {
await updateAutoLikeTask({ ...formData, id });
await updateAutoLikeTask({ ...submitData, id });
message.success("更新成功");
} else {
await createAutoLikeTask(formData);
await createAutoLikeTask(submitData);
message.success("创建成功");
}
navigate("/workspace/auto-like");
@@ -142,6 +155,28 @@ const NewAutoLike: React.FC = () => {
}
};
// 选择全部好友(仅设置标识)
const handleSelectAllFriends = () => {
if (!formData.deviceGroups || formData.deviceGroups.length === 0) {
message.warning("请先选择执行设备");
return;
}
if (selectAllFriends) {
// 取消全选标识
setSelectAllFriends(false);
// 清空已选好友
handleUpdateFormData({
wechatFriends: [],
wechatFriendsOptions: [],
});
} else {
// 设置全选标识
setSelectAllFriends(true);
message.success("已标记为选择全部好友");
}
};
// 步骤器
const renderStepIndicator = () => (
<StepIndicator steps={steps} currentStep={currentStep} />
@@ -364,16 +399,39 @@ const NewAutoLike: React.FC = () => {
const renderFriendSettings = () => (
<div className={style.basicSection}>
<div className={style.formItem}>
<FriendSelection
selectedOptions={formData.friendsGroupsOptions || []}
onSelect={friends =>
handleUpdateFormData({
friendsGroups: friends.map(f => f.id),
friendsGroupsOptions: friends,
})
}
deviceIds={formData.deviceGroups}
/>
<div className={style.friendSelectionHeader}>
<div className={style.formLabel}></div>
<Button
type={selectAllFriends ? "primary" : "default"}
size="small"
onClick={handleSelectAllFriends}
disabled={!formData.deviceGroups || formData.deviceGroups.length === 0}
className={style.selectAllBtn}
>
{selectAllFriends ? "已选择全部" : "选择全部好友"}
</Button>
</div>
{selectAllFriends ? (
<div className={style.selectAllTip}>
<span className={style.selectAllIcon}></span>
</div>
) : (
<FriendSelection
selectedOptions={formData.wechatFriendsOptions || []}
onSelect={friends => {
handleUpdateFormData({
wechatFriends: friends.map(f => f.id),
wechatFriendsOptions: friends,
});
// 如果手动选择了好友,取消全选标识
if (selectAllFriends) {
setSelectAllFriends(false);
}
}}
deviceIds={formData.deviceGroups}
/>
)}
</div>
<Button
onClick={handlePrev}
@@ -390,7 +448,8 @@ const NewAutoLike: React.FC = () => {
size="large"
loading={isSubmitting}
disabled={
!formData.friendsGroups || formData.friendsGroups.length === 0
!selectAllFriends &&
(!formData.wechatFriends || formData.wechatFriends.length === 0)
}
>
{isEditMode ? "更新任务" : "创建任务"}

View File

@@ -126,6 +126,13 @@
gap: 8px;
}
.contentTypeBtn {
flex: 1;
height: 40px;
border-radius: 8px;
font-size: 14px;
}
.contentTypeTag {
padding: 8px 16px;
border-radius: 6px;
@@ -230,3 +237,50 @@
font-size: 15px;
min-width: 120px;
}
.friendSelectionHeader {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.selectAllBtn {
height: 32px;
border-radius: 6px;
font-size: 14px;
padding: 0 16px;
}
.selectAllTip {
display: flex;
align-items: center;
gap: 8px;
padding: 12px 16px;
background: #f0f9ff;
border: 1px solid #91d5ff;
border-radius: 8px;
color: #1890ff;
font-size: 14px;
margin-top: 8px;
}
.selectAllIcon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
background: #1890ff;
color: #fff;
border-radius: 50%;
font-size: 12px;
font-weight: bold;
}
.mainBtn {
height: 44px;
border-radius: 8px;
font-size: 15px;
margin-top: 24px;
}

View File

@@ -93,7 +93,7 @@ class WorkbenchController extends Controller
$config->endTime = $param['endTime'];
$config->contentTypes = json_encode($param['contentTypes']);
$config->devices = json_encode($param['deviceGroups']);
$config->friends = json_encode($param['friendsGroups']);
$config->friends = json_encode($param['wechatFriends']);
// $config->targetGroups = json_encode($param['targetGroups']);
// $config->tagOperator = $param['tagOperator'];
$config->friendMaxLikes = $param['friendMaxLikes'];
@@ -490,7 +490,8 @@ class WorkbenchController extends Controller
if (!empty($workbench->autoLike)) {
$workbench->config = $workbench->autoLike;
$workbench->config->deviceGroups = json_decode($workbench->config->devices, true);
$workbench->config->friendsGroups = json_decode($workbench->config->friends, true);
$workbench->config->wechatFriends = json_decode($workbench->config->friends, true);
$workbench->config->targetType = 2;
//$workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true);
$workbench->config->contentTypes = json_decode($workbench->config->contentTypes, true);
@@ -689,7 +690,7 @@ class WorkbenchController extends Controller
// 获取好友当targetType=2时
if (!empty($workbench->config->wechatFriends) && isset($workbench->config->targetType) && $workbench->config->targetType == 2) {
$friendList = Db::table('s2_wechat_friend')->alias('wf')
->join('s2_wechat_account wa', 'wa.id = wf.wechatAccountId', 'left')
->join(['s2_wechat_account' => 'wa'], 'wa.id = wf.wechatAccountId', 'left')
->where('wf.id', 'in', $workbench->config->wechatFriends)
->order('wf.id', 'desc')
->field('wf.id,wf.wechatId,wf.nickname as friendName,wf.avatar as friendAvatar,wf.conRemark,wf.ownerWechatId,wa.nickName as accountName,wa.avatar as accountAvatar')
@@ -819,7 +820,7 @@ class WorkbenchController extends Controller
$config->endTime = $param['endTime'];
$config->contentTypes = json_encode($param['contentTypes']);
$config->devices = json_encode($param['deviceGroups']);
$config->friends = json_encode($param['friendsGroups']);
$config->friends = json_encode($param['wechatFriends']);
// $config->targetGroups = json_encode($param['targetGroups']);
// $config->tagOperator = $param['tagOperator'];
$config->friendMaxLikes = $param['friendMaxLikes'];