feat:【antd】【erp 系统】supplier 迁移

This commit is contained in:
YunaiV
2025-10-03 10:12:00 +08:00
parent eeb1f1ebf9
commit 85b6d0c4d6
3 changed files with 36 additions and 47 deletions

View File

@@ -1,9 +1,11 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; 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 { getDictOptions } from '@vben/hooks';
import { z } from '#/adapter/form';
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@@ -19,10 +21,10 @@ export function useFormSchema(): VbenFormSchema[] {
fieldName: 'name', fieldName: 'name',
label: '供应商名称', label: '供应商名称',
component: 'Input', component: 'Input',
rules: 'required',
componentProps: { componentProps: {
placeholder: '请输入供应商名称', placeholder: '请输入供应商名称',
}, },
rules: 'required',
}, },
{ {
fieldName: 'contact', fieldName: 'contact',
@@ -70,9 +72,11 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'RadioGroup', component: 'RadioGroup',
componentProps: { componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
}, },
rules: 'required', rules: 'required',
defaultValue: 0, defaultValue: CommonStatusEnum.ENABLE,
}, },
{ {
fieldName: 'sort', fieldName: 'sort',
@@ -80,11 +84,8 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'InputNumber', component: 'InputNumber',
componentProps: { componentProps: {
placeholder: '请输入排序', placeholder: '请输入排序',
precision: 0,
class: 'w-full',
}, },
rules: 'required', rules: 'required',
defaultValue: 0,
}, },
{ {
fieldName: 'taxNo', fieldName: 'taxNo',
@@ -102,7 +103,6 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入税率', placeholder: '请输入税率',
min: 0, min: 0,
precision: 2, precision: 2,
class: 'w-full',
}, },
}, },
{ {
@@ -206,7 +206,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'status', field: 'status',
title: '状态', title: '状态',
width: 100, minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS }, props: { type: DICT_TYPE.COMMON_STATUS },
@@ -215,7 +215,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'sort', field: 'sort',
title: '排序', title: '排序',
width: 80, minWidth: 80,
}, },
{ {
field: 'remark', field: 'remark',
@@ -224,10 +224,9 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
showOverflow: 'tooltip', showOverflow: 'tooltip',
}, },
{ {
field: 'actions',
title: '操作', title: '操作',
width: 130,
fixed: 'right', fixed: 'right',
width: 160,
slots: { default: 'actions' }, slots: { default: 'actions' },
}, },
]; ];

View File

@@ -22,18 +22,18 @@ import SupplierForm from './modules/form.vue';
defineOptions({ name: 'ErpSupplier' }); defineOptions({ name: 'ErpSupplier' });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 添加供应商 */ /** 创建供应商 */
function handleCreate() { function handleCreate() {
formModalApi.setData({ type: 'create' }).open(); formModalApi.setData(null).open();
} }
/** 编辑供应商 */ /** 编辑供应商 */
function handleEdit(row: ErpSupplierApi.Supplier) { function handleEdit(row: ErpSupplierApi.Supplier) {
formModalApi.setData({ type: 'update', id: row.id }).open(); formModalApi.setData(row).open();
} }
/** 删除供应商 */ /** 删除供应商 */
@@ -44,10 +44,8 @@ async function handleDelete(row: ErpSupplierApi.Supplier) {
}); });
try { try {
await deleteSupplier(row.id!); await deleteSupplier(row.id!);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]), handleRefresh();
});
onRefresh();
} catch { } catch {
hideLoading(); hideLoading();
} }
@@ -85,6 +83,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -103,7 +102,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
/> />
</template> </template>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="供应商列表"> <Grid table-title="供应商列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@@ -130,14 +129,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
<TableAction <TableAction
:actions="[ :actions="[
{ {
label: '编辑', label: $t('common.edit'),
type: 'link', type: 'link',
icon: ACTION_ICON.EDIT, icon: ACTION_ICON.EDIT,
auth: ['erp:supplier:update'], auth: ['erp:supplier:update'],
onClick: handleEdit.bind(null, row), onClick: handleEdit.bind(null, row),
}, },
{ {
label: '删除', label: $t('common.delete'),
type: 'link', type: 'link',
danger: true, danger: true,
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ErpSupplierApi } from '#/api/erp/purchase/supplier'; import type { ErpSupplierApi } from '#/api/erp/purchase/supplier';
import { ref } from 'vue'; import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
@@ -18,9 +18,12 @@ import { $t } from '#/locales';
import { useFormSchema } from '../data'; import { useFormSchema } from '../data';
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
const formData = ref<ErpSupplierApi.Supplier>();
const formType = ref<'create' | 'update'>('create'); const getTitle = computed(() => {
const supplierId = ref<number>(); return formData.value?.id
? $t('ui.actionTitle.edit', ['供应商'])
: $t('ui.actionTitle.create', ['供应商']);
});
const [Form, formApi] = useVbenForm({ const [Form, formApi] = useVbenForm({
commonConfig: { commonConfig: {
@@ -45,39 +48,30 @@ const [Modal, modalApi] = useVbenModal({
// 提交表单 // 提交表单
const data = (await formApi.getValues()) as ErpSupplierApi.Supplier; const data = (await formApi.getValues()) as ErpSupplierApi.Supplier;
try { try {
if (formType.value === 'create') { await (formData.value?.id ? updateSupplier(data) : createSupplier(data));
await createSupplier(data);
message.success($t('ui.actionMessage.createSuccess'));
} else {
await updateSupplier(data);
message.success($t('ui.actionMessage.updateSuccess'));
}
// 关闭并提示 // 关闭并提示
await modalApi.close(); await modalApi.close();
emit('success'); emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally { } finally {
modalApi.unlock(); modalApi.unlock();
} }
}, },
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (!isOpen) { if (!isOpen) {
formData.value = undefined;
return; return;
} }
// 加载数据 // 加载数据
const data = modalApi.getData<{ id?: number; type: 'create' | 'update' }>(); const data = modalApi.getData<ErpSupplierApi.Supplier>();
if (!data) { if (!data || !data.id) {
return; return;
} }
formType.value = data.type;
supplierId.value = data.id;
modalApi.lock(); modalApi.lock();
try { try {
if (data.type === 'update' && data.id) { formData.value = await getSupplier(data.id);
// 编辑模式,加载数据 // 设置到 values
const supplierData = await getSupplier(data.id); await formApi.setValues(formData.value);
await formApi.setValues(supplierData);
}
} finally { } finally {
modalApi.unlock(); modalApi.unlock();
} }
@@ -90,10 +84,7 @@ defineExpose({
</script> </script>
<template> <template>
<Modal <Modal :title="getTitle" class="w-1/2">
:title="formType === 'create' ? '新增供应商' : '编辑供应商'"
class="w-3/5"
>
<Form class="mx-4" /> <Form class="mx-4" />
</Modal> </Modal>
</template> </template>