Files
ragflow/web/src/pages/login/model.ts
balibabu d38e92aac8 fix: fixed the issue that the prompt word for registering an account is not in English and fixed the issue where the last message would keep loading if the backend reported an error during chat and fixed the issue where the next button would float above the file list on the file upload page (#133)
* feat: fixed the issue where the next button would float above the file list on the file upload page.

* feat: fixed the issue where the last message would keep loading if the backend reported an error during chat.

* fix: fixed the issue that the prompt word for registering an account is not in English
2024-03-19 19:21:35 +08:00

69 lines
1.8 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,
};
},
},
effects: {
*login({ payload = {} }, { call }) {
const { data, response } = yield call(userService.login, payload);
const { retcode, data: res } = data;
const authorization = response.headers.get(Authorization);
if (retcode === 0) {
message.success('logged!');
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 }) {
const { data } = yield call(userService.register, payload);
console.log();
const { retcode } = data;
if (retcode === 0) {
message.success('Registered!');
}
return retcode;
},
*logout({ payload = {} }, { call }) {
const { data } = yield call(userService.logout, payload);
const { retcode } = data;
if (retcode === 0) {
message.success('logout');
}
return retcode;
},
},
};
export default model;