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
Expand all
Show 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 diff is collapsed.
Click to expand it.
proxy.config.js
View file @
45b2a018
...
@@ -2,6 +2,6 @@
...
@@ -2,6 +2,6 @@
// - https://github.com/dora-js/dora-plugin-proxy#规则定义
// - https://github.com/dora-js/dora-plugin-proxy#规则定义
module
.
exports
=
{
module
.
exports
=
{
//
'/api/*': 'http://react.yanky.cn/',
'/api/*'
:
'http://react.yanky.cn/'
,
'/api/*'
:
'http://192.168.1.126:8080/'
//
'/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 {
...
@@ -21,6 +21,17 @@ export default class App extends Component {
store
:
PropTypes
.
object
.
isRequired
store
:
PropTypes
.
object
.
isRequired
};
};
componentDidMount
(){
this
.
fetchAuthorityList
();
}
fetchAuthorityList
()
{
this
.
props
.
dispatch
({
type
:
'FETCH_AUTHORITY_LIST'
,
query
:
{
s
:
100
}
});
};
render
()
{
render
()
{
const
styles
=
require
(
'./App.less'
);
const
styles
=
require
(
'./App.less'
);
const
menu
=
[
const
menu
=
[
...
...
src/containers/Users/EditItem.jsx
View file @
45b2a018
...
@@ -43,6 +43,9 @@ import {
...
@@ -43,6 +43,9 @@ import {
export
default
class
EditItem
extends
Component
{
export
default
class
EditItem
extends
Component
{
constructor
()
{
constructor
()
{
super
(...
arguments
);
super
(...
arguments
);
this
.
state
=
{
authoritiesCheckedValues
:
[]
}
}
}
componentDidMount
()
{
componentDidMount
()
{
...
@@ -50,27 +53,14 @@ export default class EditItem extends Component {
...
@@ -50,27 +53,14 @@ export default class EditItem extends Component {
this
.
fetchAuthorityList
();
this
.
fetchAuthorityList
();
};
};
// componentWillReceiveProps(nextProps) {
componentWillReceiveProps
(
nextProps
)
{
// if (nextProps.item && nextProps.authorities) {
if
((
nextProps
.
isEdit
!=
this
.
props
.
isEdit
)
&&
nextProps
.
item
&&
nextProps
.
item
.
authorities
)
{
// this.analysisCheckedKeys(nextProps);
this
.
setState
({
// }
authoritiesCheckedValues
:
nextProps
.
item
.
authorities
.
split
(
','
)
// };
});
//
}
// analysisCheckedKeys(props) {
// const {item, authorities, isEdit} = props;
}
// //对权限资源分组
// const authoritiesMap = {};
// const checkedKeys = [];
// authorities && authorities.forEach(authority=> {
// authoritiesMap[authority.name] = authority;
//
// });
//
// this.setState({
// authoritiesMap,
// checkedKeys
// });
// }
fetchItem
(
id
)
{
fetchItem
(
id
)
{
this
.
props
.
dispatch
({
this
.
props
.
dispatch
({
...
@@ -98,10 +88,11 @@ export default class EditItem extends Component {
...
@@ -98,10 +88,11 @@ export default class EditItem extends Component {
}
}
})
})
}
}
data
.
authorities
=
this
.
state
.
authoritiesCheckedValues
.
join
();
console
.
log
(
data
);
console
.
log
(
data
);
this
.
props
.
dispatch
({
this
.
props
.
dispatch
({
type
:
'UPDATE_USER_ITEM'
,
type
:
'UPDATE_USER_ITEM'
,
data
item
:
data
});
});
}
}
...
@@ -143,21 +134,20 @@ export default class EditItem extends Component {
...
@@ -143,21 +134,20 @@ export default class EditItem extends Component {
/>
/>
);
);
const
authoritiesMap
=
authorities
?
authorities
.
reduce
((
map
,
authority
)
=>
{
const
authoritiesMap
=
{};
map
[
authority
.
name
]
=
authority
;
const
userAuthorities
=
[];
return
map
;
if
(
item
&&
authorities
)
{
},
{})
:
{};
authorities
.
forEach
(
authority
=>
{
authority
.
label
=
authority
.
description
+
'('
+
authority
.
name
+
')'
;
if
(
item
)
{
authority
.
value
=
authority
.
name
;
item
.
authorities
=
item
.
authorities
.
split
(
','
);
authoritiesMap
[
authority
.
name
]
=
authority
.
label
;
});
item
.
authoritiesDescList
=
[];
if
(
item
.
authorities
)
{
const
uas
=
item
.
authorities
.
split
(
','
);
// item.authoritiesMap = item.authorities.reduce((map, name)=> {
uas
.
forEach
(
name
=>
{
// const authority = authoritiesMap[name];
userAuthorities
.
push
(
authoritiesMap
[
name
]);
// map[name] = authority;
});
// item.authoritiesDescList.push(authority.description);
}
// }, {});
}
}
return
(
return
(
...
@@ -166,8 +156,7 @@ export default class EditItem extends Component {
...
@@ -166,8 +156,7 @@ export default class EditItem extends Component {
{
{
item
&&
item
&&
<
Form
className=
"main-form"
horizontal
>
<
Form
className=
"main-form"
horizontal
>
<
Row
>
<
Col
span=
"12"
>
<
Form
.
Item
label=
"用户名"
{
...
smallFormItemLayout
}
>
<
Form
.
Item
label=
"用户名"
{
...
smallFormItemLayout
}
>
{
item
.
username
}
{
item
.
username
}
</
Form
.
Item
>
</
Form
.
Item
>
...
@@ -184,7 +173,17 @@ export default class EditItem extends Component {
...
@@ -184,7 +173,17 @@ export default class EditItem extends Component {
}
}
</
Form
.
Item
>
</
Form
.
Item
>
<
Form
.
Item
label=
"角色"
{
...
smallFormItemLayout
}
>
<
Form
.
Item
label=
"角色"
{
...
smallFormItemLayout
}
>
{
item
.
authoritiesDescList
.
join
()
}
{
isEdit
?
<
Checkbox
.
Group
options=
{
authorities
}
value=
{
this
.
state
.
authoritiesCheckedValues
}
onChange=
{
(
checkedValues
)
=>
{
this
.
setState
({
authoritiesCheckedValues
:
checkedValues
})
}
}
/>
:
(
userAuthorities
.
length
?
userAuthorities
.
join
(
','
)
:
NULL
)
}
</
Form
.
Item
>
</
Form
.
Item
>
<
Form
.
Item
label=
"昵称"
{
...
smallFormItemLayout
}
>
<
Form
.
Item
label=
"昵称"
{
...
smallFormItemLayout
}
>
{
{
...
@@ -244,11 +243,7 @@ export default class EditItem extends Component {
...
@@ -244,11 +243,7 @@ export default class EditItem extends Component {
{
isEdit
?
'取消'
:
'返回'
}
{
isEdit
?
'取消'
:
'返回'
}
</
Button
>
</
Button
>
</
Form
.
Item
>
</
Form
.
Item
>
</
Col
>
<
Col
span=
"12"
>
</
Col
>
</
Row
>
</
Form
>
</
Form
>
}
}
</
Spin
>
</
Spin
>
...
...
src/containers/Users/List.jsx
View file @
45b2a018
...
@@ -31,10 +31,13 @@ const columns = [
...
@@ -31,10 +31,13 @@ const columns = [
)
)
},
{
},
{
title
:
'角色'
,
title
:
'角色'
,
dataIndex
:
'
buyerName
'
,
dataIndex
:
'
authorities
'
,
key
:
'
buyerName
'
,
key
:
'
authorities
'
,
width
:
200
,
width
:
200
,
className
:
'tac'
,
className
:
'tac'
,
render
:(
authorities
)
=>
(
<
span
>
{
authorities
}
</
span
>
)
},
{
},
{
title
:
'E-mail'
,
title
:
'E-mail'
,
dataIndex
:
'email'
,
dataIndex
:
'email'
,
...
@@ -57,7 +60,7 @@ const columns = [
...
@@ -57,7 +60,7 @@ const columns = [
];
];
@
connect
(
state
=>
({
@
connect
(
state
=>
({
items
:
state
.
user
.
items
,
items
:
state
.
user
.
list
,
loading
:
state
.
user
.
loading
,
loading
:
state
.
user
.
loading
,
total
:
state
.
user
.
total
,
total
:
state
.
user
.
total
,
}))
}))
...
...
src/reducers/user.js
View file @
45b2a018
...
@@ -37,17 +37,17 @@ const user = handleActions({
...
@@ -37,17 +37,17 @@ const user = handleActions({
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
},
},
[
'FETCH_USER_LIST_SUCCESS'
](
state
,
action
){
[
'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
){
[
'FETCH_USER_LIST_FAILED'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
},
},
[
'FETCH_USER_ITEM'
](
state
){
[
'FETCH_USER_ITEM'
](
state
){
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
},
},
[
'FETCH_USER_ITEM_SUCCESS'
](
state
,
action
){
[
'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
){
[
'FETCH_USER_ITEM_FAILED'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
return
{...
state
,
loading
:
false
,
err
:
action
.
err
};
...
@@ -60,13 +60,13 @@ const user = handleActions({
...
@@ -60,13 +60,13 @@ const user = handleActions({
return
{...
state
,
isEdit
:
false
}
return
{...
state
,
isEdit
:
false
}
},
},
[
'UPDATE_USER_ITEM'
](
state
){
[
'UPDATE_USER_ITEM'
](
state
){
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
},
},
[
'UPDATE_USER_ITEM_SUCCESS'
](
state
,
action
){
[
'UPDATE_USER_ITEM_SUCCESS'
](
state
,
action
){
return
{...
state
,
loading
:
false
,
item
:
{...
state
.
item
,
...
action
.
item
},
isEdit
:
false
};
return
{...
state
,
loading
:
false
,
item
:
{...
state
.
item
,
...
action
.
item
},
isEdit
:
false
};
},
},
[
'UPDATE_USER_ITEM_FAILED'
](
state
,
action
){
[
'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
{
take
,
call
,
put
,
fork
,
cancel
,
select
,
race
}
from
'redux-saga/effects'
;
import
{
message
}
from
'antd'
;
import
{
message
}
from
'antd'
;
export default class RESTful {
export
function
index
(
id
,
api
){
constructor(id) {
return
function
*
(
query
)
{
this.id = id;
}
index() {
const {api, id} = this;
return function*(query) {
try
{
try
{
const result = yield call(api.index
, query);
const
result
=
yield
call
(
api
,
query
);
yield
put
({
yield
put
({
type
:
'FETCH_'
+
id
+
'_LIST_SUCCESS'
,
type
:
'FETCH_'
+
id
+
'_LIST_SUCCESS'
,
result
result
...
@@ -25,50 +19,82 @@ export default class RESTful {
...
@@ -25,50 +19,82 @@ export default class RESTful {
});
});
}
}
}
}
}
}
watchIndex() {
export
function
watchIndex
(
id
,
api
){
const self = this;
return
function
*
()
{
return
function
*
()
{
while
(
true
)
{
while
(
true
)
{
const {query} = yield take('FETCH_' + self.
id + '_LIST');
const
{
query
}
=
yield
take
(
'FETCH_'
+
id
+
'_LIST'
);
yield fork(self.index(
), query);
yield
fork
(
index
(
id
,
api
),
query
);
}
}
};
};
}
}
show() {
const self = this;
const {api} = this;
export
function
show
(
rid
,
api
)
{
return
function
*
(
id
)
{
return
function
*
(
id
)
{
try
{
try
{
const result = yield call(api.show
, id);
const
result
=
yield
call
(
api
,
id
);
yield
put
({
yield
put
({
type: 'FETCH_' + self.
id + '_ITEM_SUCCESS',
type
:
'FETCH_'
+
r
id
+
'_ITEM_SUCCESS'
,
result
result
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
message
.
error
(
err
);
message
.
error
(
err
);
yield
put
({
yield
put
({
type: 'FETCH_' + self.
id + '_ITEM_FAILED',
type
:
'FETCH_'
+
r
id
+
'_ITEM_FAILED'
,
err
err
});
});
}
}
}
}
}
export
function
watchShow
(
rid
,
api
)
{
return
function
*
()
{
while
(
true
)
{
const
{
id
}
=
yield
take
(
'FETCH_'
+
rid
+
'_ITEM'
);
yield
fork
(
show
(
rid
,
api
),
id
);
}
}
}
}
watchShow() {
export
function
create
(
id
,
api
)
{
const self = this;
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
});
}
}
}
export
function
watchCreate
(
id
,
api
)
{
return
function
*
()
{
return
function
*
()
{
while
(
true
)
{
while
(
true
)
{
const {id} = yield take('FETCH_' + self.
id + '_ITEM');
const
{
data
}
=
yield
take
(
'CREATE_'
+
id
+
'_ITEM'
);
yield fork(self.show(), id
);
yield
fork
(
create
(
id
,
api
),
data
);
}
}
}
}
}
/*
export default class RESTful {
constructor(id) {
this.id = id;
}
}
create() {
create() {
const {api, id} = this;
const {api, id} = this;
return function*(data) {
return function*(data) {
...
...
src/sagas/user.js
View file @
45b2a018
...
@@ -2,6 +2,8 @@ import {takeLatest} from 'redux-saga';
...
@@ -2,6 +2,8 @@ import {takeLatest} from 'redux-saga';
import
{
take
,
call
,
put
,
fork
,
cancel
,
race
}
from
'redux-saga/effects'
;
import
{
take
,
call
,
put
,
fork
,
cancel
,
race
}
from
'redux-saga/effects'
;
import
{
fetch
,
clear
,
save
,
create
,
fetchList
,
fetchItem
,
updateItem
}
from
'../services/user'
;
import
{
fetch
,
clear
,
save
,
create
,
fetchList
,
fetchItem
,
updateItem
}
from
'../services/user'
;
import
{
message
}
from
'antd'
;
import
{
message
}
from
'antd'
;
import
{
watchIndex
,
watchShow
,
watchCreate
}
from
'./RESTful'
;
function
*
authorize
(
username
,
password
,
push
)
{
function
*
authorize
(
username
,
password
,
push
)
{
try
{
try
{
...
@@ -43,58 +45,13 @@ function* watchAddItem() {
...
@@ -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
{
try
{
yield
call
(
updateItem
,
data
);
yield
call
(
updateItem
,
item
);
yield
put
({
yield
put
({
type
:
'UPDATE_USER_ITEM_SUCCESS'
,
type
:
'UPDATE_USER_ITEM_SUCCESS'
,
item
:
data
item
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
...
@@ -130,9 +87,9 @@ function* watchMidfiyItem(){
...
@@ -130,9 +87,9 @@ function* watchMidfiyItem(){
export
default
function
*
()
{
export
default
function
*
()
{
yield
fork
(
loginFlow
);
yield
fork
(
loginFlow
);
yield
fork
(
watch
AddItem
);
yield
fork
(
watch
Create
(
'USER'
,
create
)
);
yield
fork
(
watch
List
);
yield
fork
(
watch
Index
(
'USER'
,
fetchList
)
);
yield
fork
(
watch
Item
);
yield
fork
(
watch
Show
(
'USER'
,
fetchItem
)
);
yield
fork
(
watchMidfiyItem
);
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
xFetch
from
'../xFetch'
;
import
{
serialize
}
from
'../../utils'
;
import
{
serialize
}
from
'../../utils'
;
import
storage
from
'../storage'
;
export
async
function
fetchList
(
query
)
{
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
)
{
export
async
function
fetchItem
(
id
)
{
...
@@ -10,8 +11,9 @@ export async function fetchItem(id) {
...
@@ -10,8 +11,9 @@ export async function fetchItem(id) {
}
}
export
async
function
updateItem
(
item
)
{
export
async
function
updateItem
(
item
)
{
return
xFetch
(
'/api/admin/authorities/'
+
item
.
id
,
{
return
xFetch
(
'/api/admin/authorities/'
+
item
.
id
,
{
method
:
'PUT'
,
method
:
'PUT'
,
body
:
serialize
(
item
)
body
:
serialize
(
item
)
});
});
}
}
//sessionStorage
src/services/admin/resource.js
View file @
45b2a018
import
xFetch
from
'../xFetch'
;
import
xFetch
from
'../xFetch'
;
import
{
serialize
}
from
'../../utils'
;
import
{
serialize
}
from
'../../utils'
;
import
storage
from
'../storage'
;
export
async
function
fetchList
(
query
)
{
export
async
function
fetchList
(
query
)
{
return
xFetch
(
'/api/admin/resources'
+
'?'
+
serialize
({
s
:
30
,
...
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