Commit 45b2a018 authored by superman's avatar superman

ok

parent 5a303517
This diff is collapsed.
......@@ -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/'
};
......@@ -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 = [
......
This diff is collapsed.
......@@ -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,
}))
......
......@@ -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};
},
}, {
......
/*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;
......
......@@ -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(watchAddItem);
yield fork(watchList);
yield fork(watchItem);
yield fork(watchCreate('USER', create));
yield fork(watchIndex('USER', fetchList));
yield fork(watchShow('USER', fetchItem));
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 {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
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}));
......
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