设备类别新增

This commit is contained in:
2026-05-14 17:11:44 +08:00
parent 7b573cebdd
commit 965bdf44db
15 changed files with 1142 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
const { createConfirm } = useMessage();
enum Api {
list = '/xslmes/mesXslEquipmentCategory/list',
checkCategoryName = '/xslmes/mesXslEquipmentCategory/checkCategoryName',
save = '/xslmes/mesXslEquipmentCategory/add',
edit = '/xslmes/mesXslEquipmentCategory/edit',
deleteOne = '/xslmes/mesXslEquipmentCategory/delete',
deleteBatch = '/xslmes/mesXslEquipmentCategory/deleteBatch',
importExcel = '/xslmes/mesXslEquipmentCategory/importExcel',
exportXls = '/xslmes/mesXslEquipmentCategory/exportXls',
queryById = '/xslmes/mesXslEquipmentCategory/queryById',
}
export const getExportUrl = Api.exportXls;
export const getImportUrl = Api.importExcel;
export const list = (params) => defHttp.get({ url: Api.list, params });
export const queryById = (params: { id: string }) => defHttp.get({ url: Api.queryById, params });
export const checkCategoryName = (params: { categoryName: string; dataId?: string }) =>
defHttp.get(
{ url: Api.checkCategoryName, params },
{
successMessageMode: 'none',
errorMessageMode: 'none',
},
);
export const deleteOne = (params, handleSuccess) => {
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
};
export const batchDelete = (params, handleSuccess) => {
createConfirm({
iconType: 'warning',
title: '确认删除',
content: '是否删除选中数据',
okText: '确认',
cancelText: '取消',
onOk: () => {
return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
handleSuccess();
});
},
});
};
export const saveOrUpdate = (params, isUpdate) => {
const url = isUpdate ? Api.edit : Api.save;
return defHttp.post({ url, params });
};

View File

@@ -0,0 +1,87 @@
import { BasicColumn, FormSchema } from '/@/components/Table';
import { checkCategoryName } from './MesXslEquipmentCategory.api';
export const columns: BasicColumn[] = [
{ title: '类别名称', align: 'center', dataIndex: 'categoryName', width: 160 },
{ title: '工序名称', align: 'center', dataIndex: 'processOperationName', width: 180 },
{ title: '点检区分', align: 'center', dataIndex: 'inspectDistinct_dictText', width: 100 },
{ title: '保养区分', align: 'center', dataIndex: 'maintainDistinct_dictText', width: 100 },
{ title: '创建人', align: 'center', dataIndex: 'createBy', width: 100 },
{
title: '创建时间',
align: 'center',
dataIndex: 'createTime',
width: 165,
customRender: ({ text }) => (!text ? '' : String(text).length > 19 ? String(text).substring(0, 19) : text),
},
{ title: '租户ID', align: 'center', dataIndex: 'tenantId', width: 90, defaultHidden: true },
];
export const searchFormSchema: FormSchema[] = [
{ label: '类别名称', field: 'categoryName', component: 'Input', colProps: { span: 6 } },
{ label: '工序名称', field: 'processOperationName', component: 'Input', colProps: { span: 6 } },
{
label: '点检区分',
field: 'inspectDistinct',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_equipment_inspect_distinct' },
colProps: { span: 6 },
},
{
label: '保养区分',
field: 'maintainDistinct',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_equipment_maintain_distinct' },
colProps: { span: 6 },
},
];
export const formSchema: FormSchema[] = [
{ label: '', field: 'id', component: 'Input', show: false },
{
label: '类别名称',
field: 'categoryName',
component: 'Input',
componentProps: { placeholder: '同租户内未删除数据中不可重复' },
dynamicRules: ({ model }) => [
{ required: true, message: '请输入类别名称' },
{
validator: async (_rule, value) => {
const v = value == null ? '' : String(value).trim();
if (!v) {
return Promise.resolve();
}
try {
await checkCategoryName({ categoryName: v, dataId: model?.id });
return Promise.resolve();
} catch (e: any) {
const msg = e?.response?.data?.message || e?.message || '该类别名称已存在';
return Promise.reject(msg);
}
},
trigger: 'blur',
},
],
},
{ label: '', field: 'processOperationId', component: 'Input', show: false, dynamicRules: () => [{ required: true, message: '请选择所属工序' }] },
{
label: '所属工序',
field: 'processOperationName',
component: 'Input',
slot: 'processOperationPicker',
},
{
label: '点检区分',
field: 'inspectDistinct',
required: true,
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_equipment_inspect_distinct', placeholder: '请选择' },
},
{
label: '保养区分',
field: 'maintainDistinct',
required: true,
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_equipment_maintain_distinct', placeholder: '请选择' },
},
];

View File

@@ -0,0 +1,127 @@
<template>
<div>
<BasicTable @register="registerTable" :rowSelection="rowSelection">
<template #tableTitle>
<a-button type="primary" v-auth="'mes:mes_xsl_equipment_category:add'" @click="handleAdd" preIcon="ant-design:plus-outlined">
新增
</a-button>
<a-button
type="primary"
v-auth="'mes:mes_xsl_equipment_category:exportXls'"
preIcon="ant-design:export-outlined"
@click="onExportXls"
>
导出
</a-button>
<j-upload-button
type="primary"
v-auth="'mes:mes_xsl_equipment_category:importExcel'"
preIcon="ant-design:import-outlined"
@click="onImportXls"
>
导入
</j-upload-button>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined" />
删除
</a-menu-item>
</a-menu>
</template>
<a-button v-auth="'mes:mes_xsl_equipment_category:deleteBatch'">
批量操作
<Icon icon="mdi:chevron-down" />
</a-button>
</a-dropdown>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{ label: '编辑', onClick: handleEdit.bind(null, record), auth: 'mes:mes_xsl_equipment_category:edit' },
]"
:dropDownActions="getDropDownAction(record)"
/>
</template>
</BasicTable>
<MesXslEquipmentCategoryModal @register="registerModal" @success="handleSuccess" />
</div>
</template>
<script lang="ts" name="xslmes-mesXslEquipmentCategory" setup>
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import Icon from '/@/components/Icon';
import MesXslEquipmentCategoryModal from './components/MesXslEquipmentCategoryModal.vue';
import { columns, searchFormSchema } from './MesXslEquipmentCategory.data';
import { list, deleteOne, batchDelete, getExportUrl, getImportUrl } from './MesXslEquipmentCategory.api';
const [registerModal, { openModal }] = useModal();
const { tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
title: '设备类别',
api: list,
columns,
canResize: true,
formConfig: {
schemas: searchFormSchema,
labelWidth: 120,
autoSubmitOnEnter: true,
showAdvancedButton: true,
},
actionColumn: {
width: 200,
fixed: 'right',
},
},
exportConfig: {
name: '设备类别',
url: getExportUrl,
},
importConfig: {
url: getImportUrl,
success: handleSuccess,
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
function handleAdd() {
openModal(true, { isUpdate: false, showFooter: true });
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true, showFooter: true });
}
function handleDetail(record: Recordable) {
openModal(true, { record, isUpdate: true, showFooter: false });
}
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
async function batchHandleDelete() {
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
function handleSuccess() {
selectedRowKeys.value = [];
reload();
}
function getDropDownAction(record) {
return [
{ label: '详情', onClick: handleDetail.bind(null, record) },
{
label: '删除',
popConfirm: { title: '是否确认删除', confirm: handleDelete.bind(null, record) },
auth: 'mes:mes_xsl_equipment_category:delete',
},
];
}
</script>

View File

@@ -0,0 +1,76 @@
<template>
<BasicModal @register="registerModal" :title="title" width="640" v-bind="$attrs" destroyOnClose @ok="handleSubmit">
<BasicForm @register="registerForm">
<template #processOperationPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择工序" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openProcessSelect">选择工序</a-button>
<a-button v-if="model.processOperationId && !isDetail" @click="clearProcess">清除</a-button>
</a-input-group>
</template>
</BasicForm>
<MesXslProcessOperationSelectModal @register="registerProcessModal" @select="onProcessSelect" />
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from '../MesXslEquipmentCategory.data';
import { saveOrUpdate } from '../MesXslEquipmentCategory.api';
import MesXslProcessOperationSelectModal from './MesXslProcessOperationSelectModal.vue';
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
const isDetail = ref(false);
const [registerProcessModal, { openModal: openProcessModal }] = useModal();
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
await resetFields();
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
isUpdate.value = !!data?.isUpdate;
isDetail.value = !data?.showFooter;
if (unref(isUpdate)) await setFieldsValue({ ...data.record });
setProps({ disabled: !data?.showFooter });
});
const title = computed(() =>
!unref(isUpdate) ? '新增设备类别' : unref(isDetail) ? '设备类别详情' : '编辑设备类别',
);
function openProcessSelect() {
const vals = getFieldsValue();
openProcessModal(true, { processOperationId: vals.processOperationId });
}
function clearProcess() {
setFieldsValue({ processOperationId: '', processOperationName: '' });
}
function onProcessSelect(payload: { processOperationId?: string; processOperationName?: string }) {
setFieldsValue({
processOperationId: payload.processOperationId || '',
processOperationName: payload.processOperationName || '',
});
}
async function handleSubmit() {
try {
const values = await validate();
setModalProps({ confirmLoading: true });
await saveOrUpdate(values, isUpdate.value);
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

View File

@@ -0,0 +1,99 @@
<template>
<BasicModal v-bind="$attrs" title="选择工序" :width="960" @register="registerModal" @ok="handleOk">
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { list, queryById } from '/@/views/xslmes/mesXslProcessOperation/MesXslProcessOperation.api';
const emit = defineEmits(['register', 'select']);
const selectedRow = ref<Recordable | null>(null);
function handleSelectionChange(_keys: string[], rows: Recordable[]) {
selectedRow.value = rows?.[0] ?? null;
}
const [registerTable, { reload, setProps, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] =
useTable({
api: list,
columns: [
{ title: '工序编码', dataIndex: 'operationCode', width: 140 },
{ title: '工序名称', dataIndex: 'operationName', width: 200 },
],
rowKey: 'id',
useSearchForm: true,
formConfig: {
labelWidth: 90,
schemas: [
{ label: '工序编码', field: 'operationCode', component: 'Input', colProps: { span: 8 } },
{ label: '工序名称', field: 'operationName', component: 'Input', colProps: { span: 8 } },
],
},
pagination: { pageSize: 10 },
canResize: false,
showIndexColumn: false,
immediate: true,
rowSelection: {
type: 'radio',
columnWidth: 48,
onChange: handleSelectionChange,
},
clickToRowSelect: true,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
selectedRow.value = null;
clearSelectedRowKeys?.();
setProps({
rowSelection: {
type: 'radio',
columnWidth: 48,
onChange: handleSelectionChange,
},
clickToRowSelect: true,
});
setModalProps({ confirmLoading: false });
const pid = data?.processOperationId as string | undefined;
if (pid) {
setSelectedRowKeys?.([pid]);
try {
const raw = await queryById({ id: pid });
const row = (raw as any)?.id != null ? raw : (raw as any)?.result;
if (row) {
selectedRow.value = row;
}
} catch {
// 忽略
}
}
reload();
});
async function handleOk() {
const keys = (getSelectRowKeys?.() || []) as string[];
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
if (!row && keys.length) {
try {
const raw = await queryById({ id: keys[0] });
row = (raw as any)?.id != null ? raw : (raw as any)?.result;
} catch {
// 忽略
}
}
if (!row?.id) {
emit('select', { processOperationId: '', processOperationName: '' });
closeModal();
return;
}
emit('select', {
processOperationId: row.id,
processOperationName: row.operationName || '',
});
closeModal();
}
</script>