From 1fba2685678695cca45127adaada26c7b96eec12 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期六, 16 五月 2026 14:46:00 +0800
Subject: [PATCH] : 重构费用报销模块界面和功能

---
 src/components/Dialog/FileList.vue |  412 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 211 insertions(+), 201 deletions(-)

diff --git a/src/components/Dialog/FileList.vue b/src/components/Dialog/FileList.vue
index e373c27..b0e78cf 100644
--- a/src/components/Dialog/FileList.vue
+++ b/src/components/Dialog/FileList.vue
@@ -1,73 +1,63 @@
 <template>
-  <el-dialog
-      v-model="isShow"
-      :title="title"
-      :width="width"
-      @close="handleClose"
-      class="attachment-dialog"
-  >
+  <el-dialog v-model="isShow"
+             :title="title"
+             :width="width"
+             @close="handleClose"
+             class="attachment-dialog">
     <!-- 宸ュ叿鏍� -->
-    <div class="toolbar">
-      <el-button
-          type="primary"
-          size="small"
-          @click="handleUpload"
-      >
+    <div v-if="editable"
+         class="toolbar">
+      <el-button type="primary"
+                 size="small"
+                 @click="handleUpload">
         涓婁紶闄勪欢
       </el-button>
     </div>
-
     <!-- 涓婁紶缁勪欢寮圭獥 -->
-    <el-dialog
-        v-model="uploadDialogVisible"
-        title="涓婁紶闄勪欢"
-        width="50%"
-        @close="handleUploadClose"
-    >
-      <AttachmentUpload
-          v-model:file-list="newFileList"
-      />
+    <el-dialog v-model="uploadDialogVisible"
+               title="涓婁紶闄勪欢"
+               width="50%"
+               @close="closeUpload">
+      <AttachmentUpload v-model:file-list="newFileList" />
       <template #footer>
-        <el-button @click="handleUploadClose">鍏抽棴</el-button>
+        <el-button @click="saveUpload">淇濆瓨</el-button>
+        <el-button @click="closeUpload">鍏抽棴</el-button>
       </template>
     </el-dialog>
-
     <!-- 鏂囦欢鍒楄〃琛ㄦ牸 -->
     <div class="table-container">
-      <el-table
-          :data="tableData"
-          border
-          class="attachment-table"
-          :height="tableData.length > 0 ? 'auto' : '120px'"
-      >
-        <el-table-column
-            label="闄勪欢鍚嶇О"
-            prop="originalFilename"
-            show-overflow-tooltip
-        />
-        <el-table-column
-            v-if="showActions"
-            fixed="right"
-            label="鎿嶄綔"
-            :width="120"
-            align="center"
-        >
+      <el-table :data="tableData"
+                border
+                class="attachment-table"
+                :height="tableData.length > 0 ? 'auto' : '120px'">
+        <el-table-column label="闄勪欢鍚嶇О"
+                         prop="originalFilename"
+                         show-overflow-tooltip />
+        <el-table-column v-if="showActions"
+                         fixed="right"
+                         label="鎿嶄綔"
+                         :width="150"
+                         align="center">
           <template #default="scope">
-            <el-button
-                link
-                type="primary"
-                size="small"
-                :href="scope.row.downloadURL"
-                class="download-link"
-            >
+            <el-button link
+                       type="primary"
+                       size="small"
+                       class="download-link"
+                       @click="previewFile(scope.row.previewURL)">
+              棰勮
+            </el-button>
+            <el-button link
+                       type="primary"
+                       size="small"
+                       class="download-link"
+                       @click="downloadFile(scope.row.downloadURL)">
               涓嬭浇
             </el-button>
-            <el-button
-                link
-                type="danger"
-                size="small"
-                @click="handleDelete(scope.row)"
-            >
+            <el-button v-if="editable"
+                       link
+                       type="danger"
+                       size="small"
+                       @click="handleDelete(scope.row)">
               鍒犻櫎
             </el-button>
           </template>
@@ -75,179 +65,199 @@
       </el-table>
     </div>
   </el-dialog>
+  <filePreview ref="filePreviewRef" />
 </template>
 
 <script setup>
-import { ref, computed, getCurrentInstance, onMounted, watch } from 'vue'
-import AttachmentUpload from '@/components/AttachmentUpload/file/index.vue'
-import {attachmentList, deleteAttachment, createAttachment} from "@/api/basicData/storageAttachment.js";
+import { ElMessage } from 'element-plus'
+  import { ref, computed, getCurrentInstance, onMounted, watch } from "vue";
+  import AttachmentUpload from "@/components/AttachmentUpload/file/index.vue";
+  import {
+    attachmentList,
+    deleteAttachment,
+    createAttachment,
+  } from "@/api/basicData/storageAttachment.js";
+  import filePreview from '@/components/filePreview/index.vue'
+  const filePreviewRef = ref()
 
-const props = defineProps({
-  visible: {
-    type: Boolean,
-    required: true,
-  },
-  recordType: {
-    type: String,
-    default: '',
-    required: true
-  },
-  recordId: {
-    type: Number,
-    default: 0,
-    required: true
-  },
-  title: {
-    type: String,
-    default: '闄勪欢'
-  },
-  width: {
-    type: String,
-    default: '50%'
-  },
-  showActions: {
-    type: Boolean,
-    default: true
+  const props = defineProps({
+    visible: {
+      type: Boolean,
+      required: true,
+    },
+    recordType: {
+      type: String,
+      default: "",
+      required: true,
+    },
+    recordId: {
+      type: Number,
+      default: 0,
+      required: true,
+    },
+    title: {
+      type: String,
+      default: "闄勪欢",
+    },
+    width: {
+      type: String,
+      default: "50%",
+    },
+    showActions: {
+      type: Boolean,
+      default: true,
+    },
+    editable: {
+      type: Boolean,
+      default: true,
+    },
+  });
+
+  const emit = defineEmits(["close", "download", "upload", "delete"]);
+
+  const { proxy } = getCurrentInstance();
+  const tableData = ref([]);
+  const uploadDialogVisible = ref(false);
+  const newFileList = ref([]);
+
+  const isShow = computed({
+    get() {
+      return props.visible;
+    },
+    set(val) {
+      emit("update:visible", val);
+    },
+  });
+
+  const handleClose = () => {
+    isShow.value = false;
+  };
+
+  // 棰勮鏂囦欢
+  const previewFile = (url) => {
+    if (url) {
+      filePreviewRef.value.open(url)
+    } else {
+      ElMessage.warning('鏂囦欢鍦板潃鏃犳晥锛屾棤娉曢瑙�')
+    }
   }
-})
 
-const emit = defineEmits([
-  'close',
-  'download',
-  'upload',
-  'delete'
-])
+  const handleUpload = () => {
+    uploadDialogVisible.value = true;
+  };
 
-const { proxy } = getCurrentInstance()
-const tableData = ref([])
-const uploadDialogVisible = ref(false)
-const newFileList = ref([])
-
-const isShow = computed({
-  get() {
-    return props.visible;
-  },
-  set(val) {
-    emit("update:visible", val);
-  },
-});
-
-const handleClose = () => {
-  isShow.value = false
-}
-
-const handleUpload = () => {
-  uploadDialogVisible.value = true
-}
-
-const handleUploadClose = async () => {
-  // 妫�鏌ユ槸鍚︽湁鏂颁笂浼犵殑鏂囦欢
-  if (newFileList.value.length > 0) {
-    try {
-      await createAttachment({
-        application: 'file',
+  const saveUpload = async () => {
+    // 妫�鏌ユ槸鍚︽湁鏂颁笂浼犵殑鏂囦欢
+    if (newFileList.value.length > 0) {
+      createAttachment({
+        application: "file",
         recordType: props.recordType,
         recordId: props.recordId,
-        storageBlobDTOs: [...newFileList.value, ...tableData.value]
+        storageBlobDTOs: [...newFileList.value, ...tableData.value],
+      }).then((res) => {
+        if (res && res.code === 200) {
+          proxy?.$modal?.msgSuccess("涓婁紶鎴愬姛");
+          newFileList.value = [];
+          // 鍒锋柊鍒楄〃
+          setList();
+        }
+      }).finally(() => {
+        uploadDialogVisible.value = false;
       })
-      newFileList.value = []
-      // 鍒锋柊鍒楄〃
-      setList()
-    } catch (error) {
-      proxy?.$modal?.msgError('涓婁紶澶辫触')
     }
   }
-  uploadDialogVisible.value = false
-}
 
+  const closeUpload = () => {
+    newFileList.value = [];
+    uploadDialogVisible.value = false;
+  };
 
+  const handleDelete = async (row, index) => {
+    deleteAttachment([row.storageAttachmentId]).then((res) => {
+      if (res && res.code === 200) {
+        proxy?.$modal?.msgSuccess("鍒犻櫎鎴愬姛");
+        setList();
+      }
+    })
+  };
 
-const handleDelete = async (row, index) => {
-  try {
-    await deleteAttachment([row.storageAttachmentId])
-    proxy?.$modal?.msgSuccess('鍒犻櫎鎴愬姛')
-    setList()
-  } catch (error) {
-    proxy?.$modal?.msgError('鍒犻櫎澶辫触')
-  }
-}
+  const setList = () => {
+    attachmentList({
+      recordType: props.recordType,
+      recordId: props.recordId,
+    }).then(res => {
+      tableData.value = (res && res.data) || [];
+    });
+  };
 
-const setList = () => {
-  attachmentList({
-    recordType: props.recordType,
-    recordId: props.recordId,
-  }).then(res => {
-    if (res && res.data) {
-      tableData.value = res.data || []
-    }
-  })
-}
-
-onMounted(() => {
-  setList()
-})
+  const downloadFile = url => {
+    window.open(url, "_blank");
+  };
+  onMounted(() => {
+    setList();
+  });
 </script>
 
 <style scoped>
-.attachment-dialog {
-  border-radius: 12px;
-}
+  .attachment-dialog {
+    border-radius: 12px;
+  }
 
-.toolbar {
-  margin-bottom: 16px;
-  text-align: right;
-}
+  .toolbar {
+    margin-bottom: 16px;
+    text-align: right;
+  }
 
-.table-container {
-  max-height: 40vh;
-  overflow-y: auto;
-  min-height: 120px;
-  padding-bottom: 16px;
-  box-sizing: border-box;
-  will-change: scroll-position;
-  transform: translateZ(0);
-  -webkit-overflow-scrolling: touch;
-}
+  .table-container {
+    max-height: 40vh;
+    overflow-y: auto;
+    min-height: 120px;
+    padding-bottom: 16px;
+    box-sizing: border-box;
+    will-change: scroll-position;
+    transform: translateZ(0);
+    -webkit-overflow-scrolling: touch;
+  }
 
-:deep(.el-table) {
-  margin-bottom: 0;
-}
+  :deep(.el-table) {
+    margin-bottom: 0;
+  }
 
-:deep(.el-table__body-wrapper) {
-  overflow-y: auto;
-  will-change: transform;
-  transform: translateZ(0);
-}
+  :deep(.el-table__body-wrapper) {
+    overflow-y: auto;
+    will-change: transform;
+    transform: translateZ(0);
+  }
 
-:deep(.el-table__body tr) {
-  transition: none;
-}
+  :deep(.el-table__body tr) {
+    transition: none;
+  }
 
-:deep(.el-dialog__footer) {
-  padding-top: 12px;
-  border-top: 1px solid #e9ecef;
-}
+  :deep(.el-dialog__footer) {
+    padding-top: 12px;
+    border-top: 1px solid #e9ecef;
+  }
 
-.attachment-table {
-  border-radius: 8px;
-}
+  .attachment-table {
+    border-radius: 8px;
+  }
 
-:deep(.el-dialog__header) {
-  background-color: #f8f9fa;
-  border-bottom: 1px solid #e9ecef;
-  padding: 16px 20px;
-}
+  :deep(.el-dialog__header) {
+    background-color: #f8f9fa;
+    border-bottom: 1px solid #e9ecef;
+    padding: 16px 20px;
+  }
 
-:deep(.el-dialog__title) {
-  font-size: 16px;
-  font-weight: 600;
-}
+  :deep(.el-dialog__title) {
+    font-size: 16px;
+    font-weight: 600;
+  }
 
-:deep(.el-dialog__body) {
-  padding: 16px 20px;
-}
+  :deep(.el-dialog__body) {
+    padding: 16px 20px;
+  }
 
-:deep(.el-table__empty-text) {
-  color: #999;
-}
+  :deep(.el-table__empty-text) {
+    color: #999;
+  }
 </style>
\ No newline at end of file

--
Gitblit v1.9.3