Commit 7f2823df authored by 王纵's avatar 王纵

页面按钮默认方法提取到Dynamic组件

parent 47298b37
......@@ -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-08-21 15:43:25
* @LastEditTime: 2024-09-06 15:14:45
* @Version: 1.0.0
* @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
......@@ -235,7 +235,7 @@ export default {
this.fieldsObj = res.content.length ? res.content[0] : {};
this.dataLoadHandle(this.fieldsObj, this.tabInfo.tabCode); // 数据查询后的回调
this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据
this.status = 'update';
this.status = res.content.length ? 'update' : 'create';
} else {
this.status = 'create';
}
......
......@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 15:09:30
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-22 11:24:20
* @LastEditTime: 2024-09-06 15:15:19
* @Version: 1.0.0
* @Description: 页面按钮渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
......@@ -73,6 +73,10 @@ export default {
type: Array,
default: () => []
},
layoutButtonsDefaultFun: { // 默认按钮方法 - 从父组件传入,是为了方便暴露给外层页面调用
type: Array,
default: () => []
},
},
data () {
return {
......@@ -92,10 +96,10 @@ export default {
query: 'search'
},
allFuns: [
{
name: 'save',
clickFunction: this.saveFunction,
},
// {
// name: 'save',
// clickFunction: this.saveFunction,
// },
// {
// name: 'query',
// clickFunction: this.query,
......@@ -113,7 +117,7 @@ export default {
mounted() {
this.configInfo = this.dynamicInfo().config;
this.readOnly = this.dynamicInfo().queryParams.readOnly;
const funcs = [...this.allFuns, ...this.headerButtons, ...this.layoutButtonsFun]; // 综合按钮方法
const funcs = [...this.layoutButtonsDefaultFun, ...this.headerButtons, ...this.layoutButtonsFun]; // 综合按钮方法
this.allFuns = [...new Map(funcs.map(item => [item.name, item])).values()];
this.layoutButtons = (this.configInfo.layoutButtons || []).concat(this.headerButtons).filter(o => this.allFuns.some(e => e.name === o.name));
this.init();
......@@ -145,77 +149,77 @@ export default {
// remove() {
// },
async saveFunction() {
const saveDataSet = this.dynamicInfo().dataSetObject;
const dataSets = {...saveDataSet};
for (let key in dataSets) {
if (dataSets.hasOwnProperty(key) && dataSets[key].type==='Form') { // 确保key是对象自身的属性
const {instanceRef} = dataSets[key];
if(instanceRef) {
const values = await instanceRef.validate();
dataSets[key].submitValues = values;
}
}
}
const {layoutCode, metaKeys, dataSetMap} = this.getDataSets(dataSets);
save([{layoutCode, metaKeys, ...dataSetMap}]).then(res => {
Toast.success('保存成功!');
})
},
getDataSets(dataSetTree) {
const { layoutCode } = this.dynamicInfo().config;
const metaKeys = { top: [] };
const dataSetMap = {};
const serverNames = {};
const saveCheckUrls = {};
const delChackUrls = {};
Object.values(dataSetTree).forEach(config => {
const { parentDataSetName, dataSetName, baseTable, parentTable, submitValues, savedCheckApi } = config;
// async saveFunction() {
// const saveDataSet = this.dynamicInfo().dataSetObject;
// const dataSets = {...saveDataSet};
// for (let key in dataSets) {
// if (dataSets.hasOwnProperty(key) && dataSets[key].tabType==='Form') { // 确保key是对象自身的属性
// const {instanceRef} = dataSets[key];
// if(instanceRef) {
// const values = await instanceRef.validate();
// dataSets[key].submitValues = values;
// }
// }
// }
// const {layoutCode, metaKeys, dataSetMap} = this.getDataSets(dataSets);
// save([{layoutCode, metaKeys, ...dataSetMap}]).then(res => {
// Toast.success('保存成功!');
// })
// },
// getDataSets(dataSetTree) {
// const { layoutCode } = this.dynamicInfo().config;
// const metaKeys = { top: [] };
// const dataSetMap = {};
// const serverNames = {};
// const saveCheckUrls = {};
// const delChackUrls = {};
// Object.values(dataSetTree).forEach(config => {
// const { parentDataSetName, dataSetName, baseTable, parentTable, submitValues, savedCheckApi } = config;
if (baseTable !== parentTable) { // 不是同一数据源
if (parentDataSetName) {
if (dataSetMap[parentDataSetName]) { // 存在值
let currentVal = dataSetMap[parentDataSetName][0];
currentVal[dataSetName] = submitValues ? [submitValues.allValues] : [];
dataSetMap[parentDataSetName] = [currentVal];
} else {
dataSetMap[parentDataSetName] = [{
[dataSetName]: submitValues ? [submitValues.allValues] : []
}]
}
metaKeys[parentDataSetName].push(dataSetName);
metaKeys[dataSetName] = [];
} else {
if (dataSetMap[dataSetName]) { // 存在值
let currentVal = dataSetMap[dataSetName][0];
currentVal = {...(submitValues ? submitValues.allValues : {}), ...currentVal};
if (currentVal.childrenDs) {
const childs = [...currentVal.childrenDs];
delete currentVal.childrenDs;
childs.forEach(item => {
currentVal = {...currentVal, ...item};
})
}
dataSetMap[dataSetName] = [currentVal];
} else {
dataSetMap[dataSetName] = submitValues ? [submitValues.allValues] : []
}
metaKeys.top.push(dataSetName);
metaKeys[dataSetName] = [];
}
} else if (baseTable) { // 复用数据源
if (dataSetMap[parentDataSetName]) {
let currentVal = dataSetMap[parentDataSetName][0];
dataSetMap[parentDataSetName] = [{...currentVal, ...(submitValues ? submitValues.formValues : {})}];
} else {
dataSetMap[parentDataSetName] = [{childrenDs: submitValues ? submitValues.formValues : {}}]
}
}
});
return {
layoutCode, metaKeys, dataSetMap, serverNames, saveCheckUrls, delChackUrls
}
},
// if (baseTable !== parentTable) { // 不是同一数据源
// if (parentDataSetName) {
// if (dataSetMap[parentDataSetName]) { // 存在值
// let currentVal = dataSetMap[parentDataSetName][0];
// currentVal[dataSetName] = submitValues ? [submitValues.allValues] : [];
// dataSetMap[parentDataSetName] = [currentVal];
// } else {
// dataSetMap[parentDataSetName] = [{
// [dataSetName]: submitValues ? [submitValues.allValues] : []
// }]
// }
// metaKeys[parentDataSetName].push(dataSetName);
// metaKeys[dataSetName] = [];
// } else {
// if (dataSetMap[dataSetName]) { // 存在值
// let currentVal = dataSetMap[dataSetName][0];
// currentVal = {...(submitValues ? submitValues.allValues : {}), ...currentVal};
// if (currentVal.childrenDs) {
// const childs = [...currentVal.childrenDs];
// delete currentVal.childrenDs;
// childs.forEach(item => {
// currentVal = {...currentVal, ...item};
// })
// }
// dataSetMap[dataSetName] = [currentVal];
// } else {
// dataSetMap[dataSetName] = submitValues ? [submitValues.allValues] : []
// }
// metaKeys.top.push(dataSetName);
// metaKeys[dataSetName] = [];
// }
// } else if (baseTable) { // 复用数据源
// if (dataSetMap[parentDataSetName]) {
// let currentVal = dataSetMap[parentDataSetName][0];
// dataSetMap[parentDataSetName] = [{...currentVal, ...(submitValues ? submitValues.formValues : {})}];
// } else {
// dataSetMap[parentDataSetName] = [{childrenDs: submitValues ? submitValues.formValues : {}}]
// }
// }
// });
// return {
// layoutCode, metaKeys, dataSetMap, serverNames, saveCheckUrls, delChackUrls
// }
// },
}
}
</script>
......
......@@ -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-08-21 16:52:03
* @LastEditTime: 2024-09-06 15:26:18
* @Version: 1.0.0
* @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing
......@@ -30,24 +30,27 @@
v-if="configDatas.id"
:layoutButtonsFun="layoutButtons"
:headerButtons="headerButtons"
:layoutButtonsDefaultFun="layoutButtonsDefaultFun"
/>
</d-view>
</template>
<script>
import {NavBar, Loading} from 'vant';
import {NavBar, Loading, Toast} from 'vant';
import {DView, DHeader, DContent, DScroll} from './LayoutComponents';
import LayoutButtons from './LayoutButtons';
import ConfigRenderComponent from './ConfigRenderComponent/index.jsx';
import {query, queryRoute} from './service'
import {query, queryRoute, save} from './service'
import './index.less'
import EventBus from './utils/eventBus';
import {getLayoutSaveData} from './utils/utils';
export default {
name: 'Dynamic',
components: {
[Loading.name]: Loading,
[NavBar.name]: NavBar,
[Toast.name]: Toast,
LayoutButtons,
ConfigRenderComponent,
DView,
......@@ -105,7 +108,13 @@ export default {
configDatas: {}, // 页面配置信息
params: {}, // 页面路由参数
dataSetObject: {}, // 页面配置信息的dataset
duplicateDs: {}
duplicateDs: {},
layoutButtonsDefaultFun: [
{
name: 'save',
clickFunction: this.layoutSave,
},
]
}
},
provide() {
......@@ -140,7 +149,7 @@ export default {
this.loading = true;
let readOnly = false
// eslint-disable-next-line eqeqeq
if (this.params.readOnly === "YES" || this.params.readOnly == 'true') {
if (this.params.readOnly === "YES" || this.params.readOnly == 'Y' || this.params.readOnly == 'true' || this.params.readOnly === true) {
readOnly = true
}
......@@ -196,6 +205,17 @@ export default {
// componentRenderers: this.componentRenderers // 组件渲染内容
}
},
// 布局按钮保存
async layoutSave() {
const data = await getLayoutSaveData(this.getDynamicInfo());
try {
const res = await save(data);
Toast.success('保存成功!');
return true;
} catch(err) {
throw new Error("保存失败");
}
},
backClick() {
if (this.$attrs['onGoBack']) {
this.$emit('goBack');
......
......@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 14:39:47
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-21 15:45:48
* @LastEditTime: 2024-09-06 15:24:17
* @Version: 1.0.0
* @Description: 工具类
* @Copyright: Copyright (c) 2021, Hand-RongJing
......@@ -182,6 +182,84 @@ const isTenantRoleLevel = () => {
}
/**
* 获取页面布局保存数据
*/
const getLayoutSaveData = async (dynamicInfo) => {
const saveDataSet = dynamicInfo.dataSetObject;
const dataSets = {...saveDataSet};
for (let key in dataSets) {
if (dataSets.hasOwnProperty(key) && dataSets[key].tabType==='Form') { // 确保key是对象自身的属性
const {instanceRef} = dataSets[key];
if(instanceRef) {
const values = await instanceRef.validate();
dataSets[key].submitValues = values;
}
}
}
const {layoutCode, metaKeys, dataSetMap} = getDataSets(dynamicInfo, dataSets);
return [{layoutCode, metaKeys, ...dataSetMap}];
// save([{layoutCode, metaKeys, ...dataSetMap}]).then(res => {
// saveCallBack(res);
// })
}
const getDataSets = (dynamicInfo, dataSetTree) => {
const { layoutCode } = dynamicInfo.config;
const metaKeys = { top: [] };
const dataSetMap = {};
const serverNames = {};
const saveCheckUrls = {};
const delChackUrls = {};
Object.values(dataSetTree).forEach(config => {
const { parentDataSetName, dataSetName, baseTable, parentTable, submitValues, savedCheckApi } = config;
if (baseTable !== parentTable) { // 不是同一数据源
if (parentDataSetName) {
if (dataSetMap[parentDataSetName]) { // 存在值
let currentVal = dataSetMap[parentDataSetName][0];
currentVal[dataSetName] = submitValues ? [submitValues.allValues] : [];
dataSetMap[parentDataSetName] = [currentVal];
} else {
dataSetMap[parentDataSetName] = [{
[dataSetName]: submitValues ? [submitValues.allValues] : []
}]
}
metaKeys[parentDataSetName].push(dataSetName);
metaKeys[dataSetName] = [];
} else {
if (dataSetMap[dataSetName]) { // 存在值
let currentVal = dataSetMap[dataSetName][0];
currentVal = {...(submitValues ? submitValues.allValues : {}), ...currentVal};
if (currentVal.childrenDs) {
const childs = [...currentVal.childrenDs];
delete currentVal.childrenDs;
childs.forEach(item => {
currentVal = {...currentVal, ...item};
})
}
dataSetMap[dataSetName] = [currentVal];
} else {
dataSetMap[dataSetName] = submitValues ? [submitValues.allValues] : []
}
metaKeys.top.push(dataSetName);
metaKeys[dataSetName] = [];
}
} else if (baseTable) { // 复用数据源
if (dataSetMap[parentDataSetName]) {
let currentVal = dataSetMap[parentDataSetName][0];
dataSetMap[parentDataSetName] = [{...currentVal, ...(submitValues ? submitValues.formValues : {})}];
} else {
dataSetMap[parentDataSetName] = [{childrenDs: submitValues ? submitValues.formValues : {}}]
}
}
});
return {
layoutCode, metaKeys, dataSetMap, serverNames, saveCheckUrls, delChackUrls
}
}
export {
getCustomizedProp,
getCustomized,
......@@ -193,5 +271,6 @@ export {
getRefByTabCode,
getOrganizationId,
getCurrentUser,
isTenantRoleLevel
isTenantRoleLevel,
getLayoutSaveData
};
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