Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
我的qianbao
bulaienaofutuojiesenzhang25ce1b5d3bca
diff --git a/@types/resources.d.ts b/@types/resources.d.tsindex ef278b82..6ce5b11d 100644--- a/@types/resources.d.ts+++ b/@types/resources.d.ts@@ -695,6 +695,7 @@ interface Resources {"status": "状态","updateTime": "更新时间","confirmWithdraw": "确认提现申请",+ "myWallet": "我的钱包","cancel": "取消","confirm": "确认提现","withdrawAmount": "提现金额",diff --git a/src/api/userWalletAccount.ts b/src/api/userWalletAccount.tsnew file mode 100644index 00000000..dbabbb0c--- /dev/null+++ b/src/api/userWalletAccount.ts@@ -0,0 +1,43 @@+import http from "@/utils/request";++export type WalletType = "ZFB" | "WX_PAY";++export interface UserWalletAccountCreateDto {+ userId: string;+ mail: string; // email+ userName?: string;+ account: string;+ cardNum?: string;+ phone?: string;+ type: WalletType;+}++export interface UserWalletAccount extends UserWalletAccountCreateDto {+ _id: string;+ createdAt?: string;+ updatedAt?: string;+}++export function createUserWalletAccount(data: UserWalletAccountCreateDto) {+ return http.post<UserWalletAccount>("userWalletAccount", data);+}++export function updateUserWalletAccount(id: string, data: Partial<UserWalletAccountCreateDto>) {+ return http.put<UserWalletAccount>("userWalletAccount", { id, ...data });+}++export function deleteUserWalletAccount(id: string) {+ return http.delete<null>(`userWalletAccount/${id}`);+}++export function getUserWalletAccountInfo(id: string) {+ return http.get<UserWalletAccount>(`userWalletAccount/info/${id}`);+}++export function getUserWalletAccountList(pageNo: number, pageSize: number) {+ return http.get<{ list: UserWalletAccount[]; total: number }>(`userWalletAccount/list/${pageNo}/${pageSize}`);+}++export const EMAIL_REGEX = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;++diff --git a/src/app/[lng]/income/page.tsx b/src/app/[lng]/income/page.tsxindex 24444a9f..13f4b31f 100644--- a/src/app/[lng]/income/page.tsx+++ b/src/app/[lng]/income/page.tsx@@ -3,7 +3,7 @@import { useEffect, useState } from "react";import { Card, Table, Button, message, Modal, Tabs, Tag, Space, Popconfirm, Descriptions, Input, Select } from "antd";import { DollarOutlined, HistoryOutlined, WalletOutlined, CheckCircleOutlined, ClockCircleOutlined, CloseCircleOutlined } from "@ant-design/icons";-import { useRouter } from "next/navigation";+import { useParams, useRouter } from "next/navigation";import { useUserStore } from "@/store/user";import { apiGetIncomeList, apiSubmitWithdraw } from "@/api/income";import { apiGetWithdrawRecordList } from "@/api/withdraw";@@ -17,6 +17,7 @@ const { Option } = Select;export default function IncomePage() {const router = useRouter();+ const { lng } = useParams();const { userInfo, token } = useUserStore();const { t } = useTransClient('income');@@ -278,6 +279,11 @@ export default function IncomePage() {<div className={styles.balanceAmount}>¥ {userInfo?.income || 0}</div></div></div>+ <div style={{ marginLeft: 12 }}>+ <Button type="primary" onClick={() => router.push(`/${lng}/wallet`)}>+ {t('myWallet')}+ </Button>+ </div></div></div></div>diff --git a/src/app/[lng]/wallet/page.tsx b/src/app/[lng]/wallet/page.tsxnew file mode 100644index 00000000..da30f0e9--- /dev/null+++ b/src/app/[lng]/wallet/page.tsx@@ -0,0 +1,179 @@+"use client";++import { useEffect, useMemo, useState } from "react";+import { Button, Card, Form, Input, Modal, Select, Table, message, Popconfirm } from "antd";+import { useTransClient } from "@/app/i18n/client";+import { useParams } from "next/navigation";+import { useUserStore } from "@/store/user";+import {+ createUserWalletAccount,+ deleteUserWalletAccount,+ getUserWalletAccountList,+ updateUserWalletAccount,+ EMAIL_REGEX,+ UserWalletAccount,+ UserWalletAccountCreateDto,+} from "@/api/userWalletAccount";++const { Option } = Select;++export default function WalletPage() {+ const { t } = useTransClient("wallet");+ const { lng } = useParams();+ const { userInfo } = useUserStore();++ const [list, setList] = useState<UserWalletAccount[]>([]);+ const [loading, setLoading] = useState(false);+ const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 });++ const [form] = Form.useForm<UserWalletAccountCreateDto>();+ const [modalOpen, setModalOpen] = useState(false);+ const [editing, setEditing] = useState<UserWalletAccount | null>(null);+ const [submitting, setSubmitting] = useState(false);++ const columns = useMemo(+ () => [+ { title: t("columns.userName"), dataIndex: "userName", key: "userName" },+ { title: t("columns.mail"), dataIndex: "mail", key: "mail" },+ { title: t("columns.account"), dataIndex: "account", key: "account" },+ { title: t("columns.type"), dataIndex: "type", key: "type", render: (v: string) => (v === "ZFB" ? t("types.ZFB") : t("types.WX_PAY")) },+ { title: t("columns.phone"), dataIndex: "phone", key: "phone" },+ { title: t("columns.cardNum"), dataIndex: "cardNum", key: "cardNum" },+ {+ title: t("columns.actions"),+ key: "actions",+ render: (_: any, record: UserWalletAccount) => (+ <>+ <Button size="small" type="link" onClick={() => onEdit(record)}>{t("actions.edit")}</Button>+ <Popconfirm title={t("actions.deleteConfirm")} onConfirm={() => onDelete(record)}>+ <Button size="small" type="link" danger>{t("actions.delete")}</Button>+ </Popconfirm>+ </>+ )+ }+ ],+ [t]+ );++ useEffect(() => {+ fetchList(1, 10);+ }, []);++ async function fetchList(pageNo: number, pageSize: number) {+ setLoading(true);+ try {+ const res = await getUserWalletAccountList(pageNo, pageSize);+ if (res?.data) {+ setList(res.data.list || []);+ setPagination({ current: pageNo, pageSize, total: res.data.total || 0 });+ }+ } finally {+ setLoading(false);+ }+ }++ function openCreate() {+ setEditing(null);+ form.resetFields();+ form.setFieldsValue({ userId: userInfo?._id || "" } as any);+ setModalOpen(true);+ }++ function onEdit(record: UserWalletAccount) {+ setEditing(record);+ form.setFieldsValue({+ userId: record.userId,+ mail: record.mail,+ userName: record.userName,+ account: record.account,+ cardNum: record.cardNum,+ phone: record.phone,+ type: record.type,+ });+ setModalOpen(true);+ }++ async function onDelete(record: UserWalletAccount) {+ const res = await deleteUserWalletAccount(record._id);+ if (res) {+ message.success(t("messages.deleteSuccess"));+ fetchList(pagination.current, pagination.pageSize);+ }+ }++ async function onSubmit() {+ try {+ const values = await form.validateFields();+ setSubmitting(true);+ if (editing) {+ const res = await updateUserWalletAccount(editing._id, values);+ if (res) message.success(t("messages.updateSuccess"));+ } else {+ const res = await createUserWalletAccount(values);+ if (res) message.success(t("messages.createSuccess"));+ }+ setModalOpen(false);+ fetchList(pagination.current, pagination.pageSize);+ } finally {+ setSubmitting(false);+ }+ }++ return (+ <div style={{ padding: 16 }}>+ <Card title={t("title")} extra={<Button type="primary" onClick={openCreate}>{t("actions.create")}</Button>}>+ <Table+ rowKey="_id"+ columns={columns as any}+ dataSource={list}+ loading={loading}+ pagination={{+ current: pagination.current,+ pageSize: pagination.pageSize,+ total: pagination.total,+ showSizeChanger: true,+ onChange: (p, s) => fetchList(p, s || 10),+ }}+ />+ </Card>++ <Modal+ open={modalOpen}+ title={editing ? t("dialogs.editTitle") : t("dialogs.createTitle")}+ onCancel={() => setModalOpen(false)}+ onOk={onSubmit}+ confirmLoading={submitting}+ destroyOnClose+ >+ <Form form={form} layout="vertical" preserve={false}>+ <Form.Item name="userId" label={t("form.userId")} rules={[{ required: true, message: t("form.required") }]}>+ <Input disabled placeholder={t("form.userIdPlaceholder")} />+ </Form.Item>+ <Form.Item name="mail" label={t("form.mail")} rules={[{ required: true, pattern: EMAIL_REGEX, message: t("form.mailInvalid") }]}>+ <Input placeholder={t("form.mailPlaceholder")} />+ </Form.Item>+ <Form.Item name="userName" label={t("form.userName")}>+ <Input placeholder={t("form.userNamePlaceholder")} />+ </Form.Item>+ <Form.Item name="account" label={t("form.account")} rules={[{ required: true, message: t("form.required") }]}>+ <Input placeholder={t("form.accountPlaceholder")} />+ </Form.Item>+ <Form.Item name="cardNum" label={t("form.cardNum")}>+ <Input placeholder={t("form.cardNumPlaceholder")} />+ </Form.Item>+ <Form.Item name="phone" label={t("form.phone")}>+ <Input placeholder={t("form.phonePlaceholder")} />+ </Form.Item>+ <Form.Item name="type" label={t("form.type")} rules={[{ required: true, message: t("form.required") }]}>+ <Select placeholder={t("form.typePlaceholder")}>+ <Option value="ZFB">{t("types.ZFB")}</Option>+ <Option value="WX_PAY">{t("types.WX_PAY")}</Option>+ </Select>+ </Form.Item>+ </Form>+ </Modal>+ </div>+ );+}++diff --git a/src/app/i18n/locales/zh-CN/income.json b/src/app/i18n/locales/zh-CN/income.jsonindex 2b5990a5..42d513ba 100644--- a/src/app/i18n/locales/zh-CN/income.json+++ b/src/app/i18n/locales/zh-CN/income.json@@ -41,5 +41,6 @@"noWithdrawRecords": "暂无提现记录","loading": "加载中...","totalRecords": "共 {{total}} 条记录"- }+ },+ "myWallet": "我的钱包"}diff --git a/src/app/i18n/locales/zh-CN/wallet.json b/src/app/i18n/locales/zh-CN/wallet.jsonnew file mode 100644index 00000000..84571d9f--- /dev/null+++ b/src/app/i18n/locales/zh-CN/wallet.json@@ -0,0 +1,51 @@+{+ "title": "我的钱包",+ "columns": {+ "userName": "真实姓名",+ "mail": "邮箱",+ "account": "账号",+ "type": "类型",+ "phone": "手机号",+ "cardNum": "身份证号",+ "actions": "操作"+ },+ "types": {+ "ZFB": "支付宝",+ "WX_PAY": "微信支付"+ },+ "actions": {+ "create": "新增账户",+ "edit": "编辑",+ "delete": "删除",+ "deleteConfirm": "确认删除该钱包账户?"+ },+ "dialogs": {+ "createTitle": "新增钱包账户",+ "editTitle": "编辑钱包账户"+ },+ "form": {+ "userId": "用户ID",+ "userIdPlaceholder": "自动填充当前用户ID",+ "mail": "邮箱",+ "mailPlaceholder": "请输入邮箱",+ "mailInvalid": "请输入有效的邮箱地址",+ "userName": "真实姓名",+ "userNamePlaceholder": "请输入真实姓名(可选)",+ "account": "账号",+ "accountPlaceholder": "请输入收款账号",+ "cardNum": "身份证号",+ "cardNumPlaceholder": "请输入身份证号(可选)",+ "phone": "手机号",+ "phonePlaceholder": "请输入绑定手机号(可选)",+ "type": "类型",+ "typePlaceholder": "请选择类型",+ "required": "必填项"+ },+ "messages": {+ "createSuccess": "创建成功",+ "updateSuccess": "更新成功",+ "deleteSuccess": "删除成功"+ }+}++