5c3f3bca63
- 真实后端(server/):SQLite 存储 + scrypt 会话鉴权 + SMTP 邮件 - auth 注册/登录/登出/me/资料更新 - contact 联系表单(落库+邮件)、newsletter 订阅(去重) - favorites 作品收藏、comments 新闻评论、account 管理收件箱 - 用户系统 UI:个人中心 /account(资料/收藏/评论/管理员面板)、 收藏按钮、评论组件、登录/注册弹窗接真实 API(useApiError 错误映射) - 内容单点事实源:app/data/news|work 消除三处重复,页面全部引用 - 修复断链:首页动态/作品卡可点击、分享按钮真实动作、移除 # 死链、 语言切换器、社交链接统一 siteConfig - SEO:动态 sitemap/robots、JSON-LD、脚本生成真实 og-image.png - 列表增强:搜索 + 加载更多 - 部署自动化:build-and-push.sh 支持 git tag 版本化镜像; deploy.sh 一条命令构建推送+注入 Secret/ConfigMap+kubectl 滚动升级; deployment 挂 PVC 持久化;Dockerfile 支持 better-sqlite3 原生编译 - 组件注册去目录前缀,修复 AppLoader/AnimatedButton 等未渲染问题
183 lines
5.7 KiB
Vue
183 lines
5.7 KiB
Vue
<template>
|
|
<Teleport to="body">
|
|
<Transition name="modal">
|
|
<div
|
|
v-if="authModal.isLoginOpen"
|
|
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm px-4"
|
|
@click.self="closeModal"
|
|
>
|
|
<div
|
|
ref="modalRef"
|
|
class="relative w-full max-w-md bg-white rounded-2xl shadow-2xl overflow-hidden"
|
|
@click.stop
|
|
>
|
|
<!-- 关闭按钮 -->
|
|
<button
|
|
@click="closeModal"
|
|
class="absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full hover:bg-gray-100 transition-colors z-10"
|
|
aria-label="Close"
|
|
>
|
|
<Icon name="ph:x" class="w-5 h-5 text-gray-600" />
|
|
</button>
|
|
|
|
<!-- 登录表单 -->
|
|
<div class="p-8">
|
|
<h2 class="text-2xl md:text-3xl font-bold text-black mb-2">{{ t('auth.login') }}</h2>
|
|
<p class="text-gray-600 mb-8">{{ t('auth.loginDescription') }}</p>
|
|
|
|
<form @submit.prevent="handleLogin" class="space-y-5">
|
|
<div>
|
|
<label for="account" class="block text-sm font-semibold text-gray-800 mb-2">
|
|
{{ t('auth.account') }}
|
|
</label>
|
|
<input
|
|
id="account"
|
|
v-model="account"
|
|
type="text"
|
|
required
|
|
autocomplete="username"
|
|
:disabled="isSubmitting"
|
|
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
:placeholder="t('auth.accountPlaceholder')"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="password" class="block text-sm font-semibold text-gray-800 mb-2">
|
|
{{ t('auth.password') }}
|
|
</label>
|
|
<input
|
|
id="password"
|
|
v-model="password"
|
|
type="password"
|
|
required
|
|
autocomplete="current-password"
|
|
:disabled="isSubmitting"
|
|
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
:placeholder="t('auth.passwordPlaceholder')"
|
|
/>
|
|
</div>
|
|
|
|
<!-- 错误消息 -->
|
|
<div v-if="errorMessage" class="p-3 rounded-lg bg-red-50 border border-red-200 text-red-800 text-sm">
|
|
{{ errorMessage }}
|
|
</div>
|
|
|
|
<!-- 登录按钮 -->
|
|
<button
|
|
type="submit"
|
|
:disabled="isSubmitting || !account || !password"
|
|
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2"
|
|
:class="isSubmitting || !account || !password
|
|
? 'bg-gray-400 cursor-not-allowed'
|
|
: 'bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl'"
|
|
>
|
|
<Icon v-if="isSubmitting" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
|
<span>{{ isSubmitting ? t('auth.loggingIn') : t('auth.loginButton') }}</span>
|
|
</button>
|
|
</form>
|
|
|
|
<!-- 注册账号链接 -->
|
|
<p class="mt-6 text-center text-sm text-gray-600">
|
|
{{ t('auth.noAccount') }}
|
|
<button @click="authModal.switchToRegister()" class="text-black font-semibold hover:underline">
|
|
{{ t('auth.createAccount') }}
|
|
</button>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Transition>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, watch } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { useUserStore } from '~/stores/user'
|
|
import { useAuthModalStore } from '~/stores/authModal'
|
|
import { useApiError } from '~/composables/useApiError'
|
|
|
|
const { t } = useI18n()
|
|
const userStore = useUserStore()
|
|
const authModal = useAuthModalStore()
|
|
const apiError = useApiError()
|
|
|
|
const account = ref('')
|
|
const password = ref('')
|
|
const isSubmitting = ref(false)
|
|
const errorMessage = ref('')
|
|
|
|
const closeModal = () => {
|
|
if (!isSubmitting.value) {
|
|
authModal.closeAll()
|
|
}
|
|
}
|
|
|
|
// 打开时重置表单
|
|
watch(
|
|
() => authModal.isLoginOpen,
|
|
(open) => {
|
|
if (open) {
|
|
account.value = ''
|
|
password.value = ''
|
|
errorMessage.value = ''
|
|
}
|
|
},
|
|
)
|
|
|
|
const handleLogin = async () => {
|
|
if (isSubmitting.value) return
|
|
isSubmitting.value = true
|
|
errorMessage.value = ''
|
|
|
|
const result = await userStore.login(account.value, password.value)
|
|
|
|
if (result.success) {
|
|
account.value = ''
|
|
password.value = ''
|
|
authModal.closeAll()
|
|
} else {
|
|
errorMessage.value = apiError({ data: { code: result.code } })
|
|
}
|
|
isSubmitting.value = false
|
|
}
|
|
|
|
// ESC 关闭
|
|
const handleKeydown = (e: KeyboardEvent) => {
|
|
if (e.key === 'Escape' && authModal.isLoginOpen) {
|
|
closeModal()
|
|
}
|
|
}
|
|
if (typeof window !== 'undefined') {
|
|
window.addEventListener('keydown', handleKeydown)
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.modal-enter-active,
|
|
.modal-leave-active {
|
|
transition: opacity 0.3s ease;
|
|
}
|
|
|
|
.modal-enter-from,
|
|
.modal-leave-to {
|
|
opacity: 0;
|
|
}
|
|
|
|
.modal-enter-active .relative,
|
|
.modal-leave-active .relative {
|
|
transition: transform 0.3s ease, opacity 0.3s ease;
|
|
}
|
|
|
|
.modal-enter-from .relative {
|
|
transform: scale(0.95) translateY(20px);
|
|
opacity: 0;
|
|
}
|
|
|
|
.modal-leave-to .relative {
|
|
transform: scale(0.95) translateY(20px);
|
|
opacity: 0;
|
|
}
|
|
</style>
|