提交 df7cd9cf authored 作者: 姚鑫国's avatar 姚鑫国

upObjKey 函数优化

上级 e3fa9942
...@@ -32,16 +32,16 @@ export function getSpanJson({ ...@@ -32,16 +32,16 @@ export function getSpanJson({
}) { }) {
const dataList = deepCopy(data); const dataList = deepCopy(data);
let rowSpanData ,colSpanData = null; let rowSpanData, colSpanData = null;
try { try {
rowSpanData = getRowSpanJson(mergeKey, dataList, eliminateRow); rowSpanData = getRowSpanJson(mergeKey, dataList, eliminateRow);
} catch (err) { } catch (err) {
console.table("rowSpanData",err); console.table("rowSpanData", err);
} }
try { try {
colSpanData = getColSpanJson(mergeKey, dataList, eliminateCol); colSpanData = getColSpanJson(mergeKey, dataList, eliminateCol);
} catch (err) { } catch (err) {
console.table("colSpanData",err); console.table("colSpanData", err);
} }
return { return {
rowSpanData, rowSpanData,
...@@ -191,30 +191,30 @@ export function getColumns(columns) { ...@@ -191,30 +191,30 @@ export function getColumns(columns) {
} }
return res; return res;
} catch (e) { } catch (e) {
console.table("getColumnsData",e); console.table("getColumnsData", e);
return false; return false;
} }
} }
//递归行数 //递归行数
function getColumnsMaxLevel(arr = [] ) { function getColumnsMaxLevel(arr = []) {
//递归计算树形数据最大的层级数 //递归计算树形数据最大的层级数
let maxLevel = 0; let maxLevel = 0;
(function multiArr(arr, level=0) { (function multiArr(arr, level = 0) {
++level; ++level;
maxLevel = Math.max(level, maxLevel); maxLevel = Math.max(level, maxLevel);
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
let item = arr[i]; let item = arr[i];
item.level = level; item.level = level;
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
multiArr(item.children, level); multiArr(item.children, level);
} else { } else {
delete item.children; delete item.children;
} }
} }
})(arr, 0); })(arr, 0);
return maxLevel; return maxLevel;
} }
//递归当前数据宽度 //递归当前数据宽度
...@@ -343,7 +343,7 @@ export function getColumnsSqlKeyRealize({ ...@@ -343,7 +343,7 @@ export function getColumnsSqlKeyRealize({
ext, ext,
); );
} catch (err) { } catch (err) {
console.table("getColumnsSqlKeyRealize",err); console.table("getColumnsSqlKeyRealize", err);
} }
} }
...@@ -427,7 +427,7 @@ export function getColumnsDataRealize({ ...@@ -427,7 +427,7 @@ export function getColumnsDataRealize({
}); });
}); });
} catch (err) { } catch (err) {
console.table("getColumnsDataRealize",err); console.table("getColumnsDataRealize", err);
} }
...@@ -485,7 +485,7 @@ export function getColumnsDataRealize({ ...@@ -485,7 +485,7 @@ export function getColumnsDataRealize({
ext, ext,
); );
} catch (err) { } catch (err) {
console.table("getColumnsDataRealize",err); console.table("getColumnsDataRealize", err);
} }
} }
...@@ -498,7 +498,7 @@ export function renderContentAll(value, row, index, key, spanData, cloumnNames = ...@@ -498,7 +498,7 @@ export function renderContentAll(value, row, index, key, spanData, cloumnNames =
colSpan = spanData.colSpanData[key][index];// 横向合并 colSpan = spanData.colSpanData[key][index];// 横向合并
rowSpan = spanData.rowSpanData[key][index];// 纵向合并 rowSpan = spanData.rowSpanData[key][index];// 纵向合并
} catch (err) { } catch (err) {
console.table("renderContentAll",err); console.table("renderContentAll", err);
} }
const obj = { const obj = {
children: value, children: value,
...@@ -526,7 +526,7 @@ export function renderContentRow(value, row, index, key, spanData, cloumnNames = ...@@ -526,7 +526,7 @@ export function renderContentRow(value, row, index, key, spanData, cloumnNames =
} }
} }
} catch (err) { } catch (err) {
console.table("renderContentRow",err); console.table("renderContentRow", err);
} }
const obj = { const obj = {
children: value, children: value,
...@@ -662,12 +662,12 @@ export function getListWord({ ...@@ -662,12 +662,12 @@ export function getListWord({
paramsList.forEach((v, i) => { paramsList.forEach((v, i) => {
let files = []; let files = [];
let paramsObj = deepCopy(v); let paramsObj = deepCopy(v);
for(var ki in filesKey){ for (var ki in filesKey) {
let files_ = v[filesKey[ki]]; let files_ = v[filesKey[ki]];
try { try {
files = [...files, ...JSON.parse(files_).files] files = [...files, ...JSON.parse(files_).files]
} catch (e) { } catch (e) {
} }
delete paramsObj[filesKey[ki]]; delete paramsObj[filesKey[ki]];
} }
...@@ -680,7 +680,7 @@ export function getListWord({ ...@@ -680,7 +680,7 @@ export function getListWord({
...getObjectsKey(allValuesKey, paramsObj) ...getObjectsKey(allValuesKey, paramsObj)
}, },
title: (paramsObj[sonTitleKey] || "未设置名称") + `.${sonExt}`, title: (paramsObj[sonTitleKey] || "未设置名称") + `.${sonExt}`,
files:JSON.stringify(files) files: JSON.stringify(files)
}); });
}); });
let getFileData = giveFilePostDataInfoForTrue( let getFileData = giveFilePostDataInfoForTrue(
...@@ -740,79 +740,93 @@ function setObjectKey(data) { ...@@ -740,79 +740,93 @@ function setObjectKey(data) {
* @param {*} setKey {"被修改的key":"修改后的key"} * @param {*} setKey {"被修改的key":"修改后的key"}
* @returns * @returns
*/ */
export function upObjKey(obj, setKey = {},defaultValue="") { export function upObjKey(obj, setKey = {}, defaultValue = "") {
try { try {
obj = deepCopy(obj); obj = deepCopy(obj);
setKey = deepCopy(setKey); setKey = deepCopy(setKey);
let objType = Object.prototype.toString.call(obj); let objType = Object.prototype.toString.call(obj);
if (obj && (objType.indexOf("Array") > -1 || objType.indexOf("Object") > -1) && Object.keys(setKey).length > 0) { if (obj && (objType.indexOf("Array") > -1 || objType.indexOf("Object") > -1) && Object.keys(setKey).length > 0) {
if (objType === "[object Object]" && Object.keys(obj).length > 0) { let nowObj = null;
for (var e in setKey) { if (objType === "[object Object]" && !Array.isArray(obj) && Object.keys(obj).length > 0) {
let upKey = setKey[e]; nowObj = deepCopy(obj);
let { newKey = e, type, timeFormat } = getSetKeyValue(upKey); for (var e in setKey) {
obj = getSetKeyJson({ let upKey = setKey[e];
obj, e, newKey, type, timeFormat,defaultValue let { newKey = e, type, timeFormat } = getSetKeyValue(upKey);
}); nowObj = {
} ...nowObj,
} ...getSetKeyJson({
if (objType === "[object Array]" && obj.length > 0) { obj, e, newKey, type, timeFormat, defaultValue
obj.forEach((v, i, arr) => {
for (var e in setKey) {
let upKey = setKey[e];
let { newKey = e, type, timeFormat } = getSetKeyValue(upKey);
arr[i] = getSetKeyJson({
obj: v, e, newKey, type, timeFormat,defaultValue
});
}
}) })
};
delete nowObj[e];
} }
return obj; }
if (objType === "[object Array]" && Array.isArray(obj) && obj.length > 0) {
nowObj = new Array();
obj.forEach((v, i, arr) => {
let newJson = deepCopy(v);
for (var e in setKey) {
let upKey = setKey[e];
let { newKey = e, type, timeFormat } = getSetKeyValue(upKey);
newJson = {
...newJson,
...getSetKeyJson({
obj: v, e, newKey, type, timeFormat, defaultValue
})
};
delete newJson[e];
}
nowObj.push(newJson);
})
}
return nowObj;
} else { } else {
return null; return null;
} }
} catch (error) { } catch (error) {
console.log("upObjKey",error); console.log("upObjKey", error);
return undefined; return undefined;
} }
} }
function getSetKeyValue(value) { function getSetKeyValue(value) {
let valeuType = Object.prototype.toString.call(value); let valeuType = Object.prototype.toString.call(value);
let newName = null; let newName = null;
let extendJson = { let extendJson = {
"type": "string" "type": "string"
}; };
if (valeuType === "[object String]") { if (valeuType === "[object String]") {
newName = value; newName = value;
} }
if (valeuType === "[object Object]") { if (valeuType === "[object Object]") {
newName = value["new"]; newName = value["new"];
delete value["new"]; delete value["new"];
extendJson = { extendJson = {
...extendJson, ...extendJson,
...value ...value
}; };
} }
return { return {
newKey: newName, newKey: newName,
...extendJson ...extendJson
} }
} }
function getSetKeyJson({ function getSetKeyJson({
obj, e, newKey, type, timeFormat,defaultValue obj, e, newKey, type, timeFormat = "YYYY-MM-DD HH:mm:ss", defaultValue
}) { }) {
obj = deepCopy(obj); obj = deepCopy(obj);
let value = obj[e]; let value = obj[e];
delete obj[e]; let newKeyObj = {};
// delete obj[e];
switch (type) { switch (type) {
case "time": case "time":
obj[newKey] = (timeFormat && value ? moment(value).format(timeFormat) : value) || defaultValue; newKeyObj[newKey] = (timeFormat && value ? moment(value).format(timeFormat) : value) || defaultValue;
break; break;
default: default:
obj[newKey] = value || defaultValue; newKeyObj[newKey] = value || defaultValue;
} }
return obj; return newKeyObj;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论