Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
f4aa4d6c
提交
f4aa4d6c
authored
9月 05, 2017
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
小更新
上级
b787e0d1
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
83 行增加
和
31 行删除
+83
-31
yaohx_169.xml
.idea/dictionaries/yaohx_169.xml
+1
-0
index.js
src/index.js
+0
-1
login.js
src/models/login.js
+9
-1
domain.js
src/services/domain.js
+2
-19
route.js
src/services/route.js
+1
-2
config.js
src/utils/config.js
+5
-0
delete.js
src/utils/delete.js
+46
-0
error.js
src/utils/error.js
+14
-3
post.js
src/utils/post.js
+1
-1
request.js
src/utils/request.js
+1
-1
index.js
stories/index.js
+3
-3
没有找到文件。
.idea/dictionaries/yaohx_169.xml
浏览文件 @
f4aa4d6c
...
...
@@ -4,6 +4,7 @@
<w>
activex
</w>
<w>
anticon
</w>
<w>
arcfour
</w>
<w>
authed
</w>
<w>
dropdown
</w>
<w>
infos
</w>
<w>
inited
</w>
...
...
src/index.js
浏览文件 @
f4aa4d6c
...
...
@@ -15,7 +15,6 @@ const app = dva({
history
,
onError
(
error
)
{
// eslint-disable-next-line no-console
console
.
log
(
error
);
processError
(
error
);
},
});
...
...
src/models/login.js
浏览文件 @
f4aa4d6c
...
...
@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router';
import
{
login
,
userInfo
}
from
'../services/login'
;
import
{
setCookie
,
fullPath
}
from
'../utils/helper'
;
import
{
cookie
}
from
'../utils/config'
;
import
{
errors
}
from
'../utils/error'
;
export
default
{
namespace
:
'login'
,
...
...
@@ -10,7 +11,14 @@ export default {
effects
:
{
*
login
({
payload
},
{
call
,
put
})
{
const
result
=
yield
call
(
login
,
payload
);
const
{
tokenId
}
=
result
;
const
{
tokenId
,
authResponse
,
remainedAuthRequirements
}
=
result
;
if
(
authResponse
.
status
!==
'authed'
&&
authResponse
.
status
!==
'skipped'
)
{
throw
errors
.
wrongPassword
();
}
const
{
requirements
}
=
remainedAuthRequirements
;
if
(
requirements
.
length
>
0
)
{
throw
errors
.
unsupportedAuthType
(
requirements
);
}
setCookie
(
cookie
.
token
,
tokenId
);
const
uInfo
=
yield
call
(
userInfo
);
setCookie
(
cookie
.
userId
,
uInfo
.
id
);
...
...
src/services/domain.js
浏览文件 @
f4aa4d6c
/* eslint-disable no-param-reassign */
import
{
endsWith
}
from
'lodash'
;
import
request
from
'../utils/request'
;
import
post
from
'../utils/post'
;
import
{
cookie
}
from
'../utils/config'
;
import
{
getCookie
}
from
'../utils/helper'
;
const
processDomainInfo
=
(
basePath
,
info
)
=>
{
if
(
!
endsWith
(
basePath
,
'/'
))
{
basePath
=
`
${
basePath
}
/`
;
}
if
(
info
.
id
)
{
info
.
path
=
`
${
basePath
}${
info
.
id
}
`
;
}
else
{
info
.
path
=
basePath
;
}
return
info
;
};
export
async
function
fetchDomains
(
basePath
,
withRoot
=
false
)
{
if
(
!
basePath
)
{
basePath
=
getCookie
(
cookie
.
domainPath
);
...
...
@@ -36,7 +23,7 @@ export async function fetchDomains(basePath, withRoot = false) {
}
else
{
infoList
=
[];
}
return
infoList
.
map
(
info
=>
processDomainInfo
(
basePath
,
info
))
;
return
infoList
;
}
export
async
function
switchDomain
(
path
)
{
...
...
@@ -44,9 +31,5 @@ export async function switchDomain(path) {
}
export
async
function
currentDomain
()
{
const
domainInfo
=
await
request
(
'/api/domain/user/info'
);
if
(
domainInfo
)
{
domainInfo
.
path
=
await
request
(
'/api/domain/user/path'
);
}
return
domainInfo
;
return
request
(
'/api/domain/user/info'
);
}
src/services/route.js
浏览文件 @
f4aa4d6c
...
...
@@ -34,8 +34,7 @@ const getHistoryBase = (history) => {
export
const
history
=
browserHistory
;
export
const
location
=
{};
history
.
listen
((
loc
,
action
)
=>
{
console
.
log
(
action
,
loc
);
history
.
listen
((
loc
)
=>
{
location
.
pathname
=
loc
.
pathname
;
location
.
state
=
loc
.
state
;
location
.
search
=
loc
.
search
;
...
...
src/utils/config.js
浏览文件 @
f4aa4d6c
...
...
@@ -12,7 +12,12 @@ export const cookie = {
export
const
errors
=
{
exception
:
0x00010000
,
no_such_user
:
0x00010001
,
invalid_token
:
0x00010003
,
// client error:
token_missing
:
0x00000001
,
wrong_password
:
0x00000002
,
unsupported_auth_type
:
0x00000003
,
};
export
const
api
=
{
...
...
src/utils/delete.js
0 → 100644
浏览文件 @
f4aa4d6c
/* 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'
;
const
defaultOptions
=
{
headers
:
{
Accept
:
'application/json'
,
},
};
export
default
function
doDelete
(
url
,
data
,
params
=
{},
options
=
{},
auth
=
true
)
{
if
(
!
data
)
{
data
=
{};
}
if
(
auth
)
{
const
token
=
getCookie
(
cookie
.
token
);
if
(
!
token
)
{
return
Promise
.
reject
(
errors
.
tokenMissing
());
}
data
.
token
=
encrypt
(
token
);
}
let
queryParams
=
normParams
(
params
);
queryParams
=
queryParams
.
map
(([
k
,
v
])
=>
(
_
.
isNil
(
v
)
?
k
:
`
${
k
}
=
${
encodeURIComponent
(
v
)}
`
));
queryParams
=
queryParams
.
join
(
'&'
);
let
realUrl
=
url
;
if
(
queryParams
)
{
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
);
return
fetch
(
realUrl
,
realOptions
)
.
then
(
checkStatus
)
.
then
(
parseObject
);
}
src/utils/error.js
浏览文件 @
f4aa4d6c
...
...
@@ -16,6 +16,9 @@ export function processError(err) {
if
(
err
&&
err
.
data
)
{
const
data
=
err
.
data
;
switch
(
data
.
errorCode
)
{
case
errorCodes
.
no_such_user
:
message
.
error
(
'用户不存在!'
);
break
;
case
errorCodes
.
invalid_token
:
push
(
'/login'
);
break
;
...
...
@@ -56,8 +59,16 @@ export function createError({ code, msg }) {
}
export
const
errors
=
{
unLogin
:
createError
({
code
:
1
,
msg
:
'未登录'
,
tokenMissing
:
()
=>
createError
({
code
:
errorCodes
.
token_missing
,
msg
:
'需要登录!'
,
}),
wrongPassword
:
()
=>
createError
({
code
:
errorCodes
.
wrong_password
,
msg
:
'密码错误!'
,
}),
unsupportedAuthType
:
(...
types
)
=>
createError
({
code
:
errorCodes
.
unsupported_auth_type
,
msg
:
`不支持的客户端验证方式:
${
types
.
join
(
'、'
)}
.`
,
}),
};
src/utils/post.js
浏览文件 @
f4aa4d6c
...
...
@@ -20,7 +20,7 @@ export default function post(url, data, params = {}, options = {}, auth = true)
if
(
auth
)
{
const
token
=
getCookie
(
cookie
.
token
);
if
(
!
token
)
{
return
Promise
.
reject
(
errors
.
unLogin
);
return
Promise
.
reject
(
errors
.
tokenMissing
()
);
}
data
.
token
=
encrypt
(
token
);
}
...
...
src/utils/request.js
浏览文件 @
f4aa4d6c
...
...
@@ -23,7 +23,7 @@ export default function request(url, params = {}, options = {}, auth = true) {
if
(
auth
)
{
token
=
getCookie
(
cookie
.
token
);
if
(
!
token
)
{
return
Promise
.
reject
(
errors
.
unLogin
);
return
Promise
.
reject
(
errors
.
tokenMissing
()
);
}
token
=
encrypt
(
token
);
}
...
...
stories/index.js
浏览文件 @
f4aa4d6c
...
...
@@ -17,13 +17,13 @@ import { getModuleConfigure } from '../src/services/modules';
import
{
setCookie
}
from
'../src/utils/helper'
;
import
{
cookie
}
from
'../src/utils/config'
;
const
loginIt
=
async
(
userName
,
password
,
domain
Id
)
=>
{
const
loginIt
=
async
(
userName
,
password
,
domain
Path
)
=>
{
const
result
=
await
login
({
userName
,
password
});
const
{
tokenId
,
userId
}
=
result
;
setCookie
(
cookie
.
token
,
tokenId
);
setCookie
(
cookie
.
userId
,
userId
);
setCookie
(
cookie
.
userName
,
userName
);
await
switchDomain
(
domain
Id
);
await
switchDomain
(
domain
Path
);
const
config
=
await
getModuleConfigure
(
'test'
);
console
.
log
(
config
);
};
...
...
@@ -77,7 +77,7 @@ const lazy = action => (Comp) => {
storiesOf
(
'a'
,
module
)
.
add
(
'1'
,
()
=>
{
const
Comp
=
lazy
(
partial
(
loginIt
,
'
cxj'
,
'111111'
,
5
))(
wrap
()(
DsTable
));
const
Comp
=
lazy
(
partial
(
loginIt
,
'
admin'
,
'admin'
,
'/'
))(
wrap
()(
DsTable
));
const
coordinate
=
{
containerType
:
'module'
,
containerName
:
'test'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论