From f96b425b531a70c541b63b66f7b18c1d1b87fb1d Mon Sep 17 00:00:00 2001
From: 祖安之光 <11848914+light-of-zuan@user.noreply.gitee.com>
Date: 星期三, 16 七月 2025 10:18:05 +0800
Subject: [PATCH] 修改新增

---
 src/views/build/conpanyFunctionConsult/industryTemplate/index.vue |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/src/views/build/conpanyFunctionConsult/industryTemplate/index.vue b/src/views/build/conpanyFunctionConsult/industryTemplate/index.vue
index f53ebab..b13c007 100644
--- a/src/views/build/conpanyFunctionConsult/industryTemplate/index.vue
+++ b/src/views/build/conpanyFunctionConsult/industryTemplate/index.vue
@@ -30,6 +30,9 @@
             </el-option>
           </el-select>
         </el-form-item>
+        <el-form-item label="文件记录:" >
+          <el-input v-model.trim="data.queryParams.templateName"  placeholder="请输入"></el-input>
+        </el-form-item>
         <el-form-item label="分类:" >
           <el-input v-model.trim="data.queryParams.type"  placeholder="请输入"></el-input>
         </el-form-item>
@@ -48,13 +51,14 @@
       <el-table-column label="行业" prop="industryName" align="center" />
       <el-table-column label="模板" prop="fileName" align="center">
         <template #default="scope">
-          <el-link  style="" type="primary" @click="downloadFile(scope.row)">{{scope.row.fileName}}</el-link>
+          <el-link  style="" type="primary" @click="openFile(scope.row.filePath)">{{scope.row.fileName}}</el-link>
         </template>
       </el-table-column>
 
       <el-table-column label="分类" prop="type" align="center" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width" >
         <template #default="scope">
+          <el-button link type="primary" @click="downloadFile(scope.row)">下载</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>
@@ -122,6 +126,7 @@
 import axios from "axios";
 import {getToken} from "@/utils/auth";
 import {getIndustry} from "@/api/system/industry";
+import {renderAsync} from "docx-preview";
 const userStore = useUserStore()
 const { proxy } = getCurrentInstance();
 const loading = ref(false);
@@ -139,7 +144,8 @@
     pageSize: 10,
     companyId: null,
     industryType: null,
-    type: ''
+    type: '',
+    templateName: ''
   },
   total: 0,
   dataList: [],
@@ -181,7 +187,45 @@
 onUnmounted(()=>{
 
 })
+const openFile = async(path)=>{
+  const ext = path.split('.').pop().toLowerCase();
+  if (ext === 'doc' || ext === 'xls' || ext === 'xlsx') {
+    ElMessageBox.confirm('暂不支持线上预览文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
+      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
+    }).catch(() => {
+      console.log('取消预览')
+    });
+    return
+  }
+  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 getIndustryTemp(data.queryParams)
@@ -303,7 +347,8 @@
       pageSize: 10,
       companyId: null,
       industryType: null,
-      type: ''
+      type: '',
+      templateName: ''
     }
     await getCompanyList()
   }else {
@@ -312,7 +357,8 @@
       pageSize: 10,
       companyId: data.queryParams.companyId,
       industryType: null,
-      type: ''
+      type: '',
+      templateName: ''
     }
   }
   await getList()

--
Gitblit v1.9.2