diff --git a/README.md b/README.md index 77dc6fb..b031ec0 100644 --- a/README.md +++ b/README.md @@ -218,3 +218,5 @@ pnpm build 管理端站内封面从 H5/Web 域名读取,可通过 `VITE_ROLE_USER_BASE_URL` 覆盖;默认按本地、develop、production 环境分别选择 localhost:3210、dev.mrzhan.top、mrzhan.top。 标签页图标采用 `public/stellar-icon-v2.svg`,同时提供多尺寸 `favicon.ico`、180/192/512 PNG,覆盖浏览器、Apple 主屏幕和 PWA。版本化资源路径用于刷新旧图标缓存。 + +实验场景通过后台「账号实验中心 → 管理实验场景」创建和启停,系统预置项标注来源;新增场景复用已实现的整站 UI 或对话接入点,同一接入点的运行/暂停实验互斥。比例统一按百分比输入,50代表50%,保留0.01%精度;接口内部整数精度不变,既有分组不重算。 diff --git a/src/api/access.ts b/src/api/access.ts index fdba03d..35ea2de 100644 --- a/src/api/access.ts +++ b/src/api/access.ts @@ -1158,7 +1158,9 @@ export type Entry = { export type Experiment = { id: string; name: string; - scope: "ui" | "chat"; + scope: string; + runtime?: "ui" | "chat"; + sceneName?: string; state: "draft" | "running" | "paused" | "finished"; revision?: number; config: { @@ -1174,3 +1176,14 @@ export type Experiment = { description: string; }; }; + +/** 实验场景与应用接入点映射。 */ +export type ExperimentScene = { + id: string; + name: string; + runtime: "ui" | "chat"; + description: string; + enabled: number; + builtin: number; + revision: number; +}; diff --git a/src/views/digital/experiments.vue b/src/views/digital/experiments.vue index b04e852..39cda35 100644 --- a/src/views/digital/experiments.vue +++ b/src/views/digital/experiments.vue @@ -2,7 +2,13 @@ /** 账号实验中心:完整生命周期、指定用户、解释和审计均在后台完成。 */ import { computed, onMounted, ref } from "vue"; import { ElMessage, ElMessageBox } from "element-plus"; -import { digital, type Content, type Experiment } from "@/api/access"; +import SceneManager from "./scene-manager.vue"; +import { + digital, + type Content, + type Experiment, + type ExperimentScene +} from "@/api/access"; type Account = { account: string; name: string; createdAt: string }; type Details = { assignments: Array<{ @@ -40,6 +46,9 @@ type Details = { createdAt: string; }>; }; +const guideVisible = ref(false); +const scenes = ref([]), + sceneManager = ref(false); const list = ref([]), accounts = ref([]), presets = ref([]), @@ -97,14 +106,35 @@ const stats = computed(() => ({ draft: list.value.filter(e => e.state === "draft").length, finished: list.value.filter(e => e.state === "finished").length })); +/** 页面以百分比编辑,接口保留整数精度,50%对应5000。 */ +const trafficPercent = computed({ + get: () => (edit.value?.config.traffic ?? 0) / 100, + set: (value: number | undefined) => { + if (edit.value) edit.value.config.traffic = Math.round((value ?? 0) * 100); + } +}); +const weightBPercent = computed({ + get: () => (edit.value?.config.weightB ?? 0) / 100, + set: (value: number | undefined) => { + if (edit.value) edit.value.config.weightB = Math.round((value ?? 0) * 100); + } +}); +const editingRuntime = computed( + () => scenes.value.find(s => s.id === edit.value?.scope)?.runtime +); +function sceneName(id: string) { + return scenes.value.find(s => s.id === id)?.name ?? id; +} async function load() { loading.value = true; try { - const [experiments, users, content] = await Promise.all([ + const [experiments, users, content, registered] = await Promise.all([ digital("experiments"), digital("accounts"), - digital("content") + digital("content"), + digital("scenes") ]); + scenes.value = registered; list.value = experiments; accounts.value = users; presets.value = content.filter( @@ -122,7 +152,11 @@ function open(item?: Experiment) { : { id: crypto.randomUUID(), name: "", - scope: "ui", + scope: + ( + scenes.value.find(s => s.enabled && s.runtime === "ui") ?? + scenes.value.find(s => s.enabled) + )?.id ?? "", state: "draft", config: { audience: "all", @@ -135,13 +169,36 @@ function open(item?: Experiment) { }; editor.value = true; } +function createTrial() { + open(); + if (!edit.value) return; + edit.value.name = "新老 UI 验收"; + edit.value.scope = + ( + scenes.value.find(s => s.id === "ui" && s.enabled) ?? + scenes.value.find(s => s.runtime === "ui" && s.enabled) + )?.id ?? ""; + edit.value.config.audience = "specified"; + edit.value.config.accounts = []; + edit.value.config.traffic = 10000; + edit.value.config.weightB = 10000; + edit.value.config.description = + "只选择自己的账号,启动后先验证新版;在指定用户中切换A/B对照。结束时保留A可维持原界面,再另建正式实验。"; + guideVisible.value = false; +} async function save() { + if (!edit.value?.scope) return ElMessage.warning("请先创建或选择实验场景"); if (!edit.value?.name.trim()) return ElMessage.warning("请输入实验名称"); if ( ["new", "existing"].includes(edit.value.config.audience) && !edit.value.config.cutoff ) return ElMessage.warning("请选择注册时间分界"); + if ( + edit.value.config.audience === "specified" && + !edit.value.config.accounts.length + ) + return ElMessage.warning("请选择至少一个入组账号,验收时先选择自己"); saving.value = true; try { await digital(`experiments/${edit.value.id}`, "put", edit.value); @@ -276,8 +333,18 @@ onMounted(load);

账号实验中心

稳定的登录账号分流。前台消费结果,后台掌控完整实验流程。

- 创建实验 +
+ 操作指南管理实验场景创建实验 +
+
{{ stats.running }}
{{ row.config.description }}

{{ row.id }} +
    +
  1. + 创建场景:测什么 +

    + 点击「管理实验场景 → + 新建场景」,填写名称并选择已接入的功能。预置“新老 + UI”“对话风格”可以直接使用,不必重复创建。 +

    +
  2. +
  3. + 先只让自己验收 +

    + 创建实验,选择新老 UI + 场景;人群选「指定名单」并选择自己的账号,实验流量填100%,B组填100%。保存后还是草稿,不生效。 +

    +
  4. +
  5. + 启动并去前台看效果 +

    + 在列表点击「启动」,再登录前台并刷新。B是现代深色粉,A是经典深色金。仅你的账号入组,其他人使用默认方案。 +

    +
  6. +
  7. + 对照 A/B 并解释分组 +

    + 点击「管理 / 明细 → + 指定用户」,给自己指定A或B并保存;刷新前台查看。通过「分组解释」查实际方案与原因。指定记录有有效期,移除后恢复原分组。 +

    +
  8. +
  9. + 创建正式实验并看指标 +

    + 验收结束时保留A可维持原界面,再创建正式实验:人群选目标用户,流量100%、B组50%,就是入组用户A/B各一半。启动后在「效果概览」看曝光和聊天漏斗。规则启动后冻结,需要新规则时另建实验。 +

    +
  10. +
  11. + 暂停或结束 +

    + 暂停时用户回默认方案,恢复后继续原分组;结束时选择最终A/B方案,会应用于所有用户,不能重新启动。确认要正式推广后再结束并保留新版。 +

    +
  12. +
+
+