feat: pay demo
This commit is contained in:
135
apps/web-antd/src/views/pay/demo/withdraw/data.ts
Normal file
135
apps/web-antd/src/views/pay/demo/withdraw/data.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { DICT_TYPE } from '#/utils';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'subject',
|
||||
label: '提现标题',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'price',
|
||||
label: '提现金额',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
min: 1,
|
||||
precision: 2,
|
||||
step: 0.01,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'type',
|
||||
label: '提现类型',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '支付宝', value: 1 },
|
||||
{ label: '微信余额', value: 2 },
|
||||
{ label: '钱包余额', value: 3 },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'userName',
|
||||
label: '收款人姓名',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'userAccount',
|
||||
label: '收款人账号',
|
||||
rules: 'required',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '提现单编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'subject',
|
||||
title: '提现标题',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '提现类型',
|
||||
minWidth: 90,
|
||||
slots: { default: 'type' },
|
||||
},
|
||||
{
|
||||
field: 'price',
|
||||
title: '提现金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatNumber',
|
||||
},
|
||||
{
|
||||
field: 'userName',
|
||||
title: '收款人姓名',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'userAccount',
|
||||
title: '收款人账号',
|
||||
minWidth: 250,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '提现状态',
|
||||
minWidth: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'payTransferId',
|
||||
title: '转账单号',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'transferChannelCode',
|
||||
title: '转账渠道',
|
||||
minWidth: 180,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.PAY_CHANNEL_CODE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'transferTime',
|
||||
title: '转账时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'transferErrorMsg',
|
||||
title: '转账失败原因',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
145
apps/web-antd/src/views/pay/demo/withdraw/index.vue
Normal file
145
apps/web-antd/src/views/pay/demo/withdraw/index.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { DemoWithdrawApi } from '#/api/pay/demo/withdraw';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
getDemoWithdrawPage,
|
||||
transferDemoWithdraw,
|
||||
} from '#/api/pay/demo/withdraw';
|
||||
import { DocAlert } from '#/components/doc-alert';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建提现单 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 处理转账操作 */
|
||||
async function handleTransfer(row: DemoWithdrawApi.Withdraw) {
|
||||
const hideLoading = message.loading({
|
||||
content: '转账中,请稍后...',
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
const payTransferId = await transferDemoWithdraw(row.id as number);
|
||||
message.success({
|
||||
content: `转账提交成功,转账单号:${payTransferId}`,
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getDemoWithdrawPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<DemoWithdrawApi.Withdraw>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="支付宝转账接入"
|
||||
url="https://doc.iocoder.cn/pay/alipay-transfer-demo/"
|
||||
/>
|
||||
<DocAlert
|
||||
title="微信转账接入"
|
||||
url="https://doc.iocoder.cn/pay/wx-transfer-demo/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="示例提现单列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['示例提现单']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
onClick: handleCreate,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #type="{ row }">
|
||||
<Tag v-if="row.type === 1">支付宝</Tag>
|
||||
<Tag v-else-if="row.type === 2">微信余额</Tag>
|
||||
<Tag v-else-if="row.type === 3">钱包余额</Tag>
|
||||
</template>
|
||||
<template #price="{ row }">
|
||||
<span>¥{{ (row.price / 100.0).toFixed(2) }}</span>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag v-if="row.status === 0 && !row.payTransferId" type="warning">
|
||||
等待转账
|
||||
</Tag>
|
||||
<Tag v-else-if="row.status === 0 && row.payTransferId" type="info">
|
||||
转账中
|
||||
</Tag>
|
||||
<Tag v-else-if="row.status === 10" type="success"> 转账成功 </Tag>
|
||||
<Tag v-else-if="row.status === 20" type="danger"> 转账失败 </Tag>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '发起转账',
|
||||
type: 'link',
|
||||
ifShow: row.status === 0 && !row.payTransferId,
|
||||
onClick: handleTransfer.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '重新转账',
|
||||
type: 'link',
|
||||
ifShow: row.status === 20,
|
||||
onClick: handleTransfer.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
55
apps/web-antd/src/views/pay/demo/withdraw/modules/form.vue
Normal file
55
apps/web-antd/src/views/pay/demo/withdraw/modules/form.vue
Normal file
@@ -0,0 +1,55 @@
|
||||
<script lang="ts" setup>
|
||||
import type { DemoWithdrawApi } from '#/api/pay/demo/withdraw';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createDemoWithdraw } from '#/api/pay/demo/withdraw';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as DemoWithdrawApi.Withdraw;
|
||||
try {
|
||||
await createDemoWithdraw(data);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-[600px]" :title="$t('ui.actionTitle.create', ['示例提现单'])">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
Reference in New Issue
Block a user