同步vben

This commit is contained in:
JinMao 2021-09-20 11:22:14 +08:00
parent 0cf9bd2913
commit 95203e47ff
2 changed files with 43 additions and 31 deletions

View File

@ -26,7 +26,19 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
},
{
errorMessageMode: mode,
apiUrl: 'http://localhost:10088',
apiUrl: url,
},
);
}
export function registerApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
return defHttp.post(
{
url: Api.Register,
params,
},
{
errorMessageMode: mode,
apiUrl: url,
},
);
}

View File

@ -106,10 +106,10 @@ const formRef = ref();
const loading = ref(false);
const rememberMe = ref(false);
const formData = reactive({
account: 'admin',
password: '123456',
});
const formData = reactive({
account: '',
password: '',
});
const { validForm } = useFormValid(formRef);
@ -117,33 +117,33 @@ const { validForm } = useFormValid(formRef);
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
async function handleLogin() {
const data = await validForm();
if (!data) return;
try {
loading.value = true;
const userInfo = await userStore.login(
toRaw({
password: data.password,
username: data.account,
mode: 'none', //
}),
);
if (userInfo) {
notification.success({
message: t('sys.login.loginSuccessTitle'),
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.username}`,
duration: 3,
});
}
} catch (error) {
createErrorModal({
title: t('sys.api.errorTip'),
content: error.message || t('sys.api.networkExceptionMsg'),
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body,
async function handleLogin() {
const data = await validForm();
if (!data) return;
try {
loading.value = true;
const userInfo = await userStore.login(
toRaw({
password: data.password,
username: data.account,
mode: 'none', //
}),
);
if (userInfo) {
notification.success({
message: t('sys.login.loginSuccessTitle'),
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.username}`,
duration: 3,
});
} finally {
loading.value = false;
}
} catch (error) {
createErrorModal({
title: t('sys.api.errorTip'),
content: error.message || t('sys.api.networkExceptionMsg'),
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body,
});
} finally {
loading.value = false;
}
}
</script>