|
@@ -8,6 +8,10 @@ import { State, ReadonlyState, StateAction, LoginStore } from './types';
|
|
|
// 定义状态
|
|
// 定义状态
|
|
|
const stateGenerator = (): ReadonlyState => ({
|
|
const stateGenerator = (): ReadonlyState => ({
|
|
|
buttonLoading: false,
|
|
buttonLoading: false,
|
|
|
|
|
+ captchaData: {
|
|
|
|
|
+ uuid: '',
|
|
|
|
|
+ img: ''
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 修改状态
|
|
// 修改状态
|
|
@@ -16,6 +20,9 @@ const stateActionsGenerator = (state: State): StateAction => {
|
|
|
setButtonLoading: (loading) => {
|
|
setButtonLoading: (loading) => {
|
|
|
state.buttonLoading = loading;
|
|
state.buttonLoading = loading;
|
|
|
},
|
|
},
|
|
|
|
|
+ setCaptchaData:(data:any)=>{
|
|
|
|
|
+ state.captchaData = data
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -29,7 +36,9 @@ const useLoginStore = (): LoginStore => {
|
|
|
login: async (data: LoginApiParams, remember: boolean) => {
|
|
login: async (data: LoginApiParams, remember: boolean) => {
|
|
|
actions.setButtonLoading(true);
|
|
actions.setButtonLoading(true);
|
|
|
try {
|
|
try {
|
|
|
- const res = await apis.login(data);
|
|
|
|
|
|
|
+ const res = await apis.login({
|
|
|
|
|
+ ...data,
|
|
|
|
|
+ });
|
|
|
const info = res.data;
|
|
const info = res.data;
|
|
|
if (remember) {// 记住密码
|
|
if (remember) {// 记住密码
|
|
|
LocalStorage.setAccountPassword({
|
|
LocalStorage.setAccountPassword({
|
|
@@ -74,6 +83,19 @@ const useLoginStore = (): LoginStore => {
|
|
|
actions.setButtonLoading(false);
|
|
actions.setButtonLoading(false);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ // 验证码
|
|
|
|
|
+ captchaImage: async()=>{
|
|
|
|
|
+ console.log('验证码图片加载')
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await apis.captchaImage();
|
|
|
|
|
+ console.log('验证码图片加载成功',res)
|
|
|
|
|
+ actions.setCaptchaData(res?.data||{});
|
|
|
|
|
+ return res;
|
|
|
|
|
+ } catch (error: any) {
|
|
|
|
|
+ console.log('error',error)
|
|
|
|
|
+ message.error(error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 点击登录
|
|
// 点击登录
|
|
@@ -81,9 +103,16 @@ const useLoginStore = (): LoginStore => {
|
|
|
// 登录
|
|
// 登录
|
|
|
await api.login(data, remember);
|
|
await api.login(data, remember);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 切换验证码
|
|
|
|
|
+ const onCaptchaImage = async ()=>{
|
|
|
|
|
+ await api.captchaImage();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// 初始渲染
|
|
// 初始渲染
|
|
|
const init: LoginStore['init'] = (form) => {
|
|
const init: LoginStore['init'] = (form) => {
|
|
|
|
|
+ api.captchaImage();
|
|
|
const accountPassword = LocalStorage.getAccountPassword();
|
|
const accountPassword = LocalStorage.getAccountPassword();
|
|
|
if (accountPassword) {
|
|
if (accountPassword) {
|
|
|
form.setFieldsValue({
|
|
form.setFieldsValue({
|
|
@@ -104,6 +133,7 @@ const useLoginStore = (): LoginStore => {
|
|
|
return {
|
|
return {
|
|
|
state,
|
|
state,
|
|
|
onClickLogin,
|
|
onClickLogin,
|
|
|
|
|
+ onCaptchaImage,
|
|
|
init,
|
|
init,
|
|
|
reset
|
|
reset
|
|
|
};
|
|
};
|