提交 86053616 authored 作者: vipcxj's avatar vipcxj

fix:嵌套属性会被JSON.stringify第二参数过滤掉

上级 d4d098de
......@@ -10,8 +10,7 @@ const defaultOptions = {
},
};
const sortBodyForToken = (body) => {
const keys = Object.keys(body);
const sortBodyForToken = (keys) => {
const idxToken = keys.indexOf('token');
if (idxToken !== -1) {
if (idxToken === 0) {
......@@ -26,6 +25,12 @@ const sortBodyForToken = (body) => {
}
};
const orderedStringify = (obj) => {
const allKeys = [];
JSON.stringify(obj, (k, v) => { allKeys.push(k); return v; });
return JSON.stringify(obj, sortBodyForToken(allKeys));
};
export default async function post(url, data, params = {}, options = {}, auth = true) {
if (!data) {
data = {};
......@@ -48,7 +53,7 @@ export default async function post(url, data, params = {}, options = {}, auth =
realOptions.headers['Content-Type'] = 'application/json';
realOptions.method = 'POST';
const body = res ? res.data : data;
realOptions.body = JSON.stringify(body, sortBodyForToken(body));
realOptions.body = orderedStringify(body);
return fetch(realUrl, realOptions)
.then(checkStatus)
.then(resp => parseObject(resp, middleware.post.onResponse));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论