Skip to content

Let's use AI to Earn!

fix(web): task chu pay y (#474)

布莱恩·奥夫托·杰森张03c296fa5bfa
diff --git a/project/web/src/app/[lng]/income/page.tsx b/project/web/src/app/[lng]/income/page.tsx
index 06e96f03..11d2ed17 100644
--- a/project/web/src/app/[lng]/income/page.tsx
+++ b/project/web/src/app/[lng]/income/page.tsx
@@ -11,7 +11,7 @@ import { CheckCircleOutlined, ClockCircleOutlined, CloseCircleOutlined, DollarOu
import { useParams, useRouter } from 'next/navigation'
import { useEffect, useState } from 'react'
import { WithdrawRecordStatus, WithdrawStatus } from '@/api/types/withdraw'
-import { getIncomeListApi, getIncomeDetailApi, createWithdrawApi, getWithdrawListApi } from '@/api/payment'
+import { getIncomeListApi, getIncomeDetailApi, createWithdrawApi, getWithdrawListApi, withdrawAllPendingApi } from '@/api/payment'
import { useTransClient } from '@/app/i18n/client'
import WalletAccountSelect from '@/components/WalletAccountSelect'
import WalletModal from '@/components/WalletModal'
@@ -68,6 +68,9 @@ export default function IncomePage() {
// 钱包弹窗状态
const [walletModalOpen, setWalletModalOpen] = useState(false)
+ const [withdrawAllModalVisible, setWithdrawAllModalVisible] = useState(false)
+ const [withdrawAllSubmitting, setWithdrawAllSubmitting] = useState(false)
+ const [withdrawAllWalletId, setWithdrawAllWalletId] = useState<string>('')
// 收入详情状态
const [incomeDetailModalVisible, setIncomeDetailModalVisible] = useState(false)
@@ -311,16 +314,18 @@ export default function IncomePage() {
</div>
</div>
</div>
- <Button
- variant="outline"
- size="sm"
- className={styles.walletButton}
- onClick={() => setWalletModalOpen(true)}
- >
- <WalletOutlined />
- &nbsp;
- {t('myWallet')}
- </Button>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ className={styles.walletButton}
+ onClick={() => setWalletModalOpen(true)}
+ >
+ <WalletOutlined />
+ &nbsp;
+ {t('myWallet')}
+ </Button>
+ </div>
</div>
</div>
</div>
@@ -343,7 +348,7 @@ export default function IncomePage() {
</TabsList>
<TabsContent value="income" className="mt-4">
- {/* 筛选器 */}
+ {/* 筛选器 */}
<div className="flex gap-4 mb-6">
<div className="flex-1">
<Label className="mb-2 block">{t('type')}</Label>
@@ -383,6 +388,17 @@ export default function IncomePage() {
</div>
</div>
+ {/* Withdraw All 按钮 — 放在收入记录选项卡下方 */}
+ <div className="flex justify-end mb-4">
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => setWithdrawAllModalVisible(true)}
+ >
+ {t('withdrawAll')}
+ </Button>
+ </div>
+
<Spin spinning={incomeLoading}>
{incomeRecords.length > 0 ? (
<>
@@ -562,6 +578,58 @@ export default function IncomePage() {
</Tabs>
</div>
+ {/* 全部提现弹窗 */}
+ <Modal
+ title={t('withdrawAll')}
+ open={withdrawAllModalVisible}
+ onCancel={() => {
+ setWithdrawAllModalVisible(false)
+ setWithdrawAllWalletId('')
+ }}
+ onOk={async () => {
+ if (!withdrawAllWalletId) {
+ toast.error(t('selectWalletForWithdrawAll'))
+ return
+ }
+ setWithdrawAllSubmitting(true)
+ try {
+ const resp = await withdrawAllPendingApi({
+ currency: 'CNY',
+ walletAccountId: withdrawAllWalletId,
+ })
+ if (resp) {
+ toast.success(t('messages.withdrawSubmitted'))
+ setWithdrawAllModalVisible(false)
+ // refresh lists
+ fetchIncomeRecords(incomePagination.current, incomePagination.pageSize)
+ fetchWithdrawRecords(withdrawPagination.current, withdrawPagination.pageSize)
+ }
+ else {
+ toast.error(t('messages.withdrawFailed'))
+ }
+ }
+ catch (err) {
+ console.error('withdrawAll failed', err)
+ toast.error(t('messages.withdrawFailed'))
+ }
+ finally {
+ setWithdrawAllSubmitting(false)
+ }
+ }}
+ okText={t('confirm')}
+ cancelText={t('cancel')}
+ confirmLoading={withdrawAllSubmitting}
+ width={500}
+ >
+ <div>
+ <p style={{ marginBottom: 12 }}>{t('selectWalletForWithdrawAll')}</p>
+ <WalletAccountSelect
+ value={withdrawAllWalletId}
+ onChange={(val: any) => setWithdrawAllWalletId(val || '')}
+ />
+ </div>
+ </Modal>
+
{/* 提现确认弹窗 */}
<Modal
title={t('confirmWithdraw')}
diff --git a/project/web/src/app/[lng]/tasks/taskPageCore.tsx b/project/web/src/app/[lng]/tasks/taskPageCore.tsx
index dc11a120..d21899c5 100644
--- a/project/web/src/app/[lng]/tasks/taskPageCore.tsx
+++ b/project/web/src/app/[lng]/tasks/taskPageCore.tsx
@@ -539,9 +539,15 @@ export default function TaskPageCore() {
try {
setAcceptedTaskSettleLoading(true)
const infoResp: any = await apiGetSettleInfoByUserTask(userTaskId)
- if (infoResp && infoResp.data && (infoResp.code === 0 || infoResp.success) && infoResp.data.id) {
- const settleId = infoResp.data.id
- await fetchAcceptedTaskSettleItems(settleId)
+ // API may return id or _id. Accept both and fall back to empty list when missing.
+ if (infoResp && infoResp.data && (infoResp.code === 0 || infoResp.success)) {
+ const settleId = infoResp.data.id || infoResp.data._id || (infoResp.data as any).settleId
+ if (settleId) {
+ await fetchAcceptedTaskSettleItems(settleId)
+ }
+ else {
+ setAcceptedTaskSettleItems([])
+ }
}
else {
setAcceptedTaskSettleItems([])
@@ -563,7 +569,27 @@ export default function TaskPageCore() {
setAcceptedTaskSettleLoading(true)
const itemsResp: any = await apiGetSettleItemList(settleId)
if (itemsResp && itemsResp.data && (itemsResp.code === 0 || itemsResp.success)) {
- setAcceptedTaskSettleItems(itemsResp.data.list || itemsResp.data || [])
+ const rawList = itemsResp.data.list || itemsResp.data || []
+ // normalize items for UI: provide `title` and `value` fields
+ const normalized = (rawList as any[]).map(item => {
+ const dataType = item.dataType || item.type || item.key
+ // Try translate dataType; if translation returns the key itself, treat as missing and fallback.
+ let titleFromType: string | undefined = undefined
+ if (dataType) {
+ const translated = t(`settle.dataType.${dataType}` as any)
+ if (translated && !translated.includes('settle.dataType.')) {
+ titleFromType = translated
+ }
+ }
+ const title = titleFromType || item.title || item.name || dataType || ''
+ const value = item.dataValue ?? item.value ?? item.amount ?? item.pricing ?? null
+ return {
+ ...item,
+ title,
+ value,
+ }
+ })
+ setAcceptedTaskSettleItems(normalized)
}
else {
setAcceptedTaskSettleItems([])
diff --git a/project/web/src/app/i18n/locales/en/income.json b/project/web/src/app/i18n/locales/en/income.json
index 734df75a..c91f41ae 100644
--- a/project/web/src/app/i18n/locales/en/income.json
+++ b/project/web/src/app/i18n/locales/en/income.json
@@ -48,4 +48,8 @@
"loading": "Loading...",
"totalRecords": "Total {{total}} records"
}
+ ,
+ "all": "All",
+ "withdrawAll": "Withdraw All",
+ "selectWalletForWithdrawAll": "Please select a wallet account to use for withdrawing all pending income"
}
diff --git a/project/web/src/app/i18n/locales/en/task.json b/project/web/src/app/i18n/locales/en/task.json
index 06432b8f..f3362d80 100644
--- a/project/web/src/app/i18n/locales/en/task.json
+++ b/project/web/src/app/i18n/locales/en/task.json
@@ -142,4 +142,11 @@
"accountAvatar": "Account Avatar",
"notSubmitted": "Not Submitted",
"pleaseSelectDraftMaterial": "Please select a draft material"
+ ,
+ "settle": {
+ "items": "Settlement Info",
+ "dataType": {
+ "views": "Views"
+ }
+ }
}
diff --git a/project/web/src/app/i18n/locales/en/wallet.json b/project/web/src/app/i18n/locales/en/wallet.json
index 66976d7e..93aa90df 100644
--- a/project/web/src/app/i18n/locales/en/wallet.json
+++ b/project/web/src/app/i18n/locales/en/wallet.json
@@ -18,6 +18,7 @@
"edit": "Edit",
"delete": "Delete",
"deleteConfirm": "Are you sure to delete this wallet account?",
+ "deleteConfirmDesc": "This operation cannot be undone. Are you sure you want to delete this wallet account?",
"confirm": "Confirm",
"cancel": "Cancel"
},
@@ -43,9 +44,16 @@
"typePlaceholder": "Please select type",
"required": "Required field"
},
+ "selectWalletPlaceholder": "Select wallet account",
"messages": {
"createSuccess": "Created successfully",
"updateSuccess": "Updated successfully",
- "deleteSuccess": "Deleted successfully"
+ "deleteSuccess": "Deleted successfully",
+ "loading": "Loading...",
+ "noData": "No data",
+ "deleteFailed": "Delete failed",
+ "createFailed": "Create failed",
+ "setDefaultSuccess": "Set as default successfully",
+ "setDefaultFailed": "Set as default failed"
}
}
diff --git a/project/web/src/app/i18n/locales/zh-CN/common.json b/project/web/src/app/i18n/locales/zh-CN/common.json
index d4a510f4..467f5ffb 100644
--- a/project/web/src/app/i18n/locales/zh-CN/common.json
+++ b/project/web/src/app/i18n/locales/zh-CN/common.json
@@ -52,7 +52,7 @@
"header": {
"messages": "消息通知",
"income": "收入记录",
- "wallet": "我的钱包",
+ "wallet": "钱包账户",
"materialLibrary": "素材库",
"draftBox": "草稿箱"
},
diff --git a/project/web/src/app/i18n/locales/zh-CN/income.json b/project/web/src/app/i18n/locales/zh-CN/income.json
index 5df5ecd6..5eef7477 100644
--- a/project/web/src/app/i18n/locales/zh-CN/income.json
+++ b/project/web/src/app/i18n/locales/zh-CN/income.json
@@ -48,5 +48,9 @@
"loading": "加载中...",
"totalRecords": "共 {{total}} 条记录"
},
- "myWallet": "我的钱包"
+ "myWallet": "钱包账户"
+ ,
+ "all": "全部",
+ "withdrawAll": "全部提现",
+ "selectWalletForWithdrawAll": "请选择用于全部提现的钱包账号"
}
diff --git a/project/web/src/app/i18n/locales/zh-CN/task.json b/project/web/src/app/i18n/locales/zh-CN/task.json
index 4594406a..e8e54df6 100644
--- a/project/web/src/app/i18n/locales/zh-CN/task.json
+++ b/project/web/src/app/i18n/locales/zh-CN/task.json
@@ -142,4 +142,11 @@
"accountAvatar": "账号头像",
"notSubmitted": "未提交",
"pleaseSelectDraftMaterial": "请选择一个草稿素材"
+ ,
+ "settle": {
+ "items": "结算信息",
+ "dataType": {
+ "views": "播放量"
+ }
+ }
}
diff --git a/project/web/src/app/i18n/locales/zh-CN/wallet.json b/project/web/src/app/i18n/locales/zh-CN/wallet.json
index 25e05ee6..b2598254 100644
--- a/project/web/src/app/i18n/locales/zh-CN/wallet.json
+++ b/project/web/src/app/i18n/locales/zh-CN/wallet.json
@@ -1,5 +1,5 @@
{
- "title": "我的钱包",
+ "title": "钱包账户",
"columns": {
"userName": "真实姓名",
"mail": "邮箱",
@@ -18,6 +18,7 @@
"edit": "编辑",
"delete": "删除",
"deleteConfirm": "确认删除该钱包账户?",
+ "deleteConfirmDesc": "此操作不可撤销,确认要删除该钱包账户吗?",
"confirm": "确认",
"cancel": "取消"
},
@@ -43,9 +44,16 @@
"typePlaceholder": "请选择类型",
"required": "必填项"
},
+ "selectWalletPlaceholder": "选择提现钱包账户",
"messages": {
"createSuccess": "创建成功",
"updateSuccess": "更新成功",
- "deleteSuccess": "删除成功"
+ "deleteSuccess": "删除成功",
+ "loading": "加载中...",
+ "noData": "暂无数据",
+ "deleteFailed": "删除失败",
+ "createFailed": "创建失败",
+ "setDefaultSuccess": "设置为默认成功",
+ "setDefaultFailed": "设置为默认失败"
}
}
diff --git a/project/web/src/components/WalletAccountSelect/index.tsx b/project/web/src/components/WalletAccountSelect/index.tsx
index 9e2b60ee..019da299 100644
--- a/project/web/src/components/WalletAccountSelect/index.tsx
+++ b/project/web/src/components/WalletAccountSelect/index.tsx
@@ -1,9 +1,11 @@
'use client'
-import type { UserWalletAccount } from '@/api/userWalletAccount'
+// using payment API shape (id, userName, email, account, type, ...)
import { Empty, Select, Spin } from 'antd'
import { useEffect, useMemo, useState } from 'react'
-import { getUserWalletAccountList } from '@/api/userWalletAccount'
+import { getWalletAccountListApi } from '@/api/payment'
+import type { UserWalletAccount } from '@/api/userWalletAccount'
+import { useTransClient } from '@/app/i18n/client'
interface Props {
value?: string
@@ -16,8 +18,9 @@ const { Option } = Select
export default function WalletAccountSelect(props: Props) {
const { value, onChange, pageSize = 50, disabled } = props
+ const { t } = useTransClient('wallet')
const [loading, setLoading] = useState(false)
- const [list, setList] = useState<UserWalletAccount[]>([])
+ const [list, setList] = useState<any[]>([])
const [pageNo, setPageNo] = useState(1)
const [total, setTotal] = useState(0)
@@ -30,9 +33,11 @@ export default function WalletAccountSelect(props: Props) {
async function fetchPage(nextPage: number) {
setLoading(true)
try {
- const res = await getUserWalletAccountList(nextPage, pageSize)
- if (res?.data) {
- const newList = nextPage === 1 ? (res.data.list || []) : [...list, ...(res.data.list || [])]
+ // Use payment API which returns { data: { page, pageSize, totalPages, total, list: [] } }
+ const res: any = await getWalletAccountListApi({ page: nextPage, pageSize })
+ if (res && res.data && res.data.list) {
+ const rawList = res.data.list || []
+ const newList = nextPage === 1 ? rawList : [...list, ...rawList]
setList(newList)
setTotal(res.data.total || 0)
setPageNo(nextPage)
@@ -53,25 +58,19 @@ export default function WalletAccountSelect(props: Props) {
return (
<Select
showSearch
- placeholder="选择提现钱包账户"
+ placeholder={t('selectWalletPlaceholder') || '选择提现钱包账户'}
optionFilterProp="children"
value={value}
onChange={onChange}
disabled={disabled}
style={{ width: '100%' }}
onPopupScroll={onPopupScroll}
- notFoundContent={loading ? <Spin size="small" /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无账户" />}
+ notFoundContent={loading ? <Spin size="small" /> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={t('messages.noData') || '暂无账户'} />}
filterOption={(input, option) => (option?.children as unknown as string)?.toLowerCase().includes(input.toLowerCase())}
>
{list.map(item => (
- <Option key={item._id} value={item._id}>
- {item.userName || item.mail}
- {' '}
- ·
- {item.type}
- {' '}
- ·
- {item.account}
+ <Option key={item.id || item._id} value={item.id || item._id}>
+ {(item.userName || item.email) + ' · ' + (item.type || '') + ' · ' + (item.account || '')}
</Option>
))}
</Select>