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

优化 upObjKey 方法

上级 52f08607
......@@ -5,6 +5,7 @@ import { queryOauthActionPath } from '@/webPublic/one_stop_public/utils/queryCon
import { getToken } from '@/webPublic/one_stop_public/utils/token';
import { deepCopy } from '@/webPublic/zyd_public/utils/utils';
import { getTransformApi } from '@/webPublic/one_stop_public/2022beidianke/localstorageTransform';
import moment from 'moment';
const apiUrl = queryOauthActionPath();
......@@ -726,16 +727,20 @@ export function upObjKey(obj, setKey = {}) {
if (objType === "[object Object]" && Object.keys(obj).length > 0) {
for (var e in setKey) {
let upKey = setKey[e];
obj[upKey] = obj[e];
delete obj[e];
let { newKey, type, timeFormat } = getSetKeyValue(upKey);
obj = getSetKeyJson({
obj, e, newKey, type, timeFormat
});
}
}
if (objType === "[object Array]" && obj.length > 0) {
obj.forEach((v, i) => {
obj.forEach((v, i, arr) => {
for (var e in setKey) {
let upKey = setKey[e];
v[upKey] = v[e];
delete v[e];
let { newKey, type, timeFormat } = getSetKeyValue(upKey);
arr[i] = getSetKeyJson({
obj: v, e, newKey, type, timeFormat
});
}
})
}
......@@ -749,6 +754,43 @@ export function upObjKey(obj, setKey = {}) {
}
}
function getSetKeyValue(value) {
let valeuType = Object.prototype.toString.call(value);
let newName = null;
let extendJson = {
"type": "string"
};
if (valeuType === "[object String]") {
newName = value;
}
if (valeuType === "[object Object]") {
newName = value["new"];
delete value["new"];
extendJson = {
...extendJson,
...value
};
}
return {
newKey: newName,
...extendJson
}
}
function getSetKeyJson({
obj, e, newKey, type, timeFormat
}) {
switch (type) {
case "time":
debugger
obj[newKey] = timeFormat && obj[e] ? moment(obj[e]).format(timeFormat) : obj[e] || "";
break;
default:
obj[newKey] = obj[e] || "";
}
delete obj[e];
return obj;
}
// 下载附件FormdataWrapper
function isObject(value) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论