0b7c1cba24
- users.vue: 支持开户、停用、重置密码和按会话查看原始消息 - digital 路由与接口: 区分用户管理和实验用户分组,同步教程与文档
415 lines
10 KiB
Vue
415 lines
10 KiB
Vue
<script setup lang="ts">
|
||
/** 实验图文教程二级页:固定目录与独立正文滚动,按实际阅读位置同步当前章节。 */
|
||
import {
|
||
nextTick,
|
||
onActivated,
|
||
onBeforeUnmount,
|
||
onMounted,
|
||
ref,
|
||
watch
|
||
} from "vue";
|
||
import { useRouter } from "vue-router";
|
||
import guide from "../../../docs/experiments/guide.json";
|
||
import screenshotSizes from "../../../docs/experiments/screenshots.json";
|
||
// 为懒加载截图预留真实比例,避免图片出现后章节位置发生跳动。
|
||
const sizes = screenshotSizes as Record<
|
||
string,
|
||
{ width: number; height: number }
|
||
>;
|
||
const router = useRouter();
|
||
const page = ref<HTMLElement>(),
|
||
body = ref<HTMLElement>(),
|
||
toc = ref<HTMLElement>();
|
||
const activeId = ref(guide.steps[0].id);
|
||
let frame = 0,
|
||
observer: ResizeObserver | undefined;
|
||
/** 正文是唯一阅读滚动容器,懒加载图片改变章节高度后也重新判定位置。 */
|
||
function updateReadingPosition() {
|
||
frame = 0;
|
||
if (!page.value?.offsetWidth || !body.value) return;
|
||
const available =
|
||
window.innerHeight - page.value.getBoundingClientRect().top - 24;
|
||
page.value.style.setProperty(
|
||
"--guide-height",
|
||
`${Math.max(360, available)}px`
|
||
);
|
||
const sections = Array.from(
|
||
body.value.querySelectorAll<HTMLElement>(".guide-section")
|
||
);
|
||
const top = body.value.getBoundingClientRect().top + 24;
|
||
let current = sections[0]?.id;
|
||
for (const section of sections) {
|
||
if (section.getBoundingClientRect().top <= top) current = section.id;
|
||
else break;
|
||
}
|
||
// 最后一章可能不足一屏;滚到底部时仍须选中它。
|
||
if (
|
||
body.value.scrollTop + body.value.clientHeight >=
|
||
body.value.scrollHeight - 2
|
||
)
|
||
current = sections.at(-1)?.id;
|
||
if (current) activeId.value = current.replace(/^guide-/, "");
|
||
}
|
||
function scheduleUpdate() {
|
||
if (!frame) frame = requestAnimationFrame(updateReadingPosition);
|
||
}
|
||
onMounted(() => {
|
||
window.addEventListener("resize", scheduleUpdate);
|
||
observer = new ResizeObserver(scheduleUpdate);
|
||
if (page.value) observer.observe(page.value);
|
||
if (body.value) {
|
||
observer.observe(body.value);
|
||
body.value
|
||
.querySelectorAll(".guide-section")
|
||
.forEach(section => observer!.observe(section));
|
||
}
|
||
scheduleUpdate();
|
||
});
|
||
onActivated(scheduleUpdate);
|
||
onBeforeUnmount(() => {
|
||
window.removeEventListener("resize", scheduleUpdate);
|
||
observer?.disconnect();
|
||
cancelAnimationFrame(frame);
|
||
});
|
||
watch(activeId, async id => {
|
||
await nextTick();
|
||
const button = toc.value?.querySelector<HTMLElement>(
|
||
`[data-section="${id}"]`
|
||
);
|
||
if (!button || !toc.value) return;
|
||
const item = button.getBoundingClientRect(),
|
||
menu = toc.value.getBoundingClientRect();
|
||
// 仅移动目录内部,避免 scrollIntoView 带动后台外层容器。
|
||
if (item.top < menu.top || item.bottom > menu.bottom)
|
||
toc.value.scrollTop +=
|
||
item.top - menu.top - toc.value.clientHeight / 2 + item.height / 2;
|
||
});
|
||
const images = guide.steps.flatMap(step =>
|
||
(step.images ?? []).map(image => `/guides/experiments/${image}.svg`)
|
||
);
|
||
/** 在当前二级页内滚动,不修改hash路由,也不触发任何实验写操作。 */
|
||
function jump(id: string) {
|
||
const section = body.value?.querySelector<HTMLElement>(`#guide-${id}`);
|
||
if (!section || !body.value) return;
|
||
body.value.scrollTo({
|
||
top:
|
||
body.value.scrollTop +
|
||
section.getBoundingClientRect().top -
|
||
body.value.getBoundingClientRect().top,
|
||
behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
||
? "instant"
|
||
: "smooth"
|
||
});
|
||
}
|
||
</script>
|
||
<template>
|
||
<div ref="page" class="experiment-guide">
|
||
<header class="guide-heading">
|
||
<div>
|
||
<el-tag type="info">从零开始 · 图文教程</el-tag>
|
||
<h1>{{ guide.title }}</h1>
|
||
<p>{{ guide.intro }}</p>
|
||
</div>
|
||
<el-button @click="router.push('/digital/experiments')"
|
||
>返回测试方案</el-button
|
||
>
|
||
</header>
|
||
<el-alert
|
||
title="截图使用实际页面组件与隔离演示数据。红色编号对应下方操作;演示接入与统计状态不代表你的线上类型已经验收。点击图片可放大查看。"
|
||
type="info"
|
||
:closable="false"
|
||
/>
|
||
<div class="guide-layout">
|
||
<nav class="guide-toc" aria-label="教程目录">
|
||
<strong>本页目录</strong>
|
||
<div ref="toc" class="guide-links">
|
||
<button
|
||
v-for="step in guide.steps"
|
||
:key="step.id"
|
||
type="button"
|
||
:data-section="step.id"
|
||
:class="{ active: activeId === step.id }"
|
||
:aria-current="activeId === step.id ? 'location' : undefined"
|
||
@click="jump(step.id)"
|
||
>
|
||
{{ step.title }}
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
<article
|
||
ref="body"
|
||
class="guide-body"
|
||
tabindex="0"
|
||
aria-label="教程正文"
|
||
@scroll="scheduleUpdate"
|
||
>
|
||
<section
|
||
v-for="step in guide.steps"
|
||
:id="`guide-${step.id}`"
|
||
:key="step.id"
|
||
class="guide-section"
|
||
>
|
||
<h2>{{ step.title }}</h2>
|
||
<p class="guide-lead">{{ step.lead }}</p>
|
||
<figure v-for="image in step.images ?? []" :key="image">
|
||
<el-image
|
||
:src="`/guides/experiments/${image}.svg`"
|
||
:style="{
|
||
aspectRatio: `${sizes[image].width} / ${sizes[image].height}`
|
||
}"
|
||
:alt="`${step.title},带红色箭头与编号的演示截图`"
|
||
:preview-src-list="images"
|
||
:initial-index="
|
||
images.indexOf(`/guides/experiments/${image}.svg`)
|
||
"
|
||
preview-teleported
|
||
lazy
|
||
fit="contain"
|
||
><template #error
|
||
><div class="image-error">
|
||
教程图片加载失败,请刷新重试。
|
||
</div></template
|
||
></el-image
|
||
>
|
||
<figcaption>隔离演示截图 · 点击放大 · 编号对应下方操作</figcaption>
|
||
<ol class="guide-callouts">
|
||
<li v-for="note in guide.captions[image]" :key="note">
|
||
{{ note }}
|
||
</li>
|
||
</ol>
|
||
</figure>
|
||
<ul>
|
||
<li v-for="line in step.bullets" :key="line">{{ line }}</li>
|
||
</ul>
|
||
<pre v-if="'code' in step"><code>{{ step.code }}</code></pre>
|
||
</section>
|
||
<footer class="guide-footer">
|
||
<p>
|
||
教程更新:{{
|
||
guide.updated
|
||
}}。开始操作前,请确认当前环境与目标账号。
|
||
</p>
|
||
<el-button @click="router.push('/digital/experiment-types')"
|
||
>去实验类型</el-button
|
||
><el-button
|
||
type="primary"
|
||
@click="router.push('/digital/experiments')"
|
||
>去测试方案</el-button
|
||
><el-button @click="router.push('/digital/experiment-users')"
|
||
>去实验用户分组</el-button
|
||
>
|
||
</footer>
|
||
</article>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<style scoped>
|
||
.experiment-guide {
|
||
display: flex;
|
||
flex-direction: column;
|
||
max-width: 1440px;
|
||
height: var(--guide-height, calc(100dvh - 134px));
|
||
min-height: 360px;
|
||
margin: 0 auto;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.guide-heading {
|
||
display: flex;
|
||
gap: 24px;
|
||
align-items: flex-start;
|
||
justify-content: space-between;
|
||
margin-bottom: 24px;
|
||
}
|
||
|
||
.guide-heading h1 {
|
||
margin: 12px 0;
|
||
font-size: 28px;
|
||
}
|
||
|
||
.guide-heading p {
|
||
max-width: 800px;
|
||
line-height: 1.8;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.guide-layout {
|
||
display: grid;
|
||
flex: 1;
|
||
grid-template-columns: 220px minmax(0, 1fr);
|
||
gap: 32px;
|
||
min-height: 0;
|
||
margin-top: 24px;
|
||
}
|
||
|
||
.guide-toc {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
min-height: 0;
|
||
max-height: 100%;
|
||
padding: 16px;
|
||
overflow: hidden;
|
||
background: var(--el-bg-color);
|
||
border: 1px solid var(--el-border-color-lighter);
|
||
border-radius: 8px;
|
||
}
|
||
|
||
.guide-links {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.guide-toc strong {
|
||
flex-shrink: 0;
|
||
padding: 4px 8px 12px;
|
||
}
|
||
|
||
.guide-toc button {
|
||
padding: 8px;
|
||
font: inherit;
|
||
font-size: 13px;
|
||
color: var(--el-text-color-regular);
|
||
text-align: left;
|
||
cursor: pointer;
|
||
background: transparent;
|
||
border: 0;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.guide-toc button.active {
|
||
font-weight: 600;
|
||
color: var(--el-color-primary);
|
||
background: var(--el-color-primary-light-9);
|
||
box-shadow: inset 3px 0 var(--el-color-primary);
|
||
}
|
||
|
||
.guide-body {
|
||
min-width: 0;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
overscroll-behavior: contain;
|
||
}
|
||
|
||
.guide-body:focus-visible {
|
||
outline: 2px solid var(--el-color-primary);
|
||
outline-offset: -2px;
|
||
}
|
||
|
||
.guide-toc button:hover {
|
||
color: var(--el-color-primary);
|
||
background: var(--el-fill-color-light);
|
||
}
|
||
|
||
.guide-toc button:focus-visible {
|
||
outline: 2px solid var(--el-color-primary);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.guide-section {
|
||
padding: 24px;
|
||
margin-bottom: 24px;
|
||
scroll-margin-top: 0;
|
||
background: var(--el-bg-color);
|
||
border: 1px solid var(--el-border-color-lighter);
|
||
border-radius: 8px;
|
||
}
|
||
|
||
.guide-section h2 {
|
||
margin: 0 0 12px;
|
||
font-size: 21px;
|
||
}
|
||
|
||
.guide-lead {
|
||
line-height: 1.8;
|
||
}
|
||
|
||
.guide-section figure {
|
||
margin: 20px 0;
|
||
}
|
||
|
||
.guide-section .el-image {
|
||
display: block;
|
||
width: 100%;
|
||
min-height: 100px;
|
||
border: 1px solid var(--el-border-color-lighter);
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.guide-section figcaption {
|
||
margin-top: 8px;
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
text-align: center;
|
||
}
|
||
|
||
.guide-section ul {
|
||
padding-left: 22px;
|
||
line-height: 1.9;
|
||
}
|
||
|
||
.guide-section li {
|
||
margin-bottom: 12px;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
|
||
.guide-section pre {
|
||
padding: 16px;
|
||
overflow-x: auto;
|
||
font-size: 12px;
|
||
line-height: 1.8;
|
||
white-space: pre-wrap;
|
||
background: var(--el-fill-color-light);
|
||
border-radius: 6px;
|
||
}
|
||
|
||
.image-error {
|
||
padding: 24px;
|
||
color: var(--el-text-color-secondary);
|
||
text-align: center;
|
||
}
|
||
|
||
.guide-footer {
|
||
padding: 20px 0 32px;
|
||
line-height: 1.8;
|
||
}
|
||
|
||
.guide-footer p {
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
@media (width <= 900px) {
|
||
.guide-layout {
|
||
grid-template-rows: auto minmax(0, 1fr);
|
||
grid-template-columns: 1fr;
|
||
gap: 16px;
|
||
}
|
||
|
||
.guide-toc {
|
||
max-height: 140px;
|
||
}
|
||
|
||
.guide-heading {
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.guide-heading h1 {
|
||
font-size: 22px;
|
||
}
|
||
|
||
.guide-heading p {
|
||
margin: 0;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.guide-section {
|
||
padding: 16px;
|
||
}
|
||
}
|
||
</style>
|