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

23-12-14: 下班前提交

parent 836fb0f9
/**
* 遍历映射配置,构建映射关系
* @param dataMapping 映射配置
* @param rawData 源数据:    若有此输入,将认为当前是更新动作、  无此输入则认为当前是插入动作
*/
function mapping(dataMapping, rawData) {
window.dataSet = {};
if(!rawData) {
window.dataSet.isInsert = true;
var rawData = {};
}else {
window.dataSet.isInsert = false;
}
let mapper = {};
delete dataMapping.Mapper;
let entitySet = Object.entries(dataMapping);
let returnData = {};
tryForEach(entitySet,(entity) => {
let beanName = entity[0];
if(!isExist(rawData, beanName)) { throw {}; }
let entityData = rawData[beanName];
let propertyNames = entity[1];
tryForEach(propertyNames,(item) => {
if(typeof item === "string") {
if(!isExist(entityData, item, beanName)) { throw {}; }
associate(entityData, item, item, beanName,mapper, returnData);
return;
} else if(item instanceof Array) {
// Grid需要单独赋值,这里不设置returnData. 页面Input有足够的映射信息,这里只记录 property: objName
tryForEach(item, (property) => {
mapper[property] = beanName;
});
return;
} else if(item instanceof Object) {
let entry = Object.entries(item)[0];
let property = entry[0];
if(!isExist(entityData, property, beanName)) { throw {}; }
let alias = entry[1];
associate(entityData, property, alias, beanName,mapper, returnData)
} else {
console.error('The configuration of "'+item+'" in "'+beanName+'" is not recognized, and the required,' +
' parameters are ( "propertyName" or "{ propertyName: alias }" ).');
throw {};
}
});
});
dataMapping.Mapper = mapper;
// ---------------- 暂不处理无法执行到此处的情况 ----------------
// 这里写死 映射对象为:‘dataMapping’
window.dataMapping = dataMapping;
// 这里写死 数据集:‘dataSet: { rawData: {}, newData: {} }’
window.dataSet.rawData = rawData;
window.dataSet.newData = JSON.parse(JSON.stringify(dataSet.rawData));
return returnData;
}
/**
* 映射关系 => elementName(alias): { objName: property }
* @param data 数据源
* @param property 属性
* @param alias 别名
* @param objName 对象名
* @param mapper 返回值: 映射关系
* @param returnData 返回值: 页面显示数据集
*/
function associate(data, property, alias, objName, mapper, returnData) {
mapper[alias] = {};
mapper[alias][objName] = property;
returnData[alias] = data[property];
}
function testTryForEach() {
// 直接修改原型属性, 会导致当前UI grid 组件 input 不可用,未知原因。
Array.prototype.tryForEach = function (callback) {
try {
this.forEach(callback);
} catch { }
}
}
var tryForEach = function(arrayObj, callback) {
try {
arrayObj.forEach(callback);
} catch { }
}
/**
* 检测数据中是否存在对应属性
* @param obj 需要检测数据
* @param property 需要检测的属性
* @param objName 检测的对象名
* @returns {boolean}
*/
function isExist(obj, property, objName) {
if(window.dataSet.isInsert) {
obj[property] = {};
return true;
} else {
if(!objName) { objName = 'rawData'; }
// 这里注意,后端返回的类名是否与映射配置一致
if(!obj[property]) {
console.error('No data for name of ' + property + ' in ' + objName + ' !');
return false;
}
}
return true;
}
// 监听 input 管理页面显示的 Data,提交数据时,只提交修改过的 Data
function inputEventListener() {
const inputElements = document.querySelectorAll('input');
inputElements.forEach(item => {
item.addEventListener('input', (event) => {
let mapper = window.dataMapping.Mapper;
let property = event.target.getAttribute('name');
let beanMapping = mapper[property];
if(!beanMapping) {
console.error("The configuration was not found in the 'dataMapping' : '"+property+"'")
}
if(typeof beanMapping === "string") {
debugger;
}
if(beanMapping instanceof Object) {
mappings = Object.entries(beanMapping);
tryForEach(mappings, (entry) => {
let beanName = entry[0];
let property = entry[1];
let newData = window.dataSet.newData;
newData[beanName][property] = event.target.value;
console.log('Input value changed:', event.target.value);
})
}
});
});
}
function checkUpdata() {
let rawData = window.dataSet.rawData;
let newData = window.dataSet.newData;
window.dataSet.upData = {};
let rawEntry = Object.entries(rawData);
rawEntry.forEach(raw => {
let beanName = raw[0];
let rawHash = getHashCode(JSON.stringify(rawData[beanName]));
let newHash = getHashCode(JSON.stringify(newData[beanName]));
if(!(rawHash === newHash)) {
window.dataSet.upData[beanName] = newData[beanName];
}
})
}
/**
* 用于判断字符串是否更改
* @param str
* @param caseSensitive 是否区分大小写 Default: true
* @returns {number}
*/
function getHashCode (str, caseSensitive) {
if(caseSensitive === undefined) { caseSensitive = true;}
if(!caseSensitive) {
str = str.toLowerCase();
}
if (str.length === 0) return 0;
var len = str.length;
var hash = 1315423911, i, ch;
for (i = len - 1; i >= 0; i--) {
ch = str.charCodeAt(i);
hash = (hash << 5) + ch + (hash >> 2);
}
var hash2 = hash ^ (hash << 7) ^ (hash >> 6);
var hash3 = hash2 ^ (hash2 << 1) ^ (hash2 >> 13);
if (len < 50) {
var hash4 = this.getHashCode(str + str + str, caseSensitive);
return (hash ^ hash2 ^ hash3 ^ hash4) & 0x7FFFFFFF;
} else {
return (hash ^ hash2 ^ hash3 >> 3 ) & 0x7FFFFFFF;
}
}
function runObserver() {
observer.observe(document.querySelector('#panelContainer'), mutationConfig);
}
// 补充方案 监听 Value 属性
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if(mutation.type === 'attributes'&& mutation.attributeName === 'value') {
console.log('属性变化节点 : ' + mutation.target);
console.log('变化属性名 : ' + mutation.attributeName);
console.log('变化属性值 : ' + mutation.target.value);
}
})
})
const mutationConfig = { attributes: true, childList: true, subtree: true}
\ No newline at end of file
...@@ -23,7 +23,10 @@ function loadCodeRuleListGrid() { ...@@ -23,7 +23,10 @@ function loadCodeRuleListGrid() {
}); });
gridManager = UICtrl.grid("#productListGrid", { gridManager = UICtrl.grid("#productListGrid", {
columns: [ columns: [
{ display: "产品名称", name: "productName", width: 140, minWidth: 60, type: "string", align: "left" }, { display: "产品名称", name: "productName", width: 140, minWidth: 60, type: "string", align: "left", editor: {
type: 'text',
required: true
}},
{ display: "产品类别", name: "productCategoryId", width: 120, minWidth: 60, type: "string", align: "left" }, { display: "产品类别", name: "productCategoryId", width: 120, minWidth: 60, type: "string", align: "left" },
{ display: "产品状态", name: "productStatus", width: 120, minWidth: 60, type: "string", align: "left" }, { display: "产品状态", name: "productStatus", width: 120, minWidth: 60, type: "string", align: "left" },
{ display: "产品计量单位", name: "productUnit", width: 100, minWidth: 60, type: "string", align: "left" }, { display: "产品计量单位", name: "productUnit", width: 100, minWidth: 60, type: "string", align: "left" },
...@@ -36,6 +39,7 @@ function loadCodeRuleListGrid() { ...@@ -36,6 +39,7 @@ function loadCodeRuleListGrid() {
pageSize: 20, pageSize: 20,
usePager: true, usePager: true,
toolbar: toolbarOptions, toolbar: toolbarOptions,
enabledEdit: true,
width: "50%", width: "50%",
height: "100%", height: "100%",
heightDiff: -8, heightDiff: -8,
......
$(document).ready(function() { $(document).ready(function() {
loadDataTest();
initializeUI(); initializeUI();
initializeToobarContainer(); initializeToobarContainer();
initializateSelectC(); initializateSelectC();
$('#pageTab').tab(); $('#pageTab').tab();
loadDataTest();
runObserver(); runObserver();
}); });
function initializateSelectC() { function initializateSelectC() {
...@@ -55,6 +56,10 @@ function faceGrid(elId, data) { ...@@ -55,6 +56,10 @@ function faceGrid(elId, data) {
usePager: false, usePager: false,
width: "100%", width: "100%",
height: 150, height: 150,
onAfterEdit: function(editParm) {
// 后备方案: 表格遍历完成时
debugger;
},
onDblClickRow : function(data, rowindex, rowobj) { onDblClickRow : function(data, rowindex, rowobj) {
} }
...@@ -109,6 +114,9 @@ function loadDataTest() { ...@@ -109,6 +114,9 @@ function loadDataTest() {
}); });
} }
// 数据映射配置 // 数据映射配置
// alias 必须唯一.这里不再要求所有对象的属性名唯一 { property : alias }
// 未设 alias 情况同 { property : property }
// Form 映射数据格式为: elementName(alias): { objName: property }
var dataMapping = { var dataMapping = {
Product: [ Product: [
"productId" "productId"
...@@ -118,8 +126,7 @@ var dataMapping = { ...@@ -118,8 +126,7 @@ var dataMapping = {
, "productSampleCode" , "productSampleCode"
], ],
ProductDetail: [ ProductDetail: [
"factoryName" {"factoryName": "factoryName"}
, { "productLayout": "productLayout" }
], ],
ProductLooked: [ ProductLooked: [
"productLength" "productLength"
...@@ -134,169 +141,6 @@ var dataMapping = { ...@@ -134,169 +141,6 @@ var dataMapping = {
] ]
} }
/**
* 遍历映射配置,构建映射关系
* @param dataMapping 映射配置
* @param rawData 源数据:&nbsp;&nbsp;&nbsp;&nbsp;若有此输入,将认为当前是更新动作、&nbsp;&nbsp;无此输入则认为当前是插入动作
*/
function mapping(dataMapping, rawData) {
window.dataSet = {};
if(!rawData) {
window.dataSet.isInsert = true;
var rawData = {};
}else {
window.dataSet.isInsert = false;
}
let mapper = {};
delete dataMapping.Mapper;
let entitySet = Object.entries(dataMapping);
let returnData = {};
entitySet.tryForEach((entity, index) => {
let beanName = entity[0];
if(!isExist(rawData, beanName)) { throw {}; }
let entityData = rawData[beanName];
let propertyNames = entity[1];
propertyNames.tryForEach((item, index) => {
if(typeof item === "string") {
if(!isExist(entityData, item, beanName)) { throw {}; }
let value = entityData[item];
mapper[item] = beanName;
returnData[item] = value;
console.log(item);
return;
} else if(item instanceof Array) {
debugger;
return;
} else if(item instanceof Object) {
let entry = Object.entries(item)[0];
let property = entry[0];
if(!isExist(entityData, property, beanName)) { throw {}; }
let value = entityData[property];
let alias = entry[1];
mapper[alias] = {};
mapper[alias][beanName] = property ;
returnData[alias] = value;
} else {
console.error('The configuration of "'+item+'" in "'+beanName+'" is not recognized, and the required,' +
' parameters are ( "propertyName" or "{ propertyName: alias }" ).');
throw {};
}
});
});
dataMapping.Mapper = mapper;
// ---------------- 暂不处理无法执行到此处的情况 ----------------
// 这里写死 映射对象为:‘dataMapping’
window.dataMapping = dataMapping;
// 这里写死 数据集:‘dataSet: { rawData: {}, newData: {} }’
window.dataSet.rawData = rawData;
window.dataSet.newData = JSON.parse(JSON.stringify(dataSet.rawData));
return returnData;
}
Array.prototype.tryForEach = function (callback, thisArg) {
try {
this.forEach(callback, thisArg);
} catch { }
}
/**
* 检测数据中是否存在对应属性
* @param obj 需要检测数据
* @param property 需要检测的属性
* @param objName 检测的对象名
* @returns {boolean}
*/
function isExist(obj, property, objName) {
if(window.dataSet.isInsert) {
obj[property] = {};
return true;
} else {
if(!objName) { objName = 'rawData'; }
// 这里注意,后端返回的类名是否与映射配置一致
if(!obj[property]) {
console.error('No data for name of ' + property + ' in ' + objName + ' !');
return false;
}
}
return true;
}
// 监听 input 管理页面显示的 Data,提交数据时,只提交修改过的 Data
function inputEventListener() {
const inputElements = document.querySelectorAll('input');
inputElements.forEach(item => {
item.addEventListener('input', (event) => {
let mapper = window.dataMapping.Mapper;
let property = event.target.getAttribute('name');
let beanMapping = mapper[property];
if(!beanMapping) {
console.error("The configuration was not found in the 'dataMapping' : '"+property+"'")
}
let newData = window.dataSet.newData;
newData[beanMapping][property] = event.target.value;
console.log('Input value changed:', event.target.value);
});
});
}
function checkUpdata() {
let rawData = window.dataSet.rawData;
let newData = window.dataSet.newData;
window.dataSet.upData = {};
let rawEntry = Object.entries(rawData);
rawEntry.forEach(raw => {
let beanName = raw[0];
let rawHash = getHashCode(JSON.stringify(rawData[beanName]));
let newHash = getHashCode(JSON.stringify(newData[beanName]));
if(!(rawHash === newHash)) {
window.dataSet.upData[beanName] = newData[beanName];
}
})
}
/**
* 用于判断字符串是否更改
* @param str
* @param caseSensitive 是否区分大小写 Default: true
* @returns {number}
*/
function getHashCode (str, caseSensitive) {
if(caseSensitive === undefined) { caseSensitive = true;}
if(!caseSensitive) {
str = str.toLowerCase();
}
if (str.length === 0) return 0;
var len = str.length;
var hash = 1315423911, i, ch;
for (i = len - 1; i >= 0; i--) {
ch = str.charCodeAt(i);
hash = (hash << 5) + ch + (hash >> 2);
}
var hash2 = hash ^ (hash << 7) ^ (hash >> 6);
var hash3 = hash2 ^ (hash2 << 1) ^ (hash2 >> 13);
if (len < 50) {
var hash4 = this.getHashCode(str + str + str, caseSensitive);
return (hash ^ hash2 ^ hash3 ^ hash4) & 0x7FFFFFFF;
} else {
return (hash ^ hash2 ^ hash3 >> 3 ) & 0x7FFFFFFF;
}
}
function runObserver() {
observer.observe(document.querySelector('#panelContainer'), mutationConfig);
}
// 补充方案 监听 Value 属性
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if(mutation.type === 'attributes'&& mutation.attributeName === 'value') {
console.log('属性变化节点 : ' + mutation.target);
console.log('变化属性名 : ' + mutation.attributeName);
console.log('变化属性值 : ' + mutation.target.value);
}
})
})
const mutationConfig = { attributes: true, childList: true, subtree: true}
// if(!isExist(rawData, entity[0])) { // if(!isExist(rawData, entity[0])) {
// throw {}; // throw {};
......
...@@ -9,6 +9,43 @@ ...@@ -9,6 +9,43 @@
<%@taglib uri="/WEB-INF/taglib.tld" prefix="x"%> <%@taglib uri="/WEB-INF/taglib.tld" prefix="x"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html> <html>
<head>
<title>Title</title>
<x:base include="layout,dialog,grid,tree,combox,commonTree" />
<x:script src='/javaScript/common.js'/>
<x:script src='/lib/jquery/jquery.contextmenu.js'/>
<x:script src='/system/bpm/BpmUtil.js'/>
<x:script src='/biz/topsun/common/listeningFromData.js'/>
<x:script src='/biz/topsun/product/productDetail.js'/>
<%-- <x:script src='/biz/topsun/product/product.js'/>--%>
<style>
.panelX{
height: 98%;
width: 100%;
padding: 5px;
position: relative;
display: inline-flex;
flex-direction: column;
/*background-color: #f3f3f4 !important;*/
}
.panelX > div:first-child { margin-bottom: 38px; }
.panelX > form { margin-bottom: 38px; }
.panel-footerX {
width: 100%;
left: -1px;
bottom: 0;
padding: 1px 99px;
position: fixed;
display:flex;
justify-content:center;
background: none repeat scroll 0 0 #fff0;
/*border-top: 1px solid #e7eaec;*/
/*background: none repeat scroll 0 0 #fff;*/
}
.panel-footerX > div { margin: 2px; }
</style>
</head>
<body> <body>
<div class="panelX" id="panelContainer" > <div class="panelX" id="panelContainer" >
<x:hidden name="productDetailId" /> <x:hidden name="productDetailId" />
...@@ -51,6 +88,7 @@ ...@@ -51,6 +88,7 @@
<div id="layout" style="height: 280px; display: contents;"> <div id="layout" style="height: 280px; display: contents;">
<div position="left" title="正面颜色" > <div position="left" title="正面颜色" >
<div id="frontFaceGrid" style="margin: 2px;"></div> <div id="frontFaceGrid" style="margin: 2px;"></div>
</div> </div>
<div position="right" title="反面颜色"> <div position="right" title="反面颜色">
<div id="backFaceGrid" style="margin: 2px;"></div> <div id="backFaceGrid" style="margin: 2px;"></div>
...@@ -74,39 +112,7 @@ ...@@ -74,39 +112,7 @@
</div> </div>
</body> </body>
<head>
<x:base include="layout,dialog,grid,tree,combox,commonTree" />
<x:script src='/javaScript/common.js'/>
<x:script src='/lib/jquery/jquery.contextmenu.js'/>
<x:script src='/system/bpm/BpmUtil.js'/>
<x:script src='/biz/topsun/product/productDetail.js'/>
<style>
.panelX{
height: 98%;
width: 100%;
padding: 5px;
position: relative;
display: inline-flex;
flex-direction: column;
/*background-color: #f3f3f4 !important;*/
}
.panelX > div:first-child { margin-bottom: 38px; }
.panelX > form { margin-bottom: 38px; }
.panel-footerX {
width: 100%;
left: -1px;
bottom: 0;
padding: 1px 99px;
position: fixed;
display:flex;
justify-content:center;
background: none repeat scroll 0 0 #fff0;
/*border-top: 1px solid #e7eaec;*/
/*background: none repeat scroll 0 0 #fff;*/
}
.panel-footerX > div { margin: 2px; }
</style>
</head>
</html> </html>
......
...@@ -64,9 +64,11 @@ public class ProductController extends CommonController { ...@@ -64,9 +64,11 @@ public class ProductController extends CommonController {
public String forwardProductDetail() { public String forwardProductDetail() {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
String str = "{\"productId\":1,\"productName\":\"1\",\"productCategoryId\":1,\"productStatus\":\"1\"," +
"\"productUnit\":\"1\",\"productSampleCode\":\"1\",\"brandName\":\"1\",\"productType\":\"1\",\"productCode\":\"1\",\"productSizeGroupId\":\"1\",\"isOnlyCode\":\"1\",\"isBodyColor\":\"1\",\"isDisable\":\"1\",\"isBuildBom\":\"1\",\"confirmDate\":\"2023-12-01 02:52:50\",\"comfirmPerson\":\"1\",\"isFreeInspection\":\"1\",\"isNoQualityLoss\":\"1\",\"sampleOrderNo\":\"1\",\"stockNo\":\"1\",\"stockName\":\"1\",\"fileNo\":\"1\",\"__id\":\"r1001\",\"__previd\":-1,\"__index\":0,\"__status\":\"nochanged\",\"__nextid\":\"r1002\"}";
HashMap<String, Object> param; HashMap<String, Object> param;
try { try {
param = objectMapper.readValue(sdo.getString("data"), new TypeReference<HashMap<String, Object>>() {}); param = objectMapper.readValue(str, new TypeReference<HashMap<String, Object>>() {});
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
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