2019-03-04 12:15:44 +08:00
|
|
|
import { query as queryUsers } from '@/services/user';
|
|
|
|
import currentUserData from '../mock-data/currentUserData';
|
2019-02-27 11:06:55 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
namespace: 'user',
|
|
|
|
|
|
|
|
state: {
|
|
|
|
list: [],
|
|
|
|
currentUser: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
effects: {
|
|
|
|
*fetch(_, { call, put }) {
|
|
|
|
const response = yield call(queryUsers);
|
|
|
|
yield put({
|
|
|
|
type: 'save',
|
|
|
|
payload: response,
|
|
|
|
});
|
|
|
|
},
|
2019-03-04 12:15:44 +08:00
|
|
|
*fetchCurrent(_, { put }) {
|
|
|
|
// const response = yield call(queryCurrent);
|
|
|
|
const response = currentUserData;
|
2019-02-27 11:06:55 +08:00
|
|
|
yield put({
|
|
|
|
type: 'saveCurrentUser',
|
|
|
|
payload: response,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
reducers: {
|
|
|
|
save(state, action) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
list: action.payload,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
saveCurrentUser(state, action) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentUser: action.payload || {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
changeNotifyCount(state, action) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
currentUser: {
|
|
|
|
...state.currentUser,
|
|
|
|
notifyCount: action.payload.totalCount,
|
|
|
|
unreadCount: action.payload.unreadCount,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|