feat: 記住帳號, 忘記密碼開關
This commit is contained in:
@@ -110,6 +110,8 @@
|
|||||||
:remember-me-label="props.form.rememberMeLabel"
|
:remember-me-label="props.form.rememberMeLabel"
|
||||||
:remember-storage-key="props.form.rememberStorageKey"
|
:remember-storage-key="props.form.rememberStorageKey"
|
||||||
:submit-text="props.form.submitText"
|
:submit-text="props.form.submitText"
|
||||||
|
:with-forgot-password="props.form.withForgotPassword"
|
||||||
|
:with-remember-account="props.form.withRememberAccount"
|
||||||
@forgot-password="handleForgotPassword"
|
@forgot-password="handleForgotPassword"
|
||||||
@submit="handleLogin"
|
@submit="handleLogin"
|
||||||
>
|
>
|
||||||
@@ -172,6 +174,8 @@
|
|||||||
:remember-me-label="props.form.rememberMeLabel"
|
:remember-me-label="props.form.rememberMeLabel"
|
||||||
:remember-storage-key="props.form.rememberStorageKey"
|
:remember-storage-key="props.form.rememberStorageKey"
|
||||||
:submit-text="props.form.submitText"
|
:submit-text="props.form.submitText"
|
||||||
|
:with-forgot-password="props.form.withForgotPassword"
|
||||||
|
:with-remember-account="props.form.withRememberAccount"
|
||||||
@forgot-password="handleForgotPassword"
|
@forgot-password="handleForgotPassword"
|
||||||
@submit="handleLogin"
|
@submit="handleLogin"
|
||||||
>
|
>
|
||||||
@@ -311,6 +315,8 @@ interface FormConfig {
|
|||||||
rememberMeLabel?: string
|
rememberMeLabel?: string
|
||||||
submitText?: string
|
submitText?: string
|
||||||
rememberStorageKey?: string
|
rememberStorageKey?: string
|
||||||
|
withForgotPassword?: boolean
|
||||||
|
withRememberAccount?: boolean
|
||||||
withCaptcha?: boolean
|
withCaptcha?: boolean
|
||||||
captcha?: {
|
captcha?: {
|
||||||
imgUrl?: string
|
imgUrl?: string
|
||||||
@@ -400,6 +406,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
rememberMeLabel: '記住帳號',
|
rememberMeLabel: '記住帳號',
|
||||||
submitText: '登入',
|
submitText: '登入',
|
||||||
rememberStorageKey: 'sklogin.remember.username',
|
rememberStorageKey: 'sklogin.remember.username',
|
||||||
|
withForgotPassword: true,
|
||||||
|
withRememberAccount: true,
|
||||||
withCaptcha: true,
|
withCaptcha: true,
|
||||||
captcha: undefined,
|
captcha: undefined,
|
||||||
captchaValue: '',
|
captchaValue: '',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-form @submit.prevent="$emit('submit', { username, password, rememberMe })">
|
<v-form @submit.prevent="handleSubmit">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="username"
|
v-model="username"
|
||||||
bg-color="surface"
|
bg-color="surface"
|
||||||
@@ -27,8 +27,12 @@
|
|||||||
|
|
||||||
<slot name="verify"></slot>
|
<slot name="verify"></slot>
|
||||||
|
|
||||||
<div class="d-flex align-center justify-space-between mb-6 mb-md-4">
|
<div
|
||||||
|
v-if="props.withRememberAccount || props.withForgotPassword"
|
||||||
|
class="d-flex align-center justify-space-between mb-6 mb-md-4"
|
||||||
|
>
|
||||||
<v-checkbox
|
<v-checkbox
|
||||||
|
v-if="props.withRememberAccount"
|
||||||
v-model="rememberMe"
|
v-model="rememberMe"
|
||||||
color="primary"
|
color="primary"
|
||||||
density="compact"
|
density="compact"
|
||||||
@@ -36,6 +40,7 @@
|
|||||||
:label="props.rememberMeLabel"
|
:label="props.rememberMeLabel"
|
||||||
></v-checkbox>
|
></v-checkbox>
|
||||||
<a
|
<a
|
||||||
|
v-if="props.withForgotPassword"
|
||||||
class="text-body-2 text-primary text-decoration-none"
|
class="text-body-2 text-primary text-decoration-none"
|
||||||
:href="props.forgotPasswordHref || '#'"
|
:href="props.forgotPasswordHref || '#'"
|
||||||
:target="props.forgotPasswordTarget"
|
:target="props.forgotPasswordTarget"
|
||||||
@@ -100,11 +105,21 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'sklogin.remember.username',
|
default: 'sklogin.remember.username',
|
||||||
},
|
},
|
||||||
|
withRememberAccount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
withForgotPassword: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['submit', 'forgot-password'])
|
const emit = defineEmits(['submit', 'forgot-password'])
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
if (!props.withRememberAccount) return
|
||||||
|
|
||||||
const saved = localStorage.getItem(props.rememberStorageKey)
|
const saved = localStorage.getItem(props.rememberStorageKey)
|
||||||
if (saved) {
|
if (saved) {
|
||||||
username.value = saved
|
username.value = saved
|
||||||
@@ -113,6 +128,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch([rememberMe, username], ([nextRemember, nextUsername]) => {
|
watch([rememberMe, username], ([nextRemember, nextUsername]) => {
|
||||||
|
if (!props.withRememberAccount) return
|
||||||
|
|
||||||
if (!nextRemember) {
|
if (!nextRemember) {
|
||||||
localStorage.removeItem(props.rememberStorageKey)
|
localStorage.removeItem(props.rememberStorageKey)
|
||||||
return
|
return
|
||||||
@@ -126,7 +143,17 @@ watch([rememberMe, username], ([nextRemember, nextUsername]) => {
|
|||||||
localStorage.setItem(props.rememberStorageKey, nextUsername)
|
localStorage.setItem(props.rememberStorageKey, nextUsername)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function handleSubmit() {
|
||||||
|
emit('submit', {
|
||||||
|
username: username.value,
|
||||||
|
password: password.value,
|
||||||
|
rememberMe: props.withRememberAccount ? rememberMe.value : false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function handleForgotPasswordClick(e: MouseEvent) {
|
function handleForgotPasswordClick(e: MouseEvent) {
|
||||||
|
if (!props.withForgotPassword) return
|
||||||
|
|
||||||
emit('forgot-password', e)
|
emit('forgot-password', e)
|
||||||
if (!props.forgotPasswordHref) {
|
if (!props.forgotPasswordHref) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ const illustrationImage = ref(HyakkaouAcademyImage)
|
|||||||
const formPositionLayout = ref<LayoutType>('side-left')
|
const formPositionLayout = ref<LayoutType>('side-left')
|
||||||
// 是否啟用公告
|
// 是否啟用公告
|
||||||
const withAnnouncement = ref(true)
|
const withAnnouncement = ref(true)
|
||||||
|
const withForgotPassword = ref(true)
|
||||||
|
const withRememberAccount = ref(true)
|
||||||
|
|
||||||
// 功能開關:是否啟用驗證碼
|
// 功能開關:是否啟用驗證碼
|
||||||
const withCaptcha = ref(true)
|
const withCaptcha = ref(true)
|
||||||
@@ -154,6 +156,8 @@ const form = computed(() => ({
|
|||||||
captchaPlaceholder: captchaPlaceholder.value,
|
captchaPlaceholder: captchaPlaceholder.value,
|
||||||
refreshTitle: refreshTitle.value,
|
refreshTitle: refreshTitle.value,
|
||||||
rememberStorageKey: rememberStorageKey.value,
|
rememberStorageKey: rememberStorageKey.value,
|
||||||
|
withForgotPassword: withForgotPassword.value,
|
||||||
|
withRememberAccount: withRememberAccount.value,
|
||||||
// 功能開關:是否顯示驗證碼
|
// 功能開關:是否顯示驗證碼
|
||||||
withCaptcha: withCaptcha.value,
|
withCaptcha: withCaptcha.value,
|
||||||
captcha: loginCaptcha.formCaptcha.value,
|
captcha: loginCaptcha.formCaptcha.value,
|
||||||
@@ -178,6 +182,8 @@ const toolbar = computed(() => ({
|
|||||||
|
|
||||||
// 事件處理
|
// 事件處理
|
||||||
function handleForgotPassword(e: MouseEvent) {
|
function handleForgotPassword(e: MouseEvent) {
|
||||||
|
if (!withForgotPassword.value) return
|
||||||
|
|
||||||
console.log('Forgot Password Click:', e)
|
console.log('Forgot Password Click:', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user