|
|
@@ -19,7 +19,7 @@
|
|
|
`data-event-status` 是状态文本,`data-event-mode` 是当前切换。
|
|
|
-->
|
|
|
<template>
|
|
|
- <div class="event-list-pane" :data-event-mode="view.switchView.key">
|
|
|
+ <div ref="rootRef" class="event-list-pane" :data-event-mode="view.switchView.key">
|
|
|
<!-- 预警/报警分段切换(共享状态:eventStore.mode,四块面板共用一份) -->
|
|
|
<div class="event-list-pane__switch" role="group" aria-label="预警/报警切换">
|
|
|
<button
|
|
|
@@ -136,7 +136,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed, onBeforeUnmount, watch } from 'vue'
|
|
|
+import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
|
|
import { eventListSwitchOptions } from '../domain/eventList.js'
|
|
|
import { sectionPending } from '../domain/panelBlocks.js'
|
|
|
import { useEventStore } from '../stores/eventStore.js'
|
|
|
@@ -162,6 +162,46 @@ const switchOptions = eventListSwitchOptions()
|
|
|
/** 还没取过数(界面说"正在取数",不说"没有数据")。 */
|
|
|
const pending = computed(() => sectionPending(view.value.section))
|
|
|
|
|
|
+const rootRef = ref(null)
|
|
|
+let savedScrollTop = 0
|
|
|
+let savedScrollKey = ''
|
|
|
+let stableScrollKey = ''
|
|
|
+
|
|
|
+function scrollHost() {
|
|
|
+ return rootRef.value && rootRef.value.closest ? rootRef.value.closest('.cockpit-panel__body') : null
|
|
|
+}
|
|
|
+
|
|
|
+function scrollContextKey() {
|
|
|
+ const current = view.value
|
|
|
+ return [eventStore.mode, current.section && current.section.state, current.pagination && current.pagination.page, current.filterView && current.filterView.active].join('|')
|
|
|
+}
|
|
|
+
|
|
|
+watch(view, () => {
|
|
|
+ if (!eventStore.loading) stableScrollKey = scrollContextKey()
|
|
|
+}, { immediate: true })
|
|
|
+
|
|
|
+/**
|
|
|
+ * 定时刷新/手动刷新会重取整张当前列表。刷新期间保留列表 DOM,同时在 loading
|
|
|
+ * 结束的同一拍把面板滚动位置放回去;否则长列表一刷新就跳回第一条,用户找不到刚点的卡片。
|
|
|
+ */
|
|
|
+watch(() => eventStore.loading, (loading, previous) => {
|
|
|
+ if (loading && !previous) {
|
|
|
+ savedScrollTop = scrollHost() ? scrollHost().scrollTop : 0
|
|
|
+ savedScrollKey = stableScrollKey || scrollContextKey()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!loading && previous) {
|
|
|
+ const top = savedScrollTop
|
|
|
+ const key = savedScrollKey
|
|
|
+ nextTick(() => {
|
|
|
+ // 换族/翻页/换筛选是另一种浏览上下文,不能被上一次列表的滚动位置污染。
|
|
|
+ if (key !== scrollContextKey()) return
|
|
|
+ const host = scrollHost()
|
|
|
+ if (host) host.scrollTop = top
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
function canOpen(row) {
|
|
|
return typeof row.code === 'string' && row.code.trim() !== ''
|
|
|
}
|
|
|
@@ -169,7 +209,11 @@ function canOpen(row) {
|
|
|
function openEvent(row) {
|
|
|
eventStore.closeEvent()
|
|
|
// 取数用内部键;展示与详情里的「事件编码」用业务编号(definition 在 domain 层)。
|
|
|
- return entityDetailStore.show({ kind: 'event', id: row.code, family: row.family || eventStore.mode }, row, { side })
|
|
|
+ const opened = entityDetailStore.show({ kind: 'event', id: row.code, family: row.family || eventStore.mode }, row, { side })
|
|
|
+ Promise.resolve(opened)
|
|
|
+ .then((ok) => { if (ok) return eventStore.loadCurrentEvents() })
|
|
|
+ .catch(() => {})
|
|
|
+ return opened
|
|
|
}
|
|
|
|
|
|
function setMode(next) {
|