提交 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,16 +191,16 @@ export function getColumns(columns) { ...@@ -191,16 +191,16 @@ 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++) {
...@@ -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,7 +662,7 @@ export function getListWord({ ...@@ -662,7 +662,7 @@ 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]
...@@ -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,38 +740,51 @@ function setObjectKey(data) { ...@@ -740,38 +740,51 @@ 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;
if (objType === "[object Object]" && !Array.isArray(obj) && Object.keys(obj).length > 0) {
nowObj = deepCopy(obj);
for (var e in setKey) { for (var e in setKey) {
let upKey = setKey[e]; let upKey = setKey[e];
let { newKey = e, type, timeFormat } = getSetKeyValue(upKey); let { newKey = e, type, timeFormat } = getSetKeyValue(upKey);
obj = getSetKeyJson({ nowObj = {
obj, e, newKey, type, timeFormat,defaultValue ...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) => { obj.forEach((v, i, arr) => {
let newJson = deepCopy(v);
for (var e in setKey) { for (var e in setKey) {
let upKey = setKey[e]; let upKey = setKey[e];
let { newKey = e, type, timeFormat } = getSetKeyValue(upKey); let { newKey = e, type, timeFormat } = getSetKeyValue(upKey);
arr[i] = getSetKeyJson({ newJson = {
obj: v, e, newKey, type, timeFormat,defaultValue ...newJson,
}); ...getSetKeyJson({
obj: v, e, newKey, type, timeFormat, defaultValue
})
};
delete newJson[e];
} }
nowObj.push(newJson);
}) })
} }
return obj; return nowObj;
} else { } else {
return null; return null;
} }
} catch (error) { } catch (error) {
console.log("upObjKey",error); console.log("upObjKey", error);
return undefined; return undefined;
} }
} }
...@@ -800,19 +813,20 @@ function getSetKeyValue(value) { ...@@ -800,19 +813,20 @@ function getSetKeyValue(value) {
} }
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论