11<script setup lang='ts'>
22import { computed , onMounted , ref } from ' vue'
3- import { NButton , NInput , NModal , NSpace , useMessage } from ' naive-ui'
3+ import { NButton , NInput , NModal , NTabPane , NTabs , useMessage } from ' naive-ui'
44import { useRoute , useRouter } from ' vue-router'
55import { fetchLogin , fetchRegister , fetchVerify } from ' @/api'
66import { useAuthStore } from ' @/store'
@@ -24,6 +24,21 @@ const password = ref('')
2424
2525const disabled = computed (() => ! username .value .trim () || ! password .value .trim () || loading .value )
2626
27+ const activeTab = ref (' login' )
28+
29+ const showConfirmPassword = ref (false )
30+ const confirmPassword = ref (' ' )
31+
32+ function handlePasswordInput() {
33+ showConfirmPassword .value = password .value .trim () !== ' '
34+ }
35+
36+ const confirmPasswordStatus = computed (() => {
37+ if (! password .value || ! confirmPassword .value )
38+ return undefined
39+ return password .value !== confirmPassword .value ? ' error' : ' success'
40+ })
41+
2742onMounted (async () => {
2843 const verifytoken = route .query .verifytoken as string
2944 await handleVerify (verifytoken )
@@ -83,9 +98,12 @@ async function handleLogin() {
8398async function handleRegister() {
8499 const name = username .value .trim ()
85100 const pwd = password .value .trim ()
101+ const confirmPwd = confirmPassword .value .trim ()
86102
87- if (! name || ! pwd )
103+ if (! name || ! pwd || ! confirmPwd || pwd !== confirmPwd ) {
104+ ms .error (' 两次输入的密码不一致 | Passwords don\' t match' )
88105 return
106+ }
89107
90108 try {
91109 loading .value = true
@@ -114,39 +132,36 @@ async function handleRegister() {
114132 </p >
115133 <Icon403 class =" w-[200px] m-auto" />
116134 </header >
117- <NInput v-model:value =" username" type =" text" placeholder =" Email" />
118- <NInput v-model:value =" password" type =" password" placeholder =" Password" @keypress =" handlePress" />
119-
120- <NSpace v-if =" authStore.session && authStore.session.allowRegister" justify =" space-around" >
121- <NButton
122- block
123- type =" primary"
124- :disabled =" disabled"
125- :loading =" loading"
126- @click =" handleRegister"
127- >
128- {{ $t('common.register') }}
129- </NButton >
130- <NButton
131- block
132- type =" primary"
133- :disabled =" disabled"
134- :loading =" loading"
135- @click =" handleLogin"
136- >
137- {{ $t('common.login') }}
138- </NButton >
139- </NSpace >
140- <NButton
141- v-if =" !(authStore.session && authStore.session.allowRegister)"
142- block
143- type =" primary"
144- :disabled =" disabled"
145- :loading =" loading"
146- @click =" handleLogin"
147- >
148- {{ $t('common.login') }}
149- </NButton >
135+
136+ <!-- Add Tabs -->
137+ <NTabs v-model:value =" activeTab" type =" line" >
138+ <NTabPane name =" login" :label =" $t('common.login')" >
139+ <NInput v-model:value =" username" type =" text" :placeholder =" $t('common.email')" class =" mb-2" />
140+ <NInput v-model:value =" password" type =" password" :placeholder =" $t('common.password')" class =" mb-2" @keypress =" handlePress" />
141+
142+ <NButton block type =" primary" :disabled =" disabled" :loading =" loading" @click =" handleLogin" >
143+ {{ $t('common.login') }}
144+ </NButton >
145+ </NTabPane >
146+
147+ <NTabPane v-if =" authStore.session && authStore.session.allowRegister" name =" register" :label =" $t('common.register')" >
148+ <NInput v-model:value =" username" type =" text" :placeholder =" $t('common.email')" class =" mb-2" />
149+ <NInput v-model:value =" password" type =" password" :placeholder =" $t('common.password')" class =" mb-2" @input =" handlePasswordInput" />
150+ <NInput
151+ v-if =" showConfirmPassword"
152+ v-model:value =" confirmPassword"
153+ type =" password"
154+ :placeholder =" $t('common.passwordConfirm')"
155+ class =" mb-4"
156+ :status =" confirmPasswordStatus"
157+ />
158+
159+ <NButton block type =" primary" :disabled =" disabled || password !== confirmPassword" :loading =" loading" @click =" handleRegister" >
160+ {{ $t('common.register') }}
161+ </NButton >
162+ </NTabPane >
163+ </NTabs >
164+ <!-- End Tabs -->
150165 </div >
151166 </div >
152167 </NModal >
0 commit comments