Files
gongxue-base/apps/taro/README.md
2026-06-29 12:04:59 +08:00

75 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Taro 前端工程
这是 SaaS 题库的新跨端前端地基。当前阶段已经提供 H5 多入口、租户解析、统一 API client、Supabase Auth client 初始化、安全环境变量边界,以及学生端第一批可联调页面。
## 三个 H5 入口
```bash
npm run dev:taro:h5
npm run build:taro:h5:student
npm run build:taro:h5:tenant
npm run build:taro:h5:platform
```
构建产物:
```text
apps/taro/dist/h5-student
apps/taro/dist/h5-tenant-admin
apps/taro/dist/h5-platform-admin
```
可以分别部署到学生端域名、租户后台域名、平台后台域名。三个入口共用 `src/services/api.ts`,不得在页面中散写 `Taro.request`
## 当前学生端页面
已接入第一批真实后端 API
```text
pages/student/login/index 短信登录
pages/student/home/index 首页与功能入口
pages/student/catalog/index 题库入口、分类、集合、练习蓝图
pages/student/practice/index 创建练习 session、答题、收藏
pages/student/vocabulary/index 单词单元、复习计划、认识/再记、收藏
pages/student/handbook/index 手册科目、章节、知识点阅读
pages/student/scoreline/index 分数线列表
pages/student/assets/index 资料列表、预览签名、下载签名
pages/student/profile/index 个人中心、会员、订单、签到、激活码、勋章
```
这些页面是联调骨架,不是最终视觉稿。后续应继续参照旧题库样式完善刷题交互、视频解析、题目反馈、模考报告、错题复习、订单收银台和小程序兼容。
## 前端环境变量
只允许使用:
```text
TARO_APP_PORTAL=student | tenant-admin | platform-admin
TARO_APP_API_BASE_URL=https://api.example.com
TARO_APP_SUPABASE_URL=https://<supabase-host>
TARO_APP_SUPABASE_PUBLISHABLE_KEY=<publishable-key>
TARO_APP_TENANT_CODE=<可选,小程序/预览环境使用>
```
禁止把 service role、数据库连接串、支付私钥、对象存储密钥放进 Taro 构建环境。
## 接入原则
- H5 可用 Supabase client 管理 Auth session。
- 业务数据默认走 `apps/api`
- `x-tenant-id` 只是租户上下文,不是身份凭证。
- 登录后不要传 `x-user-id` 或 body/query `userId` 伪造当前用户。
- 题库练习、订单支付、内容导入、CRM、资料签名、后台配置必须走后端命令层。
## H5 部署建议
当前保留三个独立构建目录,适合分别放到三个域名或同一服务器的三个静态目录:
```text
student.example.com -> apps/taro/dist/h5-student
tenant-admin.example.com -> apps/taro/dist/h5-tenant-admin
platform-admin.example.com -> apps/taro/dist/h5-platform-admin
```
API 使用 `TARO_APP_API_BASE_URL` 指向统一后端。学生端通过域名解析租户;小程序或预览环境可用 `TARO_APP_TENANT_CODE` 指定租户。