Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
shuniu-admin-react
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
superman
shuniu-admin-react
Commits
45b2a018
Commit
45b2a018
authored
Aug 10, 2016
by
superman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok
parent
5a303517
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
309 additions
and
260 deletions
+309
-260
index.js
dist/index.js
+36
-36
proxy.config.js
proxy.config.js
+2
-2
App.jsx
src/containers/App/App.jsx
+11
-0
EditItem.jsx
src/containers/Users/EditItem.jsx
+101
-106
List.jsx
src/containers/Users/List.jsx
+6
-3
user.js
src/reducers/user.js
+5
-5
RESTful.js
src/sagas/RESTful.js
+81
-55
user.js
src/sagas/user.js
+8
-51
Storage.js
src/services/Storage.js
+54
-0
authority.js
src/services/admin/authority.js
+4
-2
resource.js
src/services/admin/resource.js
+1
-0
No files found.
dist/index.js
View file @
45b2a018
This source diff could not be displayed because it is too large. You can
view the blob
instead.
proxy.config.js
View file @
45b2a018
...
...
@@ -2,6 +2,6 @@
// - https://github.com/dora-js/dora-plugin-proxy#规则定义
module
.
exports
=
{
//
'/api/*': 'http://react.yanky.cn/',
'/api/*'
:
'http://192.168.1.126:8080/'
'/api/*'
:
'http://react.yanky.cn/'
,
//
'/api/*': 'http://192.168.1.126:8080/'
};
src/containers/App/App.jsx
View file @
45b2a018
...
...
@@ -21,6 +21,17 @@ export default class App extends Component {
store
:
PropTypes
.
object
.
isRequired
};
componentDidMount
(){
this
.
fetchAuthorityList
();
}
fetchAuthorityList
()
{
this
.
props
.
dispatch
({
type
:
'FETCH_AUTHORITY_LIST'
,
query
:
{
s
:
100
}
});
};
render
()
{
const
styles
=
require
(
'./App.less'
);
const
menu
=
[
...
...
src/containers/Users/EditItem.jsx
View file @
45b2a018
...
...
@@ -43,6 +43,9 @@ import {
export
default
class
EditItem
extends
Component
{
constructor
()
{
super
(...
arguments
);
this
.
state
=
{
authoritiesCheckedValues
:
[]
}
}
componentDidMount
()
{
...
...
@@ -50,27 +53,14 @@ export default class EditItem extends Component {
this
.
fetchAuthorityList
();
};
// componentWillReceiveProps(nextProps) {
// if (nextProps.item && nextProps.authorities) {
// this.analysisCheckedKeys(nextProps);
// }
// };
//
// analysisCheckedKeys(props) {
// const {item, authorities, isEdit} = props;
// //对权限资源分组
// const authoritiesMap = {};
// const checkedKeys = [];
// authorities && authorities.forEach(authority=> {
// authoritiesMap[authority.name] = authority;
//
// });
//
// this.setState({
// authoritiesMap,
// checkedKeys
// });
// }
componentWillReceiveProps
(
nextProps
)
{
if
((
nextProps
.
isEdit
!=
this
.
props
.
isEdit
)
&&
nextProps
.
item
&&
nextProps
.
item
.
authorities
)
{
this
.
setState
({
authoritiesCheckedValues
:
nextProps
.
item
.
authorities
.
split
(
','
)
});
}
}
fetchItem
(
id
)
{
this
.
props
.
dispatch
({
...
...
@@ -98,10 +88,11 @@ export default class EditItem extends Component {
}
})
}
data
.
authorities
=
this
.
state
.
authoritiesCheckedValues
.
join
();
console
.
log
(
data
);
this
.
props
.
dispatch
({
type
:
'UPDATE_USER_ITEM'
,
data
item
:
data
});
}
...
...
@@ -143,21 +134,20 @@ export default class EditItem extends Component {
/>
);
const
authoritiesMap
=
authorities
?
authorities
.
reduce
((
map
,
authority
)
=>
{
map
[
authority
.
name
]
=
authority
;
return
map
;
},
{})
:
{};
if
(
item
)
{
item
.
authorities
=
item
.
authorities
.
split
(
','
);
item
.
authoritiesDescList
=
[];
// item.authoritiesMap = item.authorities.reduce((map, name)=> {
// const authority = authoritiesMap[name];
// map[name] = authority;
// item.authoritiesDescList.push(authority.description);
// }, {});
const
authoritiesMap
=
{};
const
userAuthorities
=
[];
if
(
item
&&
authorities
)
{
authorities
.
forEach
(
authority
=>
{
authority
.
label
=
authority
.
description
+
'('
+
authority
.
name
+
')'
;
authority
.
value
=
authority
.
name
;
authoritiesMap
[
authority
.
name
]
=
authority
.
label
;
});
if
(
item
.
authorities
)
{
const
uas
=
item
.
authorities
.
split
(
','
);
uas
.
forEach
(
name
=>
{
userAuthorities
.
push
(
authoritiesMap
[
name
]);
});
}
}
return
(
...
...
@@ -166,72 +156,81 @@ export default class EditItem extends Component {
{
item
&&
<
Form
className=
"main-form"
horizontal
>
<
Row
>
<
Col
span=
"12"
>
<
Form
.
Item
label=
"用户名"
{
...
smallFormItemLayout
}
>
{
item
.
username
}
</
Form
.
Item
>
<
Form
.
Item
label=
"状态"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Select
placeholder=
"请选择状态"
{
...
getFieldProps
('
status
',
{
initialValue
:
userStatusToString
(
item
.
status
)})}
>
<
Select
.
Option
value=
"0"
>
未激活
</
Select
.
Option
>
<
Select
.
Option
value=
"1"
>
已激活
</
Select
.
Option
>
</
Select
>
:
(
typeof
item
.
status
!==
'undefined'
?
userStatusToString
(
item
.
status
)
:
NULL
)
}
</
Form
.
Item
>
<
Form
.
Item
label=
"角色"
{
...
smallFormItemLayout
}
>
{
item
.
authoritiesDescList
.
join
()
}
</
Form
.
Item
>
<
Form
.
Item
label=
"昵称"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
nick
',
{
initialValue
:
item
.
nick
})}
/>
:
item
.
nick
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"E-mail"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
email
',
{
initialValue
:
item
.
email
})}
/>
:
item
.
email
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"手机号"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
mobile
',
{
initialValue
:
item
.
mobile
})}
/>
:
item
.
mobile
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"注册时间"
{
...
smallFormItemLayout
}
>
{
item
.
dateCreated
&&
formatDateTime
(
item
.
dateCreated
)
}
</
Form
.
Item
>
<
Form
.
Item
{
...
footerFormSubmitLayout
}
style=
{
{
marginTop
:
30
}
}
>
{
isEdit
?
<
Button
type=
"primary"
onClick=
{
this
.
handleSubmit
.
bind
(
this
)
}
loading=
{
loading
}
>
<
Icon
type=
"save"
/>
保存
</
Button
>
:
<
Button
type=
"primary"
onClick=
{
e
=>
{
<
Form
.
Item
label=
"用户名"
{
...
smallFormItemLayout
}
>
{
item
.
username
}
</
Form
.
Item
>
<
Form
.
Item
label=
"状态"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Select
placeholder=
"请选择状态"
{
...
getFieldProps
('
status
',
{
initialValue
:
userStatusToString
(
item
.
status
)})}
>
<
Select
.
Option
value=
"0"
>
未激活
</
Select
.
Option
>
<
Select
.
Option
value=
"1"
>
已激活
</
Select
.
Option
>
</
Select
>
:
(
typeof
item
.
status
!==
'undefined'
?
userStatusToString
(
item
.
status
)
:
NULL
)
}
</
Form
.
Item
>
<
Form
.
Item
label=
"角色"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Checkbox
.
Group
options=
{
authorities
}
value=
{
this
.
state
.
authoritiesCheckedValues
}
onChange=
{
(
checkedValues
)
=>
{
this
.
setState
({
authoritiesCheckedValues
:
checkedValues
})
}
}
/>
:
(
userAuthorities
.
length
?
userAuthorities
.
join
(
','
)
:
NULL
)
}
</
Form
.
Item
>
<
Form
.
Item
label=
"昵称"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
nick
',
{
initialValue
:
item
.
nick
})}
/>
:
item
.
nick
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"E-mail"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
email
',
{
initialValue
:
item
.
email
})}
/>
:
item
.
email
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"手机号"
{
...
smallFormItemLayout
}
>
{
isEdit
?
<
Input
{
...
getFieldProps
('
mobile
',
{
initialValue
:
item
.
mobile
})}
/>
:
item
.
mobile
||
NULL
}
</
Form
.
Item
>
<
Form
.
Item
label=
"注册时间"
{
...
smallFormItemLayout
}
>
{
item
.
dateCreated
&&
formatDateTime
(
item
.
dateCreated
)
}
</
Form
.
Item
>
<
Form
.
Item
{
...
footerFormSubmitLayout
}
style=
{
{
marginTop
:
30
}
}
>
{
isEdit
?
<
Button
type=
"primary"
onClick=
{
this
.
handleSubmit
.
bind
(
this
)
}
loading=
{
loading
}
>
<
Icon
type=
"save"
/>
保存
</
Button
>
:
<
Button
type=
"primary"
onClick=
{
e
=>
{
e
.
preventDefault
();
this
.
props
.
dispatch
({
type
:
'UPDATE_USER'
});
}
}
>
<
Icon
type=
"edit"
/>
编辑
</
Button
>
<
Icon
type=
"edit"
/>
编辑
</
Button
>
}
<
Button
onClick=
{
e
=>
{
}
<
Button
onClick=
{
e
=>
{
e
.
preventDefault
();
isEdit
?
this
.
props
.
dispatch
({
...
...
@@ -239,16 +238,12 @@ export default class EditItem extends Component {
})
:
this
.
props
.
history
.
goBack
();
}
}
style=
{
{
marginLeft
:
'1em'
}
}
>
<
Icon
type=
"rollback"
/>
{
isEdit
?
'取消'
:
'返回'
}
</
Button
>
</
Form
.
Item
>
</
Col
>
<
Col
span=
"12"
>
style=
{
{
marginLeft
:
'1em'
}
}
>
<
Icon
type=
"rollback"
/>
{
isEdit
?
'取消'
:
'返回'
}
</
Button
>
</
Form
.
Item
>
</
Col
>
</
Row
>
</
Form
>
}
</
Spin
>
...
...
src/containers/Users/List.jsx
View file @
45b2a018
...
...
@@ -31,10 +31,13 @@ const columns = [
)
},
{
title
:
'角色'
,
dataIndex
:
'
buyerName
'
,
key
:
'
buyerName
'
,
dataIndex
:
'
authorities
'
,
key
:
'
authorities
'
,
width
:
200
,
className
:
'tac'
,
render
:(
authorities
)
=>
(
<
span
>
{
authorities
}
</
span
>
)
},
{
title
:
'E-mail'
,
dataIndex
:
'email'
,
...
...
@@ -57,7 +60,7 @@ const columns = [
];
@
connect
(
state
=>
({
items
:
state
.
user
.
items
,
items
:
state
.
user
.
list
,
loading
:
state
.
user
.
loading
,
total
:
state
.
user
.
total
,
}))
...
...
src/reducers/user.js
View file @
45b2a018
...
...
@@ -37,17 +37,17 @@ const user = handleActions({
return
{...
state
,
loading
:
true
};
},
[
'FETCH_USER_LIST_SUCCESS'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
items
:
action
.
items
,
total
:
action
.
total
};
return
{...
state
,
loading
:
false
,
...
action
.
result
};
},
[
'FETCH_USER_LIST_FAILED'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
},
[
'FETCH_USER_ITEM'
](
state
){
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
},
[
'FETCH_USER_ITEM_SUCCESS'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
item
:
action
.
item
};
return
{...
state
,
loading
:
false
,
item
:
action
.
result
};
},
[
'FETCH_USER_ITEM_FAILED'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
...
...
@@ -60,13 +60,13 @@ const user = handleActions({
return
{...
state
,
isEdit
:
false
}
},
[
'UPDATE_USER_ITEM'
](
state
){
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
},
[
'UPDATE_USER_ITEM_SUCCESS'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
item
:
{...
state
.
item
,
...
action
.
item
},
isEdit
:
false
};
},
[
'UPDATE_USER_ITEM_FAILED'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
err
:
action
.
err
,
isEdit
:
false
};
return
{...
state
,
loading
:
false
,
err
:
action
.
err
,
isEdit
:
false
};
},
},
{
...
...
src/sagas/RESTful.js
View file @
45b2a018
/*
import {takeLatest} from 'redux-saga';
import
{
takeLatest
}
from
'redux-saga'
;
import
{
take
,
call
,
put
,
fork
,
cancel
,
select
,
race
}
from
'redux-saga/effects'
;
import
{
message
}
from
'antd'
;
export default class RESTful {
constructor(id) {
this.id = id;
export
function
index
(
id
,
api
){
return
function
*
(
query
)
{
try
{
const
result
=
yield
call
(
api
,
query
);
yield
put
({
type
:
'FETCH_'
+
id
+
'_LIST_SUCCESS'
,
result
});
}
catch
(
err
)
{
console
.
log
(
err
);
message
.
error
(
err
);
yield
put
({
type
:
'FETCH_'
+
id
+
'_LIST_FAILED'
,
err
,
});
}
}
}
index() {
const {api, id} = this;
return function*(query) {
try {
const result = yield call(api.index, query);
yield put({
type: 'FETCH_' + id + '_LIST_SUCCESS',
result
});
} catch (err) {
console.log(err);
message.error(err);
yield put({
type: 'FETCH_' + id + '_LIST_FAILED',
err,
});
}
export
function
watchIndex
(
id
,
api
){
return
function
*
()
{
while
(
true
)
{
const
{
query
}
=
yield
take
(
'FETCH_'
+
id
+
'_LIST'
);
yield
fork
(
index
(
id
,
api
),
query
);
}
}
};
}
watchIndex() {
const self = this;
return function*() {
while (true) {
const {query} = yield take('FETCH_' + self.id + '_LIST');
yield fork(self.index(), query);
}
};
export
function
show
(
rid
,
api
)
{
return
function
*
(
id
)
{
try
{
const
result
=
yield
call
(
api
,
id
);
yield
put
({
type
:
'FETCH_'
+
rid
+
'_ITEM_SUCCESS'
,
result
});
}
catch
(
err
)
{
console
.
log
(
err
);
message
.
error
(
err
);
yield
put
({
type
:
'FETCH_'
+
rid
+
'_ITEM_FAILED'
,
err
});
}
}
}
show() {
const self = this;
const {api} = this;
export
function
watchShow
(
rid
,
api
)
{
return
function
*
()
{
while
(
true
)
{
const
{
id
}
=
yield
take
(
'FETCH_'
+
rid
+
'_ITEM'
);
yield
fork
(
show
(
rid
,
api
),
id
);
}
}
}
return function*(id
) {
try
{
const result = yield call(api.show, id);
yield put({
type: 'FETCH_' + self.id + '_ITEM_SUCCESS',
result
});
}
catch (err) {
console.log(err);
message.error
(err);
yield put({
type: 'FETCH_' + self.id + '_ITEM_FAILED',
err
});
}
export
function
create
(
id
,
api
)
{
return
function
*
(
data
)
{
try
{
const
result
=
yield
call
(
api
,
data
);
yield
put
({
type
:
'CREATE_'
+
id
+
'_ITEM_SUCCESS'
,
result
}
);
}
catch
(
err
)
{
console
.
log
(
err
);
message
.
error
(
err
);
yield
put
({
type
:
'CREATE_'
+
id
+
'_ITEM_FAILED'
,
err
}
);
}
}
}
watchShow() {
const self = this;
return function*() {
while (true) {
const {id} = yield take('FETCH_' + self.id + '_ITEM');
yield fork(self.show(), id);
}
export
function
watchCreate
(
id
,
api
)
{
return
function
*
()
{
while
(
true
)
{
const
{
data
}
=
yield
take
(
'CREATE_'
+
id
+
'_ITEM'
);
yield
fork
(
create
(
id
,
api
),
data
);
}
}
}
/*
export default class RESTful {
constructor(id) {
this.id = id;
}
create() {
const {api, id} = this;
...
...
src/sagas/user.js
View file @
45b2a018
...
...
@@ -2,6 +2,8 @@ import {takeLatest} from 'redux-saga';
import
{
take
,
call
,
put
,
fork
,
cancel
,
race
}
from
'redux-saga/effects'
;
import
{
fetch
,
clear
,
save
,
create
,
fetchList
,
fetchItem
,
updateItem
}
from
'../services/user'
;
import
{
message
}
from
'antd'
;
import
{
watchIndex
,
watchShow
,
watchCreate
}
from
'./RESTful'
;
function
*
authorize
(
username
,
password
,
push
)
{
try
{
...
...
@@ -43,58 +45,13 @@ function* watchAddItem() {
}
}
function
*
getList
(
query
)
{
try
{
const
{
list
,
total
}
=
yield
call
(
fetchList
,
query
);
yield
put
({
type
:
'FETCH_USER_LIST_SUCCESS'
,
items
:
list
,
total
});
}
catch
(
err
)
{
console
.
log
(
err
);
message
.
error
(
err
);
yield
put
({
type
:
'FETCH_USER_LIST_FAILED'
,
err
});
}
}
function
*
watchList
()
{
while
(
true
)
{
const
{
query
}
=
yield
take
(
'FETCH_USER_LIST'
);
yield
fork
(
getList
,
query
);
}
}
function
*
getItem
(
id
)
{
try
{
const
item
=
yield
call
(
fetchItem
,
id
);
yield
put
({
type
:
'FETCH_USER_ITEM_SUCCESS'
,
item
:
item
});
}
catch
(
err
)
{
console
.
log
(
err
);
message
.
error
(
err
);
yield
put
({
type
:
'FETCH_USER_ITEM_FAILED'
,
err
});
}
}
function
*
watchItem
()
{
while
(
true
)
{
const
{
id
}
=
yield
take
(
'FETCH_USER_ITEM'
);
yield
fork
(
getItem
,
id
);
}
}
function
*
modifyItem
(
data
)
{
function
*
modifyItem
(
item
)
{
try
{
yield
call
(
updateItem
,
data
);
yield
call
(
updateItem
,
item
);
yield
put
({
type
:
'UPDATE_USER_ITEM_SUCCESS'
,
item
:
data
item
});
}
catch
(
err
)
{
console
.
log
(
err
);
...
...
@@ -130,9 +87,9 @@ function* watchMidfiyItem(){
export
default
function
*
()
{
yield
fork
(
loginFlow
);
yield
fork
(
watch
AddItem
);
yield
fork
(
watch
List
);
yield
fork
(
watch
Item
);
yield
fork
(
watch
Create
(
'USER'
,
create
)
);
yield
fork
(
watch
Index
(
'USER'
,
fetchList
)
);
yield
fork
(
watch
Show
(
'USER'
,
fetchItem
)
);
yield
fork
(
watchMidfiyItem
);
}
src/services/Storage.js
0 → 100644
View file @
45b2a018
import
xFetch
from
'./xFetch'
;
const
storage
=
sessionStorage
;
const
PREFIX
=
'shuniu-cache-'
;
export
default
(
url
,
options
,
time
=
30
*
60
*
1000
)
=>
{
if
(
!
options
)
{
let
cache
=
storage
[
PREFIX
+
url
];
if
(
cache
)
{
try
{
cache
=
JSON
.
parse
(
cache
);
if
(
cache
.
time
-
Date
.
now
()
<
time
)
{
return
Promise
.
resolve
(
cache
.
data
);
}
}
catch
(
err
)
{
console
.
error
(
err
);
clearCache
(
url
);
}
}
}
else
{
let
index
=
url
.
indexOf
(
'?'
);
if
(
index
!=
-
1
)
{
clearCache
(
url
.
substr
(
0
,
index
));
}
else
{
index
=
url
.
lastIndexOf
(
'/'
);
clearCache
(
url
.
substr
(
0
,
index
));
}
}
return
xFetch
(
url
).
then
(
result
=>
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
try
{
storage
[
PREFIX
+
url
]
=
JSON
.
stringify
({
time
:
Date
.
now
(),
data
:
result
});
break
;
}
catch
(
err
)
{
console
.
error
(
err
);
clearCache
();
}
}
return
result
;
});
}
function
clearCache
(
id
)
{
console
.
log
(
'clear cache '
+
id
);
Object
.
keys
(
storage
).
forEach
(
key
=>
{
if
(
key
.
indexOf
(
PREFIX
+
id
)
===
0
)
{
storage
.
removeItem
(
key
);
}
});
}
src/services/admin/authority.js
View file @
45b2a018
import
xFetch
from
'../xFetch'
;
import
{
serialize
}
from
'../../utils'
;
import
storage
from
'../storage'
;
export
async
function
fetchList
(
query
)
{
return
xFetch
(
'/api/admin/authorities'
+
'?'
+
serialize
({
s
:
30
,
...
query
}));
return
xFetch
(
'/api/admin/authorities'
+
'?'
+
serialize
({
s
:
30
,
...
query
}));
}
export
async
function
fetchItem
(
id
)
{
...
...
@@ -10,8 +11,9 @@ export async function fetchItem(id) {
}
export
async
function
updateItem
(
item
)
{
return
xFetch
(
'/api/admin/authorities/'
+
item
.
id
,
{
return
xFetch
(
'/api/admin/authorities/'
+
item
.
id
,
{
method
:
'PUT'
,
body
:
serialize
(
item
)
});
}
//sessionStorage
src/services/admin/resource.js
View file @
45b2a018
import
xFetch
from
'../xFetch'
;
import
{
serialize
}
from
'../../utils'
;
import
storage
from
'../storage'
;
export
async
function
fetchList
(
query
)
{
return
xFetch
(
'/api/admin/resources'
+
'?'
+
serialize
({
s
:
30
,
...
query
}));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment