Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
0495c15c
提交
0495c15c
authored
9月 07, 2017
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: delete方法不能保护http body,传参必须用query参数。
fix: 生成菜单数据出错。
上级
76451936
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
35 行删除
+54
-35
index.js
src/models/main/index.js
+36
-14
delete.js
src/utils/delete.js
+18
-21
没有找到文件。
src/models/main/index.js
浏览文件 @
0495c15c
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
);
...
...
src/utils/delete.js
浏览文件 @
0495c15c
/* 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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论