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

增加逻辑: Grid 刷新映射

parent b384026f
......@@ -11,7 +11,7 @@
* @param dataMapping 映射配置
* @param rawData 源数据:    若有此输入,将认为当前是更新动作、  无此输入则认为当前是插入动作
*/
function mapping(dataMapping, rawData) {
function buildMapping(dataMapping, rawData) {
window.dataSet = {};
window.dataSet.tempId = 950366;
window.dataSet.original = JSON.parse(JSON.stringify(rawData));
......@@ -21,6 +21,34 @@ function mapping(dataMapping, rawData) {
}else {
window.dataSet.isInsert = false;
}
return mapping(rawData);
}
function refreshMapping(dataMapping, beanName, data) {
let rawData = window.dataSet.original, newData = window.dataSet.newData;
rawData[beanName] = data;
let currentData = newData[beanName];
data.forEach(item => {
currentMapping = window.dataMapping[beanName];
if(!currentMapping) {
console.error('找不到该映射,请检查映射配置是否存在该配置: ' + beanName);
return;
}
let idProperty = currentMapping.id;
let id = item[idProperty];
if(!currentData.compares) { currentData.compares = {}; }
currentData.compares[id] = item;
if(!currentData.ids) { currentData.ids = [] }
currentData.ids.push(id)
})
window.dataSet.original = JSON.parse(JSON.stringify(rawData));
let returnData = mapping(rawData);
window.dataSet.newData = JSON.parse(JSON.stringify(newData));
return returnData;
}
function mapping(rawData) {
let mapper = {}, returnData = {};
delete dataMapping.mapper;
Object.entries(dataMapping).forEach((entity) => {
......@@ -161,7 +189,7 @@ function isExist(obj, property, objName) {
}
/**
* 检查是否存在此 Grid 的映射 返回匹配到的映射
* 检查是否存在此 Grid 的映射 返回匹配到的映射
* @param str Grid Id
* @returns {{}}
*/
......@@ -177,6 +205,20 @@ function checkArrayMapper(str) {
return retrunData;
}
function onAfterEdit_(options) {
options.onAfterEdit = function(editParm) {
let gridId = editParm.column.__domid.split('|')[0], colName = editParm.column.columnname, rowNum = editParm.rowindex;
let editId = gridId + '_' + colName + '_' + rowNum;
debugger;
debugger;
// this.options.onBeforeCancelEdit.call(this, editParm)
// window.combox[editId].object.element = null;
// window.combox[editId].object.options = null;
}
}
/**
*     
* Grid 编辑前触发。 这里记录当前编辑框 对应的 Grid 行 rowIndex 和列 property <br> &nbsp;&nbsp;&nbsp;&nbsp;
......@@ -188,28 +230,54 @@ function checkArrayMapper(str) {
function onBeforeEdit_(options) {
const originalOnBeforeEdit = options.onBeforeEdit;
options.onBeforeEdit = function(editParm, gg){
let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name;
let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2];
let rowDOM;
if(!(rowDOM = document.getElementById(parentDomId))) {
parentDomId = domIds[0]+'|'+1+'|'+recordId;
rowDOM = document.getElementById(parentDomId)
}
let domIds = editParm.column.__domid.split('|'), colName = editParm.column.name;
let mapper = window.dataMapping.mapper;
let rowIndex = rowDOM.childNodes[0].childNodes[0].innerText;
let rowIndex = editParm.record.rowIndex;
let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]);
if(currentMapper.hasOwnProperty("beanName")) {
if(mapperEntry[currentMapper.beanName]) {
mapperEntry[currentMapper.beanName]['rowIndex'] = rowIndex;
mapperEntry[currentMapper.beanName]['colName'] = colName;
mapperEntry[currentMapper.beanName][rowIndex] = editParm.rowindex; // input 框定位
let currentMapping = checkArrayMapper(domIds[0]);
if(currentMapping.hasOwnProperty("beanName")) {
if(mapperEntry[currentMapping.beanName]) {
mapperEntry[currentMapping.beanName]['rowIndex'] = rowIndex;
mapperEntry[currentMapping.beanName]['colName'] = colName;
mapperEntry[currentMapping.beanName][rowIndex] = editParm.rowindex; // input 框定位
} else {
// mapperEntry[currentMapper.beanName][rowIndex] = colName;
// console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查! :" + domIds[0]);
}
}
originalOnBeforeEdit.call(this, editParm, '11');
let recordId = editParm.record.__id;
let targetDomId = domIds[0]+'|'+2+'|'+recordId +'|'+domIds[2];
let cellDOM;
if(!(cellDOM = document.getElementById(targetDomId))) {
targetDomId = domIds[0]+'|'+1+'|'+recordId +'|'+domIds[2];
cellDOM = document.getElementById(targetDomId)
}
let width = cellDOM.style.width;
settingEditDomStyle(domIds[0], editParm.value, width);
}
}
function settingEditDomStyle(eleId, inputVal, width) {
let editor = window.dataGrid[eleId].editor;
if(!editor.editing) {
setTimeout(function() {
settingEditDomStyle(eleId, inputVal, width);
}, 150);
} else {
let currentDom = editor.container[0];
if(currentDom) {
currentDom.style.width = width;
}
if(currentDom.childNodes[1]) {
// 下拉框时 添加点击事件。
let editInputDom = currentDom.childNodes[1].childNodes[0];
if(editInputDom) {
editInputDom.value = inputVal;
editInputDom.click();
}
}
}
}
......@@ -243,11 +311,19 @@ function listeningSearchbox(elId, options, gridId) {
if(property.rowIndex) {
let rowIndex = property.rowIndex;
let propertyName = property.colName;
let gridEdit = window.dataGrid['fronColorsGrid'].editor;
let gridEdit = window.dataGrid[gridId].editor;
if(!gridEdit.editParm.column) {
debugger;
}
if(gridEdit.editParm.column.editor.type === 'select') {
let fillProperty = gridEdit.editParm.column.editor.fillProperty
window.dataSet.newData[beanName].compares[rowIndex][fillProperty] = data[fillProperty];//更新数据
window.dataGrid[gridId].editor.editParm.record[propertyName] = data[propertyName]; //更新显示
// ------------------ 结束编辑时销毁此下拉框 ------------------
if(!window.combox) { window.combox = {}; }
window.combox[gridEdit.input[0].id] = {};
window.combox[gridEdit.input[0].id].isCreate = true;
window.combox[gridEdit.input[0].id].object = this;
}
gridManager = window.dataGrid[gridId];
property.rowIndex = null;
......@@ -258,9 +334,7 @@ function listeningSearchbox(elId, options, gridId) {
}
})
if(gridManager) {
originalOnChange.call(this, value, data, gridManager);
}
originalOnChange.call(this, value, data, gridManager);
}
$(elId).searchbox(options);
}
......@@ -282,7 +356,12 @@ function DropdownTrigger(node) {
let nodeId = node.id;
let tempId = nodeId.slice(0, nodeId.lastIndexOf('_'));
if(node.getAttribute('select')) {
listeningSearchbox('#'+nodeId, window.gridSearchboxOptions[tempId], nodeId.split('_')[0]);
if(!window.combox || !window.combox[nodeId]){
listeningSearchbox('#'+nodeId, window.gridSearchboxOptions[tempId], nodeId.split('_')[0]);
} else if(window.combox[nodeId]) {
// 避免重复创建
$('#'+nodeId).searchbox(window.gridSearchboxOptions[tempId]);
}
}
}
......@@ -307,9 +386,10 @@ function listeningGrid(elId, options) {
data.Rows = '';
} else { data.Rows = options.data.raw; }
options.data = data;
// ------------------ 编辑框打开前记录当前行 ------------------
// ------------------ 编辑前 记录当前 cell ------------------
onBeforeEdit_(options);
// ------------------ 编辑后 销毁下拉框 ------------------
onAfterEdit_(options);
const toolbar = options.toolbar;
if(toolbar) {
toolbar.items
......@@ -579,3 +659,34 @@ function getHashCode (str, caseSensitive) {
return (hash ^ hash2 ^ hash3 >> 3 ) & 0x7FFFFFFF;
}
}
//
// function onBeforeEdit_(options) {
// const originalOnBeforeEdit = options.onBeforeEdit;
// options.onBeforeEdit = function(editParm, gg){
// let domIds = editParm.column.__domid.split('|'), recordId = editParm.record.__id, colName = editParm.column.name;
// let parentDomId = domIds[0]+'|'+2+'|'+recordId; // +'|'+domIds[2];
// let rowDOM;
// if(!(rowDOM = document.getElementById(parentDomId))) {
// parentDomId = domIds[0]+'|'+1+'|'+recordId;
// rowDOM = document.getElementById(parentDomId)
// }
// let mapper = window.dataMapping.mapper;
// // let rowIndex = rowDOM.childNodes[0].childNodes[0].innerText;
// let rowIndex = editParm.record.rowIndex;
// let mapperEntry = mapper[colName];
// let currentMapper = checkArrayMapper(domIds[0]);
// debugger;
// if(currentMapper.hasOwnProperty("beanName")) {
// if(mapperEntry[currentMapper.beanName]) {
// mapperEntry[currentMapper.beanName]['rowIndex'] = rowIndex;
// mapperEntry[currentMapper.beanName]['colName'] = colName;
// mapperEntry[currentMapper.beanName][rowIndex] = editParm.rowindex; // input 框定位
// } else {
// // mapperEntry[currentMapper.beanName][rowIndex] = colName;
// // console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
// }
// }
// originalOnBeforeEdit.call(this, editParm, '11');
// }
// }
......@@ -46,8 +46,8 @@ function initializateSelectC() {
Public.ajax(web_app.name + "/product/queryProcessbyTechnologyId.ajax",{
productTechnologyId: data.productTechnologyId
},function (data) {
window.dataSet.original.processed = data;
let showData = mapping(dataMapping, window.dataSet.original);
let showData = refreshMapping(dataMapping, 'processed', data);
$('#submitForm').formClean();
$('#submitForm').formSet(showData);
processedGrid('#processedGrid', window.dataSet.rawData.processed);
......@@ -57,15 +57,22 @@ function initializateSelectC() {
});
}
function initGridSearchbox() {
listeningGridSearchbox('fronColorsGrid_colorName', {
type: "product",
name: "color",
autocomplete: true,
onChange: function (value, data, fillInValue) {
console.log('fillInValue : '+ fillInValue);
}
})
});
listeningGridSearchbox('backColorsGrid_colorName', {
type: "product",
name: "color",
autocomplete: true,
onChange: function (value, data, fillInValue) {
}
});
}
......@@ -125,7 +132,7 @@ function loadDataTest() {
Public.ajax(web_app.name + "/product/loadProductDetail.ajax", {
data: params.get("data")
}, function (data) {
var showData = mapping(dataMapping, data.rawData);
var showData = buildMapping(dataMapping, data.rawData);
$('#submitForm').formSet(showData);
var fronData = {};
if(window.dataSet.isInsert) {
......@@ -232,8 +239,8 @@ function faceGrid(elId, data) {
onBeforeEdit : function(editParm, gg) {
console.log('original run onBeforeEdit()');
},
onAfterEdit: function() {
debugger;
onBeforeSubmitEdit: function(editParm, gg){
// debugger;
},
});
}
......
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