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

upObjKey 函数优化

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