Commit 83114aeb authored by 王纵's avatar 王纵

低代码表单保存时增加父表ID

parent 8baea3e6
......@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-09-06 15:14:45
* @LastEditTime: 2024-09-19 15:57:20
* @Version: 1.0.0
* @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
......@@ -228,17 +228,7 @@ export default {
}
if (this.formType === 'normal') {
this.addRef(this, this.tabInfo.tabCode); //正常表单保存表单组件实例,供页面整体保存时使用
if (this.tabInfo.readUrl) {
// console.log('D-form-activated', this.tabInfo.readUrl, JSON.stringify(this.queryParams))
const res = await getFormData(this.tabInfo.readUrl, this.queryParams)
this.fieldsObj = res.content.length ? res.content[0] : {};
this.dataLoadHandle(this.fieldsObj, this.tabInfo.tabCode); // 数据查询后的回调
this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据
this.status = res.content.length ? 'update' : 'create';
} else {
this.status = 'create';
}
await this.loadData();
}
this.formatFieldsValue();
},
......@@ -264,6 +254,17 @@ export default {
})
this.originFieldsObj = {...this.fieldsObj};
},
async loadData() {
if (this.tabInfo.readUrl) {
const res = await getFormData(this.tabInfo.readUrl, this.queryParams)
this.fieldsObj = res.content.length ? res.content[0] : {};
this.dataLoadHandle(this.fieldsObj, this.tabInfo.tabCode); // 数据查询后的回调
this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据
this.status = res.content.length ? 'update' : 'create';
} else {
this.status = 'create';
}
},
getInputType(type) {
if (type === 'TextArea') {
return 'textarea';
......@@ -322,8 +323,9 @@ export default {
}
formValues[item.columnName] = values[item.columnName];
});
const parentId = this.status === 'create' ? this.getParentPrimaryKey() : {};
const result = {
allValues: {...values, _status: this.status}, // 完整的数据,包含record或者接口查询的所有字段信息
allValues: {...values, ...parentId, _status: this.status}, // 完整的数据,包含record或者接口查询的所有字段信息
formValues: {...formValues, _status: this.status} // 只包含配置的fileds信息
}
resolve(result);
......@@ -332,6 +334,26 @@ export default {
});
});
},
getParentPrimaryKey() {
if (this.formType === 'normal') {
const {baseTable, parentTable} = this.tabInfo;
const dataSetsObj = this.dynamicInfo().dataSetObject;
const dataSetlist = Object.values(dataSetsObj);
if (baseTable !== parentTable) {
const {parentDataSetName} = dataSetsObj[this.tabInfo.tabCode];
if (parentDataSetName) {
const config = dataSetlist.find(o => o.dataSetName === parentDataSetName) || {};
if (config.instanceRef) {
const val = config.instanceRef.getFieldsValue();
return {
[config.primaryKey]: val[config.primaryKey]
};
}
}
}
}
return {};
},
reset() {
this.fieldsObj = {...this.originFieldsObj};
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment