解构组合使用共通方法
parent
9baeb47f41
commit
f829157c73
|
|
@ -78,6 +78,7 @@
|
|||
getOutKeyList,
|
||||
} from '@/api/formdesign/index';
|
||||
import { functionGetForm } from '@/api/demo/formScheme';
|
||||
import { cardNestStructure, changeCardStructure } from '@/views/demo/onlineform/util.ts'
|
||||
|
||||
defineOptions({ name: 'FormModal' });
|
||||
|
||||
|
|
@ -118,66 +119,6 @@
|
|||
}
|
||||
return arr;
|
||||
}
|
||||
const changeCardStructure = (data) => {
|
||||
let result = [];
|
||||
if (data && data.length > 0) {
|
||||
data.forEach((item) => {
|
||||
if (item.component === 'Tabs') {
|
||||
item.componentProps.options = changeCardStructure(item.componentProps.options);
|
||||
} else if (item.component === 'CardGroup') {
|
||||
item.componentProps.options = changeCardStructure(item.componentProps.options);
|
||||
item.componentProps.options.forEach((childItem) => {
|
||||
if (childItem.pfield) {
|
||||
result.push(childItem);
|
||||
} else {
|
||||
result.push({ ...childItem, ptype: 'card', pfield: item.field });
|
||||
}
|
||||
});
|
||||
item.componentProps.options = [];
|
||||
} else if (item.component === 'Grid' && item.label === '栅格布局') {
|
||||
item.columns = changeCardStructure(item.columns);
|
||||
item.columns.forEach((childItem) => {
|
||||
childItem.children.forEach((col) => {
|
||||
result.push({ ...col, ptype: 'gridlayout', pfield: item.field });
|
||||
});
|
||||
});
|
||||
} else if (item.children && !item.field) {
|
||||
item.children = changeCardStructure(item.children);
|
||||
} else if (item.children && item.field.indexOf('use_card') === -1) {
|
||||
item.children = changeCardStructure(item.children);
|
||||
item.children = [];
|
||||
} else {
|
||||
if (['Card'].includes(item.component)) {
|
||||
item.columns[0].children = changeCardStructure(item.columns[0].children);
|
||||
if (item.component === 'Card' && item.columns[0].children) {
|
||||
item.columns[0].children.forEach((childItem) => {
|
||||
if (childItem.pfield) {
|
||||
result.push(childItem);
|
||||
} else {
|
||||
result.push({ ...childItem, ptype: 'card', pfield: item.field });
|
||||
}
|
||||
});
|
||||
item.columns[0].children = [];
|
||||
}
|
||||
} else if (item.field && item.field.indexOf('use_card') !== -1) {
|
||||
item.children = changeCardStructure(item.children);
|
||||
item.children.forEach((childItem) => {
|
||||
if (childItem.pfield) {
|
||||
result.push(childItem);
|
||||
} else {
|
||||
result.push({ ...childItem, ptype: 'card', pfield: item.field });
|
||||
}
|
||||
});
|
||||
item.children = [];
|
||||
}
|
||||
}
|
||||
result.push(item);
|
||||
});
|
||||
return result;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
async function designSendGrandson(value) {
|
||||
let designTab = JSON.parse(value);
|
||||
let schems = saveFormDatas.value.scheme.scheme
|
||||
|
|
@ -525,53 +466,6 @@
|
|||
saveFormDatas.value.scheme.type = 1;
|
||||
}
|
||||
}
|
||||
|
||||
const cardNestStructure = (data) => {
|
||||
let childList = {};
|
||||
let result = [];
|
||||
data.forEach((item) => {
|
||||
if (item.schemas) {
|
||||
item.schemas = cardNestStructure(item.schemas);
|
||||
result.push(item);
|
||||
}else if(item.component === 'Tabs'){
|
||||
item.componentProps.options = cardNestStructure(item.componentProps.options);
|
||||
result.push(item);
|
||||
}else if(!item.ptype && Object.keys(item).includes('children')){
|
||||
item.children = cardNestStructure(item.children)
|
||||
result.push(item);
|
||||
} else if (item.ptype) {
|
||||
if (Object.keys(item).includes('children')) {
|
||||
item.children = childList[item.field] || [];
|
||||
}
|
||||
if (item.component === 'CardGroup' && Object.keys(item).includes('componentProps')) {
|
||||
item.componentProps.options = childList[item.field] || [];
|
||||
}
|
||||
let pushItem = {};
|
||||
Object.keys(item).forEach((key) => {
|
||||
if (key !== 'ptype' && key !== 'pfield') {
|
||||
pushItem[key] = item[key];
|
||||
}
|
||||
});
|
||||
if (childList[item.pfield]) {
|
||||
childList[item.pfield].push(pushItem);
|
||||
} else {
|
||||
childList[item.pfield] = [pushItem];
|
||||
}
|
||||
} else if (item.component === 'CardGroup') {
|
||||
item.componentProps.options = childList[item.field] || [];
|
||||
result.push(item);
|
||||
} else if (item.component === 'Card') {
|
||||
item.columns[0].children = childList[item.field] || [];
|
||||
result.push(item);
|
||||
} else if (item.field &&item.field.indexOf('use_card') !== -1) {
|
||||
item.children = childList[item.field] || [];
|
||||
result.push(item);
|
||||
} else {
|
||||
result.push(item);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
// 自动建表返回后,保存数据
|
||||
function automaticFormDataBack(data) {
|
||||
if (isStageClick.value && stepsCurrent.value === 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue