Commit be16cb41 authored by 覃振观's avatar 覃振观 👶

Grid 添加、删除

parent 1a9b5b9b
......@@ -7,7 +7,6 @@
function mapping(dataMapping, rawData) {
window.dataSet = {};
window.dataSet.tempId = 950366;
debugger;
if(!rawData) {
window.dataSet.isInsert = true;
var rawData = {};
......@@ -49,24 +48,28 @@ function mapping(dataMapping, rawData) {
}
let listMap = {}, ids = [], rowId = ''; //tryForEach 变量作用域注意
entityData.forEach(rowData => {
debugger;
rowId = rowData[propertyNames.id];
rowData['rowIndex'] = rowId;
listMap[rowId] = rowData;
ids.push(rowId);
tryForEach(propertyNames.columns, (property) => {
if(!mapper[property]) {
mapper[property] = {};
}
let data = {};
data['listeningKey'] = rowId;
mapper[property][beanName] = data;
});
settingGridMapper(propertyNames.columns, mapper, rowId, beanName);
// propertyNames.columns.forEach(property => {
// if(!mapper[property]) {
// mapper[property] = {};
// }
// if(!mapper[property][beanName]) {
// mapper[property][beanName] = {};
// }
// let mapperData = {};
// mapperData[rowId] = {};
// mapper[property][beanName].push(mapperData);
// });
})
rawData[beanName] = {};
rawData[beanName].raw = entityData;
rawData[beanName].compares = listMap;
rawData[beanName].ids = ids;
debugger;
return;
}
});
......@@ -80,6 +83,21 @@ function mapping(dataMapping, rawData) {
return returnData;
}
function settingGridMapper(propertyNames, mapper, rowId, beanName, data) {
propertyNames.forEach(property => {
if(!mapper[property]) {
mapper[property] = {};
}
if(!mapper[property][beanName]) {
mapper[property][beanName] = {};
}
mapper[property][beanName][rowId] = {};
if(data) {
data[property] = '';
}
});
}
/**
* 映射关系 => elementName(alias): { objName: property }
* @param data 数据源
......@@ -158,17 +176,13 @@ function checkArrayMapper(str) {
* @returns {*}
*/
function listeningGrid(elId, options) {
tryForEach(Object.entries(window.dataMapping), entry => {
let beanName = entry[0], property = entry[1];
if(elId.indexOf(beanName) >= 0) {
let gridId = property.id;
if(!gridId) {
let currentMapper = checkArrayMapper(elId);
if(!currentMapper.property.id) {
console.error("若需要监听 GridData ,必须在映射配置指定 ID !请检查。");
throw {};
}
options.columns.unshift({ name: gridId, hide: true });
return;
}
});
options.columns.unshift({ name: 'rowIndex', hide: true });
debugger;
let data = {};
if(!options.data){
......@@ -184,15 +198,14 @@ function listeningGrid(elId, options) {
toolbar.items
tryForEach(toolbar.items, but => {
// ------------------ Grid 新增行时,设置 mapper、 newData -----------------
debugger;
if(but.id === "menuAdd") {
// 使用 gridManager 对象 可以省略 页面监听操作。需要修改。
const originalOnClick = but.click;
but.click = function() {
Object.entries(window.dataMapping).forEach(entry => {
let beanName = entry[0];
if(elId.indexOf(beanName) >= 0) {
let idProperty = entry[1].id;
debugger;
let currentMapper = checkArrayMapper(elId);
let beanName = currentMapper.beanName;
let idProperty = currentMapper.property.id;
if(!idProperty) {
console.error("若需要监听 GridData ,必须在映射配置指定 ID !请检查。");
throw {};
......@@ -200,18 +213,19 @@ function listeningGrid(elId, options) {
let mapper = window.dataMapping.mapper;
let rowId = window.dataSet.tempId += 1
let data = {}, mapperData = {};
// ------------- 设置 mapper -------------
debugger;
tryForEach(entry[1].columns, property => {
mapperData['listeningKey'] = rowId + '';
if(!mapper[property]) {
mapper[property] = {};
}
mapper[property][beanName] = mapperData;
data[property] = '';
});
settingGridMapper(currentMapper.property.columns, mapper, rowId, beanName);
// currentMapper.property.columns.forEach(property => {
// mapperData[rowId] = {};
// if(!mapper[property]) {
// mapper[property] = {};
// }
// mapper[property][beanName] = mapperData;
//
// });
data[idProperty] = rowId;
data['rowIndex'] =rowId
// ------------- 设置 compares -------------
if(!window.dataSet.newData[beanName]) {
window.dataSet.newData[beanName] = {};
......@@ -220,15 +234,12 @@ function listeningGrid(elId, options) {
window.dataSet.newData[beanName].compares = {};
}
window.dataSet.newData[beanName].compares[rowId] = data;
// ------------- 设置 ids -------------
if(!window.dataSet.newData[beanName].ids) {
window.dataSet.newData[beanName].ids = [];
}
window.dataSet.newData[beanName].ids.push(rowId);
UICtrl.addGridRow(gridManager, data);
}
})
originalOnClick.call(this, data);
}
}
......@@ -253,7 +264,6 @@ function listeningGrid(elId, options) {
}
}
})
debugger;
}
addObserver(elId);
var gridManager = UICtrl.grid(elId, options);
......@@ -284,7 +294,7 @@ function onBeforeEdit_(options) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId;
mapperEntry[currentMapper.beanName]['rowIndex'] = editParm.rowindex;
mapperEntry[currentMapper.beanName][rowId]['rowIndex'] = editParm.rowindex;
}
}
originalOnBeforeEdit.call(this, editParm, '11');
......@@ -310,26 +320,33 @@ function inputEventListener() {
function listenerContent(event) {
const property = event.target.getAttribute('name'), editId = event.target.id;
const beanMapping = window.dataMapping.mapper[property];
debugger;
if(!beanMapping) {
console.error("The configuration was not found in the 'dataMapping' : '"+property+"'")
}
let control = getControlType(beanMapping);
let control;
let inputIds = event.target.id.split('_');
let currentMapper = checkArrayMapper(inputIds[0]);
if (currentMapper.property.id) {
control = 'grid';
} else {
control = 'form';
}
// Grid 时执行此逻辑
if(control === 'grid') {
let inputIds = editId.split('_');
debugger;
tryForEach(Object.entries(beanMapping), mapperEntry => {
let mapperKey = mapperEntry[0], mapperVal = mapperEntry[1];
if(inputIds[0].lastIndexOf(mapperKey) >= 0) {
if(mapperVal.rowIndex === inputIds[2] * 1) {
window.dataSet.newData[mapperKey].compares[mapperVal.listeningKey][inputIds[1]] = event.target.value;
Object.entries(mapperEntry[1]).forEach(rowEntry => {
let rowId = rowEntry[0];
if(rowEntry[1].rowIndex != undefined) {
if(rowEntry[1].rowIndex === inputIds[2] * 1) {
window.dataSet.newData[mapperKey].compares[rowId][inputIds[1]] = event.target.value;
console.log('Input value changed:', event.target.value);
} else {
console.error('当前输入框 '+ event.target.id+ '无法与数据行'+ mapperKey + ':' + mapperVal.rowIndex + '匹配!');
}
}
})
})
return;
}
// Form 时执行此逻辑
......@@ -344,16 +361,17 @@ function listenerContent(event) {
}
}
function getControlType(beanMapping) {
let control;
// 这里根据 grid 与 form 的 mapper 数据结构差异判定。 需要优化
if(Object.entries(beanMapping)[0][1]['listeningKey']) {
control = 'grid';
} else {
control = 'form';
}
return control;
}
// function getControlType(beanMapping) {
// let control;
// // 这里根据 grid 与 form 的 mapper 数据结构差异判定。 需要优化
// debugger;
// if(Object.entries(beanMapping)[0][1]['listeningKey']) {
// control = 'grid';
// } else {
// control = 'form';
// }
// return control;
// }
/**
* 添加 DOM 监听
......
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