mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-06-30 20:12:02 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
587f06eb9f | ||
|
|
7114c63e8f | ||
|
|
2a6f9e3cc0 | ||
|
|
00d37d7bda | ||
|
|
546af84dab | ||
|
|
5953496d84 | ||
|
|
0fda7c70de | ||
|
|
48546e1999 | ||
|
|
06355ff91d | ||
|
|
523f8c4cc8 | ||
|
|
73f6e7482f |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "moviepilot",
|
"name": "moviepilot",
|
||||||
"version": "2.11.3",
|
"version": "2.11.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": "dist/service.js",
|
"bin": "dist/service.js",
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
import ColorThief from 'colorthief'
|
import ColorThief from 'colorthief'
|
||||||
|
|
||||||
|
const DEFAULT_DOMINANT_COLOR = '#28A9E1'
|
||||||
|
const DOMINANT_COLOR_CACHE_LIMIT = 100
|
||||||
|
const colorThief = new ColorThief()
|
||||||
|
const dominantColorCache = new Map<string, Promise<string>>()
|
||||||
|
|
||||||
|
interface DominantColorOptions {
|
||||||
|
fallback?: string
|
||||||
|
quality?: number
|
||||||
|
}
|
||||||
|
|
||||||
// 将 RGB 转换为十六进制
|
// 将 RGB 转换为十六进制
|
||||||
function rgbStringToHex(rgbArray: number[]): string {
|
function rgbStringToHex(rgbArray: number[]): string {
|
||||||
if (rgbArray.length !== 3 || rgbArray.some(isNaN)) throw new Error('Invalid RGB string format')
|
if (rgbArray.length !== 3 || rgbArray.some(isNaN)) throw new Error('Invalid RGB string format')
|
||||||
@@ -14,11 +24,46 @@ function rgbStringToHex(rgbArray: number[]): string {
|
|||||||
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getImageCacheKey(image: HTMLImageElement) {
|
||||||
|
return image.currentSrc || image.src || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function rememberDominantColor(key: string, colorPromise: Promise<string>) {
|
||||||
|
if (!key) return colorPromise
|
||||||
|
|
||||||
|
if (dominantColorCache.size >= DOMINANT_COLOR_CACHE_LIMIT) {
|
||||||
|
const firstKey = dominantColorCache.keys().next().value
|
||||||
|
if (firstKey) dominantColorCache.delete(firstKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
dominantColorCache.set(key, colorPromise)
|
||||||
|
return colorPromise
|
||||||
|
}
|
||||||
|
|
||||||
// 提取主要颜色
|
// 提取主要颜色
|
||||||
export async function getDominantColor(image: HTMLImageElement): Promise<string> {
|
export async function getDominantColor(
|
||||||
const colorThief = new ColorThief()
|
image: HTMLImageElement | undefined | null,
|
||||||
const dominantColor = colorThief.getColor(image)
|
options: DominantColorOptions = {},
|
||||||
return rgbStringToHex(dominantColor)
|
): Promise<string> {
|
||||||
|
const fallback = options.fallback ?? DEFAULT_DOMINANT_COLOR
|
||||||
|
|
||||||
|
if (!image) return fallback
|
||||||
|
|
||||||
|
const cacheKey = getImageCacheKey(image)
|
||||||
|
const cachedColor = cacheKey ? dominantColorCache.get(cacheKey) : undefined
|
||||||
|
if (cachedColor) return cachedColor
|
||||||
|
|
||||||
|
const colorPromise = Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
const dominantColor = colorThief.getColor(image, options.quality ?? 20)
|
||||||
|
return rgbStringToHex(dominantColor)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn('Failed to extract dominant color:', error)
|
||||||
|
return fallback
|
||||||
|
})
|
||||||
|
|
||||||
|
return rememberDominantColor(cacheKey, colorPromise)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 预加载图片
|
// 预加载图片
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ const dropdownItems = ref([
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="absolute bottom-0 right-0">
|
<div class="absolute bottom-0 right-0">
|
||||||
<IconBtn>
|
<IconBtn @click.stop>
|
||||||
<VIcon size="small" icon="mdi-dots-vertical" />
|
<VIcon size="small" icon="mdi-dots-vertical" />
|
||||||
<VMenu activator="parent" close-on-content-click>
|
<VMenu activator="parent" close-on-content-click>
|
||||||
<VList>
|
<VList>
|
||||||
@@ -273,7 +273,7 @@ const dropdownItems = ref([
|
|||||||
<!-- 安装插件进度框 -->
|
<!-- 安装插件进度框 -->
|
||||||
<ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" />
|
<ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" />
|
||||||
<!-- 更新日志 -->
|
<!-- 更新日志 -->
|
||||||
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" scrollable>
|
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" max-height="85vh" scrollable>
|
||||||
<VCard :title="t('plugin.updateHistoryTitle', { name: props.plugin?.plugin_name })">
|
<VCard :title="t('plugin.updateHistoryTitle', { name: props.plugin?.plugin_name })">
|
||||||
<VDialogCloseBtn @click="releaseDialog = false" />
|
<VDialogCloseBtn @click="releaseDialog = false" />
|
||||||
<VDivider />
|
<VDivider />
|
||||||
|
|||||||
@@ -475,7 +475,10 @@ watch(
|
|||||||
{{ props.plugin?.plugin_desc }}
|
{{ props.plugin?.plugin_desc }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="relative flex-shrink-0 self-center pb-3" :class="{ 'cursor-move': props.sortable && display.mdAndUp.value }">
|
<div
|
||||||
|
class="relative flex-shrink-0 self-center pb-3"
|
||||||
|
:class="{ 'cursor-move': props.sortable && display.mdAndUp.value }"
|
||||||
|
>
|
||||||
<VAvatar size="48">
|
<VAvatar size="48">
|
||||||
<VImg
|
<VImg
|
||||||
ref="imageRef"
|
ref="imageRef"
|
||||||
@@ -518,7 +521,7 @@ watch(
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!props.sortable" class="absolute bottom-0 right-0">
|
<div v-if="!props.sortable" class="absolute bottom-0 right-0">
|
||||||
<IconBtn>
|
<IconBtn @click.stop>
|
||||||
<VIcon icon="mdi-dots-vertical" />
|
<VIcon icon="mdi-dots-vertical" />
|
||||||
<VMenu v-model="menuVisible" activator="parent" close-on-content-click>
|
<VMenu v-model="menuVisible" activator="parent" close-on-content-click>
|
||||||
<VList>
|
<VList>
|
||||||
@@ -569,7 +572,7 @@ watch(
|
|||||||
<ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" />
|
<ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" />
|
||||||
|
|
||||||
<!-- 更新日志 -->
|
<!-- 更新日志 -->
|
||||||
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" scrollable :fullscreen="!display.mdAndUp.value">
|
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" scrollable max-height="85vh">
|
||||||
<VCard :title="t('plugin.updateHistoryTitle', { name: props.plugin?.plugin_name })">
|
<VCard :title="t('plugin.updateHistoryTitle', { name: props.plugin?.plugin_name })">
|
||||||
<VDialogCloseBtn @click="releaseDialog = false" />
|
<VDialogCloseBtn @click="releaseDialog = false" />
|
||||||
<VDivider />
|
<VDivider />
|
||||||
@@ -587,13 +590,13 @@ watch(
|
|||||||
</VDialog>
|
</VDialog>
|
||||||
|
|
||||||
<!-- 实时日志弹窗 -->
|
<!-- 实时日志弹窗 -->
|
||||||
<VDialog
|
<VDialog
|
||||||
v-if="loggingDialog"
|
v-if="loggingDialog"
|
||||||
v-model="loggingDialog"
|
v-model="loggingDialog"
|
||||||
scrollable
|
scrollable
|
||||||
max-width="72rem"
|
max-width="72rem"
|
||||||
:fullscreen="!display.mdAndUp.value"
|
:fullscreen="!display.mdAndUp.value"
|
||||||
>
|
>
|
||||||
<VCard>
|
<VCard>
|
||||||
<VDialogCloseBtn @click="loggingDialog = false" />
|
<VDialogCloseBtn @click="loggingDialog = false" />
|
||||||
<VCardItem>
|
<VCardItem>
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ onMounted(() => {
|
|||||||
</VBtn>
|
</VBtn>
|
||||||
|
|
||||||
<!-- 更多选项按钮 -->
|
<!-- 更多选项按钮 -->
|
||||||
<VBtn icon variant="text" class="mt-auto" size="36">
|
<VBtn icon variant="text" class="mt-auto" size="36" @click.stop>
|
||||||
<VIcon icon="mdi-dots-vertical" size="20" />
|
<VIcon icon="mdi-dots-vertical" size="20" />
|
||||||
<VMenu :activator="'parent'" :close-on-content-click="true" :location="'left'">
|
<VMenu :activator="'parent'" :close-on-content-click="true" :location="'left'">
|
||||||
<VList>
|
<VList>
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ function handleCardClick() {
|
|||||||
:ripple="!props.batchMode && !props.sortable"
|
:ripple="!props.batchMode && !props.sortable"
|
||||||
>
|
>
|
||||||
<div v-if="!props.sortable" class="me-n3 absolute top-1 right-4">
|
<div v-if="!props.sortable" class="me-n3 absolute top-1 right-4">
|
||||||
<IconBtn>
|
<IconBtn @click.stop>
|
||||||
<VIcon icon="mdi-dots-vertical" color="white" />
|
<VIcon icon="mdi-dots-vertical" color="white" />
|
||||||
<VMenu activator="parent" close-on-content-click>
|
<VMenu activator="parent" close-on-content-click>
|
||||||
<VList>
|
<VList>
|
||||||
|
|||||||
@@ -202,12 +202,7 @@ onMounted(() => {
|
|||||||
<dd class="flex text-sm sm:col-span-2 sm:mt-0">
|
<dd class="flex text-sm sm:col-span-2 sm:mt-0">
|
||||||
<span class="flex-grow flex flex-row items-center truncate">
|
<span class="flex-grow flex flex-row items-center truncate">
|
||||||
<code class="truncate">{{ appVersion }}</code>
|
<code class="truncate">{{ appVersion }}</code>
|
||||||
<VBtn
|
<VBtn size="x-small" variant="tonal" class="ms-2" @click="clearCache">
|
||||||
size="x-small"
|
|
||||||
variant="tonal"
|
|
||||||
class="ms-2"
|
|
||||||
@click="clearCache"
|
|
||||||
>
|
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<VIcon icon="mdi-refresh" size="14" />
|
<VIcon icon="mdi-refresh" size="14" />
|
||||||
</template>
|
</template>
|
||||||
@@ -402,7 +397,7 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
</VCardText>
|
</VCardText>
|
||||||
</VCard>
|
</VCard>
|
||||||
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" scrollable>
|
<VDialog v-if="releaseDialog" v-model="releaseDialog" width="600" scrollable max-height="85vh">
|
||||||
<VCard>
|
<VCard>
|
||||||
<VCardItem>
|
<VCardItem>
|
||||||
<VDialogCloseBtn @click="releaseDialog = false" />
|
<VDialogCloseBtn @click="releaseDialog = false" />
|
||||||
@@ -430,8 +425,8 @@ onMounted(() => {
|
|||||||
.markdown-body :deep(h1),
|
.markdown-body :deep(h1),
|
||||||
.markdown-body :deep(h2),
|
.markdown-body :deep(h2),
|
||||||
.markdown-body :deep(h3) {
|
.markdown-body :deep(h3) {
|
||||||
margin-block: 0.5rem;
|
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
margin-block: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(h1) {
|
.markdown-body :deep(h1) {
|
||||||
@@ -448,8 +443,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
.markdown-body :deep(ul),
|
.markdown-body :deep(ul),
|
||||||
.markdown-body :deep(ol) {
|
.markdown-body :deep(ol) {
|
||||||
padding-inline-start: 1.5rem;
|
|
||||||
margin-block: 0.5rem;
|
margin-block: 0.5rem;
|
||||||
|
padding-inline-start: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(li) {
|
.markdown-body :deep(li) {
|
||||||
@@ -470,18 +465,20 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(code) {
|
.markdown-body :deep(code) {
|
||||||
padding: 0.15rem 0.4rem;
|
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
|
background-color: rgba(127, 127, 127, 15%);
|
||||||
font-size: 0.875em;
|
font-size: 0.875em;
|
||||||
background-color: rgba(127, 127, 127, 0.15);
|
padding-block: 0.15rem;
|
||||||
|
padding-inline: 0.4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(pre) {
|
.markdown-body :deep(pre) {
|
||||||
padding: 0.75rem 1rem;
|
border-radius: 0.375rem;
|
||||||
|
background-color: rgba(127, 127, 127, 15%);
|
||||||
margin-block: 0.5rem;
|
margin-block: 0.5rem;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
border-radius: 0.375rem;
|
padding-block: 0.75rem;
|
||||||
background-color: rgba(127, 127, 127, 0.15);
|
padding-inline: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(pre code) {
|
.markdown-body :deep(pre code) {
|
||||||
@@ -490,37 +487,38 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(blockquote) {
|
.markdown-body :deep(blockquote) {
|
||||||
padding-inline-start: 1rem;
|
border-inline-start: 3px solid rgba(127, 127, 127, 40%);
|
||||||
|
color: rgba(127, 127, 127, 80%);
|
||||||
margin-block: 0.5rem;
|
margin-block: 0.5rem;
|
||||||
border-inline-start: 3px solid rgba(127, 127, 127, 0.4);
|
padding-inline-start: 1rem;
|
||||||
color: rgba(127, 127, 127, 0.8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(hr) {
|
.markdown-body :deep(hr) {
|
||||||
margin-block: 1rem;
|
|
||||||
border: none;
|
border: none;
|
||||||
border-block-start: 1px solid rgba(127, 127, 127, 0.3);
|
border-block-start: 1px solid rgba(127, 127, 127, 30%);
|
||||||
|
margin-block: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(table) {
|
.markdown-body :deep(table) {
|
||||||
width: 100%;
|
|
||||||
margin-block: 0.5rem;
|
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
inline-size: 100%;
|
||||||
|
margin-block: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(th),
|
.markdown-body :deep(th),
|
||||||
.markdown-body :deep(td) {
|
.markdown-body :deep(td) {
|
||||||
padding: 0.4rem 0.75rem;
|
border: 1px solid rgba(127, 127, 127, 30%);
|
||||||
border: 1px solid rgba(127, 127, 127, 0.3);
|
padding-block: 0.4rem;
|
||||||
|
padding-inline: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(th) {
|
.markdown-body :deep(th) {
|
||||||
|
background-color: rgba(127, 127, 127, 10%);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
background-color: rgba(127, 127, 127, 0.1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body :deep(img) {
|
.markdown-body :deep(img) {
|
||||||
max-width: 100%;
|
block-size: auto;
|
||||||
height: auto;
|
max-inline-size: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ interface VirtualCell {
|
|||||||
key: ItemKey
|
key: ItemKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface VirtualRange {
|
||||||
|
endIndex: number
|
||||||
|
endRow: number
|
||||||
|
startIndex: number
|
||||||
|
startRow: number
|
||||||
|
}
|
||||||
|
|
||||||
const containerRef = ref<HTMLElement | null>(null)
|
const containerRef = ref<HTMLElement | null>(null)
|
||||||
const trackRef = ref<HTMLElement | null>(null)
|
const trackRef = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
@@ -45,6 +52,8 @@ const layoutWidth = ref(0)
|
|||||||
const viewportTop = ref(0)
|
const viewportTop = ref(0)
|
||||||
const viewportBottom = ref(0)
|
const viewportBottom = ref(0)
|
||||||
const heightVersion = ref(0)
|
const heightVersion = ref(0)
|
||||||
|
const frozenVisibleRange = ref<VirtualRange | null>(null)
|
||||||
|
const isOverlayGrid = ref(false)
|
||||||
|
|
||||||
const itemHeights = new Map<ItemKey, number>()
|
const itemHeights = new Map<ItemKey, number>()
|
||||||
const observedElements = new Map<HTMLElement, ItemKey>()
|
const observedElements = new Map<HTMLElement, ItemKey>()
|
||||||
@@ -53,6 +62,7 @@ const itemRefCallbacks = new Map<ItemKey, (element: Element | ComponentPublicIns
|
|||||||
|
|
||||||
let resizeObserver: ResizeObserver | null = null
|
let resizeObserver: ResizeObserver | null = null
|
||||||
let itemResizeObserver: ResizeObserver | null = null
|
let itemResizeObserver: ResizeObserver | null = null
|
||||||
|
let overlayLockObserver: MutationObserver | null = null
|
||||||
let scrollTarget: ScrollTarget | null = null
|
let scrollTarget: ScrollTarget | null = null
|
||||||
let layoutFrameId: number | null = null
|
let layoutFrameId: number | null = null
|
||||||
let scrollFrameId: number | null = null
|
let scrollFrameId: number | null = null
|
||||||
@@ -149,7 +159,18 @@ const rowMetrics = computed(() => {
|
|||||||
|
|
||||||
const totalHeight = computed(() => rowMetrics.value.totalHeight)
|
const totalHeight = computed(() => rowMetrics.value.totalHeight)
|
||||||
|
|
||||||
const visibleRange = computed(() => {
|
const calculatedVisibleRange = computed<VirtualRange>(() => {
|
||||||
|
if (isOverlayGrid.value) {
|
||||||
|
const rowCount = Math.max(1, Math.ceil(props.items.length / columnCount.value))
|
||||||
|
|
||||||
|
return {
|
||||||
|
endIndex: props.items.length,
|
||||||
|
endRow: rowCount - 1,
|
||||||
|
startIndex: 0,
|
||||||
|
startRow: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { heights, offsets, rowCount } = rowMetrics.value
|
const { heights, offsets, rowCount } = rowMetrics.value
|
||||||
|
|
||||||
if (!props.items.length || rowCount === 0) {
|
if (!props.items.length || rowCount === 0) {
|
||||||
@@ -176,6 +197,8 @@ const visibleRange = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const visibleRange = computed(() => frozenVisibleRange.value ?? calculatedVisibleRange.value)
|
||||||
|
|
||||||
const visibleCells = computed<VirtualCell[]>(() => {
|
const visibleCells = computed<VirtualCell[]>(() => {
|
||||||
const cells: VirtualCell[] = []
|
const cells: VirtualCell[] = []
|
||||||
|
|
||||||
@@ -190,7 +213,13 @@ const visibleCells = computed<VirtualCell[]>(() => {
|
|||||||
return cells
|
return cells
|
||||||
})
|
})
|
||||||
|
|
||||||
const topSpacerHeight = computed(() => rowMetrics.value.offsets[visibleRange.value.startRow] ?? 0)
|
const topSpacerHeight = computed(() => {
|
||||||
|
if (isOverlayGrid.value) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return rowMetrics.value.offsets[visibleRange.value.startRow] ?? 0
|
||||||
|
})
|
||||||
|
|
||||||
const visibleBlockHeight = computed(() => {
|
const visibleBlockHeight = computed(() => {
|
||||||
if (!props.items.length || visibleRange.value.endIndex <= visibleRange.value.startIndex) {
|
if (!props.items.length || visibleRange.value.endIndex <= visibleRange.value.startIndex) {
|
||||||
@@ -206,6 +235,10 @@ const visibleBlockHeight = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const bottomSpacerHeight = computed(() => {
|
const bottomSpacerHeight = computed(() => {
|
||||||
|
if (isOverlayGrid.value) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
return Math.max(totalHeight.value - topSpacerHeight.value - visibleBlockHeight.value, 0)
|
return Math.max(totalHeight.value - topSpacerHeight.value - visibleBlockHeight.value, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -266,6 +299,45 @@ function findLastRowAtOrBeforeOffset(offsets: number[], rowCount: number, offset
|
|||||||
return answer
|
return answer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDocumentOverlayLocked() {
|
||||||
|
return typeof document !== 'undefined' && document.documentElement.classList.contains('v-overlay-scroll-blocked')
|
||||||
|
}
|
||||||
|
|
||||||
|
function isGridInsideOverlay() {
|
||||||
|
return Boolean(containerRef.value?.closest('.v-overlay, .v-overlay__content'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncOverlayGridState() {
|
||||||
|
isOverlayGrid.value = isGridInsideOverlay()
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldPauseVirtualSync() {
|
||||||
|
return isDocumentOverlayLocked() && !isOverlayGrid.value
|
||||||
|
}
|
||||||
|
|
||||||
|
function freezeVisibleRange() {
|
||||||
|
if (frozenVisibleRange.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 弹窗打开期间固定当前渲染窗口,防止 body 锁滚动造成坐标跳变并卸载触发弹窗的卡片。
|
||||||
|
frozenVisibleRange.value = { ...calculatedVisibleRange.value }
|
||||||
|
}
|
||||||
|
|
||||||
|
function releaseVisibleRange() {
|
||||||
|
frozenVisibleRange.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOverlayLockChange() {
|
||||||
|
if (shouldPauseVirtualSync()) {
|
||||||
|
freezeVisibleRange()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVisibleRange()
|
||||||
|
queueLayoutSync()
|
||||||
|
}
|
||||||
|
|
||||||
function getElementFromRef(element: Element | ComponentPublicInstance | null): HTMLElement | null {
|
function getElementFromRef(element: Element | ComponentPublicInstance | null): HTMLElement | null {
|
||||||
if (!element || typeof HTMLElement === 'undefined') {
|
if (!element || typeof HTMLElement === 'undefined') {
|
||||||
return null
|
return null
|
||||||
@@ -312,6 +384,11 @@ function ensureItemResizeObserver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
itemResizeObserver = new ResizeObserver(entries => {
|
itemResizeObserver = new ResizeObserver(entries => {
|
||||||
|
if (shouldPauseVirtualSync()) {
|
||||||
|
freezeVisibleRange()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let shouldUpdate = false
|
let shouldUpdate = false
|
||||||
let scrollAdjustment = 0
|
let scrollAdjustment = 0
|
||||||
const currentViewportTop = viewportTop.value
|
const currentViewportTop = viewportTop.value
|
||||||
@@ -506,6 +583,15 @@ function queueLayoutSync() {
|
|||||||
|
|
||||||
layoutFrameId = window.requestAnimationFrame(() => {
|
layoutFrameId = window.requestAnimationFrame(() => {
|
||||||
layoutFrameId = null
|
layoutFrameId = null
|
||||||
|
|
||||||
|
if (shouldPauseVirtualSync()) {
|
||||||
|
freezeVisibleRange()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 弹窗内容已经由 overlay 限定生命周期,直接完整渲染可避免弹窗内交互被虚拟回收打断。
|
||||||
|
syncOverlayGridState()
|
||||||
|
releaseVisibleRange()
|
||||||
syncLayoutWidth()
|
syncLayoutWidth()
|
||||||
refreshScrollTarget()
|
refreshScrollTarget()
|
||||||
syncViewport()
|
syncViewport()
|
||||||
@@ -520,6 +606,13 @@ function queueViewportSync() {
|
|||||||
|
|
||||||
scrollFrameId = window.requestAnimationFrame(() => {
|
scrollFrameId = window.requestAnimationFrame(() => {
|
||||||
scrollFrameId = null
|
scrollFrameId = null
|
||||||
|
|
||||||
|
if (shouldPauseVirtualSync()) {
|
||||||
|
freezeVisibleRange()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVisibleRange()
|
||||||
syncViewport()
|
syncViewport()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -681,6 +774,7 @@ function invalidateMeasurementsForLayoutChange() {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
mounted = true
|
mounted = true
|
||||||
|
syncOverlayGridState()
|
||||||
scrollTarget = findScrollTarget()
|
scrollTarget = findScrollTarget()
|
||||||
addScrollListener(scrollTarget)
|
addScrollListener(scrollTarget)
|
||||||
|
|
||||||
@@ -689,6 +783,14 @@ onMounted(() => {
|
|||||||
resizeObserver.observe(trackRef.value)
|
resizeObserver.observe(trackRef.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof MutationObserver !== 'undefined') {
|
||||||
|
overlayLockObserver = new MutationObserver(handleOverlayLockChange)
|
||||||
|
overlayLockObserver.observe(document.documentElement, {
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['class'],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', queueLayoutSync, { passive: true })
|
window.addEventListener('resize', queueLayoutSync, { passive: true })
|
||||||
|
|
||||||
queueLayoutSync()
|
queueLayoutSync()
|
||||||
@@ -716,6 +818,8 @@ onUnmounted(() => {
|
|||||||
resizeObserver = null
|
resizeObserver = null
|
||||||
itemResizeObserver?.disconnect()
|
itemResizeObserver?.disconnect()
|
||||||
itemResizeObserver = null
|
itemResizeObserver = null
|
||||||
|
overlayLockObserver?.disconnect()
|
||||||
|
overlayLockObserver = null
|
||||||
|
|
||||||
if (layoutFrameId !== null) {
|
if (layoutFrameId !== null) {
|
||||||
window.cancelAnimationFrame(layoutFrameId)
|
window.cancelAnimationFrame(layoutFrameId)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type MessageViewExpose = {
|
|||||||
pauseSSE?: () => void
|
pauseSSE?: () => void
|
||||||
resumeSSE?: () => void
|
resumeSSE?: () => void
|
||||||
refreshLatestMessages?: () => Promise<void> | void
|
refreshLatestMessages?: () => Promise<void> | void
|
||||||
|
forceScrollToEnd?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
// 国际化
|
// 国际化
|
||||||
@@ -67,15 +68,9 @@ const user_message = ref('')
|
|||||||
// 发送按钮是否可用
|
// 发送按钮是否可用
|
||||||
const sendButtonDisabled = ref(false)
|
const sendButtonDisabled = ref(false)
|
||||||
|
|
||||||
// 消息对话框引用
|
|
||||||
const messageDialogRef = ref<any>(null)
|
|
||||||
|
|
||||||
// 消息视图引用
|
// 消息视图引用
|
||||||
const messageViewRef = ref<MessageViewExpose | null>(null)
|
const messageViewRef = ref<MessageViewExpose | null>(null)
|
||||||
|
|
||||||
// 滚动容器引用
|
|
||||||
const messageContentRef = ref<any>()
|
|
||||||
|
|
||||||
// 定义捷径列表
|
// 定义捷径列表
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
@@ -148,58 +143,9 @@ function openDialog(dialogRef: any) {
|
|||||||
dialogRef.value = true
|
dialogRef.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开消息弹窗并清除徽章
|
// 打开消息弹窗
|
||||||
async function openMessageDialog() {
|
function openMessageDialog() {
|
||||||
messageDialog.value = true
|
messageDialog.value = true
|
||||||
// 延迟清除徽章,确保对话框已经打开
|
|
||||||
setTimeout(async () => {
|
|
||||||
await clearAppBadge()
|
|
||||||
}, 500)
|
|
||||||
// 延迟滚动到底部,确保弹窗完全打开
|
|
||||||
setTimeout(() => {
|
|
||||||
forceScrollToEnd()
|
|
||||||
}, 600)
|
|
||||||
// 等待对话框打开后恢复SSE连接
|
|
||||||
nextTick(() => {
|
|
||||||
messageViewRef.value?.resumeSSE?.()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 智能滚动到底部(只有用户在底部附近时才滚动)
|
|
||||||
function scrollMessageToEnd() {
|
|
||||||
// 使用更长的延迟确保DOM已更新
|
|
||||||
setTimeout(() => {
|
|
||||||
try {
|
|
||||||
// 查找消息弹窗的滚动容器
|
|
||||||
const cardText = document.querySelector('.v-dialog .v-card-text')
|
|
||||||
if (cardText) {
|
|
||||||
const { scrollTop, scrollHeight, clientHeight } = cardText
|
|
||||||
// 计算距离底部的距离
|
|
||||||
const distanceFromBottom = scrollHeight - scrollTop - clientHeight
|
|
||||||
// 如果用户距离底部小于1/3屏幕高度,认为用户在底部附近,执行自动滚动
|
|
||||||
if (distanceFromBottom <= clientHeight / 3) {
|
|
||||||
cardText.scrollTop = cardText.scrollHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
}, 500) // 增加延迟时间
|
|
||||||
}
|
|
||||||
|
|
||||||
// 强制滚动到底部(用于发送消息后)
|
|
||||||
function forceScrollToEnd() {
|
|
||||||
setTimeout(() => {
|
|
||||||
try {
|
|
||||||
// 查找消息弹窗的滚动容器
|
|
||||||
const cardText = document.querySelector('.v-dialog .v-card-text')
|
|
||||||
if (cardText) {
|
|
||||||
cardText.scrollTop = cardText.scrollHeight
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拼接全部日志url
|
// 拼接全部日志url
|
||||||
@@ -221,7 +167,7 @@ async function sendMessage() {
|
|||||||
|
|
||||||
// 发送成功后主动同步最新一页消息,避免SSE短暂断流时界面停留在旧状态。
|
// 发送成功后主动同步最新一页消息,避免SSE短暂断流时界面停留在旧状态。
|
||||||
// await messageViewRef.value?.refreshLatestMessages?.()
|
// await messageViewRef.value?.refreshLatestMessages?.()
|
||||||
forceScrollToEnd() // 发送消息后强制滚动到底部
|
messageViewRef.value?.forceScrollToEnd?.()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -240,8 +186,20 @@ defineExpose({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 监听消息对话框状态变化
|
// 监听消息对话框状态变化
|
||||||
watch(messageDialog, newValue => {
|
watch(messageDialog, async newValue => {
|
||||||
if (!newValue && messageViewRef.value?.pauseSSE) {
|
if (newValue) {
|
||||||
|
await nextTick()
|
||||||
|
messageViewRef.value?.resumeSSE?.()
|
||||||
|
messageViewRef.value?.forceScrollToEnd?.()
|
||||||
|
|
||||||
|
window.setTimeout(() => {
|
||||||
|
void clearAppBadge()
|
||||||
|
}, 500)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (messageViewRef.value?.pauseSSE) {
|
||||||
// 对话框关闭时暂停SSE连接
|
// 对话框关闭时暂停SSE连接
|
||||||
messageViewRef.value.pauseSSE()
|
messageViewRef.value.pauseSSE()
|
||||||
}
|
}
|
||||||
@@ -496,7 +454,6 @@ onMounted(() => {
|
|||||||
max-width="50rem"
|
max-width="50rem"
|
||||||
scrollable
|
scrollable
|
||||||
:fullscreen="!display.mdAndUp.value"
|
:fullscreen="!display.mdAndUp.value"
|
||||||
ref="messageDialogRef"
|
|
||||||
>
|
>
|
||||||
<VCard>
|
<VCard>
|
||||||
<VCardItem>
|
<VCardItem>
|
||||||
@@ -507,8 +464,8 @@ onMounted(() => {
|
|||||||
<VDialogCloseBtn @click="messageDialog = false" />
|
<VDialogCloseBtn @click="messageDialog = false" />
|
||||||
</VCardItem>
|
</VCardItem>
|
||||||
<VDivider />
|
<VDivider />
|
||||||
<VCardText ref="messageContentRef">
|
<VCardText>
|
||||||
<MessageView ref="messageViewRef" @scroll="scrollMessageToEnd" />
|
<MessageView ref="messageViewRef" />
|
||||||
</VCardText>
|
</VCardText>
|
||||||
<VDivider />
|
<VDivider />
|
||||||
<VCardActions class="pa-4">
|
<VCardActions class="pa-4">
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ interface SearchParams {
|
|||||||
sites: string
|
sites: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LastSearchContextResponse {
|
||||||
|
success?: boolean
|
||||||
|
data?: {
|
||||||
|
params?: Partial<SearchParams>
|
||||||
|
results?: Context[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const resourceSearchParamsStorageKey = 'MP_ResourceSearchParams'
|
const resourceSearchParamsStorageKey = 'MP_ResourceSearchParams'
|
||||||
|
|
||||||
function createSearchParams(query: LocationQuery): SearchParams {
|
function createSearchParams(query: LocationQuery): SearchParams {
|
||||||
@@ -106,10 +114,55 @@ function rememberSearchParams(params: SearchParams) {
|
|||||||
saveStoredSearchParams(nextParams)
|
saveStoredSearchParams(nextParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyRememberedSearchParams(params?: Partial<SearchParams> | null, syncActive: boolean = false) {
|
||||||
|
const nextParams = normalizeSearchParams(params)
|
||||||
|
if (!hasSearchKeyword(nextParams)) return null
|
||||||
|
|
||||||
|
rememberSearchParams(nextParams)
|
||||||
|
if (syncActive || !hasSearchKeyword(activeSearchParams.value)) {
|
||||||
|
activeSearchParams.value = { ...nextParams }
|
||||||
|
}
|
||||||
|
return nextParams
|
||||||
|
}
|
||||||
|
|
||||||
if (hasSearchKeyword(initialSearchParams)) {
|
if (hasSearchKeyword(initialSearchParams)) {
|
||||||
rememberSearchParams(initialSearchParams)
|
rememberSearchParams(initialSearchParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchLastSearchContext() {
|
||||||
|
try {
|
||||||
|
const result = (await api.get('search/last/context')) as LastSearchContextResponse
|
||||||
|
applyRememberedSearchParams(result?.data?.params, true)
|
||||||
|
return Array.isArray(result?.data?.results) ? result.data.results : []
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('读取上次搜索上下文失败,回退到仅加载结果:', error)
|
||||||
|
const results = await api.get('search/last')
|
||||||
|
return (results as unknown as Context[]) || []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveRefreshSearchParams() {
|
||||||
|
if (hasSearchKeyword(activeSearchParams.value)) {
|
||||||
|
return { ...activeSearchParams.value }
|
||||||
|
}
|
||||||
|
if (lastSearchParams.value && hasSearchKeyword(lastSearchParams.value)) {
|
||||||
|
return { ...lastSearchParams.value }
|
||||||
|
}
|
||||||
|
|
||||||
|
const storedParams = loadStoredSearchParams()
|
||||||
|
if (storedParams) {
|
||||||
|
applyRememberedSearchParams(storedParams, true)
|
||||||
|
return { ...storedParams }
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetchLastSearchContext()
|
||||||
|
if (lastSearchParams.value && hasSearchKeyword(lastSearchParams.value)) {
|
||||||
|
return { ...lastSearchParams.value }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// 查询TMDBID或标题
|
// 查询TMDBID或标题
|
||||||
const keyword = computed(() => activeSearchParams.value.keyword)
|
const keyword = computed(() => activeSearchParams.value.keyword)
|
||||||
|
|
||||||
@@ -612,11 +665,9 @@ async function fetchData(options: { force?: boolean; params?: SearchParams } = {
|
|||||||
try {
|
try {
|
||||||
enableFilterAnimation.value = true
|
enableFilterAnimation.value = true
|
||||||
if (!hasSearchKeyword(currentSearchParams)) {
|
if (!hasSearchKeyword(currentSearchParams)) {
|
||||||
// 查询上次搜索结果
|
// 查询上次搜索结果,并同步可重放的搜索参数
|
||||||
const results = await api.get('search/last', {
|
const results = await fetchLastSearchContext()
|
||||||
params: requestToken ? { _ts: requestToken } : undefined,
|
setStreamResults(results || [])
|
||||||
})
|
|
||||||
setStreamResults((results as unknown as Context[]) || [])
|
|
||||||
} else {
|
} else {
|
||||||
resetSearchResults()
|
resetSearchResults()
|
||||||
startLoadingProgress()
|
startLoadingProgress()
|
||||||
@@ -646,11 +697,15 @@ async function fetchData(options: { force?: boolean; params?: SearchParams } = {
|
|||||||
// 重新搜索(使用相同参数重新触发搜索)
|
// 重新搜索(使用相同参数重新触发搜索)
|
||||||
async function refreshSearch() {
|
async function refreshSearch() {
|
||||||
if (isRefreshing.value || progressActive.value) return
|
if (isRefreshing.value || progressActive.value) return
|
||||||
const refreshParams = lastSearchParams.value ?? activeSearchParams.value
|
|
||||||
isRefreshing.value = true
|
isRefreshing.value = true
|
||||||
try {
|
try {
|
||||||
// 重新搜索时退出 AI 视图,其余状态由 fetchData 内部重置
|
// 重新搜索时退出 AI 视图,其余状态由 fetchData 内部重置
|
||||||
showingAiResults.value = false
|
showingAiResults.value = false
|
||||||
|
const refreshParams = await resolveRefreshSearchParams()
|
||||||
|
if (!refreshParams) {
|
||||||
|
console.warn('未找到可用于重新搜索的搜索参数')
|
||||||
|
return
|
||||||
|
}
|
||||||
await fetchData({ force: true, params: refreshParams })
|
await fetchData({ force: true, params: refreshParams })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('重新搜索失败:', error)
|
console.error('重新搜索失败:', error)
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ async function fetchData({ done }: { done: any }) {
|
|||||||
page.value++
|
page.value++
|
||||||
// 返回加载成功
|
// 返回加载成功
|
||||||
done('ok')
|
done('ok')
|
||||||
|
await nextTick()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 加载一次
|
// 加载一次
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ async function fetchData({ done }: { done: any }) {
|
|||||||
page.value++
|
page.value++
|
||||||
// 返回加载成功
|
// 返回加载成功
|
||||||
done('ok')
|
done('ok')
|
||||||
|
await nextTick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -923,6 +923,11 @@ watch([dataList, installedFilter, hasUpdateFilter, enabledFilter], () => {
|
|||||||
function loadMarketMore({ done }: { done: any }) {
|
function loadMarketMore({ done }: { done: any }) {
|
||||||
// 从 dataList 中获取最前面的 20 个元素
|
// 从 dataList 中获取最前面的 20 个元素
|
||||||
const itemsToMove = sortedUninstalledList.value.splice(0, 20)
|
const itemsToMove = sortedUninstalledList.value.splice(0, 20)
|
||||||
|
if (itemsToMove.length === 0) {
|
||||||
|
done('empty')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
displayUninstalledList.value.push(...itemsToMove)
|
displayUninstalledList.value.push(...itemsToMove)
|
||||||
done('ok')
|
done('ok')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ async function fetchData({ done }: { done: any }) {
|
|||||||
page.value++
|
page.value++
|
||||||
// 返回加载成功
|
// 返回加载成功
|
||||||
done('ok')
|
done('ok')
|
||||||
|
await nextTick()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 设置加载中
|
// 设置加载中
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ async function fetchData({ done }: { done: any }) {
|
|||||||
page.value++
|
page.value++
|
||||||
// 返回加载成功
|
// 返回加载成功
|
||||||
done('ok')
|
done('ok')
|
||||||
|
await nextTick()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 设置加载中
|
// 设置加载中
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ import { useBackgroundOptimization } from '@/composables/useBackgroundOptimizati
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { useSSE } = useBackgroundOptimization()
|
const { useSSE } = useBackgroundOptimization()
|
||||||
|
|
||||||
// 定义事件
|
|
||||||
const emit = defineEmits(['scroll'])
|
|
||||||
|
|
||||||
// 消息列表
|
// 消息列表
|
||||||
const messages = ref<Message[]>([])
|
const messages = ref<Message[]>([])
|
||||||
// 当前页数据
|
// 当前页数据
|
||||||
@@ -33,6 +30,18 @@ const page = ref(1)
|
|||||||
// 存量消息最新时间
|
// 存量消息最新时间
|
||||||
const lastTime = ref('')
|
const lastTime = ref('')
|
||||||
|
|
||||||
|
// 消息列表滚动容器
|
||||||
|
const messageListRef = ref<any>(null)
|
||||||
|
|
||||||
|
// 自动滚动状态
|
||||||
|
const shouldAutoScroll = ref(true)
|
||||||
|
const isSyncingScroll = ref(false)
|
||||||
|
|
||||||
|
const MESSAGE_AUTO_SCROLL_THRESHOLD = 64
|
||||||
|
|
||||||
|
let scrollTimer: number | undefined
|
||||||
|
let scrollReleaseTimer: number | undefined
|
||||||
|
|
||||||
// 获取消息时间
|
// 获取消息时间
|
||||||
function getMessageTime(message: Message) {
|
function getMessageTime(message: Message) {
|
||||||
return message.reg_time || message.date || ''
|
return message.reg_time || message.date || ''
|
||||||
@@ -66,6 +75,98 @@ function updateLastTime(message: Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getScrollContainer() {
|
||||||
|
const container = messageListRef.value?.$el ?? messageListRef.value
|
||||||
|
|
||||||
|
return container instanceof HTMLElement ? container : null
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNearBottom(container: HTMLElement) {
|
||||||
|
const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight
|
||||||
|
|
||||||
|
return distanceFromBottom <= Math.max(MESSAGE_AUTO_SCROLL_THRESHOLD, container.clientHeight / 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAutoScrollState() {
|
||||||
|
const container = getScrollContainer()
|
||||||
|
if (!container || isSyncingScroll.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldAutoScroll.value = isNearBottom(container)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleScroll() {
|
||||||
|
updateAutoScrollState()
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindScrollListener() {
|
||||||
|
const container = getScrollContainer()
|
||||||
|
if (!container) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
container.removeEventListener('scroll', handleScroll)
|
||||||
|
container.addEventListener('scroll', handleScroll, { passive: true })
|
||||||
|
updateAutoScrollState()
|
||||||
|
}
|
||||||
|
|
||||||
|
function unbindScrollListener() {
|
||||||
|
getScrollContainer()?.removeEventListener('scroll', handleScroll)
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollContainerToEnd() {
|
||||||
|
const container = getScrollContainer()
|
||||||
|
if (!container) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isSyncingScroll.value = true
|
||||||
|
container.scrollTop = container.scrollHeight
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const latestContainer = getScrollContainer()
|
||||||
|
if (!latestContainer) {
|
||||||
|
isSyncingScroll.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
latestContainer.scrollTop = latestContainer.scrollHeight
|
||||||
|
shouldAutoScroll.value = true
|
||||||
|
|
||||||
|
if (scrollReleaseTimer) {
|
||||||
|
window.clearTimeout(scrollReleaseTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollReleaseTimer = window.setTimeout(() => {
|
||||||
|
isSyncingScroll.value = false
|
||||||
|
updateAutoScrollState()
|
||||||
|
}, 80)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestScrollToEnd(force = false) {
|
||||||
|
if (!force && !shouldAutoScroll.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollTimer) {
|
||||||
|
window.clearTimeout(scrollTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollTimer = window.setTimeout(() => {
|
||||||
|
nextTick(() => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
scrollContainerToEnd()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}, force ? 0 : 80)
|
||||||
|
}
|
||||||
|
|
||||||
|
function forceScrollToEnd() {
|
||||||
|
requestScrollToEnd(true)
|
||||||
|
}
|
||||||
|
|
||||||
// 合并消息到当前列表
|
// 合并消息到当前列表
|
||||||
function mergeMessages(items: Message[]) {
|
function mergeMessages(items: Message[]) {
|
||||||
let hasNewMessage = false
|
let hasNewMessage = false
|
||||||
@@ -95,9 +196,7 @@ function handleSSEMessage(event: MessageEvent) {
|
|||||||
if (message) {
|
if (message) {
|
||||||
const object = JSON.parse(message)
|
const object = JSON.parse(message)
|
||||||
if (mergeMessages([object])) {
|
if (mergeMessages([object])) {
|
||||||
nextTick(() => {
|
requestScrollToEnd() // 新消息到达时触发智能滚动
|
||||||
emit('scroll') // 新消息到达时触发智能滚动
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,9 +236,7 @@ async function loadMessages({ done }: { done: any }) {
|
|||||||
|
|
||||||
// 首次加载时滚动到底部
|
// 首次加载时滚动到底部
|
||||||
if (page.value === 1 && hasNewMessage) {
|
if (page.value === 1 && hasNewMessage) {
|
||||||
nextTick(() => {
|
requestScrollToEnd(true)
|
||||||
emit('scroll')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
// 页码+1
|
// 页码+1
|
||||||
page.value++
|
page.value++
|
||||||
@@ -168,9 +265,7 @@ async function refreshLatestMessages() {
|
|||||||
})) as Message[]
|
})) as Message[]
|
||||||
|
|
||||||
if (mergeMessages(latestMessages)) {
|
if (mergeMessages(latestMessages)) {
|
||||||
nextTick(() => {
|
requestScrollToEnd()
|
||||||
emit('scroll')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('刷新最新消息失败:', error)
|
console.error('刷新最新消息失败:', error)
|
||||||
@@ -206,7 +301,7 @@ function compareTime(time1: string, time2: string) {
|
|||||||
|
|
||||||
// 图片加载完成时触发智能滚动
|
// 图片加载完成时触发智能滚动
|
||||||
function handleImageLoad() {
|
function handleImageLoad() {
|
||||||
emit('scroll')
|
requestScrollToEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暂停SSE连接
|
// 暂停SSE连接
|
||||||
@@ -232,18 +327,32 @@ defineExpose({
|
|||||||
pauseSSE,
|
pauseSSE,
|
||||||
resumeSSE,
|
resumeSSE,
|
||||||
refreshLatestMessages,
|
refreshLatestMessages,
|
||||||
|
forceScrollToEnd,
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 组件挂载后触发一次滚动事件
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
emit('scroll')
|
bindScrollListener()
|
||||||
|
requestScrollToEnd(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (scrollTimer) {
|
||||||
|
window.clearTimeout(scrollTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollReleaseTimer) {
|
||||||
|
window.clearTimeout(scrollReleaseTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
unbindScrollListener()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VInfiniteScroll
|
<VInfiniteScroll
|
||||||
|
ref="messageListRef"
|
||||||
:mode="!isLoaded ? 'intersect' : 'manual'"
|
:mode="!isLoaded ? 'intersect' : 'manual'"
|
||||||
side="start"
|
side="start"
|
||||||
:items="messages"
|
:items="messages"
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ async function fetchData({ done }: { done: any }) {
|
|||||||
page.value++
|
page.value++
|
||||||
// 返回加载成功
|
// 返回加载成功
|
||||||
done('ok')
|
done('ok')
|
||||||
|
await nextTick()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 设置加载中
|
// 设置加载中
|
||||||
|
|||||||
Reference in New Issue
Block a user