ruoyi-plus-soybean/src/views/system/login/components/PwdLogin/index.vue

106 lines
3.2 KiB
Vue
Raw Normal View History

2021-09-11 02:34:36 +08:00
<template>
<div class="pt-24px">
<n-form ref="formRef" :model="model" :rules="rules" size="large" :show-label="false">
<n-form-item path="phone">
<n-input v-model:value="model.phone" placeholder="手机号码" />
</n-form-item>
<n-form-item path="pwd">
<n-input v-model:value="model.pwd" placeholder="密码" />
</n-form-item>
<n-form-item path="isCaptcha">
<div class="w-full">
<mi-captcha :theme-color="theme.themeColor" :logo="logo" @success="handleCaptcha" />
</div>
</n-form-item>
2021-09-11 02:34:36 +08:00
<n-space :vertical="true" size="large">
<div class="flex-y-center justify-between">
<n-checkbox v-model:checked="rememberMe">记住我</n-checkbox>
<span class="g_text-primary cursor-pointer" @click="toCurrentLogin('reset-pwd')">忘记密码</span>
2021-09-11 02:34:36 +08:00
</div>
<n-button type="primary" size="large" :block="true" :round="true" @click="handleSubmit">确定</n-button>
<div class="flex-y-center justify-between">
<n-button class="flex-1" :block="true" @click="toCurrentLogin('code-login')">
2021-09-11 02:34:36 +08:00
{{ EnumLoginModule['code-login'] }}
</n-button>
<div class="w-12px"></div>
<n-button class="flex-1" :block="true" @click="toCurrentLogin('register')">
{{ EnumLoginModule.register }}
</n-button>
2021-09-11 02:34:36 +08:00
</div>
</n-space>
</n-form>
<other-login />
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
2021-09-14 01:31:29 +08:00
import { NForm, NFormItem, NInput, NSpace, NCheckbox, NButton, useNotification } from 'naive-ui';
import type { FormInst, FormRules } from 'naive-ui';
2021-09-11 02:34:36 +08:00
import { EnumLoginModule } from '@/enum';
import { useThemeStore } from '@/store';
import { useRouterChange, useRouteQuery } from '@/hooks';
import { setToken } from '@/utils';
import { OtherLogin } from './components';
import logo from '@/assets/img/common/logo.png';
2021-09-11 02:34:36 +08:00
const theme = useThemeStore();
const { toHome, toCurrentLogin, toLoginRedirectUrl } = useRouterChange();
const { loginRedirectUrl } = useRouteQuery();
2021-09-14 01:31:29 +08:00
const notification = useNotification();
2021-09-11 02:34:36 +08:00
const formRef = ref<(HTMLElement & FormInst) | null>(null);
const model = reactive({
phone: '15100000000',
pwd: '123456',
isCaptcha: false
2021-09-11 02:34:36 +08:00
});
const rules: FormRules = {
2021-09-11 02:34:36 +08:00
phone: {
required: true,
trigger: ['blur', 'input'],
message: '请输入手机号'
},
pwd: {
required: true,
trigger: ['blur', 'input'],
message: '请输入密码'
},
isCaptcha: {
required: true,
type: 'boolean',
trigger: 'change',
message: '请点击按钮进行验证码校验',
validator: (_, value) => value === true
2021-09-11 02:34:36 +08:00
}
};
const rememberMe = ref(false);
function handleCaptcha() {
model.isCaptcha = true;
}
2021-09-11 02:34:36 +08:00
function handleSubmit(e: MouseEvent) {
if (!formRef.value) return;
e.preventDefault();
formRef.value.validate(errors => {
if (!errors) {
2021-09-14 01:31:29 +08:00
setToken('temp-token');
if (loginRedirectUrl.value) {
toLoginRedirectUrl(loginRedirectUrl.value);
} else {
toHome();
}
notification.success({
title: '登录成功!',
content: '欢迎回来Soybean!',
duration: 5000
2021-09-14 01:31:29 +08:00
});
2021-09-11 02:34:36 +08:00
}
});
}
</script>
<style scoped></style>