Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48aac171dd | |||
| 0b7c1cba24 | |||
| 643f1b76b8 | |||
| 4c35e50270 | |||
| 3e78e79971 | |||
| 41bf7d8bae | |||
| c93acad3d9 | |||
| c406f8c127 | |||
| 0cd7ed078e | |||
| df7b9a0cb3 |
@@ -46,7 +46,11 @@ http://localhost:8848/
|
||||
## 目录说明
|
||||
|
||||
```text
|
||||
|
||||
.
|
||||
├── docs/experiments/ # 教程README、共享内容、原始截图与标注坐标
|
||||
├── public/guides/experiments/ # 可放大的编号箭头SVG截图
|
||||
├── scripts/build-experiment-guide.mjs # 生成与核对图文教程
|
||||
├── .agents/ # 当前项目 Agent skill 索引与中文提交、注释同步规则
|
||||
├── .codex/skills/ # 旧版仓库内协作 skill,保留 README 同步规则
|
||||
├── .husky/ # Git hooks,提交前执行 lint-staged,提交信息走 commitlint
|
||||
@@ -213,7 +217,7 @@ pnpm build
|
||||
- `src/views/digital/content.vue`:角色卡、世界书、预设,草稿/发布/下架,JSON 导入导出。
|
||||
- `src/views/digital/experiments.vue`:测试方案的类型选择、A/B 返回值、百分比、人群、生命周期、效果和审计。
|
||||
- `src/views/digital/experiment-types.vue`:类型创建、默认值契约、来源、调用示例与接入验收。
|
||||
- `src/views/digital/experiment-users.vue`:按方案分页搜索真实账号、分组预览、人工指定和恢复自动。
|
||||
- `src/views/digital/experiment-users.vue`:按方案搜索真实账号,区分预计分组、实际入组和手动指定,保留有效期并解释目标人群限制。
|
||||
- `src/views/digital/experiment-value.vue`:开关/数字/字符串/JSON 类型编辑器。
|
||||
- `src/router/modules/digital.ts`:数字人菜单,只有超级管理员可见;接口仍集中在 `src/api/access.ts`,后端独立验证权限。
|
||||
- 保留既有员工管理模块和数据。沿用原 Vite 构建、域名与 Jenkins 发布。
|
||||
@@ -222,8 +226,30 @@ pnpm build
|
||||
|
||||
标签页图标采用 `public/stellar-icon-v2.svg`,同时提供多尺寸 `favicon.ico`、180/192/512 PNG,覆盖浏览器、Apple 主屏幕和 PWA。版本化资源路径用于刷新旧图标缓存。
|
||||
|
||||
「实验类型」「测试方案」「用户管理」是独立菜单。新类型填写自己的稳定标识与数据契约,先接入应用、收到实际调用并人工确认验收,再启动方案;未接入类型可存草稿。UI/对话是标注来源的已接入类型;不再使用固定业务功能的场景下拉框。方案行可直接跳转该方案的用户管理,用户预览不写分组、不记曝光,人工指定有原因、时效和审计。前台只消费决策。
|
||||
「实验类型」「测试方案」「实验用户分组」是独立菜单。新类型填写自己的稳定标识与数据契约,先接入应用、收到实际调用并人工确认验收,再启动方案;未接入类型可存草稿。系统不预置 UI/对话类型;自建类型需要真实前台接入,不再使用固定业务功能的场景下拉框。方案行可直接跳转该方案的用户管理,用户预览不写分组、不记曝光,人工指定有原因、时效和审计。前台只消费决策。
|
||||
|
||||
比例统一按百分比输入,50代表50%,保留0.01%精度;既有用户分组保持不变。
|
||||
|
||||
后台统一隐藏原生及 Element Plus 自绘内部滚动条;表格、弹窗、抽屉和下拉选项仍支持触摸、鼠标和键盘滚动。叙事预设编辑与后端预算、下架回退及方案快照行为保持一致。
|
||||
|
||||
实验方案分组支持 A~Z(最多26组),每组自行设置返回值和比例,合计必须100%。两组比例自动互补,多组显示总和并支持平均分配、补足剩余;0%组保留配置供人工验收。不再提供默认方案选择,未入组及暂停时使用类型默认返回值。用户管理按当前方案动态展示可指定的组,结束实验也可选择任意已配置组。
|
||||
|
||||
## 实验图文操作指南
|
||||
|
||||
测试方案页的「操作指南」进入二级页面 `/digital/experiments/guide`(`src/views/digital/experiment-guide.vue`),不再弹出简短说明。页面有章节目录、14张可放大的编号箭头截图和返回业务入口,覆盖类型创建、应用接入验收、仅自己验收、分组算法、启动、人工指定、正式分流、效果审计、暂停恢复及结束保留组。
|
||||
|
||||
项目内教程见 [完整实验教程](docs/experiments/README.md)。内容源为 `docs/experiments/guide.json`,网页直接读取同一文件;`screenshots.json` 保存标注坐标,原图只含隔离演示账号与状态。图中演示调用和统计不代表真实生产验收。
|
||||
|
||||
- 更新图文内容或截图后:`node scripts/build-experiment-guide.mjs`。
|
||||
- 发布前验证文档、标注与源码一致:`node scripts/build-experiment-guide.mjs --check`。
|
||||
- 原始截图及标注后的SVG都纳入版本管理,维护时保留“隔离演示”说明,不能用伪造回执替代真实接入。
|
||||
|
||||
用户分组管理提供独立的方案概况、用户查找和指定入口。列表覆盖全部真实账号,不把只读预计结果称为实际入组;手动指定明确显示草稿待生效、人群不符、已过期等状态。不符合目标人群的账号须明确选择“作为测试账号加入”,不修改其他用户的人群范围。取消指定或到期后沿用原自动分组,否则按当前方案规则计算。
|
||||
|
||||
教程目录固定在阅读区左侧,右侧正文独立滚动并自动高亮当前章节;点击目录平滑定位,目录过长时会自动滚动到当前项。窄屏将目录置于正文上方,保留正文滚动与章节同步。
|
||||
|
||||
### C 端用户管理
|
||||
|
||||
`src/views/digital/users.vue` 对应 `/digital/users`,用于创建独立 C 端账号、搜索用户、修改昵称/状态、重置密码,以及按用户查看数字人会话和原始消息。账号由后台开通,无公开注册;与管理员/员工账号分别鉴权,重置 C 端密码不影响后台。停用保留聊天记录。
|
||||
|
||||
`src/api/access.ts` 定义 C 端用户、会话和消息响应类型。消息记录第1页为最新内容,每页按发送顺序展示,支持刷新、分页和生成状态查看。原实验账号页面 `/digital/experiment-users` 更名为「实验用户分组」,只针对 C 端用户配置实验。
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
# 实验完整操作教程
|
||||
|
||||
从创建类型到结束实验,按顺序走一遍。建议第一次先只选自己的测试账号,验证真实应用效果后再扩大流量。
|
||||
|
||||
更新时间:2026-10-27
|
||||
|
||||
> 截图由仓库实际页面组件在隔离演示环境拍摄。红色箭头和编号为操作标注;演示调用、账号和统计不是生产验收证据。
|
||||
|
||||
## 目录
|
||||
|
||||
- 先分清三个概念
|
||||
- 1. 创建自己的实验类型
|
||||
- 2. 接入应用并完成业务验收
|
||||
- 3. 先建“仅自己验收”的测试方案
|
||||
- 4. 用户究竟如何被分组
|
||||
- 5. 启动验收方案
|
||||
- 6. 查看账号分组,指定 A/B 做对照
|
||||
- 7. 验收完成后,另建正式分流方案
|
||||
- 8. 查看效果与审计
|
||||
- 9. 暂停与恢复
|
||||
- 10. 结束并保留最终结果
|
||||
- 完成前再核对一次
|
||||
|
||||
## 先分清三个概念
|
||||
|
||||
类型定义测什么,测试方案定义怎么测,分组定义每种返回结果。
|
||||
|
||||
- 实验类型:例如“新老 UI(教程)”,稳定标识 tutorial_ui,返回格式为开关,默认值 false。名称不会自动接入任何功能。
|
||||
- 测试方案:一次有明确目标、人群、流量和生命周期的实验。相同类型可以先做仅自己验收,再结束验收方案、另建正式实验。
|
||||
- 分组:方案内的 A~Z 组。每组有比例和返回值,合计100%;false / true 只是教程示例,实际含义由应用代码决定。
|
||||
- 本文使用隔离演示数据拍摄实际页面组件,标注编号对应下方操作;演示调用与统计不代表你的类型已经接入或线上实验已验收。
|
||||
|
||||
## 1. 创建自己的实验类型
|
||||
|
||||
进入“实验类型”,点击“创建实验类型”。
|
||||
|
||||

|
||||
|
||||
1. 填写稳定标识;名称用于辨认,标识才是应用读取决策的依据。
|
||||
2. 选择返回值格式,本例为开关;下面的默认值使用 false。
|
||||
3. 启用类型后保存;保存成功仍须完成真实应用接入。
|
||||
|
||||
- 填写名称与稳定标识。本例 tutorial_ui 只是演示,不要照抄成已有业务的标识;标识创建后不可改。
|
||||
- 选择“开关(是/否)”,默认返回值设为关闭 false;在应用中约定 false 为旧 UI、true 为新 UI。
|
||||
- 保持“启用类型”开启并保存。启用只表示允许这一类型参与决策,不会直接开启新 UI。
|
||||
- 保存后应看到“待应用调用”。这是正常状态;此时可以保存草稿,不能启动实验。
|
||||
|
||||
## 2. 接入应用并完成业务验收
|
||||
|
||||
在类型所在行点击“接入与验收”,先让真实功能读取并使用返回值。
|
||||
|
||||

|
||||
|
||||
1. 核对要接入的稳定标识,避免读错类型。
|
||||
2. 按调用说明接入,让真实功能使用接口返回的 value。
|
||||
3. 收到调用并验证实际功能后,勾选确认、填写记录,再确认接入验收。
|
||||
|
||||
- 将类型标识、数据格式、默认值和目标功能交给负责应用接入的人。后台只能配置,不能替客户端实现界面切换。
|
||||
- 应用以当前用户的已登录身份调用决策接口,读取 value,并将 false / true 实际用于切换旧 / 新 UI。只请求接口并不等于功能已经消费返回值。
|
||||
- 在实际页面检查结果,返回后台点击“刷新调用状态”;收到当前契约的调用后,勾选真实验证并填写至少8字的验收记录,再点“确认接入验收”。
|
||||
- 应看到“已确认接入”。没有调用时按钮不可用,不应伪造回执。截图中的状态来自隔离演示,不是对线上接入的证明。
|
||||
|
||||
```text
|
||||
GET /api/digital/decisions/tutorial_ui
|
||||
Authorization: Bearer <当前用户的访问令牌>
|
||||
|
||||
// 应用接入示意:使用自己的请求封装和实际界面切换方法。
|
||||
const decision = await readDecision("tutorial_ui");
|
||||
applyUiVersion(decision.value === true ? "new" : "old");
|
||||
```
|
||||
|
||||
## 3. 先建“仅自己验收”的测试方案
|
||||
|
||||
回到“测试方案”,创建草稿,先用自己的真实测试账号验证。
|
||||
|
||||

|
||||
|
||||
1. 命名本次“仅自己验收”的方案,并选择正确类型。
|
||||
2. 入组范围选指定名单,只选择自己的测试账号。
|
||||
3. 分组配置完成后保存草稿;保存不会启动实验。
|
||||
|
||||

|
||||
|
||||
1. A设0%,保留 false;没有自动流量进入A。
|
||||
2. B设100%,返回 true;自动入组的验收账号读取B值。
|
||||
3. 核对目标、人群和返回值后保存草稿。
|
||||
|
||||
- 填方案名称、选择刚才的类型,写清目标与验收指标。方案名称用于辨认本次实验,不负责绑定功能。
|
||||
- 入组范围选“指定名单”,只选自己的测试账号;进入实验的流量设为100%。请确认页面选择的是你自己的账号。
|
||||
- A 组设0%、返回 false;B 组设100%、返回 true。A仍保留另一种返回值,可通过人工指定进行对照;没有自动流量进入A。
|
||||
- 点击“保存草稿”。保存不会改变应用行为;比例必须合计100%,0%组也必须填写合法返回值。
|
||||
|
||||
## 4. 用户究竟如何被分组
|
||||
|
||||
分组规则会直接标注在配置页,并随着比例显示当前区间。
|
||||
|
||||

|
||||
|
||||
1. 分组方式固定标注在页面:按账号稳定随机分配。
|
||||
2. 当前区间随比例联动,A/B各50%时按0~4999与5000~9999划分。
|
||||
3. 展开查看具体算法,以及人工指定、稳定分组、流量筛选的优先顺序。
|
||||
|
||||
- “所有用户”只表示所有账号有资格参加,不按性别、年龄或账号尾号区分。首次自动分配先判断人群及实验流量。
|
||||
- 系统用账号标识、本次测试方案ID及用途做SHA-256,取摘要前4字节的无符号大端整数,对10000取余,得到0~9999。流量和组别使用两个独立的用途值。
|
||||
- A/B各50%时,按配置顺序A为0~4999,B为5000~9999。A为100%时,A覆盖0~9999,B为0%不自动分配。
|
||||
- 首次实际入组后保存稳定分组,刷新和重新登录不重抽;有效人工指定优先。新建方案的ID不同,同一账号可能分到不同组。
|
||||
- 比例是分配概率,不保证小样本恰好一半。未入组、草稿或暂停时使用类型默认返回值,不属于任何组。
|
||||
|
||||
## 5. 启动验收方案
|
||||
|
||||
接入已确认、草稿配置无误后,点击方案行中的“启动”。
|
||||
|
||||

|
||||
|
||||
1. 确认目标方案,并注意启动后配置冻结。
|
||||
2. 核对无误再确认;之后到应用中验收实际效果。
|
||||
|
||||
- 核对方案名称、人群与比例,再确认启动。启动后应显示“运行中”。
|
||||
- 启动后组别、比例、人群和返回值冻结;需要新规则时创建下一条方案,不能直接改正在运行的配置。
|
||||
- 在应用中重新读取决策并检查新 UI。人工指定用户也需要刷新或等待应用读取新决策;决策请求、实际展示和曝光记录是不同的事情。
|
||||
- 如果仍看旧 UI,先检查类型标识与接入代码、账号是否在名单、返回值是否被使用,而不是仅看后台状态。
|
||||
|
||||
## 6. 查看账号分组,指定 A/B 做对照
|
||||
|
||||
从方案行进入“实验用户分组”,确认当前方案,再搜索测试账号。
|
||||
|
||||

|
||||
|
||||
1. 先选择本次测试方案,并在方案详情中核对目标人群与比例。
|
||||
2. 当前分组和值与分配方式分列展示,明确区分预计自动分组和手动指定。
|
||||
3. 查找用户或指定用户分组;已有指定可修改,也可取消,原有效期限单独展示。
|
||||
|
||||

|
||||
|
||||
1. 指定分组直接展示返回值与自动分流比例;A 为 0% 也可手动指定。
|
||||
2. 账号不在目标人群时,须明确作为测试账号加入;设置未来30天内的有效期。
|
||||
3. 填写原因后确认指定;方案运行且前台已接入时,应用下次读取才会使用指定值。
|
||||
|
||||
- 先选择本次方案,再按账号、姓名或用户名查询;用户列表包含未参与实验的账号。“预计自动分组”只读,首次实际调用后才保存入组,查询不会计曝光。
|
||||
- 点击“指定用户分组”查找账号,或在用户行点击“指定分组/修改指定”。每组直接展示返回值和自动分流比例,0% 组也可手动指定。有效期须在未来30天内,操作原因至少2字。
|
||||
- 账号不符合目标人群时,页面会说明具体原因。例如仅新用户的实验中指定老账号,须勾选“将此账号作为测试账号加入,仍使用上面指定的组”;仅对此账号放开限制,不修改其他用户。符合人群时无需此选项。
|
||||
- 有效期内不一定正在生效:草稿/暂停要等方案运行,人群不符且未允许测试账号加入时不生效。前台仍须真实接入并读取返回值,才能验证功能变化。
|
||||
- 点击“取消手动指定”,或等待到期后恢复方案规则:符合目标人群时沿用原自动分组,否则重新判断。取消指定不保证会换到另一组;修改指定会保留原有效期限,不自动延长。
|
||||
|
||||
## 7. 验收完成后,另建正式分流方案
|
||||
|
||||
先结束验收方案并保留需要的组,再为同一类型创建新的正式方案。
|
||||
|
||||

|
||||
|
||||
1. 正式分流示例A/B各50%,C为0%;合计须为100%。
|
||||
2. 返回值与比例独立配置,不要根据组名猜业务含义。
|
||||
3. 添加更多组或平均分配,最多A到Z共26组。
|
||||
|
||||
- 同一类型消费标识只允许一个运行中或暂停中的方案,可以先保存多份草稿;请先结束验收方案,再启动正式方案。
|
||||
- 本例选择“所有用户”,进入实验流量100%,A/B各50%,分别返回 false / true。也可选择新用户、老用户,并设置明确的注册时间分界。
|
||||
- 可添加到Z组。新增组初始0%,各组返回值独立配置;三组及以上需要自行调整合计100%,或点击“平均分配”“补足剩余”。
|
||||
- 如要扩大实验流量,已启动方案不能直接调规则,需要结束后另建方案。组内比例与实验流量不同:实验流量20%、A/B各50%时,目标人群约10%进入A、10%进入B,其余使用类型默认值。
|
||||
- 截图为另一份演示草稿,比例与返回值请按实际目标设置;不要把教程示例直接当作上线决策。
|
||||
|
||||
## 8. 查看效果与审计
|
||||
|
||||
在方案行点击“效果与审计”,同时核对配置、效果和操作记录。
|
||||
|
||||

|
||||
|
||||
1. 先核对当前组配置,确认所分析的值与比例。
|
||||
2. 区分决策和曝光;曝光须由实际展示后的回报产生。
|
||||
3. 切换“操作审计”,追溯创建、状态流转和人工指定。
|
||||
|
||||

|
||||
|
||||
1. 进入操作审计页签。
|
||||
2. 查看动作、操作人、详情与时间;图中为隔离演示记录。
|
||||
|
||||
- 上方显示实际组别、比例与返回值,下方按组展示决策、曝光和漏斗;人工指定与规则分组分开统计。
|
||||
- 决策次数是读取结果的次数,曝光是应用实际展示后的回报;不能将请求接口的数量当成用户已看到界面的数量。
|
||||
- 根据事先写好的指标比较体验、留存等业务结果;当前页面的漏斗统计不等于完整留存报表,也不会自动给出显著性结论。
|
||||
- “操作审计”保留创建、状态变更和人工指定等操作。没有数据时先检查是否有真实入组、是否完成曝光接入;后台预览不会制造统计。
|
||||
- 截图统计为演示样例,用于解释字段,不能作为生产结果或发布验收凭据。
|
||||
|
||||
## 9. 暂停与恢复
|
||||
|
||||
运行中可以暂停;暂停用于停止实验效果,并不释放同类型的未结束方案。
|
||||
|
||||

|
||||
|
||||
1. 已暂停表示使用类型默认返回值,不属于某个默认组。
|
||||
2. 需要继续时点击恢复;已有稳定分组保持不变。
|
||||
|
||||
- 点击“暂停”并确认后,用户使用实验类型的默认返回值,而不是某个默认组。
|
||||
- 已保存分组保留;点击“恢复”后沿用分组。暂停期间的人工指定也不会让方案重新生效。
|
||||
- 需要彻底换一套人群或分组比例时,结束当前方案,再创建下一条方案。
|
||||
|
||||
## 10. 结束并保留最终结果
|
||||
|
||||
点击“结束实验”,从当前方案已有组中选择最终保留哪一组。
|
||||
|
||||

|
||||
|
||||
1. 打开结束实验菜单。
|
||||
2. 明确选定最终保留的组,本例是返回 true 的B组。
|
||||
|
||||

|
||||
|
||||
1. 确认影响范围:结束后所有用户采用所选组返回值,且不能重新启动。
|
||||
2. 确认无误后提交;若希望回旧版,请先核对所选组是否真的返回旧版值。
|
||||
|
||||
- 本例选择“保留 B 组”,确认文案会明确说明:结束后所有用户采用该组的返回值。
|
||||
- 结束是最终状态,不能恢复运行;它不是“停止并自动回旧版”。如果希望回旧版,应选择实际返回旧版值的组。
|
||||
- 结束后该组返回值会持续生效,直到有新的有效方案接管,或类型被停用;停用类型后回类型默认返回值。
|
||||
- 结束后核对应用效果和审计,再规划下一次实验。不要仅因B叫“B”就认为它一定是新版;含义取决于该组配置的值和消费代码。
|
||||
|
||||
## 完成前再核对一次
|
||||
|
||||
每次实验都按这份清单自查。
|
||||
|
||||
- 类型标识、格式、默认值与应用实现一致,真实功能已经使用返回值,并完成当前契约的接入验收。
|
||||
- 先用自己的账号验收,再正式分流;所有组比例合计100%,零比例组的值同样正确。
|
||||
- 确认人工指定是否仍有效,区分规则分组与人工指定的统计。
|
||||
- 真实调用、真实展示、曝光回报和业务指标分别核实;截图教程与构建成功都不是业务效果验收。
|
||||
- 暂停使用类型默认值;结束保留所选组。按需要的结果操作,不凭组名猜测功能。
|
||||
|
||||
## 维护教程
|
||||
|
||||
- 内容源:`guide.json`;二级教程页直接读取同一内容源。
|
||||
- 原始截图:`screenshots/*.jpg`;标注坐标:`screenshots.json`。截图必须使用隔离演示数据。
|
||||
- 执行 `node scripts/build-experiment-guide.mjs` 重新生成本README和带箭头、编号的SVG。
|
||||
- 执行 `node scripts/build-experiment-guide.mjs --check` 检查派生文件与内容源一致。
|
||||
- 二级页面:`/digital/experiments/guide`;点击“操作指南”进入。
|
||||
@@ -0,0 +1,221 @@
|
||||
{
|
||||
"title": "实验完整操作教程",
|
||||
"updated": "2026-10-27",
|
||||
"intro": "从创建类型到结束实验,按顺序走一遍。建议第一次先只选自己的测试账号,验证真实应用效果后再扩大流量。",
|
||||
"steps": [
|
||||
{
|
||||
"id": "concepts",
|
||||
"title": "先分清三个概念",
|
||||
"lead": "类型定义测什么,测试方案定义怎么测,分组定义每种返回结果。",
|
||||
"bullets": [
|
||||
"实验类型:例如“新老 UI(教程)”,稳定标识 tutorial_ui,返回格式为开关,默认值 false。名称不会自动接入任何功能。",
|
||||
"测试方案:一次有明确目标、人群、流量和生命周期的实验。相同类型可以先做仅自己验收,再结束验收方案、另建正式实验。",
|
||||
"分组:方案内的 A~Z 组。每组有比例和返回值,合计100%;false / true 只是教程示例,实际含义由应用代码决定。",
|
||||
"本文使用隔离演示数据拍摄实际页面组件,标注编号对应下方操作;演示调用与统计不代表你的类型已经接入或线上实验已验收。"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "create-type",
|
||||
"title": "1. 创建自己的实验类型",
|
||||
"lead": "进入“实验类型”,点击“创建实验类型”。",
|
||||
"bullets": [
|
||||
"填写名称与稳定标识。本例 tutorial_ui 只是演示,不要照抄成已有业务的标识;标识创建后不可改。",
|
||||
"选择“开关(是/否)”,默认返回值设为关闭 false;在应用中约定 false 为旧 UI、true 为新 UI。",
|
||||
"保持“启用类型”开启并保存。启用只表示允许这一类型参与决策,不会直接开启新 UI。",
|
||||
"保存后应看到“待应用调用”。这是正常状态;此时可以保存草稿,不能启动实验。"
|
||||
],
|
||||
"images": ["01-create-type"]
|
||||
},
|
||||
{
|
||||
"id": "integrate",
|
||||
"title": "2. 接入应用并完成业务验收",
|
||||
"lead": "在类型所在行点击“接入与验收”,先让真实功能读取并使用返回值。",
|
||||
"bullets": [
|
||||
"将类型标识、数据格式、默认值和目标功能交给负责应用接入的人。后台只能配置,不能替客户端实现界面切换。",
|
||||
"应用以当前用户的已登录身份调用决策接口,读取 value,并将 false / true 实际用于切换旧 / 新 UI。只请求接口并不等于功能已经消费返回值。",
|
||||
"在实际页面检查结果,返回后台点击“刷新调用状态”;收到当前契约的调用后,勾选真实验证并填写至少8字的验收记录,再点“确认接入验收”。",
|
||||
"应看到“已确认接入”。没有调用时按钮不可用,不应伪造回执。截图中的状态来自隔离演示,不是对线上接入的证明。"
|
||||
],
|
||||
"code": "GET /api/digital/decisions/tutorial_ui\nAuthorization: Bearer <当前用户的访问令牌>\n\n// 应用接入示意:使用自己的请求封装和实际界面切换方法。\nconst decision = await readDecision(\"tutorial_ui\");\napplyUiVersion(decision.value === true ? \"new\" : \"old\");",
|
||||
"images": ["02-integration"]
|
||||
},
|
||||
{
|
||||
"id": "trial",
|
||||
"title": "3. 先建“仅自己验收”的测试方案",
|
||||
"lead": "回到“测试方案”,创建草稿,先用自己的真实测试账号验证。",
|
||||
"bullets": [
|
||||
"填方案名称、选择刚才的类型,写清目标与验收指标。方案名称用于辨认本次实验,不负责绑定功能。",
|
||||
"入组范围选“指定名单”,只选自己的测试账号;进入实验的流量设为100%。请确认页面选择的是你自己的账号。",
|
||||
"A 组设0%、返回 false;B 组设100%、返回 true。A仍保留另一种返回值,可通过人工指定进行对照;没有自动流量进入A。",
|
||||
"点击“保存草稿”。保存不会改变应用行为;比例必须合计100%,0%组也必须填写合法返回值。"
|
||||
],
|
||||
"images": ["03-trial", "03b-trial-groups"]
|
||||
},
|
||||
{
|
||||
"id": "allocation",
|
||||
"title": "4. 用户究竟如何被分组",
|
||||
"lead": "分组规则会直接标注在配置页,并随着比例显示当前区间。",
|
||||
"bullets": [
|
||||
"“所有用户”只表示所有账号有资格参加,不按性别、年龄或账号尾号区分。首次自动分配先判断人群及实验流量。",
|
||||
"系统用账号标识、本次测试方案ID及用途做SHA-256,取摘要前4字节的无符号大端整数,对10000取余,得到0~9999。流量和组别使用两个独立的用途值。",
|
||||
"A/B各50%时,按配置顺序A为0~4999,B为5000~9999。A为100%时,A覆盖0~9999,B为0%不自动分配。",
|
||||
"首次实际入组后保存稳定分组,刷新和重新登录不重抽;有效人工指定优先。新建方案的ID不同,同一账号可能分到不同组。",
|
||||
"比例是分配概率,不保证小样本恰好一半。未入组、草稿或暂停时使用类型默认返回值,不属于任何组。"
|
||||
],
|
||||
"images": ["04-allocation"]
|
||||
},
|
||||
{
|
||||
"id": "start",
|
||||
"title": "5. 启动验收方案",
|
||||
"lead": "接入已确认、草稿配置无误后,点击方案行中的“启动”。",
|
||||
"bullets": [
|
||||
"核对方案名称、人群与比例,再确认启动。启动后应显示“运行中”。",
|
||||
"启动后组别、比例、人群和返回值冻结;需要新规则时创建下一条方案,不能直接改正在运行的配置。",
|
||||
"在应用中重新读取决策并检查新 UI。人工指定用户也需要刷新或等待应用读取新决策;决策请求、实际展示和曝光记录是不同的事情。",
|
||||
"如果仍看旧 UI,先检查类型标识与接入代码、账号是否在名单、返回值是否被使用,而不是仅看后台状态。"
|
||||
],
|
||||
"images": ["05-start"]
|
||||
},
|
||||
{
|
||||
"id": "users",
|
||||
"title": "6. 查看账号分组,指定 A/B 做对照",
|
||||
"lead": "从方案行进入“实验用户分组”,确认当前方案,再搜索测试账号。",
|
||||
"bullets": [
|
||||
"先选择本次方案,再按账号、姓名或用户名查询;用户列表包含未参与实验的账号。“预计自动分组”只读,首次实际调用后才保存入组,查询不会计曝光。",
|
||||
"点击“指定用户分组”查找账号,或在用户行点击“指定分组/修改指定”。每组直接展示返回值和自动分流比例,0% 组也可手动指定。有效期须在未来30天内,操作原因至少2字。",
|
||||
"账号不符合目标人群时,页面会说明具体原因。例如仅新用户的实验中指定老账号,须勾选“将此账号作为测试账号加入,仍使用上面指定的组”;仅对此账号放开限制,不修改其他用户。符合人群时无需此选项。",
|
||||
"有效期内不一定正在生效:草稿/暂停要等方案运行,人群不符且未允许测试账号加入时不生效。前台仍须真实接入并读取返回值,才能验证功能变化。",
|
||||
"点击“取消手动指定”,或等待到期后恢复方案规则:符合目标人群时沿用原自动分组,否则重新判断。取消指定不保证会换到另一组;修改指定会保留原有效期限,不自动延长。"
|
||||
],
|
||||
"images": ["06-users", "06b-override"]
|
||||
},
|
||||
{
|
||||
"id": "formal",
|
||||
"title": "7. 验收完成后,另建正式分流方案",
|
||||
"lead": "先结束验收方案并保留需要的组,再为同一类型创建新的正式方案。",
|
||||
"bullets": [
|
||||
"同一类型消费标识只允许一个运行中或暂停中的方案,可以先保存多份草稿;请先结束验收方案,再启动正式方案。",
|
||||
"本例选择“所有用户”,进入实验流量100%,A/B各50%,分别返回 false / true。也可选择新用户、老用户,并设置明确的注册时间分界。",
|
||||
"可添加到Z组。新增组初始0%,各组返回值独立配置;三组及以上需要自行调整合计100%,或点击“平均分配”“补足剩余”。",
|
||||
"如要扩大实验流量,已启动方案不能直接调规则,需要结束后另建方案。组内比例与实验流量不同:实验流量20%、A/B各50%时,目标人群约10%进入A、10%进入B,其余使用类型默认值。",
|
||||
"截图为另一份演示草稿,比例与返回值请按实际目标设置;不要把教程示例直接当作上线决策。"
|
||||
],
|
||||
"images": ["07-formal"]
|
||||
},
|
||||
{
|
||||
"id": "metrics",
|
||||
"title": "8. 查看效果与审计",
|
||||
"lead": "在方案行点击“效果与审计”,同时核对配置、效果和操作记录。",
|
||||
"bullets": [
|
||||
"上方显示实际组别、比例与返回值,下方按组展示决策、曝光和漏斗;人工指定与规则分组分开统计。",
|
||||
"决策次数是读取结果的次数,曝光是应用实际展示后的回报;不能将请求接口的数量当成用户已看到界面的数量。",
|
||||
"根据事先写好的指标比较体验、留存等业务结果;当前页面的漏斗统计不等于完整留存报表,也不会自动给出显著性结论。",
|
||||
"“操作审计”保留创建、状态变更和人工指定等操作。没有数据时先检查是否有真实入组、是否完成曝光接入;后台预览不会制造统计。",
|
||||
"截图统计为演示样例,用于解释字段,不能作为生产结果或发布验收凭据。"
|
||||
],
|
||||
"images": ["08-metrics", "08b-audit"]
|
||||
},
|
||||
{
|
||||
"id": "pause",
|
||||
"title": "9. 暂停与恢复",
|
||||
"lead": "运行中可以暂停;暂停用于停止实验效果,并不释放同类型的未结束方案。",
|
||||
"bullets": [
|
||||
"点击“暂停”并确认后,用户使用实验类型的默认返回值,而不是某个默认组。",
|
||||
"已保存分组保留;点击“恢复”后沿用分组。暂停期间的人工指定也不会让方案重新生效。",
|
||||
"需要彻底换一套人群或分组比例时,结束当前方案,再创建下一条方案。"
|
||||
],
|
||||
"images": ["09-pause"]
|
||||
},
|
||||
{
|
||||
"id": "finish",
|
||||
"title": "10. 结束并保留最终结果",
|
||||
"lead": "点击“结束实验”,从当前方案已有组中选择最终保留哪一组。",
|
||||
"bullets": [
|
||||
"本例选择“保留 B 组”,确认文案会明确说明:结束后所有用户采用该组的返回值。",
|
||||
"结束是最终状态,不能恢复运行;它不是“停止并自动回旧版”。如果希望回旧版,应选择实际返回旧版值的组。",
|
||||
"结束后该组返回值会持续生效,直到有新的有效方案接管,或类型被停用;停用类型后回类型默认返回值。",
|
||||
"结束后核对应用效果和审计,再规划下一次实验。不要仅因B叫“B”就认为它一定是新版;含义取决于该组配置的值和消费代码。"
|
||||
],
|
||||
"images": ["10a-choose-winner", "10-finish"]
|
||||
},
|
||||
{
|
||||
"id": "checklist",
|
||||
"title": "完成前再核对一次",
|
||||
"lead": "每次实验都按这份清单自查。",
|
||||
"bullets": [
|
||||
"类型标识、格式、默认值与应用实现一致,真实功能已经使用返回值,并完成当前契约的接入验收。",
|
||||
"先用自己的账号验收,再正式分流;所有组比例合计100%,零比例组的值同样正确。",
|
||||
"确认人工指定是否仍有效,区分规则分组与人工指定的统计。",
|
||||
"真实调用、真实展示、曝光回报和业务指标分别核实;截图教程与构建成功都不是业务效果验收。",
|
||||
"暂停使用类型默认值;结束保留所选组。按需要的结果操作,不凭组名猜测功能。"
|
||||
]
|
||||
}
|
||||
],
|
||||
"captions": {
|
||||
"01-create-type": [
|
||||
"填写稳定标识;名称用于辨认,标识才是应用读取决策的依据。",
|
||||
"选择返回值格式,本例为开关;下面的默认值使用 false。",
|
||||
"启用类型后保存;保存成功仍须完成真实应用接入。"
|
||||
],
|
||||
"02-integration": [
|
||||
"核对要接入的稳定标识,避免读错类型。",
|
||||
"按调用说明接入,让真实功能使用接口返回的 value。",
|
||||
"收到调用并验证实际功能后,勾选确认、填写记录,再确认接入验收。"
|
||||
],
|
||||
"03-trial": [
|
||||
"命名本次“仅自己验收”的方案,并选择正确类型。",
|
||||
"入组范围选指定名单,只选择自己的测试账号。",
|
||||
"分组配置完成后保存草稿;保存不会启动实验。"
|
||||
],
|
||||
"03b-trial-groups": [
|
||||
"A设0%,保留 false;没有自动流量进入A。",
|
||||
"B设100%,返回 true;自动入组的验收账号读取B值。",
|
||||
"核对目标、人群和返回值后保存草稿。"
|
||||
],
|
||||
"04-allocation": [
|
||||
"分组方式固定标注在页面:按账号稳定随机分配。",
|
||||
"当前区间随比例联动,A/B各50%时按0~4999与5000~9999划分。",
|
||||
"展开查看具体算法,以及人工指定、稳定分组、流量筛选的优先顺序。"
|
||||
],
|
||||
"05-start": [
|
||||
"确认目标方案,并注意启动后配置冻结。",
|
||||
"核对无误再确认;之后到应用中验收实际效果。"
|
||||
],
|
||||
"06-users": [
|
||||
"先选择本次测试方案,并在方案详情中核对目标人群与比例。",
|
||||
"当前分组和值与分配方式分列展示,明确区分预计自动分组和手动指定。",
|
||||
"查找用户或指定用户分组;已有指定可修改,也可取消,原有效期限单独展示。"
|
||||
],
|
||||
"06b-override": [
|
||||
"指定分组直接展示返回值与自动分流比例;A 为 0% 也可手动指定。",
|
||||
"账号不在目标人群时,须明确作为测试账号加入;设置未来30天内的有效期。",
|
||||
"填写原因后确认指定;方案运行且前台已接入时,应用下次读取才会使用指定值。"
|
||||
],
|
||||
"07-formal": [
|
||||
"正式分流示例A/B各50%,C为0%;合计须为100%。",
|
||||
"返回值与比例独立配置,不要根据组名猜业务含义。",
|
||||
"添加更多组或平均分配,最多A到Z共26组。"
|
||||
],
|
||||
"08-metrics": [
|
||||
"先核对当前组配置,确认所分析的值与比例。",
|
||||
"区分决策和曝光;曝光须由实际展示后的回报产生。",
|
||||
"切换“操作审计”,追溯创建、状态流转和人工指定。"
|
||||
],
|
||||
"08b-audit": [
|
||||
"进入操作审计页签。",
|
||||
"查看动作、操作人、详情与时间;图中为隔离演示记录。"
|
||||
],
|
||||
"09-pause": [
|
||||
"已暂停表示使用类型默认返回值,不属于某个默认组。",
|
||||
"需要继续时点击恢复;已有稳定分组保持不变。"
|
||||
],
|
||||
"10a-choose-winner": [
|
||||
"打开结束实验菜单。",
|
||||
"明确选定最终保留的组,本例是返回 true 的B组。"
|
||||
],
|
||||
"10-finish": [
|
||||
"确认影响范围:结束后所有用户采用所选组返回值,且不能重新启动。",
|
||||
"确认无误后提交;若希望回旧版,请先核对所选组是否真的返回旧版值。"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,567 @@
|
||||
{
|
||||
"01-create-type": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 649.5,
|
||||
"y": 273.796875,
|
||||
"width": 606,
|
||||
"height": 30
|
||||
},
|
||||
"badge": {
|
||||
"x": 573.5,
|
||||
"y": 288.796875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 650.5,
|
||||
"y": 396.796875,
|
||||
"width": 156,
|
||||
"height": 24
|
||||
},
|
||||
"badge": {
|
||||
"x": 574.5,
|
||||
"y": 408.796875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1178.5,
|
||||
"y": 803.796875,
|
||||
"width": 88,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1336.5,
|
||||
"y": 819.796875
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"02-integration": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 1455.3515625,
|
||||
"y": 95,
|
||||
"width": 429.1484375,
|
||||
"height": 40
|
||||
},
|
||||
"badge": {
|
||||
"x": 1379.3515625,
|
||||
"y": 115
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1160,
|
||||
"y": 319.5,
|
||||
"width": 725,
|
||||
"height": 26.5
|
||||
},
|
||||
"badge": {
|
||||
"x": 1084,
|
||||
"y": 332.75
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1160,
|
||||
"y": 868.875,
|
||||
"width": 116,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1346,
|
||||
"y": 872
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"03-trial": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 547,
|
||||
"y": 132.09375,
|
||||
"width": 384.5,
|
||||
"height": 30
|
||||
},
|
||||
"badge": {
|
||||
"x": 471,
|
||||
"y": 147.09375
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 823.578125,
|
||||
"y": 427.09375,
|
||||
"width": 513.421875,
|
||||
"height": 24
|
||||
},
|
||||
"badge": {
|
||||
"x": 747.578125,
|
||||
"y": 439.09375
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1296,
|
||||
"y": 808.890625,
|
||||
"width": 88,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1454,
|
||||
"y": 824.890625
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"05-start": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 798,
|
||||
"y": 423,
|
||||
"width": 360,
|
||||
"height": 48
|
||||
},
|
||||
"badge": {
|
||||
"x": 722,
|
||||
"y": 447
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1098,
|
||||
"y": 483,
|
||||
"width": 60,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1228,
|
||||
"y": 499.0
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"06-users": {
|
||||
"width": 1920,
|
||||
"height": 958,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 470,
|
||||
"y": 225,
|
||||
"width": 305,
|
||||
"height": 38
|
||||
},
|
||||
"badge": {
|
||||
"x": 520,
|
||||
"y": 170
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 625,
|
||||
"y": 425,
|
||||
"width": 560,
|
||||
"height": 187
|
||||
},
|
||||
"badge": {
|
||||
"x": 580,
|
||||
"y": 447
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1200,
|
||||
"y": 355,
|
||||
"width": 675,
|
||||
"height": 255
|
||||
},
|
||||
"badge": {
|
||||
"x": 1795,
|
||||
"y": 708
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"06b-override": {
|
||||
"width": 1920,
|
||||
"height": 958,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 655,
|
||||
"y": 225,
|
||||
"width": 595,
|
||||
"height": 135
|
||||
},
|
||||
"badge": {
|
||||
"x": 1390,
|
||||
"y": 270
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 655,
|
||||
"y": 418,
|
||||
"width": 595,
|
||||
"height": 223
|
||||
},
|
||||
"badge": {
|
||||
"x": 520,
|
||||
"y": 470
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 655,
|
||||
"y": 665,
|
||||
"width": 595,
|
||||
"height": 157
|
||||
},
|
||||
"badge": {
|
||||
"x": 1390,
|
||||
"y": 720
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"03b-trial-groups": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 660,
|
||||
"y": 575.46875,
|
||||
"width": 66,
|
||||
"height": 30
|
||||
},
|
||||
"badge": {
|
||||
"x": 480,
|
||||
"y": 543.46875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 660,
|
||||
"y": 624.46875,
|
||||
"width": 66,
|
||||
"height": 30
|
||||
},
|
||||
"badge": {
|
||||
"x": 480,
|
||||
"y": 592.46875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1296,
|
||||
"y": 808.890625,
|
||||
"width": 88,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1454,
|
||||
"y": 824.890625
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"04-allocation": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 551,
|
||||
"y": 342.09375,
|
||||
"width": 182,
|
||||
"height": 16
|
||||
},
|
||||
"badge": {
|
||||
"x": 475,
|
||||
"y": 350.09375
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 551,
|
||||
"y": 395.28125,
|
||||
"width": 803,
|
||||
"height": 22.09375
|
||||
},
|
||||
"badge": {
|
||||
"x": 475,
|
||||
"y": 406.328125
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 551,
|
||||
"y": 452.46875,
|
||||
"width": 811,
|
||||
"height": 49
|
||||
},
|
||||
"badge": {
|
||||
"x": 475,
|
||||
"y": 476.46875
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"07-formal": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 660,
|
||||
"y": 575.46875,
|
||||
"width": 66,
|
||||
"height": 30
|
||||
},
|
||||
"badge": {
|
||||
"x": 480,
|
||||
"y": 543.46875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 818,
|
||||
"y": 623.46875,
|
||||
"width": 116,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 999,
|
||||
"y": 639.46875
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 536,
|
||||
"y": 729.46875,
|
||||
"width": 88,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 460,
|
||||
"y": 745.46875
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"08-metrics": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 1180,
|
||||
"y": 260.28125,
|
||||
"width": 720,
|
||||
"height": 40
|
||||
},
|
||||
"badge": {
|
||||
"x": 1104,
|
||||
"y": 280.28125
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1594,
|
||||
"y": 537.28125,
|
||||
"width": 153,
|
||||
"height": 40
|
||||
},
|
||||
"badge": {
|
||||
"x": 1518,
|
||||
"y": 557.28125
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 3,
|
||||
"rect": {
|
||||
"x": 1056,
|
||||
"y": 443.28125,
|
||||
"width": 76,
|
||||
"height": 40
|
||||
},
|
||||
"badge": {
|
||||
"x": 980,
|
||||
"y": 463.28125
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"08b-audit": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 1056,
|
||||
"y": 443.28125,
|
||||
"width": 76,
|
||||
"height": 40
|
||||
},
|
||||
"badge": {
|
||||
"x": 980,
|
||||
"y": 463.28125
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1048,
|
||||
"y": 494.28125,
|
||||
"width": 149.40625,
|
||||
"height": 17
|
||||
},
|
||||
"badge": {
|
||||
"x": 972,
|
||||
"y": 502.78125
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"09-pause": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 983,
|
||||
"y": 659.65625,
|
||||
"width": 36,
|
||||
"height": 12
|
||||
},
|
||||
"badge": {
|
||||
"x": 907,
|
||||
"y": 665.65625
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1404,
|
||||
"y": 656.65625,
|
||||
"width": 34,
|
||||
"height": 20
|
||||
},
|
||||
"badge": {
|
||||
"x": 1328,
|
||||
"y": 666.65625
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"10a-choose-winner": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 1448,
|
||||
"y": 656.65625,
|
||||
"width": 62,
|
||||
"height": 20
|
||||
},
|
||||
"badge": {
|
||||
"x": 1372,
|
||||
"y": 666.65625
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1433,
|
||||
"y": 727,
|
||||
"width": 91.453125,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1357,
|
||||
"y": 743
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"10-finish": {
|
||||
"width": 1920,
|
||||
"height": 902,
|
||||
"annotations": [
|
||||
{
|
||||
"number": 1,
|
||||
"rect": {
|
||||
"x": 798,
|
||||
"y": 435,
|
||||
"width": 338.625,
|
||||
"height": 24
|
||||
},
|
||||
"badge": {
|
||||
"x": 722,
|
||||
"y": 447
|
||||
}
|
||||
},
|
||||
{
|
||||
"number": 2,
|
||||
"rect": {
|
||||
"x": 1098,
|
||||
"y": 471,
|
||||
"width": 60,
|
||||
"height": 32
|
||||
},
|
||||
"badge": {
|
||||
"x": 1228,
|
||||
"y": 487.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 105 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 148 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 131 KiB |
@@ -0,0 +1,98 @@
|
||||
/** 从同一教程内容源生成仓库README和带编号箭头的SVG截图;--check只验证,不修改文件。 */
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const docRoot = path.join(root, "docs/experiments");
|
||||
const guide = JSON.parse(
|
||||
await readFile(path.join(docRoot, "guide.json"), "utf8")
|
||||
);
|
||||
const shots = JSON.parse(
|
||||
await readFile(path.join(docRoot, "screenshots.json"), "utf8")
|
||||
);
|
||||
const check = process.argv.includes("--check");
|
||||
const escape = value =>
|
||||
String(value).replace(
|
||||
/[&<>"']/g,
|
||||
c =>
|
||||
({
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'"
|
||||
})[c]
|
||||
);
|
||||
/** 派生文件必须与共享源一致,防止网页教程、标注和README各自漂移。 */
|
||||
async function output(file, content) {
|
||||
if (check) {
|
||||
if ((await readFile(file, "utf8")) !== content)
|
||||
throw new Error(`派生文档需要重新生成:${path.relative(root, file)}`);
|
||||
} else await writeFile(file, content);
|
||||
}
|
||||
let readme = `# ${guide.title}\n\n${guide.intro}\n\n更新时间:${guide.updated}\n\n> 截图由仓库实际页面组件在隔离演示环境拍摄。红色箭头和编号为操作标注;演示调用、账号和统计不是生产验收证据。\n\n## 目录\n\n`;
|
||||
for (const step of guide.steps) readme += `- ${step.title}\n`;
|
||||
for (const step of guide.steps) {
|
||||
readme += `\n## ${step.title}\n\n${step.lead}\n`;
|
||||
for (const image of step.images ?? []) {
|
||||
const shot = shots[image];
|
||||
if (!shot || shot.annotations.length < 1)
|
||||
throw new Error(`缺少截图标注:${image}`);
|
||||
if (guide.captions[image]?.length !== shot.annotations.length)
|
||||
throw new Error(`标注编号与说明不匹配:${image}`);
|
||||
const raw = await readFile(
|
||||
path.join(docRoot, "screenshots", `${image}.jpg`)
|
||||
);
|
||||
if (raw[0] !== 255 || raw[1] !== 216)
|
||||
throw new Error(`截图不是JPEG:${image}`);
|
||||
const { width, height } = shot;
|
||||
if (
|
||||
!Number.isInteger(width) ||
|
||||
!Number.isInteger(height) ||
|
||||
width < 1 ||
|
||||
height < 1
|
||||
)
|
||||
throw new Error("截图尺寸无效");
|
||||
const annotations = shot.annotations
|
||||
.map(a => {
|
||||
const { x, y, width: w, height: h } = a.rect,
|
||||
{ x: bx, y: by } = a.badge;
|
||||
for (const n of [x, y, w, h, bx, by])
|
||||
if (!Number.isFinite(n)) throw new Error("标注坐标无效");
|
||||
if (
|
||||
w <= 0 ||
|
||||
h <= 0 ||
|
||||
x < 0 ||
|
||||
y < 0 ||
|
||||
x + w > width + 1 ||
|
||||
y + h > height + 1 ||
|
||||
bx < 20 ||
|
||||
bx > width - 20 ||
|
||||
by < 20 ||
|
||||
by > height - 20
|
||||
)
|
||||
throw new Error(`标注超出截图:${image}`);
|
||||
const targetX = Math.max(x, Math.min(x + w, bx)),
|
||||
targetY = Math.max(y, Math.min(y + h, by));
|
||||
return `<g><rect x="${x - 4}" y="${y - 4}" width="${w + 8}" height="${h + 8}" rx="7" fill="none" stroke="#ff3b30" stroke-width="4"/><path d="M ${bx} ${by} L ${targetX} ${targetY}" fill="none" stroke="#ff3b30" stroke-width="5" marker-end="url(#arrow)"/><circle cx="${bx}" cy="${by}" r="22" fill="#ff3b30" stroke="white" stroke-width="3"/><text x="${bx}" y="${by + 8}" text-anchor="middle" fill="white" font-family="Arial,sans-serif" font-size="24" font-weight="700">${a.number}</text></g>`;
|
||||
})
|
||||
.join("");
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-labelledby="title desc"><title id="title">${escape(step.title)}</title><desc id="desc">隔离演示界面截图,红色箭头和编号对应教程操作步骤。</desc><defs><marker id="arrow" markerWidth="10" markerHeight="10" refX="9" refY="5" orient="auto" markerUnits="userSpaceOnUse"><path d="M0,0 L10,5 L0,10Z" fill="#ff3b30"/></marker></defs><image width="${width}" height="${height}" href="data:image/jpeg;base64,${raw.toString("base64")}"/>${annotations}</svg>\n`;
|
||||
await output(
|
||||
path.join(root, "public/guides/experiments", `${image}.svg`),
|
||||
svg
|
||||
);
|
||||
readme +=
|
||||
`\n\n\n` +
|
||||
guide.captions[image].map((note, i) => `${i + 1}. ${note}`).join("\n") +
|
||||
"\n";
|
||||
}
|
||||
readme += "\n" + step.bullets.map(line => `- ${line}`).join("\n") + "\n";
|
||||
if (step.code) readme += `\n\`\`\`text\n${step.code}\n\`\`\`\n`;
|
||||
}
|
||||
readme +=
|
||||
"\n## 维护教程\n\n- 内容源:`guide.json`;二级教程页直接读取同一内容源。\n- 原始截图:`screenshots/*.jpg`;标注坐标:`screenshots.json`。截图必须使用隔离演示数据。\n- 执行 `node scripts/build-experiment-guide.mjs` 重新生成本README和带箭头、编号的SVG。\n- 执行 `node scripts/build-experiment-guide.mjs --check` 检查派生文件与内容源一致。\n- 二级页面:`/digital/experiments/guide`;点击“操作指南”进入。\n";
|
||||
await output(path.join(docRoot, "README.md"), readme);
|
||||
console.log(
|
||||
check ? "图文教程与标注一致性检查通过" : "已生成图文README与标注截图"
|
||||
);
|
||||
@@ -1091,7 +1091,7 @@ export type Result<T> = { success: boolean; data: T };
|
||||
/** 数字人后台 API,复用已有 JWT 拦截器。 */
|
||||
export async function digital<T>(
|
||||
path: string,
|
||||
method: "get" | "post" | "put" | "delete" = "get",
|
||||
method: "get" | "post" | "put" | "patch" | "delete" = "get",
|
||||
data?: unknown
|
||||
): Promise<T> {
|
||||
try {
|
||||
@@ -1154,7 +1154,9 @@ export type Entry = {
|
||||
caseSensitive: boolean;
|
||||
scanDepth: number;
|
||||
};
|
||||
/** 测试方案:A/B 的返回值遵循已注册类型的数据契约。 */
|
||||
/** 组比例以万分比保存,key使用A至Z,0%组仍可用于人工指定。 */
|
||||
export type ExperimentGroup = { key: string; weight: number; value: unknown };
|
||||
/** 测试方案:动态分组的返回值遵循已注册类型的数据契约。 */
|
||||
export type Experiment = {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -1168,13 +1170,9 @@ export type Experiment = {
|
||||
cutoff?: string;
|
||||
accounts: string[];
|
||||
traffic: number;
|
||||
weightB: number;
|
||||
baseline: "A" | "B";
|
||||
winner?: "A" | "B";
|
||||
presetA?: string;
|
||||
presetB?: string;
|
||||
groups: ExperimentGroup[];
|
||||
winner?: string;
|
||||
description: string;
|
||||
values?: { A: unknown; B: unknown };
|
||||
typeRevision?: number;
|
||||
};
|
||||
};
|
||||
@@ -1213,16 +1211,49 @@ export type ExperimentUser = {
|
||||
status: string;
|
||||
createdAt: string;
|
||||
decision: null | {
|
||||
variant: "A" | "B";
|
||||
variant: string | null;
|
||||
reason: string;
|
||||
value: unknown;
|
||||
revision: number;
|
||||
};
|
||||
override: null | {
|
||||
variant: "A" | "B";
|
||||
variant: string;
|
||||
reason: string;
|
||||
expiresAt: string;
|
||||
bypassAudience: number;
|
||||
};
|
||||
assignment: null | { variant: "A" | "B"; createdAt: string };
|
||||
assignment: null | { variant: string; createdAt: string };
|
||||
};
|
||||
|
||||
/** 独立 C 端用户的后台公开资料,不含密码/令牌或员工权限。 */
|
||||
export type DigitalUser = {
|
||||
id: number;
|
||||
account: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
status: "ACTIVE" | "INACTIVE";
|
||||
createdAt: string;
|
||||
lastLoginAt: string | null;
|
||||
conversations: number;
|
||||
messages: number;
|
||||
};
|
||||
/** 用户所属会话的只读摘要。 */
|
||||
export type UserConversation = {
|
||||
id: string;
|
||||
title: string;
|
||||
characterId: string;
|
||||
characterName: string;
|
||||
messages: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
/** 持久化聊天消息;包括已停止、失败和被替换的历史版本。 */
|
||||
export type UserChatMessage = {
|
||||
id: string;
|
||||
role: "user" | "assistant";
|
||||
content: string;
|
||||
status: string;
|
||||
pinned: number;
|
||||
sequenceId: number;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,12 @@ export default {
|
||||
redirect: "/digital/content",
|
||||
meta: { title: "数字人运营", icon: "ep/chat-dot-round", rank: 0 },
|
||||
children: [
|
||||
{
|
||||
path: "/digital/users",
|
||||
name: "DigitalUsers",
|
||||
component: () => import("@/views/digital/users.vue"),
|
||||
meta: { title: "用户管理", permission: "*" }
|
||||
},
|
||||
{
|
||||
path: "/digital/content",
|
||||
name: "DigitalContent",
|
||||
@@ -26,11 +32,22 @@ export default {
|
||||
component: () => import("@/views/digital/experiments.vue"),
|
||||
meta: { title: "测试方案", permission: "*" }
|
||||
},
|
||||
{
|
||||
path: "/digital/experiments/guide",
|
||||
name: "DigitalExperimentGuide",
|
||||
component: () => import("@/views/digital/experiment-guide.vue"),
|
||||
meta: {
|
||||
title: "实验操作指南",
|
||||
permission: "*",
|
||||
showLink: false,
|
||||
activePath: "/digital/experiments"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/digital/experiment-users",
|
||||
name: "DigitalExperimentUsers",
|
||||
component: () => import("@/views/digital/experiment-users.vue"),
|
||||
meta: { title: "用户管理", permission: "*" }
|
||||
meta: { title: "实验用户分组", permission: "*" }
|
||||
}
|
||||
]
|
||||
} satisfies RouteConfigsTable;
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
<script setup lang="ts">
|
||||
/** 实验图文教程二级页:固定目录与独立正文滚动,按实际阅读位置同步当前章节。 */
|
||||
import {
|
||||
nextTick,
|
||||
onActivated,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
ref,
|
||||
watch
|
||||
} from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import guide from "../../../docs/experiments/guide.json";
|
||||
import screenshotSizes from "../../../docs/experiments/screenshots.json";
|
||||
// 为懒加载截图预留真实比例,避免图片出现后章节位置发生跳动。
|
||||
const sizes = screenshotSizes as Record<
|
||||
string,
|
||||
{ width: number; height: number }
|
||||
>;
|
||||
const router = useRouter();
|
||||
const page = ref<HTMLElement>(),
|
||||
body = ref<HTMLElement>(),
|
||||
toc = ref<HTMLElement>();
|
||||
const activeId = ref(guide.steps[0].id);
|
||||
let frame = 0,
|
||||
observer: ResizeObserver | undefined;
|
||||
/** 正文是唯一阅读滚动容器,懒加载图片改变章节高度后也重新判定位置。 */
|
||||
function updateReadingPosition() {
|
||||
frame = 0;
|
||||
if (!page.value?.offsetWidth || !body.value) return;
|
||||
const available =
|
||||
window.innerHeight - page.value.getBoundingClientRect().top - 24;
|
||||
page.value.style.setProperty(
|
||||
"--guide-height",
|
||||
`${Math.max(360, available)}px`
|
||||
);
|
||||
const sections = Array.from(
|
||||
body.value.querySelectorAll<HTMLElement>(".guide-section")
|
||||
);
|
||||
const top = body.value.getBoundingClientRect().top + 24;
|
||||
let current = sections[0]?.id;
|
||||
for (const section of sections) {
|
||||
if (section.getBoundingClientRect().top <= top) current = section.id;
|
||||
else break;
|
||||
}
|
||||
// 最后一章可能不足一屏;滚到底部时仍须选中它。
|
||||
if (
|
||||
body.value.scrollTop + body.value.clientHeight >=
|
||||
body.value.scrollHeight - 2
|
||||
)
|
||||
current = sections.at(-1)?.id;
|
||||
if (current) activeId.value = current.replace(/^guide-/, "");
|
||||
}
|
||||
function scheduleUpdate() {
|
||||
if (!frame) frame = requestAnimationFrame(updateReadingPosition);
|
||||
}
|
||||
onMounted(() => {
|
||||
window.addEventListener("resize", scheduleUpdate);
|
||||
observer = new ResizeObserver(scheduleUpdate);
|
||||
if (page.value) observer.observe(page.value);
|
||||
if (body.value) {
|
||||
observer.observe(body.value);
|
||||
body.value
|
||||
.querySelectorAll(".guide-section")
|
||||
.forEach(section => observer!.observe(section));
|
||||
}
|
||||
scheduleUpdate();
|
||||
});
|
||||
onActivated(scheduleUpdate);
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("resize", scheduleUpdate);
|
||||
observer?.disconnect();
|
||||
cancelAnimationFrame(frame);
|
||||
});
|
||||
watch(activeId, async id => {
|
||||
await nextTick();
|
||||
const button = toc.value?.querySelector<HTMLElement>(
|
||||
`[data-section="${id}"]`
|
||||
);
|
||||
if (!button || !toc.value) return;
|
||||
const item = button.getBoundingClientRect(),
|
||||
menu = toc.value.getBoundingClientRect();
|
||||
// 仅移动目录内部,避免 scrollIntoView 带动后台外层容器。
|
||||
if (item.top < menu.top || item.bottom > menu.bottom)
|
||||
toc.value.scrollTop +=
|
||||
item.top - menu.top - toc.value.clientHeight / 2 + item.height / 2;
|
||||
});
|
||||
const images = guide.steps.flatMap(step =>
|
||||
(step.images ?? []).map(image => `/guides/experiments/${image}.svg`)
|
||||
);
|
||||
/** 在当前二级页内滚动,不修改hash路由,也不触发任何实验写操作。 */
|
||||
function jump(id: string) {
|
||||
const section = body.value?.querySelector<HTMLElement>(`#guide-${id}`);
|
||||
if (!section || !body.value) return;
|
||||
body.value.scrollTo({
|
||||
top:
|
||||
body.value.scrollTop +
|
||||
section.getBoundingClientRect().top -
|
||||
body.value.getBoundingClientRect().top,
|
||||
behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
||||
? "instant"
|
||||
: "smooth"
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div ref="page" class="experiment-guide">
|
||||
<header class="guide-heading">
|
||||
<div>
|
||||
<el-tag type="info">从零开始 · 图文教程</el-tag>
|
||||
<h1>{{ guide.title }}</h1>
|
||||
<p>{{ guide.intro }}</p>
|
||||
</div>
|
||||
<el-button @click="router.push('/digital/experiments')"
|
||||
>返回测试方案</el-button
|
||||
>
|
||||
</header>
|
||||
<el-alert
|
||||
title="截图使用实际页面组件与隔离演示数据。红色编号对应下方操作;演示接入与统计状态不代表你的线上类型已经验收。点击图片可放大查看。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
/>
|
||||
<div class="guide-layout">
|
||||
<nav class="guide-toc" aria-label="教程目录">
|
||||
<strong>本页目录</strong>
|
||||
<div ref="toc" class="guide-links">
|
||||
<button
|
||||
v-for="step in guide.steps"
|
||||
:key="step.id"
|
||||
type="button"
|
||||
:data-section="step.id"
|
||||
:class="{ active: activeId === step.id }"
|
||||
:aria-current="activeId === step.id ? 'location' : undefined"
|
||||
@click="jump(step.id)"
|
||||
>
|
||||
{{ step.title }}
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
<article
|
||||
ref="body"
|
||||
class="guide-body"
|
||||
tabindex="0"
|
||||
aria-label="教程正文"
|
||||
@scroll="scheduleUpdate"
|
||||
>
|
||||
<section
|
||||
v-for="step in guide.steps"
|
||||
:id="`guide-${step.id}`"
|
||||
:key="step.id"
|
||||
class="guide-section"
|
||||
>
|
||||
<h2>{{ step.title }}</h2>
|
||||
<p class="guide-lead">{{ step.lead }}</p>
|
||||
<figure v-for="image in step.images ?? []" :key="image">
|
||||
<el-image
|
||||
:src="`/guides/experiments/${image}.svg`"
|
||||
:style="{
|
||||
aspectRatio: `${sizes[image].width} / ${sizes[image].height}`
|
||||
}"
|
||||
:alt="`${step.title},带红色箭头与编号的演示截图`"
|
||||
:preview-src-list="images"
|
||||
:initial-index="
|
||||
images.indexOf(`/guides/experiments/${image}.svg`)
|
||||
"
|
||||
preview-teleported
|
||||
lazy
|
||||
fit="contain"
|
||||
><template #error
|
||||
><div class="image-error">
|
||||
教程图片加载失败,请刷新重试。
|
||||
</div></template
|
||||
></el-image
|
||||
>
|
||||
<figcaption>隔离演示截图 · 点击放大 · 编号对应下方操作</figcaption>
|
||||
<ol class="guide-callouts">
|
||||
<li v-for="note in guide.captions[image]" :key="note">
|
||||
{{ note }}
|
||||
</li>
|
||||
</ol>
|
||||
</figure>
|
||||
<ul>
|
||||
<li v-for="line in step.bullets" :key="line">{{ line }}</li>
|
||||
</ul>
|
||||
<pre v-if="'code' in step"><code>{{ step.code }}</code></pre>
|
||||
</section>
|
||||
<footer class="guide-footer">
|
||||
<p>
|
||||
教程更新:{{
|
||||
guide.updated
|
||||
}}。开始操作前,请确认当前环境与目标账号。
|
||||
</p>
|
||||
<el-button @click="router.push('/digital/experiment-types')"
|
||||
>去实验类型</el-button
|
||||
><el-button
|
||||
type="primary"
|
||||
@click="router.push('/digital/experiments')"
|
||||
>去测试方案</el-button
|
||||
><el-button @click="router.push('/digital/experiment-users')"
|
||||
>去实验用户分组</el-button
|
||||
>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.experiment-guide {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 1440px;
|
||||
height: var(--guide-height, calc(100dvh - 134px));
|
||||
min-height: 360px;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.guide-heading {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.guide-heading h1 {
|
||||
margin: 12px 0;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.guide-heading p {
|
||||
max-width: 800px;
|
||||
line-height: 1.8;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.guide-layout {
|
||||
display: grid;
|
||||
flex: 1;
|
||||
grid-template-columns: 220px minmax(0, 1fr);
|
||||
gap: 32px;
|
||||
min-height: 0;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.guide-toc {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-height: 0;
|
||||
max-height: 100%;
|
||||
padding: 16px;
|
||||
overflow: hidden;
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.guide-links {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.guide-toc strong {
|
||||
flex-shrink: 0;
|
||||
padding: 4px 8px 12px;
|
||||
}
|
||||
|
||||
.guide-toc button {
|
||||
padding: 8px;
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.guide-toc button.active {
|
||||
font-weight: 600;
|
||||
color: var(--el-color-primary);
|
||||
background: var(--el-color-primary-light-9);
|
||||
box-shadow: inset 3px 0 var(--el-color-primary);
|
||||
}
|
||||
|
||||
.guide-body {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.guide-body:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.guide-toc button:hover {
|
||||
color: var(--el-color-primary);
|
||||
background: var(--el-fill-color-light);
|
||||
}
|
||||
|
||||
.guide-toc button:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.guide-section {
|
||||
padding: 24px;
|
||||
margin-bottom: 24px;
|
||||
scroll-margin-top: 0;
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.guide-section h2 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.guide-lead {
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.guide-section figure {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.guide-section .el-image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 100px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.guide-section figcaption {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.guide-section ul {
|
||||
padding-left: 22px;
|
||||
line-height: 1.9;
|
||||
}
|
||||
|
||||
.guide-section li {
|
||||
margin-bottom: 12px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.guide-section pre {
|
||||
padding: 16px;
|
||||
overflow-x: auto;
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.image-error {
|
||||
padding: 24px;
|
||||
color: var(--el-text-color-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.guide-footer {
|
||||
padding: 20px 0 32px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.guide-footer p {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
@media (width <= 900px) {
|
||||
.guide-layout {
|
||||
grid-template-rows: auto minmax(0, 1fr);
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.guide-toc {
|
||||
max-height: 140px;
|
||||
}
|
||||
|
||||
.guide-heading {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.guide-heading h1 {
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.guide-heading p {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.guide-section {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
/** 用户分组独立管理:分页查真实账号,预览不分配,人工指定与恢复自动均留审计。 */
|
||||
/** 用户分组管理:区分实际入组与只读预估,按目标人群解释人工指定的生效条件。 */
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
@@ -26,7 +26,10 @@ const plans = ref<Experiment[]>([]),
|
||||
saving = ref(false),
|
||||
editor = ref(false),
|
||||
detail = ref<ExperimentUser | null>(null),
|
||||
explanation = ref(false);
|
||||
explanation = ref(false),
|
||||
planDetail = ref(false),
|
||||
candidates = ref<ExperimentUser[]>([]),
|
||||
finding = ref(false);
|
||||
const selected = computed(() =>
|
||||
plans.value.find(p => p.id === selectedId.value)
|
||||
);
|
||||
@@ -35,13 +38,12 @@ const availablePlans = computed(() =>
|
||||
);
|
||||
const form = ref({
|
||||
account: "",
|
||||
variant: "B" as "A" | "B",
|
||||
variant: "",
|
||||
reason: "",
|
||||
bypassAudience: false,
|
||||
expiresAt: new Date(Date.now() + 86400000).toISOString()
|
||||
});
|
||||
const reasons: Record<string, string> = {
|
||||
baseline: "默认组",
|
||||
default: "无运行方案",
|
||||
finished: "最终方案",
|
||||
override: "人工指定",
|
||||
@@ -49,8 +51,8 @@ const reasons: Record<string, string> = {
|
||||
sticky: "已保存的稳定分组",
|
||||
outside_traffic: "未进入实验流量",
|
||||
allocated: "按规则预计分组(未写入)",
|
||||
paused: "方案暂停,使用默认组",
|
||||
draft: "草稿,使用默认组"
|
||||
paused: "方案暂停,使用类型默认值",
|
||||
draft: "草稿,使用类型默认值"
|
||||
};
|
||||
const states: Record<string, string> = {
|
||||
draft: "草稿",
|
||||
@@ -63,6 +65,7 @@ let requestVersion = 0;
|
||||
async function load() {
|
||||
const version = ++requestVersion;
|
||||
loading.value = true;
|
||||
items.value = [];
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
q: q.value,
|
||||
@@ -97,29 +100,163 @@ function summary(value: unknown) {
|
||||
function overrideActive(row: ExperimentUser) {
|
||||
return !!row.override && Date.parse(row.override.expiresAt) > Date.now();
|
||||
}
|
||||
function formatTime(value?: string) {
|
||||
return value ? new Date(value).toLocaleString() : "—";
|
||||
}
|
||||
const audienceName = computed(() => {
|
||||
const cfg = selected.value?.config;
|
||||
if (!cfg) return "";
|
||||
return {
|
||||
all: "所有用户",
|
||||
new: "新用户",
|
||||
existing: "老用户",
|
||||
specified: "指定名单"
|
||||
}[cfg.audience];
|
||||
});
|
||||
/** 与服务端人群边界一致:新用户包含分界时刻,人工指定不自动改变名单。 */
|
||||
function inAudience(row: ExperimentUser) {
|
||||
const cfg = selected.value?.config;
|
||||
if (!cfg) return false;
|
||||
if (cfg.audience === "all") return true;
|
||||
if (cfg.audience === "specified") return cfg.accounts.includes(row.account);
|
||||
const date = Date.parse(row.createdAt),
|
||||
cutoff = Date.parse(cfg.cutoff ?? "");
|
||||
if (!Number.isFinite(date) || !Number.isFinite(cutoff)) return false;
|
||||
return cfg.audience === "new" ? date >= cutoff : date < cutoff;
|
||||
}
|
||||
const outsideSelectedAudience = computed(
|
||||
() => !!detail.value && !inAudience(detail.value)
|
||||
);
|
||||
const audienceExplanation = computed(() => {
|
||||
if (!selected.value || !detail.value) return "请先选择用户";
|
||||
const cfg = selected.value.config;
|
||||
if (inAudience(detail.value))
|
||||
return `此账号符合“${audienceName.value}”范围。`;
|
||||
if (cfg.audience === "specified") return "此账号不在方案的指定名单中。";
|
||||
return `此账号注册于 ${formatTime(detail.value.createdAt)},方案仅面向${audienceName.value}(以 ${formatTime(cfg.cutoff)} 为界)。`;
|
||||
});
|
||||
function overrideStatus(row: ExperimentUser) {
|
||||
if (!overrideActive(row)) return "已过期";
|
||||
if (selected.value?.state === "finished") return "方案已结束,不再生效";
|
||||
if (selected.value?.state !== "running") return "待方案运行后生效";
|
||||
if (!selected.value.config.groups.some(g => g.key === row.override?.variant))
|
||||
return "原分组已移除";
|
||||
if (!inAudience(row) && !row.override?.bypassAudience)
|
||||
return "不符合目标人群,未生效";
|
||||
return "生效中";
|
||||
}
|
||||
function allocationLabel(row: ExperimentUser) {
|
||||
if (!row.decision) return "未选择方案";
|
||||
return (
|
||||
{
|
||||
override: "手动指定",
|
||||
sticky: "自动分组",
|
||||
allocated: "预计自动分组",
|
||||
finished: "最终统一分组"
|
||||
}[row.decision.reason] ?? "未参与实验"
|
||||
);
|
||||
}
|
||||
let candidateVersion = 0;
|
||||
/** 独立查找账号,避免将指定用户限定为当前表格页;过期响应不能覆盖新的搜索。 */
|
||||
async function findCandidates(query: string) {
|
||||
const version = ++candidateVersion;
|
||||
finding.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams({ q: query, page: "1", size: "20" });
|
||||
if (selectedId.value) params.set("experiment", selectedId.value);
|
||||
const result = await digital<{ items: ExperimentUser[] }>(
|
||||
`experiment-users?${params}`
|
||||
);
|
||||
if (version === candidateVersion)
|
||||
candidates.value = result.items.filter(row => row.status === "ACTIVE");
|
||||
} catch (e) {
|
||||
if (version === candidateVersion)
|
||||
ElMessage.error(e instanceof Error ? e.message : "查找账号失败");
|
||||
} finally {
|
||||
if (version === candidateVersion) finding.value = false;
|
||||
}
|
||||
}
|
||||
function chooseAccount(account: string) {
|
||||
const row = candidates.value.find(item => item.account === account);
|
||||
if (row) {
|
||||
detail.value = row;
|
||||
form.value.variant =
|
||||
row.override?.variant ??
|
||||
row.decision?.variant ??
|
||||
selected.value?.config.groups[0]?.key ??
|
||||
"";
|
||||
form.value.bypassAudience = !!row.override?.bypassAudience;
|
||||
form.value.expiresAt = overrideActive(row)
|
||||
? row.override!.expiresAt
|
||||
: new Date(Date.now() + 86400000).toISOString();
|
||||
}
|
||||
}
|
||||
function startAssign() {
|
||||
detail.value = null;
|
||||
form.value = {
|
||||
account: "",
|
||||
variant: selected.value?.config.groups[0]?.key ?? "",
|
||||
reason: "",
|
||||
bypassAudience: false,
|
||||
expiresAt: new Date(Date.now() + 86400000).toISOString()
|
||||
};
|
||||
candidates.value = [];
|
||||
editor.value = true;
|
||||
findCandidates("");
|
||||
}
|
||||
function open(row: ExperimentUser) {
|
||||
if (!selected.value) return;
|
||||
detail.value = row;
|
||||
form.value = {
|
||||
account: row.account,
|
||||
variant: row.override?.variant ?? "B",
|
||||
variant:
|
||||
row.override?.variant ??
|
||||
row.decision?.variant ??
|
||||
selected.value.config.groups[0]?.key ??
|
||||
"",
|
||||
reason: "",
|
||||
bypassAudience: !!row.override?.bypassAudience,
|
||||
expiresAt: new Date(Date.now() + 86400000).toISOString()
|
||||
expiresAt: overrideActive(row)
|
||||
? row.override!.expiresAt
|
||||
: new Date(Date.now() + 86400000).toISOString()
|
||||
};
|
||||
candidates.value = [row];
|
||||
editor.value = true;
|
||||
}
|
||||
async function save() {
|
||||
const id = selectedId.value;
|
||||
if (!id) return;
|
||||
if (!id || !selected.value || selected.value.state === "finished") return;
|
||||
if (!detail.value || !form.value.account)
|
||||
return ElMessage.warning("请先查找并选择用户");
|
||||
if (!selected.value.config.groups.some(g => g.key === form.value.variant))
|
||||
return ElMessage.warning("请选择方案中有效的分组");
|
||||
const expiry = Date.parse(form.value.expiresAt);
|
||||
if (
|
||||
!Number.isFinite(expiry) ||
|
||||
expiry <= Date.now() ||
|
||||
expiry > Date.now() + 30 * 86400000
|
||||
)
|
||||
return ElMessage.warning("有效期须在未来 30 天内");
|
||||
if (outsideSelectedAudience.value && !form.value.bypassAudience)
|
||||
return ElMessage.warning(
|
||||
"此账号不符合目标人群,请确认是否作为测试账号加入"
|
||||
);
|
||||
if (form.value.reason.trim().length < 2)
|
||||
return ElMessage.warning("请填写至少两个字的操作原因");
|
||||
const wasRunning = selected.value.state === "running";
|
||||
saving.value = true;
|
||||
try {
|
||||
await digital(`experiments/${id}/override`, "put", form.value);
|
||||
await digital(`experiments/${id}/override`, "put", {
|
||||
...form.value,
|
||||
bypassAudience: outsideSelectedAudience.value && form.value.bypassAudience
|
||||
});
|
||||
editor.value = false;
|
||||
await load();
|
||||
ElMessage.success("人工分组已保存,用户刷新前台后读取结果");
|
||||
ElMessage.success(
|
||||
wasRunning
|
||||
? "手动指定已保存,应用下次读取方案时生效"
|
||||
: "手动指定已保存,方案运行后才会生效"
|
||||
);
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : "指定失败");
|
||||
} finally {
|
||||
@@ -132,9 +269,9 @@ async function restore(row: ExperimentUser) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`取消 ${row.name} 的人工指定?已有稳定分组保留,没有稳定分组时按方案规则判定。`,
|
||||
"恢复自动分组",
|
||||
"取消手动指定",
|
||||
{
|
||||
confirmButtonText: "恢复自动",
|
||||
confirmButtonText: "确认取消指定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}
|
||||
@@ -153,6 +290,8 @@ async function restore(row: ExperimentUser) {
|
||||
watch(selectedId, () => {
|
||||
editor.value = false;
|
||||
explanation.value = false;
|
||||
planDetail.value = false;
|
||||
++candidateVersion;
|
||||
router.replace({
|
||||
query: { ...route.query, experiment: selectedId.value || undefined }
|
||||
});
|
||||
@@ -192,94 +331,157 @@ onMounted(async () => {
|
||||
<div class="users-page">
|
||||
<div class="heading">
|
||||
<div>
|
||||
<h2>用户管理</h2>
|
||||
<p>
|
||||
账号来自现有登录体系。这里查看实验分组与管理人工指定,测试方案在独立页面配置。
|
||||
</p>
|
||||
<h2>实验用户分组</h2>
|
||||
<p>选择测试方案,查看独立 C 端用户的分组,或为测试账号指定分组。</p>
|
||||
</div>
|
||||
<el-button @click="router.push('/digital/experiments')"
|
||||
>查看测试方案</el-button
|
||||
>
|
||||
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||
</div>
|
||||
<el-alert
|
||||
title="分组预览只读,不会给用户入组或记录曝光。先选择测试方案,再查人、指定 A/B 或恢复自动;草稿和暂停时使用方案默认组。"
|
||||
:closable="false"
|
||||
type="info"
|
||||
/>
|
||||
<el-card shadow="never" class="content"
|
||||
><div class="filters">
|
||||
<el-select v-model="typeFilter" clearable placeholder="筛选实验类型"
|
||||
><el-option
|
||||
v-for="t in types"
|
||||
:key="t.id"
|
||||
:value="t.id"
|
||||
:label="t.name" /></el-select
|
||||
><el-select
|
||||
v-model="selectedId"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="选择测试方案(指定分组前必选)"
|
||||
><el-option
|
||||
v-for="p in availablePlans"
|
||||
:key="p.id"
|
||||
:value="p.id"
|
||||
:label="`${p.name} · ${states[p.state]}`" /></el-select
|
||||
><el-input
|
||||
v-model="q"
|
||||
clearable
|
||||
placeholder="搜索用户名、姓名或账号 ID"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
/><el-button type="primary" @click="search">查询</el-button>
|
||||
</div>
|
||||
<p v-if="selected" class="context">
|
||||
{{ typeName(selected.scope) }} / {{ selected.name }}
|
||||
<el-tag>{{ states[selected.state] }}</el-tag
|
||||
><span>
|
||||
流量 {{ selected.config.traffic / 100 }}% · B 组
|
||||
{{ selected.config.weightB / 100 }}%</span
|
||||
<el-card shadow="never">
|
||||
<div class="plan-filters">
|
||||
<el-form-item label="实验类型"
|
||||
><el-select v-model="typeFilter" clearable placeholder="全部类型"
|
||||
><el-option
|
||||
v-for="t in types"
|
||||
:key="t.id"
|
||||
:value="t.id"
|
||||
:label="t.name" /></el-select
|
||||
></el-form-item>
|
||||
<el-form-item label="当前测试方案"
|
||||
><el-select
|
||||
v-model="selectedId"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择测试方案"
|
||||
><el-option
|
||||
v-for="p in availablePlans"
|
||||
:key="p.id"
|
||||
:value="p.id"
|
||||
:label="p.name + ' · ' + states[p.state]" /></el-select
|
||||
></el-form-item>
|
||||
<el-tag
|
||||
v-if="selected"
|
||||
:type="selected.state === 'running' ? 'success' : 'info'"
|
||||
>{{ states[selected.state] }}</el-tag
|
||||
>
|
||||
</p>
|
||||
<el-table v-loading="loading" :data="items"
|
||||
><el-table-column label="用户" min-width="210"
|
||||
<el-button
|
||||
v-if="selected"
|
||||
link
|
||||
type="primary"
|
||||
@click="planDetail = true"
|
||||
>方案详情</el-button
|
||||
>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="router.push('/digital/experiments')"
|
||||
>查看测试方案</el-button
|
||||
>
|
||||
</div>
|
||||
<div v-if="selected" class="plan-summary">
|
||||
{{ typeName(selected.scope) }} · 目标人群:{{ audienceName }} ·
|
||||
参与流量:{{ selected.config.traffic / 100 }}% ·
|
||||
{{
|
||||
selected.config.groups
|
||||
.map(g => `${g.key} 组 ${g.weight / 100}%`)
|
||||
.join(" / ")
|
||||
}}
|
||||
</div>
|
||||
</el-card>
|
||||
<el-alert
|
||||
v-if="selected && selected.state !== 'running'"
|
||||
class="content"
|
||||
:title="
|
||||
selected.state === 'finished'
|
||||
? '方案已结束:所有用户使用最终分组,原手动指定不再生效。'
|
||||
: `方案${states[selected.state]}:用户当前使用类型默认值。手动指定可提前保存,方案运行后才会生效。`
|
||||
"
|
||||
:closable="false"
|
||||
type="warning"
|
||||
/>
|
||||
<el-card shadow="never" class="content">
|
||||
<div class="table-toolbar">
|
||||
<div>
|
||||
<strong>用户列表</strong
|
||||
><span class="secondary"> 共 {{ total }} 个账号</span>
|
||||
<p class="secondary">
|
||||
包含尚未参与实验的账号;“预计分组”仅供查看,实际调用后才会入组。
|
||||
</p>
|
||||
</div>
|
||||
<div class="search-actions">
|
||||
<el-input
|
||||
v-model="q"
|
||||
clearable
|
||||
placeholder="用户名、姓名或账号 ID"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
/><el-button :loading="loading" @click="search">查找用户</el-button
|
||||
><el-button
|
||||
type="primary"
|
||||
:disabled="!selected || selected.state === 'finished' || loading"
|
||||
@click="startAssign"
|
||||
>指定用户分组</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<el-table v-loading="loading" :data="items" empty-text="没有匹配的账号">
|
||||
<el-table-column label="用户" min-width="230"
|
||||
><template #default="{ row }"
|
||||
><strong>{{ row.name }}</strong>
|
||||
<p class="secondary">{{ row.username }} · {{ row.account }}</p>
|
||||
<small class="secondary">{{
|
||||
new Date(row.createdAt).toLocaleString()
|
||||
}}</small></template
|
||||
><div class="user-cell">
|
||||
<el-avatar :size="36">{{
|
||||
(row.name || row.username).slice(0, 1)
|
||||
}}</el-avatar>
|
||||
<div>
|
||||
<strong>{{ row.name }}</strong>
|
||||
<p class="secondary">{{ row.username }} · {{ row.account }}</p>
|
||||
<el-tag v-if="row.status !== 'ACTIVE'" type="info" size="small"
|
||||
>账号已停用</el-tag
|
||||
>
|
||||
</div>
|
||||
</div></template
|
||||
></el-table-column
|
||||
><el-table-column label="账号状态" width="95"
|
||||
><template #default="{ row }"
|
||||
><el-tag :type="row.status === 'ACTIVE' ? 'success' : 'info'">{{
|
||||
row.status === "ACTIVE" ? "正常" : "已停用"
|
||||
}}</el-tag></template
|
||||
></el-table-column
|
||||
><el-table-column label="分组预览 / 返回值" min-width="200"
|
||||
>
|
||||
<el-table-column label="当前分组 / 返回值" min-width="210"
|
||||
><template #default="{ row }"
|
||||
><template v-if="row.decision"
|
||||
><strong>{{ row.decision.variant }} 组</strong>
|
||||
><div class="group-value">
|
||||
<el-tag v-if="row.decision.variant"
|
||||
>{{ row.decision.variant }} 组</el-tag
|
||||
><strong v-else>未参与实验</strong
|
||||
><code>{{ summary(row.decision.value) }}</code>
|
||||
</div>
|
||||
<p class="secondary">
|
||||
{{ reasons[row.decision.reason] ?? row.decision.reason }}
|
||||
</p>
|
||||
<code>{{ summary(row.decision.value) }}</code></template
|
||||
><span v-else class="secondary">先选择测试方案</span></template
|
||||
</p></template
|
||||
><span v-else class="secondary">选择方案后查看</span></template
|
||||
></el-table-column
|
||||
><el-table-column label="人工指定记录" min-width="190"
|
||||
>
|
||||
<el-table-column label="分配方式" min-width="160"
|
||||
><template #default="{ row }"
|
||||
><el-tag
|
||||
:type="row.decision?.reason === 'override' ? 'success' : 'info'"
|
||||
>{{ allocationLabel(row) }}</el-tag
|
||||
>
|
||||
<p
|
||||
v-if="row.override && row.decision?.reason !== 'override'"
|
||||
class="secondary"
|
||||
>
|
||||
有手动指定 · {{ overrideStatus(row) }}
|
||||
</p></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="手动指定有效期" min-width="190"
|
||||
><template #default="{ row }"
|
||||
><template v-if="row.override"
|
||||
><el-tag :type="overrideActive(row) ? 'warning' : 'info'"
|
||||
>{{ row.override.variant }} 组 ·
|
||||
{{ overrideActive(row) ? "有效期内" : "已过期" }}</el-tag
|
||||
>
|
||||
<p class="secondary">{{ row.override.reason }}</p>
|
||||
<small class="secondary"
|
||||
>到
|
||||
{{ new Date(row.override.expiresAt).toLocaleString() }}</small
|
||||
></template
|
||||
><span v-else class="secondary">无</span></template
|
||||
><div>
|
||||
{{ row.override.variant }} 组 · {{ overrideStatus(row) }}
|
||||
</div>
|
||||
<p class="secondary">
|
||||
至 {{ formatTime(row.override.expiresAt) }}
|
||||
</p></template
|
||||
><span v-else class="secondary">—</span></template
|
||||
></el-table-column
|
||||
><el-table-column label="操作" min-width="240" fixed="right"
|
||||
>
|
||||
<el-table-column label="操作" min-width="240" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button
|
||||
link
|
||||
@@ -289,7 +491,7 @@ onMounted(async () => {
|
||||
detail = row;
|
||||
explanation = true;
|
||||
"
|
||||
>分组详情</el-button
|
||||
>详情</el-button
|
||||
><el-button
|
||||
link
|
||||
type="primary"
|
||||
@@ -300,22 +502,19 @@ onMounted(async () => {
|
||||
loading
|
||||
"
|
||||
@click="open(row)"
|
||||
>指定分组</el-button
|
||||
>{{ row.override ? "修改指定" : "指定分组" }}</el-button
|
||||
><el-button
|
||||
v-if="row.override"
|
||||
link
|
||||
type="warning"
|
||||
:disabled="loading"
|
||||
:disabled="loading || selected?.state === 'finished'"
|
||||
@click="restore(row)"
|
||||
>恢复自动</el-button
|
||||
>取消手动指定</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
></el-table
|
||||
>
|
||||
<el-empty
|
||||
v-if="!items.length && !loading"
|
||||
description="没有匹配的账号"
|
||||
/><el-pagination
|
||||
>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
:page-size="size"
|
||||
:total="total"
|
||||
@@ -326,91 +525,209 @@ onMounted(async () => {
|
||||
</el-card>
|
||||
<el-dialog
|
||||
v-model="editor"
|
||||
title="指定用户分组"
|
||||
width="min(560px,95vw)"
|
||||
:title="detail?.override ? '修改用户指定分组' : '指定用户分组'"
|
||||
width="min(640px,95vw)"
|
||||
class="assignment-dialog"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
><el-form label-position="top"
|
||||
><el-form-item label="当前测试方案"
|
||||
><span>{{ selected?.name }}</span></el-form-item
|
||||
><el-form-item label="账号"
|
||||
><strong
|
||||
>{{ detail?.name }} · {{ form.account }}</strong
|
||||
></el-form-item
|
||||
><el-form-item label="指定分组"
|
||||
><el-radio-group v-model="form.variant"
|
||||
><el-radio value="A">A 组</el-radio
|
||||
><el-radio value="B">B 组</el-radio></el-radio-group
|
||||
></el-form-item
|
||||
><el-form-item label="有效期(最多 30 天)"
|
||||
>
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="当前测试方案"
|
||||
><strong>{{ selected?.name }}</strong
|
||||
><el-tag class="state-tag">{{
|
||||
selected ? states[selected.state] : ""
|
||||
}}</el-tag></el-form-item
|
||||
>
|
||||
<el-form-item label="用户" required
|
||||
><el-select
|
||||
v-model="form.account"
|
||||
filterable
|
||||
remote
|
||||
:remote-method="findCandidates"
|
||||
:loading="finding"
|
||||
placeholder="输入用户名、姓名或账号 ID 查找"
|
||||
@change="chooseAccount"
|
||||
><el-option
|
||||
v-for="row in candidates"
|
||||
:key="row.account"
|
||||
:value="row.account"
|
||||
:label="`${row.name} · ${row.username} · ${row.account}`" /></el-select
|
||||
></el-form-item>
|
||||
<el-form-item label="指定分组" required
|
||||
><el-radio-group v-model="form.variant" class="group-options"
|
||||
><el-radio
|
||||
v-for="group in selected?.config.groups ?? []"
|
||||
:key="group.key"
|
||||
:value="group.key"
|
||||
border
|
||||
><span>{{ group.key }} 组 · 返回 {{ summary(group.value) }}</span
|
||||
><span class="secondary">
|
||||
自动分流 {{ group.weight / 100 }}%</span
|
||||
></el-radio
|
||||
></el-radio-group
|
||||
>
|
||||
<p class="secondary">
|
||||
手动指定不受分流比例限制,0% 的组也可以选择。
|
||||
</p></el-form-item
|
||||
>
|
||||
<div v-if="detail" class="audience-note">
|
||||
<strong>目标人群:{{ audienceName }}</strong>
|
||||
<p>{{ audienceExplanation }}</p>
|
||||
<template v-if="outsideSelectedAudience"
|
||||
><el-checkbox v-model="form.bypassAudience"
|
||||
>将此账号作为测试账号加入,仍使用上面指定的组</el-checkbox
|
||||
>
|
||||
<p class="secondary">
|
||||
只对这个账号放开人群限制,不修改方案人群和其他用户的分组。
|
||||
</p></template
|
||||
>
|
||||
</div>
|
||||
<el-form-item label="有效期(最多 30 天)" required
|
||||
><el-date-picker
|
||||
:model-value="new Date(form.expiresAt)"
|
||||
type="datetime"
|
||||
:clearable="false"
|
||||
@update:model-value="
|
||||
v => {
|
||||
if (v) form.expiresAt = new Date(v).toISOString();
|
||||
}
|
||||
" /></el-form-item
|
||||
><el-form-item label="操作原因" required
|
||||
"
|
||||
/>
|
||||
<p class="secondary">
|
||||
到期后按方案规则恢复:符合目标人群时沿用原自动分组,否则重新判断。
|
||||
</p></el-form-item
|
||||
>
|
||||
<el-form-item label="指定原因" required
|
||||
><el-input
|
||||
v-model="form.reason"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="500" /></el-form-item
|
||||
><el-checkbox v-model="form.bypassAudience"
|
||||
>明确允许此账号越过人群限制</el-checkbox
|
||||
><el-alert
|
||||
title="人工指定优先于流量和稳定分组。方案未运行时仍使用默认组;恢复自动后保留原稳定分组,所有操作记录审计。"
|
||||
:rows="2"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
placeholder="例如:测试账号验证新版界面(至少 2 个字)"
|
||||
/></el-form-item>
|
||||
<el-alert
|
||||
:title="
|
||||
selected?.state === 'running'
|
||||
? '保存后,应用下次读取此方案时使用指定组的返回值。请在已接入该实验类型的前台验证效果。'
|
||||
: '当前方案未运行,保存只记录指定关系,不会切换前台。方案运行且指定未过期后才会生效。'
|
||||
"
|
||||
:closable="false"
|
||||
class="content" /></el-form
|
||||
><template #footer
|
||||
type="info"
|
||||
/>
|
||||
</el-form>
|
||||
<template #footer
|
||||
><el-button @click="editor = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="save"
|
||||
>保存指定</el-button
|
||||
><el-button
|
||||
type="primary"
|
||||
:loading="saving"
|
||||
:disabled="
|
||||
!detail || (outsideSelectedAudience && !form.bypassAudience)
|
||||
"
|
||||
@click="save"
|
||||
>确认指定</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
>
|
||||
>
|
||||
</el-dialog>
|
||||
<el-dialog
|
||||
v-model="explanation"
|
||||
title="用户分组详情(只读)"
|
||||
width="min(600px,95vw)"
|
||||
><el-descriptions v-if="detail" :column="1" border
|
||||
><el-descriptions-item label="账号"
|
||||
title="用户分组详情"
|
||||
width="min(640px,95vw)"
|
||||
>
|
||||
<el-descriptions v-if="detail" :column="1" border>
|
||||
<el-descriptions-item label="用户"
|
||||
>{{ detail.name }} · {{ detail.account }}</el-descriptions-item
|
||||
><el-descriptions-item label="注册时间">{{
|
||||
new Date(detail.createdAt).toLocaleString()
|
||||
}}</el-descriptions-item
|
||||
><el-descriptions-item label="当前预览"
|
||||
>{{ detail.decision?.variant }} 组 ·
|
||||
{{ reasons[detail.decision?.reason ?? ""] }}</el-descriptions-item
|
||||
><el-descriptions-item label="返回值">
|
||||
<pre>{{
|
||||
JSON.stringify(detail.decision?.value, null, 2)
|
||||
}}</pre></el-descriptions-item
|
||||
><el-descriptions-item label="已保存的稳定分组">{{
|
||||
detail.assignment ? detail.assignment.variant + " 组" : "尚未实际入组"
|
||||
}}</el-descriptions-item
|
||||
><el-descriptions-item label="人工指定">{{
|
||||
detail.override
|
||||
? detail.override.variant + " 组;" + detail.override.reason
|
||||
: "无"
|
||||
}}</el-descriptions-item
|
||||
><el-descriptions-item label="越过人群限制">{{
|
||||
detail.override?.bypassAudience ? "是" : "否"
|
||||
}}</el-descriptions-item></el-descriptions
|
||||
>
|
||||
<el-descriptions-item label="注册时间">{{
|
||||
formatTime(detail.createdAt)
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="当前结果"
|
||||
>{{
|
||||
detail.decision?.variant
|
||||
? detail.decision.variant + " 组"
|
||||
: "未参与实验"
|
||||
}}
|
||||
· {{ reasons[detail.decision?.reason ?? ""] }}
|
||||
<pre>{{ JSON.stringify(detail.decision?.value, null, 2) }}</pre>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="实际入组记录"
|
||||
>{{
|
||||
detail.assignment
|
||||
? detail.assignment.variant +
|
||||
" 组 · " +
|
||||
formatTime(detail.assignment.createdAt)
|
||||
: "尚无自动入组记录"
|
||||
}}
|
||||
<p class="secondary">
|
||||
手动指定单独记录,不覆盖原自动分组。
|
||||
</p></el-descriptions-item
|
||||
>
|
||||
<el-descriptions-item label="手动指定"
|
||||
><template v-if="detail.override"
|
||||
>{{ detail.override.variant }} 组 · {{ overrideStatus(detail) }}
|
||||
<p>有效期至 {{ formatTime(detail.override.expiresAt) }}</p>
|
||||
<p>原因:{{ detail.override.reason }}</p>
|
||||
<p>
|
||||
{{
|
||||
detail.override.bypassAudience
|
||||
? "已允许此测试账号不受目标人群限制"
|
||||
: "仅在此账号符合目标人群时生效"
|
||||
}}
|
||||
</p></template
|
||||
><span v-else>无</span></el-descriptions-item
|
||||
>
|
||||
<el-descriptions-item label="目标人群">{{
|
||||
audienceExplanation
|
||||
}}</el-descriptions-item> </el-descriptions
|
||||
><el-alert
|
||||
title="预览按当前规则和账号注册时间计算。首次实际调用才保存分组,实际展示后才计曝光。"
|
||||
title="页面查询不会让用户入组或记录曝光;前台需实际接入并读取实验结果,才能验证功能变化。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="content"
|
||||
/></el-dialog>
|
||||
/>
|
||||
</el-dialog>
|
||||
<el-dialog v-model="planDetail" title="当前方案详情" width="min(640px,95vw)"
|
||||
><el-descriptions v-if="selected" :column="1" border
|
||||
><el-descriptions-item label="测试方案"
|
||||
>{{ selected.name }} ·
|
||||
{{ states[selected.state] }}</el-descriptions-item
|
||||
><el-descriptions-item label="实验类型">{{
|
||||
typeName(selected.scope)
|
||||
}}</el-descriptions-item
|
||||
><el-descriptions-item label="目标人群"
|
||||
>{{ audienceName
|
||||
}}<span v-if="selected.config.cutoff"
|
||||
>(注册时间分界:{{ formatTime(selected.config.cutoff) }})</span
|
||||
><span v-if="selected.config.audience === 'specified'">
|
||||
· {{ selected.config.accounts.length }} 个账号</span
|
||||
></el-descriptions-item
|
||||
><el-descriptions-item label="参与流量"
|
||||
>{{ selected.config.traffic / 100 }}%</el-descriptions-item
|
||||
><el-descriptions-item
|
||||
v-for="group in selected.config.groups"
|
||||
:key="group.key"
|
||||
:label="group.key + ' 组'"
|
||||
>{{ group.weight / 100 }}% · 返回
|
||||
{{ summary(group.value) }}</el-descriptions-item
|
||||
></el-descriptions
|
||||
></el-dialog
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.heading {
|
||||
.heading,
|
||||
.table-toolbar,
|
||||
.plan-filters,
|
||||
.search-actions,
|
||||
.user-cell,
|
||||
.group-value {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.heading,
|
||||
.table-toolbar {
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
@@ -431,16 +748,39 @@ onMounted(async () => {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1.5fr 1.5fr auto;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
.plan-filters {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.context {
|
||||
margin-bottom: 18px;
|
||||
.plan-filters :deep(.el-form-item) {
|
||||
display: block;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.plan-filters :deep(.el-select) {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.plan-filters :deep(.el-form-item:first-child .el-select) {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.plan-summary {
|
||||
margin-top: 18px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.search-actions {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-actions :deep(.el-input) {
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
.search-actions :deep(.el-button + .el-button) {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
@@ -448,9 +788,56 @@ onMounted(async () => {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.group-options {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.group-options :deep(.el-radio) {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 42px;
|
||||
padding: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.group-options :deep(.el-radio__label) {
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.audience-note {
|
||||
padding: 14px;
|
||||
margin-bottom: 18px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.audience-note p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.audience-note :deep(.el-checkbox) {
|
||||
height: auto;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.audience-note :deep(.el-checkbox__label) {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.assignment-dialog :deep(.el-form-item__content > p) {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.state-tag {
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
code,
|
||||
pre {
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
@@ -458,16 +845,36 @@ code {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (width<=760px) {
|
||||
.filters {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.users-page :deep(.assignment-dialog .el-dialog__body) {
|
||||
max-height: 65vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@media (width <= 1000px) {
|
||||
.table-toolbar {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 760px) {
|
||||
.heading {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.plan-filters {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.plan-filters :deep(.el-form-item),
|
||||
.plan-filters :deep(.el-select),
|
||||
.search-actions,
|
||||
.search-actions :deep(.el-input) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
digital,
|
||||
type Content,
|
||||
type Experiment,
|
||||
type ExperimentGroup,
|
||||
type ExperimentType
|
||||
} from "@/api/access";
|
||||
type Account = { account: string; name: string; createdAt: string };
|
||||
@@ -47,12 +48,10 @@ type Details = {
|
||||
createdAt: string;
|
||||
}>;
|
||||
};
|
||||
const guideVisible = ref(false);
|
||||
const router = useRouter();
|
||||
const scenes = ref<ExperimentType[]>([]);
|
||||
const validA = ref(true),
|
||||
validB = ref(true),
|
||||
filterType = ref("");
|
||||
const groupValid = ref<Record<string, boolean>>({});
|
||||
const filterType = ref("");
|
||||
const filtered = computed(() =>
|
||||
list.value.filter(e => !filterType.value || e.scope === filterType.value)
|
||||
);
|
||||
@@ -98,12 +97,70 @@ const trafficPercent = computed({
|
||||
if (edit.value) edit.value.config.traffic = Math.round((value ?? 0) * 100);
|
||||
}
|
||||
});
|
||||
const weightBPercent = computed({
|
||||
get: () => (edit.value?.config.weightB ?? 0) / 100,
|
||||
set: (value: number | undefined) => {
|
||||
if (edit.value) edit.value.config.weightB = Math.round((value ?? 0) * 100);
|
||||
const groupTotal = computed(
|
||||
() => edit.value?.config.groups.reduce((sum, g) => sum + g.weight, 0) ?? 0
|
||||
);
|
||||
const groupKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
||||
/** 展示服务端按配置顺序累计的半开区间;仅解释首次自动分组,不覆盖稳定分组或人工指定。 */
|
||||
function groupRanges(groups: ExperimentGroup[]) {
|
||||
if (groups.reduce((sum, group) => sum + group.weight, 0) !== 10000)
|
||||
return "分组比例合计达到 100% 后显示区间";
|
||||
let start = 0;
|
||||
return groups
|
||||
.map(group => {
|
||||
const text =
|
||||
group.weight === 0
|
||||
? `${group.key}:0%,不参与自动分流`
|
||||
: `${group.key}:${start}~${start + group.weight - 1}`;
|
||||
start += group.weight;
|
||||
return text;
|
||||
})
|
||||
.join(";");
|
||||
}
|
||||
|
||||
/** 数字提交后更新万分比并联动两组,避免输入中间值导致控件回显与区间不同步。 */
|
||||
function setWeight(group: ExperimentGroup, percentage: number | undefined) {
|
||||
if (!edit.value) return;
|
||||
group.weight = Math.round((percentage ?? 0) * 100);
|
||||
if (edit.value.config.groups.length === 2) {
|
||||
const other = edit.value.config.groups.find(g => g.key !== group.key)!;
|
||||
other.weight = 10000 - group.weight;
|
||||
}
|
||||
});
|
||||
}
|
||||
function addGroup() {
|
||||
if (!edit.value || !editingType.value) return;
|
||||
const key = groupKeys.find(
|
||||
k => !edit.value!.config.groups.some(g => g.key === k)
|
||||
);
|
||||
if (key)
|
||||
edit.value.config.groups.push({
|
||||
key,
|
||||
weight: 0,
|
||||
value: JSON.parse(JSON.stringify(editingType.value.defaultValue))
|
||||
});
|
||||
}
|
||||
function removeGroup(key: string) {
|
||||
if (!edit.value || edit.value.config.groups.length <= 1) return;
|
||||
edit.value.config.groups = edit.value.config.groups.filter(
|
||||
g => g.key !== key
|
||||
);
|
||||
delete groupValid.value[key];
|
||||
}
|
||||
function distributeEvenly() {
|
||||
if (!edit.value) return;
|
||||
const groups = edit.value.config.groups;
|
||||
const each = Math.floor(10000 / groups.length),
|
||||
extra = 10000 % groups.length;
|
||||
groups.forEach((g, i) => {
|
||||
g.weight = each + (i < extra ? 1 : 0);
|
||||
});
|
||||
}
|
||||
function fillRemaining(group: ExperimentGroup) {
|
||||
group.weight = Math.max(0, 10000 - (groupTotal.value - group.weight));
|
||||
}
|
||||
function groupSummary(item: Experiment) {
|
||||
return item.config.groups.map(g => `${g.key} ${g.weight / 100}%`).join(" · ");
|
||||
}
|
||||
const editingType = computed(() =>
|
||||
scenes.value.find(s => s.id === edit.value?.scope)
|
||||
);
|
||||
@@ -112,23 +169,21 @@ const presetOptions = computed(() =>
|
||||
? presets.value.map(p => ({ label: p.name, value: p.id }))
|
||||
: undefined
|
||||
);
|
||||
/** 类型切换时重新初始化值,编辑历史方案时兼容旧预设字段。 */
|
||||
/** 类型切换只重置返回值,不改变用户已经配置的组别和比例。 */
|
||||
function initializeValues(reset = false) {
|
||||
if (!edit.value || !editingType.value) return;
|
||||
const t = editingType.value,
|
||||
c = edit.value.config;
|
||||
c.values = JSON.parse(
|
||||
JSON.stringify(
|
||||
t.contract.fixedValues ??
|
||||
(!reset && c.values
|
||||
? c.values
|
||||
: t.contract.optionsSource === "presets"
|
||||
? { A: c.presetA ?? "", B: c.presetB ?? "" }
|
||||
: { A: t.defaultValue, B: t.defaultValue })
|
||||
)
|
||||
);
|
||||
validA.value = true;
|
||||
validB.value = true;
|
||||
const type = editingType.value;
|
||||
for (const group of edit.value.config.groups) {
|
||||
if (reset || group.value === undefined)
|
||||
group.value = JSON.parse(
|
||||
JSON.stringify(
|
||||
type.valueType === "boolean" && group.key === "B"
|
||||
? !type.defaultValue
|
||||
: type.defaultValue
|
||||
)
|
||||
);
|
||||
}
|
||||
groupValid.value = {};
|
||||
}
|
||||
function users(item: Experiment) {
|
||||
router.push({
|
||||
@@ -173,27 +228,17 @@ function open(item?: Experiment) {
|
||||
audience: "all",
|
||||
accounts: [],
|
||||
traffic: 10000,
|
||||
weightB: 5000,
|
||||
baseline: "A",
|
||||
groups: [
|
||||
{ key: "A", weight: 5000, value: undefined },
|
||||
{ key: "B", weight: 5000, value: undefined }
|
||||
],
|
||||
description: ""
|
||||
}
|
||||
};
|
||||
edit.value.config.groups.sort((a, b) => a.key.localeCompare(b.key));
|
||||
initializeValues();
|
||||
editor.value = true;
|
||||
}
|
||||
function createTrial() {
|
||||
open();
|
||||
if (!edit.value) return;
|
||||
edit.value.name = "仅自己验收";
|
||||
edit.value.config.audience = "specified";
|
||||
edit.value.config.accounts = [];
|
||||
edit.value.config.traffic = 10000;
|
||||
edit.value.config.weightB = 10000;
|
||||
edit.value.config.description =
|
||||
"选择你创建并接入的实验类型,只选择自己的账号;在指定用户中切换A/B对照,验收完成后另建正式方案。";
|
||||
initializeValues(true);
|
||||
guideVisible.value = false;
|
||||
}
|
||||
async function save() {
|
||||
if (!edit.value?.scope) return ElMessage.warning("请先创建或选择实验类型");
|
||||
if (!edit.value?.name.trim()) return ElMessage.warning("请输入方案名称");
|
||||
@@ -207,8 +252,10 @@ async function save() {
|
||||
!edit.value.config.accounts.length
|
||||
)
|
||||
return ElMessage.warning("请选择至少一个入组账号,验收时先选择自己");
|
||||
if (!validA.value || !validB.value)
|
||||
return ElMessage.warning("请修正 A/B 返回值的 JSON 格式");
|
||||
if (groupTotal.value !== 10000)
|
||||
return ElMessage.warning("所有分组比例合计必须为 100%");
|
||||
if (Object.values(groupValid.value).some(valid => !valid))
|
||||
return ElMessage.warning("请修正分组返回值的 JSON 格式");
|
||||
saving.value = true;
|
||||
try {
|
||||
await digital(`experiments/${edit.value.id}`, "put", edit.value);
|
||||
@@ -224,15 +271,15 @@ async function save() {
|
||||
async function move(
|
||||
item: Experiment,
|
||||
state: "running" | "paused" | "finished",
|
||||
winner?: "A" | "B"
|
||||
winner?: string
|
||||
) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
state === "running"
|
||||
? `启动「${item.name}」?启动后人群、比例和方案将冻结。`
|
||||
: state === "paused"
|
||||
? "暂停后用户回到默认方案,已有分组保留。"
|
||||
: `结束后所有用户采用 ${winner} 方案,实验不能重新启动。`,
|
||||
? "暂停后用户使用类型默认返回值,已有分组保留。"
|
||||
: `结束后所有用户采用 ${winner} 组返回值,实验不能重新启动。`,
|
||||
state === "finished" ? "结束实验" : "确认状态变更",
|
||||
{ type: "warning", confirmButtonText: "确认", cancelButtonText: "取消" }
|
||||
);
|
||||
@@ -281,20 +328,21 @@ onMounted(load);
|
||||
<div>
|
||||
<h2>测试方案</h2>
|
||||
<p>
|
||||
配置测什么、给谁看、分配多少流量;账号查询与人工分组在「用户管理」。
|
||||
配置测什么、给谁看、分配多少流量;账号查询与人工分组在「实验用户分组」。
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<el-button @click="guideVisible = true">操作指南</el-button
|
||||
<el-button @click="router.push('/digital/experiments/guide')"
|
||||
>操作指南</el-button
|
||||
><el-button @click="router.push('/digital/experiment-types')"
|
||||
>实验类型</el-button
|
||||
><el-button @click="router.push('/digital/experiment-users')"
|
||||
>用户管理</el-button
|
||||
>实验用户分组</el-button
|
||||
><el-button type="primary" @click="open()">创建测试方案</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-alert
|
||||
title="第一次使用:先点「操作指南」,按“仅自己验收 → 正式实验 → 保留最终方案”走一遍。保存草稿不会改变前台,启动后才生效。"
|
||||
title="第一次使用:点击「操作指南」查看完整图文教程,按“仅自己验收 → 正式实验 → 保留最终结果”走一遍。保存草稿不会改变前台,启动后才生效。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
style="margin-bottom: 16px"
|
||||
@@ -312,7 +360,7 @@ onMounted(load);
|
||||
>
|
||||
</div>
|
||||
<el-alert
|
||||
title="同一类型消费标识只允许一个未结束方案。新老用户以账号创建时间与显式分界判定;暂停回默认方案,结束后固化最终方案。"
|
||||
title="同一类型消费标识只允许一个未结束方案。新老用户以账号创建时间与显式分界判定;暂停使用类型默认返回值,结束后保留所选组的返回值。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
style="margin-bottom: 20px"
|
||||
@@ -368,8 +416,9 @@ onMounted(load);
|
||||
><template #default="{ row }"
|
||||
><div>{{ audienceNames[row.config.audience] }}</div>
|
||||
<small class="secondary"
|
||||
>流量 {{ row.config.traffic / 100 }}% · B组
|
||||
{{ row.config.weightB / 100 }}%</small
|
||||
>实验流量 {{ row.config.traffic / 100 }}%<br />{{
|
||||
groupSummary(row)
|
||||
}}</small
|
||||
></template
|
||||
></el-table-column
|
||||
><el-table-column label="操作" min-width="260" fixed="right"
|
||||
@@ -402,16 +451,18 @@ onMounted(load);
|
||||
><el-button link type="danger">结束实验</el-button
|
||||
><template #dropdown
|
||||
><el-dropdown-menu
|
||||
><el-dropdown-item command="A">保留 A 方案</el-dropdown-item
|
||||
><el-dropdown-item command="B"
|
||||
>保留 B 方案</el-dropdown-item
|
||||
><el-dropdown-item
|
||||
v-for="group in row.config.groups"
|
||||
:key="group.key"
|
||||
:command="group.key"
|
||||
>保留 {{ group.key }} 组</el-dropdown-item
|
||||
></el-dropdown-menu
|
||||
></template
|
||||
></el-dropdown
|
||||
><el-button link type="primary" @click="inspect(row)"
|
||||
>效果与审计</el-button
|
||||
><el-button link type="primary" @click="users(row)"
|
||||
>用户管理</el-button
|
||||
>实验用户分组</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
></el-table
|
||||
@@ -422,14 +473,16 @@ onMounted(load);
|
||||
<el-dialog
|
||||
v-model="editor"
|
||||
title="测试方案草稿"
|
||||
width="min(720px,95vw)"
|
||||
class="experiment-dialog"
|
||||
top="5vh"
|
||||
width="min(880px,95vw)"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
><el-form v-if="edit" label-position="top"
|
||||
><el-form-item label="名称" required
|
||||
><el-input v-model="edit.name" maxlength="120"
|
||||
/></el-form-item>
|
||||
><el-form v-if="edit" label-position="top">
|
||||
<div class="form-grid">
|
||||
<el-form-item label="名称" required
|
||||
><el-input v-model="edit.name" maxlength="120"
|
||||
/></el-form-item>
|
||||
<el-form-item label="实验类型"
|
||||
><el-select
|
||||
v-model="edit.scope"
|
||||
@@ -440,19 +493,14 @@ onMounted(load);
|
||||
:key="s.id"
|
||||
:value="s.id"
|
||||
:label="s.name"
|
||||
:disabled="!s.enabled" /></el-select></el-form-item
|
||||
><el-form-item label="默认方案"
|
||||
><el-select v-model="edit.config.baseline"
|
||||
><el-option label="A 方案" value="A" /><el-option
|
||||
label="B 方案"
|
||||
value="B" /></el-select
|
||||
:disabled="!s.enabled" /></el-select
|
||||
></el-form-item>
|
||||
</div>
|
||||
<el-form-item label="实验目标与验收指标"
|
||||
><el-input
|
||||
v-model="edit.config.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:rows="2"
|
||||
placeholder="例如:观察首次聊天转化和用户反馈,确认新版交互是否改善体验。" /></el-form-item
|
||||
><el-divider content-position="left">实验人群</el-divider
|
||||
><el-form-item label="入组范围"
|
||||
@@ -496,60 +544,166 @@ onMounted(load);
|
||||
:label="`${a.name} (${a.account})`"
|
||||
:value="a.account" /></el-select
|
||||
></el-form-item>
|
||||
<div class="form-grid">
|
||||
<el-form-item label="进入实验的流量(%)"
|
||||
><el-input-number
|
||||
v-model="trafficPercent"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
:step="1"
|
||||
/><small>{{ edit.config.traffic / 100 }}%</small></el-form-item
|
||||
><el-form-item label="入组后 B 组比例(%)"
|
||||
><el-input-number
|
||||
v-model="weightBPercent"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
:step="1"
|
||||
/><small
|
||||
>A {{ (10000 - edit.config.weightB) / 100 }}% / B
|
||||
{{ edit.config.weightB / 100 }}%</small
|
||||
></el-form-item
|
||||
>
|
||||
</div>
|
||||
<template v-if="editingType && edit.config.values">
|
||||
<el-divider content-position="left">A/B 返回值</el-divider>
|
||||
<div class="form-grid">
|
||||
<el-form-item
|
||||
v-for="group in ['A', 'B'] as const"
|
||||
:key="group"
|
||||
:label="`${group} 组${editingType.contract.labels?.[group] ? ' · ' + editingType.contract.labels[group] : ''}`"
|
||||
required
|
||||
<el-form-item label="进入实验的流量(%)">
|
||||
<el-input-number
|
||||
v-model="trafficPercent"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
:step="1"
|
||||
/>
|
||||
<p class="secondary">
|
||||
目标人群中有多少人参与实验;未参与的用户使用类型默认返回值。
|
||||
</p>
|
||||
</el-form-item>
|
||||
<section class="group-config" aria-label="分组配置">
|
||||
<div class="group-heading">
|
||||
<strong>分组配置</strong>
|
||||
<el-tag
|
||||
:type="groupTotal === 10000 ? 'success' : 'danger'"
|
||||
role="status"
|
||||
>合计 {{ (groupTotal / 100).toFixed(2) }}% / 100%</el-tag
|
||||
>
|
||||
</div>
|
||||
<p class="secondary">
|
||||
默认 A、B 两组,可添加到 Z。0%
|
||||
组不会自动分流,仍可人工指定;返回值不因比例改变。
|
||||
</p>
|
||||
<div class="allocation-rule">
|
||||
<strong>分组方式:按账号稳定随机分配</strong>
|
||||
<p>
|
||||
账号标识与本次测试方案 ID 共同算出固定的 0~9999
|
||||
数字,落在哪个区间就进入哪组。
|
||||
</p>
|
||||
<p class="allocation-ranges">
|
||||
当前自动分组区间:{{ groupRanges(edit.config.groups) }}
|
||||
</p>
|
||||
<p>
|
||||
首次实际入组后保存分组,刷新、重新登录仍保持同组;有效的人工指定优先。比例是分配概率,不保证小样本人数恰好相等。
|
||||
</p>
|
||||
<el-collapse>
|
||||
<el-collapse-item
|
||||
title="查看具体计算步骤与优先顺序"
|
||||
name="algorithm"
|
||||
>
|
||||
<ol class="allocation-steps">
|
||||
<li>
|
||||
先检查入组范围。“所有用户”表示所有账号都有资格参与,不按性别、年龄或账号尾号分组。
|
||||
</li>
|
||||
<li>
|
||||
符合人群或获准越过人群限制的有效人工指定,直接使用指定组;否则已保存的稳定分组优先。
|
||||
</li>
|
||||
<li>
|
||||
首次自动分配先计算流量桶,数字小于“进入实验的流量 ×
|
||||
100”才入组;未入组使用类型默认返回值。
|
||||
</li>
|
||||
<li>
|
||||
入组后另算分组桶,按上方各组比例的累计区间分配。流量桶和分组桶独立,0%组不接收自动流量。
|
||||
</li>
|
||||
</ol>
|
||||
<p>
|
||||
技术算法:SHA-256
|
||||
处理下方字符串,取摘要前4字节的无符号大端整数,再对10000取余。
|
||||
</p>
|
||||
<code>dh-v1\0{用途}\0{测试方案ID}\0{账号标识}</code>
|
||||
<p>
|
||||
用途分别为 traffic(流量)和 variant(分组);\0
|
||||
为分隔符。账号标识包含账号类型与ID。新建方案的ID不同,同一账号可能分到不同组。
|
||||
</p>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</div>
|
||||
<el-table :data="edit.config.groups" row-key="key">
|
||||
<el-table-column label="组别" width="70"
|
||||
><template #default="{ row }"
|
||||
><el-tag type="info">{{ row.key }}</el-tag></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="分流比例(%)" width="200"
|
||||
><template #default="{ row }">
|
||||
<el-input-number
|
||||
:model-value="row.weight / 100"
|
||||
:aria-label="`${row.key}组分流比例`"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
:step="1"
|
||||
@change="v => setWeight(row, v)"
|
||||
/>
|
||||
<el-button
|
||||
v-if="groupTotal < 10000"
|
||||
link
|
||||
type="primary"
|
||||
@click="fillRemaining(row)"
|
||||
>补足剩余</el-button
|
||||
>
|
||||
</template></el-table-column
|
||||
>
|
||||
<el-table-column label="返回值" min-width="220"
|
||||
><template #default="{ row }">
|
||||
<ExperimentValue
|
||||
v-if="editingType"
|
||||
:key="editingType.id + row.key"
|
||||
v-model="row.value"
|
||||
:kind="editingType.valueType"
|
||||
:options="presetOptions"
|
||||
@valid="v => (groupValid[row.key] = v)"
|
||||
/>
|
||||
<span v-else class="secondary">请先选择实验类型</span>
|
||||
</template></el-table-column
|
||||
>
|
||||
<el-table-column label="操作" width="85"
|
||||
><template #default="{ row }"
|
||||
><el-button
|
||||
link
|
||||
type="danger"
|
||||
:disabled="edit.config.groups.length <= 1"
|
||||
:aria-label="`删除${row.key}组`"
|
||||
@click="removeGroup(row.key)"
|
||||
>删除</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<div class="group-actions">
|
||||
<el-button
|
||||
:disabled="!editingType || edit.config.groups.length >= 26"
|
||||
@click="addGroup"
|
||||
>添加分组</el-button
|
||||
><el-button @click="distributeEvenly">平均分配</el-button
|
||||
><span class="secondary"
|
||||
>{{ edit.config.groups.length }} / 26 组</span
|
||||
>
|
||||
<ExperimentValue
|
||||
:key="editingType.id + group"
|
||||
v-model="edit.config.values[group]"
|
||||
:kind="editingType.valueType"
|
||||
:options="presetOptions"
|
||||
:disabled="!!editingType.contract.fixedValues"
|
||||
@valid="v => (group === 'A' ? (validA = v) : (validB = v))"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="editingType.integrationState !== 'confirmed'"
|
||||
type="warning"
|
||||
title="该类型还未完成应用接入验收,可以保存草稿;请到「实验类型 → 接入与验收」完成后再启动。"
|
||||
v-if="groupTotal !== 10000"
|
||||
type="error"
|
||||
:closable="false"
|
||||
title="请调整各组比例,合计达到 100% 后才能保存。"
|
||||
/>
|
||||
</template>
|
||||
</section>
|
||||
<el-alert
|
||||
v-if="editingType && editingType.integrationState !== 'confirmed'"
|
||||
type="warning"
|
||||
title="该类型尚未完成应用接入验收,可以保存草稿;完成接入与验收后才能启动。"
|
||||
:closable="false" />
|
||||
<p v-if="editingType" class="secondary">
|
||||
未参与实验或实验暂停时,返回类型默认值:{{
|
||||
JSON.stringify(editingType.defaultValue)
|
||||
}},不属于任何实验组。
|
||||
</p>
|
||||
<el-alert
|
||||
title="启动前请核对人群和比例。启动后规则冻结,需要新规则时创建下一条实验。"
|
||||
:closable="false" /></el-form
|
||||
><template #footer
|
||||
><el-button @click="editor = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="save"
|
||||
><el-button
|
||||
type="primary"
|
||||
:loading="saving"
|
||||
:disabled="
|
||||
groupTotal !== 10000 || Object.values(groupValid).some(v => !v)
|
||||
"
|
||||
@click="save"
|
||||
>保存草稿</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
@@ -565,13 +719,36 @@ onMounted(load);
|
||||
><span>{{ sceneName(selected.scope) }}</span
|
||||
><small>版本 {{ selected.revision }}</small>
|
||||
</div>
|
||||
<div class="allocation-rule">
|
||||
<strong>分组方式:按账号稳定随机分配</strong>
|
||||
<p>
|
||||
账号标识与本次方案 ID 计算固定的 0~9999
|
||||
数字,按累计比例区间首次分组;已保存的稳定分组保留,有效人工指定优先。
|
||||
</p>
|
||||
<p class="allocation-ranges">
|
||||
当前自动分组区间:{{ groupRanges(selected.config.groups) }}
|
||||
</p>
|
||||
</div>
|
||||
<el-table :data="selected.config.groups" class="group-details">
|
||||
<el-table-column prop="key" label="组别" width="80" />
|
||||
<el-table-column label="分流比例" width="120"
|
||||
><template #default="{ row }"
|
||||
>{{ row.weight / 100 }}%</template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="返回值"
|
||||
><template #default="{ row }"
|
||||
><code>{{ JSON.stringify(row.value) }}</code></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-tabs v-model="detailTab"
|
||||
><el-tab-pane label="效果概览" name="metrics"
|
||||
><el-alert
|
||||
title="只统计实际入组流量,人工指定单列。曝光在可见页面渲染后记录,漏斗按服务端决策归因;仅作描述性统计。"
|
||||
type="info"
|
||||
:closable="false" /><el-table :data="details?.metrics ?? []"
|
||||
><el-table-column prop="variant" label="方案" /><el-table-column
|
||||
><el-table-column prop="variant" label="组别" /><el-table-column
|
||||
label="人群"
|
||||
><template #default="{ row }">{{
|
||||
row.cohort === "manual" ? "人工指定" : "规则分组"
|
||||
@@ -590,7 +767,7 @@ onMounted(load);
|
||||
description="尚无决策记录" />
|
||||
<h3 style="margin: 24px 0 12px">使用漏斗</h3>
|
||||
<el-table :data="details?.funnel ?? []"
|
||||
><el-table-column prop="variant" label="方案" /><el-table-column
|
||||
><el-table-column prop="variant" label="组别" /><el-table-column
|
||||
label="人群"
|
||||
><template #default="{ row }">{{
|
||||
row.cohort === "manual" ? "人工指定" : "规则分组"
|
||||
@@ -622,75 +799,70 @@ onMounted(load);
|
||||
></template
|
||||
></el-drawer
|
||||
>
|
||||
<el-dialog
|
||||
v-model="guideVisible"
|
||||
title="实验全流程操作指南"
|
||||
width="min(760px,95vw)"
|
||||
><ol class="workflow-guide">
|
||||
<li>
|
||||
<strong>实验类型:定义测什么</strong>
|
||||
<p>
|
||||
侧栏「实验类型 →
|
||||
创建实验类型」,填写你自己的稳定标识、数据格式和默认值。系统不预置实验类型;先在应用读取决策并使用返回值,再到「接入与验收」确认效果。
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<strong>测试方案:定义怎么测</strong>
|
||||
<p>
|
||||
选择类型,配置 A/B 返回值、人群与百分比。100% 流量、B 组 50%
|
||||
表示所有入组用户 A/B
|
||||
各一半。保存只是草稿,启动才生效;启动后规则冻结。
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<strong>用户管理:查看与指定谁</strong>
|
||||
<p>
|
||||
从方案行点击「用户管理」,搜索账号,查看只读分组预览。点击「指定分组」可指定
|
||||
A/B、有效期与原因;「恢复自动」取消人工指定,回到原稳定分组。预览本身不会分配用户或产生曝光。
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<strong>先自己验收,再正式分流</strong>
|
||||
<p>
|
||||
选择你已接入的类型,指定名单只选自己,流量 100%、B 组
|
||||
100%,启动后在应用检查 B 组效果。再到用户管理指定 A/B
|
||||
对照。其他账号按默认组。验收完成另建正式方案。
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<strong>效果、暂停与结束</strong>
|
||||
<p>
|
||||
在「效果与审计」查看决策、曝光、漏斗和操作记录。暂停回方案默认组,恢复保留原分组;结束时选择最终
|
||||
A/B,之后对所有用户长期生效。新类型须在消费者实际展示后调用曝光接口,不能把决策请求当作曝光。
|
||||
</p>
|
||||
</li>
|
||||
</ol>
|
||||
<el-alert
|
||||
title="所有管理入口都在后台。前台只读取当前用户的决策,不提供实验控制。"
|
||||
:closable="false"
|
||||
/><template #footer
|
||||
><el-button @click="guideVisible = false">知道了</el-button
|
||||
><el-button type="primary" @click="createTrial"
|
||||
>按“仅自己验收”示例创建</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.workflow-guide {
|
||||
padding-left: 22px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.workflow-guide li {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.workflow-guide p {
|
||||
margin: 6px 0;
|
||||
.allocation-rule {
|
||||
padding: 12px 14px;
|
||||
margin: 12px 0;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.7;
|
||||
background: var(--el-fill-color-light);
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.allocation-rule p {
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.allocation-ranges {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.allocation-rule code {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.allocation-steps {
|
||||
padding-left: 20px;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
:global(.experiment-dialog) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 90vh;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
:global(.experiment-dialog .el-dialog__body) {
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.group-details {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.group-config {
|
||||
margin: 8px 0 20px;
|
||||
}
|
||||
|
||||
.group-heading,
|
||||
.group-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.group-heading {
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.group-actions {
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.heading {
|
||||
|
||||
@@ -0,0 +1,609 @@
|
||||
<script setup lang="ts">
|
||||
/** 独立 C 端用户管理:开户、停用、重置密码及按用户查看持久化聊天记录。 */
|
||||
import { onMounted, ref } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import {
|
||||
digital,
|
||||
type DigitalUser,
|
||||
type UserConversation,
|
||||
type UserChatMessage
|
||||
} from "@/api/access";
|
||||
const q = ref(""),
|
||||
status = ref(""),
|
||||
page = ref(1),
|
||||
total = ref(0),
|
||||
loading = ref(false),
|
||||
users = ref<DigitalUser[]>([]);
|
||||
const creating = ref(false),
|
||||
saving = ref(false),
|
||||
createForm = ref({ username: "", displayName: "", password: "" });
|
||||
const editing = ref<DigitalUser | null>(null),
|
||||
editForm = ref({ displayName: "", status: "ACTIVE" });
|
||||
const resetTarget = ref<DigitalUser | null>(null),
|
||||
newPassword = ref("");
|
||||
const selected = ref<DigitalUser | null>(null),
|
||||
history = ref(false),
|
||||
conversations = ref<UserConversation[]>([]),
|
||||
conversationPage = ref(1),
|
||||
conversationTotal = ref(0),
|
||||
conversationLoading = ref(false);
|
||||
const active = ref<UserConversation | null>(null),
|
||||
messages = ref<UserChatMessage[]>([]),
|
||||
messagePage = ref(1),
|
||||
messageTotal = ref(0),
|
||||
messageLoading = ref(false);
|
||||
let listVersion = 0,
|
||||
chatVersion = 0,
|
||||
messageVersion = 0;
|
||||
const time = (value: string | null) =>
|
||||
value ? new Date(value).toLocaleString() : "—";
|
||||
const states: Record<string, string> = {
|
||||
complete: "已完成",
|
||||
stopped: "已停止",
|
||||
failed: "生成失败",
|
||||
generating: "生成中",
|
||||
superseded: "旧版本"
|
||||
};
|
||||
/** 请求编号避免快速切换用户时把旧请求结果写进新用户的聊天面板。 */
|
||||
async function load() {
|
||||
const version = ++listVersion;
|
||||
loading.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
q: q.value,
|
||||
page: String(page.value),
|
||||
size: "20"
|
||||
});
|
||||
if (status.value) params.set("status", status.value);
|
||||
const r = await digital<{ items: DigitalUser[]; total: number }>(
|
||||
`users?${params}`
|
||||
);
|
||||
if (version === listVersion) {
|
||||
users.value = r.items;
|
||||
total.value = r.total;
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : "加载失败");
|
||||
} finally {
|
||||
if (version === listVersion) loading.value = false;
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
page.value = 1;
|
||||
load();
|
||||
}
|
||||
async function create() {
|
||||
if (
|
||||
!createForm.value.username.trim() ||
|
||||
!createForm.value.displayName.trim() ||
|
||||
createForm.value.password.length < 8
|
||||
)
|
||||
return ElMessage.warning("请填写账号、昵称及至少8位密码");
|
||||
saving.value = true;
|
||||
try {
|
||||
await digital("users", "post", createForm.value);
|
||||
creating.value = false;
|
||||
createForm.value = { username: "", displayName: "", password: "" };
|
||||
search();
|
||||
ElMessage.success("C 端账号已创建,可在星港前台登录");
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : "创建失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
function edit(user: DigitalUser) {
|
||||
editing.value = user;
|
||||
editForm.value = { displayName: user.displayName, status: user.status };
|
||||
}
|
||||
async function saveEdit() {
|
||||
if (!editing.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await digital(`users/${editing.value.id}`, "patch", editForm.value);
|
||||
editing.value = null;
|
||||
await load();
|
||||
ElMessage.success("用户资料已保存");
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : "保存失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
async function resetPassword() {
|
||||
if (!resetTarget.value) return;
|
||||
if (newPassword.value.length < 8) return ElMessage.warning("密码至少8位");
|
||||
saving.value = true;
|
||||
try {
|
||||
await digital(`users/${resetTarget.value.id}/password`, "post", {
|
||||
password: newPassword.value
|
||||
});
|
||||
newPassword.value = "";
|
||||
resetTarget.value = null;
|
||||
ElMessage.success("密码已重置,该用户需要重新登录");
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : "重置失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
async function openHistory(user: DigitalUser) {
|
||||
selected.value = user;
|
||||
history.value = true;
|
||||
conversationPage.value = 1;
|
||||
active.value = null;
|
||||
messages.value = [];
|
||||
++messageVersion;
|
||||
await loadConversations();
|
||||
}
|
||||
async function loadConversations() {
|
||||
if (!selected.value) return;
|
||||
const version = ++chatVersion;
|
||||
conversationLoading.value = true;
|
||||
conversations.value = [];
|
||||
try {
|
||||
const r = await digital<{ items: UserConversation[]; total: number }>(
|
||||
`users/${selected.value.id}/conversations?page=${conversationPage.value}&size=20`
|
||||
);
|
||||
if (version === chatVersion) {
|
||||
conversations.value = r.items;
|
||||
conversationTotal.value = r.total;
|
||||
}
|
||||
} catch (e) {
|
||||
if (version === chatVersion)
|
||||
ElMessage.error(e instanceof Error ? e.message : "会话加载失败");
|
||||
} finally {
|
||||
if (version === chatVersion) conversationLoading.value = false;
|
||||
}
|
||||
}
|
||||
async function chooseConversation(c: UserConversation) {
|
||||
active.value = c;
|
||||
messagePage.value = 1;
|
||||
await loadMessages();
|
||||
}
|
||||
async function loadMessages() {
|
||||
if (!selected.value || !active.value) return;
|
||||
const version = ++messageVersion;
|
||||
messageLoading.value = true;
|
||||
messages.value = [];
|
||||
try {
|
||||
const r = await digital<{ items: UserChatMessage[]; total: number }>(
|
||||
`users/${selected.value.id}/conversations/${active.value.id}/messages?page=${messagePage.value}&size=30`
|
||||
);
|
||||
if (version === messageVersion) {
|
||||
messages.value = r.items;
|
||||
messageTotal.value = r.total;
|
||||
}
|
||||
} catch (e) {
|
||||
if (version === messageVersion)
|
||||
ElMessage.error(e instanceof Error ? e.message : "聊天记录加载失败");
|
||||
} finally {
|
||||
if (version === messageVersion) messageLoading.value = false;
|
||||
}
|
||||
}
|
||||
function closeHistory() {
|
||||
++chatVersion;
|
||||
++messageVersion;
|
||||
selected.value = null;
|
||||
active.value = null;
|
||||
messages.value = [];
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="customer-page">
|
||||
<div class="heading">
|
||||
<div>
|
||||
<h2>用户管理</h2>
|
||||
<p>C 端账号独立于后台管理员,由后台开通。聊天记录按用户和会话查看。</p>
|
||||
</div>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="
|
||||
createForm = { username: '', displayName: '', password: '' };
|
||||
creating = true;
|
||||
"
|
||||
>创建 C 端用户</el-button
|
||||
>
|
||||
</div>
|
||||
<el-card shadow="never"
|
||||
><div class="filters">
|
||||
<el-input
|
||||
v-model="q"
|
||||
clearable
|
||||
placeholder="搜索账号、昵称或用户 ID"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
/><el-select
|
||||
v-model="status"
|
||||
clearable
|
||||
placeholder="全部状态"
|
||||
@change="search"
|
||||
><el-option value="ACTIVE" label="正常" /><el-option
|
||||
value="INACTIVE"
|
||||
label="已停用" /></el-select
|
||||
><el-button :loading="loading" @click="search">查询</el-button>
|
||||
</div>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="users"
|
||||
empty-text="暂无 C 端用户,可点击上方创建"
|
||||
><el-table-column label="用户" min-width="220"
|
||||
><template #default="{ row }"
|
||||
><strong>{{ row.displayName }}</strong>
|
||||
<p class="secondary">
|
||||
{{ row.username }} · UID {{ row.id }}
|
||||
</p></template
|
||||
></el-table-column
|
||||
><el-table-column label="状态" width="100"
|
||||
><template #default="{ row }"
|
||||
><el-tag :type="row.status === 'ACTIVE' ? 'success' : 'info'">{{
|
||||
row.status === "ACTIVE" ? "正常" : "已停用"
|
||||
}}</el-tag></template
|
||||
></el-table-column
|
||||
><el-table-column
|
||||
prop="conversations"
|
||||
label="会话数"
|
||||
width="90"
|
||||
/><el-table-column
|
||||
prop="messages"
|
||||
label="消息数"
|
||||
width="90"
|
||||
/><el-table-column label="创建时间" min-width="175"
|
||||
><template #default="{ row }">{{
|
||||
time(row.createdAt)
|
||||
}}</template></el-table-column
|
||||
><el-table-column label="最近登录" min-width="175"
|
||||
><template #default="{ row }">{{
|
||||
time(row.lastLoginAt)
|
||||
}}</template></el-table-column
|
||||
><el-table-column label="操作" min-width="235" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button link type="primary" @click="openHistory(row)"
|
||||
>聊天记录</el-button
|
||||
><el-button link type="primary" @click="edit(row)">编辑</el-button
|
||||
><el-button
|
||||
link
|
||||
type="warning"
|
||||
@click="
|
||||
resetTarget = row;
|
||||
newPassword = '';
|
||||
"
|
||||
>重置密码</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
></el-table
|
||||
>
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
:page-size="20"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</el-card>
|
||||
<el-dialog
|
||||
v-model="creating"
|
||||
title="创建 C 端用户"
|
||||
width="min(520px,95vw)"
|
||||
:close-on-click-modal="false"
|
||||
><el-form label-position="top"
|
||||
><el-form-item label="登录账号" required
|
||||
><el-input
|
||||
v-model="createForm.username"
|
||||
maxlength="120"
|
||||
placeholder="字母、数字、手机号或邮箱"
|
||||
autocomplete="off" /></el-form-item
|
||||
><el-form-item label="用户昵称" required
|
||||
><el-input
|
||||
v-model="createForm.displayName"
|
||||
maxlength="120" /></el-form-item
|
||||
><el-form-item label="初始密码" required
|
||||
><el-input
|
||||
v-model="createForm.password"
|
||||
type="password"
|
||||
show-password
|
||||
maxlength="128"
|
||||
placeholder="至少8位"
|
||||
autocomplete="new-password" /></el-form-item></el-form
|
||||
><template #footer
|
||||
><el-button @click="creating = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="create"
|
||||
>创建用户</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
>
|
||||
<el-dialog
|
||||
:model-value="!!editing"
|
||||
title="编辑 C 端用户"
|
||||
width="min(520px,95vw)"
|
||||
@close="editing = null"
|
||||
><el-form label-position="top"
|
||||
><el-form-item label="登录账号">{{ editing?.username }}</el-form-item
|
||||
><el-form-item label="用户昵称"
|
||||
><el-input
|
||||
v-model="editForm.displayName"
|
||||
maxlength="120" /></el-form-item
|
||||
><el-form-item label="账号状态"
|
||||
><el-radio-group v-model="editForm.status"
|
||||
><el-radio value="ACTIVE">正常</el-radio
|
||||
><el-radio value="INACTIVE">停用</el-radio></el-radio-group
|
||||
></el-form-item
|
||||
></el-form
|
||||
><el-alert
|
||||
title="停用后用户无法登录,已有会话记录仍保留。"
|
||||
:closable="false"
|
||||
/><template #footer
|
||||
><el-button @click="editing = null">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="saveEdit"
|
||||
>保存</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
>
|
||||
<el-dialog
|
||||
:model-value="!!resetTarget"
|
||||
title="重置 C 端用户密码"
|
||||
width="min(520px,95vw)"
|
||||
@close="
|
||||
resetTarget = null;
|
||||
newPassword = '';
|
||||
"
|
||||
><p>{{ resetTarget?.displayName }} · {{ resetTarget?.username }}</p>
|
||||
<el-input
|
||||
v-model="newPassword"
|
||||
type="password"
|
||||
show-password
|
||||
maxlength="128"
|
||||
autocomplete="new-password"
|
||||
placeholder="设置至少8位新密码"
|
||||
/>
|
||||
<p class="secondary">
|
||||
重置后该 C 端账号的旧登录状态失效,不影响同名后台账号。
|
||||
</p>
|
||||
<template #footer
|
||||
><el-button @click="resetTarget = null">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="resetPassword"
|
||||
>确认重置</el-button
|
||||
></template
|
||||
></el-dialog
|
||||
>
|
||||
<el-dialog
|
||||
v-model="history"
|
||||
:title="`${selected?.displayName ?? ''} · 聊天记录`"
|
||||
width="min(1280px,96vw)"
|
||||
top="4vh"
|
||||
@closed="closeHistory"
|
||||
>
|
||||
<div class="history-layout">
|
||||
<aside v-loading="conversationLoading" class="conversation-list">
|
||||
<p class="secondary">
|
||||
{{ selected?.username }} · {{ conversationTotal }} 个会话
|
||||
</p>
|
||||
<el-empty
|
||||
v-if="!conversations.length && !conversationLoading"
|
||||
description="暂无聊天记录"
|
||||
/><button
|
||||
v-for="c in conversations"
|
||||
:key="c.id"
|
||||
class="conversation"
|
||||
:class="{ active: active?.id === c.id }"
|
||||
@click="chooseConversation(c)"
|
||||
>
|
||||
<strong>{{ c.characterName }}</strong
|
||||
><span>{{ c.title }}</span
|
||||
><small
|
||||
>{{ c.messages }} 条消息 · {{ time(c.updatedAt) }}</small
|
||||
></button
|
||||
><el-pagination
|
||||
v-model:current-page="conversationPage"
|
||||
small
|
||||
:page-size="20"
|
||||
:total="conversationTotal"
|
||||
layout="prev, pager, next"
|
||||
@current-change="loadConversations"
|
||||
/>
|
||||
</aside>
|
||||
<section v-loading="messageLoading" class="message-pane">
|
||||
<template v-if="active"
|
||||
><header>
|
||||
<strong>{{ active.characterName }} · {{ active.title }}</strong
|
||||
><el-button size="small" @click="loadMessages"
|
||||
>刷新记录</el-button
|
||||
>
|
||||
</header>
|
||||
<p class="secondary">
|
||||
第1页为最新记录,每页按发送顺序展示;较早内容可翻页查看。共
|
||||
{{ messageTotal }} 条。
|
||||
</p>
|
||||
<div class="messages">
|
||||
<el-empty
|
||||
v-if="!messages.length && !messageLoading"
|
||||
description="此会话尚无消息"
|
||||
/>
|
||||
<article v-for="m in messages" :key="m.id" :class="m.role">
|
||||
<div class="message-meta">
|
||||
<strong>{{
|
||||
m.role === "user"
|
||||
? selected?.displayName
|
||||
: active.characterName
|
||||
}}</strong
|
||||
><time>{{ time(m.createdAt) }}</time
|
||||
><el-tag
|
||||
v-if="m.status !== 'complete'"
|
||||
size="small"
|
||||
type="info"
|
||||
>{{ states[m.status] ?? m.status }}</el-tag
|
||||
><el-tag v-if="m.pinned" size="small">已固定</el-tag>
|
||||
</div>
|
||||
<p>{{ m.content || "(未生成正文)" }}</p>
|
||||
</article>
|
||||
</div>
|
||||
<el-pagination
|
||||
v-model:current-page="messagePage"
|
||||
:page-size="30"
|
||||
:total="messageTotal"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadMessages" /></template
|
||||
><el-empty v-else description="选择左侧会话查看聊天内容" />
|
||||
</section>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.heading,
|
||||
.filters,
|
||||
.message-pane header {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.secondary,
|
||||
.heading p {
|
||||
margin: 6px 0;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.filters .el-input {
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.filters .el-select {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.el-pagination {
|
||||
justify-content: flex-end;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.history-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 280px minmax(0, 1fr);
|
||||
gap: 20px;
|
||||
height: 72vh;
|
||||
}
|
||||
|
||||
.conversation-list,
|
||||
.message-pane {
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
padding-right: 12px;
|
||||
border-right: 1px solid var(--el-border-color-light);
|
||||
}
|
||||
|
||||
.conversation {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
padding: 14px 10px;
|
||||
color: var(--el-text-color-primary);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.conversation.active {
|
||||
color: var(--el-color-primary);
|
||||
background: var(--el-color-primary-light-9);
|
||||
}
|
||||
|
||||
.conversation small {
|
||||
font-size: 11px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.message-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.message-pane header {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.messages {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 8px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.messages article {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.message-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.message-meta time {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.messages article p {
|
||||
padding: 12px 14px;
|
||||
margin: 6px 0;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.messages article.user p {
|
||||
background: var(--el-color-primary-light-9);
|
||||
}
|
||||
|
||||
.conversation:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
@media (width<=760px) {
|
||||
.heading,
|
||||
.filters {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.filters .el-input,
|
||||
.filters .el-select {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.history-layout {
|
||||
grid-template-rows: 180px minmax(0, 1fr);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
padding-right: 0;
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--el-border-color-light);
|
||||
}
|
||||
}
|
||||
</style>
|
||||