提交代码

This commit is contained in:
ldh
2026-11-16 17:03:18 +08:00
parent ba22189a46
commit 4e80b593de
13 changed files with 1813 additions and 2 deletions
@@ -0,0 +1,286 @@
<script setup lang="ts">
import { nextTick, onBeforeUnmount, ref, watch } from 'vue'
import { verifyAdminPassword } from '@/api/systemConfig'
const props = defineProps<{
open: boolean
}>()
const emit = defineEmits<{
close: []
success: []
}>()
const password = ref('')
const error = ref('')
const submitting = ref(false)
const inputElement = ref<HTMLInputElement | null>(null)
function close() {
if (submitting.value) return
emit('close')
}
function onKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') close()
}
async function submit() {
if (submitting.value) return
if (!password.value) {
error.value = '请输入密码'
return
}
submitting.value = true
error.value = ''
try {
await verifyAdminPassword(password.value)
password.value = ''
emit('success')
} catch (err) {
error.value = err instanceof Error ? err.message : '密码校验失败'
} finally {
submitting.value = false
}
}
watch(
() => props.open,
async (open) => {
if (open) {
password.value = ''
error.value = ''
window.addEventListener('keydown', onKeydown)
await nextTick()
inputElement.value?.focus()
} else {
window.removeEventListener('keydown', onKeydown)
}
},
)
onBeforeUnmount(() => {
window.removeEventListener('keydown', onKeydown)
})
</script>
<template>
<Teleport to="body">
<Transition name="auth-modal">
<div v-if="open" class="auth-backdrop" @click.self="close">
<section class="auth-card" role="dialog" aria-modal="true" aria-label="管理员验证">
<div class="auth-card__icon" aria-hidden="true">
<svg viewBox="0 0 64 64">
<rect
x="14"
y="28"
width="36"
height="26"
rx="6"
fill="none"
stroke="currentColor"
stroke-width="3"
/>
<path
d="M22 28v-8a10 10 0 0 1 20 0v8"
fill="none"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
/>
<circle cx="32" cy="41" r="3.2" fill="currentColor" />
</svg>
</div>
<h2>管理员验证</h2>
<p>请输入管理员密码以进入系统参数管理</p>
<form class="auth-card__form" @submit.prevent="submit">
<input
ref="inputElement"
v-model="password"
class="auth-card__input"
type="password"
autocomplete="off"
placeholder="请输入密码"
:disabled="submitting"
/>
<p v-if="error" class="auth-card__error">{{ error }}</p>
<div class="auth-card__actions">
<button
class="auth-card__button auth-card__button--ghost"
type="button"
:disabled="submitting"
@click="close"
>
取消
</button>
<button
class="auth-card__button auth-card__button--primary"
type="submit"
:disabled="submitting"
>
{{ submitting ? '验证中...' : '确定' }}
</button>
</div>
</form>
</section>
</div>
</Transition>
</Teleport>
</template>
<style scoped>
.auth-backdrop {
position: fixed;
inset: 0;
z-index: 70;
display: grid;
place-items: center;
padding: 24px;
background: rgba(18, 33, 54, 0.44);
backdrop-filter: blur(5px);
}
.auth-card {
width: 560px;
padding: 42px 44px 38px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 24px;
background: #fff;
box-shadow: 0 30px 80px rgba(12, 30, 55, 0.3);
text-align: center;
}
.auth-card__icon {
display: grid;
place-items: center;
width: 86px;
height: 86px;
margin: 0 auto 24px;
border-radius: 50%;
color: var(--blue);
background: linear-gradient(145deg, #f1f7ff, #dfeaff);
box-shadow: inset 0 1px 0 #fff, 0 8px 22px rgba(47, 111, 208, 0.14);
}
.auth-card__icon svg {
width: 46px;
height: 46px;
}
.auth-card h2 {
color: #1f2937;
font-size: 30px;
font-weight: 600;
letter-spacing: 1px;
}
.auth-card p {
margin-top: 14px;
color: #778394;
font-size: 19px;
letter-spacing: 0.5px;
}
.auth-card__form {
margin-top: 26px;
}
.auth-card__input {
width: 100%;
height: 62px;
padding: 0 22px;
border: 2px solid var(--line-strong);
border-radius: 12px;
color: var(--ink);
font-family: inherit;
font-size: 22px;
letter-spacing: 2px;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.auth-card__input:focus {
border-color: var(--blue);
box-shadow: 0 0 0 4px rgba(47, 111, 208, 0.14);
}
.auth-card__input:disabled {
background: #f4f6f9;
}
.auth-card__error {
margin-top: 12px;
color: var(--red);
font-size: 17px;
letter-spacing: 0.5px;
}
.auth-card__actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px;
margin-top: 30px;
}
.auth-card__button {
height: 56px;
border-radius: 12px;
font-size: 20px;
font-weight: 600;
letter-spacing: 3px;
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.auth-card__button:disabled {
cursor: default;
opacity: 0.65;
}
.auth-card__button--ghost {
border: 2px solid var(--line-strong);
color: var(--ink-soft);
background: #fff;
}
.auth-card__button--ghost:hover:not(:disabled) {
background: var(--surface-soft);
}
.auth-card__button--primary {
color: #fff;
background: linear-gradient(180deg, #4b89e4 0%, #2f6fd0 100%);
box-shadow: 0 10px 22px rgba(47, 111, 208, 0.28);
}
.auth-card__button--primary:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 14px 28px rgba(47, 111, 208, 0.36);
}
.auth-modal-enter-active,
.auth-modal-leave-active {
transition: opacity 0.24s ease;
}
.auth-modal-enter-active .auth-card,
.auth-modal-leave-active .auth-card {
transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease;
}
.auth-modal-enter-from,
.auth-modal-leave-to {
opacity: 0;
}
.auth-modal-enter-from .auth-card,
.auth-modal-leave-to .auth-card {
opacity: 0;
transform: translateY(16px) scale(0.97);
}
</style>