Files
ragflow_python/web/src/pages/login/model.ts

66 lines
1.7 KiB
TypeScript
Raw Normal View History

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