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: { componentProps: {
placeholder: '请输入分类编码', placeholder: '请输入分类编码',
}, },
rules: z.string().regex(/^[A-Z]+$/, '分类编码必须为大写字母'), rules: 'required',
}, },
{ {
fieldName: 'sort', fieldName: 'sort',
@@ -71,7 +71,6 @@ export function useFormSchema(): VbenFormSchema[] {
}, },
rules: 'required', rules: 'required',
}, },
{ {
fieldName: 'status', fieldName: 'status',
label: '状态', 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'] { export function useGridColumns(): VxeTableGridOptions<ErpProductCategoryApi.ProductCategory>['columns'] {
return [ return [

View File

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

View File

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