同步vben

This commit is contained in:
JinMao 2021-09-20 11:22:14 +08:00
parent 83dc8a6bf6
commit 2809b6a8ac
4 changed files with 289 additions and 272 deletions

View File

@ -6,9 +6,12 @@ import { ErrorMessageMode } from '/#/axios';
enum Api {
Login = '/login',
Logout = '/logout',
Register = '/register',
GetPermCode = '/getPermCode',
GetUserInfo = '/api/user/info',
GetPermCodeByUserId = '/getPermCodeByUserId',
}
const url=`http://` + window.location.hostname + `:10088`
/**
* @description: user login api
@ -21,7 +24,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

@ -51,10 +51,10 @@
"
>
<LoginForm />
<ForgetPasswordForm />
<!-- <ForgetPasswordForm />-->
<RegisterForm />
<MobileForm />
<QrCodeForm />
<!-- <MobileForm />-->
<!-- <QrCodeForm />-->
</div>
</div>
</div>

View File

@ -53,16 +53,16 @@
</Button> -->
</FormItem>
<ARow class="enter-x">
<ACol :md="8" :xs="24">
<Button block @click="setLoginState(LoginStateEnum.MOBILE)">
{{ t('sys.login.mobileSignInFormTitle') }}
</Button>
</ACol>
<ACol :md="8" :xs="24" class="!my-2 !md:my-0 xs:mx-0 md:mx-2">
<Button block @click="setLoginState(LoginStateEnum.QR_CODE)">
{{ t('sys.login.qrSignInFormTitle') }}
</Button>
</ACol>
<!-- <ACol :md="8" :xs="24">-->
<!-- <Button block @click="setLoginState(LoginStateEnum.MOBILE)">-->
<!-- {{ t('sys.login.mobileSignInFormTitle') }}-->
<!-- </Button>-->
<!-- </ACol>-->
<!-- <ACol :md="8" :xs="24" class="!my-2 !md:my-0 xs:mx-0 md:mx-2">-->
<!-- <Button block @click="setLoginState(LoginStateEnum.QR_CODE)">-->
<!-- {{ t('sys.login.qrSignInFormTitle') }}-->
<!-- </Button>-->
<!-- </ACol>-->
<ACol :md="7" :xs="24">
<Button block @click="setLoginState(LoginStateEnum.REGISTER)">
{{ t('sys.login.registerButton') }}
@ -70,19 +70,19 @@
</ACol>
</ARow>
<Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider>
<!-- <Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider>-->
<div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">
<GithubFilled />
<WechatFilled />
<AlipayCircleFilled />
<GoogleCircleFilled />
<TwitterCircleFilled />
</div>
<!-- <div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">-->
<!-- <GithubFilled />-->
<!-- <WechatFilled />-->
<!-- <AlipayCircleFilled />-->
<!-- <GoogleCircleFilled />-->
<!-- <TwitterCircleFilled />-->
<!-- </div>-->
</Form>
</template>
<script lang="ts" setup>
import { reactive, ref, unref, computed } from 'vue';
import { reactive, ref, toRaw, unref, computed } from 'vue';
import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue';
import {
@ -119,8 +119,8 @@
const rememberMe = ref(false);
const formData = reactive({
account: 'admin',
password: '123456',
account: '',
password: '',
});
const { validForm } = useFormValid(formRef);
@ -134,22 +134,24 @@
if (!data) return;
try {
loading.value = true;
const userInfo = await userStore.login({
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.realName}`,
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.username}`,
duration: 3,
});
}
} catch (error) {
createErrorModal({
title: t('sys.api.errorTip'),
content: (error as unknown as Error).message || t('sys.api.networkExceptionMsg'),
content: error.message || t('sys.api.networkExceptionMsg'),
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body,
});
} finally {

View File

@ -1,31 +1,32 @@
<template>
<template v-if="getShow">
<LoginFormTitle class="enter-x" />
<Form class="p-4 enter-x" :model="formData" :rules="getFormRules" ref="formRef">
<Form class="p-4 enter-x" :model="formData" ref="formRef">
<FormItem name="account" class="enter-x">
<Input
class="fix-auto-fill"
size="large"
v-model:value="formData.account"
v-model:value="formData.username"
:placeholder="t('sys.login.userName')"
/>
</FormItem>
<FormItem name="mobile" class="enter-x">
<Input
size="large"
v-model:value="formData.mobile"
:placeholder="t('sys.login.mobile')"
class="fix-auto-fill"
/>
</FormItem>
<FormItem name="sms" class="enter-x">
<CountdownInput
size="large"
class="fix-auto-fill"
v-model:value="formData.sms"
:placeholder="t('sys.login.smsCode')"
/>
</FormItem>
<!-- <FormItem name="mobile" class="enter-x">-->
<!-- <Input-->
<!-- size="large"-->
<!-- v-model:value="formData.mobile"-->
<!-- :placeholder="t('sys.login.mobile')"-->
<!-- class="fix-auto-fill"-->
<!-- />-->
<!-- </FormItem>-->
<!-- <FormItem name="sms" class="enter-x">-->
<!-- <CountdownInput-->
<!-- size="large"-->
<!-- class="fix-auto-fill"-->
<!-- v-model:value="formData.sms"-->
<!-- :placeholder="t('sys.login.smsCode')"-->
<!-- />-->
<!-- </FormItem>-->
<FormItem name="password" class="enter-x">
<StrengthMeter
size="large"
@ -37,17 +38,17 @@
<InputPassword
size="large"
visibilityToggle
v-model:value="formData.confirmPassword"
v-model:value="formData.password2"
:placeholder="t('sys.login.confirmPassword')"
/>
</FormItem>
<FormItem class="enter-x" name="policy">
<!-- No logic, you need to deal with it yourself -->
<Checkbox v-model:checked="formData.policy" size="small">
{{ t('sys.login.policy') }}
</Checkbox>
</FormItem>
<!-- <FormItem class="enter-x" name="policy">-->
<!-- &lt;!&ndash; No logic, you need to deal with it yourself &ndash;&gt;-->
<!-- <Checkbox v-model:checked="formData.policy" size="small">-->
<!-- {{ t('sys.login.policy') }}-->
<!-- </Checkbox>-->
<!-- </FormItem>-->
<Button
type="primary"
@ -73,6 +74,7 @@
import { CountdownInput } from '/@/components/CountDown';
import { useI18n } from '/@/hooks/web/useI18n';
import { useLoginState, useFormRules, useFormValid, LoginStateEnum } from './useLogin';
import { registerApi } from '/@/api/sys/user';
const FormItem = Form.Item;
const InputPassword = Input.Password;
@ -83,12 +85,9 @@
const loading = ref(false);
const formData = reactive({
account: '',
username: '',
password: '',
confirmPassword: '',
mobile: '',
sms: '',
policy: false,
password2: '',
});
const { getFormRules } = useFormRules(formData);
@ -97,8 +96,9 @@
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER);
async function handleRegister() {
const data = await validForm();
if (!data) return;
console.log(data);
// const data = await validForm();
// if (!data) return;
console.log(formData);
await registerApi(formData);
}
</script>