Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
钱包界面处理
daoyian9464fb90de01
diff --git a/src/views/finance/finance.module.scss b/src/views/finance/finance.module.scssindex 2abb36ea..6812d0b6 100644--- a/src/views/finance/finance.module.scss+++ b/src/views/finance/finance.module.scss@@ -13,4 +13,65 @@}}}+}++.finance {+ height: 100%;+ display: flex;+ flex-direction: column;+ background-color: #f5f5f5;+ padding: 24px;++ .header {+ margin-bottom: 24px;++ .balanceCard {+ background: linear-gradient(135deg, #1890ff 0%, #36cfcf 100%);+ color: white;+ border-radius: 12px;+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);+ padding: 24px;++ .balanceLabel {+ color: rgba(255, 255, 255, 0.8);+ font-size: 16px;+ }++ .balanceAmount {+ color: white;+ margin: 0;+ font-size: 32px;+ }++ .walletIcon {+ font-size: 48px;+ color: rgba(255, 255, 255, 0.8);+ }+ }+ }++ .content {+ flex: 1;+ display: flex;+ gap: 24px;+ background: white;+ border-radius: 12px;+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);+ padding: 24px;++ .sidebar {+ width: 200px;+ border-right: 1px solid #f0f0f0;+ padding-right: 24px;++ .segmented {+ width: 100%;+ }+ }++ .outlet {+ flex: 1;+ padding: 0 24px;+ }+ }}\ No newline at end of filediff --git a/src/views/finance/index.tsx b/src/views/finance/index.tsxindex 170325ef..fb2bb749 100644--- a/src/views/finance/index.tsx+++ b/src/views/finance/index.tsx@@ -5,36 +5,78 @@* @LastEditors: nevin* @Description: 任务页面*/-import { VideoCameraOutlined } from '@ant-design/icons';-import { Segmented } from 'antd';+import { VideoCameraOutlined, WalletOutlined } from '@ant-design/icons';+import { Segmented, Card, Typography, Space, Row, Col } from 'antd';import { Outlet, useNavigate } from 'react-router-dom';import styles from './finance.module.scss';+import { useState, useEffect } from 'react';+import { financeApi } from '@/api/finance';++const { Title, Text } = Typography;export default function Page() {const navigate = useNavigate();+ const [balance, setBalance] = useState<number>(0);++ useEffect(() => {+ getBalance();+ }, []);++ const getBalance = async () => {+ try {+ const res = await financeApi.getUserWalletInfo();+ setBalance(res.balance || 0);+ } catch (error) {+ console.error('获取余额失败:', error);+ }+ };return (- <div className={styles.publish}>- <Segmented- vertical- size="large"- options={[- {- label: '提现记录',- value: 'userWalletRecord',- icon: <VideoCameraOutlined />,- },- {- label: '钱包账户',- value: 'userWalletAccount',- icon: <VideoCameraOutlined />,- },- ]}- onChange={(value) => {- navigate(value);- }}- />- <Outlet />+ <div className={styles.finance}>+ <div className={styles.header}>+ <Card className={styles.balanceCard} bordered={false}>+ <Row align="middle" justify="space-between">+ <Col>+ <Space direction="vertical" size="small">+ <Text type="secondary" className={styles.balanceLabel}>账户余额</Text>+ <Title level={2} className={styles.balanceAmount}>+ ¥{balance.toFixed(2)}+ </Title>+ </Space>+ </Col>+ <Col>+ <WalletOutlined className={styles.walletIcon} />+ </Col>+ </Row>+ </Card>+ </div>+ <div className={styles.content}>+ <div className={styles.sidebar}>+ <Segmented+ vertical+ size="large"+ options={[+ {+ label: '提现记录',+ value: 'userWalletRecord',+ icon: <WalletOutlined />,+ },+ {+ label: '钱包账户',+ value: 'userWalletAccount',+ icon: <WalletOutlined />,+ },+ ]}+ onChange={(value) => {+ navigate(value);+ }}+ className={styles.segmented}+ />+ </div>+ <div className={styles.outlet}>+ <Outlet />+ </div>+ </div></div>);}diff --git a/src/views/finance/userWalletAccount.tsx b/src/views/finance/userWalletAccount.tsxindex e72411d4..e5adcc85 100644--- a/src/views/finance/userWalletAccount.tsx+++ b/src/views/finance/userWalletAccount.tsx@@ -5,23 +5,30 @@* @LastEditors: nevin* @Description: 用户的钱包账户 userWalletAccount*/-import { Button } from 'antd';+import { Button, Table, Space, Tag, message } from 'antd';import { useState, useEffect, useRef } from 'react';import AddWalletAccount from './components/addWalletAccount';import { UserWalletAccount } from '@/api/types/userWalletAccount';import { financeApi } from '@/api/finance';import { AddWalletAccountRef } from './components/addWalletAccount';+import { PlusOutlined } from '@ant-design/icons';export default function Page() {- const [walletAccountList, setWalletAccountList] = useState<- UserWalletAccount[]- >([]);-+ const [walletAccountList, setWalletAccountList] = useState<UserWalletAccount[]>([]);+ const [loading, setLoading] = useState(false);const Ref_AddWalletAccountRef = useRef<AddWalletAccountRef>(null);async function getTaskList() {- const res = await financeApi.getUserWalletAccountList();- setWalletAccountList(res);+ setLoading(true);+ try {+ const res = await financeApi.getUserWalletAccountList();+ setWalletAccountList(res);+ } catch (error) {+ console.error('获取钱包账户列表失败:', error);+ message.error('获取钱包账户列表失败');+ } finally {+ setLoading(false);+ }}// 新建@@ -33,27 +40,72 @@ export default function Page() {getTaskList();}, []);+ const columns = [+ {+ title: '手机号',+ dataIndex: 'phone',+ key: 'phone',+ },+ {+ title: '账户号',+ dataIndex: 'account',+ key: 'account',+ },+ {+ title: '身份证号',+ dataIndex: 'cardNum',+ key: 'cardNum',+ },+ {+ title: '账号类型',+ dataIndex: 'type',+ key: 'type',+ render: (type: string) => (+ <Tag color={type === '支付宝' ? 'blue' : 'green'}>{type}</Tag>+ ),+ },+ {+ title: '用户名',+ dataIndex: 'userName',+ key: 'userName',+ },+ {+ title: '操作',+ key: 'action',+ render: (_, record: UserWalletAccount) => (+ <Space size="middle">+ <Button type="link" onClick={() => handleView(record)}>+ 查看+ </Button>+ </Space>+ ),+ },+ ];++ const handleView = (record: UserWalletAccount) => {+ // TODO: 实现查看详情功能+ console.log('查看账户详情:', record);+ };+return (<div>- <Button type="primary" onClick={createUserWalletAccount}>- 新建- </Button>-- <AddWalletAccount ref={Ref_AddWalletAccountRef} />- <div>- {walletAccountList.map((v) => {- return (- <div key={v.id}>- <p>手机号{v.phone} </p>- <p>账户号{v.account} </p>- <p>身份证号{v.cardNum} </p>- <p>账号类型{v.type} </p>- <p>用户名{v.userName} </p>- <Button type="primary">查看</Button>- </div>- );- })}+ <div style={{ marginBottom: 16, textAlign: 'right' }}>+ <Button+ type="primary"+ icon={<PlusOutlined />}+ onClick={createUserWalletAccount}+ >+ 添加账户+ </Button></div>+ <Table+ columns={columns}+ dataSource={walletAccountList}+ rowKey="id"+ loading={loading}+ pagination={false}+ />+ <AddWalletAccount ref={Ref_AddWalletAccountRef} /></div>);}diff --git a/src/views/finance/userWalletRecord.module.scss b/src/views/finance/userWalletRecord.module.scssnew file mode 100644index 00000000..75d28cb2--- /dev/null+++ b/src/views/finance/userWalletRecord.module.scss@@ -0,0 +1,50 @@+.container {+ .headerCard {+ margin-bottom: 24px;+ background: #fafafa;+ border-radius: 8px;++ .header {+ display: flex;+ justify-content: space-between;+ align-items: center;++ .title {+ margin: 0;+ color: #262626;+ }++ .withdrawButton {+ height: 40px;+ padding: 0 24px;+ }+ }+ }++ .tableCard {+ background: white;+ border-radius: 8px;+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);++ .table {+ :global {+ .ant-table-thead > tr > th {+ background: #fafafa;+ font-weight: 500;+ }+ }+ }+ }++ .modal {+ :global {+ .ant-modal-content {+ border-radius: 8px;+ }+ }++ .input {+ height: 40px;+ }+ }+}\ No newline at end of filediff --git a/src/views/finance/userWalletRecord.tsx b/src/views/finance/userWalletRecord.tsxindex 51e6928f..d8a0f017 100644--- a/src/views/finance/userWalletRecord.tsx+++ b/src/views/finance/userWalletRecord.tsx@@ -5,53 +5,153 @@* @LastEditors: nevin* @Description: 用户金额记录 userWalletRecord*/-import { Card } from 'antd';+import { Button, Table, Space, Tag, message, Modal, Input, Form, Card, Typography } from 'antd';import { useState, useEffect, useRef } from 'react';import AddWalletAccount from './components/addWalletAccount';import { financeApi } from '@/api/finance';import { AddWalletAccountRef } from './components/addWalletAccount';import { UserWalletRecord } from '@/api/types/finance';+import { PlusOutlined, ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons';+import styles from './userWalletRecord.module.scss';-export default function Page() {- const [walletAccountList, setWalletAccountList] = useState<- UserWalletRecord[]- >([]);+const { Title } = Typography;+export default function Page() {+ const [walletAccountList, setWalletAccountList] = useState<UserWalletRecord[]>([]);+ const [loading, setLoading] = useState(false);+ const [isWithdrawModalVisible, setIsWithdrawModalVisible] = useState(false);+ const [form] = Form.useForm();const Ref_AddWalletAccountRef = useRef<AddWalletAccountRef>(null);async function getDataList() {- const res = await financeApi.getWithdrawList({- page: 1,- pageSize: 10,- });-- console.log('----- ', res);-- setWalletAccountList(res.items);+ setLoading(true);+ try {+ const res = await financeApi.getWithdrawList({+ page: 1,+ pageSize: 10,+ });+ setWalletAccountList(res.items);+ } catch (error) {+ console.error('获取钱包记录列表失败:', error);+ message.error('获取钱包记录列表失败');+ } finally {+ setLoading(false);+ }}+ const handleWithdraw = async (values: { amount: number }) => {+ try {+ await financeApi.addUserWalletRecord({+ walletAccountId: '1', // 这里需要传入实际的账户ID+ balance: values.amount+ });+ message.success('提现申请提交成功');+ setIsWithdrawModalVisible(false);+ form.resetFields();+ getDataList();+ } catch (error) {+ console.error('提现申请失败:', error);+ message.error('提现申请失败');+ }+ };+useEffect(() => {getDataList();}, []);+ const columns = [+ {+ title: '交易类型',+ dataIndex: 'type',+ key: 'type',+ render: (type: string) => (+ <Tag color={type === 'withdraw' ? 'red' : 'green'}>+ {type === 'withdraw' ? '提现' : '充值'}+ </Tag>+ ),+ },+ {+ title: '金额',+ dataIndex: 'balance',+ key: 'balance',+ render: (amount: number) => (+ <Space>+ {amount > 0 ? <ArrowUpOutlined style={{ color: '#52c41a' }} /> : <ArrowDownOutlined style={{ color: '#ff4d4f' }} />}+ <span style={{ color: amount < 0 ? '#ff4d4f' : '#52c41a' }}>+ {amount > 0 ? '+' : ''}{amount}+ </span>+ </Space>+ ),+ },+ {+ title: '状态',+ dataIndex: 'status',+ key: 'status',+ render: (status: string) => (+ <Tag color={status === 'pending' ? 'orange' : status === 'success' ? 'green' : 'red'}>+ {status === 'pending' ? '处理中' : status === 'success' ? '成功' : '失败'}+ </Tag>+ ),+ },+ {+ title: '创建时间',+ dataIndex: 'payTime',+ key: 'payTime',+ },+ ];+return (- <div>+ <div className={styles.container}><AddWalletAccount ref={Ref_AddWalletAccountRef} />- <div>- {walletAccountList.map((v) => {- return (- <Card key={v.id}>- <p>手机号{v.account.phone} </p>- <p>账户号{v.account.account} </p>- <p>类型{v.account.type} </p>- <p>金额{v.balance} </p>- <p>状态{v.status} </p>- <p>付款证明截图:{v.imgUrl} </p>- <p>付款时间:{v.payTime} </p>- </Card>- );- })}- </div>+ <Card className={styles.headerCard} bordered={false}>+ <div className={styles.header}>+ <Title level={4} className={styles.title}>交易记录</Title>+ <Button+ type="primary"+ icon={<PlusOutlined />}+ onClick={() => setIsWithdrawModalVisible(true)}+ className={styles.withdrawButton}+ >+ 申请提现+ </Button>+ </div>+ </Card>+ <Card className={styles.tableCard} bordered={false}>+ <Table+ columns={columns}+ dataSource={walletAccountList}+ rowKey="id"+ loading={loading}+ pagination={false}+ className={styles.table}+ />+ </Card>+ <Modal+ title="申请提现"+ open={isWithdrawModalVisible}+ onCancel={() => setIsWithdrawModalVisible(false)}+ footer={null}+ className={styles.modal}+ >+ <Form form={form} onFinish={handleWithdraw}>+ <Form.Item+ name="amount"+ label="提现金额"+ rules={[+ { required: true, message: '请输入提现金额' },+ { type: 'number', message: '请输入有效的金额' },+ { min: 0, message: '提现金额必须大于0' }+ ]}+ >+ <Input type="number" placeholder="请输入提现金额" className={styles.input} />+ </Form.Item>+ <Form.Item>+ <Button type="primary" htmlType="submit" block>+ 提交+ </Button>+ </Form.Item>+ </Form>+ </Modal></div>);}