Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5677b5109 | |||
| 5dc709865a | |||
| 9b10b6b4c2 | |||
| 98ddd137e0 | |||
| 48aac171dd | |||
| 0b7c1cba24 | |||
| 643f1b76b8 | |||
| 4c35e50270 | |||
| 3e78e79971 | |||
| 41bf7d8bae |
@@ -62,7 +62,7 @@ http://localhost:8848/
|
|||||||
├── src/ # 前端源码
|
├── src/ # 前端源码
|
||||||
│ ├── api/ # HTTP API 封装,业务接口集中在 access.ts
|
│ ├── api/ # HTTP API 封装,业务接口集中在 access.ts
|
||||||
│ ├── assets/ # 图片、SVG、iconfont 等静态资源
|
│ ├── assets/ # 图片、SVG、iconfont 等静态资源
|
||||||
│ ├── components/ # 模板沉淀的通用组件
|
│ ├── components/ # 通用组件,DigitalMessageText.vue 提供对白/叙述预览与聊天记录展示
|
||||||
│ ├── config/ # 读取 public/platform-config.json 的运行时配置
|
│ ├── config/ # 读取 public/platform-config.json 的运行时配置
|
||||||
│ ├── directives/ # 自定义指令,如权限、复制、长按、波纹
|
│ ├── directives/ # 自定义指令,如权限、复制、长按、波纹
|
||||||
│ ├── layout/ # 后台布局、菜单、标签页、导航栏与布局 hooks
|
│ ├── layout/ # 后台布局、菜单、标签页、导航栏与布局 hooks
|
||||||
@@ -70,11 +70,12 @@ http://localhost:8848/
|
|||||||
│ ├── router/ # 静态路由、剩余路由、路由实例与守卫
|
│ ├── router/ # 静态路由、剩余路由、路由实例与守卫
|
||||||
│ ├── store/ # Pinia store,含用户、权限、标签页、主题等模块
|
│ ├── store/ # Pinia store,含用户、权限、标签页、主题等模块
|
||||||
│ ├── style/ # 全局样式、主题、暗色模式、侧边栏和过渡样式
|
│ ├── style/ # 全局样式、主题、暗色模式、侧边栏和过渡样式
|
||||||
│ ├── utils/ # 鉴权、HTTP、缓存、消息、进度条、树处理等工具
|
│ ├── utils/ # 鉴权、HTTP、缓存及 digital-message-format.ts 受限文本解析
|
||||||
│ └── views/
|
│ └── views/
|
||||||
│ ├── digital/ # 内容库、实验类型、测试方案和用户分组
|
│ ├── digital/ # 内容库、实验类型、测试方案和用户分组
|
||||||
│ └── ... # 原门店与员工业务兼容页面
|
│ └── ... # 原门店与员工业务兼容页面
|
||||||
├── types/ # 全局类型声明、组件声明、路由声明和 Vue shim
|
├── types/ # 全局类型声明、组件声明、路由声明和 Vue shim
|
||||||
|
├── tests/ # 数字人对白/叙述格式回归,与 role-user 使用相同用例
|
||||||
├── AGENTS.md # Codex/Agent 入口规则,转到 RTK.md 并登记本地 skill
|
├── AGENTS.md # Codex/Agent 入口规则,转到 RTK.md 并登记本地 skill
|
||||||
├── RTK.md # 本仓库协作规则与 README 同步要求
|
├── RTK.md # 本仓库协作规则与 README 同步要求
|
||||||
├── Dockerfile # 容器构建入口
|
├── Dockerfile # 容器构建入口
|
||||||
@@ -214,10 +215,14 @@ pnpm build
|
|||||||
|
|
||||||
## 数字人运营
|
## 数字人运营
|
||||||
|
|
||||||
|
角色「人格与开场」提供对白/叙述格式说明和首次问候、示例对白、其他开场的实时预览,预览替换角色/用户占位符但不修改原文。生成预设始终遵守系统统一排版:`*叙述*` 与 `“对白”`,切换时空一行。用户管理的聊天记录也使用 `DigitalMessageText.vue`,用户原文保持纯文本,角色消息兼容旧括号与引号。
|
||||||
|
|
||||||
|
`src/utils/digital-message-format.ts` 与 `role-user/src/lib/digital-message-format.ts` 保持同一实现和用例,两仓独立构建。所有内容通过文本节点展示,不使用 HTML 注入。执行 `node --experimental-strip-types --test tests/*.test.mjs` 验证协议兼容。
|
||||||
|
|
||||||
- `src/views/digital/content.vue`:角色卡、世界书、预设,草稿/发布/下架,JSON 导入导出。
|
- `src/views/digital/content.vue`:角色卡、世界书、预设,草稿/发布/下架,JSON 导入导出。
|
||||||
- `src/views/digital/experiments.vue`:测试方案的类型选择、A/B 返回值、百分比、人群、生命周期、效果和审计。
|
- `src/views/digital/experiments.vue`:测试方案的类型选择、A/B 返回值、百分比、人群、生命周期、效果和审计。
|
||||||
- `src/views/digital/experiment-types.vue`:类型创建、默认值契约、来源、调用示例与接入验收。
|
- `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/views/digital/experiment-value.vue`:开关/数字/字符串/JSON 类型编辑器。
|
||||||
- `src/router/modules/digital.ts`:数字人菜单,只有超级管理员可见;接口仍集中在 `src/api/access.ts`,后端独立验证权限。
|
- `src/router/modules/digital.ts`:数字人菜单,只有超级管理员可见;接口仍集中在 `src/api/access.ts`,后端独立验证权限。
|
||||||
- 保留既有员工管理模块和数据。沿用原 Vite 构建、域名与 Jenkins 发布。
|
- 保留既有员工管理模块和数据。沿用原 Vite 构建、域名与 Jenkins 发布。
|
||||||
@@ -226,7 +231,7 @@ pnpm build
|
|||||||
|
|
||||||
标签页图标采用 `public/stellar-icon-v2.svg`,同时提供多尺寸 `favicon.ico`、180/192/512 PNG,覆盖浏览器、Apple 主屏幕和 PWA。版本化资源路径用于刷新旧图标缓存。
|
标签页图标采用 `public/stellar-icon-v2.svg`,同时提供多尺寸 `favicon.ico`、180/192/512 PNG,覆盖浏览器、Apple 主屏幕和 PWA。版本化资源路径用于刷新旧图标缓存。
|
||||||
|
|
||||||
「实验类型」「测试方案」「用户管理」是独立菜单。新类型填写自己的稳定标识与数据契约,先接入应用、收到实际调用并人工确认验收,再启动方案;未接入类型可存草稿。UI/对话是标注来源的已接入类型;不再使用固定业务功能的场景下拉框。方案行可直接跳转该方案的用户管理,用户预览不写分组、不记曝光,人工指定有原因、时效和审计。前台只消费决策。
|
「实验类型」「测试方案」「实验用户分组」是独立菜单。新类型填写自己的稳定标识与数据契约,先接入应用、收到实际调用并人工确认验收,再启动方案;未接入类型可存草稿。系统不预置 UI/对话类型;自建类型需要真实前台接入,不再使用固定业务功能的场景下拉框。方案行可直接跳转该方案的用户管理,用户预览不写分组、不记曝光,人工指定有原因、时效和审计。前台只消费决策。
|
||||||
|
|
||||||
比例统一按百分比输入,50代表50%,保留0.01%精度;既有用户分组保持不变。
|
比例统一按百分比输入,50代表50%,保留0.01%精度;既有用户分组保持不变。
|
||||||
|
|
||||||
@@ -243,3 +248,15 @@ pnpm build
|
|||||||
- 更新图文内容或截图后:`node scripts/build-experiment-guide.mjs`。
|
- 更新图文内容或截图后:`node scripts/build-experiment-guide.mjs`。
|
||||||
- 发布前验证文档、标注与源码一致:`node scripts/build-experiment-guide.mjs --check`。
|
- 发布前验证文档、标注与源码一致:`node scripts/build-experiment-guide.mjs --check`。
|
||||||
- 原始截图及标注后的SVG都纳入版本管理,维护时保留“隔离演示”说明,不能用伪造回执替代真实接入。
|
- 原始截图及标注后的SVG都纳入版本管理,维护时保留“隔离演示”说明,不能用伪造回执替代真实接入。
|
||||||
|
|
||||||
|
用户分组管理提供独立的方案概况、用户查找和指定入口。列表覆盖全部真实账号,不把只读预计结果称为实际入组;手动指定明确显示草稿待生效、人群不符、已过期等状态。不符合目标人群的账号须明确选择“作为测试账号加入”,不修改其他用户的人群范围。取消指定或到期后沿用原自动分组,否则按当前方案规则计算。
|
||||||
|
|
||||||
|
教程目录固定在阅读区左侧,右侧正文独立滚动并自动高亮当前章节;点击目录平滑定位,目录过长时会自动滚动到当前项。窄屏将目录置于正文上方,保留正文滚动与章节同步。
|
||||||
|
|
||||||
|
### C 端用户管理
|
||||||
|
|
||||||
|
`src/views/digital/users.vue` 对应 `/digital/users`,用于创建独立 C 端账号、搜索用户、修改昵称/状态、重置密码,以及按用户查看数字人会话和原始消息。账号由后台开通,无公开注册;与管理员/员工账号分别鉴权,重置 C 端密码不影响后台。停用保留聊天记录。
|
||||||
|
|
||||||
|
`src/api/access.ts` 定义 C 端用户、会话和消息响应类型。消息记录第1页为最新内容,每页按发送顺序展示,支持刷新、分页和生成状态查看。原实验账号页面 `/digital/experiment-users` 更名为「实验用户分组」,只针对 C 端用户配置实验。
|
||||||
|
|
||||||
|
用户列表展示账号的 NSFW 开关;创建用户默认开启,编辑用户可单独开启或关闭。与前台「我的」读取和修改同一份服务端账号偏好,不覆盖收藏、称呼或身份背景。已有账号未保存该字段时默认开启,游客的登录限制不变;需与 `access-manage` 配套发布。
|
||||||
|
|||||||
@@ -122,24 +122,25 @@ applyUiVersion(decision.value === true ? "new" : "old");
|
|||||||
|
|
||||||
## 6. 查看账号分组,指定 A/B 做对照
|
## 6. 查看账号分组,指定 A/B 做对照
|
||||||
|
|
||||||
从方案行进入“用户管理”,确认当前方案,再搜索测试账号。
|
从方案行进入“实验用户分组”,确认当前方案,再搜索测试账号。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
1. 先选本次测试方案,避免在其他实验下操作账号。
|
1. 先选择本次测试方案,并在方案详情中核对目标人群与比例。
|
||||||
2. 分组预览展示预计组别和值;这里的读取不产生分配或曝光。
|
2. 当前分组和值与分配方式分列展示,明确区分预计自动分组和手动指定。
|
||||||
3. 打开“指定分组”,切换不同组进行对照验收。
|
3. 查找用户或指定用户分组;已有指定可修改,也可取消,原有效期限单独展示。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
1. 选择方案中已有的组;本例A为0%,仍允许人工指定。
|
1. 指定分组直接展示返回值与自动分流比例;A 为 0% 也可手动指定。
|
||||||
2. 设置有效期,必须在未来30天内。
|
2. 账号不在目标人群时,须明确作为测试账号加入;设置未来30天内的有效期。
|
||||||
3. 填写原因后点击保存指定;需要越过人群时另行明确勾选。
|
3. 填写原因后确认指定;方案运行且前台已接入时,应用下次读取才会使用指定值。
|
||||||
|
|
||||||
- 先选择本次方案,再按账号、姓名或用户名查询;“分组预览”只读,不会分配账号,也不会计曝光。
|
- 先选择本次方案,再按账号、姓名或用户名查询;用户列表包含未参与实验的账号。“预计自动分组”只读,首次实际调用后才保存入组,查询不会计曝光。
|
||||||
- 点击“指定分组”,选择该方案真实存在的组,填写未来30天内的有效期和至少2字的原因。0%组也可人工指定。
|
- 点击“指定用户分组”查找账号,或在用户行点击“指定分组/修改指定”。每组直接展示返回值和自动分流比例,0% 组也可手动指定。有效期须在未来30天内,操作原因至少2字。
|
||||||
- 如确需越过目标人群,明确勾选对应选项;否则账号仍须符合人群。保存后回到应用检查A、B返回值造成的实际差异。
|
- 账号不符合目标人群时,页面会说明具体原因。例如仅新用户的实验中指定老账号,须勾选“将此账号作为测试账号加入,仍使用上面指定的组”;仅对此账号放开限制,不修改其他用户。符合人群时无需此选项。
|
||||||
- 点击“恢复自动”取消人工指定。已有稳定分组会保留;未实际入组的账号重新按规则判断,不保证“恢复自动”会换到另一组。
|
- 有效期内不一定正在生效:草稿/暂停要等方案运行,人群不符且未允许测试账号加入时不生效。前台仍须真实接入并读取返回值,才能验证功能变化。
|
||||||
|
- 点击“取消手动指定”,或等待到期后恢复方案规则:符合目标人群时沿用原自动分组,否则重新判断。取消指定不保证会换到另一组;修改指定会保留原有效期限,不自动延长。
|
||||||
|
|
||||||
## 7. 验收完成后,另建正式分流方案
|
## 7. 验收完成后,另建正式分流方案
|
||||||
|
|
||||||
|
|||||||
@@ -79,12 +79,13 @@
|
|||||||
{
|
{
|
||||||
"id": "users",
|
"id": "users",
|
||||||
"title": "6. 查看账号分组,指定 A/B 做对照",
|
"title": "6. 查看账号分组,指定 A/B 做对照",
|
||||||
"lead": "从方案行进入“用户管理”,确认当前方案,再搜索测试账号。",
|
"lead": "从方案行进入“实验用户分组”,确认当前方案,再搜索测试账号。",
|
||||||
"bullets": [
|
"bullets": [
|
||||||
"先选择本次方案,再按账号、姓名或用户名查询;“分组预览”只读,不会分配账号,也不会计曝光。",
|
"先选择本次方案,再按账号、姓名或用户名查询;用户列表包含未参与实验的账号。“预计自动分组”只读,首次实际调用后才保存入组,查询不会计曝光。",
|
||||||
"点击“指定分组”,选择该方案真实存在的组,填写未来30天内的有效期和至少2字的原因。0%组也可人工指定。",
|
"点击“指定用户分组”查找账号,或在用户行点击“指定分组/修改指定”。每组直接展示返回值和自动分流比例,0% 组也可手动指定。有效期须在未来30天内,操作原因至少2字。",
|
||||||
"如确需越过目标人群,明确勾选对应选项;否则账号仍须符合人群。保存后回到应用检查A、B返回值造成的实际差异。",
|
"账号不符合目标人群时,页面会说明具体原因。例如仅新用户的实验中指定老账号,须勾选“将此账号作为测试账号加入,仍使用上面指定的组”;仅对此账号放开限制,不修改其他用户。符合人群时无需此选项。",
|
||||||
"点击“恢复自动”取消人工指定。已有稳定分组会保留;未实际入组的账号重新按规则判断,不保证“恢复自动”会换到另一组。"
|
"有效期内不一定正在生效:草稿/暂停要等方案运行,人群不符且未允许测试账号加入时不生效。前台仍须真实接入并读取返回值,才能验证功能变化。",
|
||||||
|
"点击“取消手动指定”,或等待到期后恢复方案规则:符合目标人群时沿用原自动分组,否则重新判断。取消指定不保证会换到另一组;修改指定会保留原有效期限,不自动延长。"
|
||||||
],
|
],
|
||||||
"images": ["06-users", "06b-override"]
|
"images": ["06-users", "06b-override"]
|
||||||
},
|
},
|
||||||
@@ -181,14 +182,14 @@
|
|||||||
"核对无误再确认;之后到应用中验收实际效果。"
|
"核对无误再确认;之后到应用中验收实际效果。"
|
||||||
],
|
],
|
||||||
"06-users": [
|
"06-users": [
|
||||||
"先选本次测试方案,避免在其他实验下操作账号。",
|
"先选择本次测试方案,并在方案详情中核对目标人群与比例。",
|
||||||
"分组预览展示预计组别和值;这里的读取不产生分配或曝光。",
|
"当前分组和值与分配方式分列展示,明确区分预计自动分组和手动指定。",
|
||||||
"打开“指定分组”,切换不同组进行对照验收。"
|
"查找用户或指定用户分组;已有指定可修改,也可取消,原有效期限单独展示。"
|
||||||
],
|
],
|
||||||
"06b-override": [
|
"06b-override": [
|
||||||
"选择方案中已有的组;本例A为0%,仍允许人工指定。",
|
"指定分组直接展示返回值与自动分流比例;A 为 0% 也可手动指定。",
|
||||||
"设置有效期,必须在未来30天内。",
|
"账号不在目标人群时,须明确作为测试账号加入;设置未来30天内的有效期。",
|
||||||
"填写原因后点击保存指定;需要越过人群时另行明确勾选。"
|
"填写原因后确认指定;方案运行且前台已接入时,应用下次读取才会使用指定值。"
|
||||||
],
|
],
|
||||||
"07-formal": [
|
"07-formal": [
|
||||||
"正式分流示例A/B各50%,C为0%;合计须为100%。",
|
"正式分流示例A/B各50%,C为0%;合计须为100%。",
|
||||||
|
|||||||
@@ -168,90 +168,90 @@
|
|||||||
},
|
},
|
||||||
"06-users": {
|
"06-users": {
|
||||||
"width": 1920,
|
"width": 1920,
|
||||||
"height": 902,
|
"height": 958,
|
||||||
"annotations": [
|
"annotations": [
|
||||||
{
|
{
|
||||||
"number": 1,
|
"number": 1,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 662,
|
"x": 470,
|
||||||
"y": 258,
|
"y": 225,
|
||||||
"width": 524.5,
|
"width": 305,
|
||||||
"height": 24
|
"height": 38
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 586,
|
"x": 520,
|
||||||
"y": 270
|
"y": 170
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"number": 2,
|
"number": 2,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 746,
|
"x": 625,
|
||||||
"y": 399,
|
"y": 425,
|
||||||
"width": 27.015625,
|
"width": 560,
|
||||||
"height": 17
|
"height": 187
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 670,
|
"x": 580,
|
||||||
"y": 407.5
|
"y": 447
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"number": 3,
|
"number": 3,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 1524,
|
"x": 1200,
|
||||||
"y": 428.15625,
|
"y": 355,
|
||||||
"width": 62,
|
"width": 675,
|
||||||
"height": 20
|
"height": 255
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 1448,
|
"x": 1795,
|
||||||
"y": 438.15625
|
"y": 708
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"06b-override": {
|
"06b-override": {
|
||||||
"width": 1920,
|
"width": 1920,
|
||||||
"height": 902,
|
"height": 958,
|
||||||
"annotations": [
|
"annotations": [
|
||||||
{
|
{
|
||||||
"number": 1,
|
"number": 1,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 696,
|
"x": 655,
|
||||||
"y": 390.296875,
|
"y": 225,
|
||||||
"width": 14,
|
"width": 595,
|
||||||
"height": 14
|
"height": 135
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 620,
|
"x": 1390,
|
||||||
"y": 397.296875
|
"y": 270
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"number": 2,
|
"number": 2,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 729,
|
"x": 655,
|
||||||
"y": 462.296875,
|
"y": 418,
|
||||||
"width": 176,
|
"width": 595,
|
||||||
"height": 30
|
"height": 223
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 653,
|
"x": 520,
|
||||||
"y": 477.296875
|
"y": 470
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"number": 3,
|
"number": 3,
|
||||||
"rect": {
|
"rect": {
|
||||||
"x": 696,
|
"x": 655,
|
||||||
"y": 541.296875,
|
"y": 665,
|
||||||
"width": 528,
|
"width": 595,
|
||||||
"height": 73
|
"height": 157
|
||||||
},
|
},
|
||||||
"badge": {
|
"badge": {
|
||||||
"x": 620,
|
"x": 1390,
|
||||||
"y": 565.296875
|
"y": 720
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 121 KiB |
@@ -1091,7 +1091,7 @@ export type Result<T> = { success: boolean; data: T };
|
|||||||
/** 数字人后台 API,复用已有 JWT 拦截器。 */
|
/** 数字人后台 API,复用已有 JWT 拦截器。 */
|
||||||
export async function digital<T>(
|
export async function digital<T>(
|
||||||
path: string,
|
path: string,
|
||||||
method: "get" | "post" | "put" | "delete" = "get",
|
method: "get" | "post" | "put" | "patch" | "delete" = "get",
|
||||||
data?: unknown
|
data?: unknown
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
try {
|
try {
|
||||||
@@ -1224,3 +1224,38 @@ export type ExperimentUser = {
|
|||||||
};
|
};
|
||||||
assignment: null | { variant: string; createdAt: string };
|
assignment: null | { variant: string; createdAt: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 独立 C 端用户的后台公开资料,不含密码/令牌或员工权限。 */
|
||||||
|
export type DigitalUser = {
|
||||||
|
id: number;
|
||||||
|
account: string;
|
||||||
|
username: string;
|
||||||
|
displayName: string;
|
||||||
|
status: "ACTIVE" | "INACTIVE";
|
||||||
|
/** 账号未保存内容偏好时默认开启,后端在生成时读取实际值。 */
|
||||||
|
nsfwEnabled?: boolean;
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/** 角色编辑预览与聊天记录共用的受限文本展示,用户消息和 HTML 字面量均不作为标签解释。 */
|
||||||
|
import { computed } from "vue";
|
||||||
|
import { parseDigitalMessage } from "@/utils/digital-message-format";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
text: string;
|
||||||
|
role?: "assistant" | "user";
|
||||||
|
incomplete?: boolean;
|
||||||
|
}>(),
|
||||||
|
{ role: "assistant", incomplete: false }
|
||||||
|
);
|
||||||
|
const blocks = computed(() =>
|
||||||
|
parseDigitalMessage(props.text, props.incomplete)
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="digital-message-text"
|
||||||
|
:class="{ 'is-prose': role === 'assistant' }"
|
||||||
|
>
|
||||||
|
<template v-if="role === 'assistant' && blocks.length">
|
||||||
|
<p
|
||||||
|
v-for="(block, index) in blocks"
|
||||||
|
:key="index"
|
||||||
|
:class="[
|
||||||
|
block.kind,
|
||||||
|
{
|
||||||
|
'is-latin':
|
||||||
|
/[A-Za-z]/.test(block.text) && !/[\u3400-\u9fff]/.test(block.text)
|
||||||
|
}
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<strong v-if="block.kind === 'dialogue'">{{ block.text }}</strong>
|
||||||
|
<template v-else>{{ block.text }}</template>
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<template v-else>{{ text || "(未生成正文)" }}</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.digital-message-text {
|
||||||
|
line-height: 1.9;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-prose {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-prose > p {
|
||||||
|
margin: 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-prose > p + p {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialogue {
|
||||||
|
color: var(--digital-dialogue-ink, var(--el-text-color-primary));
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialogue strong {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.narration {
|
||||||
|
color: var(--digital-narration-ink, var(--el-text-color-regular));
|
||||||
|
}
|
||||||
|
|
||||||
|
.narration.is-latin {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -8,6 +8,12 @@ export default {
|
|||||||
redirect: "/digital/content",
|
redirect: "/digital/content",
|
||||||
meta: { title: "数字人运营", icon: "ep/chat-dot-round", rank: 0 },
|
meta: { title: "数字人运营", icon: "ep/chat-dot-round", rank: 0 },
|
||||||
children: [
|
children: [
|
||||||
|
{
|
||||||
|
path: "/digital/users",
|
||||||
|
name: "DigitalUsers",
|
||||||
|
component: () => import("@/views/digital/users.vue"),
|
||||||
|
meta: { title: "用户管理", permission: "*" }
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/digital/content",
|
path: "/digital/content",
|
||||||
name: "DigitalContent",
|
name: "DigitalContent",
|
||||||
@@ -41,7 +47,7 @@ export default {
|
|||||||
path: "/digital/experiment-users",
|
path: "/digital/experiment-users",
|
||||||
name: "DigitalExperimentUsers",
|
name: "DigitalExperimentUsers",
|
||||||
component: () => import("@/views/digital/experiment-users.vue"),
|
component: () => import("@/views/digital/experiment-users.vue"),
|
||||||
meta: { title: "用户管理", permission: "*" }
|
meta: { title: "实验用户分组", permission: "*" }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
} satisfies RouteConfigsTable;
|
} satisfies RouteConfigsTable;
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/** 数字人消息的受限文本格式:对白、故事叙述与旧版括号;始终返回文本,不解释 HTML。 */
|
||||||
|
|
||||||
|
/** 有序展示片段;原始 content 继续用于存储、复制、记忆和上下文。 */
|
||||||
|
export type DigitalMessageBlock = {
|
||||||
|
kind: "dialogue" | "narration" | "plain";
|
||||||
|
text: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const quotePairs: Record<string, string> = {
|
||||||
|
'"': '"',
|
||||||
|
"“": "”",
|
||||||
|
"「": "」",
|
||||||
|
"『": "』",
|
||||||
|
"«": "»",
|
||||||
|
""": """
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 跳过转义字符;引号不跨行,括号按同类型嵌套匹配,避免误吞后续内容。 */
|
||||||
|
function closingIndex(
|
||||||
|
text: string,
|
||||||
|
from: number,
|
||||||
|
open: string,
|
||||||
|
close: string,
|
||||||
|
nested = false
|
||||||
|
) {
|
||||||
|
let depth = 1;
|
||||||
|
for (let i = from; i < text.length; i++) {
|
||||||
|
if (text[i] === "\\") {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!nested && quotePairs[open] && text[i] === "\n") return -1;
|
||||||
|
if (nested && text.startsWith(open, i)) depth++;
|
||||||
|
if (text.startsWith(close, i)) {
|
||||||
|
depth--;
|
||||||
|
if (depth === 0) return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 星号需要处于词边界,避免把乘法、文件名或普通单词里的星号视为排版。 */
|
||||||
|
function markerBoundary(text: string, index: number) {
|
||||||
|
return (
|
||||||
|
index === 0 || /[\s。!?!?,,;;::))\]”"」』»]/u.test(text[index - 1])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析累计正文而非单个 SSE delta。未闭合标记仅在流式/中断展示时延续当前样式;
|
||||||
|
* 旧版括号外文本按对白处理,有引号的旧开场白将引号外文字作为叙述,其他纯文本保留。
|
||||||
|
* 与 role-user/src/lib/digital-message-format.ts 保持同一实现和用例,独立构建时无需跨仓引用。
|
||||||
|
*/
|
||||||
|
export function parseDigitalMessage(
|
||||||
|
source: string,
|
||||||
|
streaming = false
|
||||||
|
): DigitalMessageBlock[] {
|
||||||
|
const blocks: DigitalMessageBlock[] = [];
|
||||||
|
for (const paragraph of source.replace(/\r\n?/g, "\n").split(/\n\s*\n/)) {
|
||||||
|
const parts: DigitalMessageBlock[] = [];
|
||||||
|
let legacyNarration = false;
|
||||||
|
const push = (kind: DigitalMessageBlock["kind"], text: string) => {
|
||||||
|
if (!text) return;
|
||||||
|
const last = parts[parts.length - 1];
|
||||||
|
if (last?.kind === kind) last.text += text;
|
||||||
|
else parts.push({ kind, text });
|
||||||
|
};
|
||||||
|
for (let i = 0; i < paragraph.length; ) {
|
||||||
|
const char = paragraph[i];
|
||||||
|
if (
|
||||||
|
char === "\\" &&
|
||||||
|
/[*"\\()()“”「」『』]/u.test(paragraph[i + 1] ?? "")
|
||||||
|
) {
|
||||||
|
push("plain", paragraph[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const quoteEnd = quotePairs[char];
|
||||||
|
if (quoteEnd) {
|
||||||
|
const close = closingIndex(paragraph, i + 1, char, quoteEnd);
|
||||||
|
const lineEnd = paragraph.indexOf("\n", i + 1);
|
||||||
|
const end =
|
||||||
|
close >= 0 ? close + 1 : lineEnd >= 0 ? lineEnd : paragraph.length;
|
||||||
|
push("dialogue", paragraph.slice(i, end));
|
||||||
|
i = end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
char === "*" &&
|
||||||
|
markerBoundary(paragraph, i) &&
|
||||||
|
!/\s/u.test(paragraph[i + 1] ?? "")
|
||||||
|
) {
|
||||||
|
const marker = paragraph.startsWith("**", i) ? "**" : "*";
|
||||||
|
const close = closingIndex(
|
||||||
|
paragraph,
|
||||||
|
i + marker.length,
|
||||||
|
marker,
|
||||||
|
marker
|
||||||
|
);
|
||||||
|
if (close >= 0 || streaming) {
|
||||||
|
push(
|
||||||
|
marker === "**" ? "dialogue" : "narration",
|
||||||
|
paragraph.slice(i + marker.length, close >= 0 ? close : undefined)
|
||||||
|
);
|
||||||
|
i = close >= 0 ? close + marker.length : paragraph.length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 格式不完整的历史正文原样保留,不猜测后面的哪些字符属于标记。
|
||||||
|
push("plain", paragraph.slice(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((char === "(" || char === "(") && markerBoundary(paragraph, i)) {
|
||||||
|
const close = closingIndex(
|
||||||
|
paragraph,
|
||||||
|
i + 1,
|
||||||
|
char,
|
||||||
|
char === "(" ? ")" : ")",
|
||||||
|
true
|
||||||
|
);
|
||||||
|
if (close >= 0 || streaming) {
|
||||||
|
legacyNarration = true;
|
||||||
|
push(
|
||||||
|
"narration",
|
||||||
|
paragraph.slice(i + 1, close >= 0 ? close : undefined)
|
||||||
|
);
|
||||||
|
i = close >= 0 ? close + 1 : paragraph.length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
push("plain", paragraph.slice(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
push("plain", char);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
const hasDialogue = parts.some(part => part.kind === "dialogue");
|
||||||
|
for (const part of parts) {
|
||||||
|
const kind =
|
||||||
|
part.kind !== "plain"
|
||||||
|
? part.kind
|
||||||
|
: legacyNarration
|
||||||
|
? "dialogue"
|
||||||
|
: hasDialogue
|
||||||
|
? "narration"
|
||||||
|
: "plain";
|
||||||
|
for (const line of part.text.split(/\n+/)) {
|
||||||
|
if (line.trim()) blocks.push({ kind, text: line.trim() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 数字人内容库:角色、世界书、叙事预设分别编辑,发布状态显式可见。 */
|
/** 数字人内容库:角色、世界书、预设分别编辑,开场与示例使用聊天格式实时预览。 */
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { digital, type Content, type Entry } from "@/api/access";
|
import { digital, type Content, type Entry } from "@/api/access";
|
||||||
|
import DigitalMessageText from "@/components/DigitalMessageText.vue";
|
||||||
const contents = ref<Content[]>([]),
|
const contents = ref<Content[]>([]),
|
||||||
kind = ref("character"),
|
kind = ref("character"),
|
||||||
query = ref(""),
|
query = ref(""),
|
||||||
@@ -29,6 +30,12 @@ const statusNames: Record<string, string> = {
|
|||||||
published: "已发布",
|
published: "已发布",
|
||||||
archived: "已下架"
|
archived: "已下架"
|
||||||
};
|
};
|
||||||
|
/** 占位符仅用于当前预览,不改写编辑内容或数据库中的角色模板。 */
|
||||||
|
function previewText(value: string) {
|
||||||
|
return value
|
||||||
|
.replaceAll("{{char}}", edit.value?.name || "角色")
|
||||||
|
.replaceAll("{{user}}", "旅人");
|
||||||
|
}
|
||||||
const books = computed(() =>
|
const books = computed(() =>
|
||||||
contents.value.filter(c => c.kind === "worldbook" && c.status === "published")
|
contents.value.filter(c => c.kind === "worldbook" && c.status === "published")
|
||||||
);
|
);
|
||||||
@@ -323,7 +330,12 @@ onMounted(load);
|
|||||||
v-if="edit.kind === 'character'"
|
v-if="edit.kind === 'character'"
|
||||||
label="人格与开场"
|
label="人格与开场"
|
||||||
name="persona"
|
name="persona"
|
||||||
><el-form-item label="性格、背景和关系"
|
><el-alert
|
||||||
|
class="format-guide"
|
||||||
|
title="对白与叙述分段书写"
|
||||||
|
description="对白使用成对引号,如:“你来了。”;动作、神态、心理和环境用单星号包裹,如:*她合上书,抬头微笑。*。切换时空一行,下方预览与聊天使用相同的格式规则。"
|
||||||
|
:closable="false"
|
||||||
|
/><el-form-item label="性格、背景和关系"
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.personality"
|
v-model="edit.body.personality"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
@@ -334,15 +346,36 @@ onMounted(load);
|
|||||||
type="textarea"
|
type="textarea"
|
||||||
:rows="3" /></el-form-item
|
:rows="3" /></el-form-item
|
||||||
><el-form-item label="首次问候(支持 {{char}} / {{user}} 占位符)"
|
><el-form-item label="首次问候(支持 {{char}} / {{user}} 占位符)"
|
||||||
><el-input
|
><div class="format-editor">
|
||||||
v-model="edit.body.greeting"
|
<el-input
|
||||||
type="textarea"
|
v-model="edit.body.greeting"
|
||||||
:rows="4" /></el-form-item
|
type="textarea"
|
||||||
|
:rows="4"
|
||||||
|
placeholder="*她合上书,抬头看向你。* “你来了。”"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="edit.body.greeting.trim()"
|
||||||
|
class="format-preview"
|
||||||
|
aria-label="首次问候展示预览"
|
||||||
|
>
|
||||||
|
<small>首次问候 · 展示效果</small>
|
||||||
|
<DigitalMessageText :text="previewText(edit.body.greeting)" />
|
||||||
|
</div></div></el-form-item
|
||||||
><el-form-item label="示例对白"
|
><el-form-item label="示例对白"
|
||||||
><el-input
|
><div class="format-editor">
|
||||||
v-model="edit.body.examples"
|
<el-input
|
||||||
type="textarea"
|
v-model="edit.body.examples"
|
||||||
:rows="4" /></el-form-item
|
type="textarea"
|
||||||
|
:rows="4"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="edit.body.examples.trim()"
|
||||||
|
class="format-preview"
|
||||||
|
aria-label="示例对白展示预览"
|
||||||
|
>
|
||||||
|
<small>示例对白 · 展示效果</small>
|
||||||
|
<DigitalMessageText :text="previewText(edit.body.examples)" />
|
||||||
|
</div></div></el-form-item
|
||||||
><el-form-item label="角色系统指令"
|
><el-form-item label="角色系统指令"
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.systemPrompt"
|
v-model="edit.body.systemPrompt"
|
||||||
@@ -355,12 +388,24 @@ onMounted(load);
|
|||||||
:key="i"
|
:key="i"
|
||||||
class="entry-row"
|
class="entry-row"
|
||||||
>
|
>
|
||||||
<el-input
|
<div class="format-editor">
|
||||||
v-model="edit.body.alternateGreetings[i]"
|
<el-input
|
||||||
type="textarea"
|
v-model="edit.body.alternateGreetings[i]"
|
||||||
:rows="2"
|
type="textarea"
|
||||||
/><el-button
|
:rows="2"
|
||||||
@click="edit.body.alternateGreetings.splice(i, 1)"
|
/>
|
||||||
|
<div
|
||||||
|
v-if="edit.body.alternateGreetings[i].trim()"
|
||||||
|
class="format-preview"
|
||||||
|
:aria-label="`其他开场 ${i + 1} 展示预览`"
|
||||||
|
>
|
||||||
|
<small>其他开场 {{ i + 1 }} · 展示效果</small>
|
||||||
|
<DigitalMessageText
|
||||||
|
:text="previewText(edit.body.alternateGreetings[i])"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-button @click="edit.body.alternateGreetings.splice(i, 1)"
|
||||||
>移除</el-button
|
>移除</el-button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -465,7 +510,11 @@ onMounted(load);
|
|||||||
v-if="edit.kind === 'preset'"
|
v-if="edit.kind === 'preset'"
|
||||||
label="生成编排"
|
label="生成编排"
|
||||||
name="generation"
|
name="generation"
|
||||||
><el-form-item label="系统指令"
|
><el-alert
|
||||||
|
class="format-guide"
|
||||||
|
title="系统统一区分对白和叙述"
|
||||||
|
description="本页设置叙事风格;对白使用引号、叙述使用单星号并分段的排版规则始终生效,发送、继续与重新生成共用。"
|
||||||
|
:closable="false" /><el-form-item label="系统指令"
|
||||||
><el-input
|
><el-input
|
||||||
v-model="edit.body.systemPrompt"
|
v-model="edit.body.systemPrompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
@@ -512,6 +561,37 @@ onMounted(load);
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.format-guide {
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.format-editor {
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.format-preview {
|
||||||
|
--digital-dialogue-ink: #fff5fc;
|
||||||
|
--digital-narration-ink: #c2b6c4;
|
||||||
|
|
||||||
|
max-height: 300px;
|
||||||
|
padding: 14px 18px;
|
||||||
|
margin-top: 10px;
|
||||||
|
overflow: auto;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #e6dfe7;
|
||||||
|
background: #211c23;
|
||||||
|
border: 1px solid #ffffff12;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.format-preview > small {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: #b5a6b8;
|
||||||
|
}
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
|
|||||||
@@ -1,20 +1,109 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 实验图文教程二级页:与仓库README共用内容源,截图标注只来自隔离演示。 */
|
/** 实验图文教程二级页:固定目录与独立正文滚动,按实际阅读位置同步当前章节。 */
|
||||||
|
import {
|
||||||
|
nextTick,
|
||||||
|
onActivated,
|
||||||
|
onBeforeUnmount,
|
||||||
|
onMounted,
|
||||||
|
ref,
|
||||||
|
watch
|
||||||
|
} from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import guide from "../../../docs/experiments/guide.json";
|
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 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 =>
|
const images = guide.steps.flatMap(step =>
|
||||||
(step.images ?? []).map(image => `/guides/experiments/${image}.svg`)
|
(step.images ?? []).map(image => `/guides/experiments/${image}.svg`)
|
||||||
);
|
);
|
||||||
/** 在当前二级页内滚动,不修改hash路由,也不触发任何实验写操作。 */
|
/** 在当前二级页内滚动,不修改hash路由,也不触发任何实验写操作。 */
|
||||||
function jump(id: string) {
|
function jump(id: string) {
|
||||||
document
|
const section = body.value?.querySelector<HTMLElement>(`#guide-${id}`);
|
||||||
.getElementById(`guide-${id}`)
|
if (!section || !body.value) return;
|
||||||
?.scrollIntoView({ behavior: "smooth", block: "start" });
|
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>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="experiment-guide">
|
<div ref="page" class="experiment-guide">
|
||||||
<header class="guide-heading">
|
<header class="guide-heading">
|
||||||
<div>
|
<div>
|
||||||
<el-tag type="info">从零开始 · 图文教程</el-tag>
|
<el-tag type="info">从零开始 · 图文教程</el-tag>
|
||||||
@@ -32,17 +121,28 @@ function jump(id: string) {
|
|||||||
/>
|
/>
|
||||||
<div class="guide-layout">
|
<div class="guide-layout">
|
||||||
<nav class="guide-toc" aria-label="教程目录">
|
<nav class="guide-toc" aria-label="教程目录">
|
||||||
<strong>本页目录</strong
|
<strong>本页目录</strong>
|
||||||
><button
|
<div ref="toc" class="guide-links">
|
||||||
v-for="step in guide.steps"
|
<button
|
||||||
:key="step.id"
|
v-for="step in guide.steps"
|
||||||
type="button"
|
:key="step.id"
|
||||||
@click="jump(step.id)"
|
type="button"
|
||||||
>
|
:data-section="step.id"
|
||||||
{{ step.title }}
|
:class="{ active: activeId === step.id }"
|
||||||
</button>
|
:aria-current="activeId === step.id ? 'location' : undefined"
|
||||||
|
@click="jump(step.id)"
|
||||||
|
>
|
||||||
|
{{ step.title }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<article>
|
<article
|
||||||
|
ref="body"
|
||||||
|
class="guide-body"
|
||||||
|
tabindex="0"
|
||||||
|
aria-label="教程正文"
|
||||||
|
@scroll="scheduleUpdate"
|
||||||
|
>
|
||||||
<section
|
<section
|
||||||
v-for="step in guide.steps"
|
v-for="step in guide.steps"
|
||||||
:id="`guide-${step.id}`"
|
:id="`guide-${step.id}`"
|
||||||
@@ -54,6 +154,9 @@ function jump(id: string) {
|
|||||||
<figure v-for="image in step.images ?? []" :key="image">
|
<figure v-for="image in step.images ?? []" :key="image">
|
||||||
<el-image
|
<el-image
|
||||||
:src="`/guides/experiments/${image}.svg`"
|
:src="`/guides/experiments/${image}.svg`"
|
||||||
|
:style="{
|
||||||
|
aspectRatio: `${sizes[image].width} / ${sizes[image].height}`
|
||||||
|
}"
|
||||||
:alt="`${step.title},带红色箭头与编号的演示截图`"
|
:alt="`${step.title},带红色箭头与编号的演示截图`"
|
||||||
:preview-src-list="images"
|
:preview-src-list="images"
|
||||||
:initial-index="
|
:initial-index="
|
||||||
@@ -93,7 +196,7 @@ function jump(id: string) {
|
|||||||
@click="router.push('/digital/experiments')"
|
@click="router.push('/digital/experiments')"
|
||||||
>去测试方案</el-button
|
>去测试方案</el-button
|
||||||
><el-button @click="router.push('/digital/experiment-users')"
|
><el-button @click="router.push('/digital/experiment-users')"
|
||||||
>去用户管理</el-button
|
>去实验用户分组</el-button
|
||||||
>
|
>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
@@ -102,8 +205,13 @@ function jump(id: string) {
|
|||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.experiment-guide {
|
.experiment-guide {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
max-width: 1440px;
|
max-width: 1440px;
|
||||||
|
height: var(--guide-height, calc(100dvh - 134px));
|
||||||
|
min-height: 360px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guide-heading {
|
.guide-heading {
|
||||||
@@ -127,27 +235,36 @@ function jump(id: string) {
|
|||||||
|
|
||||||
.guide-layout {
|
.guide-layout {
|
||||||
display: grid;
|
display: grid;
|
||||||
|
flex: 1;
|
||||||
grid-template-columns: 220px minmax(0, 1fr);
|
grid-template-columns: 220px minmax(0, 1fr);
|
||||||
gap: 32px;
|
gap: 32px;
|
||||||
|
min-height: 0;
|
||||||
margin-top: 24px;
|
margin-top: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guide-toc {
|
.guide-toc {
|
||||||
position: sticky;
|
|
||||||
top: 96px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
align-self: start;
|
min-height: 0;
|
||||||
max-height: calc(100vh - 130px);
|
max-height: 100%;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
overflow-y: auto;
|
overflow: hidden;
|
||||||
background: var(--el-bg-color);
|
background: var(--el-bg-color);
|
||||||
border: 1px solid var(--el-border-color-lighter);
|
border: 1px solid var(--el-border-color-lighter);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.guide-links {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.guide-toc strong {
|
.guide-toc strong {
|
||||||
|
flex-shrink: 0;
|
||||||
padding: 4px 8px 12px;
|
padding: 4px 8px 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +280,25 @@ function jump(id: string) {
|
|||||||
border-radius: 4px;
|
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 {
|
.guide-toc button:hover {
|
||||||
color: var(--el-color-primary);
|
color: var(--el-color-primary);
|
||||||
background: var(--el-fill-color-light);
|
background: var(--el-fill-color-light);
|
||||||
@@ -176,7 +312,7 @@ function jump(id: string) {
|
|||||||
.guide-section {
|
.guide-section {
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
scroll-margin-top: 100px;
|
scroll-margin-top: 0;
|
||||||
background: var(--el-bg-color);
|
background: var(--el-bg-color);
|
||||||
border: 1px solid var(--el-border-color-lighter);
|
border: 1px solid var(--el-border-color-lighter);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -247,17 +383,28 @@ function jump(id: string) {
|
|||||||
|
|
||||||
@media (width <= 900px) {
|
@media (width <= 900px) {
|
||||||
.guide-layout {
|
.guide-layout {
|
||||||
|
grid-template-rows: auto minmax(0, 1fr);
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guide-toc {
|
.guide-toc {
|
||||||
position: static;
|
max-height: 140px;
|
||||||
max-height: 220px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.guide-heading {
|
.guide-heading {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guide-heading h1 {
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.guide-heading p {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.guide-section {
|
.guide-section {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 用户分组独立管理:分页查真实账号,预览不分配,人工指定与恢复自动均留审计。 */
|
/** 用户分组管理:区分实际入组与只读预估,按目标人群解释人工指定的生效条件。 */
|
||||||
import { computed, onMounted, ref, watch } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
@@ -26,7 +26,10 @@ const plans = ref<Experiment[]>([]),
|
|||||||
saving = ref(false),
|
saving = ref(false),
|
||||||
editor = ref(false),
|
editor = ref(false),
|
||||||
detail = ref<ExperimentUser | null>(null),
|
detail = ref<ExperimentUser | null>(null),
|
||||||
explanation = ref(false);
|
explanation = ref(false),
|
||||||
|
planDetail = ref(false),
|
||||||
|
candidates = ref<ExperimentUser[]>([]),
|
||||||
|
finding = ref(false);
|
||||||
const selected = computed(() =>
|
const selected = computed(() =>
|
||||||
plans.value.find(p => p.id === selectedId.value)
|
plans.value.find(p => p.id === selectedId.value)
|
||||||
);
|
);
|
||||||
@@ -62,6 +65,7 @@ let requestVersion = 0;
|
|||||||
async function load() {
|
async function load() {
|
||||||
const version = ++requestVersion;
|
const version = ++requestVersion;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
items.value = [];
|
||||||
try {
|
try {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
q: q.value,
|
q: q.value,
|
||||||
@@ -96,30 +100,163 @@ function summary(value: unknown) {
|
|||||||
function overrideActive(row: ExperimentUser) {
|
function overrideActive(row: ExperimentUser) {
|
||||||
return !!row.override && Date.parse(row.override.expiresAt) > Date.now();
|
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) {
|
function open(row: ExperimentUser) {
|
||||||
if (!selected.value) return;
|
if (!selected.value) return;
|
||||||
detail.value = row;
|
detail.value = row;
|
||||||
form.value = {
|
form.value = {
|
||||||
account: row.account,
|
account: row.account,
|
||||||
variant:
|
variant:
|
||||||
row.override?.variant ?? selected.value.config.groups[0]?.key ?? "",
|
row.override?.variant ??
|
||||||
|
row.decision?.variant ??
|
||||||
|
selected.value.config.groups[0]?.key ??
|
||||||
|
"",
|
||||||
reason: "",
|
reason: "",
|
||||||
bypassAudience: !!row.override?.bypassAudience,
|
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;
|
editor.value = true;
|
||||||
}
|
}
|
||||||
async function save() {
|
async function save() {
|
||||||
const id = selectedId.value;
|
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)
|
if (form.value.reason.trim().length < 2)
|
||||||
return ElMessage.warning("请填写至少两个字的操作原因");
|
return ElMessage.warning("请填写至少两个字的操作原因");
|
||||||
|
const wasRunning = selected.value.state === "running";
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
try {
|
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;
|
editor.value = false;
|
||||||
await load();
|
await load();
|
||||||
ElMessage.success("人工分组已保存,用户刷新前台后读取结果");
|
ElMessage.success(
|
||||||
|
wasRunning
|
||||||
|
? "手动指定已保存,应用下次读取方案时生效"
|
||||||
|
: "手动指定已保存,方案运行后才会生效"
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ElMessage.error(e instanceof Error ? e.message : "指定失败");
|
ElMessage.error(e instanceof Error ? e.message : "指定失败");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -132,9 +269,9 @@ async function restore(row: ExperimentUser) {
|
|||||||
try {
|
try {
|
||||||
await ElMessageBox.confirm(
|
await ElMessageBox.confirm(
|
||||||
`取消 ${row.name} 的人工指定?已有稳定分组保留,没有稳定分组时按方案规则判定。`,
|
`取消 ${row.name} 的人工指定?已有稳定分组保留,没有稳定分组时按方案规则判定。`,
|
||||||
"恢复自动分组",
|
"取消手动指定",
|
||||||
{
|
{
|
||||||
confirmButtonText: "恢复自动",
|
confirmButtonText: "确认取消指定",
|
||||||
cancelButtonText: "取消",
|
cancelButtonText: "取消",
|
||||||
type: "warning"
|
type: "warning"
|
||||||
}
|
}
|
||||||
@@ -153,6 +290,8 @@ async function restore(row: ExperimentUser) {
|
|||||||
watch(selectedId, () => {
|
watch(selectedId, () => {
|
||||||
editor.value = false;
|
editor.value = false;
|
||||||
explanation.value = false;
|
explanation.value = false;
|
||||||
|
planDetail.value = false;
|
||||||
|
++candidateVersion;
|
||||||
router.replace({
|
router.replace({
|
||||||
query: { ...route.query, experiment: selectedId.value || undefined }
|
query: { ...route.query, experiment: selectedId.value || undefined }
|
||||||
});
|
});
|
||||||
@@ -192,102 +331,157 @@ onMounted(async () => {
|
|||||||
<div class="users-page">
|
<div class="users-page">
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<div>
|
<div>
|
||||||
<h2>用户管理</h2>
|
<h2>实验用户分组</h2>
|
||||||
<p>
|
<p>选择测试方案,查看独立 C 端用户的分组,或为测试账号指定分组。</p>
|
||||||
账号来自现有登录体系。这里查看实验分组与管理人工指定,测试方案在独立页面配置。
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<el-button @click="router.push('/digital/experiments')"
|
<el-button :loading="loading" @click="load">刷新</el-button>
|
||||||
>查看测试方案</el-button
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
<el-alert
|
<el-card shadow="never">
|
||||||
title="分组预览只读,不会给用户入组或记录曝光。先选择测试方案,再查人、指定任意配置组或恢复自动;草稿和暂停时使用类型默认返回值。"
|
<div class="plan-filters">
|
||||||
:closable="false"
|
<el-form-item label="实验类型"
|
||||||
type="info"
|
><el-select v-model="typeFilter" clearable placeholder="全部类型"
|
||||||
/>
|
><el-option
|
||||||
<el-card shadow="never" class="content"
|
v-for="t in types"
|
||||||
><div class="filters">
|
:key="t.id"
|
||||||
<el-select v-model="typeFilter" clearable placeholder="筛选实验类型"
|
:value="t.id"
|
||||||
><el-option
|
:label="t.name" /></el-select
|
||||||
v-for="t in types"
|
></el-form-item>
|
||||||
:key="t.id"
|
<el-form-item label="当前测试方案"
|
||||||
:value="t.id"
|
><el-select
|
||||||
:label="t.name" /></el-select
|
v-model="selectedId"
|
||||||
><el-select
|
clearable
|
||||||
v-model="selectedId"
|
filterable
|
||||||
clearable
|
placeholder="请选择测试方案"
|
||||||
filterable
|
><el-option
|
||||||
placeholder="选择测试方案(指定分组前必选)"
|
v-for="p in availablePlans"
|
||||||
><el-option
|
:key="p.id"
|
||||||
v-for="p in availablePlans"
|
:value="p.id"
|
||||||
:key="p.id"
|
:label="p.name + ' · ' + states[p.state]" /></el-select
|
||||||
:value="p.id"
|
></el-form-item>
|
||||||
:label="`${p.name} · ${states[p.state]}`" /></el-select
|
<el-tag
|
||||||
><el-input
|
v-if="selected"
|
||||||
v-model="q"
|
:type="selected.state === 'running' ? 'success' : 'info'"
|
||||||
clearable
|
>{{ states[selected.state] }}</el-tag
|
||||||
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 }}% ·
|
|
||||||
{{
|
|
||||||
selected.config.groups
|
|
||||||
.map(g => `${g.key} ${g.weight / 100}%`)
|
|
||||||
.join(" / ")
|
|
||||||
}}</span
|
|
||||||
>
|
>
|
||||||
</p>
|
<el-button
|
||||||
<el-table v-loading="loading" :data="items"
|
v-if="selected"
|
||||||
><el-table-column label="用户" min-width="210"
|
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 }"
|
><template #default="{ row }"
|
||||||
><strong>{{ row.name }}</strong>
|
><div class="user-cell">
|
||||||
<p class="secondary">{{ row.username }} · {{ row.account }}</p>
|
<el-avatar :size="36">{{
|
||||||
<small class="secondary">{{
|
(row.name || row.username).slice(0, 1)
|
||||||
new Date(row.createdAt).toLocaleString()
|
}}</el-avatar>
|
||||||
}}</small></template
|
<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
|
||||||
><el-table-column label="账号状态" width="95"
|
>
|
||||||
><template #default="{ row }"
|
<el-table-column label="当前分组 / 返回值" min-width="210"
|
||||||
><el-tag :type="row.status === 'ACTIVE' ? 'success' : 'info'">{{
|
|
||||||
row.status === "ACTIVE" ? "正常" : "已停用"
|
|
||||||
}}</el-tag></template
|
|
||||||
></el-table-column
|
|
||||||
><el-table-column label="分组预览 / 返回值" min-width="200"
|
|
||||||
><template #default="{ row }"
|
><template #default="{ row }"
|
||||||
><template v-if="row.decision"
|
><template v-if="row.decision"
|
||||||
><strong>{{
|
><div class="group-value">
|
||||||
row.decision.variant
|
<el-tag v-if="row.decision.variant"
|
||||||
? row.decision.variant + " 组"
|
>{{ row.decision.variant }} 组</el-tag
|
||||||
: "未入组 · 类型默认值"
|
><strong v-else>未参与实验</strong
|
||||||
}}</strong>
|
><code>{{ summary(row.decision.value) }}</code>
|
||||||
|
</div>
|
||||||
<p class="secondary">
|
<p class="secondary">
|
||||||
{{ reasons[row.decision.reason] ?? row.decision.reason }}
|
{{ reasons[row.decision.reason] ?? row.decision.reason }}
|
||||||
</p>
|
</p></template
|
||||||
<code>{{ summary(row.decision.value) }}</code></template
|
><span v-else class="secondary">选择方案后查看</span></template
|
||||||
><span v-else class="secondary">先选择测试方案</span></template
|
|
||||||
></el-table-column
|
></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 #default="{ row }"
|
||||||
><template v-if="row.override"
|
><template v-if="row.override"
|
||||||
><el-tag :type="overrideActive(row) ? 'warning' : 'info'"
|
><div>
|
||||||
>{{ row.override.variant }} 组 ·
|
{{ row.override.variant }} 组 · {{ overrideStatus(row) }}
|
||||||
{{ overrideActive(row) ? "有效期内" : "已过期" }}</el-tag
|
</div>
|
||||||
>
|
<p class="secondary">
|
||||||
<p class="secondary">{{ row.override.reason }}</p>
|
至 {{ formatTime(row.override.expiresAt) }}
|
||||||
<small class="secondary"
|
</p></template
|
||||||
>到
|
><span v-else class="secondary">—</span></template
|
||||||
{{ new Date(row.override.expiresAt).toLocaleString() }}</small
|
|
||||||
></template
|
|
||||||
><span v-else class="secondary">无</span></template
|
|
||||||
></el-table-column
|
></el-table-column
|
||||||
><el-table-column label="操作" min-width="240" fixed="right"
|
>
|
||||||
|
<el-table-column label="操作" min-width="240" fixed="right"
|
||||||
><template #default="{ row }"
|
><template #default="{ row }"
|
||||||
><el-button
|
><el-button
|
||||||
link
|
link
|
||||||
@@ -297,7 +491,7 @@ onMounted(async () => {
|
|||||||
detail = row;
|
detail = row;
|
||||||
explanation = true;
|
explanation = true;
|
||||||
"
|
"
|
||||||
>分组详情</el-button
|
>详情</el-button
|
||||||
><el-button
|
><el-button
|
||||||
link
|
link
|
||||||
type="primary"
|
type="primary"
|
||||||
@@ -308,22 +502,19 @@ onMounted(async () => {
|
|||||||
loading
|
loading
|
||||||
"
|
"
|
||||||
@click="open(row)"
|
@click="open(row)"
|
||||||
>指定分组</el-button
|
>{{ row.override ? "修改指定" : "指定分组" }}</el-button
|
||||||
><el-button
|
><el-button
|
||||||
v-if="row.override"
|
v-if="row.override"
|
||||||
link
|
link
|
||||||
type="warning"
|
type="warning"
|
||||||
:disabled="loading"
|
:disabled="loading || selected?.state === 'finished'"
|
||||||
@click="restore(row)"
|
@click="restore(row)"
|
||||||
>恢复自动</el-button
|
>取消手动指定</el-button
|
||||||
></template
|
></template
|
||||||
></el-table-column
|
></el-table-column
|
||||||
></el-table
|
>
|
||||||
>
|
</el-table>
|
||||||
<el-empty
|
<el-pagination
|
||||||
v-if="!items.length && !loading"
|
|
||||||
description="没有匹配的账号"
|
|
||||||
/><el-pagination
|
|
||||||
v-model:current-page="page"
|
v-model:current-page="page"
|
||||||
:page-size="size"
|
:page-size="size"
|
||||||
:total="total"
|
:total="total"
|
||||||
@@ -334,99 +525,209 @@ onMounted(async () => {
|
|||||||
</el-card>
|
</el-card>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="editor"
|
v-model="editor"
|
||||||
title="指定用户分组"
|
:title="detail?.override ? '修改用户指定分组' : '指定用户分组'"
|
||||||
width="min(560px,95vw)"
|
width="min(640px,95vw)"
|
||||||
|
class="assignment-dialog"
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
><el-form label-position="top"
|
>
|
||||||
><el-form-item label="当前测试方案"
|
<el-form label-position="top">
|
||||||
><span>{{ selected?.name }}</span></el-form-item
|
<el-form-item label="当前测试方案"
|
||||||
><el-form-item label="账号"
|
><strong>{{ selected?.name }}</strong
|
||||||
><strong
|
><el-tag class="state-tag">{{
|
||||||
>{{ detail?.name }} · {{ form.account }}</strong
|
selected ? states[selected.state] : ""
|
||||||
></el-form-item
|
}}</el-tag></el-form-item
|
||||||
><el-form-item label="指定分组"
|
>
|
||||||
><el-radio-group v-model="form.variant"
|
<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
|
><el-radio
|
||||||
v-for="group in selected?.config.groups ?? []"
|
v-for="group in selected?.config.groups ?? []"
|
||||||
:key="group.key"
|
:key="group.key"
|
||||||
:value="group.key"
|
:value="group.key"
|
||||||
>{{ group.key }} 组({{ group.weight / 100 }}%)</el-radio
|
border
|
||||||
|
><span>{{ group.key }} 组 · 返回 {{ summary(group.value) }}</span
|
||||||
|
><span class="secondary">
|
||||||
|
自动分流 {{ group.weight / 100 }}%</span
|
||||||
|
></el-radio
|
||||||
></el-radio-group
|
></el-radio-group
|
||||||
></el-form-item
|
>
|
||||||
><el-form-item label="有效期(最多 30 天)"
|
<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
|
><el-date-picker
|
||||||
:model-value="new Date(form.expiresAt)"
|
:model-value="new Date(form.expiresAt)"
|
||||||
type="datetime"
|
type="datetime"
|
||||||
|
:clearable="false"
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
v => {
|
v => {
|
||||||
if (v) form.expiresAt = new Date(v).toISOString();
|
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
|
><el-input
|
||||||
v-model="form.reason"
|
v-model="form.reason"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:rows="3"
|
:rows="2"
|
||||||
maxlength="500" /></el-form-item
|
maxlength="500"
|
||||||
><el-checkbox v-model="form.bypassAudience"
|
show-word-limit
|
||||||
>明确允许此账号越过人群限制</el-checkbox
|
placeholder="例如:测试账号验证新版界面(至少 2 个字)"
|
||||||
><el-alert
|
/></el-form-item>
|
||||||
title="人工指定优先于流量和稳定分组。方案未运行时使用类型默认返回值;恢复自动后保留原稳定分组,所有操作记录审计。"
|
<el-alert
|
||||||
|
:title="
|
||||||
|
selected?.state === 'running'
|
||||||
|
? '保存后,应用下次读取此方案时使用指定组的返回值。请在已接入该实验类型的前台验证效果。'
|
||||||
|
: '当前方案未运行,保存只记录指定关系,不会切换前台。方案运行且指定未过期后才会生效。'
|
||||||
|
"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
class="content" /></el-form
|
type="info"
|
||||||
><template #footer
|
/>
|
||||||
|
</el-form>
|
||||||
|
<template #footer
|
||||||
><el-button @click="editor = false">取消</el-button
|
><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
|
></template
|
||||||
></el-dialog
|
>
|
||||||
>
|
</el-dialog>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="explanation"
|
v-model="explanation"
|
||||||
title="用户分组详情(只读)"
|
title="用户分组详情"
|
||||||
width="min(600px,95vw)"
|
width="min(640px,95vw)"
|
||||||
><el-descriptions v-if="detail" :column="1" border
|
>
|
||||||
><el-descriptions-item label="账号"
|
<el-descriptions v-if="detail" :column="1" border>
|
||||||
|
<el-descriptions-item label="用户"
|
||||||
>{{ detail.name }} · {{ detail.account }}</el-descriptions-item
|
>{{ detail.name }} · {{ detail.account }}</el-descriptions-item
|
||||||
><el-descriptions-item label="注册时间">{{
|
>
|
||||||
new Date(detail.createdAt).toLocaleString()
|
<el-descriptions-item label="注册时间">{{
|
||||||
}}</el-descriptions-item
|
formatTime(detail.createdAt)
|
||||||
><el-descriptions-item label="当前预览"
|
}}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="当前结果"
|
||||||
>{{
|
>{{
|
||||||
detail.decision?.variant
|
detail.decision?.variant
|
||||||
? detail.decision.variant + " 组"
|
? detail.decision.variant + " 组"
|
||||||
: "未入组 · 类型默认值"
|
: "未参与实验"
|
||||||
}}
|
}}
|
||||||
· {{ reasons[detail.decision?.reason ?? ""] }}</el-descriptions-item
|
· {{ reasons[detail.decision?.reason ?? ""] }}
|
||||||
><el-descriptions-item label="返回值">
|
<pre>{{ JSON.stringify(detail.decision?.value, null, 2) }}</pre>
|
||||||
<pre>{{
|
</el-descriptions-item>
|
||||||
JSON.stringify(detail.decision?.value, null, 2)
|
<el-descriptions-item label="实际入组记录"
|
||||||
}}</pre></el-descriptions-item
|
>{{
|
||||||
><el-descriptions-item label="已保存的稳定分组">{{
|
detail.assignment
|
||||||
detail.assignment ? detail.assignment.variant + " 组" : "尚未实际入组"
|
? detail.assignment.variant +
|
||||||
}}</el-descriptions-item
|
" 组 · " +
|
||||||
><el-descriptions-item label="人工指定">{{
|
formatTime(detail.assignment.createdAt)
|
||||||
detail.override
|
: "尚无自动入组记录"
|
||||||
? detail.override.variant + " 组;" + detail.override.reason
|
}}
|
||||||
: "无"
|
<p class="secondary">
|
||||||
}}</el-descriptions-item
|
手动指定单独记录,不覆盖原自动分组。
|
||||||
><el-descriptions-item label="越过人群限制">{{
|
</p></el-descriptions-item
|
||||||
detail.override?.bypassAudience ? "是" : "否"
|
>
|
||||||
}}</el-descriptions-item></el-descriptions
|
<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
|
><el-alert
|
||||||
title="预览按当前规则和账号注册时间计算。首次实际调用才保存分组,实际展示后才计曝光。"
|
title="页面查询不会让用户入组或记录曝光;前台需实际接入并读取实验结果,才能验证功能变化。"
|
||||||
type="info"
|
type="info"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
class="content"
|
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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.heading {
|
.heading,
|
||||||
|
.table-toolbar,
|
||||||
|
.plan-filters,
|
||||||
|
.search-actions,
|
||||||
|
.user-cell,
|
||||||
|
.group-value {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
gap: 12px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heading,
|
||||||
|
.table-toolbar {
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
@@ -447,16 +748,39 @@ onMounted(async () => {
|
|||||||
margin-top: 18px;
|
margin-top: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filters {
|
.plan-filters {
|
||||||
display: grid;
|
flex-wrap: wrap;
|
||||||
grid-template-columns: 1fr 1.5fr 1.5fr auto;
|
|
||||||
gap: 12px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.context {
|
.plan-filters :deep(.el-form-item) {
|
||||||
margin-bottom: 18px;
|
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;
|
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 {
|
.pagination {
|
||||||
@@ -464,9 +788,56 @@ onMounted(async () => {
|
|||||||
margin-top: 20px;
|
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,
|
code,
|
||||||
pre {
|
pre {
|
||||||
word-break: break-word;
|
overflow-wrap: anywhere;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,16 +845,36 @@ code {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (width<=760px) {
|
.users-page :deep(.assignment-dialog .el-dialog__body) {
|
||||||
.filters {
|
max-height: 65vh;
|
||||||
grid-template-columns: 1fr;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (width <= 1000px) {
|
||||||
|
.table-toolbar {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (width <= 760px) {
|
||||||
.heading {
|
.heading {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-start;
|
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 {
|
.pagination {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ onMounted(load);
|
|||||||
<div>
|
<div>
|
||||||
<h2>测试方案</h2>
|
<h2>测试方案</h2>
|
||||||
<p>
|
<p>
|
||||||
配置测什么、给谁看、分配多少流量;账号查询与人工分组在「用户管理」。
|
配置测什么、给谁看、分配多少流量;账号查询与人工分组在「实验用户分组」。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -337,7 +337,7 @@ onMounted(load);
|
|||||||
><el-button @click="router.push('/digital/experiment-types')"
|
><el-button @click="router.push('/digital/experiment-types')"
|
||||||
>实验类型</el-button
|
>实验类型</el-button
|
||||||
><el-button @click="router.push('/digital/experiment-users')"
|
><el-button @click="router.push('/digital/experiment-users')"
|
||||||
>用户管理</el-button
|
>实验用户分组</el-button
|
||||||
><el-button type="primary" @click="open()">创建测试方案</el-button>
|
><el-button type="primary" @click="open()">创建测试方案</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -462,7 +462,7 @@ onMounted(load);
|
|||||||
><el-button link type="primary" @click="inspect(row)"
|
><el-button link type="primary" @click="inspect(row)"
|
||||||
>效果与审计</el-button
|
>效果与审计</el-button
|
||||||
><el-button link type="primary" @click="users(row)"
|
><el-button link type="primary" @click="users(row)"
|
||||||
>用户管理</el-button
|
>实验用户分组</el-button
|
||||||
></template
|
></template
|
||||||
></el-table-column
|
></el-table-column
|
||||||
></el-table
|
></el-table
|
||||||
|
|||||||
@@ -0,0 +1,659 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/** 独立 C 端用户管理:开户、内容偏好、停用、改密与区分对白/叙述的持久化聊天记录。 */
|
||||||
|
import { onMounted, ref } from "vue";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import DigitalMessageText from "@/components/DigitalMessageText.vue";
|
||||||
|
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: "",
|
||||||
|
nsfwEnabled: true
|
||||||
|
});
|
||||||
|
const editing = ref<DigitalUser | null>(null),
|
||||||
|
editForm = ref({ displayName: "", status: "ACTIVE", nsfwEnabled: true });
|
||||||
|
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: "",
|
||||||
|
nsfwEnabled: true
|
||||||
|
};
|
||||||
|
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,
|
||||||
|
nsfwEnabled: user.nsfwEnabled ?? true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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: '',
|
||||||
|
nsfwEnabled: true
|
||||||
|
};
|
||||||
|
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 label="NSFW" width="100"
|
||||||
|
><template #default="{ row }"
|
||||||
|
><el-tag :type="row.nsfwEnabled === false ? 'info' : 'success'">{{
|
||||||
|
row.nsfwEnabled === false ? "已关闭" : "已开启"
|
||||||
|
}}</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-item label="NSFW 成人内容"
|
||||||
|
><el-switch
|
||||||
|
v-model="createForm.nsfwEnabled"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<p class="secondary">
|
||||||
|
登录账号默认开启,用户可在前台保存自己的选择。
|
||||||
|
</p>
|
||||||
|
</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-item label="NSFW 成人内容"
|
||||||
|
><el-switch
|
||||||
|
v-model="editForm.nsfwEnabled"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<p class="secondary">保存后用于该账号的后续回复。</p>
|
||||||
|
</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>
|
||||||
|
<DigitalMessageText
|
||||||
|
class="history-message-body"
|
||||||
|
:text="m.content"
|
||||||
|
:role="m.role"
|
||||||
|
:incomplete="
|
||||||
|
['generating', 'stopped', 'failed'].includes(m.status)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</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 .history-message-body {
|
||||||
|
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 .history-message-body {
|
||||||
|
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>
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/** 对白、叙述、旧消息与累计流式文本的格式回归,不依赖浏览器或真实模型。 */
|
||||||
|
import test from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { parseDigitalMessage as parse } from "../src/utils/digital-message-format.ts";
|
||||||
|
|
||||||
|
test("标准消息按剧情顺序拆分叙述、对白与心理,隐藏星号并保留引号", () => {
|
||||||
|
assert.deepEqual(parse("*她合上书。*\n\n“你来了。”\n\n*她终于放松下来。*"), [
|
||||||
|
{ kind: "narration", text: "她合上书。" },
|
||||||
|
{ kind: "dialogue", text: "“你来了。”" },
|
||||||
|
{ kind: "narration", text: "她终于放松下来。" }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("旧消息的成对括号与括号外对白兼容,内层括号不会提前关闭叙述", () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parse(
|
||||||
|
"(她抱起书(封面有些旧),笑了笑)你来了。\n(她心里有些高兴)坐吧。"
|
||||||
|
),
|
||||||
|
[
|
||||||
|
{ kind: "narration", text: "她抱起书(封面有些旧),笑了笑" },
|
||||||
|
{ kind: "dialogue", text: "你来了。" },
|
||||||
|
{ kind: "narration", text: "她心里有些高兴" },
|
||||||
|
{ kind: "dialogue", text: "坐吧。" }
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("旧开场白的无标记叙述与引号对白分别展示,英文撇号不作为对白", () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parse('She picked up her book.\n"You’re early. Don\'t wait outside."'),
|
||||||
|
[
|
||||||
|
{ kind: "narration", text: "She picked up her book." },
|
||||||
|
{ kind: "dialogue", text: '"You’re early. Don\'t wait outside."' }
|
||||||
|
]
|
||||||
|
);
|
||||||
|
for (const [open, close] of [
|
||||||
|
["“", "”"],
|
||||||
|
["「", "」"],
|
||||||
|
["『", "』"],
|
||||||
|
["«", "»"],
|
||||||
|
[""", """]
|
||||||
|
]) {
|
||||||
|
assert.deepEqual(parse(`${open}你好${close}`), [
|
||||||
|
{ kind: "dialogue", text: `${open}你好${close}` }
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("纯文本、普通备注、乘法与不完整的历史标记保留原文", () => {
|
||||||
|
for (const text of [
|
||||||
|
"普通文本",
|
||||||
|
"说明(选填)",
|
||||||
|
"3 * 4 = 12",
|
||||||
|
"file*name.txt",
|
||||||
|
"*未闭合",
|
||||||
|
"(未闭合"
|
||||||
|
]) {
|
||||||
|
assert.deepEqual(parse(text), [{ kind: "plain", text }]);
|
||||||
|
}
|
||||||
|
assert.deepEqual(parse(" \n\r\n"), []);
|
||||||
|
assert.deepEqual(parse("第一段\r\n\r\n第二段"), [
|
||||||
|
{ kind: "plain", text: "第一段" },
|
||||||
|
{ kind: "plain", text: "第二段" }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("显式叙述里的引号保持为故事文本,不再二次推断", () => {
|
||||||
|
assert.deepEqual(parse("*她想到“明天”这个词,轻轻笑了。*"), [
|
||||||
|
{ kind: "narration", text: "她想到“明天”这个词,轻轻笑了。" }
|
||||||
|
]);
|
||||||
|
assert.deepEqual(parse("**“你好。”**"), [
|
||||||
|
{ kind: "dialogue", text: "“你好。”" }
|
||||||
|
]);
|
||||||
|
assert.deepEqual(parse("\\*字面星号\\*"), [
|
||||||
|
{ kind: "plain", text: "*字面星号*" }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("累计流式输入的每个字符前缀都隐藏未闭合星号,完成态排版相同", () => {
|
||||||
|
const source = "*她推开门。*\n\n“你来了。”\n\n*她松了口气。*";
|
||||||
|
for (let end = 1; end <= source.length; end++) {
|
||||||
|
const blocks = parse(source.slice(0, end), true);
|
||||||
|
assert.equal(
|
||||||
|
blocks.some(block => block.text.includes("*")),
|
||||||
|
false,
|
||||||
|
`前缀 ${end}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert.deepEqual(parse(source, true), parse(source));
|
||||||
|
assert.deepEqual(parse("*她推开门", true), [
|
||||||
|
{ kind: "narration", text: "她推开门" }
|
||||||
|
]);
|
||||||
|
assert.deepEqual(parse("(她推开门", true), [
|
||||||
|
{ kind: "narration", text: "她推开门" }
|
||||||
|
]);
|
||||||
|
assert.deepEqual(parse("“你来了", true), [
|
||||||
|
{ kind: "dialogue", text: "“你来了" }
|
||||||
|
]);
|
||||||
|
assert.deepEqual(parse("**Hello", true), [
|
||||||
|
{ kind: "dialogue", text: "Hello" }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("HTML 与脚本内容只作为文本保留,格式解析不会生成任何标签", () => {
|
||||||
|
const text = "<script>globalThis.injected = true</script>";
|
||||||
|
assert.deepEqual(parse(text), [{ kind: "plain", text }]);
|
||||||
|
});
|
||||||