ragflow/web/src/pages/login/model.ts
balibabu 7e6a82bc99
feat: layout the knowledge list page and modify the page switching button in the header (#48)
* feat: remove unnecessary 'loading' fields from other files

* feat: layout the knowledge list page

* feat: modify the page switching button in the header
2024-01-31 19:29:57 +08:00

65 lines
1.7 KiB
TypeScript

import { Authorization } from '@/constants/authorization';
import userService from '@/services/userService';
import authorizationUtil from '@/utils/authorizationUtil';
import { message } from 'antd';
import { DvaModel } from 'umi';
export interface LoginModelState {
list: any[];
info: any;
visible: boolean;
}
const model: DvaModel<LoginModelState> = {
namespace: 'loginModel',
state: {
list: [],
info: {},
visible: false,
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
},
subscriptions: {
setup({ dispatch, history }) {
history.listen((location) => {});
},
},
effects: {
*login({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.login, payload);
const { retcode, data: res } = data;
const authorization = response.headers.get(Authorization);
if (retcode === 0) {
message.success('登录成功!');
const token = res.access_token;
const userInfo = {
avatar: res.avatar,
name: res.nickname,
email: res.email,
};
authorizationUtil.setItems({
Authorization: authorization,
userInfo: JSON.stringify(userInfo),
Token: token,
});
}
return retcode;
},
*register({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.register, payload);
console.log();
const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('注册成功!');
}
return retcode;
},
},
};
export default model;