feat(mes): 新增 md item type 的迁移
parent
8bcfa20577
commit
1bdc0d992f
|
|
@ -0,0 +1,9 @@
|
|||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** 生成 MES 编码 */
|
||||
export function generateAutoCode(ruleCode: string, inputChar?: string) {
|
||||
return requestClient.post<string>('/mes/md/auto-code-record/generate', {
|
||||
inputChar,
|
||||
ruleCode,
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdItemTypeApi {
|
||||
/** MES 物料产品分类 */
|
||||
export interface ItemType {
|
||||
id?: number;
|
||||
parentId?: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
itemOrProduct?: string;
|
||||
sort?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
createTime?: Date;
|
||||
children?: ItemType[];
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询物料产品分类列表 */
|
||||
export function getItemTypeList(params?: any) {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType[]>(
|
||||
'/mes/md/item-type/list',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询物料产品分类精简列表 */
|
||||
export function getItemTypeSimpleList() {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType[]>(
|
||||
'/mes/md/item-type/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询物料产品分类详情 */
|
||||
export function getItemType(id: number) {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType>(
|
||||
`/mes/md/item-type/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增物料产品分类 */
|
||||
export function createItemType(data: MesMdItemTypeApi.ItemType) {
|
||||
return requestClient.post('/mes/md/item-type/create', data);
|
||||
}
|
||||
|
||||
/** 修改物料产品分类 */
|
||||
export function updateItemType(data: MesMdItemTypeApi.ItemType) {
|
||||
return requestClient.put('/mes/md/item-type/update', data);
|
||||
}
|
||||
|
||||
/** 删除物料产品分类 */
|
||||
export function deleteItemType(id: number) {
|
||||
return requestClient.delete(`/mes/md/item-type/delete?id=${id}`);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { default as MdItemTypeSelect } from './md-item-type-select.vue';
|
||||
export { default as MdItemTypeTree } from './md-item-type-tree.vue';
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { Tooltip, TreeSelect } from 'ant-design-vue';
|
||||
|
||||
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
|
||||
|
||||
defineOptions({ name: 'MdItemTypeSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
allowClear?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
allowClear: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择物料分类',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdItemTypeApi.ItemType | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
type ItemTypeNode = MesMdItemTypeApi.ItemType & {
|
||||
children?: ItemTypeNode[];
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const allList = ref<MesMdItemTypeApi.ItemType[]>([]);
|
||||
const itemTypeTree = ref<ItemTypeNode[]>([]);
|
||||
const selectedItem = ref<MesMdItemTypeApi.ItemType>();
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: number | undefined) => {
|
||||
emit('update:modelValue', value);
|
||||
},
|
||||
});
|
||||
|
||||
/** 递归将有子节点的分支节点标记为 disabled */
|
||||
function markParentsDisabled(nodes: MesMdItemTypeApi.ItemType[]): ItemTypeNode[] {
|
||||
return nodes.map((node) => {
|
||||
const children = node.children?.length
|
||||
? markParentsDisabled(node.children)
|
||||
: undefined;
|
||||
return {
|
||||
...node,
|
||||
children,
|
||||
disabled: Boolean(children?.length),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** 根据当前值同步 tooltip 展示的分类详情 */
|
||||
function syncSelectedItem(value: number | undefined) {
|
||||
selectedItem.value =
|
||||
value === undefined ? undefined : allList.value.find((item) => item.id === value);
|
||||
}
|
||||
|
||||
/** 除 v-model 外,额外抛出完整分类对象给业务表单使用 */
|
||||
function handleChange(value: number | undefined) {
|
||||
syncSelectedItem(value);
|
||||
emit('change', selectedItem.value);
|
||||
}
|
||||
|
||||
/** 查询物料分类树 */
|
||||
async function getItemTypeTree() {
|
||||
allList.value = await getItemTypeSimpleList();
|
||||
itemTypeTree.value = markParentsDisabled(handleTree(allList.value));
|
||||
syncSelectedItem(props.modelValue);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
syncSelectedItem(value);
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getItemTypeTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Tooltip :mouse-enter-delay="0.5" :open="selectedItem ? undefined : false">
|
||||
<template #title>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>备注:{{ selectedItem.remark || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<TreeSelect
|
||||
v-bind="$attrs"
|
||||
v-model:value="selectValue"
|
||||
:allow-clear="allowClear"
|
||||
:disabled="disabled"
|
||||
:field-names="{ children: 'children', label: 'name', value: 'id' }"
|
||||
:placeholder="placeholder"
|
||||
:tree-data="itemTypeTree"
|
||||
class="w-full"
|
||||
show-search
|
||||
tree-default-expand-all
|
||||
tree-node-filter-prop="name"
|
||||
@change="handleChange"
|
||||
/>
|
||||
</Tooltip>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { Input, Spin, Tree } from 'ant-design-vue';
|
||||
|
||||
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
|
||||
|
||||
defineOptions({ name: 'MdItemTypeTree' });
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
filterPlaceholder?: string;
|
||||
}>(),
|
||||
{
|
||||
filterPlaceholder: '搜索分类',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
nodeClick: [itemType: MesMdItemTypeApi.ItemType | undefined];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const filterText = ref('');
|
||||
const currentNodeId = ref<number>();
|
||||
const selectedKeys = ref<number[]>([]);
|
||||
const itemTypeList = ref<MesMdItemTypeApi.ItemType[]>([]);
|
||||
const itemTypeTree = ref<any[]>([]);
|
||||
|
||||
/** 加载分类树 */
|
||||
async function loadTree() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getItemTypeSimpleList();
|
||||
itemTypeList.value = data;
|
||||
itemTypeTree.value = handleTree(data, 'id', 'parentId');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理搜索逻辑 */
|
||||
function handleSearch(value: string) {
|
||||
filterText.value = value;
|
||||
const filteredList = value
|
||||
? itemTypeList.value.filter((item) => item.name?.includes(value))
|
||||
: itemTypeList.value;
|
||||
itemTypeTree.value = handleTree(filteredList, 'id', 'parentId');
|
||||
}
|
||||
|
||||
/** 处理节点点击:支持点击同一节点取消选中 */
|
||||
function handleSelect(_selectedKeys: any[], info: any) {
|
||||
const row = info.node.dataRef as MesMdItemTypeApi.ItemType;
|
||||
if (currentNodeId.value === row.id) {
|
||||
currentNodeId.value = undefined;
|
||||
selectedKeys.value = [];
|
||||
emit('nodeClick', undefined);
|
||||
return;
|
||||
}
|
||||
currentNodeId.value = row.id;
|
||||
selectedKeys.value = row.id === undefined ? [] : [row.id];
|
||||
emit('nodeClick', row);
|
||||
}
|
||||
|
||||
/** 清空选中状态 */
|
||||
function clearCurrent() {
|
||||
currentNodeId.value = undefined;
|
||||
selectedKeys.value = [];
|
||||
}
|
||||
|
||||
/** 重置整个树状态 */
|
||||
function reset() {
|
||||
clearCurrent();
|
||||
filterText.value = '';
|
||||
itemTypeTree.value = handleTree(itemTypeList.value, 'id', 'parentId');
|
||||
}
|
||||
|
||||
/** 设置当前选中分类 */
|
||||
function setCurrent(itemTypeId: number) {
|
||||
currentNodeId.value = itemTypeId;
|
||||
selectedKeys.value = [itemTypeId];
|
||||
}
|
||||
|
||||
watch(filterText, (value) => {
|
||||
handleSearch(value);
|
||||
});
|
||||
|
||||
defineExpose({ clearCurrent, loadTree, reset, setCurrent });
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
loadTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<Input
|
||||
v-model:value="filterText"
|
||||
:placeholder="filterPlaceholder"
|
||||
allow-clear
|
||||
class="w-full"
|
||||
>
|
||||
<template #prefix>
|
||||
<IconifyIcon class="size-4" icon="lucide:search" />
|
||||
</template>
|
||||
</Input>
|
||||
<Spin :spinning="loading" wrapper-class-name="w-full">
|
||||
<Tree
|
||||
v-if="itemTypeTree.length > 0"
|
||||
:default-expand-all="true"
|
||||
:field-names="{ title: 'name', key: 'id', children: 'children' }"
|
||||
:selected-keys="selectedKeys"
|
||||
:tree-data="itemTypeTree"
|
||||
class="pt-2"
|
||||
@select="handleSelect"
|
||||
/>
|
||||
<div v-else-if="!loading" class="py-4 text-center text-gray-500">
|
||||
暂无数据
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { getItemTypeList } from '#/api/mes/md/item/type';
|
||||
import {
|
||||
MesAutoCodeRuleCode,
|
||||
MesItemOrProductEnum,
|
||||
} from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改物料分类的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'parentId',
|
||||
label: '上级分类',
|
||||
component: 'ApiTreeSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
api: async () => {
|
||||
const data = await getItemTypeList();
|
||||
return [
|
||||
{
|
||||
id: 0,
|
||||
name: '顶级分类',
|
||||
children: handleTree(data),
|
||||
},
|
||||
];
|
||||
},
|
||||
childrenField: 'children',
|
||||
labelField: 'name',
|
||||
placeholder: '请选择上级分类',
|
||||
treeDefaultExpandAll: true,
|
||||
treeNodeFilterProp: 'name',
|
||||
valueField: 'id',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '分类编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 64,
|
||||
placeholder: '请输入分类编码',
|
||||
},
|
||||
rules: z.string().min(1, '分类编码不能为空').max(64),
|
||||
suffix: () =>
|
||||
h(
|
||||
Button,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_ITEM_TYPE_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '分类名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入分类名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'itemOrProduct',
|
||||
label: '物料/产品标识',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.MES_MD_ITEM_OR_PRODUCT),
|
||||
},
|
||||
rules: z.string().default(MesItemOrProductEnum.ITEM.value),
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '显示排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
rules: z.number().default(0),
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '分类名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入分类名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdItemTypeApi.ItemType>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '分类名称',
|
||||
minWidth: 200,
|
||||
align: 'left',
|
||||
treeNode: true,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '分类编码',
|
||||
width: 160,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'itemOrProduct',
|
||||
title: '物料/产品',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_MD_ITEM_OR_PRODUCT },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 260,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteItemType, getItemTypeList } from '#/api/mes/md/item/type';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'MesMdItemType' });
|
||||
|
||||
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: MesMdItemTypeApi.ItemType) {
|
||||
formModalApi.setData({ parentId: row.id }).open();
|
||||
}
|
||||
|
||||
/** 编辑分类 */
|
||||
function handleEdit(row: MesMdItemTypeApi.ItemType) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除分类 */
|
||||
async function handleDelete(row: MesMdItemTypeApi.ItemType) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteItemType(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async (_, formValues) => {
|
||||
return await getItemTypeList(formValues);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
treeConfig: {
|
||||
parentField: 'parentId',
|
||||
rowField: 'id',
|
||||
transform: true,
|
||||
expandAll: true,
|
||||
reserve: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdItemTypeApi.ItemType>,
|
||||
});
|
||||
</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: ['mes:md-item-type:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: isExpanded ? '收缩' : '展开',
|
||||
type: 'primary',
|
||||
onClick: handleExpand,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增子分类',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-item-type:create'],
|
||||
onClick: handleAppend.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-item-type:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-item-type:delete'],
|
||||
ifShow: row.parentId !== 0,
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createItemType,
|
||||
getItemType,
|
||||
updateItemType,
|
||||
} from '#/api/mes/md/item/type';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'MesMdItemTypeForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<MesMdItemTypeApi.ItemType>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['物料分类'])
|
||||
: $t('ui.actionTitle.create', ['物料分类']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 110,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdItemTypeApi.ItemType;
|
||||
try {
|
||||
await (formData.value?.id ? updateItemType(data) : createItemType(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;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MesMdItemTypeApi.ItemType>();
|
||||
if (!data || !data.id) {
|
||||
formData.value = data || undefined;
|
||||
if (data) {
|
||||
// 设置上级分类
|
||||
await formApi.setValues(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getItemType(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/** MES 物料/产品标识枚举 */
|
||||
export const MesItemOrProductEnum = {
|
||||
ITEM: {
|
||||
label: '物料',
|
||||
value: 'ITEM',
|
||||
},
|
||||
PRODUCT: {
|
||||
label: '产品',
|
||||
value: 'PRODUCT',
|
||||
},
|
||||
} as const;
|
||||
|
||||
/** MES 自动编码规则 Code 枚举 */
|
||||
export const MesAutoCodeRuleCode = {
|
||||
MD_ITEM_TYPE_CODE: 'MD_ITEM_TYPE_CODE',
|
||||
} as const;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** 生成 MES 编码 */
|
||||
export function generateAutoCode(ruleCode: string, inputChar?: string) {
|
||||
return requestClient.post<string>('/mes/md/auto-code-record/generate', {
|
||||
inputChar,
|
||||
ruleCode,
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdItemTypeApi {
|
||||
/** MES 物料产品分类 */
|
||||
export interface ItemType {
|
||||
id?: number;
|
||||
parentId?: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
itemOrProduct?: string;
|
||||
sort?: number;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
createTime?: Date;
|
||||
children?: ItemType[];
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询物料产品分类列表 */
|
||||
export function getItemTypeList(params?: any) {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType[]>(
|
||||
'/mes/md/item-type/list',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询物料产品分类精简列表 */
|
||||
export function getItemTypeSimpleList() {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType[]>(
|
||||
'/mes/md/item-type/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询物料产品分类详情 */
|
||||
export function getItemType(id: number) {
|
||||
return requestClient.get<MesMdItemTypeApi.ItemType>(
|
||||
`/mes/md/item-type/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增物料产品分类 */
|
||||
export function createItemType(data: MesMdItemTypeApi.ItemType) {
|
||||
return requestClient.post('/mes/md/item-type/create', data);
|
||||
}
|
||||
|
||||
/** 修改物料产品分类 */
|
||||
export function updateItemType(data: MesMdItemTypeApi.ItemType) {
|
||||
return requestClient.put('/mes/md/item-type/update', data);
|
||||
}
|
||||
|
||||
/** 删除物料产品分类 */
|
||||
export function deleteItemType(id: number) {
|
||||
return requestClient.delete(`/mes/md/item-type/delete?id=${id}`);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { default as MdItemTypeSelect } from './md-item-type-select.vue';
|
||||
export { default as MdItemTypeTree } from './md-item-type-tree.vue';
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { ElTooltip, ElTreeSelect } from 'element-plus';
|
||||
|
||||
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
|
||||
|
||||
defineOptions({ name: 'MdItemTypeSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
clearable?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
clearable: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择物料分类',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdItemTypeApi.ItemType | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
type ItemTypeNode = MesMdItemTypeApi.ItemType & {
|
||||
children?: ItemTypeNode[];
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const allList = ref<MesMdItemTypeApi.ItemType[]>([]);
|
||||
const itemTypeTree = ref<ItemTypeNode[]>([]);
|
||||
const selectedItem = ref<MesMdItemTypeApi.ItemType>();
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: number | undefined) => {
|
||||
emit('update:modelValue', value);
|
||||
},
|
||||
});
|
||||
|
||||
/** 递归将有子节点的分支节点标记为 disabled */
|
||||
function markParentsDisabled(nodes: MesMdItemTypeApi.ItemType[]): ItemTypeNode[] {
|
||||
return nodes.map((node) => {
|
||||
const children = node.children?.length
|
||||
? markParentsDisabled(node.children)
|
||||
: undefined;
|
||||
return {
|
||||
...node,
|
||||
children,
|
||||
disabled: Boolean(children?.length),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** 根据当前值同步 tooltip 展示的分类详情 */
|
||||
function syncSelectedItem(value: number | undefined) {
|
||||
selectedItem.value =
|
||||
value === undefined ? undefined : allList.value.find((item) => item.id === value);
|
||||
}
|
||||
|
||||
/** 除 v-model 外,额外抛出完整分类对象给业务表单使用 */
|
||||
function handleChange(value: number | undefined) {
|
||||
syncSelectedItem(value);
|
||||
emit('change', selectedItem.value);
|
||||
}
|
||||
|
||||
/** 查询物料分类树 */
|
||||
async function getItemTypeTree() {
|
||||
allList.value = await getItemTypeSimpleList();
|
||||
itemTypeTree.value = markParentsDisabled(handleTree(allList.value));
|
||||
syncSelectedItem(props.modelValue);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
syncSelectedItem(value);
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
getItemTypeTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElTooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||
<template #content>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>备注:{{ selectedItem.remark || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<ElTreeSelect
|
||||
v-bind="$attrs"
|
||||
v-model="selectValue"
|
||||
:clearable="clearable"
|
||||
:data="itemTypeTree"
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
:props="{ children: 'children', label: 'name' }"
|
||||
check-strictly
|
||||
class="w-full"
|
||||
default-expand-all
|
||||
filterable
|
||||
node-key="id"
|
||||
@change="handleChange"
|
||||
/>
|
||||
</ElTooltip>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Search } from '@vben/icons';
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { ElInput, ElTree } from 'element-plus';
|
||||
|
||||
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
|
||||
|
||||
defineOptions({ name: 'MdItemTypeTree' });
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
filterPlaceholder?: string;
|
||||
}>(),
|
||||
{
|
||||
filterPlaceholder: '搜索分类',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
nodeClick: [itemType: MesMdItemTypeApi.ItemType | undefined];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const filterText = ref('');
|
||||
const currentNodeId = ref<number>();
|
||||
const itemTypeList = ref<MesMdItemTypeApi.ItemType[]>([]);
|
||||
const itemTypeTree = ref<MesMdItemTypeApi.ItemType[]>([]);
|
||||
const treeRef = ref<InstanceType<typeof ElTree>>();
|
||||
|
||||
/** 加载分类树 */
|
||||
async function loadTree() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getItemTypeSimpleList();
|
||||
itemTypeList.value = data;
|
||||
itemTypeTree.value = handleTree(data, 'id', 'parentId');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理搜索逻辑 */
|
||||
function handleSearch(value: string) {
|
||||
filterText.value = value;
|
||||
const filteredList = value
|
||||
? itemTypeList.value.filter((item) => item.name?.includes(value))
|
||||
: itemTypeList.value;
|
||||
itemTypeTree.value = handleTree(filteredList, 'id', 'parentId');
|
||||
}
|
||||
|
||||
/** 处理节点点击:支持点击同一节点取消选中 */
|
||||
function handleNodeClick(row: MesMdItemTypeApi.ItemType) {
|
||||
if (currentNodeId.value === row.id) {
|
||||
currentNodeId.value = undefined;
|
||||
treeRef.value?.setCurrentKey(undefined);
|
||||
emit('nodeClick', undefined);
|
||||
return;
|
||||
}
|
||||
currentNodeId.value = row.id;
|
||||
emit('nodeClick', row);
|
||||
}
|
||||
|
||||
/** 清空选中状态 */
|
||||
function clearCurrent() {
|
||||
currentNodeId.value = undefined;
|
||||
treeRef.value?.setCurrentKey(undefined);
|
||||
}
|
||||
|
||||
/** 重置整个树状态 */
|
||||
function reset() {
|
||||
clearCurrent();
|
||||
filterText.value = '';
|
||||
itemTypeTree.value = handleTree(itemTypeList.value, 'id', 'parentId');
|
||||
}
|
||||
|
||||
/** 设置当前选中分类 */
|
||||
function setCurrent(itemTypeId: number) {
|
||||
currentNodeId.value = itemTypeId;
|
||||
treeRef.value?.setCurrentKey(itemTypeId);
|
||||
}
|
||||
|
||||
watch(filterText, (value) => {
|
||||
handleSearch(value);
|
||||
});
|
||||
|
||||
defineExpose({ clearCurrent, loadTree, reset, setCurrent });
|
||||
|
||||
onMounted(() => {
|
||||
loadTree();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<ElInput
|
||||
v-model="filterText"
|
||||
:placeholder="filterPlaceholder"
|
||||
class="w-full"
|
||||
clearable
|
||||
>
|
||||
<template #prefix>
|
||||
<Search class="size-4" />
|
||||
</template>
|
||||
</ElInput>
|
||||
<div v-loading="loading">
|
||||
<ElTree
|
||||
v-if="itemTypeTree.length > 0"
|
||||
ref="treeRef"
|
||||
:data="itemTypeTree"
|
||||
:expand-on-click-node="false"
|
||||
:props="{ label: 'name', children: 'children' }"
|
||||
class="pt-2"
|
||||
default-expand-all
|
||||
highlight-current
|
||||
node-key="id"
|
||||
@node-click="handleNodeClick"
|
||||
/>
|
||||
<div v-else-if="!loading" class="py-4 text-center text-gray-500">
|
||||
暂无数据
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
import { handleTree } from '@vben/utils';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { getItemTypeList } from '#/api/mes/md/item/type';
|
||||
import {
|
||||
MesAutoCodeRuleCode,
|
||||
MesItemOrProductEnum,
|
||||
} from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改物料分类的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'parentId',
|
||||
label: '上级分类',
|
||||
component: 'ApiTreeSelect',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
api: async () => {
|
||||
const data = await getItemTypeList();
|
||||
return [
|
||||
{
|
||||
id: 0,
|
||||
name: '顶级分类',
|
||||
children: handleTree(data),
|
||||
},
|
||||
];
|
||||
},
|
||||
checkStrictly: true,
|
||||
childrenField: 'children',
|
||||
defaultExpandAll: true,
|
||||
labelField: 'name',
|
||||
placeholder: '请选择上级分类',
|
||||
valueField: 'id',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '分类编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 64,
|
||||
placeholder: '请输入分类编码',
|
||||
},
|
||||
rules: z.string().min(1, '分类编码不能为空').max(64),
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_ITEM_TYPE_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '分类名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入分类名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'itemOrProduct',
|
||||
label: '物料/产品标识',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.MES_MD_ITEM_OR_PRODUCT),
|
||||
},
|
||||
rules: z.string().default(MesItemOrProductEnum.ITEM.value),
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '显示排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
rules: z.number().default(0),
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '分类名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入分类名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdItemTypeApi.ItemType>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '分类名称',
|
||||
minWidth: 200,
|
||||
align: 'left',
|
||||
treeNode: true,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '分类编码',
|
||||
width: 160,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'itemOrProduct',
|
||||
title: '物料/产品',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_MD_ITEM_OR_PRODUCT },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 260,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteItemType, getItemTypeList } from '#/api/mes/md/item/type';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'MesMdItemType' });
|
||||
|
||||
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: MesMdItemTypeApi.ItemType) {
|
||||
formModalApi.setData({ parentId: row.id }).open();
|
||||
}
|
||||
|
||||
/** 编辑分类 */
|
||||
function handleEdit(row: MesMdItemTypeApi.ItemType) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除分类 */
|
||||
async function handleDelete(row: MesMdItemTypeApi.ItemType) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteItemType(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async (_, formValues) => {
|
||||
return await getItemTypeList(formValues);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
treeConfig: {
|
||||
parentField: 'parentId',
|
||||
rowField: 'id',
|
||||
transform: true,
|
||||
expandAll: true,
|
||||
reserve: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdItemTypeApi.ItemType>,
|
||||
});
|
||||
</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: ['mes:md-item-type:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: isExpanded ? '收缩' : '展开',
|
||||
type: 'primary',
|
||||
onClick: handleExpand,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增子分类',
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-item-type:create'],
|
||||
onClick: handleAppend.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-item-type:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-item-type:delete'],
|
||||
ifShow: row.parentId !== 0,
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createItemType,
|
||||
getItemType,
|
||||
updateItemType,
|
||||
} from '#/api/mes/md/item/type';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'MesMdItemTypeForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<MesMdItemTypeApi.ItemType>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['物料分类'])
|
||||
: $t('ui.actionTitle.create', ['物料分类']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 110,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdItemTypeApi.ItemType;
|
||||
try {
|
||||
await (formData.value?.id ? updateItemType(data) : createItemType(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MesMdItemTypeApi.ItemType>();
|
||||
if (!data || !data.id) {
|
||||
formData.value = data || undefined;
|
||||
if (data) {
|
||||
// 设置上级分类
|
||||
await formApi.setValues(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getItemType(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/** MES 物料/产品标识枚举 */
|
||||
export const MesItemOrProductEnum = {
|
||||
ITEM: {
|
||||
label: '物料',
|
||||
value: 'ITEM',
|
||||
},
|
||||
PRODUCT: {
|
||||
label: '产品',
|
||||
value: 'PRODUCT',
|
||||
},
|
||||
} as const;
|
||||
|
||||
/** MES 自动编码规则 Code 枚举 */
|
||||
export const MesAutoCodeRuleCode = {
|
||||
MD_ITEM_TYPE_CODE: 'MD_ITEM_TYPE_CODE',
|
||||
} as const;
|
||||
Loading…
Reference in New Issue