Просмотр исходного кода

任务编辑上传附件预览

Zimo 1 день назад
Родитель
Сommit
ec012ab31b
1 измененных файлов с 21 добавлено и 0 удалено
  1. 21 0
      src/views/pms/iotprojecttask/IotProjectTaskForm.vue

+ 21 - 0
src/views/pms/iotprojecttask/IotProjectTaskForm.vue

@@ -478,6 +478,7 @@
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         name="files"
         name="files"
         class="w-50%"
         class="w-50%"
+        @preview="handlePreview"
       >
       >
         <el-button type="primary">上传工程设计</el-button>
         <el-button type="primary">上传工程设计</el-button>
         <template #tip>
         <template #tip>
@@ -493,6 +494,7 @@
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         name="files"
         name="files"
         class="w-50%"
         class="w-50%"
+        @preview="handlePreview"
       >
       >
         <el-button type="primary">上传地质设计</el-button>
         <el-button type="primary">上传地质设计</el-button>
         <template #tip>
         <template #tip>
@@ -508,6 +510,7 @@
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         :headers="{ 'tenant-id': 1, 'device-id': 'undefined' }"
         name="files"
         name="files"
         class="w-50%"
         class="w-50%"
+        @preview="handlePreview"
       >
       >
         <el-button :disabled="tableData[0].status !== 'wg'" type="primary">上传完井报告</el-button>
         <el-button :disabled="tableData[0].status !== 'wg'" type="primary">上传完井报告</el-button>
         <template #tip>
         <template #tip>
@@ -817,6 +820,7 @@ import * as UserApi from '@/api/system/user'
 import { IotProjectTaskAttrsApi } from '@/api/pms/iotprojecttaskattrs'
 import { IotProjectTaskAttrsApi } from '@/api/pms/iotprojecttaskattrs'
 import { DICT_TYPE, getStrDictOptions, getDictLabel } from '@/utils/dict'
 import { DICT_TYPE, getStrDictOptions, getDictLabel } from '@/utils/dict'
 import { IotOpeationFillApi } from '@/api/pms/iotopeationfill'
 import { IotOpeationFillApi } from '@/api/pms/iotopeationfill'
+import { Base64 } from 'js-base64'
 // 在导入部分添加Plus图标
 // 在导入部分添加Plus图标
 // import { Plus } from '@element-plus/icons-vue'
 // import { Plus } from '@element-plus/icons-vue'
 
 
@@ -839,6 +843,23 @@ if (params.projectId) {
     : (query.projectId as string)
     : (query.projectId as string)
 }
 }
 
 
+function handlePreview(file: any) {
+  if (!file.response) {
+    message.error('附件路径不存在')
+    return
+  }
+
+  try {
+    const filePath = file.response.data.filePath ?? file.response.data.files[0].filePath
+    const encodedPath = encodeURIComponent(Base64.encode(filePath))
+
+    window.open(`http://doc.deepoil.cc:8012/onlinePreview?url=${encodedPath}`)
+  } catch (error) {
+    console.error('预览附件失败:', error)
+    message.error('预览附件失败')
+  }
+}
+
 // 施工队伍 选择树 响应式变量
 // 施工队伍 选择树 响应式变量
 const defaultExpandedKeys = ref<number[]>([]) // 默认展开的部门节点keys
 const defaultExpandedKeys = ref<number[]>([]) // 默认展开的部门节点keys
 const treeSelectRef = ref() // 树选择组件的引用
 const treeSelectRef = ref() // 树选择组件的引用