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;
|
material.value.number = numberValue;
|
||||||
|
|
||||||
// 更新所有matGroup的选项
|
// 更新所有matGroup的选项
|
||||||
loadMatGroupDicts(matGroupTitle, material.value);
|
loadMatGroupDicts(matGroupTitle, material.value, fieldName);
|
||||||
} else if (fieldName === 'category') {
|
} else if (fieldName === 'category') {
|
||||||
console.log('类别已更改为:', event);
|
console.log('类别已更改为:', event);
|
||||||
} else if (fieldName === 'status') {
|
} else if (fieldName === 'status') {
|
||||||
@ -190,16 +190,17 @@ export default defineComponent({
|
|||||||
loadData();
|
loadData();
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadMatGroupDicts = async (matGroupTitle: any, material: any) => {
|
const loadMatGroupDicts = async (matGroupTitle: any, material: any, fieldName?: string) => {
|
||||||
const promises = Array(10)
|
try {
|
||||||
.fill(null)
|
for (let i = 0; i < matGroupDicts.value.length; i++) {
|
||||||
.map((_, i) => {
|
let refresh = fieldName === undefined || fieldName === '';
|
||||||
let filterProperty = { name: '' };
|
let filterProperty = { name: '' };
|
||||||
matGroupTitle.value.forEach(item => {
|
matGroupTitle.value.forEach(item => {
|
||||||
if (item.number === `${matGroupPrefix + i.toString().padStart(2, '0')}`) {
|
if (item.number === `${matGroupPrefix + i.toString().padStart(2, '0')}`) {
|
||||||
try {
|
try {
|
||||||
const propertyObj = JSON.parse(item.property || '{}');
|
const propertyObj = JSON.parse(item.property || '{}');
|
||||||
if (propertyObj.FilterGroup && material[propertyObj.FilterGroup]) {
|
if (propertyObj.FilterGroup && material[propertyObj.FilterGroup]) {
|
||||||
|
refresh = refresh || fieldName === propertyObj.FilterGroup;
|
||||||
filterProperty = {
|
filterProperty = {
|
||||||
name: '',
|
name: '',
|
||||||
op: 'like',
|
op: 'like',
|
||||||
@ -212,22 +213,24 @@ export default defineComponent({
|
|||||||
return;
|
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 {
|
try {
|
||||||
const responses = await Promise.all(promises);
|
if (refresh) {
|
||||||
responses.forEach((res, i) => {
|
const response = await axios.get('api/dicts', {
|
||||||
matGroupDicts.value[i] = res.data;
|
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) {
|
} catch (error) {
|
||||||
console.error('加载物料分组数据失败:', error);
|
console.error('加载物料分组数据失败:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user