Skip to content

Let's use AI to Earn!

互动任务问题

daoyian55417cdec7e5
diff --git a/src/views/replyother/replyother.tsx b/src/views/replyother/replyother.tsx
index 04b132f6..fa4ddd24 100644
--- a/src/views/replyother/replyother.tsx
+++ b/src/views/replyother/replyother.tsx
@@ -319,49 +319,6 @@ export default function Page() {
);
console.log('------ res', res);
- // // 创建任务队列
- // const taskQueue = selectedPosts.map(postId => {
- // const post = postList.find(item => item.dataId === postId);
- // if (!post) return null;
-
- // return async () => {
- // try {
- // // 根据概率决定是否执行点赞
- // // if (Math.random() * 100 <= values.likeProb) {
- // await likePost(post);
- // // }
-
- // // 根据概率决定是否执行收藏
- // if(activeAccountType != 'KWAI'){
- // if (Math.random() * 100 <= values.collectProb) {
- // await collectPost(post);
- // }
- // }
-
- // // // 根据概率决定是否执行评论
- // // if (Math.random() * 100 <= values.commentProb) {
- // // if (values.commentType === 'ai') {
- // // // AI评论逻辑
- // // await openReplyWorks(post);
- // // } else {
- // // // 自定义评论逻辑
- // // const randomComment = customComments[Math.floor(Math.random() * customComments.length)];
- // // // TODO: 实现自定义评论发送逻辑
- // // }
- // // }
- // } catch (error) {
- // console.error('执行任务失败:', error);
- // }
- // };
- // }).filter(Boolean);
-
- // // 按顺序执行任务,每个任务间隔3秒
- // for (const task of taskQueue) {
- // if (task) {
- // await task();
- // await new Promise(resolve => setTimeout(resolve, 3000)); // 等待3秒
- // }
- // }
setSelectedPosts([]);
};
diff --git a/src/views/task/interactionTask.tsx b/src/views/task/interactionTask.tsx
index e58dc3d1..5bd70fef 100644
--- a/src/views/task/interactionTask.tsx
+++ b/src/views/task/interactionTask.tsx
@@ -5,83 +5,315 @@
* @LastEditors: nevin
* @Description: 互动任务组件
*/
-import { Card, List, Typography, Button, Space, Tag } from 'antd';
-import { CommentOutlined, LikeOutlined, ShareAltOutlined } from '@ant-design/icons';
+import { Card, List, Typography, Button, Space, Tag, Spin, Modal, Descriptions, message, Progress } from 'antd';
+import { CommentOutlined, LikeOutlined, ShareAltOutlined, UserOutlined, ClockCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
import styles from './task.module.scss';
+import { useState, useEffect, useRef } from 'react';
+import { taskApi } from '@/api/task';
+import { TaskType } from '@@/types/task';
+import dayjs from 'dayjs';
+import { TaskInfoRef } from './components/popInfo';
+import ChooseAccountModule from '@/views/publish/components/ChooseAccountModule/ChooseAccountModule';
+import { PubType } from '@@/publish/PublishEnum';
+import { icpCreateInteractionOneKey } from '@/icp/replyother';
+import { useAccountStore } from '@/store/commont';
+import { useNavigate } from 'react-router-dom';
+
+// 导入平台图标
+import KwaiIcon from '@/assets/svgs/account/ks.svg';
+import WxSphIcon from '@/assets/svgs/account/wx-sph.svg';
+import XhsIcon from '@/assets/svgs/account/xhs.svg';
+import DouyinIcon from '@/assets/svgs/account/douyin.svg';
const { Title, Text } = Typography;
+const FILE_BASE_URL = import.meta.env.VITE_APP_FILE_HOST;
+
+// 平台配置
+const platformConfig = {
+ KWAI: {
+ name: '快手',
+ icon: KwaiIcon,
+ color: '#FF4D4F'
+ },
+ wxSph: {
+ name: '微信视频号',
+ icon: WxSphIcon,
+ color: '#07C160'
+ },
+ xhs: {
+ name: '小红书',
+ icon: XhsIcon,
+ color: '#FF2442'
+ },
+ douyin: {
+ name: '抖音',
+ icon: DouyinIcon,
+ color: '#000000'
+ }
+};
+
export default function InteractionTask() {
- // 模拟互动任务数据
- const interactionTasks = [
- {
- id: '1',
- title: '评论互动任务',
- content: '对指定文章进行有意义的评论和互动...',
- price: 30,
- comments: 500,
- shares: 200,
- level: '初级',
- },
- {
- id: '2',
- title: '点赞分享任务',
- content: '对指定内容进行点赞和分享...',
- price: 20,
- comments: 300,
- shares: 150,
- level: '初级',
- },
- ];
+ const [loading, setLoading] = useState(false);
+ const [taskList, setTaskList] = useState<any[]>([]);
+ const [pageInfo, setPageInfo] = useState({
+ pageNo: 1,
+ pageSize: 10,
+ totalCount: 0,
+ });
+ const [hasMore, setHasMore] = useState(true);
+ const [selectedTask, setSelectedTask] = useState<any>(null);
+ const [modalVisible, setModalVisible] = useState(false);
+ const [chooseAccountOpen, setChooseAccountOpen] = useState(false);
+ const [accountListChoose, setAccountListChoose] = useState<any[]>([]);
+ const [downloading, setDownloading] = useState(false);
+ const navigate = useNavigate();
+
+ const Ref_TaskInfo = useRef<TaskInfoRef>(null);
+
+ async function getTaskList(isLoadMore = false) {
+ setLoading(true);
+ try {
+ const res = await taskApi.getTaskList<any>({
+ ...pageInfo,
+ type: TaskType.INTERACTION,
+ });
+
+ if (isLoadMore) {
+ setTaskList((prev) => [...prev, ...res.items]);
+ } else {
+ setTaskList(res.items);
+ }
+
+ setPageInfo((prev) => ({
+ ...prev,
+ totalCount: (res as any).totalCount,
+ }));
+
+ setHasMore(pageInfo.pageNo * pageInfo.pageSize < (res as any).totalCount);
+ } catch (error) {
+ console.error('获取任务列表失败', error);
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ useEffect(() => {
+ getTaskList();
+ }, []);
+
+ const formatDate = (date: string) => {
+ return dayjs(date).format('YYYY-MM-DD HH:mm');
+ };
+
+ const getPlatformTags = (accountTypes: string[]) => {
+ return accountTypes.map(type => {
+ const platform = platformConfig[type as keyof typeof platformConfig];
+ if (!platform) return null;
+
+ return (
+ <div
+ key={type}
+ className={styles.platformIconWrapper}
+ style={{ backgroundColor: platform.color }}
+ >
+ <img
+ src={platform.icon}
+ className={styles.platformIcon}
+ alt={platform.name}
+ />
+ </div>
+ );
+ });
+ };
+
+ const handleJoinTask = (task: any) => {
+ setSelectedTask(task);
+ setModalVisible(true);
+ };
+
+ const handleCompleteTask = async () => {
+ if (!selectedTask) return;
+ setModalVisible(false);
+ setChooseAccountOpen(true);
+ };
+
+ const handleInteraction = async (account: any) => {
+ try {
+ setLoading(true);
+ const res:any = await icpCreateInteractionOneKey(
+ account.id,
+ selectedTask.dataInfo,
+ {
+ commentContent: selectedTask.description,
+ platform: account.type,
+ }
+ );
+
+ if (res.code === 1) {
+ message.success('互动任务完成成功');
+ // 更新任务状态
+ setTaskList(prev => prev.map(task =>
+ task._id === selectedTask._id ? { ...task, isAccepted: true } : task
+ ));
+ } else {
+ message.error('互动任务完成失败');
+ }
+ } catch (error) {
+ console.error('互动任务失败', error);
+ message.error('互动任务失败,请重试');
+ } finally {
+ setLoading(false);
+ setChooseAccountOpen(false);
+ }
+ };
+
+ // 刷新任务列表的函数
+ const refreshTaskList = () => {
+ setPageInfo({
+ pageSize: 10,
+ pageNo: 1,
+ totalCount: 0,
+ });
+ getTaskList();
+ };
return (
<div className={styles.taskList}>
- <List
- grid={{ gutter: 16, column: 3 }}
- dataSource={interactionTasks}
- renderItem={(item) => (
- <List.Item>
- <Card
- className={styles.taskCard}
- cover={
- <div className={styles.taskImage}>
- <CommentOutlined style={{ fontSize: '48px', color: '#52c41a' }} />
- </div>
- }
- actions={[
- <Space key="comments">
- <CommentOutlined />
- <Text>{item.comments}</Text>
- </Space>,
- <Space key="shares">
- <ShareAltOutlined />
- <Text>{item.shares}</Text>
- </Space>,
- <Button type="primary" key="join">
- 参与任务
- </Button>,
- ]}
- >
- <Card.Meta
- title={
- <div className={styles.taskTitle}>
- <Title level={5}>{item.title}</Title>
- <Tag color="green">{item.level}</Tag>
+ <ChooseAccountModule
+ open={chooseAccountOpen}
+ onClose={() => !downloading && setChooseAccountOpen(false)}
+ platChooseProps={{
+ choosedAccounts: accountListChoose,
+ pubType: PubType.VIDEO,
+ allowPlatSet: new Set(selectedTask?.accountTypes || []) as any,
+ }}
+ onPlatConfirm={async (aList) => {
+ console.log('账号:', aList);
+ setAccountListChoose(aList);
+ setChooseAccountOpen(false);
+ await handleInteraction(aList[0]);
+ }}
+ />
+
+ <Spin spinning={loading}>
+ <List
+ grid={{
+ gutter: 8,
+ xs: 1,
+ sm: 2,
+ md: 3,
+ lg: 4,
+ xl: 5,
+ xxl: 6
+ }}
+ dataSource={taskList}
+ renderItem={(item) => (
+ <List.Item>
+ <Card
+ className={styles.taskCard}
+ cover={
+ <div className={styles.taskImage}>
+ <CommentOutlined style={{ fontSize: '48px', color: '#52c41a' }} />
</div>
}
- description={
- <div className={styles.taskInfo}>
- <Text type="secondary">{item.content}</Text>
- <div className={styles.taskPrice}>
- <Text strong>¥{item.price}</Text>
+ actions={[
+ <Space key="recruits">
+ <UserOutlined />
+ <Text>{item.currentRecruits}/{item.maxRecruits}</Text>
+ </Space>,
+ <Space key="time">
+ <ClockCircleOutlined />
+ <Text>{item.keepTime}分钟</Text>
+ </Space>,
+ <Button
+ type="primary"
+ key="join"
+ disabled={item.isAccepted}
+ onClick={() => handleJoinTask(item)}
+ >
+ {item.isAccepted ? '已参与' : '参与任务'}
+ </Button>,
+ ]}
+ >
+ <Card.Meta
+ title={
+ <div className={styles.taskTitle}>
+ <Title level={5}>{item.title}</Title>
+ <Space>
+ <Tag color="green">¥{item.reward}</Tag>
+ <Space size={4}>
+ {getPlatformTags(item.accountTypes)}
+ </Space>
+ </Space>
</div>
- </div>
- }
- />
- </Card>
- </List.Item>
+ }
+ description={
+ <div className={styles.taskInfo}>
+ <div className={styles.taskProgress}>
+ <Progress
+ percent={Math.round((item.currentRecruits / item.maxRecruits) * 100)}
+ size="small"
+ showInfo={false}
+ />
+ </div>
+ <Text type="secondary">
+ {item.description.replace(/<[^>]+>/g, '')}
+ </Text>
+ <div className={styles.taskDeadline}>
+ <Text type="secondary">截止时间:{formatDate(item.deadline)}</Text>
+ </div>
+ </div>
+ }
+ />
+ </Card>
+ </List.Item>
+ )}
+ />
+ </Spin>
+
+ <Modal
+ title="任务详情"
+ open={modalVisible}
+ onCancel={() => setModalVisible(false)}
+ footer={[
+ <Button key="cancel" onClick={() => setModalVisible(false)}>
+ 取消
+ </Button>,
+ <Button
+ key="complete"
+ type="primary"
+ icon={<CheckCircleOutlined />}
+ onClick={handleCompleteTask}
+ >
+ 一键完成
+ </Button>
+ ]}
+ width={600}
+ >
+ {selectedTask && (
+ <div className={styles.taskDetail}>
+ <Descriptions column={1}>
+ <Descriptions.Item label="任务标题">{selectedTask.title}</Descriptions.Item>
+ <Descriptions.Item label="任务描述">
+ <div dangerouslySetInnerHTML={{ __html: selectedTask.description }} />
+ </Descriptions.Item>
+ <Descriptions.Item label="任务奖励">¥{selectedTask.reward}</Descriptions.Item>
+ <Descriptions.Item label="任务时长">{selectedTask.keepTime}分钟</Descriptions.Item>
+ <Descriptions.Item label="开始时间">{formatDate(selectedTask.createTime)}</Descriptions.Item>
+ <Descriptions.Item label="截止时间">{formatDate(selectedTask.deadline)}</Descriptions.Item>
+ <Descriptions.Item label="参与人数">
+ {selectedTask.currentRecruits}/{selectedTask.maxRecruits}
+ </Descriptions.Item>
+ <Descriptions.Item label="支持平台">
+ <Space size={4}>
+ {getPlatformTags(selectedTask.accountTypes)}
+ </Space>
+ </Descriptions.Item>
+ </Descriptions>
+ </div>
)}
- />
+ </Modal>
</div>
);
}
\ No newline at end of file