Commit abae8c5f by chenwq1

fix:滚动限制

1 parent 4af5ab82
Pipeline #171 for abae8c5f failed in 0 seconds
...@@ -228,8 +228,7 @@ async function fetchDetail() { ...@@ -228,8 +228,7 @@ async function fetchDetail() {
} }
} }
const scrollRootRef = ref<HTMLElement | null>(null); const scrollRef = ref<HTMLElement | null>(null);
const stickyRef = ref<HTMLElement | null>(null);
const sectionRefs = ref<HTMLElement[]>([]); const sectionRefs = ref<HTMLElement[]>([]);
function sectionOffsetTop(sectionEl: HTMLElement, scrollEl: HTMLElement): number { function sectionOffsetTop(sectionEl: HTMLElement, scrollEl: HTMLElement): number {
...@@ -248,30 +247,25 @@ function setSectionRef(index: number, el: any) { ...@@ -248,30 +247,25 @@ function setSectionRef(index: number, el: any) {
if (el) sectionRefs.value[index] = el as HTMLElement; if (el) sectionRefs.value[index] = el as HTMLElement;
} }
function getStickyHeight() {
return stickyRef.value?.offsetHeight ?? 0;
}
function onClickTab({ name }: { name: number | string }) { function onClickTab({ name }: { name: number | string }) {
const index = Number(name); const index = Number(name);
const el = sectionRefs.value[index]; const el = sectionRefs.value[index];
const scrollEl = scrollRootRef.value; const sc = scrollRef.value;
if (!el || !scrollEl) return; if (!el || !sc) return;
scrollLocked = true; scrollLocked = true;
activeTab.value = index; activeTab.value = index;
const top = sectionOffsetTop(el, scrollEl) - getStickyHeight(); sc.scrollTo({
scrollEl.scrollTo({ top: el.offsetTop,
top: Math.max(0, top),
behavior: "smooth", behavior: "smooth",
}); });
} }
function handleScroll() { function handleScroll() {
const scrollEl = scrollRootRef.value; const sc = scrollRef.value;
if (!scrollEl) return; if (!sc) return;
const threshold = scrollEl.scrollTop + getStickyHeight() + 1; const threshold = sc.scrollTop + 1;
let active = 0; let active = 0;
for (let i = sectionRefs.value.length - 1; i >= 0; i--) { for (let i = sectionRefs.value.length - 1; i >= 0; i--) {
const el = sectionRefs.value[i]; const el = sectionRefs.value[i];
...@@ -301,12 +295,10 @@ function onScroll() { ...@@ -301,12 +295,10 @@ function onScroll() {
} }
onMounted(() => { onMounted(() => {
void fetchDetail(); fetchDetail();
scrollRootRef.value?.addEventListener("scroll", onScroll, { passive: true });
}); });
onUnmounted(() => { onUnmounted(() => {
scrollRootRef.value?.removeEventListener("scroll", onScroll);
cancelAnimationFrame(rafId); cancelAnimationFrame(rafId);
if (scrollEndTimer) clearTimeout(scrollEndTimer); if (scrollEndTimer) clearTimeout(scrollEndTimer);
}); });
...@@ -314,8 +306,7 @@ onUnmounted(() => { ...@@ -314,8 +306,7 @@ onUnmounted(() => {
<template> <template>
<div class="inspect-detail-page"> <div class="inspect-detail-page">
<div ref="scrollRootRef" class="inspect-detail-scroll"> <div class="sticky-header">
<div ref="stickyRef" class="sticky-header">
<van-tabs v-model:active="activeTab" @click-tab="onClickTab"> <van-tabs v-model:active="activeTab" @click-tab="onClickTab">
<van-tab v-for="cat in displayCategories" <van-tab v-for="cat in displayCategories"
:key="cat.name" :key="cat.name"
...@@ -329,6 +320,18 @@ onUnmounted(() => { ...@@ -329,6 +320,18 @@ onUnmounted(() => {
</div> </div>
</div> </div>
<div ref="scrollRef"
class="inspect-detail-scroll"
@scroll.passive="onScroll">
<div v-for="(cat, catIdx) in displayCategories"
:key="cat.name"
:ref="(el) => setSectionRef(catIdx, el)"
class="category-section">
<div class="category-header">
<span class="category-name">{{ cat.name }}</span>
<span class="category-count"> · 共{{ cat.totalCount }}项</span>
</div>
<div v-for="(cat, catIdx) in displayCategories" <div v-for="(cat, catIdx) in displayCategories"
:key="cat.name" :key="cat.name"
:ref="(el) => setSectionRef(catIdx, el)" :ref="(el) => setSectionRef(catIdx, el)"
...@@ -417,6 +420,8 @@ onUnmounted(() => { ...@@ -417,6 +420,8 @@ onUnmounted(() => {
暂无异常项 暂无异常项
</div> </div>
</div> </div>
</div>
</div>
<van-image-preview v-model:show="previewVisible" <van-image-preview v-model:show="previewVisible"
closeable closeable
...@@ -437,6 +442,7 @@ onUnmounted(() => { ...@@ -437,6 +442,7 @@ onUnmounted(() => {
min-width: 0; min-width: 0;
height: 100vh; height: 100vh;
height: 100dvh; height: 100dvh;
max-height: 100dvh;
overflow: hidden; overflow: hidden;
background: #f2f3f7; background: #f2f3f7;
} }
...@@ -454,8 +460,7 @@ onUnmounted(() => { ...@@ -454,8 +460,7 @@ onUnmounted(() => {
} }
.sticky-header { .sticky-header {
position: sticky; flex-shrink: 0;
top: 0;
z-index: 99; z-index: 99;
background: #fff; background: #fff;
...@@ -464,6 +469,16 @@ onUnmounted(() => { ...@@ -464,6 +469,16 @@ onUnmounted(() => {
} }
} }
.inspect-detail-scroll {
position: relative;
flex: 1;
min-height: 0;
overflow-x: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding-bottom: calc(40vh + env(safe-area-inset-bottom));
}
.filter-bar { .filter-bar {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
......
...@@ -700,13 +700,15 @@ onMounted(() => { ...@@ -700,13 +700,15 @@ onMounted(() => {
@use "@assets/styles/variables" as *; @use "@assets/styles/variables" as *;
.report-page { .report-page {
display: flex;
flex-direction: column;
width: 100%; width: 100%;
min-width: 0; min-width: 0;
height: 100vh; height: 100vh;
height: 100dvh; height: 100dvh;
overflow: hidden; max-height: 100dvh;
overflow-x: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding-bottom: calc(20px + env(safe-area-inset-bottom));
background: #f2f3f7; background: #f2f3f7;
} }
......
...@@ -115,7 +115,8 @@ onMounted(() => { ...@@ -115,7 +115,8 @@ onMounted(() => {
@click="onBack" /> @click="onBack" />
<PageTitle class="title" :title="title" /> <PageTitle class="title" :title="title" />
</div> </div>
<div :class="[status == 3 ? '' : 'ctx-box']"> <div class="wo-detail-main"
:class="{ 'wo-detail-main--with-foot': status !== 3 }">
<div class="page-head"> <div class="page-head">
<div class="head-left"> <div class="head-left">
<van-tag class="head-tag" :style="{ background: pageStatusTag.bg, color: pageStatusTag.color }"> <van-tag class="head-tag" :style="{ background: pageStatusTag.bg, color: pageStatusTag.color }">
...@@ -281,23 +282,38 @@ onMounted(() => { ...@@ -281,23 +282,38 @@ onMounted(() => {
@use "@assets/styles/variables" as *; @use "@assets/styles/variables" as *;
.wo-detail-page { .wo-detail-page {
min-height: 100vh; display: flex;
padding:6px 0; flex-direction: column;
width: 100%;
min-width: 0;
height: 100vh;
height: 100dvh;
max-height: 100dvh;
overflow: hidden;
padding: 6px 0;
background: #f2f3f7; background: #f2f3f7;
.header-top{ .header-top {
flex-shrink: 0;
.nav-back{ .nav-back {
position:absolute; position: absolute;
top:15px; top: 15px;
} }
} }
} }
.ctx-box{ // 单一纵向滚动区:避免 status===3 时无 ctx-box 导致 WebView 内 document 不滚动,及嵌套 overflow 抢滚动
height:calc(100vh - 110px); .wo-detail-main {
overflow: scroll; flex: 1;
min-height: 0;
overflow-x: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
&--with-foot {
padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
} }
.page-head { .page-head {
...@@ -343,7 +359,6 @@ onMounted(() => { ...@@ -343,7 +359,6 @@ onMounted(() => {
.content { .content {
padding: 8px 12px; padding: 8px 12px;
overflow: scroll
} }
.card { .card {
...@@ -551,16 +566,18 @@ onMounted(() => { ...@@ -551,16 +566,18 @@ onMounted(() => {
text-align: center; text-align: center;
} }
.page-foot{ .page-foot {
position: fixed; position: fixed;
// right:0; right: 0;
bottom:0; bottom: 0;
left: 0;
box-sizing: border-box; box-sizing: border-box;
width:375px; width: 100%;
// left:0;
max-width: 430px; max-width: 430px;
padding:12px; margin: 0 auto;
background:#fff; padding: 12px;
padding-bottom: calc(12px + env(safe-area-inset-bottom));
background: #fff;
.edit-btn{ .edit-btn{
box-sizing: border-box; box-sizing: border-box;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!