diff --git a/.dockerignore b/.dockerignore index d69511a..71a935c 100755 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,15 @@ # 依赖目录 node_modules/ -pnpm-workspace.yaml # 编译产出目录 .output/ .nuxt/ +.nitro/ +.cache/ +dist/ + +# 本地数据(开发数据库,不进镜像) +.data/ # 环境变量文件(通常不应该被打包进去) .env diff --git a/.env.example b/.env.example index e6bd401..a3432d5 100644 --- a/.env.example +++ b/.env.example @@ -1,16 +1,41 @@ -# 本地开发环境变量示例 -# 复制为 .env 后按需修改(.env 已被 .gitignore 忽略,不会提交) +# ========================================================= +# Arcticnewone 本地开发环境变量示例 +# 复制为 .env 使用(.env 已被 gitignore,不会提交) +# +# Nuxt runtimeConfig 的环境变量映射约定:一律使用 NUXT_ 前缀 +# ========================================================= -# PostgreSQL 连接串(docker compose 起库后默认可用,宿主机端口 5433) -NUXT_DATABASE_URL=postgres://arcticnewone:arcticnewone_dev_password@localhost:5433/arcticnewone +# 站点公开地址(用于 sitemap/robots/og 等绝对链接) +NUXT_PUBLIC_SITE_URL=https://personal.virtheart.com -# JWT 签名密钥(生产环境务必改为随机长字符串) -NUXT_JWT_SECRET=dev-only-secret-change-in-production +# 会话安全密钥(生产必须设置为高强度随机值) +# 生成方式: node -e "console.log(require('crypto').randomBytes(48).toString('hex'))" +NUXT_SESSION_SECRET=dev-change-me-to-a-long-random-string -# SMTP 邮件通知(可选;不配置时联系表单/订阅仅入库) -# NUXT_SMTP_HOST=smtp.example.com -# NUXT_SMTP_PORT=465 -# NUXT_SMTP_USER=your-smtp-user -# NUXT_SMTP_PASS=your-smtp-password -# NUXT_SMTP_FROM=北极新一 -# NUXT_SMTP_CONTACT_TO=chenchun@virtheart.com +# 数据文件路径(默认:生产 /data/arcticnewone.db,开发 .data/arcticnewone.db) +# NUXT_DB_PATH=/data/arcticnewone.db + +# ---- SMTP 邮件(可选)---- +# 未配置时:联系表单与邮箱订阅仍会真实写入数据库,但不会发送邮件 +NUXT_SMTP_HOST= +NUXT_SMTP_PORT=587 +NUXT_SMTP_USER= +NUXT_SMTP_PASS= +NUXT_SMTP_FROM= +# 联系表单留言的接收邮箱 +NUXT_CONTACT_TO=chenchun@virtheart.com + +# 管理员邮箱(逗号分隔),命中邮箱的用户在个人中心显示管理面板 +NUXT_ADMIN_EMAILS=chenchun@virtheart.com + +# 预置管理员初始密码(仅首次初始化数据库时创建 admin 账号用;生产由 deploy.sh 注入) +# NUXT_ADMIN_INITIAL_PASSWORD=change-me + +# ---- OSS 文件存储(RustFS / S3 v4 兼容;凭据不写入仓库,生产由 deploy.sh 注入 Secret)---- +NUXT_OSS_ENDPOINT=oss.virtheart.com +NUXT_OSS_ACCESS_KEY= +NUXT_OSS_SECRET_KEY= +NUXT_OSS_BUCKET=arcticnewone +NUXT_OSS_REGION=us-east-1 +# 若桶公开可读,可填 https://oss.virtheart.com/arcticnewone 用于直链;留空则走 /uploads 代理 +NUXT_OSS_PUBLIC_BASE= diff --git a/Dockerfile b/Dockerfile index 60c86e4..637a88e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -4,16 +4,19 @@ # 使用国内可访问的 DaoCloud 镜像源(Docker Hub 在国内不可达) FROM docker.m.daocloud.io/library/node:22-alpine AS builder -# 启用 corepack 并安装 pnpm -RUN corepack enable && corepack prepare pnpm@9 --activate +# 启用 corepack 并安装 pnpm(与本地 pnpm 11 保持一致,兼容 pnpm-workspace.yaml 配置) +RUN corepack enable && corepack prepare pnpm@11 --activate + +# 安装原生模块编译依赖(better-sqlite3 等,构建期兜底;产物无需运行期依赖) +RUN apk add --no-cache python3 make g++ # 设置工作目录 WORKDIR /app # 复制依赖相关文件 -COPY package.json pnpm-lock.yaml ./ +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ -# 安装依赖项 +# 安装依赖项(含原生模块编译;build 需要 devDependencies,故安装全部) RUN pnpm install --frozen-lockfile # 复制项目源代码 diff --git a/README.md b/README.md index e9d79f7..19592c0 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,26 @@ # Arcticnewone 个人网站 -北极新一(Arcticnewone)的个人网站,提供个人介绍、作品集、工作室服务、动态资讯、工具箱与联系页面,是一个现代化的展示型站点。 +北极新一(Arcticnewone)的个人网站,提供个人介绍、作品集、工作室服务、动态资讯、工具箱与联系页面,是一个现代化的展示型站点。已内置**真实后端**(登录/注册、联系留言、邮箱订阅、作品收藏、新闻评论、管理员收件箱)与 **中英双语、SEO、搜索分页** 等完整功能。 ## 技术栈 -- [Nuxt 4](https://nuxt.com/) — 应用框架(服务端渲染 + 内置 Nitro Server API) +- [Nuxt 4](https://nuxt.com/) — 应用框架(服务端渲染 + Nitro 后端 API) - [Vue 3](https://vuejs.org/) — 视图层 - [Tailwind CSS](https://tailwindcss.com/) — 样式方案(通过 `@nuxtjs/tailwindcss` 集成) - [GSAP](https://gsap.com/) — 页面动画(配合 Lenis 平滑滚动) - [Pinia](https://pinia.vuejs.org/) — 状态管理 - [@nuxtjs/i18n](https://i18n.nuxtjs.org/) — 国际化(中/英双语) +- [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) — 数据存储(SQLite,K8s PVC 持久化) +- [nodemailer](https://nodemailer.com/) — 邮件发送(SMTP) - [@nuxt/icon](https://nuxt.com/modules/icon) — 图标 -- [PostgreSQL](https://www.postgresql.org/) — 数据库(用户 / 联系留言 / 资讯订阅) -- [node-postgres (pg)](https://node-postgres.com/) — 数据库驱动 -- [jose](https://github.com/panva/jose) — JWT 会话(httpOnly Cookie) -- [bcryptjs](https://github.com/dcodeIO/bcryptjs) — 密码哈希 -- [nodemailer](https://nodemailer.com/) — SMTP 邮件通知(可选) - [pnpm](https://pnpm.io/) — 包管理器 -## 功能 - -- 展示型页面:首页、工作室、作品集、动态资讯、工具箱、联系 -- 用户系统:注册 / 登录 / 登出(JWT + httpOnly Cookie,密码 bcrypt 哈希) -- 联系表单:留言入库 PostgreSQL,可选 SMTP 邮件通知 -- 资讯订阅:邮箱订阅入库(唯一约束防重复),可选 SMTP 通知 -- 国际化:中/英双语,默认中文 - ## 本地开发 ### 环境要求 - Node.js ≥ 20(推荐 22,与 Docker 构建镜像一致) - pnpm ≥ 9 -- Docker(用于本地 PostgreSQL,或自行提供 PostgreSQL 16+) ### 安装与启动 @@ -40,13 +28,10 @@ # 1. 安装依赖 pnpm install -# 2. 启动本地数据库(PostgreSQL 16,映射宿主机 5433 端口) -docker compose up -d postgres - -# 3. 配置环境变量(可写入 .env 文件,已被 .gitignore 忽略) +# 2. 配置环境变量(可选,SMTP 未配置时联系/订阅仍会真实落库) cp .env.example .env -# 4. 启动开发服务器(默认 http://localhost:3000) +# 3. 启动开发服务器(默认 http://localhost:3000) pnpm dev ``` @@ -58,107 +43,110 @@ pnpm dev | --- | --- | | `pnpm dev` | 启动开发服务器 | | `pnpm build` | 构建生产版本(生成 `.output/`) | -| `pnpm generate` | 静态站点生成(输出到 `dist/`,注意:Server API 需要 Node 运行时不支持静态生成) | +| `pnpm generate` | 静态站点生成(输出到 `dist/`) | | `pnpm preview` | 本地预览生产构建 | | `pnpm start` | 以 Node 方式启动 `.output/server/index.mjs` | -## 环境变量 +## 功能一览 -所有变量均可通过 `.env` 文件或系统环境变量注入,Nuxt 自动读取 `NUXT_*` 前缀: +| 模块 | 说明 | +| --- | --- | +| 页面 | 首页、工作室、作品(列表/详情)、动态(列表/详情)、工具箱、联系、个人中心 | +| **后台管理** | `/admin`:Dashboard、动态/作品增删改(双语 CMS)、用户/评论/联系/订阅管理、图片管理(OSS)、操作审计日志、**站点动态配置** | +| **动态配置** | 站点信息/联系方式/社交链接/工具箱/页脚文案/SEO 均可在 `/admin/settings` 后台修改,前台即时生效 | +| **文件存储** | 图片上传/管理使用 OSS(RustFS,S3 v4 兼容,桶 `arcticnewone`),经 `/uploads` 代理服务 | +| 用户系统 | 注册/登录/登出、修改密码、自助删除账号、预置 admin;个人中心(资料/收藏/评论) | +| 交互 | 作品收藏、新闻评论、分享(X/LinkedIn/复制链接)、搜索、加载更多 | +| 国际化 | 中/英双语,Header 一键切换;内容双语存于数据库 | +| SEO | 动态 `sitemap.xml`/`robots.txt`/`feed.xml`(RSS)、JSON-LD、canonical、`og-image.png` | +| 工程 | `pnpm test`(vitest:密码/SigV4/校验器/种子/配置 17 例) | -| 变量 | 必填 | 默认值 | 说明 | -| --- | --- | --- | --- | -| `NUXT_DATABASE_URL` | ✅ | — | PostgreSQL 连接串,如 `postgres://user:pass@localhost:5433/arcticnewone` | -| `NUXT_JWT_SECRET` | ✅(生产) | 开发默认值 | JWT 签名密钥,生产必须设置为随机长字符串(`openssl rand -hex 32`) | -| `NUXT_SMTP_HOST` | 否 | — | SMTP 服务器地址(配置后联系表单/订阅会发邮件通知) | -| `NUXT_SMTP_PORT` | 否 | 465 | SMTP 端口 | -| `NUXT_SMTP_USER` | 否 | — | SMTP 用户名 | -| `NUXT_SMTP_PASS` | 否 | — | SMTP 密码 | -| `NUXT_SMTP_FROM` | 否 | — | 发件人,如 `北极新一 ` | -| `NUXT_SMTP_CONTACT_TO` | 否 | SMTP_USER | 收件人(联系表单与订阅通知发往此邮箱) | -| `POSTGRES_PASSWORD` | 仅 compose | `arcticnewone_dev_password` | docker-compose 中数据库密码(本地开发) | +> **预置管理员**:首次部署设置 `ADMIN_INITIAL_PASSWORD`(或由 `deploy.sh` 自动生成并打印)会自动创建 `admin` 账号,登录后访问 `/admin` 管理内容与配置。 -SMTP 未配置时,联系表单与订阅**仍然正常入库**,只是不发送邮件通知。 +### 环境变量(详见 `.env.example`,Nuxt runtimeConfig 使用 `NUXT_` 前缀) -## Server API +| 变量 | 说明 | +| --- | --- | +| `NUXT_PUBLIC_SITE_URL` | 站点公开地址(sitemap/robots/og 绝对链接) | +| `NUXT_SESSION_SECRET` | 会话安全密钥(生产必须设置强随机值) | +| `NUXT_DB_PATH` | 数据库文件路径(默认生产 `/data/arcticnewone.db`,开发 `.data/`) | +| `NUXT_SMTP_HOST/PORT/USER/PASS/FROM` | SMTP 邮件服务(可选) | +| `NUXT_CONTACT_TO` | 联系表单留言收件邮箱 | +| `NUXT_ADMIN_EMAILS` | 管理员邮箱(逗号分隔),命中者个人中心可见管理面板 | +| `NUXT_ADMIN_INITIAL_PASSWORD` | 预置管理员初始密码(仅首次初始化创建 admin 账号用) | +| `NUXT_OSS_ENDPOINT/ACCESS_KEY/SECRET_KEY/BUCKET/REGION/PUBLIC_BASE` | OSS 文件存储(RustFS / S3 v4,凭据仅走 Secret,不写入仓库) | -项目内置 Nitro Server API(`server/` 目录),应用启动时自动建表(幂等): - -| 接口 | 方法 | 说明 | -| --- | --- | --- | -| `/api/auth/register` | POST | 注册(用户名/邮箱唯一校验,成功即自动登录) | -| `/api/auth/login` | POST | 登录(支持用户名/邮箱/手机号 + 密码) | -| `/api/auth/logout` | POST | 登出(清除 Cookie) | -| `/api/auth/me` | GET | 从 Cookie 恢复当前用户 | -| `/api/contact` | POST | 提交联系表单(入库 + 可选邮件通知) | -| `/api/newsletter/subscribe` | POST | 邮箱订阅资讯(入库,重复订阅返回 409) | - -错误响应统一返回 `{ statusMessage: '' }`,前端按错误码显示对应语言的文案。 +> `deploy.sh` 中的对外变量名(`SESSION_SECRET`/`SMTP_*`/`CONTACT_TO`/`ADMIN_EMAILS`/`ADMIN_INITIAL_PASSWORD`/`OSS_*`)会在写入 K8s Secret 时自动加 `NUXT_` 前缀。 ## 项目结构 ```text . ├── app/ # 应用源码(Nuxt 4 约定目录) -│ ├── app.vue # 应用入口(全局 SEO / Meta) -│ ├── assets/ # 静态资源(样式、图片等) -│ ├── components/ # 组件(common / home / layouts) -│ ├── composables/ # 组合式函数 -│ ├── layouts/ # 布局 -│ ├── pages/ # 页面(首页、工作室、作品、动态、工具、联系) -│ ├── plugins/ # 插件(如 Lenis 平滑滚动) -│ ├── stores/ # Pinia 状态(user / app) -│ └── types/ # 类型定义 -├── server/ # Nitro Server API(后端) -│ ├── api/ # 接口(auth / contact / newsletter) -│ ├── db/ # PostgreSQL 连接池 + Schema -│ ├── plugins/ # 启动插件(自动建表) -│ └── utils/ # JWT 认证、校验、邮件工具 -├── i18n/ -│ └── locales/ # 国际化文案(zh.json / en.json) -├── public/ # 公开静态文件(favicon、robots.txt 等) -├── Dockerfile # 容器镜像构建 -├── deploy/ # 生产部署配置(Kubernetes Deployment/Service/Ingress/PostgreSQL) -├── docker-compose.yml # 本地容器编排(应用 + PostgreSQL) -├── nuxt.config.ts # Nuxt 配置(模块、i18n、runtimeConfig 等) -├── tailwind.config.js # Tailwind 配置 -└── package.json # 项目依赖与脚本 +│ ├── app.vue # 应用入口(全局 SEO / Meta / JSON-LD) +│ ├── config/ # 站点配置(品牌、邮箱、社交链接) +│ ├── pages/ # 页面(含 account.vue 个人中心、admin/ 后台管理) +│ ├── components/ # 组件(common / home / layouts / admin) +│ ├── stores/ # Pinia 状态(用户、认证弹窗) +│ └── ... +├── server/ # Nitro 后端(utils 数据/鉴权/邮件 + api 内容/后台 + sitemap/robots + uploads) +├── i18n/locales/ # 国际化文案(zh.json / en.json) +├── scripts/ # 工具脚本(generate-og.mjs 生成分享图) +├── public/ # 公开静态文件 +├── deploy/ # 生产部署配置(K8s) +├── deploy.sh # 一条命令部署 / 升级 +├── build-and-push.sh # 版本化镜像构建推送(SWR) +└── Dockerfile ``` -## 构建与部署 +## 构建与部署(一条命令) -构建并推送镜像: +镜像版本取自 git tag(如 `0.0.1-dev` → `:0.0.1-dev`,同时更新 `:latest`),构建后推送华为云 SWR。 + +> SWR 兼容性:华为云 SWR 无法解析 Docker manifest list(多架构合并会报 `Invalid image`), +> 因此版本 tag 与 `latest` 以 **amd64 单架构 manifest** 输出(生产集群为 amd64); +> 同时分架构推送 `-amd64`/`-arm64` 标签,arm64 环境可按需使用。 ```bash -./build-and-push.sh +# 1. 打版本标签 +git add -A && git commit -m "release: 0.0.1-dev" +git tag 0.0.1-dev + +# 2. 设置环境变量(凭据绝不写入仓库) +export SWR_REGISTRY="swr.cn-north-4.myhuaweicloud.com" +export SWR_NAMESPACE="virtheart" +export SWR_USERNAME="<用户名>" +export SWR_PASSWORD="<密码>" +# 可选:export SESSION_SECRET="$(openssl rand -hex 32)" / SMTP_* / CONTACT_TO / ADMIN_EMAILS + +# 3. 一条命令:构建镜像 + 推送 + 更新集群 + 滚动升级 +./deploy.sh 0.0.1-dev # 不带参数则自动取最新 git tag ``` -脚本从环境变量读取 SWR 凭据(`SWR_REGISTRY`、`SWR_NAMESPACE`、`SWR_USERNAME`、`SWR_PASSWORD`), -多架构(`linux/amd64,linux/arm64`)一步构建并推送到华为云 SWR(`--output` 使用 `oci-mediatypes=false` 输出 Docker V2 manifest,SWR 可正常解析)。 +`deploy.sh` 自动完成:构建推送版本化镜像 → 注入 Secret(会话密钥/SMTP/管理员)与 ConfigMap(站点地址/DB 路径)→ `kubectl apply`(namespace/PVC/Deployment/Service/Ingress)→ 等待滚动更新 → 健康检查。 -Dockerfile 基础镜像使用国内可访问的 DaoCloud 镜像源(`docker.m.daocloud.io/library/node:22-alpine`,Docker Hub 在国内不可达)。 - -本地一键启动(应用 + PostgreSQL,与生产一致): +### 仅构建镜像(不部署) ```bash -docker compose up -d +./build-and-push.sh # 版本取最新 git tag +./build-and-push.sh 0.0.1-dev # 显式指定版本 ``` -生产部署使用 `deploy/` 目录下的 Kubernetes 配置(Deployment / Service / Ingress / 可选 PostgreSQL), -镜像统一推送到华为云 SWR(`swr.cn-north-4.myhuaweicloud.com/virtheart/arcticnewone:latest`), -部署、Secret 创建与回滚步骤见 [deploy/README.md](deploy/README.md)。 +### 生产部署说明 + +- 域名 `personal.virtheart.com`,Traefik Ingress + cert-manager 自动签发证书 +- SQLite 数据持久化在 PVC `arcticnewone-data`(挂载 `/data`),Pod 升级/重启不丢数据 +- 回滚:`kubectl rollout undo deployment/arcticnewone -n arcticnewone` +- 详见 [deploy/README.md](deploy/README.md) ## 国际化(i18n) -项目使用 `@nuxtjs/i18n` 实现中/英双语: - - 语言文件位于 `i18n/locales/`:`zh.json`(中文)、`en.json`(英文) -- 默认语言为中文(`defaultLocale: 'zh'`),URL 不包含语言前缀(`strategy: 'no_prefix'`),不自动探测浏览器语言 -- 组件中通过 `useI18n()` 的 `t()` 方法读取文案,例如 `t('nav.home')` -- 服务端错误码与文案键一一对应(如 `auth.emailTaken`),新增接口错误时需同步添加中英文键 - -新增文案时,在 `zh.json` 和 `en.json` 中同步添加对应键即可。 +- 默认语言为中文(`defaultLocale: 'zh'`),URL 不包含语言前缀(`strategy: 'no_prefix'`),Header 提供中/EN 切换 +- 组件中通过 `useI18n()` 的 `t()` 方法读取文案;新增文案时同步更新两个语言文件(可用根目录脚本校验键对齐) ## 说明 -本项目不含任何密钥或敏感信息;本地环境变量请使用 `.env` 文件(已被 `.gitignore` 忽略)。 +- 本项目不含任何密钥或敏感信息;本地环境变量请使用 `.env` 文件(已被 `.gitignore` 忽略) +- 联系/订阅依赖 SMTP:未配置时数据仍真实写入数据库,仅在管理面板可见但不会发邮件 +- 社交链接为品牌占位地址(`app/config/site.ts`),正式上线前请替换为真实账号 diff --git a/app/app.vue b/app/app.vue index 976880d..9d71d37 100755 --- a/app/app.vue +++ b/app/app.vue @@ -1,29 +1,56 @@ diff --git a/app/components/admin/AdminBadge.vue b/app/components/admin/AdminBadge.vue new file mode 100644 index 0000000..1a4b540 --- /dev/null +++ b/app/components/admin/AdminBadge.vue @@ -0,0 +1,22 @@ + + + diff --git a/app/components/admin/AdminBlockEditor.vue b/app/components/admin/AdminBlockEditor.vue new file mode 100644 index 0000000..9091473 --- /dev/null +++ b/app/components/admin/AdminBlockEditor.vue @@ -0,0 +1,130 @@ + + + diff --git a/app/components/admin/AdminButton.vue b/app/components/admin/AdminButton.vue new file mode 100644 index 0000000..f71384a --- /dev/null +++ b/app/components/admin/AdminButton.vue @@ -0,0 +1,40 @@ + + + diff --git a/app/components/admin/AdminCard.vue b/app/components/admin/AdminCard.vue new file mode 100644 index 0000000..8c4528b --- /dev/null +++ b/app/components/admin/AdminCard.vue @@ -0,0 +1,16 @@ + + + diff --git a/app/components/admin/AdminConfirm.vue b/app/components/admin/AdminConfirm.vue new file mode 100644 index 0000000..e6f977c --- /dev/null +++ b/app/components/admin/AdminConfirm.vue @@ -0,0 +1,27 @@ + + + diff --git a/app/components/admin/AdminConfirmDialog.vue b/app/components/admin/AdminConfirmDialog.vue new file mode 100644 index 0000000..2188d9a --- /dev/null +++ b/app/components/admin/AdminConfirmDialog.vue @@ -0,0 +1,88 @@ + + + + + diff --git a/app/components/admin/AdminEmptyState.vue b/app/components/admin/AdminEmptyState.vue new file mode 100644 index 0000000..be1da50 --- /dev/null +++ b/app/components/admin/AdminEmptyState.vue @@ -0,0 +1,17 @@ + + + diff --git a/app/components/admin/AdminImageUpload.vue b/app/components/admin/AdminImageUpload.vue new file mode 100644 index 0000000..7864f6b --- /dev/null +++ b/app/components/admin/AdminImageUpload.vue @@ -0,0 +1,86 @@ + + + diff --git a/app/components/admin/AdminInput.vue b/app/components/admin/AdminInput.vue new file mode 100644 index 0000000..0dd329f --- /dev/null +++ b/app/components/admin/AdminInput.vue @@ -0,0 +1,32 @@ + + + diff --git a/app/components/admin/AdminModal.vue b/app/components/admin/AdminModal.vue new file mode 100644 index 0000000..667bae9 --- /dev/null +++ b/app/components/admin/AdminModal.vue @@ -0,0 +1,55 @@ + + + + + diff --git a/app/components/admin/AdminPageHeader.vue b/app/components/admin/AdminPageHeader.vue new file mode 100644 index 0000000..ce26a0f --- /dev/null +++ b/app/components/admin/AdminPageHeader.vue @@ -0,0 +1,13 @@ + + + diff --git a/app/components/admin/AdminPagination.vue b/app/components/admin/AdminPagination.vue new file mode 100644 index 0000000..7d914bf --- /dev/null +++ b/app/components/admin/AdminPagination.vue @@ -0,0 +1,20 @@ + + + diff --git a/app/components/admin/AdminSelect.vue b/app/components/admin/AdminSelect.vue new file mode 100644 index 0000000..f618b49 --- /dev/null +++ b/app/components/admin/AdminSelect.vue @@ -0,0 +1,25 @@ + + + diff --git a/app/components/admin/AdminSidebar.vue b/app/components/admin/AdminSidebar.vue new file mode 100644 index 0000000..5af8112 --- /dev/null +++ b/app/components/admin/AdminSidebar.vue @@ -0,0 +1,107 @@ + + + diff --git a/app/components/admin/AdminSkeleton.vue b/app/components/admin/AdminSkeleton.vue new file mode 100644 index 0000000..917fb42 --- /dev/null +++ b/app/components/admin/AdminSkeleton.vue @@ -0,0 +1,11 @@ + + + diff --git a/app/components/admin/AdminTextarea.vue b/app/components/admin/AdminTextarea.vue new file mode 100644 index 0000000..3d7916b --- /dev/null +++ b/app/components/admin/AdminTextarea.vue @@ -0,0 +1,31 @@ + + + diff --git a/app/components/common/FavoriteButton.vue b/app/components/common/FavoriteButton.vue new file mode 100644 index 0000000..e1c3d0f --- /dev/null +++ b/app/components/common/FavoriteButton.vue @@ -0,0 +1,71 @@ + + + diff --git a/app/components/common/LoginModal.vue b/app/components/common/LoginModal.vue index e13f6ed..d83a5cc 100644 --- a/app/components/common/LoginModal.vue +++ b/app/components/common/LoginModal.vue @@ -2,7 +2,7 @@
@@ -35,7 +35,8 @@ v-model="account" type="text" required - :disabled="isLoggingIn" + 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')" /> @@ -50,7 +51,8 @@ v-model="password" type="password" required - :disabled="isLoggingIn" + 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')" /> @@ -64,21 +66,21 @@ -

+

{{ t('auth.noAccount') }} -

@@ -93,86 +95,60 @@ 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() -interface Props { - isOpen: boolean -} - -const props = defineProps() -const emit = defineEmits<{ - close: [] - switchToRegister: [] -}>() - -const modalRef = ref(null) const account = ref('') const password = ref('') -const isLoggingIn = ref(false) +const isSubmitting = ref(false) const errorMessage = ref('') -// 关闭模态框 const closeModal = () => { - if (!isLoggingIn.value) { - emit('close') + if (!isSubmitting.value) { + authModal.closeAll() } } -// 切换到注册 -const switchToRegister = () => { - emit('switchToRegister') -} - -// 处理登录 -const handleLogin = async () => { - if (isLoggingIn.value) return - - isLoggingIn.value = true - errorMessage.value = '' - - try { - const result = await userStore.login(account.value, password.value) - - if (result.success) { - // 登录成功,关闭模态框 +// 打开时重置表单 +watch( + () => authModal.isLoginOpen, + (open) => { + if (open) { account.value = '' password.value = '' - closeModal() - } else { - errorMessage.value = t(result.error) + errorMessage.value = '' } - } catch (error) { - console.error('Login error:', error) - errorMessage.value = t('auth.loginError') - } finally { - isLoggingIn.value = false - } -} + }, +) -// 监听打开状态,重置表单 -watch(() => props.isOpen, (isOpen) => { - if (isOpen) { +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 = '' - errorMessage.value = '' - // 禁止背景滚动 - document.body.style.overflow = 'hidden' + authModal.closeAll() } else { - // 恢复滚动 - document.body.style.overflow = '' + errorMessage.value = apiError({ data: { code: result.code } }) } -}) + isSubmitting.value = false +} -// ESC 键关闭 +// ESC 关闭 const handleKeydown = (e: KeyboardEvent) => { - if (e.key === 'Escape' && props.isOpen) { + if (e.key === 'Escape' && authModal.isLoginOpen) { closeModal() } } - -// 添加键盘事件监听 if (typeof window !== 'undefined') { window.addEventListener('keydown', handleKeydown) } diff --git a/app/components/common/RegisterModal.vue b/app/components/common/RegisterModal.vue index 85e17ff..c2c94fc 100644 --- a/app/components/common/RegisterModal.vue +++ b/app/components/common/RegisterModal.vue @@ -2,7 +2,7 @@
@@ -35,7 +35,8 @@ v-model="username" type="text" required - :disabled="isRegistering" + 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.usernamePlaceholder')" /> @@ -50,7 +51,8 @@ v-model="email" type="email" required - :disabled="isRegistering" + autocomplete="email" + :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.emailPlaceholder')" /> @@ -64,7 +66,8 @@ id="reg-phone" v-model="phone" type="tel" - :disabled="isRegistering" + autocomplete="tel" + :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.phonePlaceholder')" /> @@ -79,7 +82,8 @@ v-model="password" type="password" required - :disabled="isRegistering" + autocomplete="new-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')" /> @@ -94,7 +98,8 @@ v-model="confirmPassword" type="password" required - :disabled="isRegistering" + autocomplete="new-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.confirmPasswordPlaceholder')" /> @@ -113,21 +118,21 @@

{{ t('auth.alreadyHaveAccount') }} -

@@ -142,122 +147,89 @@ 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() -interface Props { - isOpen: boolean -} - -const props = defineProps() -const emit = defineEmits<{ - close: [] - switchToLogin: [] -}>() - -const modalRef = ref(null) const username = ref('') const email = ref('') const phone = ref('') const password = ref('') const confirmPassword = ref('') -const isRegistering = ref(false) +const isSubmitting = ref(false) const errorMessage = ref('') const successMessage = ref('') -// 关闭模态框 const closeModal = () => { - if (!isRegistering.value) { - emit('close') + if (!isSubmitting.value) { + authModal.closeAll() } } -// 切换到登录 -const switchToLogin = () => { - emit('switchToLogin') -} - -// 处理注册 -const handleRegister = async () => { - if (isRegistering.value) return - - // 验证密码匹配 - if (password.value !== confirmPassword.value) { - errorMessage.value = t('auth.passwordMismatch') - return - } - - // 验证手机号格式(如果填写了) - if (phone.value && !/^1[3-9]\d{9}$/.test(phone.value)) { - errorMessage.value = t('auth.invalidPhone') - return - } - - isRegistering.value = true - errorMessage.value = '' - successMessage.value = '' - - try { - const result = await userStore.register({ - username: username.value, - email: email.value, - phone: phone.value, - password: password.value - }) - - if (result.success) { - // 注册成功 - successMessage.value = t('auth.registerSuccess') - - // 清空表单 +// 打开时重置表单 +watch( + () => authModal.isRegisterOpen, + (open) => { + if (open) { username.value = '' email.value = '' phone.value = '' password.value = '' confirmPassword.value = '' - - // 2秒后关闭并自动登录 - setTimeout(() => { - closeModal() - }, 2000) - } else { - errorMessage.value = t(result.error) + errorMessage.value = '' + successMessage.value = '' } - } catch (error) { - console.error('Register error:', error) - errorMessage.value = t('auth.registerError') - } finally { - isRegistering.value = false - } -} + }, +) -// 监听打开状态,重置表单 -watch(() => props.isOpen, (isOpen) => { - if (isOpen) { +const handleRegister = async () => { + if (isSubmitting.value) return + errorMessage.value = '' + successMessage.value = '' + + if (password.value !== confirmPassword.value) { + errorMessage.value = t('auth.passwordMismatch') + return + } + if (phone.value && !/^1[3-9]\d{9}$/.test(phone.value)) { + errorMessage.value = t('auth.invalidPhone') + return + } + + isSubmitting.value = true + const result = await userStore.register({ + username: username.value, + email: email.value, + phone: phone.value, + password: password.value, + }) + + if (result.success) { + successMessage.value = t('auth.registerSuccess') username.value = '' email.value = '' phone.value = '' password.value = '' confirmPassword.value = '' - errorMessage.value = '' - successMessage.value = '' - // 禁止背景滚动 - document.body.style.overflow = 'hidden' + setTimeout(() => { + authModal.closeAll() + }, 1500) } else { - // 恢复滚动 - document.body.style.overflow = '' + errorMessage.value = apiError({ data: { code: result.code } }) } -}) + isSubmitting.value = false +} -// ESC 键关闭 +// ESC 关闭 const handleKeydown = (e: KeyboardEvent) => { - if (e.key === 'Escape' && props.isOpen) { + if (e.key === 'Escape' && authModal.isRegisterOpen) { closeModal() } } - -// 添加键盘事件监听 if (typeof window !== 'undefined') { window.addEventListener('keydown', handleKeydown) } diff --git a/app/components/home/HomePartnersWork.vue b/app/components/home/HomePartnersWork.vue index ed9d80b..3f61ae7 100755 --- a/app/components/home/HomePartnersWork.vue +++ b/app/components/home/HomePartnersWork.vue @@ -1,19 +1,31 @@ @@ -210,7 +213,7 @@ onUnmounted(() => {
@@ -219,7 +222,7 @@ onUnmounted(() => {

{{ t('home.work.title') }} - ({{ workItems.length }}) + ({{ works.length }})

@@ -235,29 +238,29 @@ onUnmounted(() => {
-
- -
-

- {{ t(item.titleKey) }} -

-

- {{ item.year }} © -

-
-
+ + +
+

+ {{ locText(item.titleZh, item.titleEn) }} +

+

+ {{ item.year }} © +

+
+
diff --git a/app/components/home/HomeTechStack.vue b/app/components/home/HomeTechStack.vue index 617eea6..a7738b0 100644 --- a/app/components/home/HomeTechStack.vue +++ b/app/components/home/HomeTechStack.vue @@ -15,7 +15,7 @@ v-for="(tech, index) in technologies" :key="tech.id" :ref="el => setTechRef(el, index)" - class="tech-tag absolute flex items-center gap-3 px-5 py-3 bg-white rounded-full shadow-lg border-2 cursor-pointer hover:scale-110 transition-transform duration-300" + class="tech-tag absolute flex items-center gap-3 px-5 py-3 bg-white rounded-full shadow-lg border-2 hover:scale-110 transition-transform duration-300" :class="tech.borderColor" :style="getTechStyle(index)" > diff --git a/app/components/home/HomeUpdates.vue b/app/components/home/HomeUpdates.vue index 5dfe25d..a15c38d 100644 --- a/app/components/home/HomeUpdates.vue +++ b/app/components/home/HomeUpdates.vue @@ -13,11 +13,12 @@
-
- {{ t(`home.updates.categories.${item.category}`) }} + {{ t(`news.categories.${item.category}`) }}

- {{ t(`home.updates.items.${item.id}.title`) }} + {{ locText(item.titleZh, item.titleEn) }}

- {{ t(`home.updates.items.${item.id}.description`) }} + {{ locText(item.excerptZh, item.excerptEn) }}

- {{ item.date }} + {{ formatNewsDate(item.date, locale) }}
-
+
@@ -69,14 +70,24 @@ diff --git a/app/layouts/admin.vue b/app/layouts/admin.vue new file mode 100644 index 0000000..5ab8a1b --- /dev/null +++ b/app/layouts/admin.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/app/middleware/admin.ts b/app/middleware/admin.ts new file mode 100644 index 0000000..db48bae --- /dev/null +++ b/app/middleware/admin.ts @@ -0,0 +1,23 @@ +import { defineNuxtRouteMiddleware, navigateTo } from '#app' +import { useUserStore } from '~/stores/user' +import { useAuthModalStore } from '~/stores/authModal' + +/** + * 后台路由守卫(/admin/**):仅管理员可访问。 + * - SSR 不拦截(真实防护在 admin API 的 requireAdmin); + * - 客户端依据已恢复的会话判定,未登录则弹出登录框并回退,非管理员回首页。 + */ +export default defineNuxtRouteMiddleware(() => { + if (import.meta.server) return + + const userStore = useUserStore() + + if (!userStore.isAuthenticated) { + const authModal = useAuthModalStore() + authModal.openLogin() + return navigateTo('/account') + } + if (userStore.user?.role !== 'admin') { + return navigateTo('/') + } +}) diff --git a/app/pages/account.vue b/app/pages/account.vue new file mode 100644 index 0000000..5f4da4e --- /dev/null +++ b/app/pages/account.vue @@ -0,0 +1,533 @@ + + + + + diff --git a/app/pages/admin/audit.vue b/app/pages/admin/audit.vue new file mode 100644 index 0000000..2c8d59a --- /dev/null +++ b/app/pages/admin/audit.vue @@ -0,0 +1,260 @@ + + + diff --git a/app/pages/admin/comments.vue b/app/pages/admin/comments.vue new file mode 100644 index 0000000..df455e8 --- /dev/null +++ b/app/pages/admin/comments.vue @@ -0,0 +1,353 @@ + + + diff --git a/app/pages/admin/contacts.vue b/app/pages/admin/contacts.vue new file mode 100644 index 0000000..812b655 --- /dev/null +++ b/app/pages/admin/contacts.vue @@ -0,0 +1,359 @@ + + + diff --git a/app/pages/admin/index.vue b/app/pages/admin/index.vue new file mode 100644 index 0000000..4ac1f3a --- /dev/null +++ b/app/pages/admin/index.vue @@ -0,0 +1,321 @@ + + + diff --git a/app/pages/admin/news.vue b/app/pages/admin/news.vue new file mode 100644 index 0000000..6777f1a --- /dev/null +++ b/app/pages/admin/news.vue @@ -0,0 +1,482 @@ + + + diff --git a/app/pages/admin/settings.vue b/app/pages/admin/settings.vue new file mode 100644 index 0000000..2d7963e --- /dev/null +++ b/app/pages/admin/settings.vue @@ -0,0 +1,260 @@ + + + diff --git a/app/pages/admin/subscribers.vue b/app/pages/admin/subscribers.vue new file mode 100644 index 0000000..bb2e3dc --- /dev/null +++ b/app/pages/admin/subscribers.vue @@ -0,0 +1,338 @@ + + + diff --git a/app/pages/admin/uploads.vue b/app/pages/admin/uploads.vue new file mode 100644 index 0000000..d7427d6 --- /dev/null +++ b/app/pages/admin/uploads.vue @@ -0,0 +1,225 @@ + + + diff --git a/app/pages/admin/users.vue b/app/pages/admin/users.vue new file mode 100644 index 0000000..457b915 --- /dev/null +++ b/app/pages/admin/users.vue @@ -0,0 +1,335 @@ + + + diff --git a/app/pages/admin/work.vue b/app/pages/admin/work.vue new file mode 100644 index 0000000..0850330 --- /dev/null +++ b/app/pages/admin/work.vue @@ -0,0 +1,640 @@ + + + diff --git a/app/pages/contact.vue b/app/pages/contact.vue index 4079e92..7d72de1 100755 --- a/app/pages/contact.vue +++ b/app/pages/contact.vue @@ -139,7 +139,7 @@
@@ -193,14 +193,16 @@