feat(experiments): 发布完整截图教程与分组规则说明

- 操作指南改为带目录和图片放大的二级教程页面,完整覆盖实验生命周期
- 用隔离演示数据拍摄14张实际组件截图,生成编号箭头标注与共享内容README
- 标明稳定分组算法与比例区间,修正比例输入提交时的回显同步
- 同步路由、项目目录和教程资源一致性校验脚本
This commit is contained in:
湛兮
2026-10-27 16:13:49 +08:00
parent df7b9a0cb3
commit c406f8c127
36 changed files with 1523 additions and 88 deletions
+11
View File
@@ -26,6 +26,17 @@ export default {
component: () => import("@/views/digital/experiments.vue"),
meta: { title: "测试方案", permission: "*" }
},
{
path: "/digital/experiments/guide",
name: "DigitalExperimentGuide",
component: () => import("@/views/digital/experiment-guide.vue"),
meta: {
title: "实验操作指南",
permission: "*",
showLink: false,
activePath: "/digital/experiments"
}
},
{
path: "/digital/experiment-users",
name: "DigitalExperimentUsers",
+267
View File
@@ -0,0 +1,267 @@
<script setup lang="ts">
/** 实验图文教程二级页:与仓库README共用内容源,截图标注只来自隔离演示。 */
import { useRouter } from "vue-router";
import guide from "../../../docs/experiments/guide.json";
const router = useRouter();
const images = guide.steps.flatMap(step =>
(step.images ?? []).map(image => `/guides/experiments/${image}.svg`)
);
/** 在当前二级页内滚动,不修改hash路由,也不触发任何实验写操作。 */
function jump(id: string) {
document
.getElementById(`guide-${id}`)
?.scrollIntoView({ behavior: "smooth", block: "start" });
}
</script>
<template>
<div class="experiment-guide">
<header class="guide-heading">
<div>
<el-tag type="info">从零开始 · 图文教程</el-tag>
<h1>{{ guide.title }}</h1>
<p>{{ guide.intro }}</p>
</div>
<el-button @click="router.push('/digital/experiments')"
>返回测试方案</el-button
>
</header>
<el-alert
title="截图使用实际页面组件与隔离演示数据。红色编号对应下方操作;演示接入与统计状态不代表你的线上类型已经验收。点击图片可放大查看。"
type="info"
:closable="false"
/>
<div class="guide-layout">
<nav class="guide-toc" aria-label="教程目录">
<strong>本页目录</strong
><button
v-for="step in guide.steps"
:key="step.id"
type="button"
@click="jump(step.id)"
>
{{ step.title }}
</button>
</nav>
<article>
<section
v-for="step in guide.steps"
:id="`guide-${step.id}`"
:key="step.id"
class="guide-section"
>
<h2>{{ step.title }}</h2>
<p class="guide-lead">{{ step.lead }}</p>
<figure v-for="image in step.images ?? []" :key="image">
<el-image
:src="`/guides/experiments/${image}.svg`"
:alt="`${step.title},带红色箭头与编号的演示截图`"
:preview-src-list="images"
:initial-index="
images.indexOf(`/guides/experiments/${image}.svg`)
"
preview-teleported
lazy
fit="contain"
><template #error
><div class="image-error">
教程图片加载失败,请刷新重试。
</div></template
></el-image
>
<figcaption>隔离演示截图 · 点击放大 · 编号对应下方操作</figcaption>
<ol class="guide-callouts">
<li v-for="note in guide.captions[image]" :key="note">
{{ note }}
</li>
</ol>
</figure>
<ul>
<li v-for="line in step.bullets" :key="line">{{ line }}</li>
</ul>
<pre v-if="'code' in step"><code>{{ step.code }}</code></pre>
</section>
<footer class="guide-footer">
<p>
教程更新:{{
guide.updated
}}。开始操作前,请确认当前环境与目标账号。
</p>
<el-button @click="router.push('/digital/experiment-types')"
>去实验类型</el-button
><el-button
type="primary"
@click="router.push('/digital/experiments')"
>去测试方案</el-button
><el-button @click="router.push('/digital/experiment-users')"
>去用户管理</el-button
>
</footer>
</article>
</div>
</div>
</template>
<style scoped>
.experiment-guide {
max-width: 1440px;
margin: 0 auto;
}
.guide-heading {
display: flex;
gap: 24px;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 24px;
}
.guide-heading h1 {
margin: 12px 0;
font-size: 28px;
}
.guide-heading p {
max-width: 800px;
line-height: 1.8;
color: var(--el-text-color-secondary);
}
.guide-layout {
display: grid;
grid-template-columns: 220px minmax(0, 1fr);
gap: 32px;
margin-top: 24px;
}
.guide-toc {
position: sticky;
top: 96px;
display: flex;
flex-direction: column;
gap: 6px;
align-self: start;
max-height: calc(100vh - 130px);
padding: 16px;
overflow-y: auto;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color-lighter);
border-radius: 8px;
}
.guide-toc strong {
padding: 4px 8px 12px;
}
.guide-toc button {
padding: 8px;
font: inherit;
font-size: 13px;
color: var(--el-text-color-regular);
text-align: left;
cursor: pointer;
background: transparent;
border: 0;
border-radius: 4px;
}
.guide-toc button:hover {
color: var(--el-color-primary);
background: var(--el-fill-color-light);
}
.guide-toc button:focus-visible {
outline: 2px solid var(--el-color-primary);
outline-offset: 2px;
}
.guide-section {
padding: 24px;
margin-bottom: 24px;
scroll-margin-top: 100px;
background: var(--el-bg-color);
border: 1px solid var(--el-border-color-lighter);
border-radius: 8px;
}
.guide-section h2 {
margin: 0 0 12px;
font-size: 21px;
}
.guide-lead {
line-height: 1.8;
}
.guide-section figure {
margin: 20px 0;
}
.guide-section .el-image {
display: block;
width: 100%;
min-height: 100px;
border: 1px solid var(--el-border-color-lighter);
border-radius: 6px;
}
.guide-section figcaption {
margin-top: 8px;
font-size: 12px;
color: var(--el-text-color-secondary);
text-align: center;
}
.guide-section ul {
padding-left: 22px;
line-height: 1.9;
}
.guide-section li {
margin-bottom: 12px;
overflow-wrap: anywhere;
}
.guide-section pre {
padding: 16px;
overflow-x: auto;
font-size: 12px;
line-height: 1.8;
white-space: pre-wrap;
background: var(--el-fill-color-light);
border-radius: 6px;
}
.image-error {
padding: 24px;
color: var(--el-text-color-secondary);
text-align: center;
}
.guide-footer {
padding: 20px 0 32px;
line-height: 1.8;
}
.guide-footer p {
color: var(--el-text-color-secondary);
}
@media (width <= 900px) {
.guide-layout {
grid-template-columns: 1fr;
gap: 16px;
}
.guide-toc {
position: static;
max-height: 220px;
}
.guide-heading {
flex-direction: column;
}
.guide-section {
padding: 16px;
}
}
</style>
+103 -88
View File
@@ -48,7 +48,6 @@ type Details = {
createdAt: string;
}>;
};
const guideVisible = ref(false);
const router = useRouter();
const scenes = ref<ExperimentType[]>([]);
const groupValid = ref<Record<string, boolean>>({});
@@ -102,7 +101,24 @@ const groupTotal = computed(
() => edit.value?.config.groups.reduce((sum, g) => sum + g.weight, 0) ?? 0
);
const groupKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
/** 两组时自动互补;更多组由用户显式填写,不悄悄改动其他组。 */
/** 展示服务端按配置顺序累计的半开区间;仅解释首次自动分组,不覆盖稳定分组或人工指定。 */
function groupRanges(groups: ExperimentGroup[]) {
if (groups.reduce((sum, group) => sum + group.weight, 0) !== 10000)
return "分组比例合计达到 100% 后显示区间";
let start = 0;
return groups
.map(group => {
const text =
group.weight === 0
? `${group.key}:0%,不参与自动分流`
: `${group.key}:${start}~${start + group.weight - 1}`;
start += group.weight;
return text;
})
.join(";");
}
/** 数字提交后更新万分比并联动两组,避免输入中间值导致控件回显与区间不同步。 */
function setWeight(group: ExperimentGroup, percentage: number | undefined) {
if (!edit.value) return;
group.weight = Math.round((percentage ?? 0) * 100);
@@ -223,21 +239,6 @@ function open(item?: Experiment) {
initializeValues();
editor.value = true;
}
function createTrial() {
open();
if (!edit.value) return;
edit.value.name = "仅自己验收";
edit.value.config.audience = "specified";
edit.value.config.accounts = [];
edit.value.config.traffic = 10000;
edit.value.config.groups.forEach(g => {
g.weight = g.key === "B" ? 10000 : 0;
});
edit.value.config.description =
"选择你创建并接入的实验类型,只选择自己的账号;在指定用户中切换各组对照,验收完成后另建正式方案。";
initializeValues(true);
guideVisible.value = false;
}
async function save() {
if (!edit.value?.scope) return ElMessage.warning("请先创建或选择实验类型");
if (!edit.value?.name.trim()) return ElMessage.warning("请输入方案名称");
@@ -331,7 +332,8 @@ onMounted(load);
</p>
</div>
<div>
<el-button @click="guideVisible = true">操作指南</el-button
<el-button @click="router.push('/digital/experiments/guide')"
>操作指南</el-button
><el-button @click="router.push('/digital/experiment-types')"
>实验类型</el-button
><el-button @click="router.push('/digital/experiment-users')"
@@ -340,7 +342,7 @@ onMounted(load);
</div>
</div>
<el-alert
title="第一次使用:先点「操作指南」,按“仅自己验收 → 正式实验 → 保留最终方案”走一遍。保存草稿不会改变前台,启动后才生效。"
title="第一次使用:点击「操作指南」查看完整图文教程,按“仅自己验收 → 正式实验 → 保留最终结果”走一遍。保存草稿不会改变前台,启动后才生效。"
type="info"
:closable="false"
style="margin-bottom: 16px"
@@ -567,6 +569,50 @@ onMounted(load);
默认 A、B 两组,可添加到 Z。0%
组不会自动分流,仍可人工指定;返回值不因比例改变。
</p>
<div class="allocation-rule">
<strong>分组方式:按账号稳定随机分配</strong>
<p>
账号标识与本次测试方案 ID 共同算出固定的 0~9999
数字,落在哪个区间就进入哪组。
</p>
<p class="allocation-ranges">
当前自动分组区间:{{ groupRanges(edit.config.groups) }}
</p>
<p>
首次实际入组后保存分组,刷新、重新登录仍保持同组;有效的人工指定优先。比例是分配概率,不保证小样本人数恰好相等。
</p>
<el-collapse>
<el-collapse-item
title="查看具体计算步骤与优先顺序"
name="algorithm"
>
<ol class="allocation-steps">
<li>
先检查入组范围。“所有用户”表示所有账号都有资格参与,不按性别、年龄或账号尾号分组。
</li>
<li>
符合人群或获准越过人群限制的有效人工指定,直接使用指定组;否则已保存的稳定分组优先。
</li>
<li>
首次自动分配先计算流量桶,数字小于“进入实验的流量 ×
100”才入组;未入组使用类型默认返回值。
</li>
<li>
入组后另算分组桶,按上方各组比例的累计区间分配。流量桶和分组桶独立,0%组不接收自动流量。
</li>
</ol>
<p>
技术算法:SHA-256
处理下方字符串,取摘要前4字节的无符号大端整数,再对10000取余。
</p>
<code>dh-v1\0{用途}\0{测试方案ID}\0{账号标识}</code>
<p>
用途分别为 traffic(流量)和 variant(分组);\0
为分隔符。账号标识包含账号类型与ID。新建方案的ID不同,同一账号可能分到不同组。
</p>
</el-collapse-item>
</el-collapse>
</div>
<el-table :data="edit.config.groups" row-key="key">
<el-table-column label="组别" width="70"
><template #default="{ row }"
@@ -582,7 +628,7 @@ onMounted(load);
:max="100"
:precision="2"
:step="1"
@update:model-value="v => setWeight(row, v)"
@change="v => setWeight(row, v)"
/>
<el-button
v-if="groupTotal < 10000"
@@ -673,6 +719,16 @@ onMounted(load);
><span>{{ sceneName(selected.scope) }}</span
><small>版本 {{ selected.revision }}</small>
</div>
<div class="allocation-rule">
<strong>分组方式:按账号稳定随机分配</strong>
<p>
账号标识与本次方案 ID 计算固定的 0~9999
数字,按累计比例区间首次分组;已保存的稳定分组保留,有效人工指定优先。
</p>
<p class="allocation-ranges">
当前自动分组区间:{{ groupRanges(selected.config.groups) }}
</p>
</div>
<el-table :data="selected.config.groups" class="group-details">
<el-table-column prop="key" label="组别" width="80" />
<el-table-column label="分流比例" width="120"
@@ -743,62 +799,36 @@ onMounted(load);
></template
></el-drawer
>
<el-dialog
v-model="guideVisible"
title="实验全流程操作指南"
width="min(760px,95vw)"
><ol class="workflow-guide">
<li>
<strong>实验类型:定义测什么</strong>
<p>
侧栏「实验类型 →
创建实验类型」,填写你自己的稳定标识、数据格式和默认值。系统不预置实验类型;先在应用读取决策并使用返回值,再到「接入与验收」确认效果。
</p>
</li>
<li>
<strong>测试方案:定义怎么测</strong>
<p>
选择类型,配置 A~Z 各组的返回值、分流比例与人群。各组比例合计必须为
100%;A 100%、B 0% 时,自动流量全部进入
A。保存只是草稿,启动才生效;启动后规则冻结。
</p>
</li>
<li>
<strong>用户管理:查看与指定谁</strong>
<p>
从方案行点击「用户管理」,搜索账号,查看只读分组预览。点击「指定分组」可指定
任意配置组、有效期与原因;「恢复自动」取消人工指定,回到原稳定分组。预览本身不会分配用户或产生曝光。
</p>
</li>
<li>
<strong>先自己验收,再正式分流</strong>
<p>
选择你已接入的类型,指定名单只选自己,流量 100%、B 组
100%,启动后在应用检查 B 组效果。再到用户管理指定不同组
对照。其他账号使用类型默认返回值。验收完成另建正式方案。
</p>
</li>
<li>
<strong>效果、暂停与结束</strong>
<p>
在「效果与审计」查看决策、曝光、漏斗和操作记录。暂停回类型默认返回值,恢复保留原分组;结束时选择最终
任意组,之后对所有用户长期生效。新类型须在消费者实际展示后调用曝光接口,不能把决策请求当作曝光。
</p>
</li>
</ol>
<el-alert
title="所有管理入口都在后台。前台只读取当前用户的决策,不提供实验控制。"
:closable="false"
/><template #footer
><el-button @click="guideVisible = false">知道了</el-button
><el-button type="primary" @click="createTrial"
>按“仅自己验收”示例创建</el-button
></template
></el-dialog
>
</div>
</template>
<style scoped>
.allocation-rule {
padding: 12px 14px;
margin: 12px 0;
font-size: 13px;
line-height: 1.7;
background: var(--el-fill-color-light);
border: 1px solid var(--el-border-color-lighter);
border-radius: 6px;
}
.allocation-rule p {
margin: 6px 0;
}
.allocation-ranges {
font-variant-numeric: tabular-nums;
}
.allocation-rule code {
overflow-wrap: anywhere;
}
.allocation-steps {
padding-left: 20px;
margin: 8px 0;
}
:global(.experiment-dialog) {
display: flex;
flex-direction: column;
@@ -835,21 +865,6 @@ onMounted(load);
margin: 16px 0;
}
.workflow-guide {
padding-left: 22px;
line-height: 1.8;
}
.workflow-guide li {
margin-bottom: 16px;
}
.workflow-guide p {
margin: 6px 0;
font-size: 13px;
color: var(--el-text-color-secondary);
}
.heading {
display: flex;
gap: 15px;