Compare commits
25
Commits
25bbb5f9c8
..
0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b75ce5b490 | ||
|
|
0483b14e9b | ||
|
|
b248d237f2 | ||
|
|
fcb536a6fe | ||
|
|
7d5db6a867 | ||
|
|
014fa90dcd | ||
|
|
058d677fc1 | ||
|
|
f05a11f0f3 | ||
|
|
a9552b3d1a | ||
|
|
879e74ebda | ||
|
|
c45025fc86 | ||
|
|
6b263af74f | ||
|
|
a81c637a98 | ||
|
|
b652132957 | ||
|
|
5fe7f5d476 | ||
|
|
d8786eb28a | ||
|
|
85b0e70907 | ||
|
|
c7f43e30a9 | ||
|
|
e81481623c | ||
|
|
a1cbc9404a | ||
|
|
ea6c080d89 | ||
|
|
6ae4c109ce | ||
|
|
5a92bab835 | ||
|
|
4833f7fa6a | ||
|
|
c6e2cb4d5b |
No files matched your search
@@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
name: review-safe-words
|
||||||
|
description: 个人小程序审核敏感词规避。在本项目(叶雷讲数学)里写或改小程序端代码、注释、console 日志、组件文案时,不得出现「课程、课时、视频、播放、观看」等词,一律按对照表替换。本项目内一切涉及小程序端的开发操作都适用。
|
||||||
|
---
|
||||||
|
|
||||||
|
# 审核敏感词规避
|
||||||
|
|
||||||
|
个人主体小程序审核严:代码里(**包括注释、日志、组件内文案**)出现某些词,会被判定为在线教育 / 媒体类内容。本项目一律避开。
|
||||||
|
|
||||||
|
## 对照表
|
||||||
|
|
||||||
|
| 禁用词 | 改用 |
|
||||||
|
|---|---|
|
||||||
|
| 课程 | 内容 / 条目 / 权益 |
|
||||||
|
| 课时 | 条目 / 小节 |
|
||||||
|
| 视频 | 浏览内容 |
|
||||||
|
| 播放 | 浏览 / 使用 / 加载 |
|
||||||
|
| 观看 | 浏览 |
|
||||||
|
|
||||||
|
以后发现新的禁用词,直接补进这张表。
|
||||||
|
|
||||||
|
注意:「媒体」也别用——它和上面几个词一样敏感,不当作替代词。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
- 小程序端(`yelaymaths/`)**所有文件**:`.js` / `.wxml` / `.wxss` / `.json`
|
||||||
|
- **包括注释和 `console.*` 日志**——以前就是把这些词写进了注释和日志里
|
||||||
|
- 变量名、函数名、配置 key 一律用英文,不要带这些中文
|
||||||
|
|
||||||
|
## 改完自查
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd yelaymaths
|
||||||
|
rg -n "课程|课时|视频|播放|观看" --glob "!miniprogram_npm" --glob "!node_modules" .
|
||||||
|
```
|
||||||
|
|
||||||
|
必须**无输出**才算干净。
|
||||||
|
|
||||||
|
## 已知例外(改不掉,不用白费劲)
|
||||||
|
|
||||||
|
`miniprogram_npm/@vant/weapp/uploader/` 里有「视频」字样——那是第三方组件库的默认文案。
|
||||||
|
|
||||||
|
- 它是【构建 npm】的产物、在 `.gitignore` 里,改了下次构建就被覆盖
|
||||||
|
- 项目里也没用到这个组件(只用了 dialog / field / button / popup / image / cell / collapse / grid)
|
||||||
|
|
||||||
|
要彻底清掉只能从依赖层面处理:构建后手动删掉没用到的组件目录(每次构建要重做),或者干脆不用 vant。
|
||||||
|
|
||||||
|
## 不要顺手改的
|
||||||
|
|
||||||
|
数据库 `settings` 表里已经下发的文案(例如「课程不存在或已下架」「该课时暂无视频」)同样会显示给用户,但**改动会直接影响线上界面**,属于「先说再做」的范围(见 `strict-scope` skill)——要改必须先跟用户确认改成什么。
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
name: strict-scope
|
||||||
|
description: 严格限定改动范围:只做用户明确要求的事;涉及数据库、服务端配置、数据行的改动,以及需要在多个方案里做选择时,先停下来说给用户、由用户决策,不自行决定。本项目(叶雷讲数学)内的一切开发与运维操作都适用。
|
||||||
|
---
|
||||||
|
|
||||||
|
# 严格限定改动范围
|
||||||
|
|
||||||
|
## 三条硬规则
|
||||||
|
|
||||||
|
1. **只做被明确要求的事。** 要求是 A,就只做 A。不做"顺手一起弄好"的额外改动。
|
||||||
|
2. **需要改动数据库配置 / 数据行 / 线上状态时,先说给用户,由用户决定。** 觉得"这里应该改一下"不是动手的理由,是提问的理由。
|
||||||
|
3. **需要做选择时先问。** 有多个方案、或某个字段该填什么值、某条数据算不算"正确状态"——这些都不是我可以替用户定的。
|
||||||
|
|
||||||
|
## 属于「先说再做」的范围
|
||||||
|
|
||||||
|
| 类别 | 具体 |
|
||||||
|
|---|---|
|
||||||
|
| 服务端配置 | `.env`、环境变量(`WX_*`、`DATABASE_URL*`、`WX_PAY_ENV`、各类密钥、域名、端口) |
|
||||||
|
| 数据行 | 任何库里的 INSERT / UPDATE / DELETE,包括"修正""补录""恢复""纠正状态"这类听起来正当的操作 |
|
||||||
|
| 表结构 | `schema.prisma`、迁移文件、给某个库补迁移 |
|
||||||
|
| 线上状态 | 部署、重启进程、切换小程序数据源、清理线上数据 |
|
||||||
|
|
||||||
|
提出时把三件事说清楚:**发现了什么 → 建议怎么改 → 影响范围**,然后等回复。
|
||||||
|
|
||||||
|
## 不属于限制范围
|
||||||
|
|
||||||
|
- 用户明确要求过的改动,照做,不要在同一个任务里反复确认。
|
||||||
|
- 只读操作不受限:查数据、看日志、比对记录、跑诊断。
|
||||||
|
- 用户已经授权的那次操作,做完即可。
|
||||||
|
|
||||||
|
## 本项目真实踩过的坑
|
||||||
|
|
||||||
|
1. 用户说「删课程」,我执行了当时写的连带删除逻辑,把课程下 55 个课时一起删了,开发库数据丢失。
|
||||||
|
→ 要求是删课程,就该只删课程那一行;其余的要问。
|
||||||
|
2. 恢复那条被误删的数据时,我自作主张给 `status` 字段填了 0。
|
||||||
|
→ 用户的原话:「万一是我手动改的呢」。恢复数据必须原样,拿不准的值要问。
|
||||||
|
3. 发现开发库缺 4 个迁移,我自己判断后直接补上了。
|
||||||
|
→ 虽然是修复,但那是改表结构,应该先说。
|
||||||
|
4. 改动 `.env` 里的 `WX_PAY_ENV` 并重启服务。
|
||||||
|
→ 结论是对的,但涉及线上配置,应当先说明再动。
|
||||||
|
|
||||||
|
## 出问题时的处理
|
||||||
|
|
||||||
|
发现自己越界了:直接承认、说清改了什么、给出恢复方案,不要辩解,也不要顺手再改点别的来"补救"。
|
||||||
+33
-3
@@ -13,6 +13,36 @@
|
|||||||
/.ignore
|
/.ignore
|
||||||
|
|
||||||
|
|
||||||
# 系统文件
|
# 系统文件
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
# Node
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
.next/
|
||||||
|
out/
|
||||||
|
.turbo/
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
# 环境变量与密钥(禁止入库)
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# 部署脚本的本地配置(含服务器地址,禁止入库)
|
||||||
|
deploy/deploy.config.ps1
|
||||||
|
deploy/deploy.config.sh
|
||||||
|
|
||||||
|
# 小程序构建产物
|
||||||
|
yelaymaths/miniprogram_npm/
|
||||||
|
yelaymaths/project.private.config.json
|
||||||
|
|
||||||
|
# 课程数据端(大文件不入库,仅保留目录骨架与说明)
|
||||||
|
yelaymaths_data.yeomai.site/**
|
||||||
|
!yelaymaths_data.yeomai.site/**/
|
||||||
|
!yelaymaths_data.yeomai.site/**/README.md
|
||||||
|
!yelaymaths_data.yeomai.site/README.md
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# 叶雷讲数学
|
||||||
|
|
||||||
|
微信小程序在线数学课程项目。
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
四个子项目**各自独立**:各自安装依赖、各自持有 lockfile,互不依赖。
|
||||||
|
仓库根目录不放任何 Node 配置,也不会有 `node_modules`。
|
||||||
|
|
||||||
|
| 目录 | 角色 | 技术栈 |
|
||||||
|
|---|---|---|
|
||||||
|
| `yelaymaths/` | 微信小程序 | 原生小程序 |
|
||||||
|
| `yelaymaths_api/` | 服务端 API | NestJS + Prisma + MySQL 5.7 |
|
||||||
|
| `yelaymaths_admin/` | 管理后台 | Next.js 15 + Tailwind |
|
||||||
|
| `yelaymaths_data.yeomai.site/` | 课程数据(图片 / 视频) | 静态文件 |
|
||||||
|
| `docs/` | 设计与部署文档 | — |
|
||||||
|
|
||||||
|
历史版本代码保留在 `前端/`、`服务端/`、`数据库/`,仅作参考,迁移完成后可删除。
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 服务端
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd yelaymaths_api
|
||||||
|
pnpm install
|
||||||
|
cp .env.example .env # 填写数据库连接串与各类密钥
|
||||||
|
pnpm prisma:generate
|
||||||
|
pnpm prisma:migrate # 建表
|
||||||
|
pnpm dev # http://127.0.0.1:3000
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 迁移旧数据
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd yelaymaths_api
|
||||||
|
pnpm legacy:check # 体检,确认旧数据可无损映射
|
||||||
|
pnpm legacy:migrate -- --dry-run # 试运行,核对行数
|
||||||
|
pnpm legacy:migrate # 正式迁移
|
||||||
|
```
|
||||||
|
|
||||||
|
详见 [`yelaymaths_api/tools/legacy/README.md`](yelaymaths_api/tools/legacy/README.md)。
|
||||||
|
|
||||||
|
### 3. 管理后台
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd yelaymaths_admin
|
||||||
|
pnpm install
|
||||||
|
cp .env.example .env.local # 填写 API 地址
|
||||||
|
pnpm dev # http://127.0.0.1:3001
|
||||||
|
```
|
||||||
|
|
||||||
|
首次打开用登录页的「创建管理员账号」入口初始化超管。
|
||||||
|
|
||||||
|
### 4. 小程序
|
||||||
|
|
||||||
|
用微信开发者工具打开 `yelaymaths/`,先在 `yelaymaths/config/index.js` 里填写 API 与静态资源域名,
|
||||||
|
然后执行【工具 → 构建 npm】。
|
||||||
|
|
||||||
|
## 部署
|
||||||
|
|
||||||
|
见 [`docs/部署指南.md`](docs/部署指南.md)。
|
||||||
|
|
||||||
|
## 设计文档
|
||||||
|
|
||||||
|
见 [`docs/重构开发文档.md`](docs/重构开发文档.md)。
|
||||||
|
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
# 一键部署脚本
|
||||||
|
|
||||||
|
在本机运行一条命令,自动完成「本地构建(可选)→ 打包 → 上传服务器 → 重启进程」。
|
||||||
|
|
||||||
|
服务器上**不需要安装任何东西**,它复用的就是你已经能用的 SSH。
|
||||||
|
|
||||||
|
## 用哪个脚本
|
||||||
|
|
||||||
|
| 你的系统 | 脚本 | 配置文件 |
|
||||||
|
|---|---|---|
|
||||||
|
| Windows | `deploy.ps1` | `deploy.config.ps1`(照抄 `deploy.config.example.ps1`) |
|
||||||
|
| macOS / Linux | `deploy.sh` | `deploy.config.sh`(照抄 `deploy.config.example.sh`) |
|
||||||
|
|
||||||
|
Mac 上先执行一次 `chmod +x deploy/deploy.sh`,之后用法和 Windows 版完全一样:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./deploy/deploy.sh api
|
||||||
|
./deploy/deploy.sh admin
|
||||||
|
./deploy/deploy.sh
|
||||||
|
./deploy/deploy.sh api --dry-run # 只打包、只显示会上传哪些文件,不真传
|
||||||
|
./deploy/deploy.sh api --with-install # 顺带装依赖(只有改了 package.json 才需要)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 第一次用先跑 `--dry-run`,它会打印打包大小和文件清单,核对无误再去掉这个参数。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一次性配置
|
||||||
|
|
||||||
|
### 1. 填配置文件
|
||||||
|
|
||||||
|
编辑 `deploy/deploy.config.ps1`(Mac 上是 `deploy/deploy.config.sh`,字段名多一层下划线,含义完全一样),需要改这几项:
|
||||||
|
|
||||||
|
| 配置项 | 填什么 | 怎么查 |
|
||||||
|
|---|---|---|
|
||||||
|
| `Host` | 服务器 IP 或域名 | — |
|
||||||
|
| `Port` | SSH 端口 | 宝塔 → 安全 → SSH 端口 |
|
||||||
|
| `User` | SSH 登录用户 | 一般是 `root` |
|
||||||
|
| `NodeBin` | Node 的 bin 目录 | 宝塔 → 软件商店 → Node 版本管理器 |
|
||||||
|
| `Api.RemotePath` | 服务端在服务器上的绝对路径 | 你部署时放的位置 |
|
||||||
|
| `Admin.RemotePath` | 管理端在服务器上的绝对路径 | 同上 |
|
||||||
|
| `Api.RestartCmd` | 重启服务端的命令 | 服务器上执行 `pm2 list` 看进程名 |
|
||||||
|
| `Admin.RestartCmd` | 重启管理端的命令 | 同上 |
|
||||||
|
| `Api.StartCmd` / `Admin.StartCmd` | 杀掉旧进程后把服务拉起来的命令 | 照抄模板;项目路径或端口变了才需要改 |
|
||||||
|
| `Api.HealthUrl` / `Admin.HealthUrl` | 启动后的探活地址 | 照抄模板;端口变了才需要改 |
|
||||||
|
| `NginxCacheDir` | Nginx 反向代理缓存目录 | 宝塔 → 软件商店 → Nginx → 配置修改,搜 `proxy_cache_path` |
|
||||||
|
| `NginxBin` | Nginx 可执行文件路径 | 一般是 `/www/server/nginx/sbin/nginx` |
|
||||||
|
|
||||||
|
### 2. 配置免密登录(强烈建议)
|
||||||
|
|
||||||
|
不配的话,每次部署要输两次密码。配好之后全程无提示。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 本机生成密钥(已生成过可跳过,直接第二次命令)
|
||||||
|
ssh-keygen -t ed25519
|
||||||
|
|
||||||
|
# 把公钥传到服务器
|
||||||
|
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@你的服务器 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 确认服务器上的 .env 已就位
|
||||||
|
|
||||||
|
脚本**不会上传** `.env`(这是故意的,避免覆盖服务器上的密钥配置)。
|
||||||
|
|
||||||
|
- 服务端:`yelaymaths_api/.env` 必须已在服务器上配好
|
||||||
|
- 管理端:`yelaymaths_admin/.env.local` 必须已在服务器上配好
|
||||||
|
- 注意 `NEXT_PUBLIC_*` 是**构建时**写死的,所以第一次构建前它就得在
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 日常使用
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\deploy\deploy.ps1 api # 只部署服务端
|
||||||
|
.\deploy\deploy.ps1 admin # 只部署管理端
|
||||||
|
.\deploy\deploy.ps1 # 两个都部署
|
||||||
|
```
|
||||||
|
|
||||||
|
输出长这样:
|
||||||
|
|
||||||
|
```
|
||||||
|
=== yelaymaths_api (server API) ===
|
||||||
|
[1/5] Building locally: pnpm prisma:generate && pnpm build
|
||||||
|
[2/5] Packing yelaymaths_api
|
||||||
|
160 KB (dist, prisma, package.json, pnpm-lock.yaml, pnpm-workspace.yaml)
|
||||||
|
[3/5] Uploading to /www/wwwroot/yelaymaths/yelaymaths_api/api
|
||||||
|
[4/5] Running on server
|
||||||
|
__DEPLOY_DONE__
|
||||||
|
[5/5] Restarted
|
||||||
|
Started, health check passed: http://127.0.0.1:3002/healthz
|
||||||
|
Nginx proxy cache cleared and reloaded
|
||||||
|
|
||||||
|
All done in 12.0s
|
||||||
|
```
|
||||||
|
|
||||||
|
### 其它参数
|
||||||
|
|
||||||
|
| 参数 | 作用 |
|
||||||
|
|---|---|
|
||||||
|
| `-DryRun` | 只打包、只显示会上传哪些文件,**不真的传**。第一次用建议先跑这个 |
|
||||||
|
| `-WithInstall` | 额外安装依赖。**只在改了 `package.json` 时才需要** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 为什么默认不装依赖
|
||||||
|
|
||||||
|
服务器上的全局 pnpm 是 **8.x**,而本机是 10.x,两代锁文件格式不兼容——服务器直接读不了我们的 `pnpm-lock.yaml`。
|
||||||
|
|
||||||
|
而服务器上**不能升级 pnpm**(其他服务也在用)。
|
||||||
|
|
||||||
|
好在只有「装依赖」这一步需要版本匹配,**「构建」不需要**——`pnpm build` 只是执行 `package.json` 里的脚本,pnpm 8 也能跑。
|
||||||
|
|
||||||
|
所以日常部署走「上传源码 + 构建」,用服务器上现成的 `node_modules`,既不碰全局 pnpm,也快得多。
|
||||||
|
|
||||||
|
只有 `package.json` 变了才需要装依赖,这时用 `-WithInstall`,它会通过 `npx` 临时拉一个 10.27.0 的 pnpm 来跑,同样不影响全局。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 上传哪些文件
|
||||||
|
|
||||||
|
脚本用的是**白名单**,只有列在 `DeployPaths` 里的路径会被打包。所以这些东西**结构上不可能**被传上去:
|
||||||
|
|
||||||
|
- `.env` / `.env.local`(服务器上的配置不会被覆盖)
|
||||||
|
- `node_modules/`
|
||||||
|
- 白名单之外的源码目录
|
||||||
|
|
||||||
|
Windows 版配置(`deploy.config.ps1`)已经在**本机构建、只传产物**:服务端传 `dist` + `prisma`(约 160 KB),
|
||||||
|
管理端传 `.next` + `next.config.ts`(约 540 KB,73 MB 的构建缓存已排除),服务器不再执行编译,部署完自动重启并探活。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 已知限制
|
||||||
|
|
||||||
|
**删除的文件不会同步删除。** 脚本是「覆盖式上传」,如果你在本地删掉某个源码文件,服务器上那份还在。
|
||||||
|
|
||||||
|
一般不影响运行(多余的文件不会被执行),但如果你发现改了名字的旧文件仍在作怪,手动上服务器删掉即可。
|
||||||
|
|
||||||
|
需要「完全同步」的场景(比如删文件、想要版本回滚),改用 git 推送部署更合适——那是另一个方案,需要时再说。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 部署结束后会清一次 Nginx 缓存
|
||||||
|
|
||||||
|
宝塔在 `/www/server/nginx/conf/proxy.conf` 里对**所有**反向代理站点开了 `proxy_cache cache_one`,而 Next.js 给页面发的响应头是 `Cache-Control: s-maxage=31536000`——翻译过来就是「这一页允许缓存一年」。
|
||||||
|
|
||||||
|
两边一叠加,后果很隐蔽:新构建传上去、进程也重启了,用户访问到的还是缓存里的旧 HTML;而旧 HTML 引用的分包早被新构建删掉,请求直接 404,页面渲染到一半就断,表现成「某个区块整块消失」,看起来像代码写错了,实际跟代码毫无关系。
|
||||||
|
|
||||||
|
所以脚本在每次部署的最后会多做一步:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
find /www/server/nginx/proxy_cache_dir -mindepth 1 -delete # 清空缓存文件
|
||||||
|
/www/server/nginx/sbin/nginx -s reload # 重载 Nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
服务端和管理端两条部署线都带这一步。缓存只影响响应速度,清空后第一次访问会回源到新构建,不会丢数据。
|
||||||
|
|
||||||
|
把 `NginxCacheDir` 留空(`''`)就会跳过这一步。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 部署结束会把服务自动拉起来
|
||||||
|
|
||||||
|
杀掉旧进程不等于新进程会跑起来。之前这里是「只杀不拉」,所以每次部署完都要去宝塔面板点一下「启动」,忘了点线上就是 502。
|
||||||
|
|
||||||
|
现在每个应用多两项配置:
|
||||||
|
|
||||||
|
- `RestartCmd`:杀掉旧进程
|
||||||
|
- `StartCmd`:把新进程拉起来(`setsid` + `nohup` + 重定向,SSH 会话断了也不受影响)
|
||||||
|
- `HealthUrl`:拉起后探活,30 秒内没响应就让部署直接判失败
|
||||||
|
|
||||||
|
所以正常输出结尾会是:
|
||||||
|
|
||||||
|
```
|
||||||
|
[5/5] Restarted
|
||||||
|
Started, health check passed: http://127.0.0.1:3001/
|
||||||
|
Nginx proxy cache cleared and reloaded
|
||||||
|
```
|
||||||
|
|
||||||
|
进程日志写在服务器上:`/www/wwwlogs/yelaymaths-api.out.log`、`/www/wwwlogs/yelaymaths-admin.out.log`。
|
||||||
|
|
||||||
|
有一点要知道:进程是脚本拉起来的,不是宝塔面板拉起来的,所以**面板里那个项目的状态可能显示成「未启动」**,但服务本身是正常在跑的(脚本每次都会探活确认)。如果想让面板重新接管,在面板点一次「重启」即可,之后照常用面板管。
|
||||||
|
|
||||||
|
只有 `RestartCmd` 不想自己启动(比如服务由 PM2 或 systemd 托管),把 `StartCmd` 留空(`''`)就会退回「只杀不拉」的老行为。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 出问题怎么排查
|
||||||
|
|
||||||
|
| 现象 | 原因 | 处理 |
|
||||||
|
|---|---|---|
|
||||||
|
| `deploy.config.ps1 not found` | 没建配置文件 | 复制 `deploy.config.example.ps1` |
|
||||||
|
| 一直提示输密码 | 没配免密登录 | 见上面第 2 步 |
|
||||||
|
| `pnpm: command not found` | `NodeBin` 填错 | 在服务器上执行 `which pnpm` 看真实路径 |
|
||||||
|
| `pm2: command not found` | PM2 不在 Node 的 bin 目录 | 服务器上执行 `which pm2`,把目录也加到 `NodeBin` |
|
||||||
|
| 构建成功但页面没变 | 进程没重启,或 Nginx 缓存没清 | 检查 `RestartCmd`、`NginxCacheDir` 填对没有 |
|
||||||
|
| 页面某个区块整块消失 | 缓存里的旧 HTML 引用了已 404 的旧分包 | 手动清一次 `NginxCacheDir` 并 reload |
|
||||||
|
| 部署报 `service did not come up` | 新进程没起来 | 看 `/www/wwwlogs/yelaymaths-*.out.log` 的报错,多半是端口被占或依赖没装 |
|
||||||
|
| `Permission denied` | 目标目录权限不对 | 服务器上 `chown -R root:root 目标目录` |
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
# Copy this file to deploy.config.ps1 and fill in your own values.
|
||||||
|
# deploy.config.ps1 is gitignored, so your server address stays out of the repo.
|
||||||
|
|
||||||
|
$Config = @{
|
||||||
|
# ---- SSH ----
|
||||||
|
Host = '1.2.3.4' # server IP or domain
|
||||||
|
Port = 22
|
||||||
|
User = 'root'
|
||||||
|
|
||||||
|
# Node bin directory on the server (prepended to PATH during the remote build).
|
||||||
|
# Find it in BT Panel -> Node version manager, e.g. /www/server/nodejs/v22.14.0/bin
|
||||||
|
NodeBin = '/www/server/nodejs/v22/bin'
|
||||||
|
|
||||||
|
# ---- Nginx proxy cache ----
|
||||||
|
# BT Panel enables `proxy_cache cache_one` globally in
|
||||||
|
# /www/server/nginx/conf/proxy.conf, while Next.js answers with
|
||||||
|
# `Cache-Control: s-maxage=31536000` — i.e. "this page may be cached for a year".
|
||||||
|
# Nginx obeys, so a fresh build is never served; the cached HTML references chunks
|
||||||
|
# that the new build already removed (404), and the page breaks halfway through.
|
||||||
|
# deploy.ps1 clears this directory and reloads Nginx after every deploy.
|
||||||
|
# Leave NginxCacheDir empty ('') to skip that step.
|
||||||
|
NginxCacheDir = '/www/server/nginx/proxy_cache_dir'
|
||||||
|
NginxBin = '/www/server/nginx/sbin/nginx'
|
||||||
|
|
||||||
|
# ---- yelaymaths_api ----
|
||||||
|
# The build runs on your machine; the server only receives build output.
|
||||||
|
Api = @{
|
||||||
|
Key = 'api'
|
||||||
|
Label = 'yelaymaths_api (server API)'
|
||||||
|
LocalPath = 'yelaymaths_api'
|
||||||
|
RemotePath = '/www/wwwroot/yelaymaths/yelaymaths_api'
|
||||||
|
# Build output only. 'prisma' carries the schema + migrations so you can still run
|
||||||
|
# `pnpm prisma:migrate` on the server. Source (src / tools / tsconfig …) is never uploaded.
|
||||||
|
DeployPaths = @(
|
||||||
|
'dist', 'prisma',
|
||||||
|
'package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml'
|
||||||
|
)
|
||||||
|
# Compile locally so the server never spends CPU on a build.
|
||||||
|
LocalBuildCmd = 'pnpm prisma:generate && pnpm build'
|
||||||
|
# Opt-in via -WithInstall. The server's global pnpm is 8.x and cannot read our
|
||||||
|
# v9+ lockfile, so npx fetches a matching pnpm into its cache instead.
|
||||||
|
InstallCmd = 'npx --yes pnpm@10.27.0 install --frozen-lockfile'
|
||||||
|
# Already built locally — do not rebuild on the server.
|
||||||
|
BuildCmd = ''
|
||||||
|
# Directories to delete on the server before unpacking, so files removed locally do
|
||||||
|
# not linger. Leave empty ('@()') when the build output is fully overwritten.
|
||||||
|
CleanPaths = @()
|
||||||
|
|
||||||
|
# Restart command: kills the old process so the new build is picked up
|
||||||
|
# (Node reads code into memory at startup — uploading alone changes nothing).
|
||||||
|
# If PM2 / systemd already keeps it running, use e.g. 'pm2 restart yelaymaths-api'
|
||||||
|
# and leave StartCmd empty ('').
|
||||||
|
RestartCmd = 'pkill -f "dist/main.js" || true'
|
||||||
|
# Start command. BT Panel does not bring the process back after it is killed,
|
||||||
|
# so we start it ourselves; setsid + nohup keeps it alive after the SSH session ends.
|
||||||
|
# `node` resolves through the NodeBin PATH exported by the remote script.
|
||||||
|
# Leave empty ('') to skip.
|
||||||
|
StartCmd = 'setsid nohup node dist/main.js >> /www/wwwlogs/yelaymaths-api.out.log 2>&1 < /dev/null &'
|
||||||
|
# Probe after start. The deploy fails if this URL does not answer in 30s.
|
||||||
|
HealthUrl = 'http://127.0.0.1:3002/healthz'
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- yelaymaths_admin ----
|
||||||
|
# NOTE: NEXT_PUBLIC_* values are inlined at build time, so .env.local must already
|
||||||
|
# exist on the server before the first deploy. It is never uploaded (it is gitignored
|
||||||
|
# and not in the whitelist).
|
||||||
|
# As with the API, the build runs on your machine and only output is uploaded.
|
||||||
|
Admin = @{
|
||||||
|
Key = 'admin'
|
||||||
|
Label = 'yelaymaths_admin (admin console)'
|
||||||
|
LocalPath = 'yelaymaths_admin'
|
||||||
|
RemotePath = '/www/wwwroot/yelaymaths/yelaymaths_admin'
|
||||||
|
# Build output only: `next start` needs .next and next.config.ts at runtime.
|
||||||
|
DeployPaths = @(
|
||||||
|
'.next',
|
||||||
|
'package.json', 'pnpm-lock.yaml', 'next.config.ts'
|
||||||
|
)
|
||||||
|
# ~73 MB of build cache inside .next is not needed at runtime.
|
||||||
|
ExcludePaths = @('.next/cache', '.next/diagnostics', '.next/trace', '.next/types')
|
||||||
|
# Next serves pre-rendered pages straight from .next/cache instead of reading the files
|
||||||
|
# on disk, so a stale cache means "deployed and restarted, page unchanged".
|
||||||
|
CleanPaths = @('.next/cache')
|
||||||
|
# Same as the API: built locally, never rebuilt on the server.
|
||||||
|
LocalBuildCmd = 'pnpm build'
|
||||||
|
InstallCmd = 'npx --yes pnpm@10.27.0 install --frozen-lockfile'
|
||||||
|
BuildCmd = ''
|
||||||
|
# next start reads pages into memory as well — restart or the old build keeps serving.
|
||||||
|
# 'next-server' is its process name.
|
||||||
|
RestartCmd = 'pkill -f "next-server" || true'
|
||||||
|
# Kill first, then bring it back up ourselves; no BT Panel click needed.
|
||||||
|
StartCmd = 'setsid nohup node node_modules/next/dist/bin/next start -p 3001 >> /www/wwwlogs/yelaymaths-admin.out.log 2>&1 < /dev/null &'
|
||||||
|
HealthUrl = 'http://127.0.0.1:3001/'
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# 复制本文件为 deploy.config.sh 并填写自己的服务器信息。
|
||||||
|
# deploy.config.sh 已 gitignore,服务器地址不会进仓库。
|
||||||
|
|
||||||
|
# ---- SSH ----
|
||||||
|
DEPLOY_HOST='1.2.3.4' # 服务器 IP 或域名
|
||||||
|
DEPLOY_PORT=22
|
||||||
|
DEPLOY_USER='root'
|
||||||
|
|
||||||
|
# 服务器上 Node 的 bin 目录(远端构建时会加进 PATH)。
|
||||||
|
# 宝塔 → 软件商店 → Node 版本管理器里看,例如 /www/server/nodejs/v22.14.0/bin
|
||||||
|
NODE_BIN='/www/server/nodejs/v22/bin'
|
||||||
|
|
||||||
|
# ---- Nginx 反代缓存 ----
|
||||||
|
# 宝塔在 /www/server/nginx/conf/proxy.conf 里全局开了 proxy_cache cache_one,
|
||||||
|
# 而 Next.js 给页面的响应头是 Cache-Control: s-maxage=31536000(允许缓存一年)。
|
||||||
|
# 两者一叠加,新构建传上去也访问不到,而旧 HTML 引用的分包早被删掉,页面会整块消失。
|
||||||
|
# 部署脚本每次清一次这个目录并 reload。留空则跳过。
|
||||||
|
NGINX_CACHE_DIR='/www/server/nginx/proxy_cache_dir'
|
||||||
|
NGINX_BIN='/www/server/nginx/sbin/nginx'
|
||||||
|
|
||||||
|
# ---- yelaymaths_api ----
|
||||||
|
API_LABEL='yelaymaths_api (server API)'
|
||||||
|
API_LOCAL='yelaymaths_api'
|
||||||
|
API_REMOTE='/www/wwwroot/yelaymaths/yelaymaths_api'
|
||||||
|
API_PATHS='src prisma tools package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.json tsconfig.build.json nest-cli.json .env.example'
|
||||||
|
API_EXCLUDES=''
|
||||||
|
# 部署前先在服务器上删掉的旧目录(留空表示不删)
|
||||||
|
API_CLEAN=''
|
||||||
|
API_LOCAL_BUILD='' # 想在本机构建就填 'pnpm build',一般留空
|
||||||
|
API_INSTALL='pnpm install --frozen-lockfile'
|
||||||
|
API_BUILD='pnpm build'
|
||||||
|
# 重启命令:杀掉旧进程。服务器上执行 pm2 list 看真实进程名。
|
||||||
|
API_RESTART='pm2 restart yelaymaths-api'
|
||||||
|
# 拉起命令:宝塔不会自动把进程拉回来,所以自己 setsid + nohup 起。留空则只杀不拉。
|
||||||
|
API_START='setsid nohup node dist/main.js >> /www/wwwlogs/yelaymaths-api.out.log 2>&1 < /dev/null &'
|
||||||
|
API_HEALTH='http://127.0.0.1:3002/healthz'
|
||||||
|
|
||||||
|
# ---- yelaymaths_admin ----
|
||||||
|
# 注意:NEXT_PUBLIC_* 是构建时写死的,.env.local 必须在服务器上先准备好(脚本不会上传它)。
|
||||||
|
ADMIN_LABEL='yelaymaths_admin (admin console)'
|
||||||
|
ADMIN_LOCAL='yelaymaths_admin'
|
||||||
|
ADMIN_REMOTE='/www/wwwroot/yelaymaths/yelaymaths_admin'
|
||||||
|
ADMIN_PATHS='src package.json pnpm-lock.yaml tsconfig.json next.config.ts postcss.config.mjs'
|
||||||
|
ADMIN_EXCLUDES=''
|
||||||
|
# Next 的预渲染缓存在 .next/cache 里,命中就不读磁盘新文件,所以每次先删掉重建
|
||||||
|
ADMIN_CLEAN='.next/cache'
|
||||||
|
ADMIN_LOCAL_BUILD=''
|
||||||
|
ADMIN_INSTALL='pnpm install --frozen-lockfile'
|
||||||
|
ADMIN_BUILD='pnpm build'
|
||||||
|
ADMIN_RESTART='pm2 restart yelaymaths-admin'
|
||||||
|
ADMIN_START='setsid nohup node node_modules/next/dist/bin/next start -p 3001 >> /www/wwwlogs/yelaymaths-admin.out.log 2>&1 < /dev/null &'
|
||||||
|
ADMIN_HEALTH='http://127.0.0.1:3001/'
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
#Requires -Version 5.1
|
||||||
|
<#
|
||||||
|
One-command deploy for yelaymaths_api / yelaymaths_admin.
|
||||||
|
|
||||||
|
Packs source files locally, uploads over SSH, builds on the server and restarts the process.
|
||||||
|
No service is installed on the server; it reuses the SSH access you already have.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
.\deploy\deploy.ps1 api
|
||||||
|
.\deploy\deploy.ps1 admin
|
||||||
|
.\deploy\deploy.ps1 all
|
||||||
|
.\deploy\deploy.ps1 api -DryRun # pack only, show what would be uploaded
|
||||||
|
.\deploy\deploy.ps1 api -WithInstall # also install dependencies (only after package.json changes)
|
||||||
|
|
||||||
|
Files are packed from an explicit whitelist, so .env / node_modules / dist / .next
|
||||||
|
are never uploaded and your server-side .env stays untouched.
|
||||||
|
#>
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[ValidateSet('api', 'admin', 'all')]
|
||||||
|
[string]$Target = 'all',
|
||||||
|
[switch]$DryRun,
|
||||||
|
[switch]$WithInstall
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$OutputEncoding = New-Object System.Text.UTF8Encoding $false
|
||||||
|
|
||||||
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
$repoRoot = Split-Path -Parent $scriptDir
|
||||||
|
$configPath = Join-Path $scriptDir 'deploy.config.ps1'
|
||||||
|
|
||||||
|
if (-not (Test-Path $configPath)) {
|
||||||
|
Write-Host 'ERROR: deploy.config.ps1 not found.' -ForegroundColor Red
|
||||||
|
Write-Host 'Copy deploy.config.example.ps1 to deploy.config.ps1 and fill in your server details.'
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
. $configPath
|
||||||
|
|
||||||
|
foreach ($exe in @('ssh', 'scp', 'tar')) {
|
||||||
|
if (-not (Get-Command $exe -ErrorAction SilentlyContinue)) {
|
||||||
|
throw "Missing required command: $exe (Windows 10+ ships OpenSSH and tar)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sshTarget = '{0}@{1}' -f $Config.User, $Config.Host
|
||||||
|
|
||||||
|
function Invoke-AppDeploy {
|
||||||
|
param([hashtable]$App)
|
||||||
|
|
||||||
|
$local = Join-Path $repoRoot $App.LocalPath
|
||||||
|
if (-not (Test-Path $local)) { throw "Local path not found: $local" }
|
||||||
|
|
||||||
|
# Whitelist: only include paths that exist. Everything else (secrets, build output)
|
||||||
|
# is structurally impossible to upload.
|
||||||
|
$items = @()
|
||||||
|
foreach ($p in $App.DeployPaths) {
|
||||||
|
if (Test-Path (Join-Path $local $p)) { $items += $p }
|
||||||
|
}
|
||||||
|
if ($items.Count -eq 0) { throw "Nothing to deploy for $($App.Key)" }
|
||||||
|
|
||||||
|
$excludes = @()
|
||||||
|
foreach ($p in ($App.ExcludePaths ?? @())) { $excludes += "--exclude=$p" }
|
||||||
|
|
||||||
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
||||||
|
$tarName = 'yelay-{0}-{1}.tar.gz' -f $App.Key, $stamp
|
||||||
|
$tarFile = Join-Path $env:TEMP $tarName
|
||||||
|
$remoteTar = '/tmp/' + $tarName
|
||||||
|
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host ('=== {0} ===' -f $App.Label) -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# ---- 本地构建:把耗时的编译放在本机,服务器只接收产物 ----
|
||||||
|
if ($App.LocalBuildCmd) {
|
||||||
|
Write-Host ('[1/5] Building locally: {0}' -f $App.LocalBuildCmd)
|
||||||
|
# 国内拉取 Prisma 引擎很慢,指向镜像
|
||||||
|
$env:PRISMA_ENGINES_MIRROR = 'https://registry.npmmirror.com/-/binary/prisma'
|
||||||
|
Push-Location $local
|
||||||
|
try {
|
||||||
|
Invoke-Expression $App.LocalBuildCmd
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "Local build failed: $($App.LocalBuildCmd)" }
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host '[1/5] Skipping local build'
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ('[2/5] Packing {0}' -f $App.LocalPath)
|
||||||
|
Push-Location $local
|
||||||
|
try {
|
||||||
|
& tar -czf $tarFile @excludes @items
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'tar failed' }
|
||||||
|
} finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
$sizeKb = [math]::Round((Get-Item $tarFile).Length / 1KB, 1)
|
||||||
|
Write-Host (' {0} KB ({1})' -f $sizeKb, ($items -join ', '))
|
||||||
|
|
||||||
|
if ($DryRun) {
|
||||||
|
Write-Host ' DryRun: nothing uploaded.'
|
||||||
|
Remove-Item $tarFile -Force
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ('[3/5] Uploading to {0}' -f $App.RemotePath)
|
||||||
|
& scp -P $Config.Port -q $tarFile ('{0}:{1}' -f $sshTarget, $remoteTar)
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'scp failed' }
|
||||||
|
|
||||||
|
$install = ''
|
||||||
|
if ($WithInstall) { $install = $App.InstallCmd }
|
||||||
|
|
||||||
|
# 部署前先在服务器上删掉指定的旧目录。
|
||||||
|
#
|
||||||
|
# 为什么必须要这一步:Next.js 会把预渲染好的页面缓存在 .next/cache 里,
|
||||||
|
# 命中时直接返回缓存(响应头 x-nextjs-cache: HIT),不再读磁盘上的新文件。
|
||||||
|
# 而 .next/cache 体积很大(约 73MB),上传时会排除掉,于是它永远是旧的 ——
|
||||||
|
# 表现就是「代码传上去了、也重启了,页面却一直没变」。这里先删掉,让它重建。
|
||||||
|
$cleanCmd = ''
|
||||||
|
foreach ($p in ($App.CleanPaths ?? @())) {
|
||||||
|
$cleanCmd += "rm -rf '$($App.RemotePath)/$p'`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 部署后清空 Nginx 反代缓存。
|
||||||
|
#
|
||||||
|
# 为什么必须清:宝塔在 /www/server/nginx/conf/proxy.conf 里全局开了
|
||||||
|
# proxy_cache cache_one,而 Next.js 给静态页面发的响应头是
|
||||||
|
# Cache-Control: s-maxage=31536000,等于告诉 Nginx「这一页可以存一年」。
|
||||||
|
# 于是新构建传上去、进程也重启了,访问到的还是缓存的旧 HTML;旧 HTML
|
||||||
|
# 引用的分包早被新构建删掉,一请求就是 404,页面渲染到一半就断,
|
||||||
|
# 表现就是「怎么改都不生效」,甚至某个区块整块消失。
|
||||||
|
# 清掉缓存目录再 reload,让它回源读新构建。
|
||||||
|
$nginxCacheCmd = ''
|
||||||
|
if ($Config.NginxCacheDir) {
|
||||||
|
$nginxCacheCmd += "find '$($Config.NginxCacheDir)' -mindepth 1 -delete 2>/dev/null || true`n"
|
||||||
|
if ($Config.NginxBin) {
|
||||||
|
$nginxCacheCmd += "'$($Config.NginxBin)' -s reload 2>/dev/null || true`n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动命令。
|
||||||
|
#
|
||||||
|
# RestartCmd 只负责杀掉旧进程,宝塔不会自动把新进程拉起来,
|
||||||
|
# 所以这里自己拉。先 sleep 2 是为了让刚被杀掉的进程彻底放开端口,
|
||||||
|
# 否则新进程会 EADDRINUSE 起不来。
|
||||||
|
$startCmd = ''
|
||||||
|
if ($App.StartCmd) {
|
||||||
|
$startCmd = "sleep 2`n$($App.StartCmd)`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动后探活:确认端口真的在响应,而不是「命令敲下去就当成功」。
|
||||||
|
# 30 秒还没起来就让部署直接失败,免得又出现「显示部署成功、线上却是 502」。
|
||||||
|
$healthCmd = ''
|
||||||
|
if ($App.HealthUrl) {
|
||||||
|
$healthCmd = "for i in {1..30}; do curl -sf -o /dev/null '$($App.HealthUrl)' && break; sleep 1; done`n"
|
||||||
|
$healthCmd += "curl -sf -o /dev/null '$($App.HealthUrl)' || { echo 'ERROR: service did not come up: $($App.HealthUrl)'; exit 1; }`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remote script is intentionally ASCII-only to avoid encoding issues over SSH.
|
||||||
|
$remoteScript = @"
|
||||||
|
set -e
|
||||||
|
export PATH=$($Config.NodeBin):`$PATH
|
||||||
|
mkdir -p '$($App.RemotePath)'
|
||||||
|
cd '$($App.RemotePath)'
|
||||||
|
$cleanCmd
|
||||||
|
tar -xzf '$remoteTar'
|
||||||
|
rm -f '$remoteTar'
|
||||||
|
$install
|
||||||
|
$($App.BuildCmd)
|
||||||
|
$($App.RestartCmd)
|
||||||
|
$startCmd
|
||||||
|
$healthCmd
|
||||||
|
$nginxCacheCmd
|
||||||
|
echo '__DEPLOY_DONE__'
|
||||||
|
"@
|
||||||
|
|
||||||
|
Write-Host '[4/5] Running on server'
|
||||||
|
$remoteScript | & ssh -p $Config.Port $sshTarget 'bash -s'
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'remote build or restart failed' }
|
||||||
|
|
||||||
|
Remove-Item $tarFile -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($App.RestartCmd) {
|
||||||
|
Write-Host '[5/5] Restarted' -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host '[5/5] Done' -ForegroundColor Green
|
||||||
|
Write-Host (' NOTE: restart "{0}" from the BT panel now.' -f $App.Label) -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
if ($App.StartCmd) {
|
||||||
|
Write-Host (' Started, health check passed: {0}' -f $App.HealthUrl) -ForegroundColor Green
|
||||||
|
}
|
||||||
|
if ($nginxCacheCmd) {
|
||||||
|
Write-Host ' Nginx proxy cache cleared and reloaded' -ForegroundColor Green
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apps = switch ($Target) {
|
||||||
|
'api' { @($Config.Api) }
|
||||||
|
'admin' { @($Config.Admin) }
|
||||||
|
'all' { @($Config.Api, $Config.Admin) }
|
||||||
|
}
|
||||||
|
|
||||||
|
$started = Get-Date
|
||||||
|
foreach ($app in $apps) { Invoke-AppDeploy -App $app }
|
||||||
|
|
||||||
|
if (-not $DryRun) {
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host ('All done in {0:N1}s' -f ((Get-Date) - $started).TotalSeconds) -ForegroundColor Green
|
||||||
|
}
|
||||||
Executable
+193
@@ -0,0 +1,193 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Mac / Linux 版一键部署,行为与 deploy.ps1 一致。
|
||||||
|
#
|
||||||
|
# ./deploy/deploy.sh api 只部署服务端
|
||||||
|
# ./deploy/deploy.sh admin 只部署管理端
|
||||||
|
# ./deploy/deploy.sh 两个都部署
|
||||||
|
# ./deploy/deploy.sh api --dry-run 只打包、只显示会上传什么,不真传
|
||||||
|
# ./deploy/deploy.sh api --with-install 顺带装依赖(只有改了 package.json 才需要)
|
||||||
|
#
|
||||||
|
# 用白名单打包,.env / node_modules / dist / .next 结构上不可能被传上去。
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
repo_root="$(dirname "$script_dir")"
|
||||||
|
config_file="$script_dir/deploy.config.sh"
|
||||||
|
|
||||||
|
target='all'
|
||||||
|
dry_run=0
|
||||||
|
with_install=0
|
||||||
|
|
||||||
|
# bash 3.2(macOS 自带)在 set -u 下对无参数的 "$@" 会报 unbound variable,所以要加这层保护
|
||||||
|
for arg in ${@+"$@"}; do
|
||||||
|
case "$arg" in
|
||||||
|
api|admin|all) target="$arg" ;;
|
||||||
|
-n|--dry-run) dry_run=1 ;;
|
||||||
|
--with-install) with_install=1 ;;
|
||||||
|
-h|--help) sed -n '2,13p' "$0"; exit 0 ;;
|
||||||
|
# ${arg} 必须带花括号:紧跟中文时 bash 会把多字节字符合进变量名
|
||||||
|
*) echo "未知参数:${arg}(可用:api | admin | all | --dry-run | --with-install)" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -f "$config_file" ]; then
|
||||||
|
echo 'ERROR: 找不到 deploy.config.sh' >&2
|
||||||
|
echo '把 deploy/deploy.config.example.sh 复制成 deploy/deploy.config.sh,填好服务器信息再跑。' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$config_file"
|
||||||
|
|
||||||
|
for cmd in ssh scp tar; do
|
||||||
|
command -v "$cmd" >/dev/null 2>&1 || { echo "缺少命令:$cmd" >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
ssh_target="$DEPLOY_USER@$DEPLOY_HOST"
|
||||||
|
|
||||||
|
# 读配置里的某一项,如 val API_LABEL
|
||||||
|
val() {
|
||||||
|
local out
|
||||||
|
eval "out=\${$1:-}"
|
||||||
|
printf '%s' "$out"
|
||||||
|
}
|
||||||
|
|
||||||
|
deploy_app() {
|
||||||
|
local key="$1"
|
||||||
|
local up label local_path remote_path paths excludes clean local_build
|
||||||
|
local install build restart start health nginx_cache nginx_bin
|
||||||
|
up="$(printf '%s' "$key" | tr '[:lower:]' '[:upper:]')"
|
||||||
|
|
||||||
|
label="$(val "${up}_LABEL")"
|
||||||
|
local_path="$repo_root/$(val "${up}_LOCAL")"
|
||||||
|
remote_path="$(val "${up}_REMOTE")"
|
||||||
|
paths="$(val "${up}_PATHS")"
|
||||||
|
excludes="$(val "${up}_EXCLUDES")"
|
||||||
|
clean="$(val "${up}_CLEAN")"
|
||||||
|
local_build="$(val "${up}_LOCAL_BUILD")"
|
||||||
|
install="$(val "${up}_INSTALL")"
|
||||||
|
build="$(val "${up}_BUILD")"
|
||||||
|
restart="$(val "${up}_RESTART")"
|
||||||
|
start="$(val "${up}_START")"
|
||||||
|
health="$(val "${up}_HEALTH")"
|
||||||
|
|
||||||
|
[ -d "$local_path" ] || { echo "本地目录不存在:$local_path" >&2; exit 1; }
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
echo "=== $label ==="
|
||||||
|
|
||||||
|
# ---- 本地构建(默认关,配了 $X_LOCAL_BUILD 才跑)----
|
||||||
|
if [ -n "$local_build" ]; then
|
||||||
|
echo "[1/5] Building locally: $local_build"
|
||||||
|
# 国内拉 Prisma 引擎很慢,指向镜像
|
||||||
|
( cd "$local_path" && PRISMA_ENGINES_MIRROR='https://registry.npmmirror.com/-/binary/prisma' bash -c "$local_build" )
|
||||||
|
else
|
||||||
|
echo '[1/5] Skipping local build'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ---- 打包:只收白名单里存在的路径 ----
|
||||||
|
echo "[2/5] Packing $(val "${up}_LOCAL")"
|
||||||
|
local stamp tar_file remote_tar items
|
||||||
|
stamp="$(date +%Y%m%d-%H%M%S)"
|
||||||
|
tar_file="${TMPDIR:-/tmp}/yelay-${key}-${stamp}.tar.gz"
|
||||||
|
remote_tar="/tmp/$(basename "$tar_file")"
|
||||||
|
|
||||||
|
local -a tar_args=()
|
||||||
|
for p in $excludes; do tar_args+=("--exclude=$p"); done
|
||||||
|
local -a file_args=()
|
||||||
|
for p in $paths; do
|
||||||
|
[ -e "$local_path/$p" ] && file_args+=("$p")
|
||||||
|
done
|
||||||
|
[ ${#file_args[@]} -gt 0 ] || { echo "白名单里没有任何存在的路径:$paths" >&2; exit 1; }
|
||||||
|
|
||||||
|
( cd "$local_path" && tar -czf "$tar_file" ${tar_args[@]+"${tar_args[@]}"} "${file_args[@]}" )
|
||||||
|
|
||||||
|
local size_kb
|
||||||
|
size_kb=$(( $(wc -c < "$tar_file") / 1024 ))
|
||||||
|
echo " ${size_kb} KB ($(printf '%s, ' "${file_args[@]}" | sed 's/, $//'))"
|
||||||
|
|
||||||
|
if [ "$dry_run" = 1 ]; then
|
||||||
|
echo ' DryRun: nothing uploaded.'
|
||||||
|
rm -f "$tar_file"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[3/5] Uploading to $remote_path"
|
||||||
|
scp -P "$DEPLOY_PORT" -q "$tar_file" "$ssh_target:$remote_tar"
|
||||||
|
|
||||||
|
# ---- 拼远端脚本 ----
|
||||||
|
local clean_cmd=''
|
||||||
|
for p in $clean; do clean_cmd="$clean_cmd
|
||||||
|
rm -rf '$remote_path/$p'"; done
|
||||||
|
|
||||||
|
local install_cmd=''
|
||||||
|
[ "$with_install" = 1 ] && install_cmd="$install"
|
||||||
|
|
||||||
|
local start_cmd=''
|
||||||
|
# 先 sleep 2 让刚被杀的进程彻底放开端口,否则新进程会 EADDRINUSE
|
||||||
|
[ -n "$start" ] && start_cmd="sleep 2
|
||||||
|
$start"
|
||||||
|
|
||||||
|
# 探活:30 秒还没起来就让部署直接失败,免得「显示成功、线上 502」
|
||||||
|
local health_cmd=''
|
||||||
|
if [ -n "$health" ]; then
|
||||||
|
health_cmd="for i in {1..30}; do curl -sf -o /dev/null '$health' && break; sleep 1; done
|
||||||
|
curl -sf -o /dev/null '$health' || { echo 'ERROR: service did not come up: $health'; exit 1; }"
|
||||||
|
fi
|
||||||
|
|
||||||
|
nginx_cache="$(val NGINX_CACHE_DIR)"
|
||||||
|
nginx_bin="$(val NGINX_BIN)"
|
||||||
|
local nginx_cmd=''
|
||||||
|
if [ -n "$nginx_cache" ]; then
|
||||||
|
nginx_cmd="find '$nginx_cache' -mindepth 1 -delete 2>/dev/null || true"
|
||||||
|
[ -n "$nginx_bin" ] && nginx_cmd="$nginx_cmd
|
||||||
|
'$nginx_bin' -s reload 2>/dev/null || true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 远端脚本保持 ASCII 注释,避免 SSH 传输编码问题
|
||||||
|
local remote_script
|
||||||
|
remote_script="$(cat <<REMOTE
|
||||||
|
set -e
|
||||||
|
export PATH=${NODE_BIN}:\$PATH
|
||||||
|
mkdir -p '$remote_path'
|
||||||
|
cd '$remote_path'
|
||||||
|
$clean_cmd
|
||||||
|
# macOS 打的包带 com.apple.provenance 之类的 xattr 头,GNU tar 每条警告一行,刷屏且无用
|
||||||
|
tar --warning=no-unknown-keyword -xzf '$remote_tar'
|
||||||
|
rm -f '$remote_tar'
|
||||||
|
$install_cmd
|
||||||
|
$build
|
||||||
|
$restart
|
||||||
|
$start_cmd
|
||||||
|
$health_cmd
|
||||||
|
$nginx_cmd
|
||||||
|
echo '__DEPLOY_DONE__'
|
||||||
|
REMOTE
|
||||||
|
)"
|
||||||
|
|
||||||
|
echo '[4/5] Running on server'
|
||||||
|
ssh -p "$DEPLOY_PORT" "$ssh_target" 'bash -s' <<< "$remote_script"
|
||||||
|
|
||||||
|
rm -f "$tar_file"
|
||||||
|
|
||||||
|
if [ -n "$restart" ]; then
|
||||||
|
echo '[5/5] Restarted'
|
||||||
|
else
|
||||||
|
echo '[5/5] Done'
|
||||||
|
echo " NOTE: 去宝塔面板手动重启 $label"
|
||||||
|
fi
|
||||||
|
[ -n "$start" ] && echo " Started, health check passed: $health"
|
||||||
|
[ -n "$nginx_cmd" ] && echo ' Nginx proxy cache cleared and reloaded'
|
||||||
|
}
|
||||||
|
|
||||||
|
started_at=$(date +%s)
|
||||||
|
case "$target" in
|
||||||
|
api) deploy_app api ;;
|
||||||
|
admin) deploy_app admin ;;
|
||||||
|
all) deploy_app api; deploy_app admin ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ "$dry_run" = 1 ] || echo "
|
||||||
|
All done in $(( $(date +%s) - started_at ))s"
|
||||||
+247
@@ -0,0 +1,247 @@
|
|||||||
|
# 课程上线指南
|
||||||
|
|
||||||
|
面向「要往小程序里上一门新课」的人。按第 7 节的顺序做,每一步都有验证方法。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. 先理解三件事
|
||||||
|
|
||||||
|
1. **数据分两处**:课程 / 课时的**文字信息**在数据库里(管理后台改的就是它);
|
||||||
|
**视频和图片**在数据端,是磁盘上的文件。
|
||||||
|
2. **付费课时不是 mp4**,是 HLS 目录(一个 `playlist.m3u8` + 一堆 `.ts` 分片)。
|
||||||
|
3. **媒体文件不在云服务器上**。数据域名整站反代到隧道另一端(NAS),服务端播放视频也走同一条路。
|
||||||
|
所以文件最终要落到 NAS 上对应的目录里,放对位置就立刻生效。
|
||||||
|
|
||||||
|
> ⚠️ 目前**还没有后台上传功能**。文件要手工(或打包成 zip)放到 NAS 的对应目录,
|
||||||
|
> 再回管理后台填表单。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 三个不能随便起的名字
|
||||||
|
|
||||||
|
这三个名字一旦定下来就**不要改**,它们是文件路径的一部分:
|
||||||
|
|
||||||
|
| 名字 | 同时还是 |
|
||||||
|
|---|---|
|
||||||
|
| `courses.code` | 视频目录名 `Course/{code}/` 和封面名 `Course/{code}.png` |
|
||||||
|
| `lessons.chapter_id` | 目录中的一级:`Course/{code}/{chapter_id}/` |
|
||||||
|
| `lessons.play_id` | 目录中的二级:`Course/{code}/{chapter_id}/{play_id}/` |
|
||||||
|
|
||||||
|
改其中任何一个,已经发出去的播放地址、封面、以及用户端的缓存全部失效。
|
||||||
|
|
||||||
|
另外一批名字是**拼出来的**,由后台填的文字决定,同样不能随手改:
|
||||||
|
|
||||||
|
| 小程序里的地址 | 由什么拼出来 |
|
||||||
|
|---|---|
|
||||||
|
| `Course/{code}.png` | 课程 `code` |
|
||||||
|
| `Images/NewCourse/{条目名}.png` | 首页新课的 `course_name` |
|
||||||
|
| `Images/FreeCourse/{条目名}.png` | 首页试听的 `course_name` |
|
||||||
|
| `Images/Banner/{文件名}` | 轮播图的 `filename`(含扩展名) |
|
||||||
|
| `WebPages/{网页id}.png` | 文章的 `legacy_page_id` |
|
||||||
|
|
||||||
|
现网示例:`code` 是 64 位十六进制,`chapter_id` 是 `1`、`2`、`3`,
|
||||||
|
`play_id` 是 13 位十六进制(如 `65eefb35e29da`)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 要准备的文件
|
||||||
|
|
||||||
|
假设新课的 `code` 是 `AbC...`(64 位),有三个章节、每章两个课时:
|
||||||
|
|
||||||
|
```
|
||||||
|
Course/AbC....png ← 课程封面,1 张
|
||||||
|
Course/AbC.../1/65eefb35e29da/playlist.m3u8 ← 课时 1
|
||||||
|
Course/AbC.../1/65eefb35e29da/0000.ts 0001.ts ... ← 该课时的分片
|
||||||
|
Course/AbC.../1/65eefb35e29db/playlist.m3u8 ← 课时 2
|
||||||
|
Course/AbC.../2/65eefb50f02b5/playlist.m3u8 ← 课时 3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
如果这门课还要上首页,另外准备:
|
||||||
|
|
||||||
|
| 用途 | 文件 | 引用方式 |
|
||||||
|
|---|---|---|
|
||||||
|
| 首页「新课上线」列表图 | `Images/NewCourse/{条目名}.png` | 按 `course_name` 拼 |
|
||||||
|
| 首页「新课上线」长图内页 | `Images/NewCourseWebPages/{分组名}/{n}.png` | 写在长图 HTML 里 |
|
||||||
|
| 首页「试听」列表图 | `Images/FreeCourse/{条目名}.png` | 按 `course_name` 拼 |
|
||||||
|
| 免费试听视频 | `FreeVideos/{任意目录}/{任意名}.m3u8` + 分片 | 路径存在数据库字段里 |
|
||||||
|
|
||||||
|
**图片规格参考**
|
||||||
|
|
||||||
|
- 课程封面:现网是 **900×500**(后台卡片按 9:5 显示,整张完整展示不裁剪)。
|
||||||
|
- 新课长图:现网每张 **800px 宽**,高度按内容(实测一张 800×564)。所有图宽度保持一致。
|
||||||
|
- 首页列表图:按名称拼 `.png`,建议和长图同宽或按 2 倍图准备。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. HLS 打包要求
|
||||||
|
|
||||||
|
现网一个真实的 `playlist.m3u8`:
|
||||||
|
|
||||||
|
```
|
||||||
|
#EXTM3U
|
||||||
|
#EXT-X-VERSION:3
|
||||||
|
#EXT-X-TARGETDURATION:4
|
||||||
|
#EXT-X-MEDIA-SEQUENCE:0
|
||||||
|
#EXTINF:4.166667,
|
||||||
|
0000.ts
|
||||||
|
#EXTINF:4.166667,
|
||||||
|
0001.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
四条硬要求:
|
||||||
|
|
||||||
|
1. **分片引用必须是相对路径**(`0000.ts`),不能写 `http://...` 绝对地址。
|
||||||
|
服务端会给每一行分片单独签名,绝对地址会被跳过——防盗链直接失效,播放器还会绕过服务端直连。
|
||||||
|
2. **文件名必须叫 `playlist.m3u8`**。这个名是服务端写死的,不是数据库里的字段。
|
||||||
|
3. **目录名只用字母数字**。`chapter_id` / `play_id` 参与播放地址的拼接与签名,中文和空格容易踩坑。
|
||||||
|
4. **目录里不要放无关文件**,整棵目录树都在签名保护下。
|
||||||
|
|
||||||
|
其余参数(切片时长、编码、加密)没有强制要求,按上面的形状切即可。
|
||||||
|
如果做了 HLS 加密,`.key` 文件要放在同一目录树内,`EXT-X-KEY` 的 URI 也用相对路径。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 首页新课长图的内容要求
|
||||||
|
|
||||||
|
「长图」不是一张图片文件,而是 `home_courses.content` 里的一段 **HTML**,
|
||||||
|
服务端原样返回,小程序用内置的 Parser 组件渲染。现网真实内容:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p style="font-size: 0; margin: 0; padding: 0;">
|
||||||
|
<img src="https://<数据域名>/Images/NewCourseWebPages/几何模型/1.png"/>
|
||||||
|
<img src="https://<数据域名>/Images/NewCourseWebPages/几何模型/2.png"/>
|
||||||
|
<img src="https://<数据域名>/Images/NewCourseWebPages/几何模型/3.png"/>
|
||||||
|
</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
要求:
|
||||||
|
|
||||||
|
1. **图片必须是绝对 URL**(带 `https://<数据域名>`)。写相对路径会裂图——小程序会把 `/xxx.png` 当成包内的本地文件。
|
||||||
|
2. **外层 `<p>` 必须带 `font-size: 0`**(通常还带 `margin:0; padding:0`)。少了它,图与图之间会露出白缝,长图就断了。
|
||||||
|
3. **不要给 `<img>` 写 width / height**。渲染时会自动补 `width:100%` 按屏宽缩放;写死像素宽度会溢出屏幕。
|
||||||
|
4. **底部要留白**。长图页底部钉着两个悬浮按钮(购买 / 咨询客服),末尾留一段空白,否则按钮压住内容。
|
||||||
|
5. **只能放静态标签**。`<script>`、`<iframe>`、`<video>` 不会执行。
|
||||||
|
6. 长图里的图片路径是**手写在 HTML 里**的,改名或挪目录内容不会跟着变,会直接 404。所以图片一次定稿再填。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 后台要填的表单
|
||||||
|
|
||||||
|
### 课程(管理后台 → 课程)
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| code | 64 位十六进制串,**创建后不可改** |
|
||||||
|
| title | 课程名 |
|
||||||
|
| intro | 一句话介绍 |
|
||||||
|
| price_fen | 价格,单位**分**(1.10 元填 110) |
|
||||||
|
| status / sort_order | 上架状态、排序 |
|
||||||
|
|
||||||
|
### 课时(管理后台 → 课时,每个视频一行)
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| course_id | 所属课程 |
|
||||||
|
| chapter_id / play_id | 必须和磁盘目录**逐字对应** |
|
||||||
|
| chapter_title / lesson_title | 章节名、视频名 |
|
||||||
|
| duration | 现网存的是分钟数,如 `14`、`21` |
|
||||||
|
| published_at / sort_order | 发布日期、排序 |
|
||||||
|
|
||||||
|
约束:`(course_id, chapter_id, play_id)` 唯一——同一章里不能有重复的 `play_id`。
|
||||||
|
|
||||||
|
### 支付商品(管理后台 → 支付商品,要卖就得填)
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| course_id | 对应课程 |
|
||||||
|
| wx_product_id | 微信后台的道具 ID |
|
||||||
|
| price_fen | **必须和微信后台道具价格完全一致**,否则下单会被拒 |
|
||||||
|
| name / status | 商品名、是否启用 |
|
||||||
|
|
||||||
|
### 首页新课(管理后台 → 首页新课,要上首页才填)
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| course_name | 条目名,**决定列表缩略图** `Images/NewCourse/{条目名}.png` |
|
||||||
|
| content | 第 4 节那段长图 HTML |
|
||||||
|
| course_id | 关联到可购买的课程;**留空则长图页不显示购买按钮**,只剩客服按钮 |
|
||||||
|
| intro / published_at / sort_order / status | 列表展示用 |
|
||||||
|
|
||||||
|
### 首页试听(管理后台 → 首页试听 + 免费试听课)
|
||||||
|
|
||||||
|
- 首页试听:`series_no`(要和免费试听课的序号对上)、`course_name`(决定 `Images/FreeCourse/{条目名}.png`)、排序、状态。
|
||||||
|
- 免费试听课:`series_no`、`course_name`、`video_title`、`duration`、`video_m3u8`(如 `FreeVideos/9102/9102.m3u8`)、`cover_image`(如 `Images/FreeCourse/xxx.png`)。
|
||||||
|
**这两个字段是数据库里存的全路径**,不是拼出来的,可以自由命名。
|
||||||
|
|
||||||
|
> 注意:课程表 / 首页新课 / 课时表里都有一个「封面文件 / cover_image」字段,
|
||||||
|
> **接口目前不使用它们**,真正生效的是第 1 节里「拼出来的」那些地址。
|
||||||
|
> 只有免费试听课的 `cover_image` 是真正生效的。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 微信小程序后台要先做的
|
||||||
|
|
||||||
|
要在小程序里卖这门课,必须先建支付道具:
|
||||||
|
|
||||||
|
1. 【虚拟支付 → 道具管理】新建道具,拿到**道具 ID** 与价格。
|
||||||
|
2. 价格记下来,后台「支付商品」里要填一模一样的分值。
|
||||||
|
3. 道具建好后要**发布**,未发布的道具下不了单。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 操作顺序
|
||||||
|
|
||||||
|
| 步骤 | 做什么 | 怎么验证 |
|
||||||
|
|---|---|---|
|
||||||
|
| 1 | 微信后台建支付道具,记下道具 ID 和价格 | 道具状态是已发布 |
|
||||||
|
| 2 | 定下课程的 `code`(64 位十六进制) | —— |
|
||||||
|
| 3 | 把封面和所有课时目录放到数据端对应路径 | 浏览器直接打开 `Course/{code}.png` 能显示 |
|
||||||
|
| 4 | 后台建**课程**行,`code` 填上面那个 | 小程序「知识」页能看到课程、封面正常 |
|
||||||
|
| 5 | 后台建**课时**行,`chapter_id` / `play_id` 和目录逐字对上 | 买过课之后能播放;没买时报「尚未拥有该课程」 |
|
||||||
|
| 6 | 后台建**支付商品**行,价格与微信一致 | 走一笔小额真实订单,能下单成功 |
|
||||||
|
| 7 | 首页要展示的话,建**首页新课 / 首页试听**并填长图 | 首页能看到条目、点进去长图完整、底部按钮不挡内容 |
|
||||||
|
| 8 | 课程 `status` 改为 1(上架) | 小程序下拉刷新后可见 |
|
||||||
|
|
||||||
|
> ⚠️ **上架前先确认后台左上角的「查看的数据源」是生产库。**
|
||||||
|
> 后台有两个概念:「查看的数据源」(只影响你自己看到什么)和「线上小程序数据源」(影响所有用户)。
|
||||||
|
> 在开发库建的课程,用户在线上是看不到的。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 上线后验证清单
|
||||||
|
|
||||||
|
- [ ] 首页能看到新课条目,缩略图正常
|
||||||
|
- [ ] 点进长图页:图片连成一张、没有白缝、底部按钮不挡住内容
|
||||||
|
- [ ] 长图页的「立即支付」按钮存在(说明 `course_id` 关联上了)
|
||||||
|
- [ ] 「知识」页能看到这门课的封面
|
||||||
|
- [ ] 未购买的账号点课程,看不到课时列表
|
||||||
|
- [ ] 走一笔小额真实支付:能拉起支付 → 支付成功后课程出现在「已购」里
|
||||||
|
- [ ] 已购账号能播放每一个课时(不是只测第一个)
|
||||||
|
- [ ] 后台「订单」页能看到这笔订单,状态「已开通」
|
||||||
|
- [ ] 后台「数据看板」的累计订单 +1、成交金额增加
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 常见坑
|
||||||
|
|
||||||
|
| 现象 | 原因 | 处理 |
|
||||||
|
|---|---|---|
|
||||||
|
| 封面 404 | 文件名和 `code` 对不上,或图片没放上去 | 地址必须是 `Course/{code}.png`,逐字核对 |
|
||||||
|
| 播放地址 404 / 播不了 | `chapter_id`、`play_id` 和目录名不一致 | 三处(数据库、目录、表单)必须逐字相同 |
|
||||||
|
| 长图断了、有白缝 | 外层 `<p>` 少了 `font-size: 0` | 见第 4 节 |
|
||||||
|
| 长图裂图 | 图片用了相对路径 | 必须写完整的 `https://<数据域名>/...` |
|
||||||
|
| 换了同名图片但没变 | 数据端对图片有 1 分钟缓存 | 等 1 分钟,或清 Nginx 缓存后 reload |
|
||||||
|
| 换了同名视频但播还是旧的 | 播放地址响应头带 5 分钟缓存 | 等 5 分钟;播放地址本身有效期是 30 分钟 |
|
||||||
|
| 下单提示「该课程尚未配置支付商品」 | `products` 里没有启用的商品行 | 见第 5 节 |
|
||||||
|
| 下单后拉不起支付 | 微信道具没发布,或价格与后台不一致 | 见第 6 节 |
|
||||||
|
| 长图页没有购买按钮 | `home_courses.course_id` 为空 | 填上关联课程 |
|
||||||
|
| 改完没生效 | 后台看的是开发库 | 切回生产库再操作 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 相关文档
|
||||||
|
|
||||||
|
- [部署指南.md](部署指南.md):服务端 / 后台 / 数据端怎么部署
|
||||||
|
- [重构开发文档.md](重构开发文档.md):整体设计与数据模型
|
||||||
|
- [数据端 README](../yelaymaths_data.yeomai.site/README.md):数据端目录结构与路径约定
|
||||||
+298
@@ -0,0 +1,298 @@
|
|||||||
|
# 部署指南
|
||||||
|
|
||||||
|
面向接手部署的人。按顺序执行即可,每一步都有验证方法。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. 变量约定
|
||||||
|
|
||||||
|
下文用占位符代替真实域名,部署时替换:
|
||||||
|
|
||||||
|
只需要**三个域名**:管理后台直接调用 `<API域名>`(服务端同一进程内含 `/admin/v1/*`),
|
||||||
|
不需要单独的接口域名。
|
||||||
|
|
||||||
|
| 占位符 | 含义 | 举例 |
|
||||||
|
|---|---|---|
|
||||||
|
| `<API域名>` | 服务端 API 域名 | `yelaymaths-api.example.com` |
|
||||||
|
| `<后台域名>` | 管理后台域名 | `yelaymaths-admin.example.com` |
|
||||||
|
| `<数据域名>` | 课程数据(图片 / 视频)域名 | `yelaymaths-data.example.com` |
|
||||||
|
|
||||||
|
> ⚠️ **三个域名都不能含下划线。** 下划线不是合法的主机名字符(RFC 1034/1035 只允许字母、数字、连字符),
|
||||||
|
> 后果是 Let's Encrypt 拒签证书、微信「request 合法域名」校验也会拒绝。
|
||||||
|
>
|
||||||
|
> 用中划线:`yelaymaths-api.example.com`,不要用 `yelaymaths_api.example.com`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 服务器准备(宝塔面板)
|
||||||
|
|
||||||
|
1. 软件商店安装:**MySQL 5.7**、**Nginx**、**Node 版本管理器**(选 Node 22 LTS)。
|
||||||
|
2. 防火墙放行 80 / 443。
|
||||||
|
3. 建 3 个站点,各配 Let's Encrypt 证书:
|
||||||
|
|
||||||
|
| 站点 | 反向代理到 |
|
||||||
|
|---|---|
|
||||||
|
| `<API域名>` | `http://127.0.0.1:3000` |
|
||||||
|
| `<后台域名>` | `http://127.0.0.1:3001` |
|
||||||
|
|
||||||
|
> 这两个站点**都不是静态站点**,反向代理必须配,只上传文件不会工作。
|
||||||
|
|
||||||
|
4. 建数据端站点 `<数据域名>`,根目录指向课程数据目录(见第 6 节)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 数据库
|
||||||
|
|
||||||
|
1. 新建数据库 `yelaymaths`,字符集 `utf8mb4`。
|
||||||
|
2. 新建数据库账号并授权。
|
||||||
|
|
||||||
|
> **关于 Prisma 权限**:`prisma migrate dev` 需要 `CREATE DATABASE` 权限来建影子库,宝塔默认账号没有。
|
||||||
|
> 生产环境**只用** `pnpm prisma:migrate`(即 `prisma migrate deploy`),它不建影子库,无需额外权限。
|
||||||
|
|
||||||
|
3. **备份旧库**(迁移前必做):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysqldump -u <用户> -p api_yeomai_site > /root/backup/api_yeomai_site_$(date +%F).sql
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 部署服务端
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /www/wwwroot
|
||||||
|
git clone <仓库地址> yelaymaths
|
||||||
|
cd yelaymaths/yelaymaths_api
|
||||||
|
pnpm install
|
||||||
|
cp .env.example .env
|
||||||
|
vi .env # 按下表填写
|
||||||
|
```
|
||||||
|
|
||||||
|
### 必须填写的环境变量
|
||||||
|
|
||||||
|
| 变量 | 说明 |
|
||||||
|
|---|---|
|
||||||
|
| `DATABASE_URL` | `mysql://用户:密码@127.0.0.1:3306/yelaymaths` |
|
||||||
|
| `LEGACY_DATABASE_URL` | 旧库连接串,仅迁移脚本使用 |
|
||||||
|
| `API_BASE_URL` | `https://<API域名>` |
|
||||||
|
| `STATIC_BASE_URL` | `https://<数据域名>` |
|
||||||
|
| `ADMIN_ORIGIN` | `https://<后台域名>`(跨域白名单) |
|
||||||
|
| `JWT_ACCESS_SECRET` | 随机 32 位以上 |
|
||||||
|
| `JWT_REFRESH_SECRET` | 随机 32 位以上 |
|
||||||
|
| `SESSION_KEY_ENC_SECRET` | 随机 32 位以上,用于加密存储用户 sessionKey |
|
||||||
|
| `MEDIA_SIGN_SECRET` | 随机 32 位以上,用于播放地址签名 |
|
||||||
|
| `WX_APPID` | `wx3fbaf897825bf04f` |
|
||||||
|
| `WX_APPSECRET` | 小程序密钥 |
|
||||||
|
| `WX_OFFER_ID` / `WX_PAY_APPKEY` | 虚拟支付参数(现网),未开通可留空 |
|
||||||
|
| `WX_PAY_APPKEY_SANDBOX` | 虚拟支付沙箱密钥,用于上线前试跑 |
|
||||||
|
| `WX_PAY_ENV` | `0` 现网 / `1` 沙箱。改完需重启服务端 |
|
||||||
|
| `DATA_ROOT` | 课程数据目录的**绝对路径** |
|
||||||
|
|
||||||
|
> 生成随机密钥:`openssl rand -hex 32`
|
||||||
|
>
|
||||||
|
> ⚠️ `STATIC_BASE_URL` 必须在跑数据迁移**之前**填对。旧库里有 48 处内容写死了旧域名,
|
||||||
|
> 迁移时会按这个变量改写;填错会导致图片与视频全部 404。
|
||||||
|
|
||||||
|
### 建表、迁移、启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm prisma:generate
|
||||||
|
pnpm prisma:migrate # 建表
|
||||||
|
pnpm legacy:check # 体检
|
||||||
|
pnpm legacy:migrate -- --dry-run # 核对行数
|
||||||
|
pnpm legacy:migrate # 正式迁移
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
在宝塔「Node 项目」里新建项目:
|
||||||
|
|
||||||
|
- 项目目录:`/www/wwwroot/yelaymaths/yelaymaths_api`
|
||||||
|
- 启动文件:`dist/main.js`
|
||||||
|
- 端口:`3000`
|
||||||
|
- 运行方式:PM2
|
||||||
|
|
||||||
|
**验证**:`curl https://<API域名>/healthz` 应返回 `{"code":0,...,"db":"ok"}`。
|
||||||
|
若 `db` 为 `down`,说明数据库连接串不对。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 部署管理后台
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /www/wwwroot/yelaymaths/yelaymaths_admin
|
||||||
|
pnpm install
|
||||||
|
cp .env.example .env.local
|
||||||
|
vi .env.local # NEXT_PUBLIC_API_BASE_URL=https://<API域名>
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
同样用宝塔「Node 项目」启动:
|
||||||
|
|
||||||
|
- 启动文件:`node_modules/next/dist/bin/next`,参数 `start -p 3001`
|
||||||
|
- 或直接用 `pnpm start`
|
||||||
|
- 端口:`3001`
|
||||||
|
|
||||||
|
**验证**:打开 `https://<后台域名>`,应看到登录页。
|
||||||
|
首次使用点「创建管理员账号」,创建完成后切回登录。
|
||||||
|
|
||||||
|
> 该接口只在系统中没有任何管理员时生效,之后调用会返回「已存在」,因此可以安全保留。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 部署课程数据端
|
||||||
|
|
||||||
|
把旧服务器的资源目录复制到 `<数据域名>` 站点根目录:
|
||||||
|
|
||||||
|
| 来源 | 目标 | 体积参考 |
|
||||||
|
|---|---|---|
|
||||||
|
| 旧站 `Images/` | `<根>/Images/` | 约 195 MB |
|
||||||
|
| 旧站 `WebPages/` | `<根>/WebPages/` | 约 21 MB |
|
||||||
|
| 旧站 `Course/` | `<根>/Course/` | 视频文件 |
|
||||||
|
| 旧站 `FreeVideos/` | `<根>/FreeVideos/` | 视频文件 |
|
||||||
|
|
||||||
|
再从旧小程序的 `static/image/` 复制三张占位图到 `<根>/Images/Placeholder/`:
|
||||||
|
|
||||||
|
```
|
||||||
|
Images/Placeholder/user.png
|
||||||
|
Images/Placeholder/defaultAvatar.png
|
||||||
|
Images/Placeholder/weixin.png
|
||||||
|
```
|
||||||
|
|
||||||
|
这三张图是**必需的**,缺了会导致「我的」页头像位、「登录」页背景显示为裂图。
|
||||||
|
验证:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -o /dev/null -s -w "%{http_code}\n" https://<数据域名>/Images/Placeholder/user.png
|
||||||
|
curl -o /dev/null -s -w "%{http_code}\n" https://<数据域名>/Images/Placeholder/weixin.png
|
||||||
|
```
|
||||||
|
|
||||||
|
两条都返回 `200` 才算就绪。
|
||||||
|
|
||||||
|
**目录名与文件名不可更改**,前端是拼路径访问的。完整约定见
|
||||||
|
[`yelaymaths_data.yeomai.site/README.md`](../yelaymaths_data.yeomai.site/README.md)。
|
||||||
|
|
||||||
|
### ⚠️ 付费视频目录必须挡住
|
||||||
|
|
||||||
|
付费视频的鉴权由服务端 `/media/*` 签名通道提供(地址有效期 30 分钟,HLS 的 `.ts` 分片也逐行带签名)。
|
||||||
|
但如果 `Course/` 目录同时被数据域名公开暴露,任何人猜到路径就能直接下载,这套防护等于没有。
|
||||||
|
|
||||||
|
注意 `Course/` 目录里有两类东西,规则要区分对待:
|
||||||
|
|
||||||
|
| 路径 | 内容 | 处理 |
|
||||||
|
|---|---|---|
|
||||||
|
| `Course/{课程code}.png` | 课程封面图 | **必须公开**,小程序课程列表要用 |
|
||||||
|
| `Course/{code}/{章节}/{播放}/playlist.m3u8` | 付费视频 | **必须挡住** |
|
||||||
|
|
||||||
|
**在数据端站点的 Nginx 配置里加这两条(顺序不能反):**
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# Course 目录下的图片(课程封面)放行
|
||||||
|
location ~* ^/Course/.*\.(png|jpe?g|webp|gif)$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Course 目录下的其它内容(视频切片、播放列表)一律拒绝
|
||||||
|
location ~ ^/Course/ {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> 两条都用正则 `location`,放行规则写在前面。Nginx 对正则 location 按书写顺序匹配,
|
||||||
|
> 第一条命中就不再往下走。**不能用 `location ^~ /Course/`** —— `^~` 优先级高于正则,
|
||||||
|
> 会跳过放行规则,导致课程封面也变成 403。
|
||||||
|
|
||||||
|
免费内容(`Images/`、`WebPages/`、`FreeVideos/`)保持公开即可。
|
||||||
|
|
||||||
|
> 若后续改用 CDN,把 `MediaService.buildSignedUrl` 换成 CDN 厂商的签名方式,并在 CDN 侧对 `Course/` 开鉴权。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 配置小程序
|
||||||
|
|
||||||
|
1. 编辑 `yelaymaths/config/index.js`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
API_BASE_URL: 'https://<API域名>',
|
||||||
|
STATIC_BASE_URL: 'https://<数据域名>',
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 用微信开发者工具打开 `yelaymaths/`,执行【工具 → 构建 npm】。
|
||||||
|
3. 上传并提交审核。
|
||||||
|
|
||||||
|
> 小程序**不打包任何业务图片**,只保留 6 个 tabBar 图标(约 19 KB)。
|
||||||
|
> tabBar 图标必须本地,这是微信的限制,无法改为网络图。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 微信小程序后台配置
|
||||||
|
|
||||||
|
| 配置项 | 位置 | 值 |
|
||||||
|
|---|---|---|
|
||||||
|
| request 合法域名 | 开发 → 开发管理 → 开发设置 | `https://<API域名>` |
|
||||||
|
| 消息推送 URL / Token | 开发 → 开发管理 → 消息推送(也是虚拟支付的发货推送地址) | URL 填 `https://<API域名>/v1/payments/notify`;Token 随便生成一串,**要和 `.env` 里的 `WX_MSG_TOKEN` 一致** |
|
||||||
|
| 发货推送 URL | 虚拟支付 → 基本配置 | `https://<API域名>/v1/payments/notify` |
|
||||||
|
| 小程序简称 | 虚拟支付 → 基础配置 | iOS 支付必需 |
|
||||||
|
| 苹果 IAP 支付 | 虚拟支付 → 基础配置 | iOS 支付需开启 |
|
||||||
|
| 支付道具 | 虚拟支付 → 道具管理 | 每门课建一个,记下道具 ID 与价格 |
|
||||||
|
|
||||||
|
> 消息推送的 URL 一保存,微信就会发一个 `GET` 来验签。服务端要是没配 `WX_MSG_TOKEN`
|
||||||
|
> 或两边不一致,页面会一直显示「服务器地址验证失败,请检查服务器配置」,发货推送也就配不上。
|
||||||
|
> 加解密方式选**明文模式**只需 Token;选**安全模式**则 `WX_MSG_AES_KEY` 也要填上后台那串 EncodingAESKey。
|
||||||
|
|
||||||
|
> `<image>` 与 `<video>` 的资源域名**不受合法域名限制**,所以数据域名与 CDN 都不需要加白名单。
|
||||||
|
|
||||||
|
创建完道具后,在管理后台「支付商品」里把 `课程 ID`、`微信道具 ID`、`价格(分)` 填进去,
|
||||||
|
价格必须与微信后台完全一致(单位:分)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 上线顺序
|
||||||
|
|
||||||
|
建议严格按此顺序,每步都可独立验证:
|
||||||
|
|
||||||
|
1. 服务器与数据库就绪 → 备份旧库
|
||||||
|
2. 部署服务端 → `/healthz` 返回 `db: ok`
|
||||||
|
3. 建表 + 数据迁移 → 行数校验通过
|
||||||
|
4. 部署管理后台 → 能登录,用户数与旧库一致
|
||||||
|
5. 部署数据端 → 浏览器直接打开一张图片能显示
|
||||||
|
6. 小程序改配置并上传 → 真机验证:首页图片、试听播放、已购课程播放
|
||||||
|
7. 微信后台配域名与支付 → 用一笔小额真实订单验证:支付 → 发货 → 课程出现在「知识」页
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 上线后验证清单
|
||||||
|
|
||||||
|
- [ ] `/healthz` 返回 `db: ok`
|
||||||
|
- [ ] 管理后台用户数 = 189(旧库 284 行中有 95 行是平台安全扫描留下的探针记录,已过滤)
|
||||||
|
- [ ] 随机挑一个老用户,其「已购课程」与升级前一致
|
||||||
|
- [ ] 首页轮播、新课长图、试听封面图片全部能加载
|
||||||
|
- [ ] `pages/VideoDetailsPage/VideoDetailsPage` 的公式图能显示
|
||||||
|
- [ ] 免费试听能播放
|
||||||
|
- [ ] 已购课程能播放(走 `/media/...` 签名地址)
|
||||||
|
- [ ] 未登录状态下访问受保护页面会跳转登录
|
||||||
|
- [ ] 未购买课程看不到课时列表(直接请求接口返回 3000 错误码)
|
||||||
|
- [ ] 支付一笔小额订单,课程正确开通
|
||||||
|
- [ ] 管理后台能看到这笔订单,状态为「已开通」
|
||||||
|
- [ ] **数据端已加 `Course/` 防盗链规则**,且「知识」页课程封面正常显示(200)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 回滚
|
||||||
|
|
||||||
|
- 旧服务端与旧数据库**保留不动**,直到新系统稳定运行一段时间。
|
||||||
|
- 小程序出现严重问题时,可在微信后台回退到上一个版本。
|
||||||
|
- 数据库出问题时用第 2 节的备份恢复。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 11. 安全提醒
|
||||||
|
|
||||||
|
以下密钥曾在旧代码与数据库导出文件中明文出现,**必须全部轮换**:
|
||||||
|
|
||||||
|
- 旧数据库账号密码
|
||||||
|
- 阿里云 AccessKey(旧短信模块使用,该模块已删除)
|
||||||
|
- 163 邮箱授权码(旧邮件脚本使用,已删除)
|
||||||
|
- 小程序 AppSecret
|
||||||
|
|
||||||
|
> ⚠️ **AppSecret 不能提前换**。旧 PHP 服务仍在使用它,一换线上小程序立刻无法登录。
|
||||||
|
> 正确做法是:新后端上线并确认可用后,再在微信后台重置 AppSecret 并同步更新新后端配置。
|
||||||
+1
-1
@@ -135,7 +135,7 @@
|
|||||||
|
|
||||||
| 旧表 | 新表 | 处理 |
|
| 旧表 | 新表 | 处理 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `用户信息` (284) | `users` | 迁移,结构重写 |
|
| `用户信息` (284 行 / 189 个真实用户) | `users` | 迁移,结构重写;非 openid 形态的 95 行攻击载荷会被过滤 |
|
||||||
| `用户已购课程` (48) | `entitlements` | 迁移为 `source = legacy` |
|
| `用户已购课程` (48) | `entitlements` | 迁移为 `source = legacy` |
|
||||||
| `课程口令码读取信息` (10) | `courses` | 升级为正式课程表 |
|
| `课程口令码读取信息` (10) | `courses` | 升级为正式课程表 |
|
||||||
| `视频课程数据` (841) | `lessons` | 迁移 |
|
| `视频课程数据` (841) | `lessons` | 迁移 |
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Eslint config file
|
||||||
|
* Documentation: https://eslint.org/docs/user-guide/configuring/
|
||||||
|
* Install the Eslint extension before using this feature.
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
es6: true,
|
||||||
|
browser: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
ecmaFeatures: {
|
||||||
|
modules: true,
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2018,
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
wx: true,
|
||||||
|
App: true,
|
||||||
|
Page: true,
|
||||||
|
getCurrentPages: true,
|
||||||
|
getApp: true,
|
||||||
|
Component: true,
|
||||||
|
requirePlugin: true,
|
||||||
|
requireMiniProgram: true,
|
||||||
|
},
|
||||||
|
// extends: 'eslint:recommended',
|
||||||
|
rules: {},
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
//CssTokenizer.js
|
||||||
|
function CssTokenizer(style = '', tagStyle = {}) {
|
||||||
|
this.res = tagStyle;
|
||||||
|
this._state = "SPACE";
|
||||||
|
this._buffer = style;
|
||||||
|
this._sectionStart = 0;
|
||||||
|
this._index = 0;
|
||||||
|
this._name = '';
|
||||||
|
this._content = '';
|
||||||
|
this._list = [];
|
||||||
|
this._comma = false;
|
||||||
|
}
|
||||||
|
CssTokenizer.prototype.SPACE = function(c) {
|
||||||
|
if (/[a-zA-Z.#]/.test(c)) {
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
this._state = "InName";
|
||||||
|
} else if (c == '@') this._state = "Ignore1";
|
||||||
|
else if (c == '/') this._state = "BeforeComment";
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.BeforeComment = function(c) {
|
||||||
|
if (c == '*') this._state = "InComment";
|
||||||
|
else {
|
||||||
|
this._index--;
|
||||||
|
this._state = "SPACE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.InComment = function(c) {
|
||||||
|
if (c == '*') this._state = "AfterComment";
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.AfterComment = function(c) {
|
||||||
|
if (c == '/') this._state = "SPACE";
|
||||||
|
else {
|
||||||
|
this._index--;
|
||||||
|
this._state = "InComment"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.InName = function(c) {
|
||||||
|
if (c == '{') {
|
||||||
|
this._list.push(this._buffer.substring(this._sectionStart, this._index))
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._state = "InContent";
|
||||||
|
} else if (c == ',') {
|
||||||
|
this._list.push(this._buffer.substring(this._sectionStart, this._index));
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._comma = true;
|
||||||
|
} else if ((c == '.' || c == '#') && !this._comma) {
|
||||||
|
this._buffer = this._buffer.splice(this._index, 1, ' ');
|
||||||
|
} else if (/\s/.test(c)) {
|
||||||
|
this._name = this._buffer.substring(this._sectionStart, this._index);
|
||||||
|
this._state = "NameSpace";
|
||||||
|
} else if (/[>:\[]/.test(c)) {
|
||||||
|
if (this._list.length) this._state = "IgnoreName";
|
||||||
|
else this._state = "Ignore1";
|
||||||
|
} else this._comma = false;
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.NameSpace = function(c) {
|
||||||
|
if (c == '{') {
|
||||||
|
this._list.push(this._name);
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._state = "InContent";
|
||||||
|
} else if (c == ',') {
|
||||||
|
this._comma = true;
|
||||||
|
this._list.push(this._name);
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._state = "InName"
|
||||||
|
} else if (/\S/.test(c)) {
|
||||||
|
if (this._comma) {
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
this._index--;
|
||||||
|
this._state = "InName";
|
||||||
|
} else if (this._list.length) this._state = "IgnoreName";
|
||||||
|
else this._state = "Ignore1"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.InContent = function(c) {
|
||||||
|
if (c == '}') {
|
||||||
|
this._content = this._buffer.substring(this._sectionStart, this._index);
|
||||||
|
for (let item of this._list)
|
||||||
|
this.res[item] = (this.res[item] || '') + this._content;
|
||||||
|
this._list = [];
|
||||||
|
this._comma = false;
|
||||||
|
this._state = "SPACE";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.IgnoreName = function(c) {
|
||||||
|
if (c == ',') {
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._state = "InName";
|
||||||
|
} else if (c == '{') {
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
this._state = "InContent";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CssTokenizer.prototype.Ignore1 = function(c) {
|
||||||
|
if (c == ';') {
|
||||||
|
this._state = "SPACE";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (c == '{') this._state = "Ignore2";
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.Ignore2 = function(c) {
|
||||||
|
if (c == '}') {
|
||||||
|
this._state = "SPACE";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (c == '{') this._state = "Ignore3";
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.Ignore3 = function(c) {
|
||||||
|
if (c == '}') this._state = "Ignore2";
|
||||||
|
};
|
||||||
|
CssTokenizer.prototype.parse = function() {
|
||||||
|
for (; this._index < this._buffer.length; this._index++)
|
||||||
|
this[this._state](this._buffer[this._index]);
|
||||||
|
return this.res;
|
||||||
|
};
|
||||||
|
module.exports = CssTokenizer;
|
||||||
@@ -0,0 +1,325 @@
|
|||||||
|
//DomHandler.js
|
||||||
|
const CssTokenizer = require('./CssTokenizer.js');
|
||||||
|
const CanIUse = require('./api.js').versionHigherThan('2.7.1');
|
||||||
|
const Common = 1,
|
||||||
|
Rich = 2;
|
||||||
|
const trustTag = {
|
||||||
|
a: Rich,
|
||||||
|
abbr: Common,
|
||||||
|
audio: Rich,
|
||||||
|
b: Common,
|
||||||
|
blockquote: Common,
|
||||||
|
br: Rich,
|
||||||
|
code: Common,
|
||||||
|
col: Rich,
|
||||||
|
colgroup: Rich,
|
||||||
|
dd: Common,
|
||||||
|
del: Common,
|
||||||
|
dl: Common,
|
||||||
|
dt: Common,
|
||||||
|
div: Common,
|
||||||
|
em: Common,
|
||||||
|
fieldset: Rich,
|
||||||
|
font: Common,
|
||||||
|
h1: Rich,
|
||||||
|
h2: Rich,
|
||||||
|
h3: Rich,
|
||||||
|
h4: Rich,
|
||||||
|
h5: Rich,
|
||||||
|
h6: Rich,
|
||||||
|
hr: Rich,
|
||||||
|
i: Common,
|
||||||
|
img: Common,
|
||||||
|
ins: Common,
|
||||||
|
label: Common,
|
||||||
|
legend: Rich,
|
||||||
|
li: Rich,
|
||||||
|
ol: Rich,
|
||||||
|
p: Common,
|
||||||
|
q: Common,
|
||||||
|
source: Rich,
|
||||||
|
span: Common,
|
||||||
|
strong: Common,
|
||||||
|
sub: Rich,
|
||||||
|
sup: Rich,
|
||||||
|
table: Rich,
|
||||||
|
tbody: Rich,
|
||||||
|
td: Rich,
|
||||||
|
tfoot: Rich,
|
||||||
|
th: Rich,
|
||||||
|
thead: Rich,
|
||||||
|
tr: Rich,
|
||||||
|
u: Common,
|
||||||
|
ul: Rich,
|
||||||
|
video: Common
|
||||||
|
};
|
||||||
|
const blockTag = {
|
||||||
|
address: true,
|
||||||
|
article: true,
|
||||||
|
aside: true,
|
||||||
|
body: true,
|
||||||
|
center: true,
|
||||||
|
cite: true,
|
||||||
|
footer: true,
|
||||||
|
header: true,
|
||||||
|
html: true,
|
||||||
|
nav: true,
|
||||||
|
pre: true,
|
||||||
|
section: true
|
||||||
|
}
|
||||||
|
const textTag = {
|
||||||
|
a: true,
|
||||||
|
abbr: true,
|
||||||
|
b: true,
|
||||||
|
big: true,
|
||||||
|
code: true,
|
||||||
|
del: true,
|
||||||
|
em: true,
|
||||||
|
font: true,
|
||||||
|
i: true,
|
||||||
|
ins: true,
|
||||||
|
label: true,
|
||||||
|
mark: true,
|
||||||
|
q: true,
|
||||||
|
s: true,
|
||||||
|
small: true,
|
||||||
|
span: true,
|
||||||
|
strong: true,
|
||||||
|
u: true
|
||||||
|
};
|
||||||
|
const ignoreTag = {
|
||||||
|
area: true,
|
||||||
|
base: true,
|
||||||
|
basefont: true,
|
||||||
|
canvas: true,
|
||||||
|
circle: true,
|
||||||
|
command: true,
|
||||||
|
ellipse: true,
|
||||||
|
embed: true,
|
||||||
|
frame: true,
|
||||||
|
head: true,
|
||||||
|
iframe: true,
|
||||||
|
input: true,
|
||||||
|
isindex: true,
|
||||||
|
keygen: true,
|
||||||
|
line: true,
|
||||||
|
link: true,
|
||||||
|
map: true,
|
||||||
|
meta: true,
|
||||||
|
param: true,
|
||||||
|
path: true,
|
||||||
|
polygon: true,
|
||||||
|
polyline: true,
|
||||||
|
rect: true,
|
||||||
|
script: true,
|
||||||
|
stop: true,
|
||||||
|
textarea: true,
|
||||||
|
title: true,
|
||||||
|
track: true,
|
||||||
|
use: true,
|
||||||
|
wbr: true
|
||||||
|
};
|
||||||
|
if (CanIUse) {
|
||||||
|
trustTag.bdi = Rich;
|
||||||
|
trustTag.bdo = Rich;
|
||||||
|
trustTag.caption = Rich;
|
||||||
|
trustTag.rt = Rich;
|
||||||
|
trustTag.ruby = Rich;
|
||||||
|
ignoreTag.rp = true;
|
||||||
|
trustTag.big = Common;
|
||||||
|
trustTag.small = Common;
|
||||||
|
trustTag.pre = Rich;
|
||||||
|
delete blockTag.pre;
|
||||||
|
}
|
||||||
|
//添加默认值
|
||||||
|
function initStyle(tagStyle) {
|
||||||
|
tagStyle.a = "display:inline;color:#366092;word-break:break-all;" + (tagStyle.a || "");
|
||||||
|
tagStyle.address = "font-style:italic;" + (tagStyle.address || "");
|
||||||
|
tagStyle.blockquote = tagStyle.blockquote || 'background-color:#f6f6f6;border-left:3px solid #dbdbdb;color:#6c6c6c;padding:5px 0 5px 10px';
|
||||||
|
tagStyle.center = 'text-align:center;' + (tagStyle.center || "");
|
||||||
|
tagStyle.cite = "font-style:italic;" + (tagStyle.cite || "");
|
||||||
|
tagStyle.code = tagStyle.code || 'padding:0 1px 0 1px;margin-left:2px;margin-right:2px;background-color:#f8f8f8;border:1px solid #cccccc;border-radius:3px';
|
||||||
|
tagStyle.dd = "margin-left:40px;" + (tagStyle.dd || "");
|
||||||
|
tagStyle.img = "max-width:100%;" + (tagStyle.img || "");
|
||||||
|
tagStyle.mark = "display:inline;background-color:yellow;" + (tagStyle.mark || "");
|
||||||
|
tagStyle.pre = "overflow:scroll;" + (tagStyle.pre || 'background-color:#f6f8fa;padding:5px;border-radius:5px;');
|
||||||
|
tagStyle.s = "display:inline;text-decoration:line-through;" + (tagStyle.s || "");
|
||||||
|
tagStyle.u = "display:inline;text-decoration:underline;" + (tagStyle.u || "");
|
||||||
|
//低版本兼容
|
||||||
|
if (!CanIUse) {
|
||||||
|
blockTag.caption = true;
|
||||||
|
tagStyle.big = "display:inline;font-size:1.2em;" + (tagStyle.big || "");
|
||||||
|
tagStyle.small = "display:inline;font-size:0.8em;" + (tagStyle.small || "");
|
||||||
|
tagStyle.pre = "font-family:monospace;white-space:pre;" + tagStyle.pre;
|
||||||
|
}
|
||||||
|
return tagStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DomHandler(style, tagStyle = {}) {
|
||||||
|
this.imgList = [];
|
||||||
|
this.nodes = [];
|
||||||
|
this.title = "";
|
||||||
|
this._videoNum = 0;
|
||||||
|
this._audioNum = 0;
|
||||||
|
this._style = new CssTokenizer(style, initStyle(tagStyle)).parse();
|
||||||
|
this._tagStack = [];
|
||||||
|
}
|
||||||
|
DomHandler.prototype._addDomElement = function(element) {
|
||||||
|
let parent = this._tagStack[this._tagStack.length - 1];
|
||||||
|
let siblings = parent ? parent.children : this.nodes;
|
||||||
|
siblings.push(element);
|
||||||
|
};
|
||||||
|
DomHandler.prototype._bubbling = function() {
|
||||||
|
for (let i = this._tagStack.length - 1; i >= 0; i--) {
|
||||||
|
if (trustTag[this._tagStack[i].name] == Common) this._tagStack[i].continue = true;
|
||||||
|
else return this._tagStack[i].name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DomHandler.prototype.onopentag = function(name, attrs) {
|
||||||
|
let element = {
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
//匹配样式
|
||||||
|
let matched = this._style[name] ? (this._style[name] + ';') : '';
|
||||||
|
if (attrs.id) {
|
||||||
|
matched += (this._style['#' + attrs.id] ? (this._style['#' + attrs.id] + ';') : '');
|
||||||
|
delete attrs.id;
|
||||||
|
}
|
||||||
|
if (attrs.class) {
|
||||||
|
for (var Class of attrs.class.split(' ')) {
|
||||||
|
matched += (this._style['.' + Class] ? (this._style['.' + Class] + ';') : '');
|
||||||
|
}
|
||||||
|
delete attrs.class;
|
||||||
|
}
|
||||||
|
//处理属性
|
||||||
|
switch (name) {
|
||||||
|
case 'div':
|
||||||
|
case 'p':
|
||||||
|
if (attrs.align) {
|
||||||
|
attrs.style += (';text-align:' + attrs.align);
|
||||||
|
delete attrs.align;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'img':
|
||||||
|
if (attrs.width) {
|
||||||
|
attrs.style = 'width:' + attrs.width + (/[0-9]/.test(attrs.width[attrs.width.length - 1]) ? 'px' : '') + ';' + attrs.style;
|
||||||
|
delete attrs.width;
|
||||||
|
}
|
||||||
|
if (attrs['data-src']) {
|
||||||
|
attrs.src = attrs.src || attrs['data-src'];
|
||||||
|
delete attrs['data-src'];
|
||||||
|
}
|
||||||
|
if (!attrs.hasOwnProperty('ignore') && attrs.src) {
|
||||||
|
this.imgList.push(attrs.src);
|
||||||
|
if (this._bubbling() == 'a') attrs.ignore = "";
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'font':
|
||||||
|
name = 'span';
|
||||||
|
if (attrs.color) {
|
||||||
|
attrs.style += (';color:' + attrs.color);
|
||||||
|
delete attrs.color;
|
||||||
|
}
|
||||||
|
if (attrs.face) {
|
||||||
|
attrs.style += (";font-family:" + attrs.face);
|
||||||
|
delete attrs.face;
|
||||||
|
}
|
||||||
|
if (attrs.size) {
|
||||||
|
var size = parseInt(attrs.size);
|
||||||
|
if (size < 1) size = 1;
|
||||||
|
else if (size > 7) size = 7;
|
||||||
|
switch (size) {
|
||||||
|
case 1:
|
||||||
|
size = 10;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
size = 13;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
size = 16;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
size = 18;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
size = 24;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
size = 32;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
size = 48;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
attrs.style += (";font-size:" + size + "px");
|
||||||
|
delete attrs.size;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
this._bubbling();
|
||||||
|
break;
|
||||||
|
case 'video':
|
||||||
|
case 'audio':
|
||||||
|
attrs.loop = attrs.hasOwnProperty('loop');
|
||||||
|
attrs.controls = attrs.hasOwnProperty('controls');
|
||||||
|
attrs.autoplay = attrs.hasOwnProperty('autoplay');
|
||||||
|
if (name == 'video') {
|
||||||
|
attrs.muted = attrs.hasOwnProperty('muted');
|
||||||
|
if (attrs.width) {
|
||||||
|
attrs.style = 'width:' + parseFloat(attrs.width) + 'px;' + attrs.style;
|
||||||
|
delete attrs.width;
|
||||||
|
}
|
||||||
|
if (attrs.height) {
|
||||||
|
attrs.style = 'height:' + parseFloat(attrs.height) + 'px;' + attrs.style;
|
||||||
|
delete attrs.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrs.id = (name + (++this['_' + name + 'Num']));
|
||||||
|
attrs.source = [];
|
||||||
|
if (attrs.src) attrs.source.push(attrs.src);
|
||||||
|
if (!attrs.controls && !attrs.autoplay)
|
||||||
|
console.warn(name + ' 标签缺少 controls 属性,可能无法正常使用', attrs);
|
||||||
|
this._bubbling();
|
||||||
|
break;
|
||||||
|
case 'source':
|
||||||
|
let parent = this._tagStack[this._tagStack.length - 1];
|
||||||
|
if (parent && (parent.name == 'video' || parent.name == 'audio')) {
|
||||||
|
parent.attrs.source.push(attrs.src);
|
||||||
|
if (!parent.attrs.src) parent.attrs.src = attrs.src;
|
||||||
|
}
|
||||||
|
this._tagStack.push(element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
attrs.style = matched + attrs.style;
|
||||||
|
if (textTag[name]) element.continue = true;
|
||||||
|
else if (blockTag[name]) name = 'div';
|
||||||
|
else if (!trustTag[name]) name = 'span';
|
||||||
|
element.name = name;
|
||||||
|
element.attrs = attrs;
|
||||||
|
this._addDomElement(element);
|
||||||
|
this._tagStack.push(element);
|
||||||
|
};
|
||||||
|
DomHandler.prototype.ontext = function(data) {
|
||||||
|
if (/\S/.test(data)) {
|
||||||
|
let element = {
|
||||||
|
text: data.replace(/ /g, '\u00A0'),
|
||||||
|
type: 'text'
|
||||||
|
};
|
||||||
|
if (/&#*((?!sp|lt|gt).){2,5};/.test(data)) element.decode = true;
|
||||||
|
this._addDomElement(element);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
DomHandler.prototype.onclosetag = function(name) {
|
||||||
|
let element = this._tagStack.pop();
|
||||||
|
if (ignoreTag[name]) {
|
||||||
|
if (name == 'title') {
|
||||||
|
try {
|
||||||
|
this.title = element.children[0].text;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
let parent = this._tagStack[this._tagStack.length - 1];
|
||||||
|
let siblings = parent ? parent.children : this.nodes;
|
||||||
|
siblings.pop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = DomHandler;
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
//Parser.js
|
||||||
|
const Tokenizer = require("./Tokenizer.js");
|
||||||
|
const DomHandler = require("./DomHandler.js");
|
||||||
|
const trustAttrs = {
|
||||||
|
align: true,
|
||||||
|
alt: true,
|
||||||
|
author: true,
|
||||||
|
autoplay: true,
|
||||||
|
class: true,
|
||||||
|
color: true,
|
||||||
|
colspan: true,
|
||||||
|
controls: true,
|
||||||
|
"data-src": true,
|
||||||
|
dir: true,
|
||||||
|
face: true,
|
||||||
|
height: true,
|
||||||
|
href: true,
|
||||||
|
id: true,
|
||||||
|
ignore: true,
|
||||||
|
loop: true,
|
||||||
|
muted: true,
|
||||||
|
name: true,
|
||||||
|
poster: true,
|
||||||
|
rowspan: true,
|
||||||
|
size: true,
|
||||||
|
span: true,
|
||||||
|
src: true,
|
||||||
|
start: true,
|
||||||
|
style: true,
|
||||||
|
type: true,
|
||||||
|
width: true,
|
||||||
|
};
|
||||||
|
const voidTag = {
|
||||||
|
area: true,
|
||||||
|
base: true,
|
||||||
|
basefont: true,
|
||||||
|
br: true,
|
||||||
|
col: true,
|
||||||
|
circle: true,
|
||||||
|
command: true,
|
||||||
|
ellipse: true,
|
||||||
|
embed: true,
|
||||||
|
frame: true,
|
||||||
|
hr: true,
|
||||||
|
img: true,
|
||||||
|
input: true,
|
||||||
|
isindex: true,
|
||||||
|
keygen: true,
|
||||||
|
line: true,
|
||||||
|
link: true,
|
||||||
|
meta: true,
|
||||||
|
param: true,
|
||||||
|
path: true,
|
||||||
|
polygon: true,
|
||||||
|
polyline: true,
|
||||||
|
rect: true,
|
||||||
|
source: true,
|
||||||
|
stop: true,
|
||||||
|
track: true,
|
||||||
|
use: true,
|
||||||
|
wbr: true
|
||||||
|
};
|
||||||
|
|
||||||
|
function Parser(cbs, callback) {
|
||||||
|
this._cbs = cbs;
|
||||||
|
this._callback = callback;
|
||||||
|
this._tagname = "";
|
||||||
|
this._attribname = "";
|
||||||
|
this._attribvalue = "";
|
||||||
|
this._attribs = null;
|
||||||
|
this._stack = [];
|
||||||
|
this._tokenizer = new Tokenizer(this);
|
||||||
|
}
|
||||||
|
Parser.prototype.ontext = function(data) {
|
||||||
|
this._cbs.ontext(data);
|
||||||
|
};
|
||||||
|
Parser.prototype.onopentagname = function(name) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
this._tagname = name;
|
||||||
|
this._attribs = {
|
||||||
|
style: ''
|
||||||
|
};
|
||||||
|
if (!voidTag[name]) this._stack.push(name);
|
||||||
|
};
|
||||||
|
Parser.prototype.onopentagend = function() {
|
||||||
|
if (this._attribs) {
|
||||||
|
this._cbs.onopentag(this._tagname, this._attribs);
|
||||||
|
this._attribs = null;
|
||||||
|
}
|
||||||
|
if (voidTag[this._tagname]) this._cbs.onclosetag(this._tagname);
|
||||||
|
this._tagname = "";
|
||||||
|
};
|
||||||
|
Parser.prototype.onclosetag = function(name) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
if (this._stack.length && !voidTag[name]) {
|
||||||
|
var pos = this._stack.lastIndexOf(name);
|
||||||
|
if (pos !== -1) {
|
||||||
|
pos = this._stack.length - pos;
|
||||||
|
while (pos--) this._cbs.onclosetag(this._stack.pop());
|
||||||
|
} else if (name === "p") {
|
||||||
|
this.onopentagname(name);
|
||||||
|
this._closeCurrentTag();
|
||||||
|
}
|
||||||
|
} else if (name === "br" || name === "hr" || name === "p") {
|
||||||
|
this.onopentagname(name);
|
||||||
|
this._closeCurrentTag();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Parser.prototype._closeCurrentTag = function() {
|
||||||
|
let name = this._tagname;
|
||||||
|
this.onopentagend();
|
||||||
|
if (this._stack[this._stack.length - 1] === name) {
|
||||||
|
this._cbs.onclosetag(name);
|
||||||
|
this._stack.pop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Parser.prototype.onattribend = function() {
|
||||||
|
this._attribvalue = this._attribvalue.replace(/"/g, '"');
|
||||||
|
if (this._attribs && trustAttrs[this._attribname]) {
|
||||||
|
this._attribs[this._attribname] = this._attribvalue;
|
||||||
|
}
|
||||||
|
this._attribname = "";
|
||||||
|
this._attribvalue = "";
|
||||||
|
};
|
||||||
|
Parser.prototype.onend = function() {
|
||||||
|
for (
|
||||||
|
var i = this._stack.length; i > 0; this._cbs.onclosetag(this._stack[--i])
|
||||||
|
);
|
||||||
|
this._callback({
|
||||||
|
'nodes': this._cbs.nodes,
|
||||||
|
'title': this._cbs.title,
|
||||||
|
'imgList': this._cbs.imgList
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Parser.prototype.write = function(chunk) {
|
||||||
|
this._tokenizer.parse(chunk);
|
||||||
|
};
|
||||||
|
|
||||||
|
function html2nodes(data, tagStyle) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
try {
|
||||||
|
let style = '';
|
||||||
|
data = data.replace(/<style.*?>([\s\S]*?)<\/style>/gi, function() {
|
||||||
|
style += arguments[1];
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
let handler = new DomHandler(style, tagStyle);
|
||||||
|
new Parser(handler, (res) => {
|
||||||
|
return resolve(res);
|
||||||
|
}).write(data);
|
||||||
|
} catch (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
module.exports = html2nodes;
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
//Tokenizer.js
|
||||||
|
function Tokenizer(cbs) {
|
||||||
|
this._state = "TEXT";
|
||||||
|
this._buffer = "";
|
||||||
|
this._sectionStart = 0;
|
||||||
|
this._index = 0;
|
||||||
|
this._cbs = cbs;
|
||||||
|
}
|
||||||
|
Tokenizer.prototype.TEXT = function(c) {
|
||||||
|
var index = this._buffer.indexOf("<", this._index);
|
||||||
|
if (index != -1) {
|
||||||
|
this._index = index;
|
||||||
|
this._cbs.ontext(this._getSection());
|
||||||
|
this._state = "BeforeTag";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
} else this._index = this._buffer.length;
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeTag = function(c) {
|
||||||
|
switch (c) {
|
||||||
|
case "/":
|
||||||
|
this._state = "BeforeCloseTag";
|
||||||
|
break;
|
||||||
|
case "!":
|
||||||
|
this._state = "BeforeDeclaration";
|
||||||
|
break;
|
||||||
|
case "?":
|
||||||
|
let index = this._buffer.indexOf(">", this._index);
|
||||||
|
if (index != -1) {
|
||||||
|
this._index = index;
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else this._sectionStart = this._index = this._buffer.length;
|
||||||
|
this._state = "TEXT";
|
||||||
|
break;
|
||||||
|
case ">":
|
||||||
|
this._state = "TEXT";
|
||||||
|
break;
|
||||||
|
case "<":
|
||||||
|
this._cbs.ontext(this._getSection());
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (/\s/.test(c)) this._state = "TEXT";
|
||||||
|
else {
|
||||||
|
this._state = "InTag";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InTag = function(c) {
|
||||||
|
if (c === "/" || c === ">" || /\s/.test(c)) {
|
||||||
|
this._cbs.onopentagname(this._getSection());
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeAttrsName = function(c) {
|
||||||
|
if (c === ">") {
|
||||||
|
this._cbs.onopentagend();
|
||||||
|
this._state = "TEXT";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (c === "/") {
|
||||||
|
this._state = "InSelfCloseTag";
|
||||||
|
} else if (!(/\s/.test(c))) {
|
||||||
|
this._state = "InAttrsName";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InAttrsName = function(c) {
|
||||||
|
if (c === "=" || c === "/" || c === ">" || /\s/.test(c)) {
|
||||||
|
this._cbs._attribname = this._getSection().toLowerCase();
|
||||||
|
this._sectionStart = -1;
|
||||||
|
this._state = "AfterAttrsName";
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.AfterAttrsName = function(c) {
|
||||||
|
if (c === "=") {
|
||||||
|
this._state = "BeforeAttrsValue";
|
||||||
|
} else if (c === "/" || c === ">") {
|
||||||
|
this._cbs.onattribend();
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
this._index--;
|
||||||
|
} else if (!(/\s/.test(c))) {
|
||||||
|
this._cbs.onattribend();
|
||||||
|
this._state = "InAttrsName";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeAttrsValue = function(c) {
|
||||||
|
if (c === '"') {
|
||||||
|
this._state = "InAttrsValueDQ";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (c === "'") {
|
||||||
|
this._state = "InAttrsValueSQ";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (!(/\s/.test(c))) {
|
||||||
|
this._state = "InAttrsValueNQ";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InAttrsValueDQ = function(c) {
|
||||||
|
if (c === '"') {
|
||||||
|
this._cbs._attribvalue += this._getSection();
|
||||||
|
this._cbs.onattribend();
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InAttrsValueSQ = function(c) {
|
||||||
|
if (c === "'") {
|
||||||
|
this._cbs._attribvalue += this._getSection();
|
||||||
|
this._cbs.onattribend();
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InAttrsValueNQ = function(c) {
|
||||||
|
if (/\s/.test(c) || c === ">") {
|
||||||
|
this._cbs._attribvalue += this._getSection();
|
||||||
|
this._cbs.onattribend();
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCloseTag = function(c) {
|
||||||
|
if (/\s/.test(c));
|
||||||
|
else if (c === ">") {
|
||||||
|
this._state = "TEXT";
|
||||||
|
} else {
|
||||||
|
this._state = "InCloseTag";
|
||||||
|
this._sectionStart = this._index;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InCloseTag = function(c) {
|
||||||
|
if (c === ">" || /\s/.test(c)) {
|
||||||
|
this._cbs.onclosetag(this._getSection());
|
||||||
|
this._state = "AfterCloseTag";
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InSelfCloseTag = function(c) {
|
||||||
|
if (c === ">") {
|
||||||
|
this._cbs.onopentagend();
|
||||||
|
this._state = "TEXT";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else if (!(/\s/.test(c))) {
|
||||||
|
this._state = "BeforeAttrsName";
|
||||||
|
this._index--;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.AfterCloseTag = function(c) {
|
||||||
|
if (c === ">") {
|
||||||
|
this._state = "TEXT";
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeDeclaration = function(c) {
|
||||||
|
if (c == '-') this._state = "InComment";
|
||||||
|
else if (c == '[') this._state = "BeforeCDATA1";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InDeclaration = function(c) {
|
||||||
|
var index = this._buffer.indexOf(">", this._index);
|
||||||
|
if (index != -1) {
|
||||||
|
this._index = index;
|
||||||
|
this._sectionStart = index + 1;
|
||||||
|
} else this._sectionStart = this._index = this._buffer.length;
|
||||||
|
this._state = "TEXT";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InComment = function(c) {
|
||||||
|
let key = (c == '-' ? '-->' : '>');
|
||||||
|
let index = this._buffer.indexOf(key, this._index);
|
||||||
|
if (index != -1) {
|
||||||
|
this._index = index + key.length - 1;
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else this._sectionStart = this._index = this._buffer.length;
|
||||||
|
this._state = "TEXT";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCDATA1 = function(c) {
|
||||||
|
if (c == 'C') this._state = "BeforeCDATA2";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCDATA2 = function(c) {
|
||||||
|
if (c == 'D') this._state = "BeforeCDATA3";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCDATA3 = function(c) {
|
||||||
|
if (c == 'A') this._state = "BeforeCDATA4";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCDATA4 = function(c) {
|
||||||
|
if (c == 'T') this._state = "BeforeCDATA5";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.BeforeCDATA5 = function(c) {
|
||||||
|
if (c == 'A') this._state = "InCDATA";
|
||||||
|
else this._state = "InDeclaration";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.InCDATA = function(c) {
|
||||||
|
let key = (c == '[' ? ']]>' : '>');
|
||||||
|
let index = this._buffer.indexOf(key, this._index);
|
||||||
|
if (index != -1) {
|
||||||
|
this._index = index + key.length - 1;
|
||||||
|
this._sectionStart = this._index + 1;
|
||||||
|
} else this._sectionStart = this._index = this._buffer.length;
|
||||||
|
this._state = "TEXT";
|
||||||
|
};
|
||||||
|
Tokenizer.prototype.parse = function(chunk) {
|
||||||
|
this._buffer += chunk;
|
||||||
|
for (; this._index < this._buffer.length; this._index++)
|
||||||
|
this[this._state](this._buffer[this._index]);
|
||||||
|
if (this._state === "TEXT" && this._sectionStart !== this._index)
|
||||||
|
this._cbs.ontext(this._buffer.substr(this._sectionStart));
|
||||||
|
this._cbs.onend();
|
||||||
|
};
|
||||||
|
Tokenizer.prototype._getSection = function() {
|
||||||
|
return this._buffer.substring(this._sectionStart, this._index);
|
||||||
|
};
|
||||||
|
module.exports = Tokenizer;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
String.prototype.splice = function(start = 0, deleteCount = 0, addStr = '') {
|
||||||
|
if (start < 0) start = this.length + start;
|
||||||
|
if (deleteCount < 0) deleteCount = 0;
|
||||||
|
return this.substring(0, start) + addStr + this.substring(start + deleteCount);
|
||||||
|
}
|
||||||
|
module.exports = {
|
||||||
|
versionHigherThan(version = '') {
|
||||||
|
//旧版 var v1 = wx.getSystemInfoSync().SDKVersion.split('.');
|
||||||
|
var v1 = wx.getAppBaseInfo().SDKVersion.split('.');
|
||||||
|
var v2 = version.split('.');
|
||||||
|
const len = Math.max(v1.length, v2.length);
|
||||||
|
while (v1.length < len) {
|
||||||
|
v1.push('0');
|
||||||
|
}
|
||||||
|
while (v2.length < len) {
|
||||||
|
v2.push('0');
|
||||||
|
}
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
const num1 = parseInt(v1[i]);
|
||||||
|
const num2 = parseInt(v2[i]);
|
||||||
|
if (num1 > num2) {
|
||||||
|
return true;
|
||||||
|
} else if (num1 < num2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
html2nodes(html, tagStyle) {
|
||||||
|
const Parser = require('./Parser.js');
|
||||||
|
return Parser(html, tagStyle);
|
||||||
|
},
|
||||||
|
css2object(style, tagStyle) {
|
||||||
|
const CssTokenizer = require('./CssTokenizer.js');
|
||||||
|
return new CssTokenizer(style, tagStyle).parse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
//Parser组件
|
||||||
|
const html2nodes = require('./Parser.js');
|
||||||
|
const initData = function(Component) {
|
||||||
|
setTimeout(() => {
|
||||||
|
Component.createSelectorQuery().select('#contain').boundingClientRect(res => {
|
||||||
|
Component.triggerEvent('ready', res);
|
||||||
|
}).exec();
|
||||||
|
Component.videoContext = [];
|
||||||
|
let nodes = [Component.selectComponent('#contain')];
|
||||||
|
nodes = nodes.concat(Component.selectAllComponents('#contain>>>#node'));
|
||||||
|
for (let node of nodes) {
|
||||||
|
for (let item of node.data.nodes) {
|
||||||
|
if (item.name == 'video') {
|
||||||
|
Component.videoContext.push({
|
||||||
|
id: item.attrs.id,
|
||||||
|
context: wx.createVideoContext(item.attrs.id, node)
|
||||||
|
});
|
||||||
|
} else if (item.name == 'audio' && item.attrs.autoplay)
|
||||||
|
wx.createAudioContext(item.attrs.id, node).play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 10)
|
||||||
|
}
|
||||||
|
Component({
|
||||||
|
properties: {
|
||||||
|
'html': {
|
||||||
|
type: String,
|
||||||
|
value: '',
|
||||||
|
observer: function(html) {
|
||||||
|
let hideAnimation = {},
|
||||||
|
showAnimation = {};
|
||||||
|
if (this.data.showWithAnimation) {
|
||||||
|
hideAnimation = wx.createAnimation({
|
||||||
|
duration: this.data.animationDuration,
|
||||||
|
timingFunction: "ease"
|
||||||
|
}).opacity(0).step().export();
|
||||||
|
showAnimation = wx.createAnimation({
|
||||||
|
duration: this.data.animationDuration,
|
||||||
|
timingFunction: "ease"
|
||||||
|
}).opacity(1).step().export();
|
||||||
|
}
|
||||||
|
if (!html) {
|
||||||
|
this.setData({
|
||||||
|
nodes: []
|
||||||
|
})
|
||||||
|
} else if (typeof html == 'string') {
|
||||||
|
html2nodes(html, this.data.tagStyle).then(res => {
|
||||||
|
this.setData({
|
||||||
|
nodes: res.nodes,
|
||||||
|
controls: {
|
||||||
|
imgMode: this.data.imgMode
|
||||||
|
},
|
||||||
|
showAnimation,
|
||||||
|
hideAnimation
|
||||||
|
}, initData(this))
|
||||||
|
if (res.title && this.data.autosetTitle) {
|
||||||
|
wx.setNavigationBarTitle({
|
||||||
|
title: res.title
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.imgList = res.imgList;
|
||||||
|
this.triggerEvent('parse', res);
|
||||||
|
}).catch(err => {
|
||||||
|
this.triggerEvent('error', err);
|
||||||
|
})
|
||||||
|
} else if (html.constructor == Array) {
|
||||||
|
this.setData({
|
||||||
|
controls: {
|
||||||
|
imgMode: this.data.imgMode
|
||||||
|
},
|
||||||
|
showAnimation,
|
||||||
|
hideAnimation
|
||||||
|
}, initData(this))
|
||||||
|
this.imgList = [];
|
||||||
|
} else if (typeof html == 'object') {
|
||||||
|
if (!html.nodes || html.nodes.constructor != Array) {
|
||||||
|
this.triggerEvent('error', {
|
||||||
|
message: "传入的nodes数组格式不正确!应该传入的类型是array,实际传入的类型是:" + typeof html.nodes
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setData({
|
||||||
|
controls: {
|
||||||
|
imgMode: this.data.imgMode
|
||||||
|
},
|
||||||
|
showAnimation,
|
||||||
|
hideAnimation
|
||||||
|
}, initData(this))
|
||||||
|
if (html.title && this.data.autosetTitle) {
|
||||||
|
wx.setNavigationBarTitle({
|
||||||
|
title: html.title
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.imgList = html.imgList || [];
|
||||||
|
} else {
|
||||||
|
this.triggerEvent('error', {
|
||||||
|
message: "错误的html类型:" + typeof html
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'autocopy': {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
'autopause': {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
'autosetTitle':{
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
'imgMode': {
|
||||||
|
type: String,
|
||||||
|
value: "default"
|
||||||
|
},
|
||||||
|
'selectable': {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
},
|
||||||
|
'tagStyle': {
|
||||||
|
type: Object,
|
||||||
|
value: { video:"width:100%" }
|
||||||
|
},
|
||||||
|
'showWithAnimation': {
|
||||||
|
type: Boolean,
|
||||||
|
value: false
|
||||||
|
},
|
||||||
|
'animationDuration': {
|
||||||
|
type: Number,
|
||||||
|
value: 400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
//事件
|
||||||
|
tapEvent(e) {
|
||||||
|
if (this.data.autocopy && e.detail && /^http/.test(e.detail)) {
|
||||||
|
wx.setClipboardData({
|
||||||
|
data: e.detail,
|
||||||
|
success() {
|
||||||
|
wx.showToast({
|
||||||
|
title: '链接已复制',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.triggerEvent('linkpress', e.detail);
|
||||||
|
},
|
||||||
|
errorEvent(e) {
|
||||||
|
this.triggerEvent('error', e.detail);
|
||||||
|
},
|
||||||
|
//内部方法
|
||||||
|
_previewImg(e) {
|
||||||
|
wx.previewImage({
|
||||||
|
current: e.detail,
|
||||||
|
urls: this.imgList.length ? this.imgList : [e.detail],
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_playVideo(e) {
|
||||||
|
if (this.videoContext.length > 1 && this.data.autopause) {
|
||||||
|
for (let video of this.videoContext) {
|
||||||
|
if (video.id == e.detail) continue;
|
||||||
|
video.context.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"trees": "./trees/trees"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<!--Parser-->
|
||||||
|
<slot wx:if="{{!(html.nodes||((html[0].name||html[0].type)?1:nodes.length))}}" animation="{{hideAnimation}}"></slot>
|
||||||
|
<trees id="contain" style="{{(showWithAnimation?'opacity:0;':'')+(selectable?'user-select:text;-webkit-user-select:text':'')}}" animation="{{showAnimation}}" nodes="{{html.nodes||((html[0].name||html[0].type)?html:nodes)}}" controls="{{controls}}" catchpreview="_previewImg"
|
||||||
|
catchplay="_playVideo" catchlinkpress="tapEvent" catcherror="errorEvent" />
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
:host {
|
||||||
|
display: block;
|
||||||
|
overflow: scroll;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Parser/trees/cssHandler.wxs
|
||||||
|
module.exports = {
|
||||||
|
getStyle: function(style, display) {
|
||||||
|
var res = "";
|
||||||
|
var reg = getRegExp("float\s*:\s*[^;]*", "i");
|
||||||
|
if (reg.test(style)) res += reg.exec(style)[0];
|
||||||
|
reg = getRegExp("margin[^;]*auto", "i");
|
||||||
|
if (reg.test(style)) res += (";" + reg.exec(style)[0]);
|
||||||
|
reg = getRegExp("display\s*:\s*([^;]*)", "i");
|
||||||
|
if (reg.test(style) && reg.exec(style)[1]!="flex") res += (';' + reg.exec(style)[0]);
|
||||||
|
else res += (';display:' + display);
|
||||||
|
reg = getRegExp("[^;\s]*width\s*:\s*[^;]*", "ig");
|
||||||
|
var width = reg.exec(style);
|
||||||
|
while (width) {
|
||||||
|
res += (';' + width[0]);
|
||||||
|
width = reg.exec(style);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
setImgStyle: function(item, imgMode) {
|
||||||
|
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
|
||||||
|
item.attrs.style += ';width:100%';
|
||||||
|
if (imgMode == "widthFix")
|
||||||
|
item.attrs.style += ";height:auto !important";
|
||||||
|
return [item];
|
||||||
|
},
|
||||||
|
setStyle: function(item) {
|
||||||
|
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
|
||||||
|
item.attrs.style += ';width:100%';
|
||||||
|
return [item];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// Parser/trees/trees.js
|
||||||
|
Component({
|
||||||
|
properties: {
|
||||||
|
nodes: {
|
||||||
|
type: Array,
|
||||||
|
value: []
|
||||||
|
},
|
||||||
|
controls: {
|
||||||
|
type: Object,
|
||||||
|
value: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
//冒泡事件
|
||||||
|
playEvent(e) {
|
||||||
|
this.triggerEvent('play', e.currentTarget.dataset.id, {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
});
|
||||||
|
},
|
||||||
|
previewEvent(e) {
|
||||||
|
if (!e.target.dataset.hasOwnProperty('ignore')) {
|
||||||
|
this.triggerEvent('preview', e.currentTarget.dataset.src, {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tapEvent(e) {
|
||||||
|
this.triggerEvent('linkpress', e.currentTarget.dataset.href, {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
});
|
||||||
|
},
|
||||||
|
errorEvent(e) {
|
||||||
|
//尝试加载其他源
|
||||||
|
if (!this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > 1) {
|
||||||
|
this.data.controls[e.currentTarget.dataset.id] = {
|
||||||
|
play: false,
|
||||||
|
index: 1
|
||||||
|
}
|
||||||
|
} else if (this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > (this.data.controls[e.currentTarget.dataset.id].index + 1)) {
|
||||||
|
this.data.controls[e.currentTarget.dataset.id].index++;
|
||||||
|
}
|
||||||
|
this.setData({
|
||||||
|
controls: this.data.controls
|
||||||
|
})
|
||||||
|
this.triggerEvent('error', {
|
||||||
|
target: e.currentTarget,
|
||||||
|
message: e.detail.errMsg
|
||||||
|
}, {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//内部方法:点击封面后加载真实内容
|
||||||
|
_loadVideo(e) {
|
||||||
|
this.data.controls[e.currentTarget.dataset.id] = {
|
||||||
|
play: true,
|
||||||
|
index: 0
|
||||||
|
}
|
||||||
|
this.setData({
|
||||||
|
controls: this.data.controls
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"trees":"./trees"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<!--Parser/trees/trees.wxml-->
|
||||||
|
<wxs module="cssHandler" src="./cssHandler.wxs" />
|
||||||
|
<block wx:for='{{nodes}}' wx:key="index">
|
||||||
|
<block wx:if="{{!item.continue}}">
|
||||||
|
<!--图片-->
|
||||||
|
<rich-text wx:if="{{item.name=='img'}}" style="{{cssHandler.getStyle(item.attrs.style,'inline-block')}}" nodes='{{cssHandler.setImgStyle(item,controls.imgMode)}}' data-ignore='{{item.attrs.ignore}}' data-src='{{item.attrs.src}}' bindtap='previewEvent' />
|
||||||
|
<!--文本-->
|
||||||
|
<block wx:elif="{{item.type=='text'}}">
|
||||||
|
<text wx:if="{{!item.decode}}" decode>{{item.text}}</text>
|
||||||
|
<rich-text wx:else style="display:inline-block" nodes="{{[item]}}"></rich-text>
|
||||||
|
</block>
|
||||||
|
<text wx:elif="{{item.name=='br'}}">\n</text>
|
||||||
|
<!--浏览内容-->
|
||||||
|
<block wx:elif="{{item.name=='video'}}">
|
||||||
|
<view wx:if="{{item.attrs.id>'video3'&&!controls[item.attrs.id].play}}" class="video" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" bindtap="_loadVideo">
|
||||||
|
<view class="video-triangle" />
|
||||||
|
</view>
|
||||||
|
<video wx:else src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' autoplay="{{item.attrs.autoplay||controls[item.attrs.id].play}}"
|
||||||
|
class="v" muted="{{item.attrs.muted}}" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" bindplay='playEvent'
|
||||||
|
binderror="errorEvent" />
|
||||||
|
</block>
|
||||||
|
<!--音频-->
|
||||||
|
<audio wx:elif="{{item.name=='audio'}}" src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' poster='{{item.attrs.poster}}'
|
||||||
|
name='{{item.attrs.name}}' author='{{item.attrs.author}}' style="{{item.attrs.style}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" binderror="errorEvent" />
|
||||||
|
<!--富文本-->
|
||||||
|
<rich-text wx:else class="{{item.name}}" style="{{cssHandler.getStyle(item.attrs.style,'block')}}" nodes="{{cssHandler.setStyle(item)}}" />
|
||||||
|
</block>
|
||||||
|
<!--链接-->
|
||||||
|
<navigator wx:elif="{{item.name=='a'}}" url="{{item.attrs.href}}" style="{{item.attrs.style}}" data-href='{{item.attrs.href}}' hover-class="navigator-hover" hover-start-time="25" hover-stay-time="300" bindtap="tapEvent">
|
||||||
|
<trees id="node" nodes="{{item.children}}" controls="{{controls}}" />
|
||||||
|
</navigator>
|
||||||
|
<!--继续递归-->
|
||||||
|
<trees wx:else id="node" class="{{item.name}}" style="{{item.attrs.style}}" nodes="{{item.children}}" controls="{{controls}}" />
|
||||||
|
</block>
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/* 链接受到点击的hover-class,可自定义修改 */
|
||||||
|
.navigator-hover {
|
||||||
|
opacity: 0.7;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
/* 以下内容不建议修改 */
|
||||||
|
:host {
|
||||||
|
display: inherit;
|
||||||
|
float: inherit;
|
||||||
|
}
|
||||||
|
.sub, .sup, .bdo, .bdi, .ruby, .rt {
|
||||||
|
display: inline-block !important;
|
||||||
|
}
|
||||||
|
.div, .blockquote, .p{
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
.b, .strong {
|
||||||
|
display: inline;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.em, .i {
|
||||||
|
display: inline;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.del {
|
||||||
|
display: inline;
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
.ins {
|
||||||
|
display: inline;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.code {
|
||||||
|
display: inline;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
.big {
|
||||||
|
font-size:1.2em;
|
||||||
|
display:inline;
|
||||||
|
}
|
||||||
|
.small {
|
||||||
|
font-size:0.8em;
|
||||||
|
display:inline;
|
||||||
|
}
|
||||||
|
.q, .span, .label, .abbr {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
.q::before {
|
||||||
|
content: '"';
|
||||||
|
}
|
||||||
|
.q::after {
|
||||||
|
content: '"';
|
||||||
|
}
|
||||||
|
.video {
|
||||||
|
background-color: rgb(0, 0, 0);
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.video-triangle {
|
||||||
|
border-width: 15px 0 15px 30px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: transparent transparent transparent white;
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
margin: -15px 0 0 -15px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// app.js
|
||||||
|
const api = require('./utils/api');
|
||||||
|
const store = require('./utils/store');
|
||||||
|
|
||||||
|
App({
|
||||||
|
globalData: {
|
||||||
|
/** 初始化完成的 Promise,页面 onLoad 里等它即可,避免首屏读不到数据 */
|
||||||
|
ready: null,
|
||||||
|
},
|
||||||
|
|
||||||
|
onLaunch() {
|
||||||
|
this.globalData.ready = this.bootstrap();
|
||||||
|
this.watchUpdates();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本更新监听。**只在这里注册一次**。
|
||||||
|
*
|
||||||
|
* 以前写在首页的 onShow 里,每切回首页就注册一遍;微信这个接口不去重,
|
||||||
|
* 回调会一层层叠加,同一次更新会连着弹好几个弹窗。放在 App 里天然只执行一次。
|
||||||
|
*
|
||||||
|
* 提示文案来自后台配置,所以要等启动流程把配置读回来再弹,避免弹出空白内容。
|
||||||
|
*/
|
||||||
|
watchUpdates() {
|
||||||
|
const updateManager = wx.getUpdateManager();
|
||||||
|
|
||||||
|
updateManager.onUpdateReady(() => {
|
||||||
|
void this.ready().then(() => {
|
||||||
|
wx.showModal({
|
||||||
|
title: store.cfg('app.update.title'),
|
||||||
|
showCancel: false,
|
||||||
|
content: store.cfg('app.update.content'),
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) updateManager.applyUpdate();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
updateManager.onUpdateFailed(() => {
|
||||||
|
void this.ready().then(() => {
|
||||||
|
wx.showModal({
|
||||||
|
title: store.cfg('app.update.title'),
|
||||||
|
showCancel: false,
|
||||||
|
content: store.cfg('app.update.failed'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动流程:配置再静默登录,最后拉已购内容。
|
||||||
|
*
|
||||||
|
* 每一步失败都不阻断启动:配置缺失时页面按空值渲染,登录失败时按未登录渲染。
|
||||||
|
* 旧版本在页面 data 里同步读缓存、而缓存由异步写入,首次安装必然报错,这里不再重蹈。
|
||||||
|
*/
|
||||||
|
bootstrap() {
|
||||||
|
const tasks = [
|
||||||
|
api
|
||||||
|
.getConfig()
|
||||||
|
.then((cfg) => store.setSiteConfig(cfg))
|
||||||
|
.catch((err) => console.warn('[app] 配置加载失败', err)),
|
||||||
|
|
||||||
|
api
|
||||||
|
.login()
|
||||||
|
.then((res) => {
|
||||||
|
// 静默登录只建立身份。用户从没主动登录过、或者已经退出,就不去拉已购内容,
|
||||||
|
// 否则知识页会在「未登录」状态下又冒出一份已购列表。
|
||||||
|
if (!res || !res.user || res.user.isLogin !== 1) {
|
||||||
|
store.setEntitlements([]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return api.getEntitlements().then((list) => store.setEntitlements(list));
|
||||||
|
})
|
||||||
|
.catch((err) => console.warn('[app] 登录或权益加载失败', err)),
|
||||||
|
];
|
||||||
|
return Promise.all(tasks);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 页面调用它确保初始化完成。 */
|
||||||
|
ready() {
|
||||||
|
return this.globalData.ready || Promise.resolve();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
"pages/index/index",
|
||||||
|
"pages/wode/wode",
|
||||||
|
"pages/kecheng/kecheng",
|
||||||
|
"pages/LoginOrOutDetails/LoginOrOutDetails",
|
||||||
|
"pages/WebPageDetails/WebPageDetails",
|
||||||
|
"pages/VideoDetails/VideoDetails",
|
||||||
|
"pages/buy/buy",
|
||||||
|
"pages/VideoDetailsPage/VideoDetailsPage",
|
||||||
|
"pages/IndexNewCourseDetails/IndexNewCourseDetails",
|
||||||
|
"pages/IndexFreeCourseDetails/IndexFreeCourseDetails",
|
||||||
|
"pages/orders/orders",
|
||||||
|
"pages/ChangeUserInfo/ChangeUserInfo"
|
||||||
|
],
|
||||||
|
"window": {
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"navigationBarTitleText": "叶雷讲数学",
|
||||||
|
"navigationBarBackgroundColor": "#fff",
|
||||||
|
"backgroundColor": "#fff"
|
||||||
|
},
|
||||||
|
"tabBar": {
|
||||||
|
"color":"#000",
|
||||||
|
"selectedColor":"#00aa00",
|
||||||
|
"borderStyle": "black",
|
||||||
|
"list": [{
|
||||||
|
"text": "首页",
|
||||||
|
"pagePath": "pages/index/index",
|
||||||
|
"iconPath": "static/image/shouye.png",
|
||||||
|
"selectedIconPath": "static/image/shouye-selected.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "知识",
|
||||||
|
"pagePath": "pages/kecheng/kecheng",
|
||||||
|
"iconPath": "static/image/kecheng.png",
|
||||||
|
"selectedIconPath": "static/image/kecheng-selected.png"
|
||||||
|
},{
|
||||||
|
"text": "我的",
|
||||||
|
"pagePath": "pages/wode/wode",
|
||||||
|
"iconPath": "static/image/wode.png",
|
||||||
|
"selectedIconPath": "static/image/wode-selected.png"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"componentFramework": "glass-easel",
|
||||||
|
"sitemapLocation": "sitemap.json",
|
||||||
|
"lazyCodeLoading": "requiredComponents"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/**app.wxss**/
|
||||||
|
.container {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 200rpx 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* 全局配置。
|
||||||
|
*
|
||||||
|
* 部署时只需修改本文件即可切换环境——所有域名与路径都收口在这里。
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* 服务端 API。
|
||||||
|
* 这个域名同时要加到微信后台的「request 合法域名」白名单。
|
||||||
|
*/
|
||||||
|
API_BASE_URL: 'https://yelaymaths-api.yeomai.site',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态资源端(图片、浏览内容)。
|
||||||
|
* 已存库的正文 HTML 里的地址与此无关——那部分在数据迁移时按服务端的 STATIC_BASE_URL 改写。
|
||||||
|
*/
|
||||||
|
STATIC_BASE_URL: 'https://yelaymaths-data.yeomai.site',
|
||||||
|
|
||||||
|
/** 本地缓存 key */
|
||||||
|
STORAGE: {
|
||||||
|
TOKEN: 'accessToken',
|
||||||
|
REFRESH_TOKEN: 'refreshToken',
|
||||||
|
USER: 'userInfo',
|
||||||
|
CONFIG: 'siteConfig',
|
||||||
|
ENTITLEMENTS: 'entitlements',
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 占位图(走网络,不占用小程序包体积) */
|
||||||
|
PLACEHOLDER: {
|
||||||
|
AVATAR: '/Images/Placeholder/defaultAvatar.png',
|
||||||
|
WECHAT: '/Images/Placeholder/weixin.png',
|
||||||
|
USER: '/Images/Placeholder/user.png',
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 请求超时(毫秒) */
|
||||||
|
TIMEOUT: 15000,
|
||||||
|
};
|
||||||
Generated
+21
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "yelaymaths",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "yelaymaths",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@vant/weapp": "^1.11.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@vant/weapp": {
|
||||||
|
"version": "1.11.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.11.7.tgz",
|
||||||
|
"integrity": "sha512-Rwn9BBnb4kHSV4XmvBicwtd42J+amEUfnFDcXJsGNPNX4a9c/DoT6YLsm4X1wB2+sQbdiQsbFBLAvGRBxCkD8g==",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "yelaymaths",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"description": "叶雷讲数学 — 微信小程序",
|
||||||
|
"dependencies": {
|
||||||
|
"@vant/weapp": "^1.11.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
// pages/ChangeUserInfo/ChangeUserInfo.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const config = require('../../config/index');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
// wxml 里直接用它拼头像路径,保持不变
|
||||||
|
BaseURL: config.STATIC_BASE_URL,
|
||||||
|
activeNames: [],
|
||||||
|
username: '',
|
||||||
|
HeadiconID: 0,
|
||||||
|
list: 50,
|
||||||
|
// 表单上的固定文案,全部来自后台配置
|
||||||
|
labelName: '',
|
||||||
|
placeholderName: '',
|
||||||
|
labelAvatar: '',
|
||||||
|
textSubmit: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
app.ready().then(() => this.applyUser());
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
this.applyUser();
|
||||||
|
},
|
||||||
|
|
||||||
|
applyUser() {
|
||||||
|
const user = store.getUser() || {};
|
||||||
|
this.setData({
|
||||||
|
username: user.nickname || '',
|
||||||
|
HeadiconID: user.headiconId || 0,
|
||||||
|
list: parseInt(store.cfg('profile.headicon_count'), 10) || 0,
|
||||||
|
labelName: store.cfg('profile.form.name'),
|
||||||
|
placeholderName: store.cfg('profile.form.namePlaceholder'),
|
||||||
|
labelAvatar: store.cfg('profile.form.avatar'),
|
||||||
|
textSubmit: store.cfg('profile.form.submit'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange(event) {
|
||||||
|
let inputVal = event.detail;
|
||||||
|
// 只保留中英文与数字
|
||||||
|
inputVal = inputVal.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '');
|
||||||
|
// 去掉开头的数字
|
||||||
|
inputVal = inputVal.replace(/^[0-9]+/, '');
|
||||||
|
inputVal = inputVal.substring(0, 8);
|
||||||
|
this.setData({ username: inputVal });
|
||||||
|
},
|
||||||
|
|
||||||
|
selectHeadicon(event) {
|
||||||
|
this.setData({ HeadiconID: event.currentTarget.dataset.index });
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange2(event) {
|
||||||
|
this.setData({ activeNames: event.detail });
|
||||||
|
},
|
||||||
|
|
||||||
|
onConfirm() {
|
||||||
|
const nickname = (this.data.username || '').trim();
|
||||||
|
if (!nickname) {
|
||||||
|
wx.showToast({ title: '请输入用户名', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wx.showModal({
|
||||||
|
title: store.cfg('common.dialog.title'),
|
||||||
|
content: store.cfg('profile.confirm.save'),
|
||||||
|
confirmColor: '#ff0000',
|
||||||
|
success: (res) => {
|
||||||
|
if (!res.confirm) return;
|
||||||
|
wx.showLoading({ title: '提交中', mask: true });
|
||||||
|
|
||||||
|
api
|
||||||
|
.updateMe({ nickname: nickname, headiconId: this.data.HeadiconID })
|
||||||
|
.then((user) => {
|
||||||
|
store.setUser(user);
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
||||||
|
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.showToast({ title: err.message || '修改失败', icon: 'none', mask: true });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"van-field": "@vant/weapp/field/index",
|
||||||
|
"van-collapse": "@vant/weapp/collapse/index",
|
||||||
|
"van-collapse-item": "@vant/weapp/collapse-item/index",
|
||||||
|
"van-grid": "@vant/weapp/grid/index",
|
||||||
|
"van-grid-item": "@vant/weapp/grid-item/index",
|
||||||
|
"van-image": "@vant/weapp/image/index",
|
||||||
|
"van-button": "@vant/weapp/button/index"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<van-cell-group>
|
||||||
|
<van-field
|
||||||
|
label="{{labelName}}"
|
||||||
|
value="{{username}}"
|
||||||
|
placeholder="{{placeholderName}}"
|
||||||
|
border="true"
|
||||||
|
bind:change="onChange"
|
||||||
|
/>
|
||||||
|
</van-cell-group>
|
||||||
|
|
||||||
|
<van-collapse value="{{ activeNames }}" bind:change="onChange2">
|
||||||
|
<van-collapse-item title="{{labelAvatar}}" name="1">
|
||||||
|
<view style="display: flex; justify-content: center; padding: 20rpx 0;">
|
||||||
|
<van-image width="120rpx" height="120rpx" src="{{BaseURL}}/Images/Headicons/Headicon{{HeadiconID}}.png" />
|
||||||
|
</view>
|
||||||
|
<van-grid icon-size="80rpx">
|
||||||
|
<scroll-view scroll-y style="min-height: 200rpx;max-height: 620rpx;" class="scroll-area">
|
||||||
|
<van-grid-item wx:for="{{ list }}" wx:key="index" icon="{{BaseURL}}/Images/Headicons/Headicon{{index + 1}}.png" text="{{index + 1}}" bind:click="selectHeadicon" data-index="{{index + 1}}"/>
|
||||||
|
</scroll-view>
|
||||||
|
</van-grid>
|
||||||
|
</van-collapse-item>
|
||||||
|
</van-collapse>
|
||||||
|
|
||||||
|
<view class="button-container" style="text-align: center;padding: 20rpx;">
|
||||||
|
<van-button type="primary" bind:click="onConfirm">{{textSubmit}}</van-button>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/* pages/ChangeUserInfo/ChangeUserInfo.wxss */
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// pages/IndexFreeCourseDetails/IndexFreeCourseDetails.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const format = require('../../utils/format');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
VideoTitle: '',
|
||||||
|
playdata: [],
|
||||||
|
VideoPlayerSrc: '',
|
||||||
|
HiddenVideoControl: true,
|
||||||
|
top: 0,
|
||||||
|
/** 列表上方的更新期数文案,整句来自后台配置 */
|
||||||
|
updatedText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
const seriesNo = options.seriesNo;
|
||||||
|
if (!seriesNo) {
|
||||||
|
wx.switchTab({ url: '/pages/index/index' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
api
|
||||||
|
.getFreeLessons(Number(seriesNo))
|
||||||
|
.then((list) => {
|
||||||
|
const rows = (list || []).map((item) => ({
|
||||||
|
coverUrl: item.coverUrl,
|
||||||
|
videoTitle: item.videoTitle,
|
||||||
|
intro: item.intro,
|
||||||
|
publishedAt: format.toDateString(item.publishedAt),
|
||||||
|
duration: item.duration,
|
||||||
|
videoUrl: item.videoUrl,
|
||||||
|
}));
|
||||||
|
this.setData({
|
||||||
|
playdata: rows,
|
||||||
|
VideoTitle: rows.length ? rows[0].videoTitle || '' : '',
|
||||||
|
updatedText: store.cfg('course.lesson.updated').replace('{n}', rows.length),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('[IndexFreeCourseDetails] 加载失败', err);
|
||||||
|
this.setData({ playdata: [] });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onTapLesson(e) {
|
||||||
|
const item = this.data.playdata[e.currentTarget.dataset.index];
|
||||||
|
if (!item || !item.videoUrl) {
|
||||||
|
wx.showToast({ title: store.cfg('course.tip.lessonNoVideo'), icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setData({ VideoPlayerSrc: item.videoUrl, HiddenVideoControl: false, top: 420 });
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<video hidden="{{HiddenVideoControl}}" class="videoplayer" src="{{VideoPlayerSrc}}" />
|
||||||
|
<scroll-view class="scrollarea" scroll-y type="list" style="top:{{top}}rpx;">
|
||||||
|
<view class="jieshao">
|
||||||
|
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||||
|
<text decode class="video_info"> {{updatedText}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="videolistcontainer" bind:tap="onTapLesson"
|
||||||
|
wx:for="{{playdata}}" wx:for-item="item" wx:for-index="index" wx:key="index" data-index="{{index}}">
|
||||||
|
<view class="videoimage">
|
||||||
|
<image class="coverimage" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
<view class="videoinfo">
|
||||||
|
<text class="videotitle">{{item.videoTitle}}</text>
|
||||||
|
<text class="videodetails">{{item.intro}}</text>
|
||||||
|
<view class="videoinfo2">
|
||||||
|
<text class="videodata">{{item.publishedAt}}</text>
|
||||||
|
<text class="videotime">{{item.duration}}min</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
.videoplayer {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 420rpx;
|
||||||
|
width: 750rpx;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
.scrollarea {
|
||||||
|
position: relative;
|
||||||
|
top: 420rpx;
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: hidden;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.jieshao {
|
||||||
|
margin-bottom: 10rpx;
|
||||||
|
/* box-shadow: 0 4rpx 4rpx rgba(150, 150, 150, 0.5); */
|
||||||
|
position: relative;
|
||||||
|
/* height: 100rpx; */
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.video_biaoti {
|
||||||
|
text-align: center;
|
||||||
|
display: block;
|
||||||
|
font-size: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video_miaoshu {
|
||||||
|
text-align: center;
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.video_info {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10rpx;
|
||||||
|
display: block;
|
||||||
|
font-size: 24rpx;
|
||||||
|
right: 30rpx;
|
||||||
|
}
|
||||||
|
.video_list_content {
|
||||||
|
margin: 10rpx 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.videolistcontainer {
|
||||||
|
border-radius: 20rpx;
|
||||||
|
margin: 10rpx 10rpx;
|
||||||
|
box-shadow: 0 0 4rpx rgba(0, 0, 0, 0.5);
|
||||||
|
width: 730rpx;
|
||||||
|
height: 200rpx;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.videoimage {
|
||||||
|
width: 320rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-left: 10rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.videoinfo{
|
||||||
|
position: relative;
|
||||||
|
width: 390rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.videotitle {
|
||||||
|
text-align: left;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.videodetails {
|
||||||
|
display: block;
|
||||||
|
margin: 10rpx 0rpx;
|
||||||
|
font-size: 25rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videoinfo2 {
|
||||||
|
position:absolute;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content:left;
|
||||||
|
}
|
||||||
|
.videodata {
|
||||||
|
font-size: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videotime {
|
||||||
|
font-size: 20rpx;
|
||||||
|
margin-left: 40rpx;
|
||||||
|
}
|
||||||
|
.coverimage {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// pages/IndexNewCourseDetails/IndexNewCourseDetails.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
html: ' ',
|
||||||
|
courseCode: '',
|
||||||
|
courseTitle: '',
|
||||||
|
priceYuan: '',
|
||||||
|
buyText: '',
|
||||||
|
contactText: '',
|
||||||
|
/** 是否已拥有这门课:已拥有时按钮就在本页提示,不再跳购买页 */
|
||||||
|
owned: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
const id = options.id;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
api
|
||||||
|
.getHomeCourses()
|
||||||
|
.then((list) => {
|
||||||
|
const item = (list || []).filter((c) => String(c.id) === String(id))[0];
|
||||||
|
if (!item) return;
|
||||||
|
this.setData({
|
||||||
|
html: item.content || ' ',
|
||||||
|
courseCode: item.courseCode || '',
|
||||||
|
courseTitle: item.courseTitle || '',
|
||||||
|
});
|
||||||
|
this.refreshOwned();
|
||||||
|
})
|
||||||
|
.catch((err) => console.error('[IndexNewCourseDetails] 加载失败', err));
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
app.ready().then(() => {
|
||||||
|
this.applyConfig();
|
||||||
|
// 买完回来要立刻变成「已拥有」,所以每次显示都重新问一次
|
||||||
|
this.refreshOwned();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 查这门课的拥有状态。拿不到就按未拥有处理,不影响正常购买。 */
|
||||||
|
refreshOwned() {
|
||||||
|
const code = this.data.courseCode;
|
||||||
|
if (!code) return;
|
||||||
|
api
|
||||||
|
.getCourse(code)
|
||||||
|
.then((course) => this.setData({ owned: !!course.owned }))
|
||||||
|
.catch((err) => console.warn('[IndexNewCourseDetails] 拥有状态加载失败', err));
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 按钮文案取自后台配置,后台改完小程序下拉刷新即可生效。 */
|
||||||
|
applyConfig() {
|
||||||
|
this.setData({
|
||||||
|
buyText: store.cfg('course.button.buy'),
|
||||||
|
contactText: store.cfg('course.button.contact'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 购买统一走商业化页面。 */
|
||||||
|
toBuy() {
|
||||||
|
if (!this.data.courseCode) return;
|
||||||
|
// 已经拥有就不必再跳过去了:原地提示一句
|
||||||
|
if (this.data.owned) {
|
||||||
|
wx.showToast({ title: store.cfg('course.tip.owned'), icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.navigateTo({ url: '/pages/buy/buy?code=' + this.data.courseCode });
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"Parser":"/Parser/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!--pages/IndexNewCourseDetails/IndexNewCourseDetails.wxml-->
|
||||||
|
<Parser html="{{html}}">加载中...</Parser>
|
||||||
|
|
||||||
|
<view class="fixed-btn-wrapper">
|
||||||
|
<view class="btn-group">
|
||||||
|
<button wx:if="{{courseCode}}" class="DianJiXiangQing1" bind:tap="toBuy">
|
||||||
|
<text class="DianJiXiangQing2">{{buyText}}</text>
|
||||||
|
</button>
|
||||||
|
<button class="DianJiXiangQing1" open-type="contact" bindcontact="handleContact">
|
||||||
|
<text class="DianJiXiangQing2">{{contactText}}</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/* pages/IndexNewCourseDetails/IndexNewCourseDetails.wxss */
|
||||||
|
@keyframes breathe {
|
||||||
|
0%, 100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-btn-wrapper {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 60rpx;
|
||||||
|
padding: 0 20rpx; /* 调整为左右边距 */
|
||||||
|
display: flex;
|
||||||
|
justify-content: center; /* 水平居中 */
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-group {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 700rpx;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.DianJiXiangQing1 {
|
||||||
|
flex: 1;
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
margin: 0 10rpx;
|
||||||
|
border-radius: 45rpx;
|
||||||
|
height: 90rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
animation: breathe 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.DianJiXiangQing2 {
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// pages/LoginOrOutDetails/LoginOrOutDetails.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const config = require('../../config/index');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
/** 未填昵称时自动生成,与旧版行为一致:用户 + 8 位小写字母数字 */
|
||||||
|
function randomNickname() {
|
||||||
|
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
let s = '';
|
||||||
|
for (let i = 0; i < 8; i++) s += chars[Math.floor(Math.random() * chars.length)];
|
||||||
|
return '用户' + s;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
userInfo: { avatarUrl: '', nickName: '' },
|
||||||
|
loginStatue: false,
|
||||||
|
LoginTag: '',
|
||||||
|
// 页面固定文案,全部来自后台配置
|
||||||
|
pageTitle: '',
|
||||||
|
pageSubtitle: '',
|
||||||
|
logoutText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
app.ready().then(() => this.refresh());
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
this.refresh();
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
const user = store.getUser();
|
||||||
|
// 「已登录」看的是用户主动登录过没有(服务端记着这一位),不是有没有 token
|
||||||
|
const registered = !!(user && user.isLogin === 1);
|
||||||
|
this.setData({
|
||||||
|
loginStatue: registered,
|
||||||
|
LoginTag: registered ? store.cfg('login.button.logout') : store.cfg('login.button.login'),
|
||||||
|
logoutText: store.cfg('login.button.logout'),
|
||||||
|
pageTitle: store.cfg('login.title'),
|
||||||
|
pageSubtitle: store.cfg('login.subtitle'),
|
||||||
|
userInfo: {
|
||||||
|
avatarUrl: config.STATIC_BASE_URL + config.PLACEHOLDER.WECHAT,
|
||||||
|
nickName: registered ? user.nickname : '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录 / 注册。
|
||||||
|
*
|
||||||
|
* 关键:不能凭本地缓存决定昵称。
|
||||||
|
* 退出登录会清空本地缓存,此时若直接生成随机昵称并提交,
|
||||||
|
* 会把老用户在服务端的真实昵称覆盖掉。正确做法是先取服务端资料:
|
||||||
|
* - 已有昵称 → 老用户,原样保留,不提交任何修改
|
||||||
|
* - 没有昵称 → 首次注册,生成一个随机昵称
|
||||||
|
*
|
||||||
|
* activeLogin 负责把数据库里的「已登录」标记置 1——只有用户亲自点这里才会置 1,
|
||||||
|
* 静默登录不碰它。它带鉴权,未登录时会自动完成静默登录,无需手动判断 token。
|
||||||
|
*/
|
||||||
|
onLoginBtnClick() {
|
||||||
|
wx.showLoading({ title: '请稍候', mask: true });
|
||||||
|
|
||||||
|
api
|
||||||
|
.activeLogin()
|
||||||
|
.then(() => api.getMe())
|
||||||
|
.then((user) => {
|
||||||
|
store.setUser(user);
|
||||||
|
if (user.nickname) return user;
|
||||||
|
return api.updateMe({ nickname: randomNickname() }).then((created) => {
|
||||||
|
store.setUser(created);
|
||||||
|
return created;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
||||||
|
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.showToast({ title: (err && err.message) || '登录失败', icon: 'none', mask: true });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onlogout() {
|
||||||
|
if (!this.data.loginStatue) return;
|
||||||
|
wx.showModal({
|
||||||
|
title: store.cfg('common.dialog.title'),
|
||||||
|
content: store.cfg('login.confirm.logout'),
|
||||||
|
confirmColor: '#ff0000',
|
||||||
|
success: (res) => {
|
||||||
|
if (!res.confirm) return;
|
||||||
|
wx.showLoading({ title: '请稍候', mask: true });
|
||||||
|
api.logout().then(() => {
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.switchTab({ url: '/pages/wode/wode' });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {},
|
||||||
|
"navigationBarTitleText": "个人信息"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<scroll-view class="scrollarea" scroll-y type="list">
|
||||||
|
|
||||||
|
<view class="imgview">
|
||||||
|
<image class="touxiang_img" src="{{userInfo.avatarUrl}}" mode="" />
|
||||||
|
</view>
|
||||||
|
<view class="imgview2">
|
||||||
|
<text class="imgtext2">{{pageTitle}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="imgview3">
|
||||||
|
<text class="imgtext3">{{pageSubtitle}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{!loginStatue}}" class="btn_wrapper">
|
||||||
|
<button plain class="btn1" bind:tap="onLoginBtnClick">
|
||||||
|
<text class="btn_text">{{LoginTag}}</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
<view wx:else="{{loginStatue}}" class="btn_wrapper">
|
||||||
|
<button plain class="btn2" bind:tap="onlogout">
|
||||||
|
<text class="btn_text">{{logoutText}}</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
|
||||||
|
</scroll-view>
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/* pages/LoginOrOutDetails/LoginOrOutDetails.wxss */
|
||||||
|
page {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollarea {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
|
.warp {
|
||||||
|
|
||||||
|
/* border: 1px solid #353535; */
|
||||||
|
padding: 10rpx 0;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
margin: 50rpx 100rpx;
|
||||||
|
border-radius: 30rpx;
|
||||||
|
}
|
||||||
|
.userinfo1 {
|
||||||
|
margin-top: 100rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo2 {
|
||||||
|
margin-top: 80rpx;
|
||||||
|
margin-bottom: 100rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.touxiang_btn[plain] {
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
padding: 0;
|
||||||
|
margin-left: 50rpx;
|
||||||
|
margin-right: 50rpx;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.touxiang_text {
|
||||||
|
margin-right: 50rpx;
|
||||||
|
font-size: 34rpx;
|
||||||
|
}
|
||||||
|
.imgview {
|
||||||
|
margin-top: 300rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.imgview2 {
|
||||||
|
margin-top: 10rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.imgview3 {
|
||||||
|
color: rgb(95, 95, 95);
|
||||||
|
font-size: 25rpx;
|
||||||
|
margin-top: 15rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.imgtext {
|
||||||
|
display: block;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.touxiang_img {
|
||||||
|
display: block;
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nickname_label {
|
||||||
|
margin-right: 50rpx;
|
||||||
|
font-size: 34rpx;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.nickname_input {
|
||||||
|
width: 160rpx;
|
||||||
|
padding-left: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn1 {
|
||||||
|
width: 546rpx;
|
||||||
|
margin-top: 30rpx;
|
||||||
|
border-radius: 15rpx;
|
||||||
|
}
|
||||||
|
.btn1[plain] {
|
||||||
|
border: 0px solid #d10000;
|
||||||
|
background-color: #d10000;
|
||||||
|
/* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); */
|
||||||
|
}
|
||||||
|
.btn2 {
|
||||||
|
width: 546rpx;
|
||||||
|
margin-top: 30rpx;
|
||||||
|
margin-bottom: 100rpx;
|
||||||
|
border-radius: 15rpx;
|
||||||
|
}
|
||||||
|
.btn2[plain] {
|
||||||
|
border: 0px solid #d10000;
|
||||||
|
background-color: #d10000;
|
||||||
|
/* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); */
|
||||||
|
}
|
||||||
|
.btn_text {
|
||||||
|
|
||||||
|
color: rgb(255, 255, 255);
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// pages/VideoDetails/VideoDetails.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const format = require('../../utils/format');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
code: '',
|
||||||
|
owned: false,
|
||||||
|
loading: true,
|
||||||
|
buyText: '',
|
||||||
|
contactText: '',
|
||||||
|
VideoTitle: '',
|
||||||
|
VideoDetails: '',
|
||||||
|
coverUrl: '',
|
||||||
|
playdata: [],
|
||||||
|
/** 列表上方的更新期数文案,整句来自后台配置 */
|
||||||
|
updatedText: '',
|
||||||
|
VideoPlayerSrc: '',
|
||||||
|
HiddenVideoControl: true,
|
||||||
|
top: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
const code = options.code;
|
||||||
|
if (!code) {
|
||||||
|
wx.switchTab({ url: '/pages/kecheng/kecheng' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setData({ code: code });
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 首次进入和从购买页返回都会走这里:买完回来要立刻变成已拥有。 */
|
||||||
|
onShow() {
|
||||||
|
app.ready().then(() => this.applyConfig());
|
||||||
|
if (this.data.code) this.load(this.data.code);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 按钮文案取自后台配置,后台改完小程序下拉刷新即可生效。 */
|
||||||
|
applyConfig() {
|
||||||
|
this.setData({
|
||||||
|
buyText: store.cfg('course.button.buy'),
|
||||||
|
contactText: store.cfg('course.button.contact'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
load(code) {
|
||||||
|
api
|
||||||
|
.getCourse(code)
|
||||||
|
.then((course) => {
|
||||||
|
this.setData({
|
||||||
|
loading: false,
|
||||||
|
owned: course.owned,
|
||||||
|
VideoTitle: course.title || '',
|
||||||
|
VideoDetails: course.intro || '',
|
||||||
|
coverUrl: course.coverUrl || '',
|
||||||
|
});
|
||||||
|
if (course.owned) this.loadLessons(code);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.setData({ loading: false });
|
||||||
|
wx.showToast({ title: err.message || store.cfg('course.tip.loadFailed'), icon: 'none' });
|
||||||
|
setTimeout(() => wx.switchTab({ url: '/pages/kecheng/kecheng' }), 1500);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
loadLessons(code) {
|
||||||
|
api
|
||||||
|
.getLessons(code)
|
||||||
|
.then((list) => {
|
||||||
|
const rows = (list || []).map((item) => ({
|
||||||
|
chapterId: item.chapterId,
|
||||||
|
playId: item.playId,
|
||||||
|
chapterTitle: item.chapterTitle,
|
||||||
|
lessonTitle: item.lessonTitle,
|
||||||
|
duration: item.duration,
|
||||||
|
publishedAt: format.toDateString(item.publishedAt),
|
||||||
|
coverUrl: item.coverUrl,
|
||||||
|
}));
|
||||||
|
// 期数文案整句来自后台配置,{n} 在这里替换成实际条数
|
||||||
|
this.setData({
|
||||||
|
playdata: rows,
|
||||||
|
updatedText: store.cfg('course.lesson.updated').replace('{n}', rows.length),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.setData({ playdata: [] });
|
||||||
|
console.warn('[VideoDetails] 条目加载失败', err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 点条目:向后端换一次性地址,真实文件不直接暴露。 */
|
||||||
|
onTapLesson(e) {
|
||||||
|
const item = this.data.playdata[e.currentTarget.dataset.index];
|
||||||
|
if (!item) return;
|
||||||
|
|
||||||
|
wx.showLoading({ title: '加载中', mask: true });
|
||||||
|
api
|
||||||
|
.getPlayUrl(this.data.code, item.chapterId, item.playId)
|
||||||
|
.then((res) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
this.setData({ VideoPlayerSrc: res.url, HiddenVideoControl: false, top: 420 });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
wx.showToast({ title: err.message || store.cfg('course.tip.playFailed'), icon: 'none' });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 购买入口:详情页不做交易,统一跳商业化页面。 */
|
||||||
|
goBuy() {
|
||||||
|
if (!this.data.code) return;
|
||||||
|
// 已经拥有就不必再进购买页:原地提示一句
|
||||||
|
if (this.data.owned) {
|
||||||
|
wx.showToast({ title: store.cfg('course.tip.owned'), icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.navigateTo({ url: '/pages/buy/buy?code=' + this.data.code });
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<!--pages/VideoDetails/VideoDetails.wxml-->
|
||||||
|
|
||||||
|
<!-- 已拥有:正常浏览 -->
|
||||||
|
<block wx:if="{{owned}}">
|
||||||
|
<video hidden="{{HiddenVideoControl}}" class="videoplayer" src="{{VideoPlayerSrc}}" />
|
||||||
|
<scroll-view class="scrollarea" scroll-y type="list" style="top:{{top}}rpx;">
|
||||||
|
<view class="jieshao">
|
||||||
|
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||||
|
<text decode class="video_miaoshu"> {{VideoDetails}}</text>
|
||||||
|
<text decode class="video_info"> {{updatedText}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="videolistcontainer" bind:tap="onTapLesson"
|
||||||
|
wx:for="{{playdata}}" wx:for-item="item" wx:for-index="index" wx:key="index" data-index="{{index}}">
|
||||||
|
<view class="videoimage">
|
||||||
|
<image class="coverimage" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
<view class="videoinfo">
|
||||||
|
<text class="videotitle">{{item.chapterTitle}}</text>
|
||||||
|
<text class="videodetails">{{item.lessonTitle}}</text>
|
||||||
|
<view class="videoinfo2">
|
||||||
|
<text class="videodata">{{item.publishedAt}}</text>
|
||||||
|
<text class="videotime">{{item.duration}}min</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</block>
|
||||||
|
|
||||||
|
<!-- 购买入口 -->
|
||||||
|
<block wx:else>
|
||||||
|
<scroll-view class="scrollarea" scroll-y type="list">
|
||||||
|
<view class="jieshao">
|
||||||
|
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||||
|
<text decode class="video_miaoshu"> {{VideoDetails}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view style="padding: 0 40rpx;">
|
||||||
|
<image style="width: 100%; border-radius: 16rpx;" src="{{coverUrl}}" mode="widthFix" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="fixed-btn-wrapper">
|
||||||
|
<view class="btn-group">
|
||||||
|
<button class="DianJiXiangQing1" bind:tap="goBuy">
|
||||||
|
<text class="DianJiXiangQing2">{{buyText}}</text>
|
||||||
|
</button>
|
||||||
|
<button class="DianJiXiangQing1" open-type="contact">
|
||||||
|
<text class="DianJiXiangQing2">{{contactText}}</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</block>
|
||||||
|
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
.videoplayer {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 420rpx;
|
||||||
|
width: 750rpx;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
.scrollarea {
|
||||||
|
position: relative;
|
||||||
|
top: 420rpx;
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: hidden;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.jieshao {
|
||||||
|
margin-bottom: 10rpx;
|
||||||
|
/* box-shadow: 0 4rpx 4rpx rgba(150, 150, 150, 0.5); */
|
||||||
|
position: relative;
|
||||||
|
height: 200rpx;
|
||||||
|
}
|
||||||
|
.video_biaoti {
|
||||||
|
text-align: center;
|
||||||
|
display: block;
|
||||||
|
font-size: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video_miaoshu {
|
||||||
|
text-align: center;
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.video_info {
|
||||||
|
position:absolute;
|
||||||
|
bottom: 10rpx;
|
||||||
|
display: block;
|
||||||
|
font-size: 24rpx;
|
||||||
|
right: 30rpx;
|
||||||
|
}
|
||||||
|
.video_list_content {
|
||||||
|
margin: 10rpx 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.videolistcontainer {
|
||||||
|
border-radius: 20rpx;
|
||||||
|
margin: 10rpx 10rpx;
|
||||||
|
box-shadow: 0 0 4rpx rgba(0, 0, 0, 0.5);
|
||||||
|
width: 730rpx;
|
||||||
|
height: 200rpx;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.videoimage {
|
||||||
|
width: 320rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-left: 10rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.videoinfo{
|
||||||
|
position: relative;
|
||||||
|
width: 390rpx;
|
||||||
|
height: 180rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.videotitle {
|
||||||
|
text-align: left;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.videodetails {
|
||||||
|
display: block;
|
||||||
|
margin: 10rpx 0rpx;
|
||||||
|
font-size: 25rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videoinfo2 {
|
||||||
|
position:absolute;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content:left;
|
||||||
|
}
|
||||||
|
.videodata {
|
||||||
|
font-size: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.videotime {
|
||||||
|
font-size: 20rpx;
|
||||||
|
margin-left: 40rpx;
|
||||||
|
}
|
||||||
|
.coverimage {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// pages/VideoDetailsPage/VideoDetailsPage.js
|
||||||
|
// 正文 HTML 放在后台配置里(settings.page.formula.content),这里只负责取出来交给 Parser 渲染。
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
|
||||||
|
Page({
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面的初始数据
|
||||||
|
*/
|
||||||
|
data: {
|
||||||
|
htmlSnip: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面加载
|
||||||
|
*/
|
||||||
|
onLoad(options) {
|
||||||
|
// 页面可能被直接打开(小程序码、搜一搜),等初始化把站点配置读回来
|
||||||
|
app.ready().then(() => this.setData({ htmlSnip: store.cfg('page.formula.content') }));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
|
*/
|
||||||
|
onReady() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面显示
|
||||||
|
*/
|
||||||
|
onShow() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面隐藏
|
||||||
|
*/
|
||||||
|
onHide() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面卸载
|
||||||
|
*/
|
||||||
|
onUnload() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||||||
|
*/
|
||||||
|
onPullDownRefresh() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面上拉触底事件的处理函数
|
||||||
|
*/
|
||||||
|
onReachBottom() {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点击右上角分享
|
||||||
|
*/
|
||||||
|
onShareAppMessage() {
|
||||||
|
|
||||||
|
},
|
||||||
|
//允许分享到朋友圈
|
||||||
|
onShareTimeline(){
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"Parser":"/Parser/index"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<text>VideoDetailsPage</text>
|
||||||
|
<text>富文本测试</text>
|
||||||
|
<Parser html="{{htmlSnip}}" />
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/* pages/VideoDetailsPage/VideoDetailsPage.wxss */
|
||||||
|
text {
|
||||||
|
/* display:inherit; */
|
||||||
|
left: 400rpx;
|
||||||
|
top: 100 px;
|
||||||
|
padding-left: 20rpx;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// pages/WebPageDetails/WebPageDetails.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const format = require('../../utils/format');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
htmlcontent: ' ',
|
||||||
|
author: '',
|
||||||
|
title: '',
|
||||||
|
date: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
const id = options.id;
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
api
|
||||||
|
.getArticle(id)
|
||||||
|
.then((article) => {
|
||||||
|
if (!article) return;
|
||||||
|
this.setData({
|
||||||
|
htmlcontent: article.content || ' ',
|
||||||
|
author: article.publisher || '',
|
||||||
|
title: article.title || '',
|
||||||
|
date: format.toDateString(article.publishedAt),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => console.error('[WebPageDetails] 加载失败', err));
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareTimeline() {
|
||||||
|
return { title: store.cfg('share.title') };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"Parser":"/Parser/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<scroll-view class="scrollarea" scroll-y type="list">
|
||||||
|
<text class="pagetitle">{{title}}</text>
|
||||||
|
|
||||||
|
<view class="pageauthoranddate">
|
||||||
|
<text class="pageauthor">{{author}}</text>
|
||||||
|
<text class="pagedate">{{date}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<Parser html="{{htmlcontent}}" />
|
||||||
|
|
||||||
|
|
||||||
|
</scroll-view>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/**index.wxss**/
|
||||||
|
page {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.scrollarea {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
|
.pagetitle {
|
||||||
|
display: block;
|
||||||
|
font-size: 40rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.pagecontent {
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
text-align: left;
|
||||||
|
text-indent: 0rem;
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
padding: 0 10rpx;
|
||||||
|
}
|
||||||
|
.pagecontent:first-child {
|
||||||
|
margin-top: 30rpx;
|
||||||
|
}
|
||||||
|
.pageimg {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.pagevideo {
|
||||||
|
width: 750rpx;
|
||||||
|
height: 421rpx;
|
||||||
|
}
|
||||||
|
.pageauthor {
|
||||||
|
color: rgb(165, 165, 165);
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.pagedate {
|
||||||
|
color: rgb(151, 151, 151);
|
||||||
|
padding-left: 60rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
.pageauthoranddate {
|
||||||
|
height: 80rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.sharebtn[plain] {
|
||||||
|
display: inline;
|
||||||
|
color: cadetblue;
|
||||||
|
border:none;
|
||||||
|
font-size: 30rpx;
|
||||||
|
margin:0 rpx;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
margin-right: 0rpx;
|
||||||
|
padding:0 ;
|
||||||
|
width: 120rpx;
|
||||||
|
}
|
||||||
|
.content123 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
// pages/buy/buy.js
|
||||||
|
//
|
||||||
|
// 商业化页面:所有购买入口都落到这里。
|
||||||
|
// 职责是「确认订单 → 拉起微信支付 → 确认发货」。
|
||||||
|
//
|
||||||
|
// 两种进入方式:
|
||||||
|
// - 带 ?code=xxx(从详情页进来):只显示这一条
|
||||||
|
// - 不带参数:列出全部条目,一条一个购买按钮
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const format = require('../../utils/format');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
const POLL_INTERVAL = 1500;
|
||||||
|
// 微信的发货推送实测要 13~17 秒才到,原来只等 12 秒,用户多半先拿到兜底提示而不是成功提示
|
||||||
|
const POLL_MAX = 20;
|
||||||
|
|
||||||
|
/** iPhone 上跑 Apple 支付要求微信客户端 ≥ 这个版本 */
|
||||||
|
const IOS_MIN_WECHAT = '8.0.68';
|
||||||
|
|
||||||
|
/** 当前微信客户端版本号,取不到就返回空串。 */
|
||||||
|
function clientVersion() {
|
||||||
|
try {
|
||||||
|
const info = typeof wx.getAppBaseInfo === 'function' ? wx.getAppBaseInfo() : wx.getSystemInfoSync();
|
||||||
|
return (info && info.version) || '';
|
||||||
|
} catch (err) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 版本号比大小:'8.0.68' vs '8.0.5' → 正数表示前者新。 */
|
||||||
|
function compareVersion(a, b) {
|
||||||
|
const left = String(a).split('.').map(Number);
|
||||||
|
const right = String(b).split('.').map(Number);
|
||||||
|
const len = Math.max(left.length, right.length);
|
||||||
|
for (let i = 0; i < len; i += 1) {
|
||||||
|
const l = left[i] || 0;
|
||||||
|
const r = right[i] || 0;
|
||||||
|
if (l !== r) return l - r;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
code: '',
|
||||||
|
loading: true,
|
||||||
|
buying: false,
|
||||||
|
owned: false,
|
||||||
|
title: '',
|
||||||
|
coverUrl: '',
|
||||||
|
priceYuan: '',
|
||||||
|
list: [],
|
||||||
|
// 页面上的固定文案全部来自后台配置,这里只放容器
|
||||||
|
textBuy: '',
|
||||||
|
textBuyList: '',
|
||||||
|
textPaying: '',
|
||||||
|
textOwned: '',
|
||||||
|
textEmpty: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(options) {
|
||||||
|
// 页面可能被直接打开(分享、扫码),先等初始化把站点配置读回来
|
||||||
|
app.ready().then(() => this.applyTexts());
|
||||||
|
const code = options && options.code;
|
||||||
|
if (code) {
|
||||||
|
this.setData({ code: code });
|
||||||
|
this.load(code);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadList();
|
||||||
|
},
|
||||||
|
|
||||||
|
applyTexts() {
|
||||||
|
this.setData({
|
||||||
|
textBuy: store.cfg('course.buy.button'),
|
||||||
|
textBuyList: store.cfg('course.buy.buttonList'),
|
||||||
|
textPaying: store.cfg('course.buy.paying'),
|
||||||
|
textOwned: store.cfg('course.buy.owned'),
|
||||||
|
textEmpty: store.cfg('course.buy.empty'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
load(code) {
|
||||||
|
api
|
||||||
|
.getCourse(code)
|
||||||
|
.then((course) => {
|
||||||
|
this.setData({
|
||||||
|
loading: false,
|
||||||
|
owned: course.owned,
|
||||||
|
title: course.title || '',
|
||||||
|
coverUrl: course.coverUrl || '',
|
||||||
|
priceYuan: format.fenToYuan(course.priceFen),
|
||||||
|
});
|
||||||
|
// 已经拥有就不用再买了,避免重复下单
|
||||||
|
if (course.owned) this.rejectOut(store.cfg('course.tip.owned'));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.setData({ loading: false });
|
||||||
|
// 条目被下架或编号拼错,后端会返回错误,这里按同样的方式退出
|
||||||
|
this.rejectOut((err && err.message) || store.cfg('course.tip.notFound'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 不带编号进来:列出全部条目,让用户自己挑。 */
|
||||||
|
loadList() {
|
||||||
|
api
|
||||||
|
.getCourses()
|
||||||
|
.then((courses) => {
|
||||||
|
this.setData({
|
||||||
|
loading: false,
|
||||||
|
list: (courses || []).map((c) => ({
|
||||||
|
code: c.code,
|
||||||
|
title: c.title,
|
||||||
|
priceYuan: format.fenToYuan(c.priceFen),
|
||||||
|
owned: c.owned,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.setData({ loading: false });
|
||||||
|
wx.showToast({ title: (err && err.message) || store.cfg('course.tip.loadFailed'), icon: 'none' });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 进错页面(没带编号、条目不存在、已经买过):提示一句然后退出去。 */
|
||||||
|
rejectOut(message) {
|
||||||
|
wx.showToast({ title: message, icon: 'none' });
|
||||||
|
setTimeout(() => this.back(), 1500);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 退回上一页;没有上一页(直接打开)就回知识页,避免停在死页面。 */
|
||||||
|
back() {
|
||||||
|
if (getCurrentPages().length > 1) {
|
||||||
|
wx.navigateBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.switchTab({ url: '/pages/kecheng/kecheng' });
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买:下单 → 拉起支付 → 轮询订单状态确认发货。
|
||||||
|
* 编号优先取按钮上的 data-code(列表模式),没有就用页面参数(单条模式)。
|
||||||
|
*/
|
||||||
|
buyNow(e) {
|
||||||
|
const code =
|
||||||
|
(e && e.currentTarget && e.currentTarget.dataset && e.currentTarget.dataset.code) || this.data.code;
|
||||||
|
if (this.data.buying || !code) return;
|
||||||
|
|
||||||
|
// 购买的前置条件:用户主动使用过登录功能。静默登录不算。
|
||||||
|
if (!store.isLoggedIn()) {
|
||||||
|
wx.showModal({
|
||||||
|
title: store.cfg('course.login.title'),
|
||||||
|
content: store.cfg('course.login.desc'),
|
||||||
|
confirmText: store.cfg('course.login.confirm'),
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
wx.navigateTo({ url: '/pages/LoginOrOutDetails/LoginOrOutDetails' });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof wx.requestVirtualPayment !== 'function') {
|
||||||
|
wx.showToast({ title: '当前微信版本不支持支付,请升级微信', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// iOS 版本预检放在下单之前:版本不够时不该先建出一笔待支付订单
|
||||||
|
if (!this.checkIosVersion()) return;
|
||||||
|
|
||||||
|
this.setData({ buying: true });
|
||||||
|
wx.showLoading({ title: store.cfg('course.loading.paying'), mask: true });
|
||||||
|
|
||||||
|
api
|
||||||
|
.createOrder(code)
|
||||||
|
.then((order) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
return api.requestVirtualPayment(order.payData).then(() => order.outTradeNo);
|
||||||
|
})
|
||||||
|
.then((outTradeNo) => this.waitForDelivery(outTradeNo))
|
||||||
|
.catch((err) => {
|
||||||
|
wx.hideLoading();
|
||||||
|
this.setData({ buying: false });
|
||||||
|
// 用户主动取消不算错误
|
||||||
|
if (err && err.errMsg && err.errMsg.indexOf('cancel') >= 0) return;
|
||||||
|
// 拉起支付失败时微信给的是 errMsg/errno,服务端报错给的是 message。
|
||||||
|
// 原来只弹「支付失败」,把排查线索全丢了,所以原样带出来。
|
||||||
|
const detail = (err && (err.errMsg || err.message)) || '未知错误';
|
||||||
|
const errno = err && (err.errno || err.errCode);
|
||||||
|
wx.showModal({
|
||||||
|
title: '支付失败',
|
||||||
|
content: errno ? detail + '\n错误码:' + errno : detail,
|
||||||
|
showCancel: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iPhone 上 Apple 支付要求微信 ≥ 8.0.68,低了拉不起来。
|
||||||
|
* 只在 iOS 上校验;安卓等没有这个限制,取不到版本号也不拦(交给微信自己报错)。
|
||||||
|
*/
|
||||||
|
checkIosVersion() {
|
||||||
|
if (api.devicePlatform() !== 'ios') return true;
|
||||||
|
const version = clientVersion();
|
||||||
|
if (!version || compareVersion(version, IOS_MIN_WECHAT) >= 0) return true;
|
||||||
|
|
||||||
|
wx.showModal({
|
||||||
|
content: '请先升级微信',
|
||||||
|
showCancel: false,
|
||||||
|
confirmText: '知道了',
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功后权益由服务端发货推送发放,存在秒级延迟,这里轮询确认。
|
||||||
|
* 即便轮询全部超时也不会丢单:服务端有定时查单兜底。
|
||||||
|
*/
|
||||||
|
waitForDelivery(outTradeNo) {
|
||||||
|
let attempts = 0;
|
||||||
|
const poll = () => {
|
||||||
|
attempts += 1;
|
||||||
|
return api.getOrder(outTradeNo).then((order) => {
|
||||||
|
if (order.status === 2) {
|
||||||
|
this.setData({ buying: false, owned: true });
|
||||||
|
wx.showToast({ title: store.cfg('course.tip.buySuccess'), icon: 'success', mask: true });
|
||||||
|
// 单条模式从详情页进来,买完退回去;列表模式留在原地刷新
|
||||||
|
if (this.data.code) {
|
||||||
|
setTimeout(() => this.back(), 1500);
|
||||||
|
} else {
|
||||||
|
this.loadList();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (attempts >= POLL_MAX || order.status === 3 || order.status === 4) {
|
||||||
|
this.setData({ buying: false });
|
||||||
|
wx.showToast({ title: store.cfg('course.tip.payPending'), icon: 'none', duration: 3000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL)).then(poll);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return poll();
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<!--pages/buy/buy.wxml-->
|
||||||
|
|
||||||
|
<view class="buy-page">
|
||||||
|
<!-- 带 ?code= 进来就只买这一条,否则列出全部条目、一条一个购买按钮。
|
||||||
|
注意别在 wx:if 和 wx:else 之间插注释。 -->
|
||||||
|
<view class="buy-single" wx:if="{{code}}">
|
||||||
|
<text class="buy-title">{{title}}</text>
|
||||||
|
<text class="buy-price">¥{{priceYuan}}</text>
|
||||||
|
<button
|
||||||
|
class="buy-btn"
|
||||||
|
disabled="{{buying || owned}}"
|
||||||
|
bindtap="buyNow"
|
||||||
|
>{{owned ? textOwned : (buying ? textPaying : textBuy)}}</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="buy-list" wx:else>
|
||||||
|
<view class="buy-item" wx:for="{{list}}" wx:key="code">
|
||||||
|
<view class="buy-item-main">
|
||||||
|
<text class="buy-item-title">{{item.title}}</text>
|
||||||
|
<text class="buy-item-price">¥{{item.priceYuan}}</text>
|
||||||
|
</view>
|
||||||
|
<button
|
||||||
|
class="buy-btn buy-btn-mini"
|
||||||
|
size="mini"
|
||||||
|
disabled="{{buying || item.owned}}"
|
||||||
|
data-code="{{item.code}}"
|
||||||
|
bindtap="buyNow"
|
||||||
|
>{{item.owned ? textOwned : textBuyList}}</button>
|
||||||
|
</view>
|
||||||
|
<view class="buy-empty" wx:if="{{!loading && list.length === 0}}">
|
||||||
|
<text>{{textEmpty}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/* pages/buy/buy.wxss */
|
||||||
|
|
||||||
|
.buy-page {
|
||||||
|
min-height: 100vh;
|
||||||
|
background: #f6f7f9;
|
||||||
|
padding: 24rpx 24rpx 48rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 单条 ─────────────────────────────────────────────── */
|
||||||
|
.buy-single {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 48rpx 32rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-title {
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #222;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-price {
|
||||||
|
margin-top: 24rpx;
|
||||||
|
font-size: 44rpx;
|
||||||
|
color: #ff4d4f;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 列表 ─────────────────────────────────────────────── */
|
||||||
|
.buy-list {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 28rpx 24rpx;
|
||||||
|
border-bottom: 1rpx solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-item-main {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-item-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #222;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-item-price {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #ff4d4f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-empty {
|
||||||
|
padding: 80rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 26rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 按钮 ─────────────────────────────────────────────── */
|
||||||
|
.buy-btn {
|
||||||
|
margin-top: 40rpx;
|
||||||
|
background: #07c160;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 30rpx;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
line-height: 2.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-btn-mini {
|
||||||
|
margin-top: 0;
|
||||||
|
flex: none;
|
||||||
|
font-size: 26rpx;
|
||||||
|
line-height: 2.4;
|
||||||
|
padding: 0 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buy-btn[disabled] {
|
||||||
|
background: #d8d8d8;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 去掉微信按钮自带的那圈边框 */
|
||||||
|
.buy-btn::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
// pages/index/index.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const config = require('../../config/index');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
const PAGE_SIZE = 10;
|
||||||
|
|
||||||
|
/** 广播文字默认色(红),配置里没填或填得不像颜色时用它 */
|
||||||
|
const DEFAULT_BROADCAST_COLOR = '#e60012';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只认安全的颜色写法,其余一律回退默认色。
|
||||||
|
* 后台是文本框,填错一个字符不该把首页样式搞坏,也不该让这个值变成注入点。
|
||||||
|
*/
|
||||||
|
function safeColor(value) {
|
||||||
|
const v = String(value || '').trim();
|
||||||
|
if (/^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$/.test(v)) return v;
|
||||||
|
if (/^rgba?\([\d\s.,%]+\)$/.test(v)) return v;
|
||||||
|
if (/^hsla?\([\d\s.,%]+\)$/.test(v)) return v;
|
||||||
|
if (/^[a-zA-Z]{3,20}$/.test(v)) return v; // red / orange / tomato ...
|
||||||
|
return DEFAULT_BROADCAST_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
staticBase: config.STATIC_BASE_URL,
|
||||||
|
banners: [],
|
||||||
|
courseList: [],
|
||||||
|
freeCourseList: [],
|
||||||
|
articles: [],
|
||||||
|
page: 1,
|
||||||
|
articleTotal: 0,
|
||||||
|
loadingMore: false,
|
||||||
|
noMore: false,
|
||||||
|
title1: '',
|
||||||
|
title2: '',
|
||||||
|
title3: '',
|
||||||
|
footerText: '',
|
||||||
|
/** 首页信息广播文案,空则不显示整条 */
|
||||||
|
broadcast: '',
|
||||||
|
/** 文案超出宽度时才横向滚动 */
|
||||||
|
broadcastScroll: false,
|
||||||
|
/** 广播文字颜色,取自 home.broadcast_color */
|
||||||
|
broadcastColor: DEFAULT_BROADCAST_COLOR,
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
// 等应用初始化完成再取配置,避免首屏读到空缓存
|
||||||
|
app.ready().then(() => this.applyConfig());
|
||||||
|
this.loadAll();
|
||||||
|
},
|
||||||
|
|
||||||
|
applyConfig() {
|
||||||
|
this.setData(
|
||||||
|
{
|
||||||
|
title1: store.cfg('home.title.paid'),
|
||||||
|
title2: store.cfg('home.title.trial'),
|
||||||
|
title3: store.cfg('home.title.public'),
|
||||||
|
footerText: store.cfg('home.footer_text'),
|
||||||
|
broadcast: store.cfg('home.broadcast') || '',
|
||||||
|
broadcastColor: safeColor(store.cfg('home.broadcast_color')),
|
||||||
|
broadcastScroll: false,
|
||||||
|
},
|
||||||
|
// 等渲染完再量宽度:只有真放不下才让它滚动,短文案就静静居中
|
||||||
|
() => this.measureBroadcast(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 量一下广播文字有没有超出容器,超了才加滚动动画。量不到就当不超。 */
|
||||||
|
measureBroadcast() {
|
||||||
|
if (!this.data.broadcast) return;
|
||||||
|
const query = wx.createSelectorQuery().in(this);
|
||||||
|
query.select('.broadcast-body').boundingClientRect();
|
||||||
|
query.select('.broadcast-text').boundingClientRect();
|
||||||
|
query.exec((res) => {
|
||||||
|
const box = res && res[0];
|
||||||
|
const text = res && res[1];
|
||||||
|
if (!box || !text) return;
|
||||||
|
if (text.width > box.width) this.setData({ broadcastScroll: true });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
loadAll() {
|
||||||
|
this.setData({ page: 1, noMore: false });
|
||||||
|
|
||||||
|
api
|
||||||
|
.getBanners()
|
||||||
|
.then((list) => this.setData({ banners: list || [] }))
|
||||||
|
.catch((err) => console.error('[index] 轮播加载失败', err));
|
||||||
|
|
||||||
|
api
|
||||||
|
.getHomeCourses()
|
||||||
|
.then((list) => this.setData({ courseList: list || [] }))
|
||||||
|
.catch((err) => console.error('[index] 新课加载失败', err));
|
||||||
|
|
||||||
|
api
|
||||||
|
.getHomeFreeCourses()
|
||||||
|
.then((list) => this.setData({ freeCourseList: list || [] }))
|
||||||
|
.catch((err) => console.error('[index] 试听列表加载失败', err));
|
||||||
|
|
||||||
|
api
|
||||||
|
.getArticles(1, PAGE_SIZE)
|
||||||
|
.then((res) => this.setData({ articles: res.items || [], articleTotal: res.total || 0, page: 1 }))
|
||||||
|
.catch((err) => console.error('[index] 文章加载失败', err));
|
||||||
|
},
|
||||||
|
|
||||||
|
onPullDownRefresh() {
|
||||||
|
Promise.all([this.reload()]).then(() => wx.stopPullDownRefresh());
|
||||||
|
},
|
||||||
|
|
||||||
|
async reload() {
|
||||||
|
try {
|
||||||
|
const cfg = await api.getConfig();
|
||||||
|
store.setSiteConfig(cfg);
|
||||||
|
this.applyConfig();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[index] 配置刷新失败', err);
|
||||||
|
}
|
||||||
|
this.loadAll();
|
||||||
|
},
|
||||||
|
|
||||||
|
onReachBottom() {
|
||||||
|
if (this.data.loadingMore || this.data.noMore) return;
|
||||||
|
const next = this.data.page + 1;
|
||||||
|
this.setData({ loadingMore: true });
|
||||||
|
|
||||||
|
api
|
||||||
|
.getArticles(next, PAGE_SIZE)
|
||||||
|
.then((res) => {
|
||||||
|
const merged = this.data.articles.concat(res.items || []);
|
||||||
|
this.setData({
|
||||||
|
articles: merged,
|
||||||
|
page: next,
|
||||||
|
loadingMore: false,
|
||||||
|
noMore: merged.length >= (res.total || 0),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('[index] 加载更多失败', err);
|
||||||
|
this.setData({ loadingMore: false });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
toArticle(e) {
|
||||||
|
wx.navigateTo({ url: '/pages/WebPageDetails/WebPageDetails?id=' + e.currentTarget.dataset.id });
|
||||||
|
},
|
||||||
|
|
||||||
|
toNewCourse(e) {
|
||||||
|
wx.navigateTo({ url: '/pages/IndexNewCourseDetails/IndexNewCourseDetails?id=' + e.currentTarget.dataset.id });
|
||||||
|
},
|
||||||
|
|
||||||
|
toFreeCourse(e) {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '/pages/IndexFreeCourseDetails/IndexFreeCourseDetails?seriesNo=' + e.currentTarget.dataset.series,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareTimeline() {
|
||||||
|
return { title: store.cfg('share.title') };
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {},
|
||||||
|
"onReachBottomDistance":50,
|
||||||
|
"enablePullDownRefresh":true
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<!--index.wxml-->
|
||||||
|
|
||||||
|
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||||
|
<!-- 信息广播:文案取自站点配置 home.broadcast,空则整条不显示。
|
||||||
|
文字放得下就静态居中,放不下就横向滚动(避免长通知被截断看不到)。 -->
|
||||||
|
<view class="broadcast" wx:if="{{broadcast}}">
|
||||||
|
<view class="broadcast-body">
|
||||||
|
<view class="broadcast-track {{broadcastScroll ? 'broadcast-scroll' : ''}}" style="color: {{broadcastColor}}">
|
||||||
|
<text class="broadcast-text">{{broadcast}}</text>
|
||||||
|
<text class="broadcast-text broadcast-clone" wx:if="{{broadcastScroll}}">{{broadcast}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="banner">
|
||||||
|
<swiper class="bannerswiper" autoplay interval="20000" circular indicator-dots indicator-color="rgba(255, 255, 255, .3)" indicator-active-color="rgba(255, 255, 255, 1.0)" indicator-type="normal" duration="1000" easing-function="easeOutCubic">
|
||||||
|
<swiper-item wx:for="{{banners}}" wx:for-item="item" wx:key="id" class="bannerswiperitem">
|
||||||
|
<image class="indeximage" src="{{item.imageUrl}}" mode="aspectFill" />
|
||||||
|
</swiper-item>
|
||||||
|
</swiper>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 新课上线 -->
|
||||||
|
<view class="shouyetupianlist">
|
||||||
|
<view wx:if="{{courseList.length > 0}}" class="biaoti01">
|
||||||
|
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/xinke.png" mode="aspectFill" />
|
||||||
|
<text decode> {{title1}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="shouyetupianlistcontent" wx:for="{{courseList}}" wx:for-item="item" wx:for-index="index" wx:key="id" data-id="{{item.id}}" bind:tap="toNewCourse">
|
||||||
|
<view class="hengxianglist">
|
||||||
|
<image class="indeximagelist" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 自我学习 -->
|
||||||
|
<view class="shouyetupianlist">
|
||||||
|
<view wx:if="{{freeCourseList.length > 0}}" class="biaoti01">
|
||||||
|
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/ziwoxuexi.png" mode="aspectFill" />
|
||||||
|
<text decode> {{title2}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="shouyetupianlistcontent" wx:for="{{freeCourseList}}" wx:for-item="item" wx:for-index="index" wx:key="id" data-series="{{item.seriesNo}}" bind:tap="toFreeCourse">
|
||||||
|
<view class="hengxianglist">
|
||||||
|
<image class="indeximagelist" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 知识速通 -->
|
||||||
|
<view class="shouyetupianlist">
|
||||||
|
<view wx:if="{{articles.length > 0}}" class="biaoti01">
|
||||||
|
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/sutong.png" mode="aspectFill" />
|
||||||
|
<text decode> {{title3}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="shouyetupianlistcontent01" wx:for="{{articles}}" wx:for-item="item" wx:for-index="index" wx:key="id" bind:tap="toArticle" data-id="{{item.id}}">
|
||||||
|
<view class="hengxianglist01">
|
||||||
|
<image class="indeximagelist01" src="{{item.thumbUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
<view class="indeximagelistmiaosu">{{item.title}}</view>
|
||||||
|
<view class="indeximagelistmiaosu01">
|
||||||
|
<text class="indeximagelistmiaosu0102">{{item.intro}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view style="width: auto; margin: 0px auto; margin-bottom: 10px;">
|
||||||
|
<text wx:if="{{noMore}}">{{footerText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</scroll-view>
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
/**index.wxss**/
|
||||||
|
/* 暂时未用到
|
||||||
|
page {
|
||||||
|
|
||||||
|
} */
|
||||||
|
|
||||||
|
|
||||||
|
.container {
|
||||||
|
padding:0;
|
||||||
|
align-items:center;
|
||||||
|
flex-direction:column;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
.mulucontainer {
|
||||||
|
width: 710rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
white-space: nowrap; /*强制子元素为一行 */
|
||||||
|
margin-left: 25rpx;
|
||||||
|
}
|
||||||
|
.navpage001 {
|
||||||
|
display: inline-block;
|
||||||
|
width: 150rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
margin-right: 25rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.navpage001img {
|
||||||
|
margin:0 auto;
|
||||||
|
width: 60%;
|
||||||
|
height: 60%;
|
||||||
|
}
|
||||||
|
.mulucontainer .navpage001:last-child{
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
.banner{
|
||||||
|
width: 100%;
|
||||||
|
height: 400rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.shouyetupianlist {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;/* 允许内容换行 */
|
||||||
|
justify-content:space-between;/* 水平方向上两端对齐 */
|
||||||
|
/* 左右各留 20rpx,和卡片之间的 20rpx 间距相同,视觉上三边等宽 */
|
||||||
|
width: 750rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
}
|
||||||
|
.shouyetupianlistcontent {
|
||||||
|
/* display: inline; */
|
||||||
|
padding: 0;
|
||||||
|
/* 水平间距交给容器 padding + space-between,这里只留出上下行距 */
|
||||||
|
margin: 0 0 40rpx 0;
|
||||||
|
height: 204rpx;
|
||||||
|
/* (750 - 左右各 20 - 中间 20) / 2 = 345 */
|
||||||
|
width: 345rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.shouyetupianlistcontent01 {
|
||||||
|
position: relative;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 40rpx 0;
|
||||||
|
height: 260rpx;
|
||||||
|
/* 容器内容区宽度,正好铺满 */
|
||||||
|
width: 710rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.indeximagelist {
|
||||||
|
width: 100%;
|
||||||
|
height: 204rpx;
|
||||||
|
}
|
||||||
|
.indeximagelist01 {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tupianwenzi {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.biaoti01 {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
height: 60rpx;
|
||||||
|
align-items: center;
|
||||||
|
/* 左侧对齐交给容器 padding,去掉后标题和小图/卡片左边缘对齐 */
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
.biaoti01img {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
}
|
||||||
|
.hengxianglist01 {
|
||||||
|
display: flex;
|
||||||
|
width: 300rpx;
|
||||||
|
height: inherit; /* 推荐尺寸在300*250rpx 即150*125px */
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.indeximage{
|
||||||
|
border-radius: 20rpx;
|
||||||
|
height: 350rpx;
|
||||||
|
width: 710rpx;
|
||||||
|
transform: translate(20rpx, 30rpx);
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bannerswiper {
|
||||||
|
height: 390rpx;
|
||||||
|
}
|
||||||
|
.indeximagelistmiaosu {
|
||||||
|
font-size: 28rpx;
|
||||||
|
display:flex;
|
||||||
|
position: absolute;
|
||||||
|
top: 10rpx;
|
||||||
|
left: 300rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 20rpx;
|
||||||
|
}
|
||||||
|
.indeximagelistmiaosu01 {
|
||||||
|
display: inline;
|
||||||
|
position: absolute;
|
||||||
|
left: 300rpx;
|
||||||
|
/* 原为 35px:再看它与标题的关系(下面那行 top:-15px),两者会重叠。
|
||||||
|
标题框实际占到 40px,这里退到 90rpx(45px)之后才真正错开。 */
|
||||||
|
top: 90rpx;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 20rpx;
|
||||||
|
}
|
||||||
|
.indeximagelistmiaosu0102 {
|
||||||
|
font-size: 20rpx;
|
||||||
|
position: relative;
|
||||||
|
/* 原为 -15px:这一步把简介往上提了 15px,正好压到标题上。
|
||||||
|
容器已经让开了位置,这里不再需要负偏移。 */
|
||||||
|
top: 0;
|
||||||
|
width: 370rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── 信息广播(首页最上方,文案为空则整条不渲染)─────────────────
|
||||||
|
文案放得下就静态居中;放不下加 .broadcast-scroll 横向滚动,
|
||||||
|
并把同一段文字渲染两遍首尾相接,滚动到 -50% 时正好接上,看不出循环接缝。 */
|
||||||
|
.broadcast {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 710rpx;
|
||||||
|
margin: 12rpx auto 0;
|
||||||
|
padding: 14rpx 20rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: #fff7e6;
|
||||||
|
border: 1rpx solid #ffe3a3;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.broadcast-body {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 静态:居中显示,实在超了也留个省略号兜底 */
|
||||||
|
.broadcast-track {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #e60012; /* 兜底色:真实颜色由 home.broadcast_color 以内联样式覆盖 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动:两段文字并排,整体左移 50% 后无缝重来 */
|
||||||
|
.broadcast-scroll {
|
||||||
|
display: inline-flex;
|
||||||
|
overflow: visible;
|
||||||
|
text-overflow: clip;
|
||||||
|
animation: broadcast-marquee 18s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动时两段文字各带一个等宽右边距,整条宽度 = 2 ×(文字+间距),
|
||||||
|
左移 50% 正好是一段,循环无缝。
|
||||||
|
这个边距**只能在滚动时加**:静态居中时它会算进居中范围,把文字整体推偏。 */
|
||||||
|
.broadcast-scroll .broadcast-text {
|
||||||
|
margin-right: 80rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes broadcast-marquee {
|
||||||
|
from {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
// pages/kecheng/kecheng.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const config = require('../../config/index');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
staticBase: config.STATIC_BASE_URL,
|
||||||
|
hasCourse: false,
|
||||||
|
ownedCourses: [],
|
||||||
|
tipsHtml: '',
|
||||||
|
/** 账号被封禁:不显示已购权益,改为显示提示。文字全部来自后台配置 */
|
||||||
|
blocked: false,
|
||||||
|
blockedTitle: '',
|
||||||
|
blockedDesc: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
// 旧版本用 10ms 轮询最多 5 秒等登录数据,这里改为等初始化完成
|
||||||
|
app.ready().then(() => this.refresh());
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
if (store.isLoggedIn()) this.refresh();
|
||||||
|
// 未登录(含刚退出登录)不能留着一份别人的已购列表
|
||||||
|
else this.setData({ ownedCourses: [], hasCourse: false });
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
this.loadTips();
|
||||||
|
|
||||||
|
api
|
||||||
|
.getEntitlements()
|
||||||
|
.then((list) => {
|
||||||
|
store.setEntitlements(list);
|
||||||
|
this.setData({ ownedCourses: list || [], hasCourse: (list || []).length > 0, blocked: false });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err && err.code === api.ACCOUNT_DISABLED) {
|
||||||
|
// 服务端不返回权益了,本地缓存也一并清掉,免得露出上一次的已购内容
|
||||||
|
store.setEntitlements([]);
|
||||||
|
this.setData({
|
||||||
|
ownedCourses: [],
|
||||||
|
hasCourse: false,
|
||||||
|
blocked: true,
|
||||||
|
blockedTitle: store.cfg('account.blocked_title'),
|
||||||
|
blockedDesc: store.cfg('account.blocked_desc'),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.warn('[kecheng] 已购内容加载失败', err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
loadTips() {
|
||||||
|
if (this.data.tipsHtml) return;
|
||||||
|
api
|
||||||
|
.getTips()
|
||||||
|
.then((tip) => this.setData({ tipsHtml: (tip && tip.content) || ' ' }))
|
||||||
|
.catch((err) => console.warn('[kecheng] 文案加载失败', err));
|
||||||
|
},
|
||||||
|
|
||||||
|
toMyCourse(e) {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '/pages/VideoDetails/VideoDetails?code=' + e.currentTarget.dataset.code,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"Parser":"/Parser/index"
|
||||||
|
},
|
||||||
|
"navigationBarTitleText": "知识"
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||||
|
<block wx:if="{{blocked}}">
|
||||||
|
<view class="blocked-tip">
|
||||||
|
<text wx:if="{{blockedTitle}}" class="blocked-title">{{blockedTitle}}</text>
|
||||||
|
<text wx:if="{{blockedDesc}}" class="blocked-desc">{{blockedDesc}}</text>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
|
||||||
|
<block wx:elif="{{!hasCourse}}">
|
||||||
|
<view style="width: 100%;height: 400rpx;">
|
||||||
|
<image style="margin-top: 30rpx; margin-left: 20rpx; height: 350rpx; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); width: 710rpx; border-radius: 20rpx; background-color: rgb(0, 255, 255);"
|
||||||
|
src="{{staticBase}}/Images/Banner/BGbanner.png" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
<Parser html="{{tipsHtml}}" />
|
||||||
|
</block>
|
||||||
|
|
||||||
|
<block wx:elif="{{hasCourse}}">
|
||||||
|
<view wx:for="{{ownedCourses}}" wx:for-item="item" wx:for-index="index" wx:key="courseId"
|
||||||
|
class="kecheng" bind:tap="toMyCourse" data-code="{{item.code}}">
|
||||||
|
<view class="kecheng_video_up">
|
||||||
|
<image class="kecheng_img" src="{{item.coverUrl}}" mode="aspectFit" />
|
||||||
|
</view>
|
||||||
|
<view class="kecheng_video_right">
|
||||||
|
<text class="kecheng_title">{{item.title}}</text>
|
||||||
|
<text class="kecheng_details">{{item.intro}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* pages/kecheng/kecheng.wxss */
|
||||||
|
.container {
|
||||||
|
padding:0;
|
||||||
|
align-items:center;
|
||||||
|
flex-direction:column;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
.kecheng {
|
||||||
|
width: 710rpx;
|
||||||
|
height: 275rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
justify-content: left;
|
||||||
|
align-items: center;
|
||||||
|
margin: 6px 0;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.kecheng_video_up {
|
||||||
|
width: 400rpx;
|
||||||
|
height: 225rpx;
|
||||||
|
margin-left: 10rpx;
|
||||||
|
}
|
||||||
|
.kecheng_video_right {
|
||||||
|
margin-left: 5rpx;
|
||||||
|
width: 290rpx;
|
||||||
|
height: 225rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
}
|
||||||
|
.kecheng_img {
|
||||||
|
background-color: #15457b;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 15rpx;
|
||||||
|
}
|
||||||
|
.kecheng_title {
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.kecheng_details {
|
||||||
|
display: block;
|
||||||
|
font-size: 25rpx;
|
||||||
|
margin-top: 15rpx;
|
||||||
|
margin-left: 15rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 账号异常提示的容器:整页替换成这一块,文字由后台配置下发 */
|
||||||
|
.blocked-tip {
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 710rpx;
|
||||||
|
margin-top: 120rpx;
|
||||||
|
padding: 60rpx 40rpx;
|
||||||
|
border: 1rpx solid #ffd9d9;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
background-color: #fff7f7;
|
||||||
|
}
|
||||||
|
.blocked-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
color: #e60012;
|
||||||
|
}
|
||||||
|
.blocked-desc {
|
||||||
|
display: block;
|
||||||
|
margin-top: 20rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
text-align: center;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// pages/orders/orders.js
|
||||||
|
//
|
||||||
|
// 订单中心:列出当前用户的全部订单,微信审核要求交易类小程序必须提供这个页面。
|
||||||
|
// 数据来自服务端 GET /v1/orders(只返回自己的单)。
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const format = require('../../utils/format');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
loading: true,
|
||||||
|
list: [],
|
||||||
|
/** 按钮文案走后台配置 */
|
||||||
|
contactText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
// 等启动流程把配置和身份准备好再拉,避免首屏空白
|
||||||
|
app.ready().then(() => {
|
||||||
|
this.applyConfig();
|
||||||
|
this.load();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 每次回到页面都重新拉一次,付款回来能立刻看到新订单。 */
|
||||||
|
onShow() {
|
||||||
|
if (!this.data.loading) this.load();
|
||||||
|
},
|
||||||
|
|
||||||
|
applyConfig() {
|
||||||
|
this.setData({ contactText: store.cfg('course.button.contact') });
|
||||||
|
},
|
||||||
|
|
||||||
|
load() {
|
||||||
|
api
|
||||||
|
.getOrders()
|
||||||
|
.then((list) => {
|
||||||
|
this.setData({
|
||||||
|
loading: false,
|
||||||
|
list: (list || []).map((item) => ({
|
||||||
|
outTradeNo: item.outTradeNo,
|
||||||
|
title: item.courseTitle || '',
|
||||||
|
statusText: item.statusText || '',
|
||||||
|
status: item.status,
|
||||||
|
amountYuan: format.fenToYuan(item.amountFen),
|
||||||
|
createdAtText: format.toDateTimeString(item.createdAt),
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.setData({ loading: false });
|
||||||
|
wx.showToast({ title: (err && err.message) || '订单加载失败', icon: 'none' });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"navigationBarTitleText": "我的订单"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<!--pages/orders/orders.wxml-->
|
||||||
|
<scroll-view class="order-page" scroll-y type="custom">
|
||||||
|
<view wx:if="{{loading}}" class="order-hint">加载中…</view>
|
||||||
|
<view wx:elif="{{list.length === 0}}" class="order-hint">暂无订单</view>
|
||||||
|
|
||||||
|
<block wx:else>
|
||||||
|
<view class="order-item" wx:for="{{list}}" wx:key="outTradeNo">
|
||||||
|
<view class="order-line">
|
||||||
|
<text class="order-title">{{item.title}}</text>
|
||||||
|
<text class="order-status">{{item.statusText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="order-line order-sub">
|
||||||
|
<text>订单号 {{item.outTradeNo}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="order-line order-sub">
|
||||||
|
<text class="order-amount">¥{{item.amountYuan}}</text>
|
||||||
|
<text>{{item.createdAtText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
|
||||||
|
<button class="order-service" open-type="contact">
|
||||||
|
<text>{{contactText}}</text>
|
||||||
|
</button>
|
||||||
|
</scroll-view>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* pages/orders/orders.wxss */
|
||||||
|
.order-page {
|
||||||
|
padding: 20rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-hint {
|
||||||
|
margin-top: 200rpx;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-item {
|
||||||
|
width: 710rpx;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
padding: 24rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-line {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-title {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-status {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #00aa00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-sub {
|
||||||
|
margin-top: 12rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-amount {
|
||||||
|
color: #e60012;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-service {
|
||||||
|
width: 710rpx;
|
||||||
|
margin: 40rpx 0 60rpx;
|
||||||
|
border-radius: 45rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #4caf50;
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// pages/wode/wode.js
|
||||||
|
const api = require('../../utils/api');
|
||||||
|
const store = require('../../utils/store');
|
||||||
|
const config = require('../../config/index');
|
||||||
|
|
||||||
|
const app = getApp();
|
||||||
|
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
showCode: false,
|
||||||
|
headiconUrl: '',
|
||||||
|
isLoggedIn: false,
|
||||||
|
// 文字全部来自后台配置
|
||||||
|
userNameText: '',
|
||||||
|
loginBtnText: '',
|
||||||
|
version: '',
|
||||||
|
qrcodeUrl: '',
|
||||||
|
text2: '',
|
||||||
|
text3: '',
|
||||||
|
text4: '',
|
||||||
|
text5: '',
|
||||||
|
text6: '',
|
||||||
|
/** 「我的订单」入口文案,走后台配置 */
|
||||||
|
ordersText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
app.ready().then(() => {
|
||||||
|
this.applyConfig();
|
||||||
|
this.applyUser();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow() {
|
||||||
|
if (store.getSiteConfig() && Object.keys(store.getSiteConfig()).length) this.applyConfig();
|
||||||
|
this.applyUser();
|
||||||
|
},
|
||||||
|
|
||||||
|
applyConfig() {
|
||||||
|
const qrcodeName = store.cfg('profile.qrcode_image');
|
||||||
|
this.setData({
|
||||||
|
version: store.cfg('site.version'),
|
||||||
|
text2: store.cfg('profile.menu.change_info'),
|
||||||
|
text3: store.cfg('profile.menu.share'),
|
||||||
|
text4: store.cfg('profile.menu.contact'),
|
||||||
|
text5: store.cfg('profile.menu.wechat'),
|
||||||
|
text6: store.cfg('profile.qrcode_caption'),
|
||||||
|
ordersText: store.cfg('profile.menu.orders'),
|
||||||
|
qrcodeUrl: qrcodeName ? config.STATIC_BASE_URL + '/Images/WXCode/' + qrcodeName + '.png' : '',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
applyUser() {
|
||||||
|
const user = store.getUser();
|
||||||
|
// 「已登录」看的是用户主动登录过没有(服务端记着这一位),不是有没有 token
|
||||||
|
const registered = !!(user && user.isLogin === 1);
|
||||||
|
this.setData({
|
||||||
|
isLoggedIn: registered,
|
||||||
|
userNameText: registered ? user.nickname : store.cfg('profile.user.guest'),
|
||||||
|
loginBtnText: registered ? store.cfg('login.button.logout') : store.cfg('profile.button.login'),
|
||||||
|
// 未登录一律用默认头像:静默登录仍会带回上次设置的头像,
|
||||||
|
// 不挡住的话退出登录后还会显示用户自己的头像。
|
||||||
|
headiconUrl:
|
||||||
|
registered && user.headiconUrl
|
||||||
|
? user.headiconUrl
|
||||||
|
: config.STATIC_BASE_URL + config.PLACEHOLDER.USER,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
toLoginOrOut() {
|
||||||
|
wx.navigateTo({ url: '/pages/LoginOrOutDetails/LoginOrOutDetails' });
|
||||||
|
},
|
||||||
|
|
||||||
|
toChangeUserInfo() {
|
||||||
|
if (!this.data.isLoggedIn) {
|
||||||
|
wx.showToast({ mask: true, icon: 'error', title: store.cfg('profile.tip.needLogin') });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.navigateTo({ url: '/pages/ChangeUserInfo/ChangeUserInfo' });
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 订单中心:微信审核要求交易类小程序必须有,入口放在这一页。 */
|
||||||
|
toOrders() {
|
||||||
|
wx.navigateTo({ url: '/pages/orders/orders' });
|
||||||
|
},
|
||||||
|
|
||||||
|
showQrcode() {
|
||||||
|
this.setData({ showCode: true });
|
||||||
|
},
|
||||||
|
|
||||||
|
onCodeClose() {
|
||||||
|
this.setData({ showCode: false });
|
||||||
|
},
|
||||||
|
|
||||||
|
onShareAppMessage() {
|
||||||
|
return { title: store.cfg('share.title'), path: '/pages/index/index' };
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {
|
||||||
|
"van-popup": "@vant/weapp/popup/index",
|
||||||
|
"van-image": "@vant/weapp/image/index"
|
||||||
|
},
|
||||||
|
"navigationBarTitleText": "个人中心"
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<!--pages/wode/wode.wxml-->
|
||||||
|
<van-popup show="{{ showCode }}" bind:close="onCodeClose">
|
||||||
|
<view class="code-container">
|
||||||
|
<text wx:if="{{text6}}" class="tip-text">{{text6}}</text>
|
||||||
|
<van-image
|
||||||
|
show-menu-by-longpress="true"
|
||||||
|
use-loading-slot
|
||||||
|
use-error-slot
|
||||||
|
width="600rpx"
|
||||||
|
height="816rpx"
|
||||||
|
src="{{qrcodeUrl}}"
|
||||||
|
/>
|
||||||
|
<van-loading slot="loading" type="spinner" size="20" vertical />
|
||||||
|
</view>
|
||||||
|
</van-popup>
|
||||||
|
|
||||||
|
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||||
|
<view class="login">
|
||||||
|
<view class="touxiangimg">
|
||||||
|
<image class="loginuserimg" src="{{headiconUrl}}" mode="aspectFill" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="userinfo_name">
|
||||||
|
<text>{{userNameText}}</text>
|
||||||
|
<button class="loginbtn" bindtap="toLoginOrOut" plain>{{loginBtnText}}</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<button wx:if="{{isLoggedIn}}" class="functions2" bind:tap="toChangeUserInfo">
|
||||||
|
<text class="zuobianwenzi">{{text2}}</text>
|
||||||
|
<text class="jiantou"> > </text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="functions2" bind:tap="toOrders">
|
||||||
|
<text class="zuobianwenzi">{{ordersText}}</text>
|
||||||
|
<text class="jiantou"> > </text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="functions2" open-type="share">
|
||||||
|
<text class="zuobianwenzi">{{text3}}</text>
|
||||||
|
<text class="jiantou"> > </text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="functions2" open-type="contact">
|
||||||
|
<text class="zuobianwenzi">{{text4}}</text>
|
||||||
|
<text class="jiantou"> > </text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="functions2" bind:tap="showQrcode">
|
||||||
|
<text class="zuobianwenzi">{{text5}}</text>
|
||||||
|
<text class="jiantou"> > </text>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<view class="version">
|
||||||
|
<text style="display: block;">Version {{version}}</text>
|
||||||
|
<text style="font-size: 20rpx;display: block;">Copyright<text style="font-size: 15rpx;position: relative;top: -10rpx;right: 0rpx;">©</text> 2026 YelayMaths. All Rights Reserved.</text>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/* pages/wode/wode.wxss */
|
||||||
|
.container {
|
||||||
|
padding:0;
|
||||||
|
align-items:center;
|
||||||
|
flex-direction:column;
|
||||||
|
justify-content:space-between;
|
||||||
|
}
|
||||||
|
.code-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center; /* 水平居中 */
|
||||||
|
padding: 20rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-color: rgb(0, 201, 77);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 文字样式:可选加粗、颜色、间距等 */
|
||||||
|
.tip-text {
|
||||||
|
font-size: 34rpx;
|
||||||
|
color: #ffffff;
|
||||||
|
margin-bottom: 20rpx; /* 与图片保持间距 */
|
||||||
|
text-align: center; /* 冗余保险,虽然 flex 已居中 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.login {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
/* border: 3rpx solid rgb(110, 110, 110); */
|
||||||
|
width: 710rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
margin: 20rpx;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.touxiangimg {
|
||||||
|
display: flex;
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
border-radius: 50rpx;
|
||||||
|
}
|
||||||
|
.userinfo_name {
|
||||||
|
width: 500rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
margin-left: 30rpx;
|
||||||
|
border-radius: 75rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.loginbtn {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.loginbtn[plain] {
|
||||||
|
color: #353535;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 0px solid #353535;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 0rpx 20rpx;
|
||||||
|
}
|
||||||
|
.loginuserimg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.functions1 {
|
||||||
|
border: 3rpx solid rgb(110, 110, 110);
|
||||||
|
width: 670rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
margin: 20rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 20rpx;
|
||||||
|
}
|
||||||
|
.functions2 {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
/* border: 3rpx solid rgb(110, 110, 110); */
|
||||||
|
background-color: white;
|
||||||
|
width: 710rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
margin: 8rpx 20rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
.jiantou {
|
||||||
|
font-size: 40rpx;
|
||||||
|
}
|
||||||
|
.zuobianwenzi {
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.function001 {
|
||||||
|
height: 150rpx;
|
||||||
|
width: 75rpx;
|
||||||
|
|
||||||
|
padding: 10rpx 47rpx;
|
||||||
|
text-align: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.functionimg001 {
|
||||||
|
width: 75rpx;
|
||||||
|
height: 75rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.functionimg002 {
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
}
|
||||||
|
.functiontext001 {
|
||||||
|
font-size: 25rpx;
|
||||||
|
}
|
||||||
|
.functionstools {
|
||||||
|
position: relative;
|
||||||
|
top: 20rpx;
|
||||||
|
padding-bottom: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.version {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 10rpx;
|
||||||
|
color: rgb(197, 197, 197);
|
||||||
|
font-size: 25rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"compileType": "miniprogram",
|
||||||
|
"libVersion": "3.7.12",
|
||||||
|
"packOptions": {
|
||||||
|
"ignore": [],
|
||||||
|
"include": []
|
||||||
|
},
|
||||||
|
"setting": {
|
||||||
|
"coverView": true,
|
||||||
|
"es6": true,
|
||||||
|
"postcss": true,
|
||||||
|
"minified": true,
|
||||||
|
"enhance": true,
|
||||||
|
"showShadowRootInWxmlPanel": true,
|
||||||
|
"packNpmManually": true,
|
||||||
|
"packNpmRelationList": [
|
||||||
|
{
|
||||||
|
"packageJsonPath": "./package.json",
|
||||||
|
"miniprogramNpmDistDir": "./"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"babelSetting": {
|
||||||
|
"ignore": [],
|
||||||
|
"disablePlugins": [],
|
||||||
|
"outputPath": ""
|
||||||
|
},
|
||||||
|
"compileWorklet": false,
|
||||||
|
"uglifyFileName": false,
|
||||||
|
"uploadWithSourceMap": true,
|
||||||
|
"minifyWXSS": true,
|
||||||
|
"minifyWXML": true,
|
||||||
|
"localPlugins": false,
|
||||||
|
"disableUseStrict": false,
|
||||||
|
"useCompilerPlugins": false,
|
||||||
|
"condition": false,
|
||||||
|
"swc": false,
|
||||||
|
"disableSWC": true
|
||||||
|
},
|
||||||
|
"condition": {},
|
||||||
|
"editorSetting": {
|
||||||
|
"tabIndent": "auto",
|
||||||
|
"tabSize": 2
|
||||||
|
},
|
||||||
|
"appid": "wx3fbaf897825bf04f",
|
||||||
|
"simulatorPluginLibVersion": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||||
|
"rules": [{
|
||||||
|
"action": "allow",
|
||||||
|
"page": "*"
|
||||||
|
}]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -0,0 +1,251 @@
|
|||||||
|
/**
|
||||||
|
* 统一请求层与接口封装。
|
||||||
|
*
|
||||||
|
* 替代旧版本「每个接口手写一遍 wx.request + Promise」的写法。
|
||||||
|
* 职责:
|
||||||
|
* - 自动附带 Authorization
|
||||||
|
* - 统一解包 { code, message, data, requestId }
|
||||||
|
* - token 失效自动刷新,刷新失败自动重新登录
|
||||||
|
*/
|
||||||
|
|
||||||
|
const config = require('../config/index');
|
||||||
|
const store = require('./store');
|
||||||
|
|
||||||
|
/** 进行中的会话恢复,避免并发 401 触发多次恢复流程 */
|
||||||
|
let recovering = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端错误码:账号被封禁。
|
||||||
|
* 要和「登录过期」分开:页面据此走自己的提示分支,而不是把人赶去登录。
|
||||||
|
* 具体提示什么文字由后台配置决定,这里只管把错误码原样带出去。
|
||||||
|
*/
|
||||||
|
const ACCOUNT_DISABLED = 2003;
|
||||||
|
|
||||||
|
function staticUrl(path) {
|
||||||
|
if (!path) return '';
|
||||||
|
if (/^https?:\/\//i.test(path)) return path;
|
||||||
|
return config.STATIC_BASE_URL.replace(/\/+$/, '') + '/' + String(path).replace(/^\/+/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下单设备。平台按设备路由支付渠道(iOS 走 Apple 支付,只能用户自己找 App Store 退),
|
||||||
|
* 服务端靠这个字段判断一笔单能不能主动退款,所以下单时要一起报上去。
|
||||||
|
*/
|
||||||
|
function platform() {
|
||||||
|
try {
|
||||||
|
if (typeof wx.getDeviceInfo === 'function') return wx.getDeviceInfo().platform || 'unknown';
|
||||||
|
return wx.getSystemInfoSync().platform || 'unknown';
|
||||||
|
} catch (err) {
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeError(body, statusCode) {
|
||||||
|
if (body && typeof body.code === 'number') {
|
||||||
|
return { code: body.code, message: body.message || '请求失败', requestId: body.requestId };
|
||||||
|
}
|
||||||
|
return { code: -1, message: '服务异常(' + statusCode + ')' };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 底层请求。不做鉴权重试,返回完整响应体。 */
|
||||||
|
function rawRequest(options) {
|
||||||
|
const header = { 'content-type': 'application/json' };
|
||||||
|
if (options.auth !== false) {
|
||||||
|
const token = store.getToken();
|
||||||
|
if (token) header.Authorization = 'Bearer ' + token;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
wx.request({
|
||||||
|
url: config.API_BASE_URL.replace(/\/+$/, '') + options.url,
|
||||||
|
method: options.method || 'GET',
|
||||||
|
data: options.data,
|
||||||
|
header,
|
||||||
|
timeout: config.TIMEOUT,
|
||||||
|
success(res) {
|
||||||
|
resolve({ statusCode: res.statusCode, body: res.data || {} });
|
||||||
|
},
|
||||||
|
fail() {
|
||||||
|
reject({ code: -1, message: '网络异常,请检查网络后重试' });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 带鉴权的请求。token 失效时自动恢复会话并重试一次。 */
|
||||||
|
function request(options) {
|
||||||
|
return rawRequest(options).then(({ statusCode, body }) => {
|
||||||
|
if (body.code === 0) return body.data;
|
||||||
|
|
||||||
|
const needLogin = statusCode === 401 || body.code === 2000 || body.code === 2001;
|
||||||
|
if (needLogin && options.auth !== false && options.retried !== true) {
|
||||||
|
return recoverSession()
|
||||||
|
.then(() => request(Object.assign({}, options, { retried: true })))
|
||||||
|
.catch((err) => {
|
||||||
|
// 账号异常:把原因原样抛给页面,并且不清本地用户——
|
||||||
|
// 清掉的话知识页会把它当成未登录,只剩一片空白,看不出发生了什么
|
||||||
|
if (err && err.code === ACCOUNT_DISABLED) throw err;
|
||||||
|
store.reset();
|
||||||
|
throw { code: 2000, message: '登录已过期,请重新进入小程序' };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
throw normalizeError(body, statusCode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 恢复会话。两级兜底:
|
||||||
|
* 1. 用 refreshToken 换新 accessToken(快,不打扰用户)
|
||||||
|
* 2. refreshToken 也没有或已失效时,重新走一次微信静默登录
|
||||||
|
*
|
||||||
|
* 第 2 级是必需的:「退出登录」会清空全部 token,
|
||||||
|
* 此后任何需要鉴权的操作(例如再次点「登录注册」改昵称)都必须先重新登录,
|
||||||
|
* 否则必然 401。
|
||||||
|
*/
|
||||||
|
function recoverSession() {
|
||||||
|
if (recovering) return recovering;
|
||||||
|
|
||||||
|
recovering = refreshAccessToken()
|
||||||
|
.catch(() => login())
|
||||||
|
.finally(() => {
|
||||||
|
recovering = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return recovering;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshAccessToken() {
|
||||||
|
const refreshToken = store.getRefreshToken();
|
||||||
|
if (!refreshToken) return Promise.reject({ code: 2000, message: '未登录' });
|
||||||
|
|
||||||
|
return rawRequest({
|
||||||
|
url: '/v1/auth/refresh',
|
||||||
|
method: 'POST',
|
||||||
|
data: { refreshToken },
|
||||||
|
auth: false,
|
||||||
|
}).then(({ body }) => {
|
||||||
|
if (body.code !== 0) throw { code: 2000, message: '登录已过期' };
|
||||||
|
store.setTokens(body.data.accessToken);
|
||||||
|
return body.data.accessToken;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 登录 ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** wx.login 换 code,再用 code 换服务端 token。 */
|
||||||
|
function login() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
wx.login({
|
||||||
|
success(res) {
|
||||||
|
if (!res.code) {
|
||||||
|
reject({ code: 3002, message: '微信登录失败,请重试' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request({
|
||||||
|
url: '/v1/auth/wx-login',
|
||||||
|
method: 'POST',
|
||||||
|
data: { code: res.code },
|
||||||
|
auth: false,
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
store.setTokens(data.accessToken, data.refreshToken);
|
||||||
|
store.setUser(data.user);
|
||||||
|
resolve(data);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
},
|
||||||
|
fail() {
|
||||||
|
reject({ code: 3002, message: '微信登录失败,请重试' });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
return request({ url: '/v1/auth/logout', method: 'POST' }).catch(() => null).then(() => {
|
||||||
|
store.reset();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户主动登录:把数据库里的「已登录」标记置 1。
|
||||||
|
*
|
||||||
|
* 静默登录(login)不会碰这个标记——它只负责建立身份。只有用户亲自点了登录,
|
||||||
|
* 才算「主动使用过登录功能」,购买资格也以这个标记为准,而不是有没有 token。
|
||||||
|
*/
|
||||||
|
function activeLogin() {
|
||||||
|
return request({ url: '/v1/auth/login', method: 'POST' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 首页内容 ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const api = {
|
||||||
|
staticUrl,
|
||||||
|
login,
|
||||||
|
logout,
|
||||||
|
activeLogin,
|
||||||
|
|
||||||
|
getConfig: () => request({ url: '/v1/config', auth: false }),
|
||||||
|
getBanners: () => request({ url: '/v1/banners', auth: false }),
|
||||||
|
getHomeCourses: () => request({ url: '/v1/home/courses', auth: false }),
|
||||||
|
getHomeFreeCourses: () => request({ url: '/v1/home/free-courses', auth: false }),
|
||||||
|
getArticles: (page, pageSize) =>
|
||||||
|
request({ url: '/v1/articles?page=' + (page || 1) + '&pageSize=' + (pageSize || 10), auth: false }),
|
||||||
|
getArticle: (id) => request({ url: '/v1/articles/' + id, auth: false }),
|
||||||
|
getTips: () => request({ url: '/v1/tips', auth: false }),
|
||||||
|
|
||||||
|
// ── 内容 ────────────────────────────────────────────────────────────
|
||||||
|
getCourses: () => request({ url: '/v1/courses' }),
|
||||||
|
getCourse: (code) => request({ url: '/v1/courses/' + code }),
|
||||||
|
getLessons: (code) => request({ url: '/v1/courses/' + code + '/lessons' }),
|
||||||
|
getPlayUrl: (code, chapterId, playId) =>
|
||||||
|
request({
|
||||||
|
url:
|
||||||
|
'/v1/courses/' +
|
||||||
|
code +
|
||||||
|
'/play?chapterId=' +
|
||||||
|
encodeURIComponent(chapterId) +
|
||||||
|
'&playId=' +
|
||||||
|
encodeURIComponent(playId),
|
||||||
|
}),
|
||||||
|
getFreeLessons: (seriesNo) =>
|
||||||
|
request({ url: '/v1/free-lessons' + (seriesNo === undefined ? '' : '?seriesNo=' + seriesNo), auth: false }),
|
||||||
|
|
||||||
|
// ── 用户 ────────────────────────────────────────────────────────────
|
||||||
|
getMe: () => request({ url: '/v1/me' }),
|
||||||
|
updateMe: (payload) => request({ url: '/v1/me', method: 'PATCH', data: payload }),
|
||||||
|
getEntitlements: () => request({ url: '/v1/me/entitlements' }),
|
||||||
|
|
||||||
|
// ── 订单与支付 ──────────────────────────────────────────────────────
|
||||||
|
/** 我的订单列表(订单中心用)。 */
|
||||||
|
getOrders: () => request({ url: '/v1/orders' }),
|
||||||
|
createOrder: (courseCode) =>
|
||||||
|
request({
|
||||||
|
url: '/v1/orders',
|
||||||
|
method: 'POST',
|
||||||
|
data: { courseCode: courseCode, terminal: platform() },
|
||||||
|
}),
|
||||||
|
getOrder: (outTradeNo) => request({ url: '/v1/orders/' + outTradeNo }),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉起虚拟支付。
|
||||||
|
*
|
||||||
|
* 支付成功只代表「钱付了」,权益由服务端收到发货推送后发放,
|
||||||
|
* 因此这里不直接开通权益,而是让调用方轮询订单状态。
|
||||||
|
*/
|
||||||
|
function requestVirtualPayment(payData) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
wx.requestVirtualPayment({
|
||||||
|
signData: payData.signData,
|
||||||
|
mode: payData.mode,
|
||||||
|
paySig: payData.paySig,
|
||||||
|
signature: payData.signature,
|
||||||
|
success: resolve,
|
||||||
|
fail: reject,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Object.assign(api, { requestVirtualPayment, devicePlatform: platform, ACCOUNT_DISABLED });
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/** 展示用格式化。 */
|
||||||
|
|
||||||
|
function pad(n) {
|
||||||
|
return n < 10 ? '0' + n : String(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ISO 字符串 → YYYY-MM-DD */
|
||||||
|
function toDateString(value) {
|
||||||
|
if (!value) return '';
|
||||||
|
const d = new Date(value);
|
||||||
|
if (isNaN(d.getTime())) return '';
|
||||||
|
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ISO 字符串 → YYYY-MM-DD HH:mm */
|
||||||
|
function toDateTimeString(value) {
|
||||||
|
if (!value) return '';
|
||||||
|
const d = new Date(value);
|
||||||
|
if (isNaN(d.getTime())) return '';
|
||||||
|
return toDateString(value) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 分 → 元(保留两位,去掉多余的 .00) */
|
||||||
|
function fenToYuan(fen) {
|
||||||
|
const n = Number(fen);
|
||||||
|
if (!isFinite(n)) return '0';
|
||||||
|
const yuan = n / 100;
|
||||||
|
return yuan % 1 === 0 ? String(yuan) : yuan.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { toDateString, toDateTimeString, fenToYuan };
|
||||||
|
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/**
|
||||||
|
* 极简全局状态。
|
||||||
|
*
|
||||||
|
* 替代旧版本在各页面直接读写 wx.getStorageSync 的做法:
|
||||||
|
* 统一从内存读、同步落盘,页面只与这里交互。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const config = require('../config/index');
|
||||||
|
|
||||||
|
const memory = {
|
||||||
|
user: null,
|
||||||
|
siteConfig: null,
|
||||||
|
entitlements: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const listeners = new Set();
|
||||||
|
|
||||||
|
function notify() {
|
||||||
|
listeners.forEach((fn) => {
|
||||||
|
try {
|
||||||
|
fn();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[store] 监听器执行失败', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function read(key, fallback) {
|
||||||
|
try {
|
||||||
|
const v = wx.getStorageSync(key);
|
||||||
|
return v === '' || v === undefined || v === null ? fallback : v;
|
||||||
|
} catch (e) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = {
|
||||||
|
// ── token ────────────────────────────────────────────────────────────
|
||||||
|
getToken: () => read(config.STORAGE.TOKEN, ''),
|
||||||
|
getRefreshToken: () => read(config.STORAGE.REFRESH_TOKEN, ''),
|
||||||
|
|
||||||
|
setTokens(accessToken, refreshToken) {
|
||||||
|
wx.setStorageSync(config.STORAGE.TOKEN, accessToken);
|
||||||
|
if (refreshToken) wx.setStorageSync(config.STORAGE.REFRESH_TOKEN, refreshToken);
|
||||||
|
},
|
||||||
|
|
||||||
|
clearTokens() {
|
||||||
|
wx.removeStorageSync(config.STORAGE.TOKEN);
|
||||||
|
wx.removeStorageSync(config.STORAGE.REFRESH_TOKEN);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否「已登录」。
|
||||||
|
*
|
||||||
|
* 指用户主动使用过登录功能(标记由服务端返回、跟着 user 一起存),
|
||||||
|
* 不是「本地有没有 token」——静默登录每次都会拿到 token,那不算登录。
|
||||||
|
*/
|
||||||
|
isLoggedIn: () => {
|
||||||
|
const user = store.getUser();
|
||||||
|
return !!(user && user.isLogin === 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
// ── 用户 ─────────────────────────────────────────────────────────────
|
||||||
|
getUser() {
|
||||||
|
if (memory.user) return memory.user;
|
||||||
|
memory.user = read(config.STORAGE.USER, null);
|
||||||
|
return memory.user;
|
||||||
|
},
|
||||||
|
|
||||||
|
setUser(user) {
|
||||||
|
memory.user = user;
|
||||||
|
wx.setStorageSync(config.STORAGE.USER, user);
|
||||||
|
notify();
|
||||||
|
},
|
||||||
|
|
||||||
|
// ── 站点配置 ─────────────────────────────────────────────────────────
|
||||||
|
getSiteConfig() {
|
||||||
|
if (memory.siteConfig) return memory.siteConfig;
|
||||||
|
memory.siteConfig = read(config.STORAGE.CONFIG, {});
|
||||||
|
return memory.siteConfig;
|
||||||
|
},
|
||||||
|
|
||||||
|
setSiteConfig(cfg) {
|
||||||
|
memory.siteConfig = cfg || {};
|
||||||
|
wx.setStorageSync(config.STORAGE.CONFIG, memory.siteConfig);
|
||||||
|
notify();
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 取配置项。数据库里配什么就是什么,没配返回空字符串,由页面自己决定要不要渲染。 */
|
||||||
|
cfg(key) {
|
||||||
|
const value = store.getSiteConfig()[key];
|
||||||
|
return value === undefined ? '' : value;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ── 已购内容 ─────────────────────────────────────────────────────────
|
||||||
|
getEntitlements() {
|
||||||
|
if (memory.entitlements && memory.entitlements.length) return memory.entitlements;
|
||||||
|
memory.entitlements = read(config.STORAGE.ENTITLEMENTS, []) || [];
|
||||||
|
return memory.entitlements;
|
||||||
|
},
|
||||||
|
|
||||||
|
setEntitlements(list) {
|
||||||
|
memory.entitlements = list || [];
|
||||||
|
wx.setStorageSync(config.STORAGE.ENTITLEMENTS, memory.entitlements);
|
||||||
|
notify();
|
||||||
|
},
|
||||||
|
|
||||||
|
hasCourse(code) {
|
||||||
|
return store.getEntitlements().some((item) => item.code === code);
|
||||||
|
},
|
||||||
|
|
||||||
|
// ── 订阅与清理 ───────────────────────────────────────────────────────
|
||||||
|
subscribe(fn) {
|
||||||
|
listeners.add(fn);
|
||||||
|
return () => listeners.delete(fn);
|
||||||
|
},
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
memory.user = null;
|
||||||
|
memory.entitlements = [];
|
||||||
|
store.clearTokens();
|
||||||
|
// 站点配置与登录态无关,保留;否则退出登录后页面文案会退回默认值
|
||||||
|
wx.removeStorageSync(config.STORAGE.USER);
|
||||||
|
wx.removeStorageSync(config.STORAGE.ENTITLEMENTS);
|
||||||
|
notify();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = store;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const formatTime = timestamp => {
|
||||||
|
const date = new Date(timestamp);
|
||||||
|
const year = date.getFullYear()
|
||||||
|
const month = date.getMonth() + 1
|
||||||
|
const day = date.getDate()
|
||||||
|
const hour = date.getHours()
|
||||||
|
const minute = date.getMinutes()
|
||||||
|
const second = date.getSeconds()
|
||||||
|
|
||||||
|
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatNumber = n => {
|
||||||
|
n = n.toString()
|
||||||
|
return n[1] ? n : `0${n}`
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
formatTime
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# 服务端 API 地址
|
||||||
|
NEXT_PUBLIC_API_BASE_URL="https://yelaymaths-api.yeomai.site"
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
/// <reference types="next" />
|
||||||
|
/// <reference types="next/image-types/global" />
|
||||||
|
/// <reference path="./.next/types/routes.d.ts" />
|
||||||
|
|
||||||
|
// NOTE: This file should not be edited
|
||||||
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import type { NextConfig } from 'next';
|
||||||
|
|
||||||
|
const config: NextConfig = {
|
||||||
|
reactStrictMode: true,
|
||||||
|
eslint: { ignoreDuringBuilds: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "yelaymaths_admin",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"description": "叶雷讲数学 — 管理后台",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev -p 3001",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start -p 3001",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"next": "^15.1.6",
|
||||||
|
"react": "^19.0.0",
|
||||||
|
"react-dom": "^19.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4.0.0",
|
||||||
|
"@types/node": "^22.10.0",
|
||||||
|
"@types/react": "^19.0.0",
|
||||||
|
"@types/react-dom": "^19.0.0",
|
||||||
|
"tailwindcss": "^4.0.0",
|
||||||
|
"typescript": "^5.7.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Generated
+1004
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
'@tailwindcss/postcss': {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useParams } from 'next/navigation';
|
||||||
|
import { ResourceTable } from '@/components/ResourceTable';
|
||||||
|
import { findResource } from '@/lib/resources';
|
||||||
|
|
||||||
|
export default function ResourcePage() {
|
||||||
|
const params = useParams<{ resource: string }>();
|
||||||
|
const key = params?.resource ?? '';
|
||||||
|
const config = findResource(key);
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-gray-200 bg-white p-6 text-sm text-gray-500">
|
||||||
|
未知的资源类型:{key}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h1 className="text-lg font-semibold text-gray-900">{config.title}</h1>
|
||||||
|
<ResourceTable config={config} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Loaded 100 of 193 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user