refactor(material-edit): 优化物料分组字典加载逻辑
重构`loadMatGroupDicts`函数,将并行请求改为顺序请求,并增加`fieldName`参数以控制刷新条件,提升代码可读性和维护性。
This commit is contained in:
parent
11f0e62d05
commit
00f160707a
@ -140,7 +140,7 @@ export default defineComponent({
|
||||
material.value.number = numberValue;
|
||||
|
||||
// 更新所有matGroup的选项
|
||||
loadMatGroupDicts(matGroupTitle, material.value);
|
||||
loadMatGroupDicts(matGroupTitle, material.value, fieldName);
|
||||
} else if (fieldName === 'category') {
|
||||
console.log('类别已更改为:', event);
|
||||
} else if (fieldName === 'status') {
|
||||
@ -190,16 +190,17 @@ export default defineComponent({
|
||||
loadData();
|
||||
});
|
||||
|
||||
const loadMatGroupDicts = async (matGroupTitle: any, material: any) => {
|
||||
const promises = Array(10)
|
||||
.fill(null)
|
||||
.map((_, i) => {
|
||||
const loadMatGroupDicts = async (matGroupTitle: any, material: any, fieldName?: string) => {
|
||||
try {
|
||||
for (let i = 0; i < matGroupDicts.value.length; i++) {
|
||||
let refresh = fieldName === undefined || fieldName === '';
|
||||
let filterProperty = { name: '' };
|
||||
matGroupTitle.value.forEach(item => {
|
||||
if (item.number === `${matGroupPrefix + i.toString().padStart(2, '0')}`) {
|
||||
try {
|
||||
const propertyObj = JSON.parse(item.property || '{}');
|
||||
if (propertyObj.FilterGroup && material[propertyObj.FilterGroup]) {
|
||||
refresh = refresh || fieldName === propertyObj.FilterGroup;
|
||||
filterProperty = {
|
||||
name: '',
|
||||
op: 'like',
|
||||
@ -212,22 +213,24 @@ export default defineComponent({
|
||||
return;
|
||||
}
|
||||
});
|
||||
return axios.get('api/dicts', {
|
||||
params: {
|
||||
number: { name: '' },
|
||||
name: { name: '' },
|
||||
property: filterProperty,
|
||||
parentNumber: { op: '=', value: `${matGroupPrefix + i.toString().padStart(2, '0')}` },
|
||||
status: { op: '=', value: '1' },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
try {
|
||||
const responses = await Promise.all(promises);
|
||||
responses.forEach((res, i) => {
|
||||
matGroupDicts.value[i] = res.data;
|
||||
});
|
||||
try {
|
||||
if (refresh) {
|
||||
const response = await axios.get('api/dicts', {
|
||||
params: {
|
||||
number: { name: '' },
|
||||
name: { name: '' },
|
||||
property: filterProperty,
|
||||
parentNumber: { op: '=', value: `${matGroupPrefix + i.toString().padStart(2, '0')}` },
|
||||
status: { op: '=', value: '1' },
|
||||
},
|
||||
});
|
||||
matGroupDicts.value[i] = response.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`加载物料分组${i}数据失败:`, error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载物料分组数据失败:', error);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user