ludu-cloud/admin-web/src/models/user.js

55 lines
1.1 KiB
JavaScript

import { query as queryUsers } from '@/services/user';
import currentUserData from '../mock-data/currentUserData';
export default {
namespace: 'user',
state: {
list: [],
currentUser: {},
},
effects: {
*fetch(_, { call, put }) {
const response = yield call(queryUsers);
yield put({
type: 'save',
payload: response,
});
},
*fetchCurrent(_, { put }) {
// const response = yield call(queryCurrent);
const response = currentUserData;
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,
},
};
},
},
};