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

5555

parent db845d4a
...@@ -16,22 +16,21 @@ function mapping(dataMapping, rawData) { ...@@ -16,22 +16,21 @@ function mapping(dataMapping, rawData) {
} }
let mapper = {}, returnData = {}; let mapper = {}, returnData = {};
delete dataMapping.mapper; delete dataMapping.mapper;
let entitySet = Object.entries(dataMapping); Object.entries(dataMapping).forEach((entity) => {
tryForEach(entitySet,(entity) => {
let beanName = entity[0], propertyNames = entity[1], entityData = rawData[beanName]; let beanName = entity[0], propertyNames = entity[1], entityData = rawData[beanName];
if(!isExist(rawData, beanName)) { throw {}; } if(!isExist(rawData, beanName)) { return; }
if(!entityData) { entityData = {}; }
if(propertyNames instanceof Array) { if(propertyNames instanceof Array) {
// Form 时执行此逻辑 // Form 时执行此逻辑
tryForEach(propertyNames,(item) => { tryForEach(propertyNames,(item) => {
if(!entityData) { entityData = {}; }
if(typeof item === "string") { if(typeof item === "string") {
if(!isExist(entityData, item, beanName)) { throw {}; } if(!isExist(entityData, item, beanName)) { return; }
associate(entityData, item, item, beanName,mapper, returnData); associate(entityData, item, item, beanName,mapper, returnData);
return; return;
} else if(item instanceof Object) { } else if(item instanceof Object) {
let entry = Object.entries(item)[0]; let entry = Object.entries(item)[0];
let property = entry[0], alias = entry[1]; let property = entry[0], alias = entry[1];
if(!isExist(entityData, property, beanName)) { throw {}; } if(!isExist(entityData, property, beanName)) { return; }
associate(entityData, property, alias, beanName,mapper, returnData) associate(entityData, property, alias, beanName,mapper, returnData)
} else { } else {
console.error('The configuration of "'+item+'" in "'+beanName+'" is not recognized, and the required,' + console.error('The configuration of "'+item+'" in "'+beanName+'" is not recognized, and the required,' +
...@@ -108,7 +107,9 @@ function testTryForEach() { ...@@ -108,7 +107,9 @@ function testTryForEach() {
const tryForEach = function(arrayObj, callback) { const tryForEach = function(arrayObj, callback) {
try { try {
arrayObj.forEach(callback); arrayObj.forEach(callback);
} catch { } } catch(error) {
console.error(error);
}
} }
/** /**
...@@ -176,39 +177,19 @@ function listeningGrid(elId, options) { ...@@ -176,39 +177,19 @@ function listeningGrid(elId, options) {
} else { data.Rows = options.data.raw; } } else { data.Rows = options.data.raw; }
options.data = data; options.data = data;
// ------------------ 编辑框打开前记录当前行 ------------------ // ------------------ 编辑框打开前记录当前行 ------------------
const originalOnBeforeEdit = options.onBeforeEdit; onBeforeEdit_(options);
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 rowId = rowDOM.childNodes[0].childNodes[0].innerText;
let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]);
debugger;
if(currentMapper.hasOwnProperty("beanName")) {
if(!mapperEntry[currentMapper.beanName]) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId;
mapperEntry[currentMapper.beanName]['rowIndex'] = editParm.rowindex;
}
}
originalOnBeforeEdit.call(this, editParm, '11');
}
const toolbar = options.toolbar; const toolbar = options.toolbar;
if(toolbar) { if(toolbar) {
toolbar.items toolbar.items
tryForEach(toolbar.items, but => { tryForEach(toolbar.items, but => {
// ------------------ Grid 新增行时,设置 mapper、 newData -----------------
debugger;
if(but.id === "menuAdd") { if(but.id === "menuAdd") {
// 使用 gridManager 对象 可以省略 页面监听操作。需要修改。
const originalOnClick = but.click; const originalOnClick = but.click;
but.click = function() { but.click = function() {
let mappingEntry = Object.entries(window.dataMapping); Object.entries(window.dataMapping).forEach(entry => {
mappingEntry.forEach(entry => {
let beanName = entry[0]; let beanName = entry[0];
if(elId.indexOf(beanName) >= 0) { if(elId.indexOf(beanName) >= 0) {
let idProperty = entry[1].id; let idProperty = entry[1].id;
...@@ -250,7 +231,26 @@ function listeningGrid(elId, options) { ...@@ -250,7 +231,26 @@ function listeningGrid(elId, options) {
}) })
originalOnClick.call(this, data); originalOnClick.call(this, data);
} }
}
if(but.id === "menuDelete") {
const originalOnClick = but.click;
but.click = function() {
let selectRow = gridManager.getSelectedRow();
let currentMapper = checkArrayMapper(gridManager.id);
let beanName = currentMapper.beanName;
let currentData = window.dataSet.newData[beanName];
let propertyId = window.dataMapping[beanName].id;
let currentId = selectRow[propertyId];
delete currentData.compares[currentId];
currentData.ids.pop(currentId);
// window.dataMapping[beanName].columns.forEach(property => {
// window.dataMapping.mapper[property][beanName]
// });
gridManager.deleteSelectedRow();
originalOnClick.call(this, selectRow);
}
} }
}) })
debugger; debugger;
...@@ -258,7 +258,37 @@ function listeningGrid(elId, options) { ...@@ -258,7 +258,37 @@ function listeningGrid(elId, options) {
addObserver(elId); addObserver(elId);
var gridManager = UICtrl.grid(elId, options); var gridManager = UICtrl.grid(elId, options);
return gridManager; return gridManager;
}
/**
* Grid 编辑前触发。 这里记录当前编辑框 对应的 Grid 行索引 GridRowIndex
* @param options
* @private
*/
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 rowId = rowDOM.childNodes[0].childNodes[0].innerText;
let mapperEntry = mapper[colName];
let currentMapper = checkArrayMapper(domIds[0]);
if(currentMapper.hasOwnProperty("beanName")) {
if(!mapperEntry[currentMapper.beanName]) {
console.error("dataMapping 中,无法找到该 DOMId 的映射。请检查!");
} else {
//mapperEntry[currentMapper.beanName]['rowId'] = parentDomId;
mapperEntry[currentMapper.beanName]['rowIndex'] = editParm.rowindex;
}
}
originalOnBeforeEdit.call(this, editParm, '11');
}
} }
/** /**
......
...@@ -93,6 +93,7 @@ function loadDataTest() { ...@@ -93,6 +93,7 @@ function loadDataTest() {
faceGrid("#fronColorsGrid", data.rawData.fronColors); faceGrid("#fronColorsGrid", data.rawData.fronColors);
faceGrid("#backColorsGrid", data.rawData.backColors); faceGrid("#backColorsGrid", data.rawData.backColors);
processedGrid('#processedGrid', data.rawData.processed); processedGrid('#processedGrid', data.rawData.processed);
debugger;
productLossGrid('#productLossGrid', data.rawData.productLoss); productLossGrid('#productLossGrid', data.rawData.productLoss);
inputEventListener(); inputEventListener();
}); });
...@@ -104,12 +105,12 @@ function loadDataTest() { ...@@ -104,12 +105,12 @@ function loadDataTest() {
// Grid: 需要监听 Grid Data 时,必须设置 唯一 id 列。 // Grid: 需要监听 Grid Data 时,必须设置 唯一 id 列。
var dataMapping = { var dataMapping = {
Product: [ Product: [
"productId", "brandName","productCategoryId", "productUnit", "productSizeGroupId", "confirmDate", "comfirmPerson", "productId", "brandName","productCategoryId", "productUnit", "productSizeGroupId", "confirmDate", "comfirmPerson"
"isFreeInspection", "isNoQualityLoss", "sampleOrderNo", "stockNo", "fileNo", "brandName" , "isFreeInspection", "isNoQualityLoss", "sampleOrderNo", "stockNo", "fileNo", "brandName"
], ],
ProductDetail: [ ProductDetail: [
{"factoryName": "factoryName"}, "productLayout", "materialCode", "productCode", "productEnCode", "bodyColor", {"factoryName": "factoryName"}, "productLayout", "materialCode", "productCode", "productEnCode", "bodyColor"
"customerMaterialCode" ,"versionNo", "isNewSpecification", "specificationNo" , "customerMaterialCode" ,"versionNo", "isNewSpecification", "specificationNo"
], ],
ProductLooked: [ ProductLooked: [
"productLength", "productWidth", "productHeight", "productThick", "productWeight", "productAngleType", "productAngle" "productLength", "productWidth", "productHeight", "productThick", "productWeight", "productAngleType", "productAngle"
...@@ -117,8 +118,8 @@ var dataMapping = { ...@@ -117,8 +118,8 @@ var dataMapping = {
, "productSysCertification", "storeName", "productBuyUnit", "purchaseConversionValue", "coefficient" , "productSysCertification", "storeName", "productBuyUnit", "purchaseConversionValue", "coefficient"
], ],
ProductTechnology: [ ProductTechnology: [
"beerPlateNo", "goldPlateNo" , "dieCutPlateNo", "copperpResinLateNo", "netPlateNo", "beerPlateNo", "goldPlateNo" , "dieCutPlateNo", "copperpResinLateNo", "netPlateNo"
"productTechnologyRequire", "packageStyle", "packageStyle", "physicalTest", "chemistryTest" , "productTechnologyRequire", "packageStyle", "packageStyle", "physicalTest", "chemistryTest"
, "productMaterial" , "productMaterial"
, "copperpNo", "colorNoCard", "plateNo", "plasticBagStructure" , "copperpNo", "colorNoCard", "plateNo", "plasticBagStructure"
], ],
...@@ -151,8 +152,8 @@ function faceGrid(elId, data) { ...@@ -151,8 +152,8 @@ function faceGrid(elId, data) {
updateHandler: function(){ updateHandler: function(){
updateHandler(); updateHandler();
}, },
deleteHandler: () => { deleteHandler: (rowData) => {
gridManager.deleteSelectedRow(); console.log(rawData);
}, },
}); });
var gridManager = listeningGrid(elId, { var gridManager = listeningGrid(elId, {
...@@ -230,11 +231,11 @@ function productLossGrid(elId, data) { ...@@ -230,11 +231,11 @@ function productLossGrid(elId, data) {
}); });
var gridManager = listeningGrid(elId, { var gridManager = listeningGrid(elId, {
columns: [ columns: [
{ display: "客户名称", name: "customerName", width: 140, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true }}, { display: "客户名称", name: "customerName", width: 140, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false }},
{ display: "产品最大loss数量", name: "productLossMax", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } }, { display: "产品最大loss数量", name: "productLossMax", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "loss比率", name: "productLossRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } }, { display: "loss比率", name: "productLossRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "备注信息", name: "productLossRedundance", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } }, { display: "备注信息", name: "productLossRedundance", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } },
{ display: "产品最大loss数量", name: "productLossRemark", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } }, { display: "产品最大loss数量", name: "productLossRemark", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: false } }
], ],
toolbar: toolbarOptions, toolbar: toolbarOptions,
dataType: "local", dataType: "local",
......
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