feat:【antd】【erp 系统】product category 迁移

This commit is contained in:
YunaiV
2025-10-03 08:50:43 +08:00
parent 76b00821cb
commit bfbf97874c
3 changed files with 75 additions and 33 deletions

View File

@@ -58,7 +58,7 @@ export function useFormSchema(): VbenFormSchema[] {
componentProps: {
placeholder: '请输入分类编码',
},
rules: z.string().regex(/^[A-Z]+$/, '分类编码必须为大写字母'),
rules: 'required',
},
{
fieldName: 'sort',
@@ -71,7 +71,6 @@ export function useFormSchema(): VbenFormSchema[] {
},
rules: 'required',
},
{
fieldName: 'status',
label: '状态',
@@ -86,6 +85,31 @@ export function useFormSchema(): VbenFormSchema[] {
];
}
/** 查询表单 */
export function useQueryFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'name',
label: '分类名称',
componentProps: {
placeholder: '请输入分类名称',
allowClear: true,
},
},
{
component: 'Select',
fieldName: 'status',
label: '开启状态',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
placeholder: '请选择开启状态',
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<ErpProductCategoryApi.ProductCategory>['columns'] {
return [

View File

@@ -5,17 +5,19 @@ import type { ErpProductCategoryApi } from '#/api/erp/product/category';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteProductCategory,
exportProductCategory,
getProductCategoryList,
} from '#/api/erp/product/category';
import { $t } from '#/locales';
import { useGridColumns } from './data';
import { useGridColumns, useQueryFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
@@ -25,16 +27,22 @@ const [FormModal, formModalApi] = useVbenModal({
/** 切换树形展开/收缩状态 */
const isExpanded = ref(true);
function toggleExpand() {
function handleExpand() {
isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value);
}
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportProductCategory(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '产品分类.xls', source: data });
}
/** 创建分类 */
function handleCreate() {
formModalApi.setData(null).open();
@@ -58,29 +66,30 @@ async function handleDelete(row: ErpProductCategoryApi.ProductCategory) {
});
try {
await deleteProductCategory(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useQueryFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
proxyConfig: {
ajax: {
query: async () => {
return await getProductCategoryList();
},
},
},
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_, formValues) => {
return await getProductCategoryList(formValues);
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
@@ -90,11 +99,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true,
},
treeConfig: {
transform: true,
rowField: 'id',
parentField: 'parentId',
rowField: 'id',
transform: true,
expandAll: true,
accordion: false,
reserve: true,
},
} as VxeTableGridOptions<ErpProductCategoryApi.ProductCategory>,
});
@@ -108,7 +117,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
url="https://doc.iocoder.cn/erp/product/"
/>
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="产品分类列表">
<template #toolbar-tools>
<TableAction
@@ -120,10 +130,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['erp:product-category:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['erp:product-category:export'],
onClick: handleExport,
},
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: toggleExpand,
onClick: handleExpand,
},
]"
/>
@@ -151,7 +168,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['erp:product-category:delete'],
ifShow: !(row.children && row.children.length > 0),
disabled: row.children && row.children.length > 0,
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),

View File

@@ -66,21 +66,22 @@ const [Modal, modalApi] = useVbenModal({
return;
}
// 加载数据
let data = modalApi.getData<ErpProductCategoryApi.ProductCategory>();
if (!data) {
const data = modalApi.getData<ErpProductCategoryApi.ProductCategory>();
if (!data || !data.id) {
// 设置上级
await formApi.setValues(data);
return;
}
if (data.id) {
modalApi.lock();
try {
data = await getProductCategory(data.id);
} finally {
modalApi.unlock();
modalApi.lock();
try {
formData.value = await getProductCategory(data.id);
// 设置到 values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
// 设置到 values
formData.value = data;
await formApi.setValues(formData.value);
},
});
</script>