complete login i18n

This commit is contained in:
KUN1007 2023-06-16 08:50:22 +08:00
parent 338fe87a7f
commit c6704627fc
4 changed files with 93 additions and 48 deletions

View file

@ -15,15 +15,16 @@
</div> </div>
</div> </div>
<div class="msg"> <div class="msg">
<div v-if="isVerified" class="pass">验证通过</div> <div v-if="errorCount > 0" class="error">
<div v-else-if="errorCount > 0" class="error"> {{ $t('AlertInfo.capture.error') }}
点击错误请重新点击
</div> </div>
<div class="hint" v-if="!isVerified"> <div class="hint" v-if="!isVerified">
请按顺序点击以下字符: {{ $t('AlertInfo.capture.order') }}
{{ characters.map((char) => char.value).join(' ') }} {{ characters.map((char) => char.value).join(' ') }}
</div> </div>
<div class="refresh" @click="resetCharacters">点击刷新</div> <div class="refresh" @click="resetCharacters">
{{ $t('AlertInfo.capture.refresh') }}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -55,9 +56,9 @@ interface Character {
emits('validate', false) emits('validate', false)
// 26 //
function generateRandomCharacters(): Character[] { function generateRandomCharacters(): Character[] {
const chars = t('AlertInfo.captureText') const chars = t('AlertInfo.capture.text')
const randomChars: Character[] = [] const randomChars: Character[] = []
// Set // Set
@ -84,6 +85,7 @@ function generateRandomCharacters(): Character[] {
return randomChars return randomChars
} }
//
function getRandomCoordinate(): number { function getRandomCoordinate(): number {
const minCoordinate = 50 const minCoordinate = 50
const maxCoordinate = 150 const maxCoordinate = 150
@ -93,6 +95,7 @@ function getRandomCoordinate(): number {
) )
} }
//
const handleCharacterClick = (char: Character): Promise<boolean> => { const handleCharacterClick = (char: Character): Promise<boolean> => {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
clickedCharacters.value += char.value clickedCharacters.value += char.value
@ -110,6 +113,7 @@ const handleCharacterClick = (char: Character): Promise<boolean> => {
}) })
} }
// .
function resetCharacters() { function resetCharacters() {
characters.value = generateRandomCharacters() characters.value = generateRandomCharacters()
clickedCharacters.value = '' clickedCharacters.value = ''

View file

@ -119,20 +119,41 @@ export default {
publish: 'Confirm Publish', publish: 'Confirm Publish',
draft: 'Save Draft', draft: 'Save Draft',
}, },
login: {
loginTitle: 'Login',
forget: 'Forgot your password? Click here to send a password reset email',
loginUsername: 'Username or email',
loginPassword: 'Password',
capture: 'Click to proceed with the human verification process',
},
// 非页面组件这里统一用大驼峰 // 非页面组件这里统一用大驼峰
ComponentAlert: { ComponentAlert: {
confirm: 'OK', confirm: 'OK',
cancel: 'Cancel', cancel: 'Cancel',
}, },
AlertInfo: { AlertInfo: {
publish: 'Confirm to publish?', edit: {
publishSuccess: 'Publish Successfully', publish: 'Confirm to publish?',
publishCancel: 'Cancel Publish', publishSuccess: 'Publish Successfully',
draft: 'The draft has been saved successfully!', publishCancel: 'Cancel Publish',
login: 'Login Successfully! Welcome to KUN Visual Novel ~ ', draft: 'The draft has been saved successfully!',
}, },
CaptureInfo: { login: {
capture: 'Human-machine identity verification successful.', success: 'Login Successfully! Welcome to KUN Visual Novel ~ ',
text: 'abcdefghijklmnopqrstuvwxyz', emptyUsername: 'Username cannot be empty',
emptyPassword: 'Password cannot be empty',
invalidPassword:
'Invalid password format. Password must be 6 to 17 characters long and must include at least one letter and one number. It can optionally include special characters such as \\w!@#$%^&()-+=',
invalidUsername:
'Invalid username. Username should be 1 to 17 characters long and can include: Chinese characters, English letters, numbers, underscore, and tilde (~)',
},
capture: {
click: 'Please click above to complete the human verification',
success: 'Human-machine identity verification successful',
text: 'abcdefghijklmnopqrstuvwxyz',
order: 'Please click the characters in order',
refresh: 'Refresh',
error: 'Click error, please click again',
},
}, },
} }

View file

@ -118,20 +118,41 @@ export default {
publish: '确认发布', publish: '确认发布',
draft: '保存草稿', draft: '保存草稿',
}, },
login: {
loginTitle: '登录',
forget: '忘记密码? 点击发送重置邮件',
loginUsername: '用户名或邮箱',
loginPassword: '密码',
capture: '点击进行人机身份验证',
},
// 非页面组件这里统一用大驼峰 // 非页面组件这里统一用大驼峰
ComponentAlert: { ComponentAlert: {
confirm: '确定', confirm: '确定',
cancel: '取消', cancel: '取消',
}, },
AlertInfo: { AlertInfo: {
publish: '确认发布吗?', edit: {
publishSuccess: '发布成功', publish: '确认发布吗?',
publishCancel: '取消发布', publishSuccess: '发布成功',
draft: '草稿已经保存成功!', publishCancel: '取消发布',
login: '登陆成功!欢迎来到 鲲 Galgame ~ ', draft: '草稿已经保存成功!',
}, },
CaptureInfo: { login: {
capture: '人机身份验证通过', login: '登陆成功!欢迎来到 鲲 Galgame ~ ',
text: '闭月羞花出水芙蓉亭亭玉立小只可爱软萌鲲', emptyUsername: '用户名不可为空',
emptyPassword: '密码不可为空',
invalidPassword:
'非法的密码格式,密码的长度为 6 到 17 位,必须包含至少一个英文字符和一个数字,可以选择性的包含 \\w!@#$%^&*()-+= 等特殊字符',
invalidUsername:
'非法的用户名,用户名为 1 到 17 位,可以包含:中文、英文、数字、下划线、波浪线',
},
capture: {
click: '请点击上方完成人机身份验证',
success: '人机身份验证通过 ~ ',
text: '闭月羞花出水芙蓉亭亭玉立小只可爱软萌鲲',
order: '请按顺序点击以下字符',
refresh: '刷新',
error: '点击错误,请重新点击',
},
}, },
} }

View file

@ -11,6 +11,10 @@ import Capture from '@/components/capture/Capture.vue'
// //
import { isValidEmail, isValidName, isValidPassword } from '@/utils/validate' import { isValidEmail, isValidName, isValidPassword } from '@/utils/validate'
// i18n
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
// //
const isShowValidate = ref(false) const isShowValidate = ref(false)
// //
@ -32,7 +36,7 @@ const handleVerify = (result: boolean) => {
if (result) { if (result) {
// //
isShowValidate.value = false isShowValidate.value = false
info.info('CaptureInfo.capture') info.info(t('AlertInfo.capture.success'))
isCaptureComplete.value = true isCaptureComplete.value = true
} }
} }
@ -41,11 +45,11 @@ const isEmptyInput = () => {
// //
if (!loginForm.username.trim()) { if (!loginForm.username.trim()) {
// //
info.info('用户名不可为空') info.info(t('AlertInfo.login.emptyUsername'))
return false return false
} else if (!loginForm.password.trim()) { } else if (!loginForm.password.trim()) {
// //
info.info('密码不可为空') info.info(t('AlertInfo.login.emptyPassword'))
return false return false
} else { } else {
return true return true
@ -64,16 +68,12 @@ const isValidInput = (): boolean => {
return true return true
} else { } else {
// //
info.info( info.info(t('AlertInfo.login.invalidPassword'))
`非法的密码格式,密码的长度为 6 到 17 位,必须包含至少一个英文字符和一个数字,可以选择性的包含 \\w!@#$%^&*()-+= 等特殊字符`
)
return false return false
} }
} else { } else {
// //
info.info( info.info(t('AlertInfo.login.invalidUsername'))
`非法的用户名,用户名为 1 到 17 位,可以包含:中文、英文、数字、下划线、波浪线 `
)
return false return false
} }
} }
@ -84,7 +84,7 @@ const handleLogin = () => {
if (isValidInput()) { if (isValidInput()) {
// //
if (!isCaptureComplete.value) { if (!isCaptureComplete.value) {
info.info('请点击上方完成人机身份验证') info.info(t('AlertInfo.capture.click'))
return return
} }
// //
@ -92,7 +92,7 @@ const handleLogin = () => {
// //
if (res.success) { if (res.success) {
router.push('/') router.push('/')
info.info('AlertInfo.login') info.info(t('AlertInfo.login.success'))
} }
}) })
} }
@ -104,24 +104,26 @@ const handleLogin = () => {
<div class="login"> <div class="login">
<Capture @validate="handleVerify" :isShowValidate="isShowValidate" /> <Capture @validate="handleVerify" :isShowValidate="isShowValidate" />
<form class="form" @submit.prevent="handleLogin"> <form class="form" @submit.prevent="handleLogin">
<h2 class="title">登陆</h2> <h2 class="title">{{ $t('login.loginTitle') }}</h2>
<input <input
v-model="loginForm.username" v-model="loginForm.username"
type="text" type="text"
placeholder="用户名或邮箱" :placeholder="$t('login.loginUsername')"
class="input" class="input"
/> />
<input <input
v-model="loginForm.password" v-model="loginForm.password"
type="password" type="password"
placeholder="密码" :placeholder="$t('login.loginPassword')"
class="input" class="input"
/> />
<span class="forget">忘记密码? 点击发送重置邮件</span> <span class="forget">{{ $t('login.forget') }}</span>
<span @click="isShowValidate = true" class="capture" <span @click="isShowValidate = true" class="capture">{{
>点击进行人机身份验证</span $t('login.capture')
> }}</span>
<button class="btn" type="submit">登陆</button> <button class="btn" type="submit">
{{ $t('login.loginTitle') }}
</button>
</form> </form>
</div> </div>
</template> </template>
@ -188,6 +190,7 @@ const handleLogin = () => {
.btn { .btn {
position: absolute; position: absolute;
margin-top: 1.5rem;
bottom: 7%; bottom: 7%;
border-radius: 50px; border-radius: 50px;
background-color: var(--kungalgame-trans-white-5); background-color: var(--kungalgame-trans-white-5);
@ -207,10 +210,6 @@ const handleLogin = () => {
color: var(--kungalgame-white); color: var(--kungalgame-white);
} }
.form > .btn {
margin-top: 1.5rem;
}
.btn:active { .btn:active {
transform: scale(0.95); transform: scale(0.95);
} }