0b7c1cba24
- users.vue: 支持开户、停用、重置密码和按会话查看原始消息 - digital 路由与接口: 区分用户管理和实验用户分组,同步教程与文档
976 lines
32 KiB
Vue
976 lines
32 KiB
Vue
<script setup lang="ts">
|
||
/** 测试方案管理:类型契约、百分比、人群与生命周期;用户分组使用独立页面。 */
|
||
import { computed, onMounted, ref } from "vue";
|
||
import { ElMessage, ElMessageBox } from "element-plus";
|
||
import ExperimentValue from "./experiment-value.vue";
|
||
import { useRouter } from "vue-router";
|
||
import {
|
||
digital,
|
||
type Content,
|
||
type Experiment,
|
||
type ExperimentGroup,
|
||
type ExperimentType
|
||
} from "@/api/access";
|
||
type Account = { account: string; name: string; createdAt: string };
|
||
type Details = {
|
||
assignments: Array<{
|
||
account: string;
|
||
variant: string;
|
||
reason: string;
|
||
createdAt: string;
|
||
}>;
|
||
overrides: Array<{
|
||
account: string;
|
||
variant: string;
|
||
reason: string;
|
||
bypassAudience: boolean;
|
||
expiresAt: string;
|
||
}>;
|
||
metrics: Array<{
|
||
variant: string;
|
||
cohort: string;
|
||
decisions: number;
|
||
assignedUsers: number;
|
||
exposures: number;
|
||
exposedUsers: number;
|
||
}>;
|
||
funnel: Array<{
|
||
variant: string;
|
||
cohort: string;
|
||
eventName: string;
|
||
events: number;
|
||
users: number;
|
||
}>;
|
||
audits: Array<{
|
||
actor: string;
|
||
action: string;
|
||
detail: unknown;
|
||
createdAt: string;
|
||
}>;
|
||
};
|
||
const router = useRouter();
|
||
const scenes = ref<ExperimentType[]>([]);
|
||
const groupValid = ref<Record<string, boolean>>({});
|
||
const filterType = ref("");
|
||
const filtered = computed(() =>
|
||
list.value.filter(e => !filterType.value || e.scope === filterType.value)
|
||
);
|
||
const list = ref<Experiment[]>([]),
|
||
accounts = ref<Account[]>([]),
|
||
presets = ref<Content[]>([]),
|
||
loading = ref(false),
|
||
saving = ref(false),
|
||
edit = ref<Experiment | null>(null),
|
||
editor = ref(false),
|
||
selected = ref<Experiment | null>(null),
|
||
drawer = ref(false),
|
||
details = ref<Details | null>(null),
|
||
detailTab = ref("metrics");
|
||
const eventNames: Record<string, string> = {
|
||
conversation_started: "开启会话",
|
||
message_sent: "发送消息",
|
||
reply_complete: "回复完成",
|
||
reply_stopped: "主动停止",
|
||
reply_failed: "生成失败"
|
||
};
|
||
const stateNames: Record<string, string> = {
|
||
draft: "草稿",
|
||
running: "运行中",
|
||
paused: "已暂停",
|
||
finished: "已结束"
|
||
};
|
||
const audienceNames: Record<string, string> = {
|
||
all: "所有用户",
|
||
new: "新用户",
|
||
existing: "老用户",
|
||
specified: "指定名单"
|
||
};
|
||
const stats = computed(() => ({
|
||
running: list.value.filter(e => e.state === "running").length,
|
||
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 groupTotal = computed(
|
||
() => edit.value?.config.groups.reduce((sum, g) => sum + g.weight, 0) ?? 0
|
||
);
|
||
const groupKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
||
/** 展示服务端按配置顺序累计的半开区间;仅解释首次自动分组,不覆盖稳定分组或人工指定。 */
|
||
function groupRanges(groups: ExperimentGroup[]) {
|
||
if (groups.reduce((sum, group) => sum + group.weight, 0) !== 10000)
|
||
return "分组比例合计达到 100% 后显示区间";
|
||
let start = 0;
|
||
return groups
|
||
.map(group => {
|
||
const text =
|
||
group.weight === 0
|
||
? `${group.key}:0%,不参与自动分流`
|
||
: `${group.key}:${start}~${start + group.weight - 1}`;
|
||
start += group.weight;
|
||
return text;
|
||
})
|
||
.join(";");
|
||
}
|
||
|
||
/** 数字提交后更新万分比并联动两组,避免输入中间值导致控件回显与区间不同步。 */
|
||
function setWeight(group: ExperimentGroup, percentage: number | undefined) {
|
||
if (!edit.value) return;
|
||
group.weight = Math.round((percentage ?? 0) * 100);
|
||
if (edit.value.config.groups.length === 2) {
|
||
const other = edit.value.config.groups.find(g => g.key !== group.key)!;
|
||
other.weight = 10000 - group.weight;
|
||
}
|
||
}
|
||
function addGroup() {
|
||
if (!edit.value || !editingType.value) return;
|
||
const key = groupKeys.find(
|
||
k => !edit.value!.config.groups.some(g => g.key === k)
|
||
);
|
||
if (key)
|
||
edit.value.config.groups.push({
|
||
key,
|
||
weight: 0,
|
||
value: JSON.parse(JSON.stringify(editingType.value.defaultValue))
|
||
});
|
||
}
|
||
function removeGroup(key: string) {
|
||
if (!edit.value || edit.value.config.groups.length <= 1) return;
|
||
edit.value.config.groups = edit.value.config.groups.filter(
|
||
g => g.key !== key
|
||
);
|
||
delete groupValid.value[key];
|
||
}
|
||
function distributeEvenly() {
|
||
if (!edit.value) return;
|
||
const groups = edit.value.config.groups;
|
||
const each = Math.floor(10000 / groups.length),
|
||
extra = 10000 % groups.length;
|
||
groups.forEach((g, i) => {
|
||
g.weight = each + (i < extra ? 1 : 0);
|
||
});
|
||
}
|
||
function fillRemaining(group: ExperimentGroup) {
|
||
group.weight = Math.max(0, 10000 - (groupTotal.value - group.weight));
|
||
}
|
||
function groupSummary(item: Experiment) {
|
||
return item.config.groups.map(g => `${g.key} ${g.weight / 100}%`).join(" · ");
|
||
}
|
||
const editingType = computed(() =>
|
||
scenes.value.find(s => s.id === edit.value?.scope)
|
||
);
|
||
const presetOptions = computed(() =>
|
||
editingType.value?.contract.optionsSource === "presets"
|
||
? presets.value.map(p => ({ label: p.name, value: p.id }))
|
||
: undefined
|
||
);
|
||
/** 类型切换只重置返回值,不改变用户已经配置的组别和比例。 */
|
||
function initializeValues(reset = false) {
|
||
if (!edit.value || !editingType.value) return;
|
||
const type = editingType.value;
|
||
for (const group of edit.value.config.groups) {
|
||
if (reset || group.value === undefined)
|
||
group.value = JSON.parse(
|
||
JSON.stringify(
|
||
type.valueType === "boolean" && group.key === "B"
|
||
? !type.defaultValue
|
||
: type.defaultValue
|
||
)
|
||
);
|
||
}
|
||
groupValid.value = {};
|
||
}
|
||
function users(item: Experiment) {
|
||
router.push({
|
||
path: "/digital/experiment-users",
|
||
query: { experiment: item.id }
|
||
});
|
||
}
|
||
|
||
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, registered] = await Promise.all([
|
||
digital<Experiment[]>("experiments"),
|
||
digital<Account[]>("accounts"),
|
||
digital<Content[]>("content"),
|
||
digital<ExperimentType[]>("experiment-types")
|
||
]);
|
||
scenes.value = registered;
|
||
list.value = experiments;
|
||
accounts.value = users;
|
||
presets.value = content.filter(
|
||
c => c.kind === "preset" && c.status === "published"
|
||
);
|
||
} catch (e) {
|
||
ElMessage.error(e instanceof Error ? e.message : "加载失败");
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
function open(item?: Experiment) {
|
||
edit.value = item
|
||
? JSON.parse(JSON.stringify(item))
|
||
: {
|
||
id: crypto.randomUUID(),
|
||
name: "",
|
||
scope: "",
|
||
state: "draft",
|
||
config: {
|
||
audience: "all",
|
||
accounts: [],
|
||
traffic: 10000,
|
||
groups: [
|
||
{ key: "A", weight: 5000, value: undefined },
|
||
{ key: "B", weight: 5000, value: undefined }
|
||
],
|
||
description: ""
|
||
}
|
||
};
|
||
edit.value.config.groups.sort((a, b) => a.key.localeCompare(b.key));
|
||
initializeValues();
|
||
editor.value = true;
|
||
}
|
||
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("请选择至少一个入组账号,验收时先选择自己");
|
||
if (groupTotal.value !== 10000)
|
||
return ElMessage.warning("所有分组比例合计必须为 100%");
|
||
if (Object.values(groupValid.value).some(valid => !valid))
|
||
return ElMessage.warning("请修正分组返回值的 JSON 格式");
|
||
saving.value = true;
|
||
try {
|
||
await digital(`experiments/${edit.value.id}`, "put", edit.value);
|
||
editor.value = false;
|
||
await load();
|
||
ElMessage.success("实验草稿已保存");
|
||
} catch (e) {
|
||
ElMessage.error(e instanceof Error ? e.message : "保存失败");
|
||
} finally {
|
||
saving.value = false;
|
||
}
|
||
}
|
||
async function move(
|
||
item: Experiment,
|
||
state: "running" | "paused" | "finished",
|
||
winner?: string
|
||
) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
state === "running"
|
||
? `启动「${item.name}」?启动后人群、比例和方案将冻结。`
|
||
: state === "paused"
|
||
? "暂停后用户使用类型默认返回值,已有分组保留。"
|
||
: `结束后所有用户采用 ${winner} 组返回值,实验不能重新启动。`,
|
||
state === "finished" ? "结束实验" : "确认状态变更",
|
||
{ type: "warning", confirmButtonText: "确认", cancelButtonText: "取消" }
|
||
);
|
||
await digital(`experiments/${item.id}/transition`, "post", {
|
||
state,
|
||
revision: item.revision,
|
||
winner
|
||
});
|
||
await load();
|
||
if (selected.value?.id === item.id) {
|
||
selected.value = list.value.find(v => v.id === item.id) ?? null;
|
||
await loadDetails();
|
||
}
|
||
ElMessage.success("状态已更新");
|
||
} catch (e) {
|
||
if (e === "cancel" || e === "close") return;
|
||
ElMessage.error(e instanceof Error ? e.message : "状态变更失败");
|
||
}
|
||
}
|
||
async function inspect(item: Experiment) {
|
||
selected.value = item;
|
||
details.value = null;
|
||
detailTab.value = "metrics";
|
||
drawer.value = true;
|
||
await loadDetails();
|
||
}
|
||
async function loadDetails() {
|
||
if (!selected.value) return;
|
||
try {
|
||
details.value = await digital<Details>(
|
||
`experiments/${selected.value.id}/details`
|
||
);
|
||
} catch (e) {
|
||
ElMessage.error(e instanceof Error ? e.message : "明细读取失败");
|
||
}
|
||
}
|
||
function accountLabel(account: string) {
|
||
const a = accounts.value.find(a => a.account === account);
|
||
return a ? `${a.name} (${account})` : account;
|
||
}
|
||
onMounted(load);
|
||
</script>
|
||
<template>
|
||
<div class="experiment-page">
|
||
<div class="heading">
|
||
<div>
|
||
<h2>测试方案</h2>
|
||
<p>
|
||
配置测什么、给谁看、分配多少流量;账号查询与人工分组在「实验用户分组」。
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<el-button @click="router.push('/digital/experiments/guide')"
|
||
>操作指南</el-button
|
||
><el-button @click="router.push('/digital/experiment-types')"
|
||
>实验类型</el-button
|
||
><el-button @click="router.push('/digital/experiment-users')"
|
||
>实验用户分组</el-button
|
||
><el-button type="primary" @click="open()">创建测试方案</el-button>
|
||
</div>
|
||
</div>
|
||
<el-alert
|
||
title="第一次使用:点击「操作指南」查看完整图文教程,按“仅自己验收 → 正式实验 → 保留最终结果”走一遍。保存草稿不会改变前台,启动后才生效。"
|
||
type="info"
|
||
:closable="false"
|
||
style="margin-bottom: 16px"
|
||
/>
|
||
<div class="stats">
|
||
<el-card shadow="never"
|
||
><strong>{{ stats.running }}</strong
|
||
><span>运行中</span></el-card
|
||
><el-card shadow="never"
|
||
><strong>{{ stats.draft }}</strong
|
||
><span>待启动</span></el-card
|
||
><el-card shadow="never"
|
||
><strong>{{ stats.finished }}</strong
|
||
><span>已完成</span></el-card
|
||
>
|
||
</div>
|
||
<el-alert
|
||
title="同一类型消费标识只允许一个未结束方案。新老用户以账号创建时间与显式分界判定;暂停使用类型默认返回值,结束后保留所选组的返回值。"
|
||
type="info"
|
||
:closable="false"
|
||
style="margin-bottom: 20px"
|
||
/>
|
||
<el-card shadow="never"
|
||
><div class="toolbar">
|
||
<el-select
|
||
v-model="filterType"
|
||
clearable
|
||
placeholder="筛选实验类型"
|
||
style="max-width: 320px"
|
||
><el-option
|
||
v-for="t in scenes"
|
||
:key="t.id"
|
||
:label="t.name"
|
||
:value="t.id" /></el-select
|
||
><el-button @click="load">刷新</el-button>
|
||
</div>
|
||
<el-table v-loading="loading" :data="filtered"
|
||
><el-table-column label="实验" min-width="240"
|
||
><template #default="{ row }"
|
||
><strong>{{ row.name }}</strong>
|
||
<p class="secondary">{{ row.config.description }}</p>
|
||
<small class="secondary">{{ row.id }}</small></template
|
||
></el-table-column
|
||
><el-table-column label="实验类型" min-width="140"
|
||
><template #default="{ row }"
|
||
>{{ sceneName(row.scope) }}
|
||
<p
|
||
v-if="
|
||
scenes.find(t => t.id === row.scope)?.integrationState !==
|
||
'confirmed'
|
||
"
|
||
class="secondary"
|
||
>
|
||
待接入验收,暂不可启动
|
||
</p></template
|
||
></el-table-column
|
||
><el-table-column label="状态" width="100"
|
||
><template #default="{ row }"
|
||
><el-tag
|
||
:type="
|
||
row.state === 'running'
|
||
? 'success'
|
||
: row.state === 'paused'
|
||
? 'warning'
|
||
: 'info'
|
||
"
|
||
>{{ stateNames[row.state] }}</el-tag
|
||
></template
|
||
></el-table-column
|
||
><el-table-column label="人群 / 比例" min-width="180"
|
||
><template #default="{ row }"
|
||
><div>{{ audienceNames[row.config.audience] }}</div>
|
||
<small class="secondary"
|
||
>实验流量 {{ row.config.traffic / 100 }}%<br />{{
|
||
groupSummary(row)
|
||
}}</small
|
||
></template
|
||
></el-table-column
|
||
><el-table-column label="操作" min-width="260" fixed="right"
|
||
><template #default="{ row }"
|
||
><el-button
|
||
v-if="row.state === 'draft'"
|
||
link
|
||
type="primary"
|
||
@click="open(row)"
|
||
>编辑</el-button
|
||
><el-button
|
||
v-if="row.state === 'draft' || row.state === 'paused'"
|
||
link
|
||
type="success"
|
||
:disabled="
|
||
scenes.find(t => t.id === row.scope)?.integrationState !==
|
||
'confirmed'
|
||
"
|
||
@click="move(row, 'running')"
|
||
>{{ row.state === "draft" ? "启动" : "恢复" }}</el-button
|
||
><el-button
|
||
v-if="row.state === 'running'"
|
||
link
|
||
type="warning"
|
||
@click="move(row, 'paused')"
|
||
>暂停</el-button
|
||
><el-dropdown
|
||
v-if="row.state === 'running' || row.state === 'paused'"
|
||
@command="v => move(row, 'finished', v)"
|
||
><el-button link type="danger">结束实验</el-button
|
||
><template #dropdown
|
||
><el-dropdown-menu
|
||
><el-dropdown-item
|
||
v-for="group in row.config.groups"
|
||
:key="group.key"
|
||
:command="group.key"
|
||
>保留 {{ group.key }} 组</el-dropdown-item
|
||
></el-dropdown-menu
|
||
></template
|
||
></el-dropdown
|
||
><el-button link type="primary" @click="inspect(row)"
|
||
>效果与审计</el-button
|
||
><el-button link type="primary" @click="users(row)"
|
||
>实验用户分组</el-button
|
||
></template
|
||
></el-table-column
|
||
></el-table
|
||
><el-empty
|
||
v-if="!filtered.length && !loading"
|
||
description="从一条可解释的实验开始"
|
||
/></el-card>
|
||
<el-dialog
|
||
v-model="editor"
|
||
title="测试方案草稿"
|
||
class="experiment-dialog"
|
||
top="5vh"
|
||
width="min(880px,95vw)"
|
||
:close-on-click-modal="false"
|
||
destroy-on-close
|
||
><el-form v-if="edit" label-position="top">
|
||
<div class="form-grid">
|
||
<el-form-item label="名称" required
|
||
><el-input v-model="edit.name" maxlength="120"
|
||
/></el-form-item>
|
||
<el-form-item label="实验类型"
|
||
><el-select
|
||
v-model="edit.scope"
|
||
placeholder="选择实验类型"
|
||
@change="initializeValues(true)"
|
||
><el-option
|
||
v-for="s in scenes"
|
||
:key="s.id"
|
||
:value="s.id"
|
||
:label="s.name"
|
||
:disabled="!s.enabled" /></el-select
|
||
></el-form-item>
|
||
</div>
|
||
<el-form-item label="实验目标与验收指标"
|
||
><el-input
|
||
v-model="edit.config.description"
|
||
type="textarea"
|
||
:rows="2"
|
||
placeholder="例如:观察首次聊天转化和用户反馈,确认新版交互是否改善体验。" /></el-form-item
|
||
><el-divider content-position="left">实验人群</el-divider
|
||
><el-form-item label="入组范围"
|
||
><el-radio-group v-model="edit.config.audience"
|
||
><el-radio value="all">所有用户</el-radio
|
||
><el-radio value="new">新用户</el-radio
|
||
><el-radio value="existing">老用户</el-radio
|
||
><el-radio value="specified">指定名单</el-radio></el-radio-group
|
||
></el-form-item
|
||
><el-form-item
|
||
v-if="
|
||
edit.config.audience === 'new' ||
|
||
edit.config.audience === 'existing'
|
||
"
|
||
label="注册时间分界(新用户 ≥ 分界,老用户 < 分界)"
|
||
><el-date-picker
|
||
:model-value="
|
||
edit.config.cutoff ? new Date(edit.config.cutoff) : undefined
|
||
"
|
||
type="datetime"
|
||
placeholder="选择本地时间"
|
||
@update:model-value="
|
||
v => {
|
||
if (edit)
|
||
edit.config.cutoff = v
|
||
? new Date(v).toISOString()
|
||
: undefined;
|
||
}
|
||
"
|
||
/>
|
||
<p class="secondary">
|
||
按本地时区显示,服务端以 UTC 保存;创建时间取账号表。
|
||
</p></el-form-item
|
||
><el-form-item
|
||
v-if="edit.config.audience === 'specified'"
|
||
label="指定入组账号"
|
||
><el-select v-model="edit.config.accounts" multiple filterable
|
||
><el-option
|
||
v-for="a in accounts"
|
||
:key="a.account"
|
||
:label="`${a.name} (${a.account})`"
|
||
:value="a.account" /></el-select
|
||
></el-form-item>
|
||
<el-form-item label="进入实验的流量(%)">
|
||
<el-input-number
|
||
v-model="trafficPercent"
|
||
:min="0"
|
||
:max="100"
|
||
:precision="2"
|
||
:step="1"
|
||
/>
|
||
<p class="secondary">
|
||
目标人群中有多少人参与实验;未参与的用户使用类型默认返回值。
|
||
</p>
|
||
</el-form-item>
|
||
<section class="group-config" aria-label="分组配置">
|
||
<div class="group-heading">
|
||
<strong>分组配置</strong>
|
||
<el-tag
|
||
:type="groupTotal === 10000 ? 'success' : 'danger'"
|
||
role="status"
|
||
>合计 {{ (groupTotal / 100).toFixed(2) }}% / 100%</el-tag
|
||
>
|
||
</div>
|
||
<p class="secondary">
|
||
默认 A、B 两组,可添加到 Z。0%
|
||
组不会自动分流,仍可人工指定;返回值不因比例改变。
|
||
</p>
|
||
<div class="allocation-rule">
|
||
<strong>分组方式:按账号稳定随机分配</strong>
|
||
<p>
|
||
账号标识与本次测试方案 ID 共同算出固定的 0~9999
|
||
数字,落在哪个区间就进入哪组。
|
||
</p>
|
||
<p class="allocation-ranges">
|
||
当前自动分组区间:{{ groupRanges(edit.config.groups) }}
|
||
</p>
|
||
<p>
|
||
首次实际入组后保存分组,刷新、重新登录仍保持同组;有效的人工指定优先。比例是分配概率,不保证小样本人数恰好相等。
|
||
</p>
|
||
<el-collapse>
|
||
<el-collapse-item
|
||
title="查看具体计算步骤与优先顺序"
|
||
name="algorithm"
|
||
>
|
||
<ol class="allocation-steps">
|
||
<li>
|
||
先检查入组范围。“所有用户”表示所有账号都有资格参与,不按性别、年龄或账号尾号分组。
|
||
</li>
|
||
<li>
|
||
符合人群或获准越过人群限制的有效人工指定,直接使用指定组;否则已保存的稳定分组优先。
|
||
</li>
|
||
<li>
|
||
首次自动分配先计算流量桶,数字小于“进入实验的流量 ×
|
||
100”才入组;未入组使用类型默认返回值。
|
||
</li>
|
||
<li>
|
||
入组后另算分组桶,按上方各组比例的累计区间分配。流量桶和分组桶独立,0%组不接收自动流量。
|
||
</li>
|
||
</ol>
|
||
<p>
|
||
技术算法:SHA-256
|
||
处理下方字符串,取摘要前4字节的无符号大端整数,再对10000取余。
|
||
</p>
|
||
<code>dh-v1\0{用途}\0{测试方案ID}\0{账号标识}</code>
|
||
<p>
|
||
用途分别为 traffic(流量)和 variant(分组);\0
|
||
为分隔符。账号标识包含账号类型与ID。新建方案的ID不同,同一账号可能分到不同组。
|
||
</p>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
</div>
|
||
<el-table :data="edit.config.groups" row-key="key">
|
||
<el-table-column label="组别" width="70"
|
||
><template #default="{ row }"
|
||
><el-tag type="info">{{ row.key }}</el-tag></template
|
||
></el-table-column
|
||
>
|
||
<el-table-column label="分流比例(%)" width="200"
|
||
><template #default="{ row }">
|
||
<el-input-number
|
||
:model-value="row.weight / 100"
|
||
:aria-label="`${row.key}组分流比例`"
|
||
:min="0"
|
||
:max="100"
|
||
:precision="2"
|
||
:step="1"
|
||
@change="v => setWeight(row, v)"
|
||
/>
|
||
<el-button
|
||
v-if="groupTotal < 10000"
|
||
link
|
||
type="primary"
|
||
@click="fillRemaining(row)"
|
||
>补足剩余</el-button
|
||
>
|
||
</template></el-table-column
|
||
>
|
||
<el-table-column label="返回值" min-width="220"
|
||
><template #default="{ row }">
|
||
<ExperimentValue
|
||
v-if="editingType"
|
||
:key="editingType.id + row.key"
|
||
v-model="row.value"
|
||
:kind="editingType.valueType"
|
||
:options="presetOptions"
|
||
@valid="v => (groupValid[row.key] = v)"
|
||
/>
|
||
<span v-else class="secondary">请先选择实验类型</span>
|
||
</template></el-table-column
|
||
>
|
||
<el-table-column label="操作" width="85"
|
||
><template #default="{ row }"
|
||
><el-button
|
||
link
|
||
type="danger"
|
||
:disabled="edit.config.groups.length <= 1"
|
||
:aria-label="`删除${row.key}组`"
|
||
@click="removeGroup(row.key)"
|
||
>删除</el-button
|
||
></template
|
||
></el-table-column
|
||
>
|
||
</el-table>
|
||
<div class="group-actions">
|
||
<el-button
|
||
:disabled="!editingType || edit.config.groups.length >= 26"
|
||
@click="addGroup"
|
||
>添加分组</el-button
|
||
><el-button @click="distributeEvenly">平均分配</el-button
|
||
><span class="secondary"
|
||
>{{ edit.config.groups.length }} / 26 组</span
|
||
>
|
||
</div>
|
||
<el-alert
|
||
v-if="groupTotal !== 10000"
|
||
type="error"
|
||
:closable="false"
|
||
title="请调整各组比例,合计达到 100% 后才能保存。"
|
||
/>
|
||
</section>
|
||
<el-alert
|
||
v-if="editingType && editingType.integrationState !== 'confirmed'"
|
||
type="warning"
|
||
title="该类型尚未完成应用接入验收,可以保存草稿;完成接入与验收后才能启动。"
|
||
:closable="false" />
|
||
<p v-if="editingType" class="secondary">
|
||
未参与实验或实验暂停时,返回类型默认值:{{
|
||
JSON.stringify(editingType.defaultValue)
|
||
}},不属于任何实验组。
|
||
</p>
|
||
<el-alert
|
||
title="启动前请核对人群和比例。启动后规则冻结,需要新规则时创建下一条实验。"
|
||
:closable="false" /></el-form
|
||
><template #footer
|
||
><el-button @click="editor = false">取消</el-button
|
||
><el-button
|
||
type="primary"
|
||
:loading="saving"
|
||
:disabled="
|
||
groupTotal !== 10000 || Object.values(groupValid).some(v => !v)
|
||
"
|
||
@click="save"
|
||
>保存草稿</el-button
|
||
></template
|
||
></el-dialog
|
||
>
|
||
<el-drawer
|
||
v-model="drawer"
|
||
:title="selected?.name"
|
||
size="min(960px,96vw)"
|
||
destroy-on-close
|
||
><template v-if="selected"
|
||
><div class="detail-summary">
|
||
<el-tag>{{ stateNames[selected.state] }}</el-tag
|
||
><span>{{ sceneName(selected.scope) }}</span
|
||
><small>版本 {{ selected.revision }}</small>
|
||
</div>
|
||
<div class="allocation-rule">
|
||
<strong>分组方式:按账号稳定随机分配</strong>
|
||
<p>
|
||
账号标识与本次方案 ID 计算固定的 0~9999
|
||
数字,按累计比例区间首次分组;已保存的稳定分组保留,有效人工指定优先。
|
||
</p>
|
||
<p class="allocation-ranges">
|
||
当前自动分组区间:{{ groupRanges(selected.config.groups) }}
|
||
</p>
|
||
</div>
|
||
<el-table :data="selected.config.groups" class="group-details">
|
||
<el-table-column prop="key" label="组别" width="80" />
|
||
<el-table-column label="分流比例" width="120"
|
||
><template #default="{ row }"
|
||
>{{ row.weight / 100 }}%</template
|
||
></el-table-column
|
||
>
|
||
<el-table-column label="返回值"
|
||
><template #default="{ row }"
|
||
><code>{{ JSON.stringify(row.value) }}</code></template
|
||
></el-table-column
|
||
>
|
||
</el-table>
|
||
<el-tabs v-model="detailTab"
|
||
><el-tab-pane label="效果概览" name="metrics"
|
||
><el-alert
|
||
title="只统计实际入组流量,人工指定单列。曝光在可见页面渲染后记录,漏斗按服务端决策归因;仅作描述性统计。"
|
||
type="info"
|
||
:closable="false" /><el-table :data="details?.metrics ?? []"
|
||
><el-table-column prop="variant" label="组别" /><el-table-column
|
||
label="人群"
|
||
><template #default="{ row }">{{
|
||
row.cohort === "manual" ? "人工指定" : "规则分组"
|
||
}}</template></el-table-column
|
||
><el-table-column
|
||
prop="decisions"
|
||
label="决策次数" /><el-table-column
|
||
prop="assignedUsers"
|
||
label="决策人数" /><el-table-column
|
||
prop="exposures"
|
||
label="曝光次数" /><el-table-column
|
||
prop="exposedUsers"
|
||
label="曝光人数" /></el-table
|
||
><el-empty
|
||
v-if="!details?.metrics.length"
|
||
description="尚无决策记录" />
|
||
<h3 style="margin: 24px 0 12px">使用漏斗</h3>
|
||
<el-table :data="details?.funnel ?? []"
|
||
><el-table-column prop="variant" label="组别" /><el-table-column
|
||
label="人群"
|
||
><template #default="{ row }">{{
|
||
row.cohort === "manual" ? "人工指定" : "规则分组"
|
||
}}</template></el-table-column
|
||
><el-table-column label="行为"
|
||
><template #default="{ row }">{{
|
||
eventNames[row.eventName]
|
||
}}</template></el-table-column
|
||
><el-table-column prop="events" label="次数" /><el-table-column
|
||
prop="users"
|
||
label="人数" /></el-table
|
||
></el-tab-pane>
|
||
<el-tab-pane label="操作审计" name="audits"
|
||
><el-timeline
|
||
><el-timeline-item
|
||
v-for="(a, i) in details?.audits ?? []"
|
||
:key="i"
|
||
:timestamp="new Date(a.createdAt).toLocaleString()"
|
||
><strong>{{ a.action }}</strong>
|
||
<p>{{ accountLabel(a.actor) }}</p>
|
||
<pre>{{
|
||
typeof a.detail === "string"
|
||
? a.detail
|
||
: JSON.stringify(a.detail, null, 2)
|
||
}}</pre>
|
||
</el-timeline-item></el-timeline
|
||
></el-tab-pane
|
||
></el-tabs
|
||
></template
|
||
></el-drawer
|
||
>
|
||
</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;
|
||
max-height: 90vh;
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
:global(.experiment-dialog .el-dialog__body) {
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.group-details {
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.group-config {
|
||
margin: 8px 0 20px;
|
||
}
|
||
|
||
.group-heading,
|
||
.group-actions {
|
||
display: flex;
|
||
gap: 12px;
|
||
align-items: center;
|
||
}
|
||
|
||
.group-heading {
|
||
justify-content: space-between;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.group-actions {
|
||
margin: 16px 0;
|
||
}
|
||
|
||
.heading {
|
||
display: flex;
|
||
gap: 15px;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 24px;
|
||
}
|
||
|
||
.heading h2 {
|
||
margin: 0 0 8px;
|
||
font-size: 24px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.heading p,
|
||
.secondary {
|
||
margin: 4px 0;
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.stats {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 16px;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.stats strong {
|
||
display: block;
|
||
font-size: 30px;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.stats span {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.form-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 0 20px;
|
||
}
|
||
|
||
.el-select {
|
||
width: 100%;
|
||
}
|
||
|
||
.toolbar {
|
||
display: flex;
|
||
gap: 15px;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.detail-summary {
|
||
display: flex;
|
||
gap: 15px;
|
||
align-items: center;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.detail-summary span {
|
||
font-size: 13px;
|
||
}
|
||
|
||
.detail-summary small {
|
||
margin-left: auto;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
pre {
|
||
max-height: 260px;
|
||
padding: 12px;
|
||
overflow: auto;
|
||
font-size: 11px;
|
||
word-break: break-word;
|
||
white-space: pre-wrap;
|
||
background: var(--el-fill-color-light);
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.el-dropdown {
|
||
margin: 0 10px;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
@media (width <= 650px) {
|
||
.form-grid {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.heading {
|
||
flex-direction: column;
|
||
align-items: flex-start;
|
||
}
|
||
|
||
.stats {
|
||
gap: 8px;
|
||
}
|
||
|
||
.toolbar {
|
||
flex-wrap: wrap;
|
||
}
|
||
}
|
||
</style>
|