新增混炼示方生成预览与批量创建功能,优化相关字段及用户交互,修复界面显示问题,增强系统稳定性和用户体验。

This commit is contained in:
geht
2026-05-22 19:43:41 +08:00
parent f3e3a99ebc
commit c85657d199
30 changed files with 1786 additions and 61 deletions

View File

@@ -0,0 +1,22 @@
import { ref } from 'vue';
/** MES 物料分类 - 原辅材料编码 */
export const MATERIAL_RAW_AUX_CODE = 'XSLMES_MATERIAL_RAW_AUX';
/** 原辅材料分类节点 ID运行时加载 */
export const materialRawAuxCategoryId = ref('');
/** 是否为原辅材料的直接子类 */
export function isMaterialRawAuxSubCategory(pid?: string) {
return !!materialRawAuxCategoryId.value && pid === materialRawAuxCategoryId.value;
}
/** 表单 Checkbox 布尔值 -> 数据库存储值 */
export function toIsRubberFlag(value: unknown) {
return value === true || value === '1' ? '1' : '0';
}
/** 数据库存储值 -> 表单 Checkbox 布尔值 */
export function fromIsRubberFlag(value: unknown) {
return value === '1' || value === 1 || value === true;
}

View File

@@ -1,5 +1,6 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { isMaterialRawAuxSubCategory } from './category.constants';
export const columns: BasicColumn[] = [
{
@@ -73,4 +74,13 @@ export const formSchema: FormSchema[] = [
placeholder: '留空将按规则自动生成(如 A01.A02',
},
},
{
label: ' ',
field: 'isRubber',
component: 'Checkbox',
defaultValue: false,
renderComponentContent: '胶料',
colProps: { span: 24 },
show: ({ values }) => isMaterialRawAuxSubCategory(values.pid),
},
];

View File

@@ -9,12 +9,40 @@
import { BasicForm, useForm } from '/src/components/Form';
import { formSchema } from '../category.data';
import { loadTreeData, saveOrUpdateDict } from '../category.api';
import { defHttp } from '/@/utils/http/axios';
import {
MATERIAL_RAW_AUX_CODE,
materialRawAuxCategoryId,
isMaterialRawAuxSubCategory,
toIsRubberFlag,
fromIsRubberFlag,
} from '../category.constants';
import type { Recordable } from '/@/types/global';
// 获取emit
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
const expandedRowKeys = ref([]);
const treeData = ref([]);
const isSubAdd = ref(false);
async function ensureMaterialRawAuxCategoryId() {
if (materialRawAuxCategoryId.value) {
return;
}
const res = await defHttp.get(
{ url: '/sys/category/loadOne', params: { field: 'code', val: MATERIAL_RAW_AUX_CODE } },
{ isTransformResponse: false },
);
if (res?.success && res?.result?.id) {
materialRawAuxCategoryId.value = res.result.id;
}
}
function normalizeSubmitValues(values: Recordable) {
const payload = { ...values };
payload.isRubber = isMaterialRawAuxSubCategory(payload.pid) ? toIsRubberFlag(payload.isRubber) : '0';
return payload;
}
//表单配置
const [registerForm, { resetFields, setFieldsValue, validate, updateSchema }] = useForm({
schemas: formSchema,
@@ -35,12 +63,14 @@
expandedRowKeys.value = [];
setModalProps({ confirmLoading: false, minHeight: 80 });
isUpdate.value = !!data?.isUpdate;
await ensureMaterialRawAuxCategoryId();
// 代码逻辑说明: 分类字典data.record为空报错------------
isSubAdd.value = !data?.isUpdate && data.record && data.record.id;
if (data?.record) {
//表单赋值
await setFieldsValue({
...data.record,
isRubber: fromIsRubberFlag(data.record.isRubber),
});
}
//父级节点树信息
@@ -76,6 +106,7 @@
async function handleSubmit() {
try {
let values = await validate();
values = normalizeSubmitValues(values);
setModalProps({ confirmLoading: true });
//提交表单
await saveOrUpdateDict(values, isUpdate.value);