Skip to content

Let's use AI to Earn!

111

daoyiana4c88a34b8ab
diff --git a/src/api/notification.ts b/src/api/notification.ts
index 63c84c82..f80f742e 100644
--- a/src/api/notification.ts
+++ b/src/api/notification.ts
@@ -39,7 +39,7 @@ export const getNotificationList = (params: {
// 获取通知详情
export const getNotificationDetail = (id: string) => {
- return http.get<NotificationDetailResponse>(`notification/${id}`);
+ return http.get(`notification/${id}`);
};
// 标记通知为已读
@@ -60,4 +60,46 @@ export const getUnreadCount = () => {
// 删除通知
export const deleteNotifications = (notificationIds: string[]) => {
return http.delete("notification", { notificationIds } );
+};
+
+// 任务相关类型定义
+export interface TaskData {
+ targetWorksId: string;
+ targetAuthorId: string;
+ platform: string;
+}
+
+export interface TaskItem {
+ id: string;
+ title: string;
+ description: string;
+ type: string;
+ maxRecruits: number;
+ currentRecruits: number;
+ deadline: string;
+ reward: number;
+ status: string;
+ accountTypes: string[];
+ taskData: TaskData;
+ materials: string[];
+ createdAt: string;
+ updatedAt: string;
+ opportunityId: string;
+ opportunityStatus: string;
+ expiredAt: string;
+ accountId: string;
+}
+
+export interface TaskResponse {
+ data: TaskItem;
+}
+
+// 获取任务详情
+export const getTaskDetail = (opportunityId: string) => {
+ return http.get<TaskResponse>(`task/opportunity/${opportunityId}`);
+};
+
+// 接受任务
+export const acceptTask = (taskId: string, opportunityId: string) => {
+ return http.post("task/accept", { taskId, opportunityId });
};
\ No newline at end of file
diff --git a/src/components/notification/NotificationPanel.module.scss b/src/components/notification/NotificationPanel.module.scss
index d5d481b9..586fff7d 100644
--- a/src/components/notification/NotificationPanel.module.scss
+++ b/src/components/notification/NotificationPanel.module.scss
@@ -99,4 +99,59 @@
border: 1px solid #f0f0f0;
font-size: 15px;
}
+}
+
+.taskDetail {
+ margin-top: 24px;
+ padding-top: 24px;
+ border-top: 1px solid #f0f0f0;
+}
+
+.taskInfo {
+ background: #f8f9fa;
+ border-radius: 8px;
+ padding: 16px;
+ border: 1px solid #e9ecef;
+}
+
+.taskHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 16px;
+ padding-bottom: 12px;
+ border-bottom: 1px solid #e9ecef;
+
+ h5 {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: #262626;
+ }
+}
+
+.taskContent {
+ p {
+ margin-bottom: 8px;
+ line-height: 1.6;
+ color: #595959;
+
+ strong {
+ color: #262626;
+ margin-right: 8px;
+ }
+ }
+
+ div {
+ margin-bottom: 8px;
+ line-height: 1.6;
+ color: #595959;
+ }
+}
+
+.taskActions {
+ margin-top: 16px;
+ padding-top: 16px;
+ border-top: 1px solid #e9ecef;
+ text-align: center;
}
\ No newline at end of file
diff --git a/src/components/notification/NotificationPanel.tsx b/src/components/notification/NotificationPanel.tsx
index 9e6511d1..a45ea890 100644
--- a/src/components/notification/NotificationPanel.tsx
+++ b/src/components/notification/NotificationPanel.tsx
@@ -12,8 +12,13 @@ import {
markAllNotificationsAsRead,
getUnreadCount,
deleteNotifications,
- type NotificationItem
+ getTaskDetail,
+ acceptTask,
+ type NotificationItem,
+ type TaskItem
} from "@/api/notification";
+import { getOssUrl } from "@/utils/oss";
+import { PubType } from "@/app/config/publishConfig";
import styles from "./NotificationPanel.module.scss";
interface NotificationPanelProps {
@@ -28,7 +33,9 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
const [loading, setLoading] = useState(false);
const [unreadCount, setUnreadCount] = useState(0);
const [selectedNotification, setSelectedNotification] = useState<NotificationItem | null>(null);
+ const [selectedTask, setSelectedTask] = useState<TaskItem | null>(null);
const [detailModalVisible, setDetailModalVisible] = useState(false);
+ const [taskLoading, setTaskLoading] = useState(false);
// 获取通知列表
const fetchNotifications = async () => {
@@ -97,11 +104,16 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
const handleViewDetail = async (notification: NotificationItem) => {
try {
// 调用API获取通知详情
- const response = await getNotificationDetail(notification.id);
- if (response && response.data && response.data.data) {
- setSelectedNotification(response.data.data);
+ const response:any = await getNotificationDetail(notification.id);
+ if (response && response.data && response.code == 0) {
+ setSelectedNotification(response.data);
setDetailModalVisible(true);
+ // 如果是任务提醒类型且有relatedId,获取任务详情
+ if (notification.type === 'task_reminder' && notification.relatedId) {
+ await fetchTaskDetail(notification.relatedId);
+ }
+
// 如果是未读状态,标记为已读
if (notification.status === 'unread') {
handleMarkAsRead(notification.id);
@@ -115,6 +127,42 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
}
};
+ // 获取任务详情
+ const fetchTaskDetail = async (opportunityId: string) => {
+ try {
+ setTaskLoading(true);
+ const response: any = await getTaskDetail(opportunityId);
+ if (response && response.data && response.code === 0) {
+ setSelectedTask(response.data);
+ } else {
+ console.error("获取任务详情失败");
+ }
+ } catch (error) {
+ console.error("获取任务详情失败:", error);
+ } finally {
+ setTaskLoading(false);
+ }
+ };
+
+ // 接受任务
+ const handleAcceptTask = async () => {
+ if (!selectedTask) return;
+
+ try {
+ const response: any = await acceptTask(selectedTask.id, selectedTask.opportunityId);
+ if (response && response.code === 0) {
+ message.success("接任务成功!");
+ // 重新获取任务详情以更新状态
+ await fetchTaskDetail(selectedTask.opportunityId);
+ } else {
+ message.error("接任务失败");
+ }
+ } catch (error) {
+ message.error("接任务失败");
+ console.error("接任务失败:", error);
+ }
+ };
+
// 格式化时间
const formatTime = (timeString: string) => {
const date = new Date(timeString);
@@ -167,6 +215,36 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
}
};
+ // 获取平台显示名称
+ const getPlatformName = (type: string) => {
+ const platformNames: Record<string, string> = {
+ 'tiktok': 'TikTok',
+ 'youtube': 'YouTube',
+ 'twitter': 'Twitter',
+ 'bilibili': '哔哩哔哩',
+ 'KWAI': '快手',
+ 'douyin': '抖音',
+ 'xhs': '小红书',
+ 'wxSph': '微信视频号',
+ 'wxGzh': '微信公众号',
+ 'facebook': 'Facebook',
+ 'instagram': 'Instagram',
+ 'threads': 'Threads',
+ 'pinterest': 'Pinterest',
+ };
+ return platformNames[type] || type;
+ };
+
+ // 获取任务类型显示名称
+ const getTaskTypeName = (type: string) => {
+ const taskTypeNames: Record<string, string> = {
+ 'video': '视频',
+ 'article': '图文',
+ 'article2': '纯文字',
+ };
+ return taskTypeNames[type] || type;
+ };
+
useEffect(() => {
if (visible) {
fetchNotifications();
@@ -298,14 +376,21 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
<span style={{ fontSize: '16px', fontWeight: '600' }}>通知详情</span>
</div>
}
- open={detailModalVisible}
- onCancel={() => setDetailModalVisible(false)}
- footer={[
- <Button key="close" onClick={() => setDetailModalVisible(false)} type="primary">
- 关闭
- </Button>
- ]}
- width={600}
+ zIndex={2000}
+ open={detailModalVisible}
+ onCancel={() => {
+ setDetailModalVisible(false);
+ setSelectedTask(null);
+ }}
+ footer={[
+ <Button key="close" onClick={() => {
+ setDetailModalVisible(false);
+ setSelectedTask(null);
+ }} type="primary">
+ 关闭
+ </Button>
+ ]}
+ width={800}
styles={{
header: {
borderBottom: '1px solid #f0f0f0',
@@ -316,10 +401,10 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
}
}}
>
- {selectedNotification && (
- <div className={styles.notificationDetail}>
- <h3>{selectedNotification.title}</h3>
- <div className={styles.meta}>
+ {selectedNotification && (
+ <div className={styles.notificationDetail}>
+ <h3>{selectedNotification.title}</h3>
+ <div className={styles.meta}>
<span>
<Tag color={getNotificationTypeColor(selectedNotification.type)}>
{getNotificationTypeText(selectedNotification.type)}
@@ -332,16 +417,144 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
</span>
{selectedNotification.readAt && (
<span style={{ color: '#52c41a' }}>
- 已读时间: {formatTime(selectedNotification.readAt)}
+ 已读时间: {formatTime(selectedNotification.readAt)}
</span>
)}
</div>
</div>
- <div className={styles.content}>
- {selectedNotification.content}
- </div>
- </div>
- )}
+ <div className={styles.content}>
+ {selectedNotification.content}
+ </div>
+
+ {/* 任务详情部分 */}
+ {selectedNotification.type === 'task_reminder' && (
+ <div className={styles.taskDetail}>
+ <h4 style={{ marginBottom: '16px', color: '#1890ff' }}>任务详情</h4>
+ <Spin spinning={taskLoading}>
+ {selectedTask ? (
+ <div className={styles.taskInfo}>
+ <div className={styles.taskHeader}>
+ <h5>{selectedTask.title}</h5>
+ <Tag color={selectedTask.status === 'active' ? 'green' : 'red'}>
+ {selectedTask.status === 'active' ? '进行中' : '已结束'}
+ </Tag>
+ </div>
+ <div className={styles.taskContent}>
+ <p><strong>描述:</strong>
+ <div dangerouslySetInnerHTML={{ __html: selectedTask.description }} />
+ </p>
+ <p><strong>奖励:</strong>¥{selectedTask.reward}</p>
+ {/* <p><strong>招募人数:</strong>{selectedTask.currentRecruits}/{selectedTask.maxRecruits}</p> */}
+
+ <p><strong>任务类型:</strong>
+ <Tag color="blue" style={{ marginLeft: '4px' }}>
+ {getTaskTypeName(selectedTask.type)}
+ </Tag>
+ </p>
+ {selectedTask.accountTypes && selectedTask.accountTypes.length > 0 && (
+ <p><strong>账号类型:</strong>
+ {selectedTask.accountTypes.map(type => (
+ <Tag key={type} style={{ marginLeft: '4px' }}>{getPlatformName(type)}</Tag>
+ ))}
+ </p>
+ )}
+
+ {/* 任务素材展示 */}
+ {selectedTask.materials && selectedTask.materials.length > 0 && (
+ <div style={{ marginTop: '16px' }}>
+ <p><strong>任务素材:</strong></p>
+ <div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}>
+ {selectedTask.materials.map((material: any, index: number) => (
+ <div key={index} style={{
+ border: '1px solid #e8e8e8',
+ borderRadius: '8px',
+ padding: '8px',
+ maxWidth: '200px'
+ }}>
+ <div style={{ fontSize: '12px', fontWeight: '500', marginBottom: '4px' }}>
+ {material.title}
+ </div>
+ {material.coverUrl && (
+ <img
+ src={getOssUrl(material.coverUrl)}
+ alt="cover"
+ style={{
+ width: '100%',
+ height: '100px',
+ objectFit: 'cover',
+ borderRadius: '4px',
+ marginBottom: '4px'
+ }}
+ />
+ )}
+ <div style={{ fontSize: '11px', color: '#666', lineHeight: '1.3' }}>
+ {material.desc?.substring(0, 50)}{material.desc?.length > 50 ? '...' : ''}
+ </div>
+ {material.mediaList && material.mediaList.length > 0 && (
+ <div style={{
+ display: 'flex',
+ gap: '4px',
+ marginTop: '4px',
+ flexWrap: 'wrap'
+ }}>
+ {material.mediaList.slice(0, 3).map((media: any, mediaIndex: number) => (
+ <img
+ key={mediaIndex}
+ src={getOssUrl(media.url)}
+ alt="media"
+ style={{
+ width: '40px',
+ height: '40px',
+ objectFit: 'cover',
+ borderRadius: '2px'
+ }}
+ />
+ ))}
+ {material.mediaList.length > 3 && (
+ <div style={{
+ width: '40px',
+ height: '40px',
+ background: '#f0f0f0',
+ borderRadius: '2px',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: '10px',
+ color: '#666'
+ }}>
+ +{material.mediaList.length - 3}
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ {selectedTask.status === 'active' && selectedTask.currentRecruits < selectedTask.maxRecruits && (
+ <div className={styles.taskActions}>
+ <Button
+ type="primary"
+ onClick={handleAcceptTask}
+ style={{ marginTop: '12px' }}
+ >
+ 接受任务
+ </Button>
+ </div>
+ )}
+ </div>
+ ) : !taskLoading && (
+ <div style={{ textAlign: 'center', color: '#999' }}>
+ 暂无任务详情
+ </div>
+ )}
+ </Spin>
+ </div>
+ )}
+ </div>
+ )}
</Modal>
</>
);