提交 0495c15c authored 作者: vipcxj's avatar vipcxj

fix: delete方法不能保护http body,传参必须用query参数。

fix: 生成菜单数据出错。
上级 76451936
import { routerRedux } from 'dva/router';
import { isString } from 'lodash';
import { logout } from '../../services/main';
import { fetchDomains, switchDomain, currentDomain } from '../../services/domain';
import { cookie } from '../../utils/config';
import { getMenus } from '../../data/modules';
import { getMenus, getModuleInfo } from '../../data/modules';
import { setCookie, delCookie, fullPath, getCookie } from '../../utils/helper';
const createMenu = (configure) => {
return {
const createMenu = async (configure) => {
const menu = {
name: configure.name,
icon: configure.icon,
text: configure.showName,
children: [
...(configure.children || []).map(child => createMenu(child)),
...(configure.modules || []).map(module => ({
name: module.name,
icon: module.icon,
text: module.showName,
})),
],
};
if (!menu.children) {
menu.children = [];
}
if (configure.children) {
for (const child of configure.children) {
menu.children.push(await createMenu(child));
}
}
if (configure.modules) {
for (const module of configure.modules) {
let info = module;
if (isString(module)) {
info = await getModuleInfo(module);
}
menu.children.push({
name: info.name,
icon: info.icon,
text: info.showName,
});
}
}
return menu;
};
const createMenus = (menusConfigure) => {
return (menusConfigure || []).map(configure => createMenu(configure));
const createMenus = async (menusConfigure) => {
const menus = [];
if (menusConfigure) {
for (const configure of menusConfigure) {
menus.push(await createMenu(configure));
}
}
return menus;
};
// const createMenus = () => {
......@@ -122,7 +143,8 @@ export default {
},
*fetchModules(action, { put, call }) {
const configures = yield call(getMenus);
yield put({ type: 'queryMenusSuccess', payload: createMenus(configures) });
const menus = yield call(createMenus, configures);
yield put({ type: 'queryMenusSuccess', payload: menus });
},
*logout(action, { put, call }) {
yield call(logout);
......
/* eslint-disable no-param-reassign */
import fetch from 'dva/fetch';
import _ from 'lodash';
import { getCookie, encrypt } from './helper';
import { checkStatus, normParams, parseObject } from './http-helper';
import { cookie } from './config';
import { errors } from './error';
import { checkStatus, normParams, parseObject } from './http-helper';
const defaultOptions = {
headers: {
Accept: 'application/json',
},
headers: { Accept: 'application/json' },
};
export default function doDelete(url, data, params = {}, options = {}, auth = true) {
if (!data) {
data = {};
}
/**
* Requests a URL, returning a promise.
*
* @param {string} url The URL we want to request
* @param auth
* @param params
* @param {object} [options] The options we want to pass to "fetch"
* @return {object} An object containing either "data" or "err"
*/
export default function doDelete(url, params = {}, options = {}, auth = true) {
let token;
if (auth) {
const token = getCookie(cookie.token);
token = getCookie(cookie.token);
if (!token) {
return Promise.reject(errors.tokenMissing());
}
data.token = encrypt(token);
token = encrypt(token);
}
let queryParams = normParams(params);
let queryParams = token ? [...normParams(params), ['token', token]] : normParams(params);
queryParams = queryParams.map(([k, v]) => (_.isNil(v) ? k : `${k}=${encodeURIComponent(v)}`));
queryParams = queryParams.join('&');
let realUrl = url;
......@@ -32,15 +35,9 @@ export default function doDelete(url, data, params = {}, options = {}, auth = tr
realUrl = `${url}?${queryParams}`;
}
const realOptions = _.defaults(options, defaultOptions);
if (!realOptions.headers) {
realOptions.headers = {
Accept: 'application/json',
};
}
realOptions.headers['Content-Type'] = 'application/json';
realOptions.method = 'DELETE';
realOptions.body = JSON.stringify(data);
realOptions.method = 'POST';
return fetch(realUrl, realOptions)
.then(checkStatus)
.then(parseObject);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论