Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cda13a787f | ||
|
|
6b688fd473 | ||
|
|
1e8da5fee2 | ||
|
|
51f410d942 | ||
|
|
a8732f51be | ||
|
|
4a63ccd10f | ||
|
|
865d8b0516 | ||
|
|
d2a165ada8 | ||
|
|
e29d5115fa | ||
|
|
aef8a059f2 | ||
|
|
f905b44675 |
+36
-66
@@ -165,88 +165,58 @@ docker compose restart xiaobai-review
|
||||
docker compose down
|
||||
```
|
||||
|
||||
### 镜像构建的唯一安全入口(2026-08 HEL-235 起)
|
||||
### 服务器本地目录更新与构建(日常推荐)
|
||||
|
||||
生产机 `192.168.200.11` 上的 `/opt/1panel/docker/compose/xiaobaifupan` 只是历史文件树:
|
||||
不是 Git 仓库、内容停在旧提交、与线上镜像不一致,且其 `compose.yaml` 会把构建结果打进
|
||||
`xiaobai-review:latest`。**禁止在该目录(或任何服务器工作树)里 `docker build` /
|
||||
`docker compose build`**,否则会把已上线功能悄悄打回旧版。
|
||||
|
||||
唯一安全构建方式是在有仓库检出、能免密 SSH 到部署机的机器上运行:
|
||||
|
||||
```bash
|
||||
tools/build_image.sh <提交号> <镜像tag>
|
||||
# 示例:tools/build_image.sh cefc86917d89 verify-hel235-cefc869
|
||||
```
|
||||
|
||||
该脚本的行为约束:
|
||||
|
||||
- 先 `git fetch`,再把提交号解析为完整 SHA,解析失败立即中止,绝不使用本地脏状态或服务器旧目录;
|
||||
- 构建前读取当前线上容器镜像的 `org.opencontainers.image.revision`,用 Git 祖先关系确认候选提交包含线上全部历史;落后 `main`、旁支或错误提交会直接退出,并打印线上提交、候选提交、文件差异和将丢失的提交;
|
||||
- 镜像 tag 必须以 `-<提交短号7位>` 结尾(如 `hel234-cefc869`),禁止 `latest`、`rollback-*`;
|
||||
- 通过 `git archive <提交> | ssh 部署机 docker build -` 流式构建,服务器上不存在构建用工作树;
|
||||
- 构建后回读镜像 label 里的 `org.opencontainers.image.revision`,与预期提交不一致则删除镜像并中止;
|
||||
- 每次构建在部署机 `~/xiaobai-build/BUILD_LOG.tsv` 留痕,可追溯每个镜像的来源提交。
|
||||
|
||||
构建只产出镜像,不启动、不替换任何容器;换版用新 tag 起新容器,回滚用既有镜像 tag 重跑。
|
||||
|
||||
### 使用 Gitea 更新程序(旧方式,生产机禁用)
|
||||
|
||||
代码仓库为:
|
||||
生产机 `192.168.200.11` 的 `/opt/1panel/docker/compose/xiaobaifupan` 自 2026-08-29(HEL-235B)
|
||||
起已是受 Git 管理的工作目录,只跟踪 Gitea `main`(仓库
|
||||
`http://192.168.200.36:3200/leefer/xiaobai-review.git`)。由于目录顶层归 root,
|
||||
`.git` 存放在部署账号家目录(外部 Git 目录方案):
|
||||
|
||||
```text
|
||||
http://192.168.200.36:3200/leefer/xiaobaifupan.git
|
||||
~/xiaobai-build/repos/xiaobai-review.git Git 元数据(分支/历史/索引)
|
||||
/opt/1panel/docker/compose/xiaobaifupan 工作目录(程序文件本体)
|
||||
~/xiaobai-build/update-from-main.sh 一键更新+构建入口
|
||||
~/xiaobai-git 便捷查看(status/log/diff)
|
||||
```
|
||||
|
||||
首次在服务器部署代码时,可以直接克隆到目标目录:
|
||||
日常更新只需要在服务器上执行一条命令:
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /opt/xiaobai-review
|
||||
sudo chown "$USER":"$USER" /opt/xiaobai-review
|
||||
git clone http://192.168.200.36:3200/leefer/xiaobaifupan.git /opt/xiaobai-review
|
||||
cd /opt/xiaobai-review
|
||||
~/xiaobai-build/update-from-main.sh # 更新到 main 并构建 main-<短号> 镜像
|
||||
~/xiaobai-build/update-from-main.sh verify-tag main-a8732f5 # 部署前复核镜像与 main 一致
|
||||
```
|
||||
|
||||
私有仓库会提示输入 Gitea 用户名和密码或访问令牌。不要把密码写入仓库 URL、
|
||||
`compose.yaml` 或脚本。然后把原 `.env` 与 `data/` 放回该目录;这两项已被 Git
|
||||
忽略,后续拉取代码不会覆盖数据库与密钥。
|
||||
脚本在构建前强制完成五道校验,任一不符立即停止、不产出镜像:
|
||||
|
||||
如需部署管理员私有问师,通过 NAS 文件管理器将本地
|
||||
`data/private-mentor-skills/` 复制到服务器项目的同名 `data` 目录,并保持目录仅由
|
||||
部署账号和容器运行用户读取。该内容不会通过 Gitea 同步。
|
||||
1. `git fetch` 成功(连不上 Gitea 即停);
|
||||
2. 必须在 `main` 分支(智能体不得用功能分支直接当正式线);
|
||||
3. 工作区无未提交改动、无多余文件;
|
||||
4. 只允许快进合并到 `origin/main`(分叉即停);main 新增/删除顶层文件时会给出
|
||||
需管理员执行的精确清单(目录顶层归 root);
|
||||
5. 构建后回读镜像 `org.opencontainers.image.revision`,与 `main` 提交不一致则删除镜像。
|
||||
|
||||
每次更新前先创建 SQLite 一致性备份,再拉取并重建容器(注意:`docker compose up -d --build`
|
||||
从服务器本地工作树构建,仅适用于来源可信的全新环境;生产机 `192.168.200.11` 禁用,
|
||||
请用 `tools/build_image.sh` 构建后换容器):
|
||||
镜像 tag 固定为 `main-<提交短号7位>`(不带提交号的模糊 tag 一律禁止);每次构建在
|
||||
`~/xiaobai-build/BUILD_LOG.tsv` 留痕。构建只产出镜像,不启动、不替换容器;换版与
|
||||
回滚步骤见 `~/xiaobai-build/README.md`。
|
||||
|
||||
```bash
|
||||
cd /opt/xiaobai-review
|
||||
docker compose exec -T xiaobai-review python -c "import sqlite3; s=sqlite3.connect('/app/data/review.db'); d=sqlite3.connect('/app/data/review-before-update.db'); s.backup(d); d.close(); s.close()"
|
||||
git pull --ff-only origin main
|
||||
docker compose up -d --build
|
||||
docker compose ps
|
||||
curl --fail http://127.0.0.1:8765/api/health
|
||||
```
|
||||
`compose.yaml` 的镜像名与 revision 标签同样做了强校验:直接 `docker compose up -d --build`
|
||||
会因缺少 `XIAOBAI_GIT_REV` / `XIAOBAI_GIT_SHORT` 变量而拒绝执行,避免再出现构建进
|
||||
`latest` 的模糊版本。需要用 compose 时先 `export` 这两个变量(值以
|
||||
`~/xiaobai-build/xiaobai-git rev-parse HEAD` 为准),或直接用上面的脚本。
|
||||
|
||||
`docker compose up -d --build` 会原地替换应用容器,不删除宿主机的 `data` 目录。
|
||||
数据库迁移会在新容器启动时自动执行。若 `git pull --ff-only` 提示本地代码有修改,
|
||||
先用 `git status` 查明原因,不要用强制重置覆盖 `.env` 或 `data`。
|
||||
### 智能体高级入口:Git 归档流式构建
|
||||
|
||||
### 不使用 Git 时更新(生产机禁用)
|
||||
有仓库检出、能免密 SSH 到部署机的智能体可以用 `tools/build_image.sh <提交号> <镜像tag>`
|
||||
从任意明确提交流式构建(`git archive | ssh docker build`),tag 同样必须以
|
||||
`-<提交短号7位>` 结尾,构建后回读 revision 校验并留痕。用于在服务器不便拉取时的
|
||||
应急构建;日常正式线仍应走 `main`。
|
||||
|
||||
`docker compose build` 会从服务器本地目录构建,来源提交不可追溯。生产机
|
||||
`192.168.200.11` 上禁止使用本节方式,一律改用上一节的 `tools/build_image.sh`。
|
||||
### 历史方式(已废弃)
|
||||
|
||||
重新上传代码后执行:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose build --pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
`docker compose down` 不会删除宿主机的 `data` 目录。不要使用带有手工删除
|
||||
`data` 目录的清理命令。
|
||||
早期文档建议在服务器重新 `git clone` 一份或手工上传代码后 `docker compose up --build`。
|
||||
这两条路径已废弃:服务器上**只允许存在一个受管工作目录**(上述
|
||||
`/opt/1panel/docker/compose/xiaobaifupan`),任何脱离 Git 校验的本地构建都会把
|
||||
来源提交变成不可追溯状态,禁止使用。
|
||||
|
||||
## 7. 备份与恢复
|
||||
|
||||
|
||||
@@ -1,76 +1,360 @@
|
||||
# 小白复盘 Web
|
||||
# 小白复盘
|
||||
|
||||
一个面向 A 股盘后复盘的本地 Web 工作台。后端使用 Python 访问 Tushare Pro,前端不依赖构建工具。
|
||||
> 一个给 A 股股民自己用的**盘后复盘工作台**。
|
||||
> 收盘以后打开它,把「今天市场到底发生了什么」按情绪、梯队、轮动、竞价、龙虎榜一条条看明白,再决定明天激进还是保守。
|
||||
|
||||
本目录是经过保真迁移、结构治理和用户人工验收的唯一正式源码,不依赖父目录旧程序或失败版本。
|
||||
目录职责见[ARCHITECTURE.md](ARCHITECTURE.md),产品与维护文档见[docs/README.md](docs/README.md)。
|
||||
**一句话定位**:小白复盘是一套可以自己部署、自己掌控数据的 A 股盘后复盘工具。它把散落在各个行情软件里的涨停、炸板、连板梯队、板块轮动、集合竞价、龙虎榜数据,整理成一套**看得懂、能追问、可记录**的复盘界面。
|
||||
|
||||
当前包含集合竞价、涨停池、炸板池、跌停板、昨日涨停、涨停表现、市场天梯、板块轮动、题材库、人气热榜、龙虎榜和个人复盘工作区。交易日快照与同步记录保存在本地 SQLite 数据库 `data/review.db`。
|
||||
它**不是**行情交易软件,**不接券商、不代为下单**,也不提供任何形式的个股推荐。
|
||||
|
||||
集合竞价中心采用盘前生命周期:9:15 前显示预告,9:15–9:25 明确等待最终竞价,9:25–9:30 自动读取并重试最终竞价筛选,9:30 后停止更新并冻结为复盘归档。当前 Tushare 只提供 9:25 最终竞价快照,不将其表述为动态虚拟撮合行情。
|
||||
---
|
||||
|
||||
第三阶段加入了机构席位、席位别名、个股复权日 K、资金流、自选股、涨停原因修订、个股笔记、每日复盘和历史数据回补。
|
||||
## 一、为什么值得试(项目亮点)
|
||||
|
||||
股票代码在桌面端悬停后会显示分时与日 K 快速预览,默认优先展示日 K;移动端点击代码后从底部打开预览面板。股票详情以及板块、题材、指数详情均可在日 K 与最新分时之间切换。日 K 复用个股详情缓存;分时优先使用 iFinD,东方财富仅作隔离的展示兜底,并使用短时内存缓存。图表数据不写入主行情、不参与情绪、选股或问天计算;不可用时明确显示“分时不可用”,不会用日 K 模拟分时走势。
|
||||
1. **先看情绪,再看个股**
|
||||
用一个 0–100 的「情绪温度」,把当天市场的冷热程度和它处在哪个阶段(冰点 → 修复 → 发酵 → 高潮 → 分化 → 退潮)直接摆在第一屏。先判断环境,再谈个股。
|
||||
|
||||
智能选股包含六阶段盘后候选、29 套精选策略、自定义公式 DSL、自然语言公式编译、候选排名和滚动回测。阶段与精选策略在当日行情更新后由后台确定性计算;自定义选股由用户手动执行,LLM 只负责编译自然语言条件,不参与候选筛选。竞价、估值、财务、资金、人气和席位等字段按已登记的数据可用性进入因子库,缺失时明确显示覆盖问题。
|
||||
2. **说的就是短线玩家的话**
|
||||
晋级、断板、连板高度、梯队完整度、封单额、炸板……这些词不用解释,界面上原样呈现,不用再自己在行情软件里一层层翻。
|
||||
|
||||
候选只有经用户手动加入后才进入五交易日持续跟踪,展示 T+1 开盘/收盘、T+3、T+5、最大涨幅与最大回撤。提醒中心支持手工日期提醒,并在策略首日反馈和五日跟踪完成时生成账号私有的站内提醒。
|
||||
3. **不会写公式,也能按自己的想法筛股票**
|
||||
可以直接写一句人话(比如「连续两天放量上涨且不是 ST」),系统会把它编译成受控公式再执行筛选。技术活儿交给程序,判断权始终在你手上。
|
||||
|
||||
问师模块会读取当前复盘、近十日市场情绪、涨跌停、昨日反馈、板块轮动、市场阶段、龙虎榜和指定个股数据,再按选中的游资思维 Skill 进行单师对话。对话记录按账号、老师和交易日期保存在服务端;主模型不可用时自动切换辅助模型。
|
||||
4. **有问题可以「问」**
|
||||
- **问师**:挑一位游资思维模型,系统自动把当天情绪、梯队、龙虎榜等数据喂给它,单师对话,边看数据边追问。
|
||||
- **问天**:一个偏传统文化视角的模块,分「观势 / 观气 / 观心」三部分,看盘之外也给自己留一段安静时间。
|
||||
|
||||
新增公开问师角色时,在 `游资skills` 下增加一个包含 `SKILL.md` 的独立目录,并在 `游资skills/mentor_catalog.json` 中登记素材等级与结构质检。管理员私有角色放在 `data/private-mentor-skills`,该目录不进入 Git 或 Docker 镜像,且只会出现在管理员的问师列表中。系统会从 Skill 的 frontmatter、一级标题、核心模型和引用语中自动生成角色信息,无需修改注册代码。
|
||||
5. **复盘能留下来,而不是第二天就忘**
|
||||
交易日志可以记录当时的买卖逻辑和情绪标签(平静 / 笃定 / 犹豫 / 焦虑 / 冲动),配合每日复盘三问和提醒中心,帮自己看清是不是在情绪化操作。
|
||||
|
||||
问天模块包含三个相互独立的部分:观势以市场数据生成三才六爻,用于观察“势”,行情缺失或自动取象明显偏差时可显式手动校准六爻,人工结果与自动来源严格区分;观气依据干支、精确节气、五运六气及客主加临关系观察“运”,行业五行仅作传统取象归类;观心先准备1秒,再完成5轮“吸3秒、顿2秒、呼4秒”,随后以六次三枚铜钱起卦、察念和解卦完成一次不输入问题的问心仪式。卦象、干支、节气与气机关系均由本地确定性程序计算,LLM只负责解释,不参与起卦或改动结果。
|
||||
6. **数据在自己手里**
|
||||
所有数据存在部署机器本地的 SQLite 数据库里,账号密码用 scrypt 哈希保存,行情 Token 和模型密钥加密存放。没有云端账号,不上传个人交易记录。
|
||||
|
||||
问天模块使用项目本地的 `lunar-python` 计算历法,并使用 `data/iching_zh.json` 中的固定六十四卦、卦辞和爻辞。第三方授权见 `THIRD_PARTY_NOTICES.md`。
|
||||
7. **一套界面,白天晚上都能看**
|
||||
内置日间 / 夜间两套配色,股票代码上悬停就弹出日 K 与分时小图,`Ctrl + K` 可以全局搜索股票、板块和题材。
|
||||
|
||||
“我的复盘”包含结构化手工交易日志,可记录方向、价格、数量、仓位、盈亏、逻辑、执行、情绪和标签,不接券商也不自动下单。顶部“复盘助手”以流式方式读取市场统计、策略跟踪、提醒、个人复盘和交易日志;对话按账号保存,只提供分析和条件化计划。
|
||||
---
|
||||
|
||||
## 启动
|
||||
## 二、主要功能
|
||||
|
||||
```powershell
|
||||
cd app
|
||||
界面左侧一共有 **16 个页面**,另有一个内嵌页面(策略持续跟踪)。下面按分组说明。
|
||||
|
||||
### 2.1 市场数据(登录即可用)
|
||||
|
||||
| 页面 | 解决什么问题 | 打开后能看到什么 |
|
||||
| --- | --- | --- |
|
||||
| **情绪周期** | 收盘后说不清市场整体冷热、处在什么阶段 | 0–100 情绪温度、升温 / 降温方向、六阶段判定、由五个维度(市场宽度 20、涨停生态 25、赚钱效应 30、连板结构 15、成交活跃度 10)加权算出 |
|
||||
| **涨停池** | 当天封板的票散在各处,看不出封板结构 | 按首板 / 2 板 / 3 板+ 筛选,含首封时间、开板次数、封单额、涨停原因 |
|
||||
| **炸板池** | 触板没封住容易被误当成涨停 | 距涨停还差多少、开了几次板、炸板原因 |
|
||||
| **跌停板** | 亏钱效应集中在哪不直观 | 连续跌停天数、风险线索、风险行业聚集提示 |
|
||||
| **昨日涨停** | 昨天追板的人今天怎么样 | 晋级 / 炸板 / 跌停 / 断板四类结果,加一条「兑现率」(收红口径)摘要 |
|
||||
| **涨停表现** | 梯队到底健不健康 | 按连板高度看晋级率、收红率、平均涨幅,并给出当日结论 |
|
||||
| **市场天梯** | 连板梯队靠手翻拼不出来 | 从首板逐层排到当天最高板(至少展示 5 层),配市场高度与梯队完整度指标 |
|
||||
| **板块轮动** | 热点是延续还是一日游 | 最近 9 个交易日、Top 12 板块的热力矩阵,点板块可跨日高亮看连续性,并可下钻到申万二级成分股 |
|
||||
| **集合竞价** | 9:25 的竞价信息太散 | 四个页签:重点异动 / 我的自选 / 全部候选 / 竞价一字;关注分满分 100,可按「超预期 / 符合预期 / 低于预期」筛选;9:30 后停止更新,冻结归档供复盘 |
|
||||
| **题材库** | 题材排行和成分股要开好几个网站 | 左边题材排行、右边成分股,题材上悬停直接出日 K / 分时预览 |
|
||||
| **人气热榜** | 各家榜单各看各的 | 同花顺 + 东方财富双榜汇总,可切单榜或看「双榜共识」 |
|
||||
| **龙虎榜** | 上榜明细和游资动向查起来费劲 | 每日明细、净买入 / 净卖出筛选、活跃游资,点游资可看当日操作,游资档案带席位归类 |
|
||||
|
||||
### 2.2 智能功能(会员可用)
|
||||
|
||||
| 页面 | 解决什么问题 | 打开后能看到什么 |
|
||||
| --- | --- | --- |
|
||||
| **智能选股** | 自己写条件门槛高,盘中手翻太累 | 三种模式:① 六阶段策略,当日行情更新后(15:10 之后)自动计算;② **29 套精选策略库**,每套都标注适用环境、失效风险与准入条件;③ 自定义选股,自然语言写条件 → 编译成受控公式 → 确定性筛选执行 → 滚动回测 |
|
||||
| **策略持续跟踪** | 选出来的票加完自选就忘了为什么选 | 只有手动加入的候选才进入跟踪,展示 T+1 开盘 / 收盘、T+3、T+5、最大涨幅与最大回撤,到期自动提醒 |
|
||||
| **问师** | 复盘时没人讨论、视角单一 | 选一位游资思维模型单师对话,系统按模型流派自动喂情绪、梯队、龙虎榜等对应数据,回答为流式输出并带动态追问 |
|
||||
| **问天** | 想换个视角看市场,也想让自己静下来 | **观势**:用市场数据生成三才六爻,用来观察「势」;**观气**:依干支、精确节气、五运六气观察「运」;**观心**:不看盘、不输问题,先准备 1 秒,接着做 5 轮「吸气 3 秒、停顿 2 秒、呼气 4 秒」,再以六次三枚铜钱起卦完成一次问心仪式 |
|
||||
| **我的复盘** | 交易散养、不复盘、情绪化操作 | 结构化交易日志(方向、价格、仓位、盈亏、逻辑、执行、情绪、标签)、每日复盘三问、提醒中心、复盘助手(读取你的日志与市场数据,给出分析和条件化计划) |
|
||||
|
||||
> 说明:卦象、干支、节气与气机关系全部由本地程序确定性计算,大模型只负责文字解释,不参与起卦,也不会改动结果。
|
||||
|
||||
### 2.3 全局能力
|
||||
|
||||
- 股票 / 板块 / 题材上悬停,弹出日 K 与分时快速预览
|
||||
- `Ctrl + K` 全局搜索
|
||||
- 日间 / 夜间双主题一键切换
|
||||
- 提醒中心集中查看策略跟踪与手工提醒
|
||||
- 登录页有一组会动的小 K 线小人(红涨绿跌)
|
||||
|
||||
---
|
||||
|
||||
## 三、特色页面展示
|
||||
|
||||
> 下面每个占位都写清了「这张图要展示什么」。补图时,把图片文件放进仓库的 `docs/images/` 目录、按占位里写好的文件名命名,然后将该占位块(引文整段)替换为「补图后替换本块」后面那行图片语法(去掉反引号)即可;图未补上之前,方框内的文字就是给补图人的说明,不影响阅读。
|
||||
|
||||
### 3.1 情绪周期
|
||||
|
||||
> **【图 1|情绪周期主界面(截图)】**
|
||||
> 展示:日间主题下情绪周期页整屏,需清楚露出 0–100 情绪温度大数字、当前阶段卡(如「发酵」)、以及温度变化曲线。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 2|阶段与五维构成(截图)】**
|
||||
> 展示:阶段卡与五个维度的评分构成(市场宽度、涨停生态、赚钱效应、连板结构、成交活跃度),体现「温度不是拍脑袋来的」。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 3|日距切换(动图,约 4 秒)】**
|
||||
> 展示:在 10 / 20 / 60 日之间切换查看温度走势,动作要慢一点,让人看清曲线在动。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.2 市场天梯
|
||||
|
||||
> **【图 4|连板梯队全景(截图)】**
|
||||
> 展示:从首板一路排到当天最高板的分层结构,右侧「市场高度」与「梯队完整度」两个指标要同时入镜。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 5|展开 / 收起交互(动图,约 4 秒)】**
|
||||
> 展示:点击展开某高度的成分股再收起,说明每一层都能点开看细节。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.3 涨停相关股池
|
||||
|
||||
> **【图 6|涨停池与炸板池(截图,两张并排)】**
|
||||
> 展示:左为涨停池(含首封时间、开板次数、封单额、涨停原因),右为炸板池(含距涨停、开板次数、炸板原因)。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 7|昨日涨停与涨停表现(截图,两张并排)】**
|
||||
> 展示:左为昨日涨停的四类结果与兑现率摘要,右为涨停表现按连板高度列出的晋级率、收红率、平均涨幅与当日结论。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.4 板块轮动
|
||||
|
||||
> **【图 8|9 日热力矩阵(截图)】**
|
||||
> 展示:最近 9 个交易日、Top 12 板块的强度色阶矩阵,含强度图例。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 9|点板块跨日高亮(动图,约 6 秒)】**
|
||||
> 展示:点选某个板块后,该板块在 9 天里的位置被高亮,直观看出「延续」还是「一日游」;再点开看下钻的申万二级成分股。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.5 集合竞价
|
||||
|
||||
> **【图 10|竞价中心与关注分(截图)】**
|
||||
> 展示:重点异动页签下的候选列表,关注分列(满分 100)与「超预期 / 符合预期 / 低于预期」筛选条要看得见,右侧的题材承接卡片一并入镜。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 11|竞价生命周期(截图或示意静态图)】**
|
||||
> 展示:9:15 前预告 → 9:15–9:25 等待最终竞价 → 9:25–9:30 读取最终竞价 → 9:30 后冻结归档这四个节点。**建议用静态图表达,不做盘中动态录屏,避免被误解为实时撮合行情。**
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.6 龙虎榜
|
||||
|
||||
> **【图 12|龙虎榜明细与净买卖(截图)】**
|
||||
> 展示:每日上榜明细表,净买入 / 净卖出筛选条,以及活跃游资区域。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 13|游资档案(截图)】**
|
||||
> 展示:游资档案详情,含席位归类与当日操作列表。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 14|点游资看当日操作(动图,约 5 秒)】**
|
||||
> 展示:在明细里点某个游资,弹出它当天的全部操作,说明「席位 ↔ 个股」是打通的。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.7 智能选股
|
||||
|
||||
> **【图 15|29 套精选策略库(截图)】**
|
||||
> 展示:策略库列表,画面里要能数出策略卡片,并露出其中一张的「适用环境 / 失效风险 / 准入条件」。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 16|自然语言写公式全流程(动图,约 15 秒,可加速)】**
|
||||
> 展示:输入一句人话 → 编译成受控公式 → 执行筛选 → 返回候选表 → 加入持续跟踪,完整走一遍。**本图是全篇技术含量最高的一张,务必配「不构成投资建议」角标。**
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 17|策略持续跟踪(截图)】**
|
||||
> 展示:某个候选的 T+1 开盘 / 收盘、T+3、T+5、最大涨幅与最大回撤。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.8 问师
|
||||
|
||||
> **【图 18|问师对话(截图)】**
|
||||
> 展示:模型选择区与一段已完成的对话,回答中引用了情绪、梯队、龙虎榜等真实市场数据。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.9 问天
|
||||
|
||||
> **【图 19|观势(截图)】**
|
||||
> 展示:由市场数据生成的三才六爻卦象图,以及六爻与市场数据的对应关系。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 20|观气(截图)】**
|
||||
> 展示:干支、精确节气、五运六气与客主加临关系的呈现。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 21|观心(截图)】**
|
||||
> 展示:观心呼吸引导界面(准备 1 秒 + 「吸 3 秒、顿 2 秒、呼 4 秒」共 5 轮),以及六次三枚铜钱起卦的界面。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 22|起卦动效(动图,约 10 秒)】**
|
||||
> 展示:铜钱起卦与六爻推演的现有效果。**只录现有动画,不做任何页面改动;全片挂「传统文化娱乐化观察,非预测」角标。**
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.10 我的复盘
|
||||
|
||||
> **【图 23|交易日志与情绪标签(截图)】**
|
||||
> 展示:一条交易记录的完整字段,并把情绪五标签(平静 / 笃定 / 犹豫 / 焦虑 / 冲动)放大到看得清。
|
||||
> 补图后替换本块:``
|
||||
|
||||
> **【图 24|复盘助手(动图,约 8 秒)】**
|
||||
> 展示:复盘助手读取个人日志与市场数据后,流式输出一段分析与条件化计划。
|
||||
> 补图后替换本块:``
|
||||
|
||||
### 3.11 全局细节
|
||||
|
||||
> **【图 25|四个小细节(截图,四宫格拼图)】**
|
||||
> 展示:① 代码悬停弹出的日 K / 分时预览;② `Ctrl + K` 全局搜索;③ 日间 / 夜间双主题对比;④ 登录页会动的小 K 线小人。
|
||||
> 补图后替换本块:``
|
||||
|
||||
---
|
||||
|
||||
## 四、适合谁用
|
||||
|
||||
- **每天收盘后不知道从哪看起的散户**:先给一个情绪温度和阶段,再往下拆。
|
||||
- **做短线、看连板梯队的人**:晋级、断板、高度、完整度都在一个页面里。
|
||||
- **想按自己的条件筛股票、但不会写公式的人**:说人话就行。
|
||||
- **知道自己「管不住手」的人**:交易日志 + 情绪标签 + 每日复盘三问,把情绪化操作摆到自己面前。
|
||||
- **在意数据隐私、想把工具放在自己机器上的人**:私有部署,数据不出本机。
|
||||
- **对传统文化视角感兴趣的玩家**:问天的观势 / 观气 / 观心提供了另一种看市场的方式。
|
||||
|
||||
**不太适合**:想要一键自动下单的人(本项目不接券商);想要「跟着买就能赚」的人(本项目不提供任何形式的投资建议)。
|
||||
|
||||
---
|
||||
|
||||
## 五、一天怎么用(典型流程)
|
||||
|
||||
1. **收盘后 10 分钟:定环境**
|
||||
打开「情绪周期」,看温度多少、在哪个阶段、是升温还是降温。先定下明天的基调是激进还是保守。
|
||||
|
||||
2. **看结构:谁在涨、涨到几板**
|
||||
进「市场天梯」看连板梯队和市场高度,再到「涨停池 / 炸板池 / 跌停板」看当天的封板结构与亏钱效应。
|
||||
|
||||
3. **看延续:热点有没有搬家**
|
||||
进「板块轮动」,点几个强势板块,看它们在最近 9 天是连续走强还是只有一天行情。
|
||||
|
||||
4. **看结果:昨天追板的人今天怎么样**
|
||||
进「昨日涨停」和「涨停表现」,对照梯队健康度,检验自己的判断。
|
||||
|
||||
5. **查人气与席位**
|
||||
「人气热榜」看双榜共识,「龙虎榜」看活跃游资当天做了什么。
|
||||
|
||||
6. **按自己的条件选一批候选**
|
||||
进「智能选股」,要么用六阶段策略或 29 套精选策略,要么直接写一句人话让它编译成公式。选出来的候选**手动**加入「策略持续跟踪」,后面 T+1 / T+3 / T+5 会自动提醒你回看。
|
||||
|
||||
7. **有疑问就问**
|
||||
「问师」按游资思维模型边看数据边追问;想静一静就去「问天」做一次观心。
|
||||
|
||||
8. **记下来**
|
||||
在「我的复盘」里写当天交易日志(含情绪标签)和复盘三问。第二天开盘前,先回看昨天的记录。
|
||||
|
||||
---
|
||||
|
||||
## 六、部署与访问
|
||||
|
||||
> 本项目为**私有部署的个人工具**,没有官方在线版,也不提供公共账号。
|
||||
|
||||
- **部署方式**:仓库内提供 `Dockerfile` 与 `compose.yaml`,在已有 Docker 环境的机器上即可启动;也可直接用 Python 运行 `server.py` 在本机启动。
|
||||
- **访问方式**:部署完成后通过浏览器访问该机器上的服务端口(默认 8765),**具体地址由部署者自己决定**。出于安全考虑,本文档不写任何内网 IP、账号、密码或密钥。
|
||||
- **数据存放**:所有行情快照、复盘记录与账号数据都存在部署机器本地的 SQLite 数据库文件中(`data/review.db`),随 `data/` 目录一起备份即可。
|
||||
- **账号**:首次使用先注册,第一个注册的账号自动成为管理员,之后注册的默认为普通用户。
|
||||
- **数据来源**:行情数据来自 Tushare Pro 等第三方数据接口(部分分时数据优先使用同花顺 iFinD),**需要部署者自己申请并配置 Token**;部分接口的可用性取决于数据源方的授权与积分权限,个别数据缺失时页面会明确提示,不会用估算值顶替。
|
||||
- **大模型功能**:问师、问天解释、复盘助手、自然语言编译公式等需要配置一个 OpenAI 兼容的接口,由部署者自行配置与管理额度;未配置时这些对话与解释功能不可用,市场数据部分不受影响。
|
||||
|
||||
### 本机启动
|
||||
|
||||
仓库根目录即为运行目录(`server.py`、`requirements.txt` 都在根目录)。
|
||||
|
||||
```bash
|
||||
python -m pip install -r requirements.txt
|
||||
python server.py
|
||||
```
|
||||
|
||||
浏览器打开 `http://127.0.0.1:8765`,首次使用先注册账号。首个账号自动成为管理员,后续账号默认为普通用户。主行情不再回退演示数据:盘前、非交易日或临时取数失败时沿用最近真实收盘快照;没有任何真实快照时提示等待管理员完成首次同步。
|
||||
默认监听本机回环地址、端口 `8765`(仅本机浏览器可访问)。首次使用先注册账号。主行情不再回退演示数据:盘前、非交易日或临时取数失败时沿用最近真实收盘快照;没有任何真实快照时,页面会提示等待管理员完成首次同步。
|
||||
|
||||
需要后台启动本地验收端口时,使用`tools/start_local.ps1`。该工具把日志、进程号和Python缓存
|
||||
统一写入`runtime/`,不在源码根目录产生运行文件:
|
||||
Windows 下若需要后台启动,并把日志、进程号和 Python 缓存统一写入 `runtime/`(不在源码根目录产生运行文件),可使用:
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File tools/start_local.ps1 -Port 8797
|
||||
powershell -ExecutionPolicy Bypass -File tools/start_local.ps1
|
||||
```
|
||||
|
||||
局域网 Docker 部署使用 `Dockerfile` 与 `compose.yaml`,完整的迁移、持久化、
|
||||
防火墙、备份和恢复步骤见 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)。
|
||||
### Docker 部署
|
||||
|
||||
账号密码使用 scrypt 哈希;公共 Tushare Token、平台模型密钥以及原始生辰资料均使用 `APP_ENCRYPTION_KEY` 加密后保存在 SQLite。公共数据和平台模型归系统所有,生辰资料仍按账号隔离。普通用户不配置 LLM,只有管理员授权的有效会员可以使用平台模型。请将 `.env` 与数据库一起备份,丢失加密密钥后无法恢复这些资料。
|
||||
局域网或服务器部署使用仓库根目录的 `Dockerfile` 与 `compose.yaml`。完整的迁移、持久化、防火墙、备份和恢复步骤见 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)。
|
||||
|
||||
## 系统与账号配置
|
||||
### 系统与账号配置
|
||||
|
||||
管理员通过页面右上角“系统管理”保存公共 Tushare Token、平台主/辅助模型、会员每日额度和后台刷新开关。所有用户读取同一份 SQLite 行情快照,不再分别配置行情 Token。已有个人凭据中的 Tushare Token 会在升级时迁移到系统配置并从个人凭据移除。
|
||||
管理员通过页面右上角「系统管理」保存公共 Tushare Token、平台主/辅助模型、会员每日额度和后台刷新开关。所有用户读取同一份 SQLite 行情快照,不再分别配置行情 Token。
|
||||
|
||||
```text
|
||||
TUSHARE_TOKEN=你的Token
|
||||
```
|
||||
`.env` 中的 Tushare 和平台 LLM 配置只用于初始化系统配置,密钥不会返回到浏览器。请将 `.env` 与数据库一起备份,丢失 `APP_ENCRYPTION_KEY` 后无法恢复加密资料。
|
||||
|
||||
`.env` 中的 Tushare 和平台 LLM 配置只用于初始化系统配置,密钥不会返回到浏览器。后台刷新只在交易时段更新 SQLite 快照,不会主动刷新或重绘用户页面;用户点击页面“刷新”时读取最新快照。管理员也可点“后台刷新”立即启动一次后台同步,当前页面仍保持不变。
|
||||
普通用户在「账号设置」中维护个人资料、查看会员状态和修改密码,不配置个人 LLM。有效会员自动使用平台模型;管理员可在「系统管理」中手动开通、续期、停用会员。平台模型受管理员设置的每日调用次数限制,管理员账号始终可用。
|
||||
|
||||
普通用户在“账号设置”中维护个人资料、查看会员状态和修改密码,不配置个人 LLM。有效会员自动使用平台模型;管理员可在“系统管理”中手动开通、续期、停用会员。平台模型受管理员设置的每日调用次数限制,管理员账号始终可用。
|
||||
新增公开问师角色时,在 `游资skills` 下增加一个包含 `SKILL.md` 的独立目录,并在 `游资skills/mentor_catalog.json` 中登记。管理员私有角色放在 `data/private-mentor-skills`,该目录不进入 Git 或 Docker 镜像,且只会出现在管理员的问师列表中。
|
||||
|
||||
Tushare 各接口有独立积分权限。程序优先使用 `limit_list_d` 获取涨跌停明细;该接口不可用时,会尝试通过日线和每日涨跌停价格推算。
|
||||
### 相关文档
|
||||
|
||||
## 隔离实时聚合验证
|
||||
- [ARCHITECTURE.md](ARCHITECTURE.md) — 模块边界与源码职责
|
||||
- [docs/README.md](docs/README.md) — 交接手册入口
|
||||
- [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md) — Docker 部署、备份与恢复
|
||||
- [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) — 第三方授权(含问天历法库)
|
||||
|
||||
`backend/data/realtime.py`用于验证东方财富、同花顺和选股宝网页数据源。它不写入 SQLite 主行情快照,也不参与情绪评分或智能选股;当 Tushare 实时指数权限不可用时,观势会使用东方财富三大指数和板块外显,并继续使用 Tushare 的板块成分内核与个股数据。
|
||||
**技术组成(简要)**
|
||||
|
||||
登录后可调用:
|
||||
| 层面 | 说明 |
|
||||
| --- | --- |
|
||||
| 后端 | Python 3.12,仅用标准库自带的 HTTP 服务与自研路由,第三方依赖极少 |
|
||||
| 数据库 | SQLite(WAL 模式),单文件,易备份 |
|
||||
| 前端 | 原生 JavaScript + HTML,无构建工具、无打包步骤,改完刷新即可 |
|
||||
| 部署 | Docker / Docker Compose,或本机直接运行 |
|
||||
| 安全 | 账号密码 scrypt 哈希存储;行情 Token 与模型密钥使用 `APP_ENCRYPTION_KEY` 加密后存库,密钥与数据库需一起备份 |
|
||||
|
||||
```text
|
||||
GET /api/realtime-aggregate/health?sector=元器件
|
||||
```
|
||||
---
|
||||
|
||||
返回内容包括东方财富三大指数及板块快照、指数时间差、同花顺和选股宝可用性、每个来源的耗时与错误。盘中指数时间差不超过15秒,收盘后不超过120秒。`ready=true` 仅表示本次验证满足聚合层约束,不代表这些网页内部接口具有长期稳定性或商业使用授权。
|
||||
## 七、免责声明
|
||||
|
||||
- 本项目是一个**个人研究与复盘工具**,所提供的全部数据、指标、候选与文字分析,**均不构成投资建议、证券推荐或买卖要约**。
|
||||
- 本项目**不接券商、不代为下单**,交易日志只做手工记录与统计,不代表任何实际成交。
|
||||
- 情绪温度、阶段判定、连板梯队、策略筛选等均为**基于公开数据的统计与规则计算结果**,不预测未来走势,不保证任何收益。历史统计与回测结果不代表未来表现。
|
||||
- 「问天」模块属于**传统文化视角的娱乐化观察**,卦象、干支、节气与气机关系由本地程序确定性生成,用于换个角度看市场和自我觉察,**不具备预测功能,不得作为投资依据**。
|
||||
- 行情数据来自第三方接口,可能存在延迟、缺失或口径调整;页面会在数据不可用时明确提示,请以交易所与券商正式披露的数据为准。
|
||||
- 股市有风险,入市需谨慎。投资决策及其后果由使用者本人承担。
|
||||
|
||||
---
|
||||
|
||||
## 附:精简版项目推荐语
|
||||
|
||||
> 下面三段可以单独整段复制转发,不需要带图也能看懂。
|
||||
|
||||
### 一句话版(约 60 字,适合评论区、群聊快速安利)
|
||||
|
||||
> 小白复盘:一个自己部署的 A 股盘后复盘工作台——情绪、梯队、轮动、龙虎榜一页页看明白;说人话就能选股,不荐股、不下单,数据只存自己机器。
|
||||
|
||||
### 短版(约 320 字,适合社交平台、群聊、朋友圈)
|
||||
|
||||
> 发现一个挺特别的 A 股盘后复盘工具,叫「小白复盘」。
|
||||
>
|
||||
> 它不荐股、也不下单,就专心做一件事:把收盘后散落在各个软件里的信息整理成人看得懂的样子。打开先给你一个 0–100 的情绪温度和「冰点→修复→发酵→高潮→分化→退潮」六个阶段,让你先知道今天是什么环境;然后连板梯队、涨停炸板、板块轮动的 9 天热力图、集合竞价、龙虎榜游资动向,一页一页往下看。
|
||||
>
|
||||
> 最惊喜的是不会写公式也能选股——直接写一句人话,它帮你编译成条件去筛。还有「问师」可以按游资思维跟你对话,「问天」用卦象换个角度看市场、也让你静一静。
|
||||
>
|
||||
> 数据存在自己机器上的本地数据库里,私有部署,不上传。
|
||||
>
|
||||
> 提醒一句:它只是个把信息摆清楚的工具,不荐股也不下单,不构成投资建议。
|
||||
|
||||
### 稍长版(约 580 字,适合发论坛、公众号、仓库简介)
|
||||
|
||||
> **小白复盘 —— 给 A 股股民自己的盘后复盘工作台**
|
||||
>
|
||||
> 收盘以后,你是怎么复盘的?在好几个软件之间来回切,还是干脆不复盘?
|
||||
>
|
||||
> 小白复盘是一套可以自己部署的 A 股盘后复盘工具。它把涨停、炸板、跌停、连板梯队、板块轮动、集合竞价、龙虎榜这些散落各处的数据,整理成 16 个看得懂的页面:
|
||||
>
|
||||
> - **情绪周期**:0–100 情绪温度 + 六阶段判定,由市场宽度、涨停生态、赚钱效应、连板结构、成交活跃度五个维度加权算出,先看环境再看个股。
|
||||
> - **市场天梯**:从首板一路排到当天最高板,配市场高度与梯队完整度。
|
||||
> - **板块轮动**:近 9 个交易日 Top 12 板块热力矩阵,点一下就能看出热点是延续还是一日游。
|
||||
> - **集合竞价**:关注分满分 100,9:30 后自动冻结归档,专门留给复盘看。
|
||||
> - **龙虎榜**:席位明细、活跃游资、游资档案打通,点游资就能看它当天做了什么。
|
||||
> - **智能选股**:29 套精选策略(每套都写了适用环境和失效风险),也可以直接写一句人话,让它编译成公式去筛选。
|
||||
> - **问师 / 问天 / 我的复盘**:一个陪你按游资思维聊数据,一个用传统卦象换个角度看市场,一个帮你记下每笔交易的逻辑和情绪。
|
||||
>
|
||||
> 它不接券商、不代为下单,也不给出任何个股推荐——只负责把信息摆清楚,判断始终在你自己手里。所有数据存在你自己机器的本地 SQLite 里,私有部署,不上传。
|
||||
>
|
||||
> 项目私有部署、无公共在线版;文中所有功能描述均对应现有实现,不构成投资建议,市场有风险。
|
||||
|
||||
+3
-1
@@ -3,7 +3,9 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: xiaobai-review:latest
|
||||
labels:
|
||||
org.opencontainers.image.revision: "${XIAOBAI_GIT_REV:?必须先设置 XIAOBAI_GIT_REV=当前 main 完整提交号(或改用 tools/update_from_main.sh)}"
|
||||
image: xiaobai-review:main-${XIAOBAI_GIT_SHORT:?必须先设置 XIAOBAI_GIT_SHORT=7位提交短号(或改用 tools/update_from_main.sh)}
|
||||
container_name: xiaobai-review
|
||||
ports:
|
||||
- "0.0.0.0:8765:8765/tcp"
|
||||
|
||||
@@ -374,10 +374,10 @@
|
||||
}
|
||||
],
|
||||
"css_layers": [
|
||||
"/shared/tokens.css?v=20260829-1",
|
||||
"/shared/tokens.css?v=20260829-hel240",
|
||||
"/shared/base.css?v=20260806-1",
|
||||
"/shared/shell.css?v=20260829-hel237",
|
||||
"/shared/auth.css?v=20260829-hel237",
|
||||
"/shared/auth.css?v=20260829-hel240b",
|
||||
"/shared/components/controls.css?v=20260829-hel237",
|
||||
"/shared/components/navigation.css?v=20260820-1",
|
||||
"/shared/components/cards.css?v=20260820-1",
|
||||
@@ -465,7 +465,7 @@
|
||||
},
|
||||
{
|
||||
"path": "frontend/index.html",
|
||||
"bytes": 48248,
|
||||
"bytes": 48254,
|
||||
"lines": 664
|
||||
},
|
||||
{
|
||||
@@ -553,16 +553,16 @@
|
||||
"bytes": 13681,
|
||||
"lines": 338
|
||||
},
|
||||
{
|
||||
"path": "frontend/shared/session.js",
|
||||
"bytes": 13219,
|
||||
"lines": 289
|
||||
},
|
||||
{
|
||||
"path": "frontend/shared/dashboard.js",
|
||||
"bytes": 12894,
|
||||
"lines": 274
|
||||
},
|
||||
{
|
||||
"path": "frontend/shared/session.js",
|
||||
"bytes": 12848,
|
||||
"lines": 283
|
||||
},
|
||||
{
|
||||
"path": "backend/features/market/insights_auction_data.py",
|
||||
"bytes": 12829,
|
||||
@@ -673,16 +673,16 @@
|
||||
"bytes": 5451,
|
||||
"lines": 118
|
||||
},
|
||||
{
|
||||
"path": "frontend/pages.config.js",
|
||||
"bytes": 5385,
|
||||
"lines": 130
|
||||
},
|
||||
{
|
||||
"path": "frontend/pages/market/search.js",
|
||||
"bytes": 5384,
|
||||
"lines": 131
|
||||
},
|
||||
{
|
||||
"path": "frontend/pages.config.js",
|
||||
"bytes": 5380,
|
||||
"lines": 130
|
||||
},
|
||||
{
|
||||
"path": "frontend/pages/auction/page.html",
|
||||
"bytes": 5350,
|
||||
|
||||
+2
-2
@@ -34,10 +34,10 @@
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="/shared/tokens.css?v=20260829-1">
|
||||
<link rel="stylesheet" href="/shared/tokens.css?v=20260829-hel240">
|
||||
<link rel="stylesheet" href="/shared/base.css?v=20260806-1">
|
||||
<link rel="stylesheet" href="/shared/shell.css?v=20260829-hel237">
|
||||
<link rel="stylesheet" href="/shared/auth.css?v=20260829-hel237">
|
||||
<link rel="stylesheet" href="/shared/auth.css?v=20260829-hel240b">
|
||||
<link rel="stylesheet" href="/shared/components/controls.css?v=20260829-hel237">
|
||||
<link rel="stylesheet" href="/shared/components/navigation.css?v=20260820-1">
|
||||
<link rel="stylesheet" href="/shared/components/cards.css?v=20260820-1">
|
||||
|
||||
+127
-24
@@ -19,41 +19,144 @@
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="/shared/tokens.css?v=20260829-1">
|
||||
<link rel="stylesheet" href="/shared/tokens.css?v=20260829-hel251">
|
||||
<link rel="stylesheet" href="/shared/base.css?v=20260806-1">
|
||||
<link rel="stylesheet" href="/shared/auth.css?v=20260829-1">
|
||||
<link rel="stylesheet" href="/shared/auth.css?v=20260829-hel251">
|
||||
<link rel="stylesheet" href="/shared/components/controls.css?v=20260820-2">
|
||||
</head>
|
||||
<body class="login-portal">
|
||||
<button id="loginThemeToggle" class="login-theme-toggle" type="button">🌙 夜间</button>
|
||||
<aside class="login-brand" aria-hidden="true">
|
||||
<div class="login-brand-mark"><span class="login-brand-glyph">复</span></div>
|
||||
<p class="login-brand-kicker">收盘之后 · 复盘开始</p>
|
||||
<h1 class="login-brand-title">小白复盘</h1>
|
||||
<p class="login-brand-lead">看懂情绪周期,把复盘变成下一次的先手。</p>
|
||||
<dl class="login-brand-stats">
|
||||
<div class="login-stat">
|
||||
<dt>市场情绪</dt>
|
||||
<dd>72 <span class="login-stat-tag">高热</span></dd>
|
||||
<div class="login-brand-header">
|
||||
<div class="login-brand-mark"><span class="login-brand-glyph">复</span></div>
|
||||
<div class="login-brand-identity">
|
||||
<p class="login-brand-name">小白复盘</p>
|
||||
<p class="login-brand-subtitle">A股个人复盘工作台</p>
|
||||
</div>
|
||||
<div class="login-stat">
|
||||
<dt>涨停</dt>
|
||||
<dd>63</dd>
|
||||
</div>
|
||||
<div class="login-mascots" id="loginMascots" aria-hidden="true" data-mood="idle">
|
||||
<div class="login-mascots-stage">
|
||||
<div class="login-mascot is-red">
|
||||
<div class="login-mascot-breathe">
|
||||
<div class="login-mascot-lean">
|
||||
<svg class="login-mascot-figure" viewBox="0 0 96 210" focusable="false">
|
||||
<ellipse class="login-mascot-shadow" cx="48" cy="200" rx="26" ry="5.5"></ellipse>
|
||||
<line class="login-mascot-wick" x1="48" y1="10" x2="48" y2="50"></line>
|
||||
<rect class="login-mascot-body" x="16" y="50" width="64" height="126" rx="14"></rect>
|
||||
<line class="login-mascot-wick" x1="48" y1="176" x2="48" y2="190"></line>
|
||||
<g class="login-mascot-face">
|
||||
<circle class="login-mascot-eye" cx="36" cy="94" r="10"></circle>
|
||||
<circle class="login-mascot-eye" cx="60" cy="94" r="10"></circle>
|
||||
<circle class="login-mascot-pupil" cx="36" cy="94" r="4.2"></circle>
|
||||
<circle class="login-mascot-pupil" cx="60" cy="94" r="4.2"></circle>
|
||||
<rect class="login-mascot-lid" x="24" y="82" width="48" height="24" rx="10"></rect>
|
||||
<path class="login-mascot-happy" d="M28 96 Q36 88 44 96"></path>
|
||||
<path class="login-mascot-happy" d="M52 96 Q60 88 68 96"></path>
|
||||
<circle class="login-mascot-sad" cx="36" cy="96" r="2.2"></circle>
|
||||
<circle class="login-mascot-sad" cx="60" cy="96" r="2.2"></circle>
|
||||
</g>
|
||||
<ellipse class="login-mascot-arm is-left" cx="16" cy="128" rx="8" ry="5.5"></ellipse>
|
||||
<ellipse class="login-mascot-arm is-right" cx="80" cy="128" rx="8" ry="5.5"></ellipse>
|
||||
<ellipse class="login-mascot-hand is-left" cx="16" cy="128" rx="9" ry="7"></ellipse>
|
||||
<ellipse class="login-mascot-hand is-right" cx="80" cy="128" rx="9" ry="7"></ellipse>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-mascot is-green">
|
||||
<div class="login-mascot-breathe">
|
||||
<div class="login-mascot-lean">
|
||||
<div class="login-mascot-figure">
|
||||
<svg class="login-mascot-front" viewBox="0 0 84 175" focusable="false">
|
||||
<ellipse class="login-mascot-shadow" cx="42" cy="166" rx="22" ry="4.5"></ellipse>
|
||||
<line class="login-mascot-wick" x1="42" y1="8" x2="42" y2="42"></line>
|
||||
<rect class="login-mascot-body" x="15" y="42" width="54" height="104" rx="12"></rect>
|
||||
<line class="login-mascot-wick" x1="42" y1="146" x2="42" y2="158"></line>
|
||||
<g class="login-mascot-face">
|
||||
<circle class="login-mascot-eye" cx="32" cy="76" r="8.5"></circle>
|
||||
<circle class="login-mascot-eye" cx="52" cy="76" r="8.5"></circle>
|
||||
<circle class="login-mascot-pupil" cx="32" cy="76" r="3.6"></circle>
|
||||
<circle class="login-mascot-pupil" cx="52" cy="76" r="3.6"></circle>
|
||||
<rect class="login-mascot-lid" x="22" y="66" width="40" height="20" rx="8"></rect>
|
||||
<path class="login-mascot-happy" d="M25 78 Q32 71 39 78"></path>
|
||||
<path class="login-mascot-happy" d="M45 78 Q52 71 59 78"></path>
|
||||
<circle class="login-mascot-sad" cx="32" cy="78" r="1.9"></circle>
|
||||
<circle class="login-mascot-sad" cx="52" cy="78" r="1.9"></circle>
|
||||
</g>
|
||||
<ellipse class="login-mascot-arm is-left" cx="15" cy="108" rx="7" ry="4.5"></ellipse>
|
||||
<ellipse class="login-mascot-arm is-right" cx="69" cy="108" rx="7" ry="4.5"></ellipse>
|
||||
</svg>
|
||||
<svg class="login-mascot-back" viewBox="0 0 84 175" focusable="false">
|
||||
<ellipse class="login-mascot-shadow" cx="42" cy="166" rx="22" ry="4.5"></ellipse>
|
||||
<line class="login-mascot-wick" x1="42" y1="8" x2="42" y2="42"></line>
|
||||
<rect class="login-mascot-body" x="15" y="42" width="54" height="104" rx="12"></rect>
|
||||
<line class="login-mascot-wick" x1="42" y1="146" x2="42" y2="158"></line>
|
||||
<rect class="login-mascot-slit" x="40.5" y="58" width="3" height="72" rx="1.5"></rect>
|
||||
<ellipse class="login-mascot-arm is-left" cx="15" cy="108" rx="7" ry="4.5"></ellipse>
|
||||
<ellipse class="login-mascot-arm is-right" cx="69" cy="108" rx="7" ry="4.5"></ellipse>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-stat">
|
||||
<dt>跌停</dt>
|
||||
<dd>4</dd>
|
||||
</div>
|
||||
<div class="login-stat">
|
||||
<dt>两市成交</dt>
|
||||
<dd>1.02万亿</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="login-brand-copy">
|
||||
<p class="login-brand-kicker">收盘之后 · 复盘开始</p>
|
||||
<h1 class="login-brand-title">看懂情绪周期,把复盘变成下一次的先手。</h1>
|
||||
<p class="login-brand-lead">情绪周期、涨停梯队、主题轮动、竞价、龙虎榜、人气榜、交易复盘,集中在一个安静的复盘空间。</p>
|
||||
</div>
|
||||
<div class="login-brand-market">
|
||||
<svg class="login-brand-chart" viewBox="0 0 480 168" focusable="false">
|
||||
<defs>
|
||||
<linearGradient id="loginChartFade" x1="0" x2="0" y1="0" y2="1">
|
||||
<stop offset="0%" stop-color="#d7e4ff" stop-opacity="0.18"></stop>
|
||||
<stop offset="100%" stop-color="#d7e4ff" stop-opacity="0"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<path class="login-chart-area" d="M8 118 C 52 108, 78 96, 112 102 S 168 128, 204 112 S 268 78, 312 86 S 372 118, 428 92 L 472 84 L 472 168 L 8 168 Z"></path>
|
||||
<g class="login-candles">
|
||||
<g class="is-up" transform="translate(36 0)"><line x1="8" y1="58" x2="8" y2="128"></line><rect x="2" y="72" width="12" height="40"></rect></g>
|
||||
<g class="is-down" transform="translate(68 0)"><line x1="8" y1="64" x2="8" y2="132"></line><rect x="2" y="86" width="12" height="28"></rect></g>
|
||||
<g class="is-up" transform="translate(100 0)"><line x1="8" y1="48" x2="8" y2="118"></line><rect x="2" y="60" width="12" height="44"></rect></g>
|
||||
<g class="is-down" transform="translate(132 0)"><line x1="8" y1="70" x2="8" y2="136"></line><rect x="2" y="92" width="12" height="26"></rect></g>
|
||||
<g class="is-up" transform="translate(164 0)"><line x1="8" y1="42" x2="8" y2="110"></line><rect x="2" y="54" width="12" height="38"></rect></g>
|
||||
<g class="is-up" transform="translate(196 0)"><line x1="8" y1="36" x2="8" y2="98"></line><rect x="2" y="48" width="12" height="32"></rect></g>
|
||||
<g class="is-down" transform="translate(228 0)"><line x1="8" y1="58" x2="8" y2="128"></line><rect x="2" y="78" width="12" height="36"></rect></g>
|
||||
<g class="is-up" transform="translate(260 0)"><line x1="8" y1="40" x2="8" y2="104"></line><rect x="2" y="52" width="12" height="36"></rect></g>
|
||||
<g class="is-down" transform="translate(292 0)"><line x1="8" y1="66" x2="8" y2="134"></line><rect x="2" y="88" width="12" height="30"></rect></g>
|
||||
<g class="is-up" transform="translate(324 0)"><line x1="8" y1="44" x2="8" y2="112"></line><rect x="2" y="58" width="12" height="40"></rect></g>
|
||||
<g class="is-down" transform="translate(356 0)"><line x1="8" y1="72" x2="8" y2="138"></line><rect x="2" y="96" width="12" height="24"></rect></g>
|
||||
<g class="is-up" transform="translate(388 0)"><line x1="8" y1="38" x2="8" y2="108"></line><rect x="2" y="50" width="12" height="42"></rect></g>
|
||||
<g class="is-up" transform="translate(420 0)"><line x1="8" y1="32" x2="8" y2="96"></line><rect x="2" y="44" width="12" height="34"></rect></g>
|
||||
</g>
|
||||
<path class="login-chart-line" d="M8 118 C 52 108, 78 96, 112 102 S 168 128, 204 112 S 268 78, 312 86 S 372 118, 428 92 L 472 84"></path>
|
||||
</svg>
|
||||
<dl class="login-brand-stats">
|
||||
<div class="login-stat">
|
||||
<dt>市场情绪</dt>
|
||||
<dd>72 <span class="login-stat-tag">高热</span></dd>
|
||||
</div>
|
||||
<div class="login-stat">
|
||||
<dt>涨停</dt>
|
||||
<dd>63</dd>
|
||||
</div>
|
||||
<div class="login-stat">
|
||||
<dt>跌停</dt>
|
||||
<dd>4</dd>
|
||||
</div>
|
||||
<div class="login-stat login-stat-wide">
|
||||
<dt>两市成交</dt>
|
||||
<dd>1.02万亿</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
<p class="login-brand-disclaimer">股市有风险,投资需谨慎 · 本工具仅供个人复盘学习使用</p>
|
||||
</aside>
|
||||
<main class="login-stage">
|
||||
<button id="loginThemeToggle" class="login-theme-toggle" type="button">🌙 夜间</button>
|
||||
<section class="login-card" id="loginCard" aria-live="polite"></section>
|
||||
</main>
|
||||
<script src="/shared/api.js?v=20260803-2"></script>
|
||||
<script src="/login/page.js?v=20260829-1"></script>
|
||||
<script src="/login/page.js?v=20260829-hel251"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+360
-23
@@ -13,6 +13,9 @@
|
||||
loading: false,
|
||||
confirmingId: null,
|
||||
error: "",
|
||||
username: "",
|
||||
password: "",
|
||||
passwordVisible: false,
|
||||
};
|
||||
|
||||
function escapeHtml(value) {
|
||||
@@ -52,48 +55,90 @@
|
||||
state.error = message || "";
|
||||
}
|
||||
|
||||
function membershipLabel(account) {
|
||||
if (account.role === "admin") return account.membership?.subscribed ? "管理员 · 会员" : "管理员";
|
||||
return account.membership?.subscribed ? "会员" : "普通用户";
|
||||
function formatLastUsed(value) {
|
||||
if (!value) return "";
|
||||
const parsed = new Date(value);
|
||||
if (Number.isNaN(parsed.getTime())) return "";
|
||||
const now = new Date();
|
||||
const hh = String(parsed.getHours()).padStart(2, "0");
|
||||
const mm = String(parsed.getMinutes()).padStart(2, "0");
|
||||
if (parsed.toDateString() === now.toDateString()) return `今天 ${hh}:${mm}`;
|
||||
const yesterday = new Date(now);
|
||||
yesterday.setDate(now.getDate() - 1);
|
||||
if (parsed.toDateString() === yesterday.toDateString()) return `昨天 ${hh}:${mm}`;
|
||||
return `${parsed.getMonth() + 1}月${parsed.getDate()}日`;
|
||||
}
|
||||
|
||||
function chipsFor(account, current) {
|
||||
const chips = [];
|
||||
if (current) chips.push('<span class="login-chip login-chip-current">当前</span>');
|
||||
if (account.role === "admin") chips.push('<span class="login-chip">管理员</span>');
|
||||
if (account.membership?.subscribed) chips.push('<span class="login-chip login-chip-member">会员</span>');
|
||||
else if (account.role !== "admin") chips.push('<span class="login-chip">普通用户</span>');
|
||||
return chips.join("");
|
||||
}
|
||||
|
||||
function returnPath() {
|
||||
const raw = new URLSearchParams(global.location.search).get("next") || "";
|
||||
if (!raw) return "/";
|
||||
try {
|
||||
const url = new URL(raw, global.location.origin);
|
||||
if (url.origin !== global.location.origin) return "/";
|
||||
const path = url.pathname || "/";
|
||||
if (path === "/login" || path.startsWith("/login/")) return "/";
|
||||
return `${path}${url.search}${url.hash}` || "/";
|
||||
} catch (_error) {
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
|
||||
function enterApp() {
|
||||
const next = new URLSearchParams(global.location.search).get("next");
|
||||
global.location.replace(next && next.startsWith("/") ? next : "/");
|
||||
global.location.replace(returnPath());
|
||||
}
|
||||
|
||||
function formMarkup(options) {
|
||||
const registering = state.mode === "register";
|
||||
const submitLabel = options.submitLabel
|
||||
|| (state.loading ? "正在登录..." : registering ? "注册并进入" : options.add ? "添加并进入" : "登录");
|
||||
const lead = options.lead;
|
||||
const hint = options.hint;
|
||||
const invalid = state.error ? " is-invalid" : "";
|
||||
const passwordType = state.passwordVisible ? "text" : "password";
|
||||
const passwordToggle = state.passwordVisible ? "隐藏" : "显示";
|
||||
return [
|
||||
options.back
|
||||
? '<button class="login-back" type="button" data-login-action="picker">返回账号列表</button>'
|
||||
: "",
|
||||
`<h2 class="login-card-title">${escapeHtml(options.title)}</h2>`,
|
||||
`<p class="login-card-lead">${escapeHtml(options.lead)}</p>`,
|
||||
`<p class="login-card-lead">${escapeHtml(lead)}</p>`,
|
||||
'<div class="login-tabs" role="tablist">',
|
||||
`<button class="login-tab${state.mode === "login" ? " is-active" : ""}" type="button" data-auth-mode="login">登录</button>`,
|
||||
`<button class="login-tab${state.mode === "register" ? " is-active" : ""}" type="button" data-auth-mode="register">注册</button>`,
|
||||
"</div>",
|
||||
'<form class="login-form" id="loginForm">',
|
||||
'<label class="form-field"><span>账号名</span><input id="loginUsername" type="text" minlength="3" maxlength="30" autocomplete="username" required></label>',
|
||||
`<label class="form-field"><span>密码</span><input id="loginPassword" type="password" minlength="8" maxlength="128" autocomplete="${registering ? "new-password" : "current-password"}" required></label>`,
|
||||
`<label class="form-field"><span>账号名</span><input id="loginUsername" type="text" minlength="3" maxlength="30" autocomplete="username" placeholder="请输入账号名" value="${escapeHtml(state.username)}" required></label>`,
|
||||
`<label class="form-field"><span>密码</span><span class="login-password-wrap"><input id="loginPassword" class="${invalid.trim()}" type="${passwordType}" minlength="8" maxlength="128" autocomplete="${registering ? "new-password" : "current-password"}" placeholder="请输入密码" value="${escapeHtml(state.password)}" required><button class="login-password-toggle" type="button" data-login-action="toggle-password" aria-pressed="${state.passwordVisible ? "true" : "false"}" aria-label="${state.passwordVisible ? "隐藏密码" : "显示密码"}">${passwordToggle}</button></span></label>`,
|
||||
`<label class="form-field" id="loginConfirmField"${registering ? "" : " hidden"}><span>确认密码</span><input id="loginPasswordConfirm" type="password" minlength="8" maxlength="128" autocomplete="new-password"${registering ? " required" : ""}></label>`,
|
||||
state.error ? `<p class="login-error">${escapeHtml(state.error)}</p>` : '<p class="login-error" hidden></p>',
|
||||
`<button class="button primary login-submit" type="submit"${state.loading ? " disabled" : ""}>`,
|
||||
state.loading ? '<span class="login-spinner" aria-hidden="true"></span>' : "",
|
||||
`<span>${escapeHtml(submitLabel)}</span></button>`,
|
||||
"</form>",
|
||||
'<p class="login-hint">密码连续输错 5 次将锁定 10 分钟。还没有账号?切换到「注册」创建。</p>',
|
||||
`<p class="login-hint">${escapeHtml(hint)}</p>`,
|
||||
].join("");
|
||||
}
|
||||
|
||||
function accountRow(account) {
|
||||
const current = Number(account.user_id) === Number(state.currentUserId);
|
||||
const confirming = Number(state.confirmingId) === Number(account.user_id);
|
||||
const classes = `login-account-row${current ? " is-current" : ""}${confirming ? " is-confirming" : ""}`;
|
||||
if (state.view === "manage" && confirming) {
|
||||
const managing = state.view === "manage";
|
||||
const classes = [
|
||||
"login-account-row",
|
||||
current ? "is-current" : "",
|
||||
confirming ? "is-confirming" : "",
|
||||
!managing ? "is-switchable" : "",
|
||||
].filter(Boolean).join(" ");
|
||||
if (managing && confirming) {
|
||||
return [
|
||||
`<div class="${classes}" data-user-id="${account.user_id}">`,
|
||||
`<p class="login-confirm-copy">移除「${escapeHtml(account.username)}」的本机记录?</p>`,
|
||||
@@ -103,16 +148,25 @@
|
||||
"</div></div>",
|
||||
].join("");
|
||||
}
|
||||
const action = state.view === "manage"
|
||||
? `<button class="login-account-remove" type="button" data-confirm-id="${account.user_id}">移除</button>`
|
||||
const glyph = escapeHtml(String(account.username || "账").slice(0, 1));
|
||||
const tone = Number(account.user_id || 0) % 4;
|
||||
const used = formatLastUsed(account.last_used_at);
|
||||
const action = managing
|
||||
? `<button class="login-account-remove" type="button" data-confirm-id="${account.user_id}" aria-label="移除 ${escapeHtml(account.username)}"><svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M6 2h4l.5 1H14v1H2V3h3.5L6 2zm1 4v6H6V6h1zm3 0v6H9V6h1zM3.5 5H13l-.7 8.2A1.5 1.5 0 0 1 10.81 14H5.19a1.5 1.5 0 0 1-1.49-1.8L3.5 5z"></path></svg></button>`
|
||||
: current
|
||||
? '<span class="login-account-check" aria-hidden="true">✓</span>'
|
||||
: `<button class="login-account-enter" type="button" data-switch-id="${account.user_id}">进入</button>`;
|
||||
? '<span class="login-account-action"><span class="login-account-check" aria-hidden="true">✓</span>继续使用</span>'
|
||||
: "";
|
||||
const switchAttr = !managing && !current ? ` data-switch-id="${account.user_id}"` : "";
|
||||
const resumeAttr = !managing && current ? ` data-resume-id="${account.user_id}"` : "";
|
||||
return [
|
||||
`<div class="${classes}" data-user-id="${account.user_id}">`,
|
||||
`<div class="${classes}" data-user-id="${account.user_id}"${switchAttr}${resumeAttr}>`,
|
||||
`<span class="login-avatar tone-${tone}" aria-hidden="true">${glyph}</span>`,
|
||||
'<div class="login-account-meta">',
|
||||
'<div class="login-account-name">',
|
||||
`<strong>${escapeHtml(account.username)}</strong>`,
|
||||
`<span>${escapeHtml(membershipLabel(account))}${current ? " · 当前" : ""}</span>`,
|
||||
chipsFor(account, current),
|
||||
"</div>",
|
||||
used ? `<span class="login-account-used">上次登录 ${escapeHtml(used)}</span>` : "",
|
||||
"</div>",
|
||||
action,
|
||||
"</div>",
|
||||
@@ -123,10 +177,15 @@
|
||||
const count = state.accounts.length;
|
||||
const managing = state.view === "manage";
|
||||
return [
|
||||
`<h2 class="login-card-title">${managing ? "管理账号记录" : "选择账号"}</h2>`,
|
||||
`<p class="login-card-lead">这台电脑已记录 ${count} 个账号,可直接进入,无需再次输入密码。</p>`,
|
||||
managing
|
||||
? '<button class="login-manage" type="button" data-login-action="picker">完成</button>'
|
||||
? ""
|
||||
: '<button class="login-back" type="button" data-login-action="resume">返回复盘</button>',
|
||||
`<h2 class="login-card-title">${managing ? "管理账号记录" : "选择账号"}</h2>`,
|
||||
`<p class="login-card-lead">${managing
|
||||
? "移除只删除这台电脑上的登录记录,不会注销账号"
|
||||
: `这台电脑已记录 ${count} 个账号,点选即可进入,无需再次输入密码。`}</p>`,
|
||||
managing
|
||||
? '<div class="login-manage-toolbar"><p class="login-manage-hint">点击右侧图标移除对应记录</p><button class="login-manage-done" type="button" data-login-action="picker">完成</button></div>'
|
||||
: "",
|
||||
`<div class="login-account-list">${state.accounts.map(accountRow).join("")}</div>`,
|
||||
managing
|
||||
@@ -136,7 +195,9 @@
|
||||
? ""
|
||||
: '<button class="login-manage" type="button" data-login-action="manage">管理已记录的账号</button>',
|
||||
state.error ? `<p class="login-error">${escapeHtml(state.error)}</p>` : "",
|
||||
'<p class="login-privacy"><span class="login-lock" aria-hidden="true">🔒</span>账号记录仅保存在这台电脑的浏览器中</p>',
|
||||
managing
|
||||
? '<p class="login-privacy"><span class="login-lock" aria-hidden="true">🔒</span>移除后再次登录该账号需重新输入密码</p>'
|
||||
: '<p class="login-privacy"><span class="login-lock" aria-hidden="true">🔒</span>账号记录仅保存在这台电脑的浏览器中</p>',
|
||||
].join("");
|
||||
}
|
||||
|
||||
@@ -145,7 +206,10 @@
|
||||
if (state.view === "first" || state.view === "add") {
|
||||
card.innerHTML = formMarkup({
|
||||
title: state.view === "add" ? "添加账号" : "欢迎回来",
|
||||
lead: "登录后进入你的复盘空间",
|
||||
lead: state.view === "add" ? "登录另一个账号,添加后可随时一键切换" : "登录后进入你的复盘空间",
|
||||
hint: state.view === "add"
|
||||
? "添加后账号会保存在这台电脑,方便随时切换。"
|
||||
: "密码连续输错 5 次将锁定 10 分钟。还没有账号?切换到「注册」创建。",
|
||||
add: state.view === "add",
|
||||
back: state.view === "add",
|
||||
});
|
||||
@@ -153,6 +217,7 @@
|
||||
card.innerHTML = pickerMarkup();
|
||||
}
|
||||
bindCard();
|
||||
if (mascots) mascots.sync();
|
||||
}
|
||||
|
||||
function bindCard() {
|
||||
@@ -166,6 +231,14 @@
|
||||
card.querySelectorAll("[data-login-action]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const action = button.dataset.loginAction;
|
||||
if (action === "toggle-password") {
|
||||
togglePasswordVisible();
|
||||
return;
|
||||
}
|
||||
if (action === "resume") {
|
||||
resumeCurrentAccount();
|
||||
return;
|
||||
}
|
||||
if (action === "picker") {
|
||||
state.view = state.accounts.length ? "picker" : "first";
|
||||
state.confirmingId = null;
|
||||
@@ -184,8 +257,12 @@
|
||||
card.querySelectorAll("[data-switch-id]").forEach((button) => {
|
||||
button.addEventListener("click", () => switchAccount(Number(button.dataset.switchId)));
|
||||
});
|
||||
card.querySelectorAll("[data-resume-id]").forEach((button) => {
|
||||
button.addEventListener("click", () => resumeCurrentAccount());
|
||||
});
|
||||
card.querySelectorAll("[data-confirm-id]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
button.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
state.confirmingId = Number(button.dataset.confirmId);
|
||||
render();
|
||||
});
|
||||
@@ -212,6 +289,8 @@
|
||||
event.preventDefault();
|
||||
const username = document.querySelector("#loginUsername").value.trim();
|
||||
const password = document.querySelector("#loginPassword").value;
|
||||
state.username = username;
|
||||
state.password = password;
|
||||
if (state.mode === "register" && password !== document.querySelector("#loginPasswordConfirm").value) {
|
||||
setError("两次输入的密码不一致。");
|
||||
render();
|
||||
@@ -222,11 +301,13 @@
|
||||
render();
|
||||
try {
|
||||
await api.request(`/api/auth/${state.mode}`, "POST", { username, password });
|
||||
await celebrateLogin();
|
||||
enterApp();
|
||||
} catch (error) {
|
||||
state.loading = false;
|
||||
setError(error.message || "账号操作失败");
|
||||
render();
|
||||
mascots.fail();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +325,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function resumeCurrentAccount() {
|
||||
state.loading = true;
|
||||
setError("");
|
||||
render();
|
||||
try {
|
||||
const session = await api.request("/api/auth/me");
|
||||
const sessionUserId = session.user?.id;
|
||||
const matches = Boolean(session.authenticated) && (
|
||||
!state.currentUserId || Number(sessionUserId) === Number(state.currentUserId)
|
||||
);
|
||||
if (!matches) {
|
||||
throw new Error("当前会话已失效,请重新登录");
|
||||
}
|
||||
enterApp();
|
||||
} catch (error) {
|
||||
state.loading = false;
|
||||
setError(error.message || "当前会话已失效,请重新登录");
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
async function forgetAccount(userId) {
|
||||
try {
|
||||
await api.request("/api/auth/forget", "POST", { user_id: userId });
|
||||
@@ -258,6 +360,241 @@
|
||||
}
|
||||
}
|
||||
|
||||
function togglePasswordVisible() {
|
||||
state.passwordVisible = !state.passwordVisible;
|
||||
const input = document.querySelector("#loginPassword");
|
||||
const button = document.querySelector(".login-password-toggle");
|
||||
if (input) {
|
||||
input.type = state.passwordVisible ? "text" : "password";
|
||||
input.focus();
|
||||
}
|
||||
if (button) {
|
||||
button.textContent = state.passwordVisible ? "隐藏" : "显示";
|
||||
button.setAttribute("aria-pressed", state.passwordVisible ? "true" : "false");
|
||||
button.setAttribute("aria-label", state.passwordVisible ? "隐藏密码" : "显示密码");
|
||||
}
|
||||
mascots.sync();
|
||||
}
|
||||
|
||||
function reducedMotion() {
|
||||
return Boolean(global.matchMedia && global.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
||||
}
|
||||
|
||||
function finePointer() {
|
||||
return Boolean(global.matchMedia && global.matchMedia("(pointer: fine)").matches);
|
||||
}
|
||||
|
||||
function wait(ms) {
|
||||
return new Promise((resolve) => global.setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function celebrateLogin() {
|
||||
mascots.succeed();
|
||||
if (!reducedMotion()) await wait(720);
|
||||
}
|
||||
|
||||
const mascots = (() => {
|
||||
const root = document.querySelector("#loginMascots");
|
||||
const red = root && root.querySelector(".login-mascot.is-red");
|
||||
const green = root && root.querySelector(".login-mascot.is-green");
|
||||
const motion = {
|
||||
pupilX: 0,
|
||||
pupilY: 0,
|
||||
targetX: 0,
|
||||
targetY: 0,
|
||||
leanRed: 0,
|
||||
leanGreen: 0,
|
||||
targetLeanRed: 0,
|
||||
targetLeanGreen: 0,
|
||||
};
|
||||
let mood = "idle";
|
||||
let locked = "";
|
||||
let blinkTimer = 0;
|
||||
let failTimer = 0;
|
||||
let raf = 0;
|
||||
|
||||
function setVars() {
|
||||
if (!red || !green) return;
|
||||
const pupilX = `${motion.pupilX.toFixed(2)}px`;
|
||||
const pupilY = `${motion.pupilY.toFixed(2)}px`;
|
||||
red.style.setProperty("--pupil-x", pupilX);
|
||||
red.style.setProperty("--pupil-y", pupilY);
|
||||
green.style.setProperty("--pupil-x", pupilX);
|
||||
green.style.setProperty("--pupil-y", pupilY);
|
||||
red.style.setProperty("--lean", `${motion.leanRed.toFixed(2)}deg`);
|
||||
green.style.setProperty("--lean", `${motion.leanGreen.toFixed(2)}deg`);
|
||||
}
|
||||
|
||||
function poseFor(next) {
|
||||
if (next === "account" || next === "busy") {
|
||||
motion.targetX = 3.2;
|
||||
motion.targetY = 0.8;
|
||||
motion.targetLeanRed = 7;
|
||||
motion.targetLeanGreen = 5.6;
|
||||
return;
|
||||
}
|
||||
if (next === "password") {
|
||||
motion.targetX = 0;
|
||||
motion.targetY = 0;
|
||||
motion.targetLeanRed = 0;
|
||||
motion.targetLeanGreen = 0;
|
||||
return;
|
||||
}
|
||||
if (next === "fail") {
|
||||
motion.targetX = 0;
|
||||
motion.targetY = 2.8;
|
||||
motion.targetLeanRed = 8;
|
||||
motion.targetLeanGreen = 8;
|
||||
return;
|
||||
}
|
||||
if (next === "success") {
|
||||
motion.targetX = 0;
|
||||
motion.targetY = 0;
|
||||
motion.targetLeanRed = 0;
|
||||
motion.targetLeanGreen = 0;
|
||||
return;
|
||||
}
|
||||
if (!finePointer()) {
|
||||
motion.targetX = 2.4;
|
||||
motion.targetY = 0.4;
|
||||
motion.targetLeanRed = 4;
|
||||
motion.targetLeanGreen = 3.2;
|
||||
return;
|
||||
}
|
||||
motion.targetLeanRed = 0;
|
||||
motion.targetLeanGreen = 0;
|
||||
}
|
||||
|
||||
function applyMood(next) {
|
||||
if (!root) return;
|
||||
const changed = next !== mood;
|
||||
if (changed) {
|
||||
mood = next;
|
||||
root.dataset.mood = next;
|
||||
poseFor(next);
|
||||
} else if (next !== "idle") {
|
||||
poseFor(next);
|
||||
}
|
||||
if (reducedMotion()) {
|
||||
motion.pupilX = motion.targetX;
|
||||
motion.pupilY = motion.targetY;
|
||||
motion.leanRed = motion.targetLeanRed;
|
||||
motion.leanGreen = motion.targetLeanGreen;
|
||||
setVars();
|
||||
}
|
||||
}
|
||||
|
||||
function focusedControl() {
|
||||
const active = document.activeElement;
|
||||
if (!active || !card.contains(active)) return "";
|
||||
if (active.classList.contains("login-password-toggle")) return "loginPassword";
|
||||
return active.id || "";
|
||||
}
|
||||
|
||||
function desiredMood() {
|
||||
if (locked === "success") return "success";
|
||||
if (state.loading) return "busy";
|
||||
const focused = focusedControl();
|
||||
if (focused === "loginPassword" || focused === "loginPasswordConfirm") return "password";
|
||||
if (focused === "loginUsername") return "account";
|
||||
if (locked === "fail") return "fail";
|
||||
return "idle";
|
||||
}
|
||||
|
||||
function sync() {
|
||||
applyMood(desiredMood());
|
||||
}
|
||||
|
||||
function succeed() {
|
||||
locked = "success";
|
||||
applyMood("success");
|
||||
}
|
||||
|
||||
function fail() {
|
||||
locked = "fail";
|
||||
applyMood("fail");
|
||||
global.clearTimeout(failTimer);
|
||||
failTimer = global.setTimeout(() => {
|
||||
if (locked === "fail") locked = "";
|
||||
sync();
|
||||
}, 900);
|
||||
}
|
||||
|
||||
function blink() {
|
||||
if (!root || reducedMotion()) return;
|
||||
if (mood !== "idle" && mood !== "account" && mood !== "busy") return;
|
||||
root.classList.remove("is-blinking");
|
||||
void root.offsetWidth;
|
||||
root.classList.add("is-blinking");
|
||||
global.setTimeout(() => root.classList.remove("is-blinking"), 160);
|
||||
}
|
||||
|
||||
function scheduleBlink() {
|
||||
global.clearTimeout(blinkTimer);
|
||||
if (reducedMotion()) return;
|
||||
const waitMs = 4000 + Math.random() * 2000;
|
||||
blinkTimer = global.setTimeout(() => {
|
||||
blink();
|
||||
scheduleBlink();
|
||||
}, waitMs);
|
||||
}
|
||||
|
||||
function onMouseMove(event) {
|
||||
if (reducedMotion() || !finePointer()) return;
|
||||
if (desiredMood() !== "idle") return;
|
||||
const rect = root.getBoundingClientRect();
|
||||
const cx = rect.left + rect.width * 0.42;
|
||||
const cy = rect.top + rect.height * 0.42;
|
||||
const dx = event.clientX - cx;
|
||||
const dy = event.clientY - cy;
|
||||
const dist = Math.hypot(dx, dy) || 1;
|
||||
const cap = 3.5;
|
||||
motion.targetX = (dx / dist) * Math.min(cap, Math.abs(dx) / 90);
|
||||
motion.targetY = (dy / dist) * Math.min(cap, Math.abs(dy) / 90);
|
||||
const tilt = Math.max(-5, Math.min(5, (dx / Math.max(global.innerWidth, 1)) * 10));
|
||||
motion.targetLeanRed = tilt;
|
||||
motion.targetLeanGreen = tilt * 0.8;
|
||||
}
|
||||
|
||||
function tick() {
|
||||
if (!root) return;
|
||||
if (!reducedMotion()) {
|
||||
motion.pupilX += (motion.targetX - motion.pupilX) * 0.18;
|
||||
motion.pupilY += (motion.targetY - motion.pupilY) * 0.18;
|
||||
motion.leanRed += (motion.targetLeanRed - motion.leanRed) * 0.18;
|
||||
motion.leanGreen += (motion.targetLeanGreen - motion.leanGreen) * 0.18;
|
||||
setVars();
|
||||
} else {
|
||||
motion.pupilX = motion.targetX;
|
||||
motion.pupilY = motion.targetY;
|
||||
motion.leanRed = motion.targetLeanRed;
|
||||
motion.leanGreen = motion.targetLeanGreen;
|
||||
setVars();
|
||||
}
|
||||
raf = global.requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
function onFocusChange() {
|
||||
global.requestAnimationFrame(sync);
|
||||
}
|
||||
|
||||
if (root) {
|
||||
document.addEventListener("focusin", onFocusChange);
|
||||
document.addEventListener("focusout", onFocusChange);
|
||||
global.addEventListener("mousemove", onMouseMove, { passive: true });
|
||||
if (!reducedMotion()) {
|
||||
raf = global.requestAnimationFrame(tick);
|
||||
scheduleBlink();
|
||||
} else {
|
||||
poseFor("idle");
|
||||
setVars();
|
||||
}
|
||||
sync();
|
||||
}
|
||||
|
||||
return { sync, succeed, fail };
|
||||
})();
|
||||
|
||||
themeButton.addEventListener("click", () => {
|
||||
applyTheme(document.documentElement.dataset.theme === "dark" ? "light" : "dark", true);
|
||||
});
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
"/shared/table.js?v=20260803-1",
|
||||
"/shared/theme.js?v=20260803-1",
|
||||
"/shared/dashboard.js?v=20260820-1",
|
||||
"/shared/session.js?v=20260803-1",
|
||||
"/shared/session.js?v=20260829-hel243",
|
||||
"/shared/admin.js?v=20260803-1",
|
||||
"/app.js?v=20260803-2",
|
||||
];
|
||||
|
||||
+786
-67
File diff suppressed because it is too large
Load Diff
@@ -196,7 +196,13 @@ async function changeAccountPassword(event) {
|
||||
|
||||
async function switchAccount() {
|
||||
toggleAccountDropdown(false);
|
||||
window.location.assign("/login/");
|
||||
const params = new URLSearchParams();
|
||||
const next = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||
if (next.startsWith("/") && !next.startsWith("//") && next !== "/login" && !next.startsWith("/login/") && !next.startsWith("/login?")) {
|
||||
params.set("next", next);
|
||||
}
|
||||
const query = params.toString();
|
||||
window.location.assign("/login/" + (query ? `?${query}` : ""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,6 +147,31 @@
|
||||
--duration-fast: 150ms;
|
||||
--duration-normal: 220ms;
|
||||
--login-brand-gradient: linear-gradient(165deg, #0c1e4a, #16307c, #2153cc);
|
||||
--login-brand-share: 34%;
|
||||
--login-brand-min: 420px;
|
||||
--login-brand-cap: 560px;
|
||||
--login-brand-wide-share: 29.2%;
|
||||
--login-brand-pad: 36px 40px 24px;
|
||||
--login-brand-mark-size: 44px;
|
||||
--login-brand-name-size: 16px;
|
||||
--login-hero-size: 28px;
|
||||
--login-card-width: 408px;
|
||||
--login-card-pad: 32px;
|
||||
--login-card-title-size: 22px;
|
||||
--login-account-row-min: 72px;
|
||||
--login-account-avatar: 40px;
|
||||
--login-submit-height: 40px;
|
||||
--login-stat-chip-bg: rgba(8, 12, 24, 0.48);
|
||||
--login-candle-up: #e07078;
|
||||
--login-candle-down: #3db88a;
|
||||
--login-trend-line: rgba(244, 247, 255, 0.88);
|
||||
--login-mascot-red: #e8605a;
|
||||
--login-mascot-red-shade: #c74a45;
|
||||
--login-mascot-green: #46be93;
|
||||
--login-mascot-green-shade: #37997a;
|
||||
--login-mascot-eye: #f7f9fc;
|
||||
--login-mascot-pupil: #1a2440;
|
||||
--login-mascot-height: clamp(150px, 15vw, 260px);
|
||||
|
||||
--font-size-aux: 11.5px;
|
||||
--font-size-caption: 12.5px;
|
||||
@@ -516,6 +541,10 @@
|
||||
--warning-line-strong: #66502d;
|
||||
--control-shadow: 0 1px 3px rgba(0, 0, 0, .3);
|
||||
--login-brand-gradient: linear-gradient(165deg, #080c18, #0e1730, #14224a);
|
||||
--login-stat-chip-bg: rgba(6, 8, 16, 0.58);
|
||||
--login-candle-up: #f06d73;
|
||||
--login-candle-down: #43bc8a;
|
||||
--login-trend-line: rgba(232, 236, 244, 0.9);
|
||||
--dialog-backdrop: var(--backdrop);
|
||||
--ladder-level-1: #2d2426;
|
||||
--ladder-level-2: #2b2822;
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
const { test, expect } = require("@playwright/test");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const SHOT_DIR = path.resolve(__dirname, "../../../verify-shots");
|
||||
fs.mkdirSync(SHOT_DIR, { recursive: true });
|
||||
|
||||
function loginPayload(user) {
|
||||
return {
|
||||
@@ -54,6 +59,15 @@ async function mockLoginPortal(page, options = {}) {
|
||||
return;
|
||||
}
|
||||
if ((url.pathname === "/api/auth/login" || url.pathname === "/api/auth/register") && method === "POST") {
|
||||
if (options.loginDelay) await new Promise((resolve) => setTimeout(resolve, options.loginDelay));
|
||||
if (options.loginFails) {
|
||||
await route.fulfill({
|
||||
status: 401,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ error: "账号名或密码不正确,请重新输入。" }),
|
||||
});
|
||||
return;
|
||||
}
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
@@ -67,14 +81,58 @@ async function mockLoginPortal(page, options = {}) {
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/auth/me") {
|
||||
const current = accounts.find((item) => Number(item.user_id) === Number(currentUserId)) || null;
|
||||
const authenticated = Boolean(current) && !options.sessionExpired;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
ok: true,
|
||||
authenticated: Boolean(currentUserId),
|
||||
authenticated,
|
||||
csrf_token: "portal-csrf",
|
||||
user: accounts.find((item) => Number(item.user_id) === Number(currentUserId)) || null,
|
||||
user: authenticated ? {
|
||||
id: current.user_id,
|
||||
username: current.username,
|
||||
role: current.role,
|
||||
membership: current.membership,
|
||||
} : null,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/dashboard") {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
ok: true,
|
||||
meta: {
|
||||
trade_date: "2026-07-22",
|
||||
requested_date: "2026-07-22",
|
||||
source: "tushare",
|
||||
realtime: false,
|
||||
cached: true,
|
||||
market_status: "closed",
|
||||
updated_at: "2026-07-22T15:00:00+08:00",
|
||||
},
|
||||
overview: {
|
||||
up_count: 2100,
|
||||
down_count: 2800,
|
||||
limit_up_count: 42,
|
||||
limit_down_count: 8,
|
||||
broken_count: 17,
|
||||
seal_rate: 71.2,
|
||||
amount_billion: 12600,
|
||||
sentiment_score: 48,
|
||||
},
|
||||
limits: [],
|
||||
broken: [],
|
||||
down_limits: [],
|
||||
yesterday_limits: [],
|
||||
limit_performance: [],
|
||||
ladders: [],
|
||||
sectors: [],
|
||||
sector_rotation: [],
|
||||
}),
|
||||
});
|
||||
return;
|
||||
@@ -149,3 +207,350 @@ test("managing accounts removes a local record after inline confirmation", async
|
||||
await expect(page.locator(".login-account-row")).toHaveCount(1);
|
||||
await expect(page.locator(".login-account-row")).toContainText("alpha_user");
|
||||
});
|
||||
|
||||
async function assertConfirmedSkeleton(page, { width, height }) {
|
||||
await expect(page.locator(".login-brand-title")).toHaveText("看懂情绪周期,把复盘变成下一次的先手。");
|
||||
await expect(page.locator(".login-brand-header")).toBeVisible();
|
||||
await expect(page.locator(".login-brand-chart")).toBeVisible();
|
||||
await expect(page.locator(".login-brand-stats")).toBeVisible();
|
||||
await expect(page.locator(".login-brand-kicker")).toHaveText("收盘之后 · 复盘开始");
|
||||
const brand = await page.locator(".login-brand").boundingBox();
|
||||
const header = await page.locator(".login-brand-header").boundingBox();
|
||||
const mark = await page.locator(".login-brand-mark").boundingBox();
|
||||
const name = await page.locator(".login-brand-name").boundingBox();
|
||||
const title = await page.locator(".login-brand-title").boundingBox();
|
||||
const stats = await page.locator(".login-brand-stats").boundingBox();
|
||||
const chart = await page.locator(".login-brand-chart").boundingBox();
|
||||
const card = await page.locator(".login-card").boundingBox();
|
||||
expect(brand).toBeTruthy();
|
||||
expect(header.y - brand.y).toBeLessThan(48);
|
||||
expect(Math.abs(mark.y - name.y)).toBeLessThan(16);
|
||||
expect(title.y).toBeGreaterThan(height * 0.28);
|
||||
expect(title.y).toBeLessThan(height * 0.72);
|
||||
expect(stats.y).toBeGreaterThan(height * 0.55);
|
||||
expect(chart.height).toBeGreaterThan(80);
|
||||
await expect(page.locator("#loginMascots")).toBeVisible();
|
||||
expect(card.width).toBeGreaterThan(380);
|
||||
expect(card.width).toBeLessThan(450);
|
||||
if (width === 1440) {
|
||||
expect(brand.width).toBeGreaterThan(470);
|
||||
expect(brand.width).toBeLessThan(520);
|
||||
expect(brand.height).toBe(height);
|
||||
const mascots = await page.locator("#loginMascots").boundingBox();
|
||||
const kicker = await page.locator(".login-brand-kicker").boundingBox();
|
||||
expect(mascots).toBeTruthy();
|
||||
expect(kicker).toBeTruthy();
|
||||
expect(mascots.y).toBeGreaterThan(header.y + header.height - 4);
|
||||
expect(mascots.y + mascots.height).toBeLessThan(kicker.y + 8);
|
||||
const gapTop = header.y + header.height;
|
||||
const gapBottom = kicker.y;
|
||||
const mid = (gapTop + gapBottom) / 2;
|
||||
const mascotMid = mascots.y + mascots.height / 2;
|
||||
expect(Math.abs(mascotMid - mid)).toBeLessThan(48);
|
||||
expect(title.y).toBeGreaterThan(470);
|
||||
expect(title.y).toBeLessThan(580);
|
||||
} else if (width === 1920) {
|
||||
expect(brand.width).toBeGreaterThan(540);
|
||||
expect(brand.width).toBeLessThan(580);
|
||||
} else {
|
||||
expect(brand.width).toBeGreaterThan(560);
|
||||
}
|
||||
}
|
||||
|
||||
async function openPortal(page, { theme, width, height, accounts, currentUserId, loginFails, loginDelay }) {
|
||||
await page.addInitScript((nextTheme) => {
|
||||
localStorage.setItem("xiaobaiTheme", nextTheme);
|
||||
}, theme);
|
||||
await page.setViewportSize({ width, height });
|
||||
await mockLoginPortal(page, { accounts, currentUserId, loginFails, loginDelay });
|
||||
await page.goto("/login/");
|
||||
}
|
||||
|
||||
for (const theme of ["light", "dark"]) {
|
||||
for (const [width, height] of [[1440, 900], [1920, 1080]]) {
|
||||
test(`confirmed skeleton ${theme} ${width}x${height}`, async ({ page }) => {
|
||||
await openPortal(page, { theme, width, height, accounts: [] });
|
||||
await assertConfirmedSkeleton(page, { width, height });
|
||||
await expect(page.locator("#loginThemeToggle")).toHaveText(theme === "dark" ? "☀ 日间" : "🌙 夜间");
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, `first-${theme}-${width}.png`), fullPage: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test("ultrawide keeps the left brand from collapsing into a strip", async ({ page }) => {
|
||||
await openPortal(page, { theme: "dark", width: 2560, height: 1080, accounts: [] });
|
||||
await assertConfirmedSkeleton(page, { width: 2560, height: 1080 });
|
||||
});
|
||||
|
||||
test("picker add remove error and loading share the same desktop skeleton", async ({ page }) => {
|
||||
const accounts = SAVED_ACCOUNTS.map((item) => ({ ...item }));
|
||||
await openPortal(page, {
|
||||
theme: "dark",
|
||||
width: 1440,
|
||||
height: 900,
|
||||
accounts,
|
||||
currentUserId: 1,
|
||||
});
|
||||
await assertConfirmedSkeleton(page, { width: 1440, height: 900 });
|
||||
await expect(page.locator(".login-card-title")).toHaveText("选择账号");
|
||||
await expect(page.locator(".login-avatar")).toHaveCount(2);
|
||||
await expect(page.locator(".login-add")).toBeVisible();
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "picker-dark-1440.png"), fullPage: true });
|
||||
|
||||
await page.locator('[data-login-action="add"]').click();
|
||||
await expect(page.locator(".login-card-title")).toHaveText("添加账号");
|
||||
await assertConfirmedSkeleton(page, { width: 1440, height: 900 });
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "add-dark-1440.png"), fullPage: true });
|
||||
|
||||
await page.locator('[data-login-action="picker"]').click();
|
||||
await page.locator('[data-login-action="manage"]').click();
|
||||
await expect(page.locator(".login-card-title")).toHaveText("管理账号记录");
|
||||
await page.locator('[data-confirm-id="2"]').click();
|
||||
await expect(page.locator(".login-confirm-copy")).toContainText("beta_user");
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "remove-dark-1440.png"), fullPage: true });
|
||||
});
|
||||
|
||||
test("login failure and loading keep the confirmed first-login skeleton", async ({ page }) => {
|
||||
await openPortal(page, {
|
||||
theme: "light",
|
||||
width: 1440,
|
||||
height: 900,
|
||||
accounts: [],
|
||||
loginFails: true,
|
||||
});
|
||||
await page.locator("#loginUsername").fill("baiqizhi");
|
||||
await page.locator("#loginPassword").fill("wrong-password");
|
||||
await page.locator(".login-submit").click();
|
||||
await expect(page.locator(".login-error")).toContainText("账号名或密码不正确");
|
||||
await expect(page.locator("#loginPassword")).toHaveClass(/is-invalid/);
|
||||
await assertConfirmedSkeleton(page, { width: 1440, height: 900 });
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "error-light-1440.png"), fullPage: true });
|
||||
});
|
||||
|
||||
test("loading button appears on the confirmed first-login skeleton", async ({ page }) => {
|
||||
await openPortal(page, {
|
||||
theme: "dark",
|
||||
width: 1440,
|
||||
height: 900,
|
||||
accounts: [],
|
||||
loginDelay: 2500,
|
||||
});
|
||||
await page.evaluate(() => {
|
||||
window.location.replace = () => {};
|
||||
});
|
||||
await page.locator("#loginUsername").fill("baiqizhi");
|
||||
await page.locator("#loginPassword").fill("password12");
|
||||
const submit = page.locator(".login-submit").click();
|
||||
await expect(page.locator(".login-submit")).toContainText("正在登录...");
|
||||
await expect(page.locator(".login-spinner")).toBeVisible();
|
||||
await assertConfirmedSkeleton(page, { width: 1440, height: 900 });
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "loading-dark-1440.png"), fullPage: true });
|
||||
await submit;
|
||||
});
|
||||
|
||||
async function openPicker(page, options = {}) {
|
||||
const accounts = options.accounts || SAVED_ACCOUNTS.map((item) => ({ ...item }));
|
||||
const currentUserId = options.currentUserId ?? 1;
|
||||
const next = options.next || "/index.html?view=sentimentCycleView";
|
||||
await page.unroute("**/api/**").catch(() => {});
|
||||
await mockLoginPortal(page, {
|
||||
accounts,
|
||||
currentUserId,
|
||||
sessionExpired: options.sessionExpired,
|
||||
switchFails: options.switchFails,
|
||||
});
|
||||
await page.goto(`/login/?next=${encodeURIComponent(next)}`);
|
||||
await expect(page.locator(".login-card-title")).toHaveText("选择账号");
|
||||
}
|
||||
|
||||
test("clicking the current account from two workspace pages returns without switching", async ({ page }) => {
|
||||
const views = ["sentimentCycleView", "ladderView"];
|
||||
for (const viewId of views) {
|
||||
const next = `/index.html?view=${viewId}`;
|
||||
const switchCalls = [];
|
||||
const onRequest = (request) => {
|
||||
if (request.url().includes("/api/auth/switch") && request.method() === "POST") {
|
||||
switchCalls.push(request);
|
||||
}
|
||||
};
|
||||
page.on("request", onRequest);
|
||||
await openPicker(page, { next });
|
||||
await expect(page.locator('[data-resume-id="1"]')).toContainText("继续使用");
|
||||
await expect(page.locator('[data-resume-id="1"]')).toContainText("当前");
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page).toHaveURL(new RegExp(`[?&]view=${viewId}\\b`));
|
||||
expect(switchCalls).toEqual([]);
|
||||
page.off("request", onRequest);
|
||||
}
|
||||
});
|
||||
|
||||
test("a lone current account can return from the picker instead of dead-ending", async ({ page }) => {
|
||||
await openPicker(page, {
|
||||
accounts: [SAVED_ACCOUNTS[0]],
|
||||
currentUserId: 1,
|
||||
next: "/index.html?view=reviewWorkspaceView",
|
||||
});
|
||||
await expect(page.locator(".login-account-row")).toHaveCount(1);
|
||||
await expect(page.locator('[data-switch-id]')).toHaveCount(0);
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page).toHaveURL(/view=reviewWorkspaceView/);
|
||||
});
|
||||
|
||||
test("the return control also restores the originating workspace page", async ({ page }) => {
|
||||
await openPicker(page, { next: "/index.html?view=ladderView" });
|
||||
await page.locator('[data-login-action="resume"]').click();
|
||||
await expect(page).toHaveURL(/view=ladderView/);
|
||||
});
|
||||
|
||||
test("refreshing the picker still returns to the originating page", async ({ page }) => {
|
||||
await openPicker(page, { next: "/index.html?view=sentimentCycleView" });
|
||||
await page.reload();
|
||||
await expect(page.locator(".login-card-title")).toHaveText("选择账号");
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page).toHaveURL(/view=sentimentCycleView/);
|
||||
});
|
||||
|
||||
test("an expired current session asks for login instead of pretending to return", async ({ page }) => {
|
||||
await openPicker(page, {
|
||||
next: "/index.html?view=sentimentCycleView",
|
||||
sessionExpired: true,
|
||||
});
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page.locator(".login-error")).toHaveText("当前会话已失效,请重新登录");
|
||||
await expect(page).toHaveURL(/\/login\/?/);
|
||||
});
|
||||
|
||||
test("other saved accounts still switch while the current row only resumes", async ({ page }) => {
|
||||
await openPicker(page, { next: "/index.html?view=auctionView" });
|
||||
const switched = page.waitForRequest((request) => (
|
||||
request.url().includes("/api/auth/switch") && request.method() === "POST"
|
||||
));
|
||||
await page.locator('[data-switch-id="2"]').click();
|
||||
const request = await switched;
|
||||
expect(JSON.parse(request.postData() || "{}")).toEqual({ user_id: 2 });
|
||||
});
|
||||
|
||||
test("workspace switch-account menu carries the current page back to the picker", async ({ page }) => {
|
||||
await mockLoginPortal(page, {
|
||||
accounts: SAVED_ACCOUNTS.map((item) => ({ ...item })),
|
||||
currentUserId: 1,
|
||||
});
|
||||
await page.goto("/index.html?view=sentimentCycleView");
|
||||
await expect(page.locator("#accountButton")).toBeVisible();
|
||||
await page.locator("#accountButton").click();
|
||||
await page.locator("#switchAccountMenuButton").click();
|
||||
await expect(page).toHaveURL(/\/login\/\?next=/);
|
||||
await expect(page.locator(".login-card-title")).toHaveText("选择账号");
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page).toHaveURL(/view=sentimentCycleView/);
|
||||
});
|
||||
|
||||
test("workspace switch-account from a second page also returns to that page", async ({ page }) => {
|
||||
await mockLoginPortal(page, {
|
||||
accounts: SAVED_ACCOUNTS.map((item) => ({ ...item })),
|
||||
currentUserId: 1,
|
||||
});
|
||||
await page.goto("/index.html?view=ladderView");
|
||||
await expect(page.locator("#accountButton")).toBeVisible();
|
||||
await page.locator("#accountButton").click();
|
||||
await page.locator("#switchAccountMenuButton").click();
|
||||
await expect(page.locator(".login-card-title")).toHaveText("选择账号");
|
||||
await page.locator('[data-resume-id="1"]').click();
|
||||
await expect(page).toHaveURL(/view=ladderView/);
|
||||
});
|
||||
|
||||
test("desktop mascots react to account focus, password, toggle, loading, success and failure", async ({ page }) => {
|
||||
await openPortal(page, { theme: "light", width: 1440, height: 900, accounts: [] });
|
||||
const mascots = page.locator("#loginMascots");
|
||||
await expect(mascots).toHaveAttribute("data-mood", "idle");
|
||||
await page.locator("#loginUsername").focus();
|
||||
await expect(mascots).toHaveAttribute("data-mood", "account");
|
||||
await page.locator("#loginPassword").focus();
|
||||
await expect(mascots).toHaveAttribute("data-mood", "password");
|
||||
await expect.poll(async () => (
|
||||
page.locator(".login-mascot.is-red .login-mascot-hand.is-left").evaluate((node) => getComputedStyle(node).opacity)
|
||||
)).toBe("1");
|
||||
await page.locator(".login-password-toggle").click();
|
||||
await expect(page.locator("#loginPassword")).toHaveAttribute("type", "text");
|
||||
await expect(mascots).toHaveAttribute("data-mood", "password");
|
||||
await page.locator(".login-password-toggle").click();
|
||||
await expect(page.locator("#loginPassword")).toHaveAttribute("type", "password");
|
||||
await expect(mascots).toHaveAttribute("data-mood", "password");
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "mascots-password-light-1440.png"), fullPage: true });
|
||||
});
|
||||
|
||||
test("login loading and failure drive short mascot feedback", async ({ page }) => {
|
||||
await openPortal(page, {
|
||||
theme: "dark",
|
||||
width: 1440,
|
||||
height: 900,
|
||||
accounts: [],
|
||||
loginFails: true,
|
||||
loginDelay: 800,
|
||||
});
|
||||
await page.locator("#loginUsername").fill("baiqizhi");
|
||||
await page.locator("#loginPassword").fill("wrong-password");
|
||||
const submit = page.locator(".login-submit").click();
|
||||
await expect(page.locator("#loginMascots")).toHaveAttribute("data-mood", "busy");
|
||||
await expect(page.locator(".login-error")).toContainText("账号名或密码不正确");
|
||||
await expect(page.locator("#loginMascots")).toHaveAttribute("data-mood", "fail");
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "mascots-fail-dark-1440.png"), fullPage: true });
|
||||
await submit;
|
||||
});
|
||||
|
||||
test("login success plays a hop before leaving the portal", async ({ page }) => {
|
||||
await openPortal(page, { theme: "light", width: 1440, height: 900, accounts: [] });
|
||||
await page.evaluate(() => {
|
||||
window.location.replace = () => {};
|
||||
});
|
||||
await page.locator("#loginUsername").fill("baiqizhi");
|
||||
await page.locator("#loginPassword").fill("password12");
|
||||
const submit = page.locator(".login-submit").click();
|
||||
await expect(page.locator("#loginMascots")).toHaveAttribute("data-mood", /busy|success/);
|
||||
await expect(page.locator("#loginMascots")).toHaveAttribute("data-mood", "success", { timeout: 4000 });
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "mascots-success-light-1440.png"), fullPage: true });
|
||||
await submit;
|
||||
});
|
||||
|
||||
test("reduced motion keeps static mascots without mouse tracking", async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await openPortal(page, { theme: "dark", width: 1440, height: 900, accounts: [] });
|
||||
const mascots = page.locator("#loginMascots");
|
||||
await expect(mascots).toBeVisible();
|
||||
await expect(mascots).toHaveAttribute("data-mood", "idle");
|
||||
const before = await mascots.evaluate((node) => getComputedStyle(node.querySelector(".login-mascot.is-red")).getPropertyValue("--pupil-x"));
|
||||
await page.mouse.move(1200, 120);
|
||||
await page.waitForTimeout(120);
|
||||
const after = await mascots.evaluate((node) => getComputedStyle(node.querySelector(".login-mascot.is-red")).getPropertyValue("--pupil-x"));
|
||||
expect(after).toBe(before);
|
||||
await page.locator("#loginPassword").focus();
|
||||
await expect(mascots).toHaveAttribute("data-mood", "password");
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "mascots-reduced-dark-1440.png"), fullPage: true });
|
||||
});
|
||||
|
||||
test("mouse follow updates mascot pupils on a fine pointer", async ({ page }) => {
|
||||
await openPortal(page, { theme: "light", width: 1440, height: 900, accounts: [] });
|
||||
const mascots = page.locator("#loginMascots");
|
||||
await page.mouse.move(80, 160);
|
||||
await page.waitForTimeout(180);
|
||||
const left = await mascots.evaluate((node) => getComputedStyle(node.querySelector(".login-mascot.is-red")).getPropertyValue("--pupil-x"));
|
||||
await page.mouse.move(1280, 200);
|
||||
await page.waitForTimeout(180);
|
||||
const right = await mascots.evaluate((node) => getComputedStyle(node.querySelector(".login-mascot.is-red")).getPropertyValue("--pupil-x"));
|
||||
expect(Number.parseFloat(right)).toBeGreaterThan(Number.parseFloat(left));
|
||||
});
|
||||
|
||||
test("narrow screens hide mascots without moving the login card", async ({ page }) => {
|
||||
await openPortal(page, { theme: "light", width: 800, height: 900, accounts: [] });
|
||||
await expect(page.locator("#loginMascots")).toBeHidden();
|
||||
await expect(page.locator(".login-card-title")).toHaveText("欢迎回来");
|
||||
await expect(page.locator(".login-brand-title")).toBeHidden();
|
||||
});
|
||||
|
||||
test("theme toggle keeps mascots in the brand gap", async ({ page }) => {
|
||||
await openPortal(page, { theme: "light", width: 1440, height: 900, accounts: [] });
|
||||
await page.locator("#loginThemeToggle").click();
|
||||
await expect(page.locator("html")).toHaveAttribute("data-theme", "dark");
|
||||
await assertConfirmedSkeleton(page, { width: 1440, height: 900 });
|
||||
await page.screenshot({ path: path.join(SHOT_DIR, "mascots-idle-dark-1440.png"), fullPage: true });
|
||||
});
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
LOGIN = (ROOT / "frontend" / "login" / "index.html").read_text(encoding="utf-8")
|
||||
LOGIN_JS = (ROOT / "frontend" / "login" / "page.js").read_text(encoding="utf-8")
|
||||
AUTH = (ROOT / "frontend" / "shared" / "auth.css").read_text(encoding="utf-8")
|
||||
TOKENS = (ROOT / "frontend" / "shared" / "tokens.css").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
class LoginPortalContractTests(unittest.TestCase):
|
||||
def test_confirmed_brand_skeleton_is_in_markup(self) -> None:
|
||||
for needle in (
|
||||
'class="login-brand-header"',
|
||||
'class="login-brand-name"',
|
||||
"A股个人复盘工作台",
|
||||
'class="login-brand-kicker"',
|
||||
"看懂情绪周期,把复盘变成下一次的先手。",
|
||||
'class="login-brand-chart"',
|
||||
'class="login-brand-stats"',
|
||||
"股市有风险,投资需谨慎",
|
||||
'id="loginThemeToggle"',
|
||||
'id="loginCard"',
|
||||
):
|
||||
self.assertIn(needle, LOGIN)
|
||||
|
||||
def test_login_tokens_own_the_confirmed_layout_metrics(self) -> None:
|
||||
for needle in (
|
||||
"--login-brand-share: 34%;",
|
||||
"--login-brand-cap: 560px;",
|
||||
"--login-brand-wide-share: 29.2%;",
|
||||
"--login-card-width: 408px;",
|
||||
"--login-hero-size: 28px;",
|
||||
"--login-account-row-min: 72px;",
|
||||
):
|
||||
self.assertIn(needle, TOKENS)
|
||||
self.assertIn("width: var(--login-brand-share);", AUTH)
|
||||
self.assertIn("width: var(--login-card-width);", AUTH)
|
||||
self.assertIn("justify-content: flex-end;", AUTH)
|
||||
self.assertIn("body.login-portal {", AUTH)
|
||||
self.assertIn("padding-bottom: 0;", AUTH)
|
||||
self.assertNotIn("padding: 0 0 var(--statusbar-height);", AUTH)
|
||||
|
||||
def test_confirmed_mascots_fill_the_brand_gap(self) -> None:
|
||||
for needle in (
|
||||
'id="loginMascots"',
|
||||
'aria-hidden="true"',
|
||||
'class="login-mascot is-red"',
|
||||
'class="login-mascot is-green"',
|
||||
'class="login-mascot-back"',
|
||||
'class="login-mascot-slit"',
|
||||
):
|
||||
self.assertIn(needle, LOGIN)
|
||||
for needle in (
|
||||
"--login-mascot-red: #e8605a;",
|
||||
"--login-mascot-green: #46be93;",
|
||||
"--login-mascot-height: clamp(150px, 15vw, 260px);",
|
||||
):
|
||||
self.assertIn(needle, TOKENS)
|
||||
self.assertIn("flex: 1 1 auto;", AUTH)
|
||||
self.assertIn(".login-mascots {", AUTH)
|
||||
self.assertIn("prefers-reduced-motion: reduce", AUTH)
|
||||
self.assertIn('next === "password"', LOGIN_JS)
|
||||
self.assertIn("toggle-password", LOGIN_JS)
|
||||
self.assertIn("celebrateLogin", LOGIN_JS)
|
||||
|
||||
def test_portal_keeps_account_switch_and_theme_hooks(self) -> None:
|
||||
self.assertIn("data-switch-id", LOGIN_JS)
|
||||
self.assertIn("data-resume-id", LOGIN_JS)
|
||||
self.assertIn('data-login-action="manage"', LOGIN_JS)
|
||||
self.assertIn('data-login-action="add"', LOGIN_JS)
|
||||
self.assertIn('data-login-action="resume"', LOGIN_JS)
|
||||
self.assertIn("继续使用", LOGIN_JS)
|
||||
self.assertIn("返回复盘", LOGIN_JS)
|
||||
self.assertIn("/api/auth/me", LOGIN_JS)
|
||||
self.assertIn("xiaobaiTheme", LOGIN_JS)
|
||||
self.assertNotIn("内网个人版", LOGIN)
|
||||
self.assertNotIn("192.168.200.11", LOGIN)
|
||||
self.assertNotIn("/api/heaven", LOGIN_JS)
|
||||
|
||||
def test_current_account_row_stays_clickable_without_reswitching(self) -> None:
|
||||
self.assertIn("resumeCurrentAccount", LOGIN_JS)
|
||||
self.assertIn("当前会话已失效,请重新登录", LOGIN_JS)
|
||||
self.assertNotIn("!managing && !current ? \"is-switchable\"", LOGIN_JS)
|
||||
session = (ROOT / "frontend" / "shared" / "session.js").read_text(encoding="utf-8")
|
||||
self.assertIn('params.set("next", next)', session)
|
||||
self.assertIn(".login-account-action", AUTH)
|
||||
+11
-5
@@ -20,12 +20,18 @@ registry, and verification tools.
|
||||
- `python tools/backfill_recent_snapshots.py --account <admin> [--lookback 60] [--dry-run]`:
|
||||
auditable recent trading-day dashboard snapshot backfill. See
|
||||
`docs/maintenance/行情历史补档.md`.
|
||||
- `bash tools/build_image.sh <commit> <tag>`: the only sanctioned way to build the
|
||||
production Docker image. Streams `git archive <commit>` to the deploy host over SSH
|
||||
(default `moxiaobai@192.168.200.11`), refuses tags that do not end with the commit
|
||||
- `tools/update_from_main.sh` (deployed to the server as
|
||||
`~/xiaobai-build/update-from-main.sh`): the server-side update-and-build entry for
|
||||
the managed local worktree at `/opt/1panel/docker/compose/xiaobaifupan`. Fetches
|
||||
Gitea `main`, enforces branch/clean/fast-forward checks, builds a
|
||||
`main-<shortsha>` tagged image with the revision label, and verifies the label
|
||||
after the build. `tools/xiaobai-git` is the matching git wrapper for that
|
||||
worktree (`status`/`log`/`diff`).
|
||||
- `bash tools/build_image.sh <commit> <tag>`: agent-grade entry that streams
|
||||
`git archive <commit>` to the deploy host over SSH (default
|
||||
`moxiaobai@192.168.200.11`), refuses tags that do not end with the commit
|
||||
short SHA, verifies the revision label after the build, and appends a record to
|
||||
`~/xiaobai-build/BUILD_LOG.tsv` on the host. Building from any server-side working
|
||||
tree is forbidden; see `DOCKER_DEPLOY.md`. Before building, it runs
|
||||
`~/xiaobai-build/BUILD_LOG.tsv` on the host. Before building, it runs
|
||||
`tools/check_deploy_baseline.sh` so the candidate commit must contain the currently
|
||||
running container's Git revision as an ancestor.
|
||||
- `bash tools/check_deploy_baseline.sh <commit> [--live-revision <sha>]`: deployment
|
||||
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
# 小白复盘服务器本地目录安全更新/构建入口(HEL-235B 固化)
|
||||
# 作用:把 /opt/1panel/docker/compose/xiaobaifupan 的 Git 工作目录安全快进到 Gitea main,
|
||||
# 校验“本地 HEAD = origin/main = 镜像 revision”后,从本地目录构建带提交号的镜像。
|
||||
# 禁止:不从 main 构建;不使用不带提交短号的 tag;本地有改动/落后/分叉时一律停止。
|
||||
# 说明:目录顶层归 root,本脚本用“截断写入”绕开 git 对顶层文件 unlink+重建的权限要求;
|
||||
# 但 main 新增/删除顶层文件时无法自动处理,会列出需管理员执行的精确清单。
|
||||
set -euo pipefail
|
||||
|
||||
GIT_DIR_PATH="$HOME/xiaobai-build/repos/xiaobai-review.git"
|
||||
WORK_TREE="/opt/1panel/docker/compose/xiaobaifupan"
|
||||
IMAGE_REPO="xiaobai-review"
|
||||
LOG_FILE="$HOME/xiaobai-build/BUILD_LOG.tsv"
|
||||
MODE="${1:-build}"
|
||||
|
||||
g() { git --git-dir="$GIT_DIR_PATH" --work-tree="$WORK_TREE" "$@"; }
|
||||
|
||||
refuse() { printf '拒绝:%s\n' "$*" >&2; exit 1; }
|
||||
|
||||
[ "$MODE" = "build" ] || [ "$MODE" = "verify-tag" ] || refuse "未知子命令「${MODE}」(可用:build / verify-tag <tag>)"
|
||||
[ -d "$GIT_DIR_PATH" ] || refuse "Git 目录不存在:$GIT_DIR_PATH"
|
||||
|
||||
echo "==> 拉取 Gitea origin/main"
|
||||
g fetch --quiet origin main || refuse "无法连接 Gitea 拉取 origin/main"
|
||||
|
||||
echo "==> 检查分支与工作区"
|
||||
BRANCH="$(g symbolic-ref --short HEAD 2>/dev/null || true)"
|
||||
[ "$BRANCH" = "main" ] || refuse "当前不在 main 分支(${BRANCH:-detached}),停止"
|
||||
DIRTY="$(g status --porcelain)"
|
||||
[ -z "$DIRTY" ] || refuse "本地目录有未提交改动或多余文件,先处理再构建:
|
||||
$DIRTY"
|
||||
|
||||
LOCAL_HEAD="$(g rev-parse HEAD)"
|
||||
REMOTE_HEAD="$(g rev-parse origin/main)"
|
||||
if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then
|
||||
g merge-base --is-ancestor "$LOCAL_HEAD" "$REMOTE_HEAD" \
|
||||
|| refuse "本地 main 与 origin/main 历史分叉,停止(未改写工作目录)"
|
||||
CHANGES="$(g diff --no-renames --name-status HEAD origin/main)"
|
||||
TOP_AD="$(printf '%s\n' "$CHANGES" | grep -E "^[AD][[:space:]]+[^/]+$" || true)"
|
||||
[ -z "$TOP_AD" ] || refuse "main 相比本地新增/删除了顶层文件,目录顶层归 root,需管理员执行:
|
||||
$TOP_AD"
|
||||
echo "==> 同步 origin/main 文件(顶层文件保留原 inode,避免目录权限限制)"
|
||||
while IFS=$'\t' read -r status path; do
|
||||
[ -n "$path" ] || continue
|
||||
case "$status" in
|
||||
D)
|
||||
case "$path" in
|
||||
*/*) rm -f -- "$WORK_TREE/$path" ;;
|
||||
*) refuse "main 删除了顶层文件 $path,需管理员处理" ;;
|
||||
esac
|
||||
;;
|
||||
A|M)
|
||||
MODE_BITS="$(g ls-tree origin/main -- "$path" | awk '{print $1}')"
|
||||
case "$MODE_BITS" in
|
||||
100644|100755) ;;
|
||||
*) refuse "文件 ${path} 的 Git 类型 ${MODE_BITS} 不支持自动同步,需管理员处理" ;;
|
||||
esac
|
||||
mkdir -p -- "$(dirname "$WORK_TREE/$path")"
|
||||
g show "origin/main:$path" > "$WORK_TREE/$path"
|
||||
[ "$MODE_BITS" = "100755" ] && chmod 755 "$WORK_TREE/$path" || chmod 644 "$WORK_TREE/$path"
|
||||
;;
|
||||
*) refuse "遇到未支持的 Git 变更类型 ${status}:${path}" ;;
|
||||
esac
|
||||
done <<< "$CHANGES"
|
||||
g read-tree origin/main
|
||||
g update-ref refs/heads/main "$REMOTE_HEAD" "$LOCAL_HEAD"
|
||||
DIRTY="$(g status --porcelain)"
|
||||
[ -z "$DIRTY" ] || refuse "快进后工作区仍不一致,停止:
|
||||
$DIRTY"
|
||||
LOCAL_HEAD="$(g rev-parse HEAD)"
|
||||
fi
|
||||
[ "$LOCAL_HEAD" = "$REMOTE_HEAD" ] || refuse "本地 HEAD 与 origin/main 不一致,停止"
|
||||
SHORT="${LOCAL_HEAD:0:7}"
|
||||
echo "==> 校验通过:本地 HEAD = origin/main = ${LOCAL_HEAD}(${SHORT})"
|
||||
|
||||
if [ "$MODE" = "verify-tag" ]; then
|
||||
TAG="${2:?用法: update-from-main.sh verify-tag <tag>}"
|
||||
[ "$TAG" = "main-${SHORT}" ] \
|
||||
|| refuse "镜像标签必须是当前 main 对应的 main-${SHORT},收到:${TAG}"
|
||||
LABEL="$(docker image inspect "${IMAGE_REPO}:${TAG}" \
|
||||
--format '{{index .Config.Labels "org.opencontainers.image.revision"}}' 2>/dev/null)" \
|
||||
|| refuse "镜像 ${IMAGE_REPO}:${TAG} 不存在"
|
||||
[ "$LABEL" = "$LOCAL_HEAD" ] || refuse "镜像 revision(${LABEL})与当前 main(${LOCAL_HEAD})不一致,禁止部署"
|
||||
echo "==> 通过:${IMAGE_REPO}:${TAG} 的 revision 与 main 一致,可以部署"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TAG="main-${SHORT}"
|
||||
echo "==> 从本地目录构建 ${IMAGE_REPO}:${TAG}"
|
||||
docker build --rm -t "${IMAGE_REPO}:${TAG}" \
|
||||
--label "org.opencontainers.image.revision=${LOCAL_HEAD}" \
|
||||
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
"$WORK_TREE" 2>&1 | tail -5
|
||||
|
||||
echo "==> 回读校验镜像 revision"
|
||||
GOT="$(docker image inspect "${IMAGE_REPO}:${TAG}" \
|
||||
--format '{{index .Config.Labels "org.opencontainers.image.revision"}}')"
|
||||
if [ "$GOT" != "$LOCAL_HEAD" ]; then
|
||||
docker rmi "${IMAGE_REPO}:${TAG}" >/dev/null 2>&1 || true
|
||||
refuse "镜像 revision(${GOT})与 main(${LOCAL_HEAD})不一致,已删除镜像"
|
||||
fi
|
||||
IMAGE_ID="$(docker image inspect "${IMAGE_REPO}:${TAG}" --format '{{.Id}}' | cut -c8-19)"
|
||||
mkdir -p "$(dirname "$LOG_FILE")"
|
||||
printf '%s\t%s\t%s\t%s\tlocal-worktree\n' \
|
||||
"$(date '+%F %T')" "${IMAGE_REPO}:${TAG}" "${LOCAL_HEAD}" "${IMAGE_ID}" >> "$LOG_FILE"
|
||||
|
||||
cat <<EOF
|
||||
==> 完成:${IMAGE_REPO}:${TAG}(revision=${LOCAL_HEAD})
|
||||
部署需人工确认,参考 ~/xiaobai-build/README.md 的换版与回滚步骤。
|
||||
EOF
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# 查看服务器本地目录 Git 状态的便捷入口:xiaobai-git status / log / diff 等
|
||||
exec git \
|
||||
--git-dir="$HOME/xiaobai-build/repos/xiaobai-review.git" \
|
||||
--work-tree="/opt/1panel/docker/compose/xiaobaifupan" \
|
||||
"$@"
|
||||
Reference in New Issue
Block a user