feat:【antd】【ele】【pay 支付】pay/wallet/package 迁移 antd、ele 版本
This commit is contained in:
@@ -1,50 +1,66 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '套餐名',
|
||||
label: '套餐名称',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: '请输入套餐名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'payPrice',
|
||||
label: '支付金额(元)',
|
||||
component: 'InputNumber',
|
||||
rules: 'required',
|
||||
rules: z.number().min(0, '支付金额不能小于0'),
|
||||
componentProps: {
|
||||
min: 0,
|
||||
precision: 2,
|
||||
step: 0.01,
|
||||
placeholder: '请输入支付金额',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'bonusPrice',
|
||||
label: '赠送金额(元)',
|
||||
component: 'InputNumber',
|
||||
rules: 'required',
|
||||
rules: z.number().min(0, '赠送金额不能小于0'),
|
||||
componentProps: {
|
||||
min: 0,
|
||||
precision: 2,
|
||||
step: 0.01,
|
||||
placeholder: '请输入赠送金额',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '开启状态',
|
||||
component: 'RadioGroup',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -56,14 +72,19 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'name',
|
||||
label: '套餐名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入套餐名称',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -71,8 +92,8 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
...getRangePickerDefaultProps(),
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -83,25 +104,30 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
title: '套餐编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '套餐名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'payPrice',
|
||||
title: '支付金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatFenToYuanAmount',
|
||||
},
|
||||
{
|
||||
field: 'bonusPrice',
|
||||
title: '赠送金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatFenToYuanAmount',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
@@ -110,11 +136,12 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { WalletRechargePackageApi } from '#/api/pay/wallet/rechargePackage';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
@@ -7,8 +8,8 @@ import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePackage,
|
||||
getPackagePage,
|
||||
deleteWalletRechargePackage,
|
||||
getWalletRechargePackagePage,
|
||||
} from '#/api/pay/wallet/rechargePackage';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
@@ -21,7 +22,7 @@ const [FormModal, formModalApi] = useVbenModal({
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
@@ -31,19 +32,19 @@ function handleCreate() {
|
||||
}
|
||||
|
||||
/** 编辑套餐 */
|
||||
function handleEdit(row: any) {
|
||||
function handleEdit(row: WalletRechargePackageApi.WalletRechargePackage) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除套餐 */
|
||||
async function handleDelete(row: any) {
|
||||
async function handleDelete(row: WalletRechargePackageApi.WalletRechargePackage) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deletePackage(row.id as number);
|
||||
await deleteWalletRechargePackage(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
onRefresh();
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
@@ -60,7 +61,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPackagePage({
|
||||
return await getWalletRechargePackagePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
@@ -70,18 +71,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<any>,
|
||||
} as VxeTableGridOptions<WalletRechargePackageApi.WalletRechargePackage>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<FormModal @success="onRefresh" />
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="充值套餐列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
|
||||
@@ -10,16 +10,16 @@ import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createPackage,
|
||||
getPackage,
|
||||
updatePackage,
|
||||
createWalletRechargePackage,
|
||||
getWalletRechargePackage,
|
||||
updateWalletRechargePackage,
|
||||
} from '#/api/pay/wallet/rechargePackage';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<WalletRechargePackageApi.Package>();
|
||||
const formData = ref<WalletRechargePackageApi.WalletRechargePackage>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['充值套餐'])
|
||||
@@ -32,7 +32,7 @@ const [Form, formApi] = useVbenForm({
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
labelWidth: 100,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
@@ -48,12 +48,14 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data =
|
||||
(await formApi.getValues()) as WalletRechargePackageApi.Package;
|
||||
(await formApi.getValues()) as WalletRechargePackageApi.WalletRechargePackage;
|
||||
try {
|
||||
// 转换金额单位
|
||||
data.payPrice = yuanToFen(data.payPrice);
|
||||
data.bonusPrice = yuanToFen(data.bonusPrice);
|
||||
await (formData.value?.id ? updatePackage(data) : createPackage(data));
|
||||
await (formData.value?.id
|
||||
? updateWalletRechargePackage(data)
|
||||
: createWalletRechargePackage(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
@@ -68,13 +70,14 @@ const [Modal, modalApi] = useVbenModal({
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<WalletRechargePackageApi.Package>();
|
||||
const data =
|
||||
modalApi.getData<WalletRechargePackageApi.WalletRechargePackage>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getPackage(data.id);
|
||||
formData.value = await getWalletRechargePackage(data.id);
|
||||
// 转换金额单位
|
||||
formData.value.payPrice = Number.parseFloat(
|
||||
fenToYuan(formData.value.payPrice),
|
||||
@@ -92,7 +95,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-2/5" :title="getTitle">
|
||||
<Modal :title="getTitle" class="w-1/4">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user