perf: 密码验证样式优化

This commit is contained in:
wangdan-fit2cloud 2024-10-17 16:18:32 +08:00
parent 01e775d579
commit a242242d49
6 changed files with 116 additions and 83 deletions

View File

@ -390,11 +390,12 @@ const updatePlatformStatus: (application_id: string, data: any) => Promise<Resul
/** /**
* *
*/ */
const validatePassword: (application_id: string, password: string) => Promise<Result<any>> = ( const validatePassword: (
application_id, application_id: string,
password password: string,
) => { loading?: Ref<boolean>
return get(`/application/${application_id}/auth/${password}`, undefined) ) => Promise<Result<any>> = (application_id, password, loading) => {
return get(`/application/${application_id}/auth/${password}`, undefined, loading)
} }
export default { export default {

View File

@ -1,10 +1,9 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import applicationApi from '@/api/application' import applicationApi from '@/api/application'
import applicationXpackApi from '@/api/application-xpack' import applicationXpackApi from '@/api/application-xpack'
import { type Ref, type UnwrapRef } from 'vue' import { type Ref } from 'vue'
import useUserStore from './user' import useUserStore from './user'
import type { ApplicationFormType } from '@/api/type/application'
const useApplicationStore = defineStore({ const useApplicationStore = defineStore({
id: 'application', id: 'application',
@ -123,7 +122,7 @@ const useApplicationStore = defineStore({
async validatePassword(id: string, password: string, loading?: Ref<boolean>) { async validatePassword(id: string, password: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
applicationApi applicationApi
.validatePassword(id, password) .validatePassword(id, password, loading)
.then((data) => { .then((data) => {
resolve(data) resolve(data)
}) })

View File

@ -2,9 +2,8 @@
<div class="chat-embed layout-bg" v-loading="loading"> <div class="chat-embed layout-bg" v-loading="loading">
<el-dialog <el-dialog
v-model="isPasswordDialogVisible" v-model="isPasswordDialogVisible"
width="480px" width="480"
height="236px" title="请输入密码打开链接"
title="输入密码打开链接"
custom-class="no-close-button" custom-class="no-close-button"
:close-on-click-modal="false" :close-on-click-modal="false"
:close-on-press-escape="false" :close-on-press-escape="false"
@ -12,21 +11,19 @@
center center
:modal="true" :modal="true"
> >
<el-input <el-form ref="FormRef" :model="form" :rules="rules" v-loading="validateLoading">
style="width: 400px; height: 40px" <el-form-item prop="password">
v-model="password" <el-input
:placeholder="$t('login.ldap.passwordPlaceholder')" v-model="form.password"
show-password :placeholder="$t('login.ldap.passwordPlaceholder')"
/> show-password
<span class="input-error" v-if="passwordError">{{ passwordError }}</span> />
<el-button </el-form-item>
type="primary" <el-button class="w-full mt-8" type="primary" @click="submitHandle(FormRef)"
@click="validatePassword" >确定</el-button
style="width: 400px; height: 40px; margin-top: 24px" >
>确定</el-button </el-form>
>
</el-dialog> </el-dialog>
<div v-if="isAuthenticated"> <div v-if="isAuthenticated">
<div class="chat-embed__header" :class="!isDefaultTheme ? 'custom-header' : ''"> <div class="chat-embed__header" :class="!isDefaultTheme ? 'custom-header' : ''">
<div class="chat-width flex align-center"> <div class="chat-width flex align-center">
@ -131,6 +128,7 @@
import { ref, onMounted, reactive, nextTick, computed } from 'vue' import { ref, onMounted, reactive, nextTick, computed } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { isAppIcon } from '@/utils/application' import { isAppIcon } from '@/utils/application'
import type { FormInstance, FormRules } from 'element-plus'
import useStore from '@/stores' import useStore from '@/stores'
const route = useRoute() const route = useRoute()
const { const {
@ -150,11 +148,47 @@ const applicationDetail = ref<any>({})
const applicationAvailable = ref<boolean>(true) const applicationAvailable = ref<boolean>(true)
const chatLogeData = ref<any[]>([]) const chatLogeData = ref<any[]>([])
const show = ref(false) const show = ref(false)
const FormRef = ref()
const isPasswordDialogVisible = ref(false) const isPasswordDialogVisible = ref(false)
const password = ref('') const validateLoading = ref(false)
const passwordError = ref('')
const form = ref({
password: ''
})
const isAuthenticated = ref(false) const isAuthenticated = ref(false)
const validateName = (rule: any, value: string, callback: any) => {
if (value === '') {
callback(new Error('密码不能为空'))
} else {
application
.validatePassword(applicationDetail?.value.id, form.value.password, validateLoading)
.then((res: any) => {
if (res?.data.is_valid) {
callback()
} else {
callback(new Error('密码错误'))
}
})
}
}
const rules = reactive({
password: [{ required: true, validator: validateName, trigger: 'blur' }]
})
const submitHandle = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid) => {
if (valid) {
isAuthenticated.value = true
isPasswordDialogVisible.value = false
}
})
}
const paginationConfig = reactive({ const paginationConfig = reactive({
current_page: 1, current_page: 1,
page_size: 20, page_size: 20,
@ -204,20 +238,6 @@ function newChat() {
currentRecordList.value = [] currentRecordList.value = []
currentChatId.value = 'new' currentChatId.value = 'new'
} }
function validatePassword() {
if (!password.value) {
passwordError.value = '密码不能为空'
return //
}
application.validatePassword(applicationDetail?.value.id, password.value).then((res: any) => {
if (res?.data.is_valid) {
isAuthenticated.value = true
isPasswordDialogVisible.value = false
} else {
passwordError.value = '密码错误'
}
})
}
function getAccessToken(token: string) { function getAccessToken(token: string) {
application application

View File

@ -2,9 +2,8 @@
<div class="chat-pc layout-bg" :class="classObj" v-loading="loading"> <div class="chat-pc layout-bg" :class="classObj" v-loading="loading">
<el-dialog <el-dialog
v-model="isPasswordDialogVisible" v-model="isPasswordDialogVisible"
width="480px" width="480"
height="236px" title="请输入密码打开链接"
title="输入密码打开链接"
custom-class="no-close-button" custom-class="no-close-button"
:close-on-click-modal="false" :close-on-click-modal="false"
:close-on-press-escape="false" :close-on-press-escape="false"
@ -12,19 +11,18 @@
center center
:modal="true" :modal="true"
> >
<el-input <el-form ref="FormRef" :model="form" :rules="rules" v-loading="validateLoading">
style="width: 400px; height: 40px" <el-form-item prop="password">
v-model="password" <el-input
:placeholder="$t('login.ldap.passwordPlaceholder')" v-model="form.password"
show-password :placeholder="$t('login.ldap.passwordPlaceholder')"
/> show-password
<span class="input-error" v-if="passwordError">{{ passwordError }}</span> />
<el-button </el-form-item>
type="primary" <el-button class="w-full mt-8" type="primary" @click="submitHandle(FormRef)"
@click="validatePassword" >确定</el-button
style="width: 400px; height: 40px; margin-top: 24px" >
>确定</el-button </el-form>
>
</el-dialog> </el-dialog>
<div v-if="isAuthenticated"> <div v-if="isAuthenticated">
@ -160,8 +158,6 @@ import useStore from '@/stores'
import useResize from '@/layout/hooks/useResize' import useResize from '@/layout/hooks/useResize'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { t } from '@/locales' import { t } from '@/locales'
import authApi from '@/api/auth-setting'
import { MsgSuccess } from '@/utils/message'
useResize() useResize()
const route = useRoute() const route = useRoute()
@ -176,12 +172,48 @@ const isDefaultTheme = computed(() => {
return user.isDefaultTheme() return user.isDefaultTheme()
}) })
const FormRef = ref()
const isCollapse = ref(false) const isCollapse = ref(false)
const isPasswordDialogVisible = ref(false) const isPasswordDialogVisible = ref(false)
const password = ref('') const validateLoading = ref(false)
const passwordError = ref('')
const form = ref({
password: ''
})
const isAuthenticated = ref(false) const isAuthenticated = ref(false)
const validateName = (rule: any, value: string, callback: any) => {
if (value === '') {
callback(new Error('密码不能为空'))
} else {
application
.validatePassword(applicationDetail?.value.id, form.value.password, validateLoading)
.then((res: any) => {
if (res?.data.is_valid) {
callback()
} else {
callback(new Error('密码错误'))
}
})
}
}
const rules = reactive({
password: [{ required: true, validator: validateName, trigger: 'blur' }]
})
const submitHandle = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid) => {
if (valid) {
isAuthenticated.value = true
isPasswordDialogVisible.value = false
}
})
}
const classObj = computed(() => { const classObj = computed(() => {
return { return {
mobile: common.isMobile(), mobile: common.isMobile(),
@ -376,21 +408,6 @@ async function exportHTML(): Promise<void> {
saveAs(blob, suggestedName) saveAs(blob, suggestedName)
} }
function validatePassword() {
if (!password.value) {
passwordError.value = '密码不能为空'
return //
}
application.validatePassword(applicationDetail?.value.id, password.value).then((res: any) => {
if (res?.data.is_valid) {
isAuthenticated.value = true
isPasswordDialogVisible.value = false
} else {
passwordError.value = '密码错误'
}
})
}
onMounted(() => { onMounted(() => {
user.changeUserType(2) user.changeUserType(2)
getAccessToken(accessToken) getAccessToken(accessToken)
@ -510,8 +527,4 @@ onMounted(() => {
} }
} }
} }
.input-error {
color: red;
display: block;
}
</style> </style>

View File

@ -45,12 +45,12 @@
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="使用" align="center" width="80" fixed="right"> <el-table-column label="查看" align="center" width="80" fixed="right">
<template #header> <template #header>
<el-checkbox <el-checkbox
:disabled="props.manage" :disabled="props.manage"
v-model="allChecked[TeamEnum.USE]" v-model="allChecked[TeamEnum.USE]"
label="使用" label="查看"
@change="handleCheckAllChange($event, TeamEnum.USE)" @change="handleCheckAllChange($event, TeamEnum.USE)"
/> />
</template> </template>

View File

@ -320,7 +320,7 @@ onMounted(() => {
border-bottom: none !important; border-bottom: none !important;
:deep(.el-collapse-item__header) { :deep(.el-collapse-item__header) {
border-bottom: none !important; border-bottom: none !important;
padding: 10px 0 10px 16px; padding-left: 16px;
font-size: 14px; font-size: 14px;
&:hover { &:hover {
background: var(--app-text-color-light-1); background: var(--app-text-color-light-1);