refactor(preview): simplify fullscreen handling and improve styling
- Removed unnecessary fullscreen event listeners and streamlined the fullscreen toggle logic in the document preview component. - Updated the CSS for fullscreen mode to enhance layout and responsiveness for various document types, including images and presentations. - Adjusted the structure of the preview container to eliminate reliance on a ref, improving code clarity and maintainability. These changes enhance the user experience by providing a more intuitive fullscreen functionality and better visual presentation of documents.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, shallowRef, watch, onUnmounted, nextTick, defineAsyncComponent, onMounted } from 'vue';
|
import { ref, shallowRef, watch, onUnmounted, nextTick, defineAsyncComponent } from 'vue';
|
||||||
import { previewKnowledgeFile } from '@/api/knowledge-base/index';
|
import { previewKnowledgeFile } from '@/api/knowledge-base/index';
|
||||||
import { MessagePlugin } from 'tdesign-vue-next';
|
import { MessagePlugin } from 'tdesign-vue-next';
|
||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
@@ -33,30 +33,16 @@ const imageNaturalHeight = ref(0);
|
|||||||
let loadedForId = '';
|
let loadedForId = '';
|
||||||
|
|
||||||
const isFullscreen = ref(false);
|
const isFullscreen = ref(false);
|
||||||
const previewContainerRef = ref<HTMLElement | null>(null);
|
|
||||||
|
|
||||||
function toggleFullscreen() {
|
function toggleFullscreen() {
|
||||||
if (!document.fullscreenElement) {
|
isFullscreen.value = !isFullscreen.value;
|
||||||
if (previewContainerRef.value?.requestFullscreen) {
|
if (isFullscreen.value) {
|
||||||
previewContainerRef.value.requestFullscreen().catch((err: any) => {
|
document.body.style.overflow = 'hidden';
|
||||||
console.error(`Error attempting to enable fullscreen: ${err.message}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (document.exitFullscreen) {
|
document.body.style.overflow = '';
|
||||||
document.exitFullscreen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFullscreenChange() {
|
|
||||||
isFullscreen.value = !!document.fullscreenElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const fileTypeMap: Record<string, typeof previewType.value> = {};
|
const fileTypeMap: Record<string, typeof previewType.value> = {};
|
||||||
['pdf'].forEach(t => fileTypeMap[t] = 'pdf');
|
['pdf'].forEach(t => fileTypeMap[t] = 'pdf');
|
||||||
@@ -322,13 +308,13 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
document.removeEventListener('fullscreenchange', handleFullscreenChange);
|
document.body.style.overflow = '';
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div ref="previewContainerRef" class="document-preview" :class="{ 'is-fullscreen': isFullscreen }">
|
<div class="document-preview" :class="{ 'is-fullscreen': isFullscreen }">
|
||||||
<!-- Toolbar -->
|
<!-- Toolbar -->
|
||||||
<div class="preview-toolbar" v-if="!loading && !error && previewType !== 'unsupported'">
|
<div class="preview-toolbar" v-if="!loading && !error && previewType !== 'unsupported'">
|
||||||
<t-space size="small">
|
<t-space size="small">
|
||||||
@@ -439,19 +425,39 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.is-fullscreen {
|
.is-fullscreen {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
z-index: 2001;
|
||||||
background: var(--td-bg-color-container);
|
background: var(--td-bg-color-container);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
z-index: 1000;
|
|
||||||
|
|
||||||
.preview-container {
|
.preview-toolbar {
|
||||||
max-height: 100vh;
|
position: fixed;
|
||||||
|
top: 12px;
|
||||||
|
right: 32px;
|
||||||
|
z-index: 2002;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-pdf, .preview-pptx {
|
.preview-pdf {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-pptx {
|
||||||
|
height: auto;
|
||||||
|
min-height: 100vh;
|
||||||
|
overflow: visible;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
:deep(.pptx-preview-wrapper) {
|
||||||
|
height: auto !important;
|
||||||
|
overflow-y: visible !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.preview-docx {
|
.preview-docx {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -462,6 +468,22 @@ onUnmounted(() => {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-image {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
.image-wrapper img {
|
||||||
|
max-height: calc(100vh - 80px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-excel .excel-container,
|
||||||
|
.preview-markdown,
|
||||||
|
.preview-text .code-preview {
|
||||||
|
max-height: 100vh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-toolbar {
|
.preview-toolbar {
|
||||||
@@ -563,12 +585,17 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
// ── PPTX ──
|
// ── PPTX ──
|
||||||
.preview-pptx {
|
.preview-pptx {
|
||||||
height: @preview-max-h;
|
max-height: @preview-max-h;
|
||||||
min-height: 500px;
|
min-height: 500px;
|
||||||
border: 1px solid @border-color;
|
border: 1px solid @border-color;
|
||||||
border-radius: @border-radius;
|
border-radius: @border-radius;
|
||||||
overflow: hidden;
|
overflow: auto;
|
||||||
background: @bg-subtle;
|
background: @bg-subtle;
|
||||||
|
|
||||||
|
:deep(.pptx-preview-wrapper) {
|
||||||
|
height: auto !important;
|
||||||
|
overflow-y: visible !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Excel ──
|
// ── Excel ──
|
||||||
@@ -702,12 +729,12 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
:deep(.vue-office-pptx) {
|
:deep(.vue-office-pptx) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.vue-office-pptx-main) {
|
:deep(.vue-office-pptx-main) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.excel-sheet) {
|
:deep(.excel-sheet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user