chore: 同步继续功能与阅读体验发布到测试分支 #17
@@ -245,3 +245,5 @@ pnpm build
|
||||
- 原始截图及标注后的SVG都纳入版本管理,维护时保留“隔离演示”说明,不能用伪造回执替代真实接入。
|
||||
|
||||
用户分组管理提供独立的方案概况、用户查找和指定入口。列表覆盖全部真实账号,不把只读预计结果称为实际入组;手动指定明确显示草稿待生效、人群不符、已过期等状态。不符合目标人群的账号须明确选择“作为测试账号加入”,不修改其他用户的人群范围。取消指定或到期后沿用原自动分组,否则按当前方案规则计算。
|
||||
|
||||
教程目录固定在阅读区左侧,右侧正文独立滚动并自动高亮当前章节;点击目录平滑定位,目录过长时会自动滚动到当前项。窄屏将目录置于正文上方,保留正文滚动与章节同步。
|
||||
|
||||
@@ -1,20 +1,109 @@
|
||||
<script setup lang="ts">
|
||||
/** 实验图文教程二级页:与仓库README共用内容源,截图标注只来自隔离演示。 */
|
||||
/** 实验图文教程二级页:固定目录与独立正文滚动,按实际阅读位置同步当前章节。 */
|
||||
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) {
|
||||
document
|
||||
.getElementById(`guide-${id}`)
|
||||
?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
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 class="experiment-guide">
|
||||
<div ref="page" class="experiment-guide">
|
||||
<header class="guide-heading">
|
||||
<div>
|
||||
<el-tag type="info">从零开始 · 图文教程</el-tag>
|
||||
@@ -32,17 +121,28 @@ function jump(id: string) {
|
||||
/>
|
||||
<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>
|
||||
<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>
|
||||
<article
|
||||
ref="body"
|
||||
class="guide-body"
|
||||
tabindex="0"
|
||||
aria-label="教程正文"
|
||||
@scroll="scheduleUpdate"
|
||||
>
|
||||
<section
|
||||
v-for="step in guide.steps"
|
||||
:id="`guide-${step.id}`"
|
||||
@@ -54,6 +154,9 @@ function jump(id: string) {
|
||||
<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="
|
||||
@@ -102,8 +205,13 @@ function jump(id: string) {
|
||||
</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 {
|
||||
@@ -127,27 +235,36 @@ function jump(id: string) {
|
||||
|
||||
.guide-layout {
|
||||
display: grid;
|
||||
flex: 1;
|
||||
grid-template-columns: 220px minmax(0, 1fr);
|
||||
gap: 32px;
|
||||
min-height: 0;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.guide-toc {
|
||||
position: sticky;
|
||||
top: 96px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
align-self: start;
|
||||
max-height: calc(100vh - 130px);
|
||||
min-height: 0;
|
||||
max-height: 100%;
|
||||
padding: 16px;
|
||||
overflow-y: auto;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -163,6 +280,25 @@ function jump(id: string) {
|
||||
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);
|
||||
@@ -176,7 +312,7 @@ function jump(id: string) {
|
||||
.guide-section {
|
||||
padding: 24px;
|
||||
margin-bottom: 24px;
|
||||
scroll-margin-top: 100px;
|
||||
scroll-margin-top: 0;
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
@@ -247,17 +383,28 @@ function jump(id: string) {
|
||||
|
||||
@media (width <= 900px) {
|
||||
.guide-layout {
|
||||
grid-template-rows: auto minmax(0, 1fr);
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.guide-toc {
|
||||
position: static;
|
||||
max-height: 220px;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user