Commit 45b2a018 authored by superman's avatar superman

ok

parent 5a303517
This diff is collapsed.
...@@ -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/'
}; };
...@@ -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 = [
......
This diff is collapsed.
...@@ -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,
})) }))
......
...@@ -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};
}, },
}, { }, {
......
/*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; 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() { export function watchIndex(id, api){
const {api, id} = this; return function*() {
return function*(query) { while (true) {
try { const {query} = yield take('FETCH_' + id + '_LIST');
const result = yield call(api.index, query); yield fork(index(id, 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,
});
}
} }
} };
}
watchIndex() { export function show(rid, api) {
const self = this; return function*(id) {
return function*() { try {
while (true) { const result = yield call(api, id);
const {query} = yield take('FETCH_' + self.id + '_LIST'); yield put({
yield fork(self.index(), query); type: 'FETCH_' + rid + '_ITEM_SUCCESS',
} result
}; });
} catch (err) {
console.log(err);
message.error(err);
yield put({
type: 'FETCH_' + rid + '_ITEM_FAILED',
err
});
}
} }
}
show() { export function watchShow(rid, api) {
const self = this; return function*() {
const {api} = this; while (true) {
const {id} = yield take('FETCH_' + rid + '_ITEM');
yield fork(show(rid, api), id);
}
}
}
return function*(id) { export function create(id, api) {
try { return function*(data) {
const result = yield call(api.show, id); try {
yield put({ const result = yield call(api, data);
type: 'FETCH_' + self.id + '_ITEM_SUCCESS', yield put({
result type: 'CREATE_' + id + '_ITEM_SUCCESS',
}); result
} catch (err) { });
console.log(err); } catch (err) {
message.error(err); console.log(err);
yield put({ message.error(err);
type: 'FETCH_' + self.id + '_ITEM_FAILED', yield put({
err type: 'CREATE_' + id + '_ITEM_FAILED',
}); err
} });
} }
} }
}
watchShow() { export function watchCreate(id, api) {
const self = this; return function*() {
return function*() { while (true) {
while (true) { const {data} = yield take('CREATE_' + id + '_ITEM');
const {id} = yield take('FETCH_' + self.id + '_ITEM'); yield fork(create(id, api), data);
yield fork(self.show(), id);
}
} }
} }
}
/*
export default class RESTful {
constructor(id) {
this.id = id;
}
create() { create() {
const {api, id} = this; const {api, id} = this;
......
...@@ -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(watchAddItem); yield fork(watchCreate('USER', create));
yield fork(watchList); yield fork(watchIndex('USER', fetchList));
yield fork(watchItem); yield fork(watchShow('USER', fetchItem));
yield fork(watchMidfiyItem); yield fork(watchMidfiyItem);
} }
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);
}
});
}
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
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}));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment