feat:搭建基础模块,新增物流信息、基础分类功能

This commit is contained in:
zhouz
2026-07-14 17:40:15 +08:00
parent 11fe65a437
commit f6950471bf
56 changed files with 3922 additions and 937 deletions

View File

@@ -46,6 +46,7 @@
"@videojs-player/vue": "catalog:",
"@vueuse/core": "catalog:",
"@vueuse/integrations": "catalog:",
"ant-design-vue": "catalog:",
"antdv-next": "catalog:",
"benz-amr-recorder": "catalog:",
"bpmn-js": "catalog:",

View File

@@ -0,0 +1,68 @@
import { requestClient } from '#/api/request';
export namespace BaseClassStandardApi {
/** 基础数据分类标准信息 */
export interface ClassStandard {
classId?: number;
className: string;
parentClassId?: number;
status: number;
sort: number;
classCode?: string;
classDesc?: string;
classLevel?: string;
createTime?: Date;
children?: ClassStandard[];
}
}
/** 查询分类标准(精简)列表 */
export async function getSimpleClassStandardList() {
return requestClient.get<BaseClassStandardApi.ClassStandard[]>(
'/base/class-standard/simple-list',
);
}
/** 查询分类标准列表(树形) */
export async function getClassStandardList() {
return requestClient.get<BaseClassStandardApi.ClassStandard[]>(
'/base/class-standard/list',
);
}
/** 查询分类标准详情 */
export async function getClassStandard(id: number) {
return requestClient.get<BaseClassStandardApi.ClassStandard>(
`/base/class-standard/get?id=${id}`,
);
}
/** 新增分类标准 */
export async function createClassStandard(data: BaseClassStandardApi.ClassStandard) {
return requestClient.post('/base/class-standard/create', data);
}
/** 修改分类标准 */
export async function updateClassStandard(data: BaseClassStandardApi.ClassStandard) {
return requestClient.put('/base/class-standard/update', data);
}
/** 删除分类标准 */
export async function deleteClassStandard(id: number) {
return requestClient.delete(`/base/class-standard/delete?id=${id}`);
}
/** 根据分类编码获取分支及子分类(用于下拉框) */
export async function getClassStandardListByCode(classCode: string) {
return requestClient.get<BaseClassStandardApi.ClassStandard[]>(
'/base/class-standard/list-by-code',
{ params: { classCode } },
);
}
/** 批量删除分类标准 */
export async function deleteClassStandardList(ids: number[]) {
return requestClient.delete(
`/base/class-standard/delete-list?ids=${ids.join(',')}`,
);
}

View File

@@ -0,0 +1,64 @@
import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';
import { requestClient } from '#/api/request';
export namespace BaseMaterialBaseApi {
/** 物料基本信息信息 */
export interface MaterialBase {
materialCode?: string; // 物料编码
materialName?: string; // 物料名称
materialSpec: string; // 规格
materialModel: string; // 型号
englishName: string; // 外文名称
baseUnitId?: number; // 基本计量单位
assUnitId: number; // 辅助计量单位
materialTypeId: number; // 物料分类
lenUnitId: number; // 长度单位
weightUnitId: number; // 重量单位
isUsed?: string; // 是否启用
extId: string; // 外部标识
}
}
/** 查询物料基本信息分页 */
export function getMaterialBasePage(params: PageParam) {
return requestClient.get<PageResult<BaseMaterialBaseApi.MaterialBase>>(
'/base/material-base/page',
{ params },
);
}
/** 查询物料基本信息详情 */
export function getMaterialBase(id: number) {
return requestClient.get<BaseMaterialBaseApi.MaterialBase>(
`/base/material-base/get?id=${id}`,
);
}
/** 新增物料基本信息 */
export function createMaterialBase(data: BaseMaterialBaseApi.MaterialBase) {
return requestClient.post('/base/material-base/create', data);
}
/** 修改物料基本信息 */
export function updateMaterialBase(data: BaseMaterialBaseApi.MaterialBase) {
return requestClient.put('/base/material-base/update', data);
}
/** 删除物料基本信息 */
export function deleteMaterialBase(id: number) {
return requestClient.delete(`/base/material-base/delete?id=${id}`);
}
/** 批量删除物料基本信息 */
export function deleteMaterialBaseList(ids: number[]) {
return requestClient.delete(
`/base/material-base/delete-list?ids=${ids.join(',')}`,
);
}
/** 导出物料基本信息 */
export function exportMaterialBase(params: any) {
return requestClient.download('/base/material-base/export-excel', { params });
}

View File

@@ -0,0 +1,139 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseClassStandardApi } from '#/api/base/classstandard';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { handleTree } from '@vben/utils';
import { z } from '#/adapter/form';
import { getClassStandardList } from '#/api/base/classstandard';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'classId',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'parentClassId',
label: '上级分类',
component: 'ApiTreeSelect',
componentProps: {
allowClear: true,
api: async () => {
const data = await getClassStandardList();
data.unshift({
classId: 0,
className: '顶级分类',
});
return handleTree(data, 'classId', 'parentClassId');
},
labelField: 'className',
valueField: 'classId',
childrenField: 'children',
placeholder: '请选择上级分类',
treeDefaultExpandAll: true,
},
rules: 'selectRequired',
},
{
fieldName: 'className',
label: '分类名称',
component: 'Input',
componentProps: {
placeholder: '请输入分类名称',
},
rules: 'required',
},
{
fieldName: 'classCode',
label: '分类编码',
component: 'Input',
componentProps: {
placeholder: '请输入分类编码',
},
},
{
fieldName: 'classDesc',
label: '分类简要描述',
component: 'Input',
componentProps: {
placeholder: '请输入分类简要描述',
},
},
{
fieldName: 'sort',
label: '显示顺序',
component: 'InputNumber',
componentProps: {
class: '!w-full',
min: 0,
placeholder: '请输入显示顺序',
},
rules: 'required',
},
{
fieldName: 'status',
label: '状态',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
},
rules: z.number().default(CommonStatusEnum.ENABLE),
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseClassStandardApi.ClassStandard>['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'className',
title: '分类名称',
minWidth: 200,
align: 'left',
fixed: 'left',
treeNode: true,
},
{
field: 'classCode',
title: '分类编码',
minWidth: 120,
},
{
field: 'sort',
title: '显示顺序',
minWidth: 100,
},
{
field: 'status',
title: '分类状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
},
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 220,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,199 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseClassStandardApi } from '#/api/base/classstandard';
import { ref } from 'vue';
import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'antdv-next';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteClassStandard,
deleteClassStandardList,
getClassStandardList,
} from '#/api/base/classstandard';
import { $t } from '#/locales';
import { useGridColumns } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 切换树形展开/收缩状态 */
const isExpanded = ref(true);
function handleExpand() {
isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value);
}
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建分类标准 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 添加下级分类 */
function handleAppend(row: BaseClassStandardApi.ClassStandard) {
formModalApi.setData({ parentClassId: row.classId }).open();
}
/** 编辑分类标准 */
function handleEdit(row: BaseClassStandardApi.ClassStandard) {
formModalApi.setData(row).open();
}
/** 删除分类标准 */
async function handleDelete(row: BaseClassStandardApi.ClassStandard) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.className]),
duration: 0,
});
try {
await deleteClassStandard(row.classId!);
message.success($t('ui.actionMessage.deleteSuccess', [row.className]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 批量删除分类标准 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteClassStandardList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: BaseClassStandardApi.ClassStandard[];
}) {
checkedIds.value = records.map((item) => item.classId!);
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useGridColumns(),
height: 'auto',
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async () => {
return await getClassStandardList();
},
},
},
rowConfig: {
keyField: 'classId',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
treeConfig: {
parentField: 'parentClassId',
rowField: 'classId',
transform: true,
expandAll: true,
reserve: true,
},
} as VxeTableGridOptions<BaseClassStandardApi.ClassStandard>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="handleRefresh" />
<Grid table-title="基础数据分类标准列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['分类标准']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['base:class-standard:create'],
onClick: handleCreate,
},
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: handleExpand,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['base:class-standard:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '新增下级',
type: 'link',
icon: ACTION_ICON.ADD,
auth: ['base:class-standard:create'],
onClick: handleAppend.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['base:class-standard:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['base:class-standard:delete'],
disabled: row.children && row.children.length > 0,
popConfirm: {
disabled: row.children && row.children.length > 0,
title: $t('ui.actionMessage.deleteConfirm', [row.className]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,90 @@
<script lang="ts" setup>
import type { BaseClassStandardApi } from '#/api/base/classstandard';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'antdv-next';
import { useVbenForm } from '#/adapter/form';
import {
createClassStandard,
getClassStandard,
updateClassStandard,
} from '#/api/base/classstandard';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<BaseClassStandardApi.ClassStandard>();
const getTitle = computed(() => {
return formData.value?.classId
? $t('ui.actionTitle.edit', ['分类标准'])
: $t('ui.actionTitle.create', ['分类标准']);
});
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 BaseClassStandardApi.ClassStandard;
try {
await (formData.value?.classId
? updateClassStandard(data)
: createClassStandard(data));
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
// 加载数据
const data = modalApi.getData<BaseClassStandardApi.ClassStandard>();
if (!data || !data.classId) {
// 设置上级分类
await formApi.setValues(data);
return;
}
modalApi.lock();
try {
formData.value = await getClassStandard(data.classId);
// 设置到 values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>

View File

@@ -0,0 +1,371 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseMaterialBaseApi } from '#/api/base/materialbase';
import type { BaseClassStandardApi } from '#/api/base/classstandard';
import { handleTree } from '@vben/utils';
import { z } from '#/adapter/form';
import { getClassStandardList, getClassStandardListByCode } from '#/api/base/classstandard';
import { getRangePickerDefaultProps } from '#/utils';
/** 分类名称映射表classId → className */
let categoryNameMap: Record<number, string> = {};
getClassStandardList().then((data) => {
if (data) {
data.forEach((item) => {
if (item.classId) {
categoryNameMap[item.classId] = item.className;
}
});
}
});
/** 获取物料分类的树形下拉数据 */
async function loadMaterialTypeTree() {
const data = await getClassStandardListByCode('0001');
if (!data || data.length === 0) {
return [];
}
return handleTree(data, 'classId', 'parentClassId');
}
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'materialId',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'materialCode',
label: '物料编码',
rules: 'required',
component: 'Input',
componentProps: {
placeholder: '请输入物料编码',
},
},
{
fieldName: 'materialName',
label: '物料名称',
rules: 'required',
component: 'Input',
componentProps: {
placeholder: '请输入物料名称',
},
},
{
fieldName: 'materialSpec',
label: '规格',
component: 'Input',
componentProps: {
placeholder: '请输入规格',
},
},
{
fieldName: 'materialModel',
label: '型号',
component: 'Input',
componentProps: {
placeholder: '请输入型号',
},
},
{
fieldName: 'englishName',
label: '外文名称',
component: 'Input',
componentProps: {
placeholder: '请输入外文名称',
},
},
{
fieldName: 'materialTypeId',
label: '物料分类',
component: 'ApiTreeSelect',
componentProps: {
api: loadMaterialTypeTree,
labelField: 'className',
valueField: 'classId',
childrenField: 'children',
placeholder: '请选择物料分类',
allowClear: true,
treeDefaultExpandAll: true,
},
},
{
fieldName: 'baseUnitId',
label: '基本计量单位',
rules: 'required',
component: 'Input',
componentProps: {
placeholder: '请输入基本计量单位',
},
},
{
fieldName: 'assUnitId',
label: '辅助计量单位',
component: 'Input',
componentProps: {
placeholder: '请输入辅助计量单位',
},
},
{
fieldName: 'lenUnitId',
label: '长度单位',
component: 'Input',
componentProps: {
placeholder: '请输入长度单位',
},
},
{
fieldName: 'weightUnitId',
label: '重量单位',
component: 'Input',
componentProps: {
placeholder: '请输入重量单位',
},
},
{
fieldName: 'isUsed',
label: '是否启用',
rules: 'required',
component: 'RadioGroup',
componentProps: {
options: [
{ label: '是', value: '1' },
{ label: '否', value: '0' },
],
buttonStyle: 'solid',
optionType: 'button',
},
},
{
fieldName: 'extId',
label: '外部标识',
component: 'Input',
componentProps: {
placeholder: '请输入外部标识',
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'materialCode',
label: '物料编码',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入物料编码',
},
},
{
fieldName: 'materialName',
label: '物料名称',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入物料名称',
},
},
{
fieldName: 'materialSpec',
label: '规格',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入规格',
},
},
{
fieldName: 'materialModel',
label: '型号',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入型号',
},
},
{
fieldName: 'englishName',
label: '外文名称',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入外文名称',
},
},
{
fieldName: 'materialTypeId',
label: '物料分类',
component: 'ApiTreeSelect',
componentProps: {
api: loadMaterialTypeTree,
labelField: 'className',
valueField: 'classId',
childrenField: 'children',
placeholder: '请选择物料分类',
allowClear: true,
treeDefaultExpandAll: true,
},
},
{
fieldName: 'baseUnitId',
label: '基本计量单位',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入基本计量单位',
},
},
{
fieldName: 'assUnitId',
label: '辅助计量单位',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入辅助计量单位',
},
},
{
fieldName: 'lenUnitId',
label: '长度单位',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入长度单位',
},
},
{
fieldName: 'weightUnitId',
label: '重量单位',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入重量单位',
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
allowClear: true,
},
},
{
fieldName: 'isUsed',
label: '是否启用',
component: 'Select',
componentProps: {
allowClear: true,
placeholder: '请选择',
options: [
{ label: '是', value: '1' },
{ label: '否', value: '0' },
],
},
},
{
fieldName: 'extId',
label: '外部标识',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入外部标识',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseMaterialBaseApi.MaterialBase>['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'materialCode',
title: '物料编码',
minWidth: 120,
},
{
field: 'materialName',
title: '物料名称',
minWidth: 200,
},
{
field: 'materialSpec',
title: '规格',
minWidth: 120,
},
{
field: 'materialModel',
title: '型号',
minWidth: 120,
},
{
field: 'englishName',
title: '外文名称',
minWidth: 120,
},
{
field: 'baseUnitId',
title: '基本计量单位',
minWidth: 120,
},
{
field: 'assUnitId',
title: '辅助计量单位',
minWidth: 120,
},
{
field: 'materialTypeId',
title: '物料分类',
minWidth: 150,
formatter: ({ cellValue }: { cellValue: number }) =>
categoryNameMap[cellValue] || cellValue || '-',
},
{
field: 'lenUnitId',
title: '长度单位',
minWidth: 120,
},
{
field: 'weightUnitId',
title: '重量单位',
minWidth: 120,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'isUsed',
title: '是否启用',
minWidth: 100,
formatter: ({ cellValue }: { cellValue: string }) =>
cellValue === '1' ? '是' : '否',
},
{
field: 'extId',
title: '外部标识',
minWidth: 120,
},
{
title: '操作',
width: 200,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,186 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseMaterialBaseApi } from '#/api/base/materialbase';
import { ref } from 'vue';
import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'antdv-next';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteMaterialBase,
deleteMaterialBaseList,
exportMaterialBase,
getMaterialBasePage,
} from '#/api/base/materialbase';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建物料基本信息 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑物料基本信息 */
function handleEdit(row: BaseMaterialBaseApi.MaterialBase) {
formModalApi.setData(row).open();
}
/** 删除物料基本信息 */
async function handleDelete(row: BaseMaterialBaseApi.MaterialBase) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.materialId]),
duration: 0,
});
try {
await deleteMaterialBase(row.materialId!);
message.success($t('ui.actionMessage.deleteSuccess', [row.materialId]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 批量删除物料基本信息 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteMaterialBaseList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: BaseMaterialBaseApi.MaterialBase[];
}) {
checkedIds.value = records.map((item) => item.materialId!);
}
/** 导出表格 */
async function handleExport() {
const data = await exportMaterialBase(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '物料基本信息.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getMaterialBasePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'materialId',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<BaseMaterialBaseApi.MaterialBase>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="handleRefresh" />
<Grid table-title="物料基本信息列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['物料基本信息']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['base:material-base:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['base:material-base:export'],
onClick: handleExport,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['base:material-base:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['base:material-base:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['base:material-base:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.materialId]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,82 @@
<script lang="ts" setup>
import type { BaseMaterialBaseApi } from '#/api/base/materialbase';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'antdv-next';
import { useVbenForm } from '#/adapter/form';
import { createMaterialBase, getMaterialBase, updateMaterialBase } from '#/api/base/materialbase';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<BaseMaterialBaseApi.MaterialBase>();
const getTitle = computed(() => {
return formData.value?.materialId
? $t('ui.actionTitle.edit', ['物料基本信息'])
: $t('ui.actionTitle.create', ['物料基本信息']);
});
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 BaseMaterialBaseApi.MaterialBase;
try {
await (formData.value?.materialId ? updateMaterialBase(data) : createMaterialBase(data));
// 关闭并提示
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
// 加载数据
const data = modalApi.getData<BaseMaterialBaseApi.MaterialBase>();
if (!data || !data.materialId) {
return;
}
modalApi.lock();
try {
formData.value = await getMaterialBase(data.materialId);
// 设置到 values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>

File diff suppressed because it is too large Load Diff