From b2555a328ee990e8e25f32040633c2ec2fde8221 Mon Sep 17 00:00:00 2001
From: 祖安之光 <11848914+light-of-zuan@user.noreply.gitee.com>
Date: 星期一, 18 八月 2025 16:47:57 +0800
Subject: [PATCH] 修改新增
---
src/views/build/conpanyFunctionConsult/standardSysTemp/sysStandardModule/index.vue | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/src/views/build/conpanyFunctionConsult/standardSysTemp/sysStandardModule/index.vue b/src/views/build/conpanyFunctionConsult/standardSysTemp/sysStandardModule/index.vue
index b7e2c7c..ebee8de 100644
--- a/src/views/build/conpanyFunctionConsult/standardSysTemp/sysStandardModule/index.vue
+++ b/src/views/build/conpanyFunctionConsult/standardSysTemp/sysStandardModule/index.vue
@@ -32,11 +32,12 @@
<el-table-column label="模板名称" prop="templateName" align="center"/>
<el-table-column label="模板文件" align="center">
<template #default="scope">
- <el-button link type="primary" @click="downloadFile(scope.row.filePath)">{{scope.row.templateName + '模板'}}</el-button>
+ <el-link type="primary" @click="openFile(scope.row.filePath)">{{scope.row.templateName + '模板' + scope.row.format}}</el-link>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" >
<template #default="scope">
+ <el-button link type="primary" @click="downloadFile(scope.row.filePath)">下载</el-button>
<el-button link type="primary" @click="openDialog('edit',scope.row)">编辑</el-button>
<el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
</template>
@@ -50,7 +51,7 @@
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
-
+ <div id="docx-preview-container" style="width: 100%; height: auto; border: 1px solid #ccc;"></div>
<edit-dialog ref="dialogRef" @getList=getList></edit-dialog>
</div>
</template>
@@ -63,6 +64,8 @@
import editDialog from './components/editDialog.vue'
import useUserStore from "@/store/modules/user";
import {getStandardTemp,delStandardTemp} from "@/api/standardSys/standardSys";
+import { renderAsync } from "docx-preview";
+
const userStore = useUserStore()
const { proxy } = getCurrentInstance();
const loading = ref(false);
@@ -97,6 +100,50 @@
})
+const openFile = async(path)=>{
+ const ext = path.split('.').pop().toLowerCase();
+ if (ext === 'doc') {
+ ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
+ window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
+ }).catch(() => {
+ console.log('取消预览')
+ });
+ return
+ }else if(ext === 'pdf'){
+ window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
+ }else{
+ try {
+ // 1. 获取文件
+ const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
+ const arrayBuffer = await response.arrayBuffer();
+ // 2. 创建新窗口
+ const win = window.open('', '_blank');
+ win.document.write(`
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <title>预览</title>
+ <style>
+ body { margin: 20px; font-family: Arial; }
+ .docx-container { width: 100%; height: 100%; }
+ </style>
+ </head>
+ <body>
+ <div id="container" class="docx-container"></div>
+ </body>
+ </html>
+ `);
+ // 3. 渲染 DOCX
+ await renderAsync(arrayBuffer, win.document.getElementById('container'));
+
+ } catch (error) {
+ console.error('预览失败:', error);
+ alert(`预览失败: ${error.message}`);
+ }
+ }
+}
+
+
const getList = async () => {
loading.value = true
const res = await getStandardTemp(data.queryParams)
--
Gitblit v1.9.2