feat: 木箱类型crud
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace LmsBoxTypeApi {
|
||||
/** 木箱类型信息 */
|
||||
export interface BoxType {
|
||||
id?: number; // id
|
||||
boxType: string; // 木箱类型
|
||||
boxName?: string; // 木箱描述
|
||||
lashNum: string; // 捆扎模版
|
||||
lashNumOne: number; // 一次捆扎次数
|
||||
lashNumTwo: number; // 二次捆扎次数
|
||||
needLashOne: boolean; // 是否一次捆扎
|
||||
needLashTwo: boolean; // 是否二次捆扎
|
||||
expendWidth: number; // 叉车取货宽度
|
||||
boxStructure: string; // 木箱结构
|
||||
desiccantNum?: number; // 干燥剂数量
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询木箱类型分页 */
|
||||
export function getBoxTypePage(params: PageParam) {
|
||||
return requestClient.get<PageResult<LmsBoxTypeApi.BoxType>>(
|
||||
'/lms/box-type/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询木箱类型详情 */
|
||||
export function getBoxType(id: number) {
|
||||
return requestClient.get<LmsBoxTypeApi.BoxType>(
|
||||
`/lms/box-type/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增木箱类型 */
|
||||
export function createBoxType(data: LmsBoxTypeApi.BoxType) {
|
||||
return requestClient.post('/lms/box-type/create', data);
|
||||
}
|
||||
|
||||
/** 修改木箱类型 */
|
||||
export function updateBoxType(data: LmsBoxTypeApi.BoxType) {
|
||||
return requestClient.put('/lms/box-type/update', data);
|
||||
}
|
||||
|
||||
/** 删除木箱类型 */
|
||||
export function deleteBoxType(id: number) {
|
||||
return requestClient.delete(`/lms/box-type/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 批量删除木箱类型 */
|
||||
export function deleteBoxTypeList(ids: number[]) {
|
||||
return requestClient.delete(
|
||||
`/lms/box-type/delete-list?ids=${ids.join(',')}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 导出木箱类型 */
|
||||
export function exportBoxType(params: any) {
|
||||
return requestClient.download('/lms/box-type/export-excel', { params });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { LmsBoxTypeApi } from '#/api/lms/boxtype';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'boxType',
|
||||
label: '木箱类型',
|
||||
rules: 'required',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请选择木箱类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'boxName',
|
||||
label: '木箱描述',
|
||||
rules: 'required',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '选择物料后自动带出',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'needLashOne',
|
||||
label: '是否一次捆扎',
|
||||
component: 'RadioGroup',
|
||||
defaultValue: true,
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'lashNumOne',
|
||||
label: '一次捆扎次数',
|
||||
component: 'InputNumber',
|
||||
defaultValue: 1,
|
||||
componentProps: {
|
||||
min: 0,
|
||||
placeholder: '请输入一次捆扎次数',
|
||||
precision: 0,
|
||||
step: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'needLashTwo',
|
||||
label: '是否二次捆扎',
|
||||
component: 'RadioGroup',
|
||||
defaultValue: true,
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'lashNumTwo',
|
||||
label: '二次捆扎次数',
|
||||
component: 'InputNumber',
|
||||
defaultValue: 1,
|
||||
componentProps: {
|
||||
min: 0,
|
||||
placeholder: '请输入二次捆扎次数',
|
||||
precision: 0,
|
||||
step: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'expendWidth',
|
||||
label: '叉车取货宽度',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
placeholder: '请输入叉车取货宽度',
|
||||
step: 0.01,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'lashNum',
|
||||
label: '捆扎模版',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入捆扎模版',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'desiccantNum',
|
||||
label: '干燥剂数量',
|
||||
rules: 'required',
|
||||
component: 'InputNumber',
|
||||
defaultValue: 6,
|
||||
componentProps: {
|
||||
min: 0,
|
||||
placeholder: '请输入干燥剂数量',
|
||||
precision: 0,
|
||||
step: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'boxStructure',
|
||||
label: '木箱结构',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入木箱结构',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'boxType',
|
||||
label: '木箱类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: [],
|
||||
placeholder: '请选择木箱类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'boxName',
|
||||
label: '木箱描述',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入木箱描述',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'needLashOne',
|
||||
label: '是否一次捆扎',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
placeholder: '请选择是否一次捆扎',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'needLashTwo',
|
||||
label: '是否二次捆扎',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
|
||||
placeholder: '请选择是否二次捆扎',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<LmsBoxTypeApi.BoxType>['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 40 },
|
||||
{
|
||||
field: 'boxType',
|
||||
title: '木箱类型',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'boxName',
|
||||
title: '木箱描述',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'lashNum',
|
||||
title: '捆扎模版',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'desiccantNum',
|
||||
title: '干燥剂数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'lashNumOne',
|
||||
title: '一次捆扎次数',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'lashNumTwo',
|
||||
title: '二次捆扎次数',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'needLashOne',
|
||||
title: '是否一次捆扎',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'needLashTwo',
|
||||
title: '是否二次捆扎',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'expendWidth',
|
||||
title: '叉车取货宽度',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'boxStructure',
|
||||
title: '木箱结构',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { LmsBoxTypeApi } from '#/api/lms/boxtype';
|
||||
|
||||
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 {
|
||||
deleteBoxType,
|
||||
deleteBoxTypeList,
|
||||
exportBoxType,
|
||||
getBoxTypePage,
|
||||
} from '#/api/lms/boxtype';
|
||||
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: LmsBoxTypeApi.BoxType) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除木箱类型 */
|
||||
async function handleDelete(row: LmsBoxTypeApi.BoxType) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.id]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteBoxType(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||
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 deleteBoxTypeList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
}: {
|
||||
records: LmsBoxTypeApi.BoxType[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportBoxType(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 getBoxTypePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<LmsBoxTypeApi.BoxType>,
|
||||
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: ['lms:box-type:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['lms:box-type:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.deleteBatch'),
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['lms:box-type:delete'],
|
||||
disabled: isEmpty(checkedIds),
|
||||
onClick: handleDeleteBatch,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['lms:box-type:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['lms:box-type:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.id]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script lang="ts" setup>
|
||||
import type { BaseMaterialBaseApi } from '#/api/base/materialbase';
|
||||
import type { LmsBoxTypeApi } from '#/api/lms/boxtype';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'antdv-next';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createBoxType, getBoxType, updateBoxType } from '#/api/lms/boxtype';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import MaterialSelectModalComponent from '../../../base/materialbase/components/MaterialSelectModal.vue';
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<LmsBoxTypeApi.BoxType>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['木箱类型'])
|
||||
: $t('ui.actionTitle.create', ['木箱类型']);
|
||||
});
|
||||
|
||||
/** 物料选择弹窗 */
|
||||
const [MaterialSelectModal, materialSelectModalApi] = useVbenModal({
|
||||
connectedComponent: MaterialSelectModalComponent,
|
||||
});
|
||||
|
||||
/** 打开物料单选弹窗 */
|
||||
function openMaterialSelect() {
|
||||
materialSelectModalApi.setData({ multiple: false }).open();
|
||||
}
|
||||
|
||||
/** 回填木箱类型和木箱描述 */
|
||||
async function handleMaterialSelect(
|
||||
rows: BaseMaterialBaseApi.MaterialBase[],
|
||||
) {
|
||||
const material = rows[0];
|
||||
if (!material) {
|
||||
return;
|
||||
}
|
||||
await formApi.setValues({
|
||||
boxName: material.materialName,
|
||||
boxType: material.materialCode,
|
||||
});
|
||||
}
|
||||
|
||||
const schema = useFormSchema().map((field) => {
|
||||
if (field.fieldName === 'boxType') {
|
||||
return {
|
||||
...field,
|
||||
componentProps: {
|
||||
...field.componentProps,
|
||||
onClick: openMaterialSelect,
|
||||
readonly: true,
|
||||
style: 'cursor: pointer',
|
||||
},
|
||||
};
|
||||
}
|
||||
if (field.fieldName === 'boxName') {
|
||||
return {
|
||||
...field,
|
||||
componentProps: {
|
||||
...field.componentProps,
|
||||
readonly: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
return field;
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 112,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema,
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2 gap-x-4',
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as LmsBoxTypeApi.BoxType;
|
||||
try {
|
||||
await (formData.value?.id ? updateBoxType(data) : createBoxType(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<LmsBoxTypeApi.BoxType>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getBoxType(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/2">
|
||||
<Form class="mx-4" />
|
||||
<MaterialSelectModal @select="handleMaterialSelect" />
|
||||
</Modal>
|
||||
</template>
|
||||
Reference in New Issue
Block a user