feat: 新增 Nitro Server API 与 PostgreSQL 后端,接入用户系统/联系表单/资讯订阅

- server/api: 注册/登录/登出/会话恢复(JWT + httpOnly Cookie, bcrypt 密码哈希)
- server/api: 联系表单与资讯订阅入库,支持 SMTP 邮件通知(可选)
- 应用启动自动建表(幂等),docker-compose 新增 PostgreSQL 16 服务
- 前端移除全部 mock:user store、登录注册弹窗、联系表单、页脚订阅接入真实接口
- i18n 补充服务端错误码中英文案,移除 demoHint
- deploy: Deployment 环境变量(Secret 引用)、可选集群内 PostgreSQL(postgres.yaml)
- 新增 .env.example 与 README/deploy 文档更新
This commit is contained in:
2026-08-06 06:49:14 +08:00
parent 6192ae0a38
commit 4bef241544
29 changed files with 1320 additions and 354 deletions
+10 -13
View File
@@ -234,19 +234,14 @@ const handleSubmit = async () => {
statusMessage.value = ''
try {
// 模拟 API 调用 - 你需要替换为真实的邮件服务
// 可选方案:
// 1. 使用 Nuxt server API: await $fetch('/api/contact', { method: 'POST', body: form })
// 2. 使用 Formspree: await fetch('https://formspree.io/f/YOUR_ID', { ... })
// 3. 使用 EmailJS 等第三方服务
await new Promise(resolve => setTimeout(resolve, 1500)) // 模拟网络延迟
// 模拟成功
console.log('Form submitted:', form)
// 真实提交:入库(PostgreSQL)+ 可选 SMTP 邮件通知
await $fetch('/api/contact', {
method: 'POST',
body: { ...form },
})
submitStatus.value = 'success'
statusMessage.value = t('contact.form.successMessage') || 'Message sent successfully! We will get back to you soon.'
statusMessage.value = t('contact.form.successMessage')
// 清空表单
Object.keys(form).forEach(key => {
@@ -259,10 +254,12 @@ const handleSubmit = async () => {
statusMessage.value = ''
}, 3000)
} catch (error) {
} catch (error: any) {
console.error('Form submission error:', error)
submitStatus.value = 'error'
statusMessage.value = t('contact.form.errorMessage') || 'Failed to send message. Please try again or contact us directly.'
// 优先显示服务端返回的具体错误码(i18n key),否则显示通用错误
const code = error?.data?.statusMessage || error?.statusMessage || ''
statusMessage.value = code && code !== 'Bad Request' ? t(code) : t('contact.form.errorMessage')
} finally {
isSubmitting.value = false
}