2025-05-06 01:46:24 +08:00
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
|
|
|
|
import { useVbenDrawer } from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
import VueOfficePptx from '@vue-office/pptx';
|
2025-05-12 19:52:53 +08:00
|
|
|
|
import { message } from 'ant-design-vue';
|
2025-05-06 01:46:24 +08:00
|
|
|
|
|
|
|
|
|
// import '@vue-office/pptx/lib/index.css';
|
2025-05-06 10:28:44 +08:00
|
|
|
|
// http://47.112.173.8:6802/static/66f3cfd95e364a239d8036390db658ae.pptx
|
2025-05-06 16:50:28 +08:00
|
|
|
|
// const url = ref('');
|
2025-05-12 19:52:53 +08:00
|
|
|
|
const isLoading = ref(false); // 新增:加载状态变量
|
2025-05-06 10:28:44 +08:00
|
|
|
|
const pptx = ref('/pptx/66f3cfd95e364a239d8036390db658ae.pptx');
|
2025-05-06 01:46:24 +08:00
|
|
|
|
const pptStyle = ref({
|
|
|
|
|
height: 'calc(100vh - 100px)',
|
2025-05-08 19:00:31 +08:00
|
|
|
|
width: '100%',
|
2025-05-06 01:46:24 +08:00
|
|
|
|
margin: 'auto',
|
2025-05-06 10:28:44 +08:00
|
|
|
|
background: '#ffffff',
|
2025-05-06 01:46:24 +08:00
|
|
|
|
});
|
|
|
|
|
const renderedHandler = () => {
|
2025-05-12 19:52:53 +08:00
|
|
|
|
isLoading.value = false; // 文档渲染完成,关闭加载状态
|
|
|
|
|
message.success('渲染完成');
|
2025-05-06 01:46:24 +08:00
|
|
|
|
};
|
2025-05-12 19:52:53 +08:00
|
|
|
|
const errorHandler = () => {
|
|
|
|
|
isLoading.value = false; // 出错时也关闭加载状态
|
|
|
|
|
message.error('渲染失败');
|
2025-05-06 01:46:24 +08:00
|
|
|
|
};
|
|
|
|
|
const [Drawer, drawerApi] = useVbenDrawer({
|
|
|
|
|
onCancel() {
|
|
|
|
|
drawerApi.close();
|
|
|
|
|
},
|
|
|
|
|
onClosed() {
|
|
|
|
|
drawerApi.setState({ overlayBlur: 0, placement: 'right' });
|
|
|
|
|
},
|
|
|
|
|
onOpenChange(isOpen: boolean) {
|
|
|
|
|
if (isOpen) {
|
2025-05-06 16:50:28 +08:00
|
|
|
|
const data = drawerApi.getData<Record<string, any>>();
|
|
|
|
|
if (data) {
|
2025-05-12 19:52:53 +08:00
|
|
|
|
isLoading.value = true; // 开始加载文档,开启加载状态
|
2025-05-16 23:02:11 +08:00
|
|
|
|
pptx.value = `/pptx/${data}`; // 更新 pptx 的值
|
2025-05-06 16:50:28 +08:00
|
|
|
|
}
|
|
|
|
|
// url.value = drawerApi.getData<Record<string, any>>();
|
2025-05-06 01:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
2025-05-08 19:00:31 +08:00
|
|
|
|
<Drawer title="文档预览" :footer="false">
|
2025-05-12 19:52:53 +08:00
|
|
|
|
<div v-if="isLoading" class="loading-overlay">正在加载文档,请稍候...</div>
|
2025-05-06 01:46:24 +08:00
|
|
|
|
<VueOfficePptx
|
|
|
|
|
:src="pptx"
|
|
|
|
|
:style="pptStyle"
|
|
|
|
|
@rendered="renderedHandler"
|
|
|
|
|
@error="errorHandler"
|
|
|
|
|
/>
|
|
|
|
|
</Drawer>
|
|
|
|
|
</template>
|
2025-05-06 10:28:44 +08:00
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.pptx-preview-wrapper {
|
2025-05-08 19:00:31 +08:00
|
|
|
|
background: #fff;
|
2025-05-06 10:28:44 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|