mirror of
https://github.com/sunniejs/vue-h5-template.git
synced 2026-12-02 13:53:47 +08:00
docs: add commerce backend and Japanese guides
This commit is contained in:
parent
f8280fc05c
commit
e94b85de04
@ -10,6 +10,8 @@ const zhSidebar = [
|
||||
{ text: "项目介绍", link: "/guide/" },
|
||||
{ text: "快速开始", link: "/guide/start" },
|
||||
{ text: "项目架构", link: "/guide/architecture" },
|
||||
{ text: "后端服务与联调", link: "/guide/backend" },
|
||||
{ text: "商城示例", link: "/guide/commerce" },
|
||||
{ text: "环境与构建", link: "/guide/environment" },
|
||||
{ text: "请求与鉴权", link: "/guide/request" },
|
||||
{ text: "状态管理", link: "/guide/state-management" },
|
||||
@ -31,6 +33,8 @@ const enSidebar = [
|
||||
{ text: "Introduction", link: "/en/guide/" },
|
||||
{ text: "Getting Started", link: "/en/guide/start" },
|
||||
{ text: "Architecture", link: "/en/guide/architecture" },
|
||||
{ text: "Backend Integration", link: "/en/guide/backend" },
|
||||
{ text: "Commerce Example", link: "/en/guide/commerce" },
|
||||
{ text: "Environment & Build", link: "/en/guide/environment" },
|
||||
{ text: "Requests & Auth", link: "/en/guide/request" },
|
||||
{ text: "State Management", link: "/en/guide/state-management" },
|
||||
@ -45,6 +49,29 @@ const enSidebar = [
|
||||
},
|
||||
];
|
||||
|
||||
const jaSidebar = [
|
||||
{
|
||||
text: "ガイド",
|
||||
items: [
|
||||
{ text: "プロジェクト紹介", link: "/ja/guide/" },
|
||||
{ text: "クイックスタート", link: "/ja/guide/start" },
|
||||
{ text: "アーキテクチャ", link: "/ja/guide/architecture" },
|
||||
{ text: "バックエンド連携", link: "/ja/guide/backend" },
|
||||
{ text: "コマース実装例", link: "/ja/guide/commerce" },
|
||||
{ text: "環境とビルド", link: "/ja/guide/environment" },
|
||||
{ text: "リクエストと認証", link: "/ja/guide/request" },
|
||||
{ text: "状態管理", link: "/ja/guide/state-management" },
|
||||
{ text: "AI Chat", link: "/ja/guide/ai-chat" },
|
||||
{ text: "UI フレームワーク", link: "/ja/guide/ui-framework" },
|
||||
{ text: "国際化", link: "/ja/guide/i18n" },
|
||||
{ text: "テスト", link: "/ja/guide/testing" },
|
||||
{ text: "デプロイ", link: "/ja/guide/deployment" },
|
||||
{ text: "v2 移行", link: "/ja/guide/migration-v2" },
|
||||
{ text: "コントリビューション", link: "/ja/guide/contributing" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default defineConfig({
|
||||
base: "/vue-h5-template/",
|
||||
cleanUrls: true,
|
||||
@ -102,5 +129,31 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
ja: {
|
||||
label: "日本語",
|
||||
lang: "ja-JP",
|
||||
link: "/ja/",
|
||||
title: "Vue H5 Template",
|
||||
description: "Vue 3、Vite 8、TypeScript によるモダンなモバイル H5 テンプレート",
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: "ガイド", link: "/ja/guide/" },
|
||||
{ text: "GitHub", link: repository },
|
||||
],
|
||||
sidebar: jaSidebar,
|
||||
outline: { label: "目次" },
|
||||
docFooter: { prev: "前へ", next: "次へ" },
|
||||
lastUpdated: { text: "最終更新" },
|
||||
editLink: {
|
||||
pattern: `${repository}/edit/docs/docs/:path`,
|
||||
text: "GitHub で編集",
|
||||
},
|
||||
socialLinks,
|
||||
footer: {
|
||||
message: "MIT License で公開",
|
||||
copyright: "Copyright © 2022-present Fonghehe",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
38
docs/en/guide/backend.md
Normal file
38
docs/en/guide/backend.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Backend Services and Local Integration
|
||||
|
||||
## Why there are two repositories
|
||||
|
||||
Backend workloads are split by runtime and scaling profile:
|
||||
|
||||
- `vue-h5-template-business-service`: Gin + PostgreSQL for login, profiles, projects, and product CRUD.
|
||||
- `vue-h5-template-ai-service`: FastAPI + Redis for AI providers, authenticated SSE, and quotas.
|
||||
|
||||
Their languages, dependencies, CI, and release cycles differ. They share a JWT contract but no source imports. The parent backend directory is local Compose orchestration, not a third repository. Each backend repository has Chinese, English, and Japanese guides on its `docs` branch.
|
||||
|
||||
## Start the complete stack
|
||||
|
||||
```bash
|
||||
cd /Users/fong/Workspace/personal/backend/vue-h5-template
|
||||
docker compose up --build -d
|
||||
docker compose ps
|
||||
|
||||
cd /Users/fong/Workspace/personal/frontend/vue/vue-h5-template/vue-h5-template
|
||||
pnpm install
|
||||
pnpm dev:integration
|
||||
```
|
||||
|
||||
Open the URL printed by Vite and sign in with `demo` / `demo1234`. `/shop` is public, `/shop/admin/products` provides authenticated administration, and `/ai/chat` streams through FastAPI.
|
||||
|
||||
```bash
|
||||
cd /Users/fong/Workspace/personal/backend/vue-h5-template
|
||||
SMOKE_BASE_URL=http://127.0.0.1:5173 python3 scripts/smoke.py
|
||||
```
|
||||
|
||||
The smoke test verifies the Vue proxy, Gin login and product CRUD, PostgreSQL persistence, and authenticated FastAPI streaming, then removes temporary records.
|
||||
|
||||
## PostgreSQL and DataGrip
|
||||
|
||||
Compose exposes PostgreSQL 17 on `localhost:5432`, database `vue_h5_business`, user `vue_h5`, password `vue_h5_local`. Create a PostgreSQL DataGrip source and install the official JDBC driver when prompted. Inspect `products`, `users`, `projects`, and `schema_migrations`. These credentials are local-only and must be replaced in production.
|
||||
|
||||
`docker compose stop` or `docker compose down` preserves the database volume. Run `docker compose down -v` only when you intentionally want irreversible local data removal.
|
||||
|
||||
20
docs/en/guide/commerce.md
Normal file
20
docs/en/guide/commerce.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Commerce Example
|
||||
|
||||
The store is a real server-state flow, not a button demo.
|
||||
|
||||
## Routes
|
||||
|
||||
- `/shop`: public catalog, keyword search, category filters, sorting, and infinite query.
|
||||
- `/shop/products/:id`: localized detail, quantity, and a safe-area purchase bar.
|
||||
- `/shop/admin/products`: authenticated admin search, create, edit, publication status, and soft deletion.
|
||||
|
||||
Reusable product presentation and editing live in `src/components/shop`. Endpoints stay in `src/api/modules/products.ts`. TanStack Query owns cache, cancellation, mutations, and invalidation; product server state never enters Pinia.
|
||||
|
||||
## Types and data
|
||||
|
||||
Product contracts are generated from `openapi/schema.yaml`. Money is stored as integer cents and rendered with `Intl.NumberFormat`. Names, subtitles, and descriptions require `zh-CN`, `en-US`, and `ja-JP`, and the current locale selects the display value.
|
||||
|
||||
Cover images allow same-origin paths or HTTPS only and fall back to a local placeholder. Admin deletion is soft deletion and the public API exposes only `on_sale` products.
|
||||
|
||||
`pnpm dev` uses `mock/index.ts`, so the full store works without Docker. `pnpm dev:integration` sends the same API module calls to Gin and persists data in PostgreSQL. Pages contain no environment-specific branches.
|
||||
|
||||
@ -28,9 +28,9 @@ cd /Users/fong/Workspace/personal/frontend/vue/vue-h5-template/vue-h5-template
|
||||
pnpm dev:integration
|
||||
```
|
||||
|
||||
Sign in with `demo / demo1234`. `.env.integration` sends `/api` to Gin on 8002 and gives the more specific `/api/ai` route to FastAPI on 8001. Run `python3 scripts/smoke.py` from the backend workspace to verify login, CRUD, and SSE through the Vue proxy.
|
||||
Sign in with `demo / demo1234`. `.env.integration` sends `/api` to Gin on 8002 and gives the more specific `/api/ai` route to FastAPI on 8001. Run `python3 scripts/smoke.py` from the backend workspace to verify login, product CRUD, PostgreSQL persistence, and SSE through the Vue proxy.
|
||||
|
||||
Gin defaults to SQLite with versions recorded in `schema_migrations`; production can select PostgreSQL with `DATABASE_DRIVER=postgres`. Both backends must share the JWT secret, issuer, and audience, while provider keys remain exclusively in FastAPI.
|
||||
Gin uses PostgreSQL 17 for local integration and production with versions recorded in `schema_migrations`; SQLite remains only for fast, isolated unit tests. Both backends must share the JWT secret, issuer, and audience, while provider keys remain exclusively in FastAPI.
|
||||
|
||||
## AI Streaming
|
||||
|
||||
|
||||
@ -15,11 +15,13 @@ Vite merges `.env` with the active mode file. `build/utils.ts` then converts fea
|
||||
| `VITE_USE_COMPRESS` | `false` | Generate Gzip assets |
|
||||
| `VITE_USE_REPORT` | `false` | Generate a bundle analysis report |
|
||||
| `VITE_USE_HTTPS` | `false` | Enable local HTTPS |
|
||||
| `VITE_USE_PWA` | `false` | Enable PWA support |
|
||||
| `VITE_PWA_ENABLED` | `false` | Enable PWA support |
|
||||
| `VITE_IMAGE_OPTIMIZE` | `false` | Optimize images in production builds only |
|
||||
| `VITE_UI_FRAMEWORK` | `vant` | Select Vant, NutUI, or Varlet at build time |
|
||||
|
||||
## Mock Mode
|
||||
|
||||
`.env.development` enables Mock by default. The example login request resolves to `/api/login`, which is handled by `mock/index.ts`.
|
||||
`.env.development` enables Mock by default. Login uses `/api/auth/login`; the catalog and administration use `/api/products` and `/api/admin/products`. `mock/index.ts` implements the same contracts.
|
||||
|
||||
## Use a Real Backend
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ pnpm check
|
||||
|
||||
Vitest and Vue Test Utils cover URL redirects, request errors, API modules, the user store, SSE parsing, the streaming composable, safe Markdown, Login Form, and Chat Composer. Core thresholds are 60% for lines/statements/functions and 50% branches; v2 currently reports 76.68% lines.
|
||||
|
||||
Playwright uses a Pixel 7 profile for Home, three-language switching, Login, Mock API, AI Streaming/Stop, and 401 Redirect. The backend workspace adds `scripts/smoke.py`, which verifies Gin login/Project CRUD and authenticated FastAPI SSE through the real Vue proxy.
|
||||
Playwright uses a Pixel 7 profile for Home, three-language switching, the shop catalog/detail flow, empty Login privacy checks, Mock API, AI Streaming/Stop, and 401 Redirect. The backend workspace adds `scripts/smoke.py`, which verifies Gin login/product CRUD, PostgreSQL, and authenticated FastAPI SSE through the real Vue proxy.
|
||||
|
||||
Backend gates are Ruff + mypy + pytest for FastAPI and `go test ./...` + `go vet ./...` for Gin. The backend workspace includes its own GitHub Actions workflow.
|
||||
|
||||
|
||||
57
docs/guide/backend.md
Normal file
57
docs/guide/backend.md
Normal file
@ -0,0 +1,57 @@
|
||||
# 后端服务与本地联调
|
||||
|
||||
## 为什么拆成两个仓库
|
||||
|
||||
后端按运行时和扩缩容特征拆分,适合分别发布到 GitHub:
|
||||
|
||||
- `vue-h5-template-business-service`:Gin + PostgreSQL,负责登录、用户、Project 与商品 CRUD。
|
||||
- `vue-h5-template-ai-service`:FastAPI + Redis,负责 AI Provider、鉴权 SSE 和限流。
|
||||
|
||||
两者语言、依赖、CI 和部署节奏不同。它们只共享 JWT 协议,不应互相导入代码。上层 `vue-h5-template` 目录仅作为本地 Compose 编排,不需要成为第三个仓库。两个后端仓库的 `docs` 分支均有中、英、日开发文档。
|
||||
|
||||
## 启动完整环境
|
||||
|
||||
```bash
|
||||
cd /Users/fong/Workspace/personal/backend/vue-h5-template
|
||||
docker compose up --build -d
|
||||
docker compose ps
|
||||
|
||||
cd /Users/fong/Workspace/personal/frontend/vue/vue-h5-template/vue-h5-template
|
||||
pnpm install
|
||||
pnpm dev:integration
|
||||
```
|
||||
|
||||
打开终端输出的地址,使用演示账号 `demo` / `demo1234`。`/shop` 是公开商城;登录后可进入 `/shop/admin/products`;`/ai/chat` 使用 FastAPI SSE。
|
||||
|
||||
端到端检查:
|
||||
|
||||
```bash
|
||||
cd /Users/fong/Workspace/personal/backend/vue-h5-template
|
||||
SMOKE_BASE_URL=http://127.0.0.1:5173 python3 scripts/smoke.py
|
||||
```
|
||||
|
||||
脚本验证 Vue 代理、Gin 登录与商品 CRUD、PostgreSQL 持久化,以及 FastAPI 鉴权 Streaming,并清理临时记录。
|
||||
|
||||
## PostgreSQL 与 DataGrip
|
||||
|
||||
Compose 默认启动 PostgreSQL 17,数据库连接是:
|
||||
|
||||
```text
|
||||
Host: localhost
|
||||
Port: 5432
|
||||
Database: vue_h5_business
|
||||
User: vue_h5
|
||||
Password: vue_h5_local
|
||||
```
|
||||
|
||||
在 DataGrip 新建 PostgreSQL 数据源并下载官方 JDBC Driver。通过 Schemas 面板可以查看 `products`、`users`、`projects` 和 `schema_migrations`。这些密码仅用于本地 Compose,生产必须更换。
|
||||
|
||||
## 停止与数据
|
||||
|
||||
```bash
|
||||
docker compose stop
|
||||
docker compose down
|
||||
```
|
||||
|
||||
上述命令不会删除 PostgreSQL Volume。只有明确需要清空本地数据时才执行 `docker compose down -v`,该操作不可恢复。
|
||||
|
||||
22
docs/guide/commerce.md
Normal file
22
docs/guide/commerce.md
Normal file
@ -0,0 +1,22 @@
|
||||
# 商城示例
|
||||
|
||||
商城不是按钮 Demo,而是一条真实 Server State 链路。
|
||||
|
||||
## 页面
|
||||
|
||||
- `/shop`:公开商品列表、关键词搜索、分类、排序和 Infinite Query。
|
||||
- `/shop/products/:id`:商品详情、数量、Safe Area 底部购买栏。
|
||||
- `/shop/admin/products`:登录且为 admin 后的商品查询、创建、编辑、上下架和软删除。
|
||||
|
||||
商品卡片与编辑器位于 `src/components/shop`,页面只负责路由级组合。业务接口集中在 `src/api/modules/products.ts`,缓存、取消、Mutation 与失效由 TanStack Query 管理,不进入 Pinia。
|
||||
|
||||
## 类型与数据
|
||||
|
||||
商品类型由 `openapi/schema.yaml` 生成。金额以整数分存储,避免浮点误差;展示时由 `Intl.NumberFormat` 格式化。名称、卖点和详情必须包含 `zh-CN`、`en-US` 与 `ja-JP`,切换语言后读取对应字段。
|
||||
|
||||
封面只允许同源路径或 HTTPS URL,异常值回退到本地占位图。后台删除使用软删除,公开 API 只展示 `on_sale` 商品。
|
||||
|
||||
## Mock 与真实后端
|
||||
|
||||
`pnpm dev` 使用 `mock/index.ts`,无需 Docker 即可浏览和编辑商品。`pnpm dev:integration` 把同一套 API 调用转发到 Gin,数据保存到 PostgreSQL。页面代码不包含环境条件分支。
|
||||
|
||||
@ -28,9 +28,9 @@ cd /Users/fong/Workspace/personal/frontend/vue/vue-h5-template/vue-h5-template
|
||||
pnpm dev:integration
|
||||
```
|
||||
|
||||
使用 `demo / demo1234` 登录。`.env.integration` 将 `/api` 转发到 Gin 8002,将 `/api/ai` 优先转发到 FastAPI 8001。后端目录的 `python3 scripts/smoke.py` 会通过 Vue 代理验证完整登录、CRUD 和 SSE 链路。
|
||||
使用 `demo / demo1234` 登录。`.env.integration` 将 `/api` 转发到 Gin 8002,将 `/api/ai` 优先转发到 FastAPI 8001。后端目录的 `python3 scripts/smoke.py` 会通过 Vue 代理验证登录、商品 CRUD、PostgreSQL 持久化和 SSE 链路。
|
||||
|
||||
Gin 本地默认 SQLite,并用 `schema_migrations` 保存版本;生产可通过 `DATABASE_DRIVER=postgres` 切换 PostgreSQL。两个后端必须共享 JWT secret、issuer 和 audience,供应商密钥只存在 FastAPI。
|
||||
Gin 的本地集成与生产默认使用 PostgreSQL 17,并用 `schema_migrations` 保存版本;SQLite 只保留给快速、隔离的单元测试。两个后端必须共享 JWT secret、issuer 和 audience,供应商密钥只存在 FastAPI。
|
||||
|
||||
## AI Streaming
|
||||
|
||||
|
||||
@ -15,11 +15,13 @@ Vite 会合并 `.env` 和当前模式文件,`build/utils.ts` 再将功能开
|
||||
| `VITE_USE_COMPRESS` | `false` | 生成 Gzip 文件 |
|
||||
| `VITE_USE_REPORT` | `false` | 生成构建产物分析报告 |
|
||||
| `VITE_USE_HTTPS` | `false` | 启用本地 HTTPS |
|
||||
| `VITE_USE_PWA` | `false` | 启用 PWA |
|
||||
| `VITE_PWA_ENABLED` | `false` | 启用 PWA |
|
||||
| `VITE_IMAGE_OPTIMIZE` | `false` | 仅在生产构建优化图片 |
|
||||
| `VITE_UI_FRAMEWORK` | `vant` | 构建期选择 Vant/NutUI/Varlet |
|
||||
|
||||
## Mock 模式
|
||||
|
||||
`.env.development` 默认启用 Mock。示例登录请求最终访问 `/api/login`,由 `mock/index.ts` 响应。
|
||||
`.env.development` 默认启用 Mock。登录请求访问 `/api/auth/login`,商品列表与管理访问 `/api/products` 和 `/api/admin/products`,均由 `mock/index.ts` 按真实契约响应。
|
||||
|
||||
## 连接真实后端
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ pnpm check
|
||||
|
||||
Vitest + Vue Test Utils 覆盖 URL/Redirect、请求错误、API modules、user Store、SSE parser、streaming composable、安全 Markdown、Login Form 和 Chat Composer。核心范围门槛为 lines/statements/functions 60%,branches 50%;v2 实测 lines 76.68%。
|
||||
|
||||
Playwright 使用 Pixel 7 配置覆盖 Home、三语言切换、Login、Mock API、AI Streaming/Stop 与 401 Redirect。后端工作区的 `scripts/smoke.py` 额外通过真实 Vue 代理验证 Gin 登录/Project CRUD 和 FastAPI 鉴权 SSE。
|
||||
Playwright 使用 Pixel 7 配置覆盖 Home、三语言切换、商城列表与详情、Login 空值隐私检查、Mock API、AI Streaming/Stop 与 401 Redirect。后端工作区的 `scripts/smoke.py` 额外通过真实 Vue 代理验证 Gin 登录/商品 CRUD、PostgreSQL 和 FastAPI 鉴权 SSE。
|
||||
|
||||
后端质量门禁分别为 FastAPI 的 Ruff + mypy + pytest,以及 Gin 的 `go test ./...` + `go vet ./...`。后端工作区自带独立 GitHub Actions 配置。
|
||||
|
||||
|
||||
10
docs/ja/guide/ai-chat.md
Normal file
10
docs/ja/guide/ai-chat.md
Normal file
@ -0,0 +1,10 @@
|
||||
# AI Chat と Streaming
|
||||
|
||||
フロントエンドは Provider 非依存の `ChatProvider` と `AsyncIterable<ChatChunk>` を使います。`FetchStreamChatProvider` が `POST /api/ai/chat` を呼び、`parseSseStream` が `start / delta / usage / done / error` を解析します。
|
||||
|
||||
`useStreamingChat` は Message、Streaming、Abort、Retry、Regenerate を管理します。Stop は `AbortController.abort()` を即時実行します。
|
||||
|
||||
Markdown は Raw HTML を無効にし、DOMPurify で再度 Sanitization します。AI HTML を信頼して `v-html` に直接渡してはいけません。大きい Syntax Highlighter は必要な Route で Dynamic Import します。
|
||||
|
||||
FastAPI は Gin JWT を検証し、Redis でユーザー単位に制限します。Provider Key は Backend だけに保存します。
|
||||
|
||||
14
docs/ja/guide/architecture.md
Normal file
14
docs/ja/guide/architecture.md
Normal file
@ -0,0 +1,14 @@
|
||||
# アーキテクチャ
|
||||
|
||||
```text
|
||||
views -> components / composables -> api modules / services -> transport / types
|
||||
main -> plugins / router / store
|
||||
build -> Vite plugins
|
||||
```
|
||||
|
||||
`api/client.ts` は Axios、Interceptor、Response 展開、`ApiError` だけを担当します。Domain Endpoint は `api/modules`、Framework 非依存 Provider は `services`、Vue Lifecycle は `composables` に配置します。
|
||||
|
||||
Route は明示的な `RouteRecordRaw` を維持します。現在の規模では Permission、Layout、title、KeepAlive、Lazy Chunk をレビューしやすく、File Routing を導入する利益より複雑性が大きいためです。
|
||||
|
||||
Pinia は Client State、TanStack Query は Server State、AI Conversation は `useStreamingChat` が管理します。3つの UI Framework を同一 Production Bundle に入れません。
|
||||
|
||||
21
docs/ja/guide/backend.md
Normal file
21
docs/ja/guide/backend.md
Normal file
@ -0,0 +1,21 @@
|
||||
# バックエンド連携
|
||||
|
||||
バックエンドは独立した2リポジトリです。
|
||||
|
||||
- `vue-h5-template-business-service`: Gin + PostgreSQL。認証、プロフィール、Project、商品 CRUD。
|
||||
- `vue-h5-template-ai-service`: FastAPI + Redis。AI Provider、認証付き SSE、レート制限。
|
||||
|
||||
親ディレクトリはローカル Compose 用で、第三の Git リポジトリにはしません。各サービスの `docs` ブランチにも中英日ガイドがあります。
|
||||
|
||||
```bash
|
||||
cd /Users/fong/Workspace/personal/backend/vue-h5-template
|
||||
docker compose up --build -d
|
||||
|
||||
cd /Users/fong/Workspace/personal/frontend/vue/vue-h5-template/vue-h5-template
|
||||
pnpm dev:integration
|
||||
```
|
||||
|
||||
デモアカウントは `demo` / `demo1234` です。DataGrip は Host `localhost`、Port `5432`、Database `vue_h5_business`、User `vue_h5`、Password `vue_h5_local` で接続できます。これはローカル専用です。
|
||||
|
||||
`SMOKE_BASE_URL=http://127.0.0.1:5173 python3 scripts/smoke.py` で Vue Proxy、Gin、PostgreSQL、FastAPI SSE をまとめて検証できます。
|
||||
|
||||
10
docs/ja/guide/commerce.md
Normal file
10
docs/ja/guide/commerce.md
Normal file
@ -0,0 +1,10 @@
|
||||
# コマース実装例
|
||||
|
||||
- `/shop`: 公開商品一覧、検索、カテゴリ、並び替え、Infinite Query。
|
||||
- `/shop/products/:id`: 3言語詳細、数量、Safe Area 対応購入バー。
|
||||
- `/shop/admin/products`: admin の商品作成、編集、公開状態、論理削除。
|
||||
|
||||
契約は OpenAPI から生成し、金額は整数の最小通貨単位で保存します。商品名、特徴、説明は `zh-CN`、`en-US`、`ja-JP` が必須です。画像 URL は同一 Origin または HTTPS だけを許可します。
|
||||
|
||||
`pnpm dev` は同じ契約の Mock、`pnpm dev:integration` は Gin/PostgreSQL を使います。Remote State は TanStack Query が管理し、Pinia には保存しません。
|
||||
|
||||
13
docs/ja/guide/contributing.md
Normal file
13
docs/ja/guide/contributing.md
Normal file
@ -0,0 +1,13 @@
|
||||
# コントリビューション
|
||||
|
||||
変更前に `AGENTS.md` を読み、Layer Boundary、API、State、UI、Test の規則に従ってください。Public Contract 変更は OpenAPI と生成 Type、三言語 Documentation を同期します。
|
||||
|
||||
```bash
|
||||
pnpm lint
|
||||
pnpm typecheck
|
||||
pnpm test
|
||||
pnpm build
|
||||
```
|
||||
|
||||
PR では Loading、Empty、Error、Offline、Abort、Safe Area、Keyboard、Accessibility、Security を確認します。実ユーザー情報、Token、Provider Key、Production Credential を Commit してはいけません。
|
||||
|
||||
10
docs/ja/guide/deployment.md
Normal file
10
docs/ja/guide/deployment.md
Normal file
@ -0,0 +1,10 @@
|
||||
# デプロイ
|
||||
|
||||
`pnpm check` と `pnpm build` を実行し、`dist` を Nginx/CDN に配置します。History Router のため `try_files` で `index.html` に戻します。
|
||||
|
||||
PWA は `VITE_PWA_ENABLED=true` のときだけ有効で、認証 API を既定では Cache しません。画像最適化は Production のみです。
|
||||
|
||||
Gateway は `/api/ai` を FastAPI、残りの `/api` を Gin に転送します。SSE は Buffering と変換を無効化し、Read Timeout を調整します。PostgreSQL と Redis は Private Network に置き、Secret Manager、TLS、Backup、監視を利用します。
|
||||
|
||||
CSP は実際の API、Image CDN、Monitoring Domain に合わせて設定し、Mock や Debug Tool を Production に含めません。
|
||||
|
||||
18
docs/ja/guide/environment.md
Normal file
18
docs/ja/guide/environment.md
Normal file
@ -0,0 +1,18 @@
|
||||
# 環境とビルド
|
||||
|
||||
主要変数:
|
||||
|
||||
| 変数 | 用途 |
|
||||
| --- | --- |
|
||||
| `VITE_USE_MOCK` | 開発 Mock の有効化 |
|
||||
| `VITE_API_BASE_URL` | Axios API Prefix |
|
||||
| `VITE_API_TARGET` | Gin 開発 Proxy Target |
|
||||
| `VITE_AI_API_BASE_URL` | AI Stream Prefix |
|
||||
| `VITE_AI_API_TARGET` | FastAPI 開発 Proxy Target |
|
||||
| `VITE_UI_FRAMEWORK` | `vant` / `nutui` / `varlet` |
|
||||
| `VITE_PWA_ENABLED` | PWA の有効化 |
|
||||
| `VITE_IMAGE_OPTIMIZE` | Production 画像最適化 |
|
||||
| `VITE_USE_REPORT` | Bundle Report |
|
||||
|
||||
Secret を `VITE_*` に保存しないでください。これらは Browser Bundle から参照できます。Production Mock は既定で無効です。
|
||||
|
||||
8
docs/ja/guide/i18n.md
Normal file
8
docs/ja/guide/i18n.md
Normal file
@ -0,0 +1,8 @@
|
||||
# 国際化
|
||||
|
||||
対応 Locale は `zh-CN`、`en-US`、`ja-JP` です。Home の Selector は `setLang` を呼び、Message を Lazy Load して `vue-i18n` の Reactive Locale、`localStorage`、HTML `lang` を同期します。
|
||||
|
||||
画面に直接固定文言を書かず、すべての翻訳可能な UI は Locale JSON に置きます。商品 Content は Backend の Localized Field から現在の Locale を選択します。
|
||||
|
||||
Locale 追加時は Message Key の同期、Router Title、E2E 切替、日付・金額 Formatter、Fallback を確認してください。
|
||||
|
||||
6
docs/ja/guide/index.md
Normal file
6
docs/ja/guide/index.md
Normal file
@ -0,0 +1,6 @@
|
||||
# プロジェクト紹介
|
||||
|
||||
vue-h5-template v2 は Vue 3、Vite 8、TypeScript を基盤にした実案件向け Mobile H5 テンプレートです。Vant、NutUI、Varlet の一つをビルド時に選択し、型安全 API、TanStack Query、PWA、SVG Sprite、3言語、AI Streaming、コマース例を提供します。
|
||||
|
||||
デモを増やすことではなく、交換可能でテスト可能な設計境界を示すことが目的です。
|
||||
|
||||
8
docs/ja/guide/migration-v2.md
Normal file
8
docs/ja/guide/migration-v2.md
Normal file
@ -0,0 +1,8 @@
|
||||
# v2 への移行
|
||||
|
||||
主な Breaking Change:pnpm のみ、明示 Router、新しい `api/client.ts` と Domain Module、`ApiError`、Pinia/Query の責務分離、3言語 Locale、UI Framework のビルド時選択、独立した Gin/FastAPI Backend です。
|
||||
|
||||
推奨手順:新しい v2 Template から Branch を作成し、Business Page を段階的に移します。API Contract を OpenAPI に合わせ、Server State を TanStack Query に移し、旧 Request Wrapper と複数 UI Global Install を削除します。
|
||||
|
||||
各段階で `pnpm check` と重要 Flow の Playwright を実行し、最後に Compose Smoke Test を行います。
|
||||
|
||||
15
docs/ja/guide/request.md
Normal file
15
docs/ja/guide/request.md
Normal file
@ -0,0 +1,15 @@
|
||||
# リクエストと認証
|
||||
|
||||
ページから Axios を直接 import せず、`src/api/modules` の Domain 関数を使います。JSON API は `ApiResponse<T>` を展開し、失敗は `ApiError` に正規化します。Token と任意の Request ID は Request Interceptor が追加します。
|
||||
|
||||
HTTP、Business Error、401、Timeout、Network、Cancel を区別します。401 は Session を削除し、安全な内部 Redirect だけを Login に渡します。
|
||||
|
||||
契約変更時:
|
||||
|
||||
```bash
|
||||
pnpm api:generate
|
||||
pnpm typecheck
|
||||
```
|
||||
|
||||
`openapi/schema.yaml` と生成済み `src/types/api/generated.d.ts` を同時に Commit します。
|
||||
|
||||
15
docs/ja/guide/start.md
Normal file
15
docs/ja/guide/start.md
Normal file
@ -0,0 +1,15 @@
|
||||
# クイックスタート
|
||||
|
||||
Node.js 20.10 以上と pnpm 9.12 以上を使用します。Lockfile は `pnpm-lock.yaml` だけです。
|
||||
|
||||
```bash
|
||||
git clone https://github.com/sunniejs/vue-h5-template.git
|
||||
cd vue-h5-template
|
||||
pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
`pnpm dev` は Mock API を使います。実バックエンド連携は PostgreSQL、Gin、FastAPI、Redis を Compose で起動し、`pnpm dev:integration` を実行します。
|
||||
|
||||
主なコマンド:`pnpm lint`、`pnpm typecheck`、`pnpm test`、`pnpm test:e2e`、`pnpm build`、`pnpm check`、`pnpm api:generate`。
|
||||
|
||||
9
docs/ja/guide/state-management.md
Normal file
9
docs/ja/guide/state-management.md
Normal file
@ -0,0 +1,9 @@
|
||||
# 状態管理
|
||||
|
||||
- Pinia:Token、ユーザー、テーマ、Feature Flag など Client 所有の状態。
|
||||
- TanStack Query:API Cache、Loading、Retry、Mutation、Pagination、Invalidation。
|
||||
- Local State:Form 入力や一時 UI。
|
||||
- `useStreamingChat`:AI Conversation、AbortController、再生成、Error。
|
||||
|
||||
Server Response を Pinia にコピーすると Cache が二重になるため禁止します。Query Key は Domain と Filter を含め、Component Unmount や Filter 変更時に `AbortSignal` を Transport まで渡します。
|
||||
|
||||
15
docs/ja/guide/testing.md
Normal file
15
docs/ja/guide/testing.md
Normal file
@ -0,0 +1,15 @@
|
||||
# テスト
|
||||
|
||||
Vitest は Utility、Request Error、Store、Streaming Parser/Composable、Login Form、Chat Composer、Locale を検証します。Vue Test Utils は Public Behavior を対象にし、Implementation Detail だけの Test は追加しません。
|
||||
|
||||
Playwright の Pixel 7 Project は Home、3言語切替、Shop、Login、Mock API、AI Streaming、401 Redirect を検証します。
|
||||
|
||||
```bash
|
||||
pnpm test
|
||||
pnpm test:coverage
|
||||
pnpm test:e2e
|
||||
pnpm check
|
||||
```
|
||||
|
||||
実バックエンド変更時は Compose と Smoke Script、Gin の `go test ./...`、FastAPI の Ruff/mypy/pytest も実行します。
|
||||
|
||||
8
docs/ja/guide/ui-framework.md
Normal file
8
docs/ja/guide/ui-framework.md
Normal file
@ -0,0 +1,8 @@
|
||||
# UI フレームワーク戦略
|
||||
|
||||
`VITE_UI_FRAMEWORK` が Vant、NutUI、Varlet の Resolver と Demo Alias をビルド時に一つだけ選択します。実業務ページで複数 Framework を混在させません。
|
||||
|
||||
各 UI Demo は Button だけでなく、状態、設定 List、Switch、Progress、Tag など実際の Interaction を示します。Product Icon は `src/assets/icons` と `<SvgIcon />` を使い、UI Library 固有 Icon と分離します。
|
||||
|
||||
アプリ固有 Layout は Scoped SCSS と Design Token を使います。Atomic Utility を長く並べることを必須にしません。
|
||||
|
||||
24
docs/ja/index.md
Normal file
24
docs/ja/index.md
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: Vue H5 Template
|
||||
text: モダンな Vue 3 Mobile H5 スターター
|
||||
tagline: 型安全 API、PostgreSQL コマース、Streaming AI、3言語 UI、選択式モバイル UI フレームワーク
|
||||
actions:
|
||||
- theme: brand
|
||||
text: はじめる
|
||||
link: /ja/guide/start
|
||||
- theme: alt
|
||||
text: アーキテクチャ
|
||||
link: /ja/guide/architecture
|
||||
|
||||
features:
|
||||
- title: 実際に動く機能
|
||||
details: 商品一覧、管理 CRUD、AI Streaming、認証を Mock と実バックエンドの両方で確認できます。
|
||||
- title: 明確な境界
|
||||
details: Pinia は Client State、TanStack Query は Server State、API Module は型付き契約を担当します。
|
||||
- title: Mobile First
|
||||
details: Safe Area、ソフトキーボード、44px Touch Target、iOS Safari と WebView を考慮しています。
|
||||
---
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user