ruoyi-plus-soybean/src/views/_builtin/login/modules/pwd-login.vue

119 lines
3.4 KiB
Vue
Raw Normal View History

2023-11-17 08:45:00 +08:00
<script setup lang="ts">
2024-01-28 16:24:43 +08:00
import { computed, reactive } from 'vue';
2023-11-17 08:45:00 +08:00
import { $t } from '@/locales';
import { loginModuleRecord } from '@/constants/app';
import { useRouterPush } from '@/hooks/common/router';
2023-12-14 21:45:29 +08:00
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
2023-11-17 08:45:00 +08:00
import { useAuthStore } from '@/store/modules/auth';
defineOptions({
name: 'PwdLogin'
});
const authStore = useAuthStore();
const { toggleLoginModule } = useRouterPush();
const { formRef, validate } = useNaiveForm();
interface FormModel {
userName: string;
password: string;
}
const model: FormModel = reactive({
userName: 'Soybean',
password: '123456'
});
2024-01-28 16:24:43 +08:00
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
2024-03-24 03:02:08 +08:00
// inside computed to make locale reactive, if not apply i18n, you can define it without computed
const { formRules } = useFormRules();
2024-01-28 16:24:43 +08:00
return {
userName: formRules.userName,
password: formRules.pwd
};
});
2023-11-17 08:45:00 +08:00
async function handleSubmit() {
await validate();
await authStore.login(model.userName, model.password);
}
2024-03-24 15:39:41 +08:00
type AccountKey = 'super' | 'admin' | 'user';
interface Account {
key: AccountKey;
label: string;
userName: string;
password: string;
}
const accounts = computed<Account[]>(() => [
{
key: 'super',
label: $t('page.login.pwdLogin.superAdmin'),
userName: 'Super',
password: '123456'
},
{
key: 'admin',
label: $t('page.login.pwdLogin.admin'),
userName: 'Admin',
password: '123456'
},
{
key: 'user',
label: $t('page.login.pwdLogin.user'),
userName: 'User',
password: '123456'
}
]);
async function handleAccountLogin(account: Account) {
await authStore.login(account.userName, account.password);
}
2023-11-17 08:45:00 +08:00
</script>
<template>
<NForm ref="formRef" :model="model" :rules="rules" size="large" :show-label="false">
<NFormItem path="userName">
<NInput v-model:value="model.userName" :placeholder="$t('page.login.common.userNamePlaceholder')" />
</NFormItem>
<NFormItem path="password">
<NInput
v-model:value="model.password"
type="password"
2024-03-24 04:03:49 +08:00
show-password-on="click"
2023-11-17 08:45:00 +08:00
:placeholder="$t('page.login.common.passwordPlaceholder')"
/>
</NFormItem>
2023-12-14 21:45:29 +08:00
<NSpace vertical :size="24">
2023-11-17 08:45:00 +08:00
<div class="flex-y-center justify-between">
<NCheckbox>{{ $t('page.login.pwdLogin.rememberMe') }}</NCheckbox>
2024-03-24 03:02:08 +08:00
<NButton quaternary @click="toggleLoginModule('reset-pwd')">
{{ $t('page.login.pwdLogin.forgetPassword') }}
</NButton>
2023-11-17 08:45:00 +08:00
</div>
<NButton type="primary" size="large" round block :loading="authStore.loginLoading" @click="handleSubmit">
2023-11-17 08:45:00 +08:00
{{ $t('common.confirm') }}
</NButton>
<div class="flex-y-center justify-between gap-12px">
<NButton class="flex-1" block @click="toggleLoginModule('code-login')">
{{ $t(loginModuleRecord['code-login']) }}
</NButton>
<NButton class="flex-1" block @click="toggleLoginModule('register')">
{{ $t(loginModuleRecord.register) }}
</NButton>
</div>
2024-03-24 15:39:41 +08:00
<NDivider class="text-14px text-#666 !m-0">{{ $t('page.login.pwdLogin.otherAccountLogin') }}</NDivider>
<div class="flex-center gap-12px">
<NButton v-for="item in accounts" :key="item.key" type="primary" @click="handleAccountLogin(item)">
{{ item.label }}
</NButton>
</div>
2023-11-17 08:45:00 +08:00
</NSpace>
</NForm>
</template>
<style scoped></style>