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

优化 upObjKey 方法

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