Skip to content

Let's use AI to Earn!

tiaoshibaocuo

bulaienaofutuojiesenzhangfc4c1b5158f0
diff --git a/src/app/[lng]/tasks/taskPageCore.tsx b/src/app/[lng]/tasks/taskPageCore.tsx
index 22bb950e..aecd9d95 100644
--- a/src/app/[lng]/tasks/taskPageCore.tsx
+++ b/src/app/[lng]/tasks/taskPageCore.tsx
@@ -25,6 +25,7 @@ import { getTaskDetail, acceptTask, submitTask } from "@/api/notification";
import { getDays, getUtcDays } from "@/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils";
import { Steps } from "antd";
import http from "@/utils/request";
+import { useRouter, useParams } from "next/navigation";
import styles from "./taskPageCore.module.scss";
const { TabPane } = Tabs;
@@ -32,6 +33,9 @@ const { TabPane } = Tabs;
export default function TaskPageCore() {
const { t } = useTransClient("task" as any);
const token = useUserStore((state) => state.token);
+ const router = useRouter();
+ const params = useParams();
+ const lng = params.lng as string;
// 如果未登录,显示登录提示
if (!token) {
@@ -112,6 +116,12 @@ export default function TaskPageCore() {
qrCodeUrl: "" as string | undefined
});
+ // 账号选择弹窗状态
+ const [accountSelectVisible, setAccountSelectVisible] = useState(false);
+ const [availableAccounts, setAvailableAccounts] = useState<SocialAccount[]>([]);
+ const [selectedAccount, setSelectedAccount] = useState<SocialAccount | null>(null);
+ const [requiredAccountTypes, setRequiredAccountTypes] = useState<string[]>([]);
+
// 获取待接受任务列表
const fetchPendingTasks = async (page: number = 1, pageSize: number = 20) => {
if (!token) return;
@@ -350,6 +360,159 @@ export default function TaskPageCore() {
return accountList.find(account => account.id === accountId) || null;
};
+ // 获取符合条件的账号
+ const getAvailableAccounts = (accountTypes: string[]): SocialAccount[] => {
+ if (!accountTypes || accountTypes.length === 0) {
+ return accountList;
+ }
+ return accountList.filter(account => accountTypes.includes(account.type));
+ };
+
+ // 处理任务操作(接受任务)
+ const handleTaskAction = (task: any) => {
+ // 如果任务指定了账号ID,直接使用该账号
+ if (task.accountId) {
+ const publishAccount = getAccountById(task.accountId);
+ if (publishAccount) {
+ // 检查是否需要App操作
+ const appRequiredPlatforms = getTasksRequiringApp([publishAccount.type]);
+ if (appRequiredPlatforms.length > 0) {
+ const firstPlatform = appRequiredPlatforms[0];
+ const config = getAppDownloadConfig(firstPlatform);
+
+ if (config) {
+ setDownloadAppConfig({
+ platform: config.platform,
+ appName: config.appName,
+ downloadUrl: config.downloadUrl,
+ qrCodeUrl: config.qrCodeUrl
+ });
+ setDownloadAppVisible(true);
+ return;
+ }
+ }
+
+ // 使用指定账号接受任务
+ handleAcceptTaskFromDetail(task, publishAccount);
+ return;
+ }
+ }
+
+ // 如果没有指定账号,需要用户选择账号
+ const availableAccounts = getAvailableAccounts(task.accountTypes || []);
+
+ if (availableAccounts.length === 0) {
+ // 没有符合条件的账号,跳转到账户界面并弹出授权界面
+ setRequiredAccountTypes(task.accountTypes || []);
+ setTaskDetailModalVisible(false); // 关闭任务详情弹窗
+ message.info(t('accountSelect.redirectingToAccounts' as any));
+ router.push(`/${lng}/accounts`); // 跳转到账户界面
+ return;
+ }
+
+ if (availableAccounts.length === 1) {
+ // 只有一个符合条件的账号,直接使用
+ const account = availableAccounts[0];
+
+ // 检查是否需要App操作
+ const appRequiredPlatforms = getTasksRequiringApp([account.type]);
+ if (appRequiredPlatforms.length > 0) {
+ const firstPlatform = appRequiredPlatforms[0];
+ const config = getAppDownloadConfig(firstPlatform);
+
+ if (config) {
+ setDownloadAppConfig({
+ platform: config.platform,
+ appName: config.appName,
+ downloadUrl: config.downloadUrl,
+ qrCodeUrl: config.qrCodeUrl
+ });
+ setDownloadAppVisible(true);
+ return;
+ }
+ }
+
+ // 直接使用这个账号接受任务
+ handleAcceptTaskFromDetail(task, account);
+ return;
+ }
+
+ // 多个符合条件的账号,显示选择弹窗
+ setAvailableAccounts(availableAccounts);
+ setAccountSelectVisible(true);
+ };
+
+ // 处理账号选择
+ const handleAccountSelect = (account: SocialAccount) => {
+ setSelectedAccount(account);
+ setAccountSelectVisible(false);
+
+ // 检查是否需要App操作
+ const appRequiredPlatforms = getTasksRequiringApp([account.type]);
+ if (appRequiredPlatforms.length > 0) {
+ const firstPlatform = appRequiredPlatforms[0];
+ const config = getAppDownloadConfig(firstPlatform);
+
+ if (config) {
+ setDownloadAppConfig({
+ platform: config.platform,
+ appName: config.appName,
+ downloadUrl: config.downloadUrl,
+ qrCodeUrl: config.qrCodeUrl
+ });
+ setDownloadAppVisible(true);
+ return;
+ }
+ }
+
+ // 使用选择的账号接受任务
+ if (taskDetail) {
+ handleAcceptTaskFromDetail(taskDetail, account);
+ }
+ };
+
+ // 检查是否有新添加的符合条件账号
+ const checkForNewAccounts = () => {
+ if (requiredAccountTypes.length > 0 && taskDetail) {
+ const newAvailableAccounts = getAvailableAccounts(requiredAccountTypes);
+
+ if (newAvailableAccounts.length > 0) {
+ // 有新账号了,清除需求状态
+ setRequiredAccountTypes([]);
+
+ if (newAvailableAccounts.length === 1) {
+ // 只有一个新账号,直接使用
+ const account = newAvailableAccounts[0];
+
+ // 检查是否需要App操作
+ const appRequiredPlatforms = getTasksRequiringApp([account.type]);
+ if (appRequiredPlatforms.length > 0) {
+ const firstPlatform = appRequiredPlatforms[0];
+ const config = getAppDownloadConfig(firstPlatform);
+
+ if (config) {
+ setDownloadAppConfig({
+ platform: config.platform,
+ appName: config.appName,
+ downloadUrl: config.downloadUrl,
+ qrCodeUrl: config.qrCodeUrl
+ });
+ setDownloadAppVisible(true);
+ return;
+ }
+ }
+
+ // 直接使用这个账号接受任务
+ handleAcceptTaskFromDetail(taskDetail, account);
+ } else {
+ // 多个新账号,显示选择弹窗
+ setAvailableAccounts(newAvailableAccounts);
+ setAccountSelectVisible(true);
+ }
+ }
+ }
+ };
+
// 获取平台图标
const getPlatformIcon = (accountType: string) => {
const platInfo = AccountPlatInfoMap.get(accountType as PlatType);
@@ -397,7 +560,7 @@ export default function TaskPageCore() {
};
// 从任务详情接受任务
- const handleAcceptTaskFromDetail = async (task: any) => {
+ const handleAcceptTaskFromDetail = async (task: any, account?: SocialAccount) => {
if (!task) return;
// 关闭详情弹窗
@@ -417,7 +580,7 @@ export default function TaskPageCore() {
try {
// 第一步:接受任务
- const response: any = await acceptTask(task.id, task.opportunityId);
+ const response: any = await acceptTask(task.id, task.opportunityId, account?.account);
if (response && response.code === 0) {
// 更新进度:第一步完成,开始第二步
setTaskProgress(prev => ({
@@ -432,7 +595,7 @@ export default function TaskPageCore() {
}));
// 第二步:发布任务
- const publishAccount = getAccountById(task.accountId);
+ const publishAccount = account || getAccountById(task.accountId);
if (publishAccount) {
// 处理素材链接,确保使用完整链接
const processedMaterials = task.materials?.map((material: any) => ({
@@ -705,6 +868,13 @@ export default function TaskPageCore() {
}
}, [token]);
+ // 监听账号列表变化,检查是否有新添加的符合条件账号
+ useEffect(() => {
+ if (accountList.length > 0) {
+ checkForNewAccounts();
+ }
+ }, [accountList, requiredAccountTypes, taskDetail]);
+
return (
<div className={styles.taskPage}>
{/* <div className={styles.header}>
@@ -1254,7 +1424,7 @@ export default function TaskPageCore() {
<Button
type="primary"
size="large"
- onClick={() => handleAcceptTaskFromDetail(taskDetail)}
+ onClick={() => handleTaskAction(taskDetail)}
style={{ marginTop: '12px' }}
>
{t('acceptTask')}
@@ -1729,6 +1899,85 @@ export default function TaskPageCore() {
/>
</Modal>
+ {/* 账号选择弹窗 */}
+ <Modal
+ title={t('accountSelect.title' as any)}
+ open={accountSelectVisible}
+ onCancel={() => setAccountSelectVisible(false)}
+ footer={null}
+ width={600}
+ zIndex={2000}
+ styles={{
+ header: {
+ borderBottom: '1px solid #f0f0f0',
+ paddingBottom: '16px'
+ },
+ body: {
+ padding: '24px'
+ }
+ }}
+ >
+ <div style={{ marginBottom: '16px' }}>
+ <p style={{ margin: 0, color: '#666' }}>
+ {t('accountSelect.description' as any)}
+ </p>
+ </div>
+ <List
+ dataSource={availableAccounts}
+ renderItem={(account) => (
+ <List.Item
+ style={{
+ padding: '16px',
+ border: '1px solid #f0f0f0',
+ borderRadius: '8px',
+ marginBottom: '8px',
+ cursor: 'pointer',
+ transition: 'all 0.3s ease'
+ }}
+ onMouseEnter={(e) => {
+ e.currentTarget.style.borderColor = '#1890ff';
+ e.currentTarget.style.backgroundColor = '#f6ffed';
+ }}
+ onMouseLeave={(e) => {
+ e.currentTarget.style.borderColor = '#f0f0f0';
+ e.currentTarget.style.backgroundColor = 'transparent';
+ }}
+ onClick={() => handleAccountSelect(account)}
+ >
+ <List.Item.Meta
+ avatar={
+ <img
+ src={account.avatar ? getOssUrl(account.avatar) : '/default-avatar.png'}
+ alt="账号头像"
+ style={{
+ width: '48px',
+ height: '48px',
+ borderRadius: '50%',
+ objectFit: 'cover'
+ }}
+ onError={(e) => {
+ e.currentTarget.src = '/default-avatar.png';
+ }}
+ />
+ }
+ title={
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
+ <span style={{ fontWeight: '500' }}>{account.nickname}</span>
+ <Tag color="blue">{getPlatformName(account.type)}</Tag>
+ </div>
+ }
+ description={
+ <div style={{ color: '#666' }}>
+ <div>{t('accountSelect.accountId' as any)}: {account.account}</div>
+ {account.nickname && <div>{t('accountSelect.description' as any)}: {account.nickname}</div>}
+ </div>
+ }
+ />
+ </List.Item>
+ )}
+ />
+ </Modal>
+
{/* 下载App提示弹窗 */}
<DownloadAppModal
visible={downloadAppVisible}
diff --git a/src/app/i18n/locales/en/notification.json b/src/app/i18n/locales/en/notification.json
index e74e25e6..7158320e 100644
--- a/src/app/i18n/locales/en/notification.json
+++ b/src/app/i18n/locales/en/notification.json
@@ -83,6 +83,7 @@
"title": "Select Publisher Account",
"description": "Please select an account to publish the task:",
"noAccounts": "No eligible accounts found, please add an account first",
+ "redirectingToAccounts": "Redirecting to accounts page, please add eligible accounts",
"accountId": "Account ID",
"description": "Description"
}
diff --git a/src/app/i18n/locales/zh-CN/notification.json b/src/app/i18n/locales/zh-CN/notification.json
index 499c8997..2d2fe9b0 100644
--- a/src/app/i18n/locales/zh-CN/notification.json
+++ b/src/app/i18n/locales/zh-CN/notification.json
@@ -83,6 +83,7 @@
"title": "选择发布账号",
"description": "请选择用于发布任务的账号:",
"noAccounts": "没有符合条件的账号,请先添加账号",
+ "redirectingToAccounts": "正在跳转到账户界面,请添加符合条件的账号",
"accountId": "账号ID",
"description": "描述"
}
diff --git a/src/components/notification/NotificationPanel.tsx b/src/components/notification/NotificationPanel.tsx
index 053906d9..f42b70cd 100644
--- a/src/components/notification/NotificationPanel.tsx
+++ b/src/components/notification/NotificationPanel.tsx
@@ -87,6 +87,7 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
const [accountSelectVisible, setAccountSelectVisible] = useState(false);
const [availableAccounts, setAvailableAccounts] = useState<SocialAccount[]>([]);
const [selectedAccount, setSelectedAccount] = useState<SocialAccount | null>(null);
+ const [requiredAccountTypes, setRequiredAccountTypes] = useState<string[]>([]);
// 获取通知列表
const fetchNotifications = async (page: number = 1, pageSize: number = 20) => {
@@ -235,7 +236,7 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
try {
// 第一步:接受任务
- const response: any = await acceptTask(selectedTask.id, selectedTask.opportunityId, account?.account);
+ const response: any = await acceptTask(selectedTask.id, selectedTask.opportunityId, account?.id);
if (response && response.code === 0) {
// 更新进度:第一步完成,开始第二步
setTaskProgress(prev => ({
@@ -377,10 +378,16 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
const availableAccounts = getAvailableAccounts(task.accountTypes || []);
if (availableAccounts.length === 0) {
- message.error(t('accountSelect.noAccounts' as any));
+ // 没有符合条件的账号,跳转到账户界面并弹出授权界面
+ setRequiredAccountTypes(task.accountTypes || []);
+ setDetailModalVisible(false); // 关闭任务详情弹窗
+ message.info(t('accountSelect.redirectingToAccounts' as any));
+ router.push(`/${lng}/accounts`); // 跳转到账户界面
return;
}
-
+
+
+
if (availableAccounts.length === 1) {
// 只有一个符合条件的账号,直接使用
const account = availableAccounts[0];
@@ -587,6 +594,48 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
handleAcceptTask(account);
};
+ // 检查是否有新添加的符合条件账号
+ const checkForNewAccounts = () => {
+ if (requiredAccountTypes.length > 0 && selectedTask) {
+ const newAvailableAccounts = getAvailableAccounts(requiredAccountTypes);
+
+ if (newAvailableAccounts.length > 0) {
+ // 有新账号了,清除需求状态
+ setRequiredAccountTypes([]);
+
+ if (newAvailableAccounts.length === 1) {
+ // 只有一个新账号,直接使用
+ const account = newAvailableAccounts[0];
+
+ // 检查是否需要App操作
+ const appRequiredPlatforms = getTasksRequiringApp([account.type]);
+ if (appRequiredPlatforms.length > 0) {
+ const firstPlatform = appRequiredPlatforms[0];
+ const config = getAppDownloadConfig(firstPlatform);
+
+ if (config) {
+ setDownloadAppConfig({
+ platform: config.platform,
+ appName: config.appName,
+ downloadUrl: config.downloadUrl,
+ qrCodeUrl: config.qrCodeUrl
+ });
+ setDownloadAppVisible(true);
+ return;
+ }
+ }
+
+ // 直接使用这个账号接受任务
+ handleAcceptTask(account);
+ } else {
+ // 多个新账号,显示选择弹窗
+ setAvailableAccounts(newAvailableAccounts);
+ setAccountSelectVisible(true);
+ }
+ }
+ }
+ };
+
useEffect(() => {
if (visible) {
fetchNotifications();
@@ -595,6 +644,13 @@ const NotificationPanel: React.FC<NotificationPanelProps> = ({ visible, onClose
}
}, [visible, token]);
+ // 监听账号列表变化,检查是否有新添加的符合条件账号
+ useEffect(() => {
+ if (accountList.length > 0) {
+ checkForNewAccounts();
+ }
+ }, [accountList, requiredAccountTypes, selectedTask]);
+
return (
<>
<Modal