gaoluyang
2026-05-18 da57fbd8e7fa021614fb32502fb1520ea4e34e1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
  <el-dialog v-model="dialogVisible" title="附件" width="40%" :before-close="handleClose" draggable>
    <el-table :data="tableData" border height="40vh">
      <el-table-column label="附件名称" prop="originalFilename" min-width="400" show-overflow-tooltip />
      <el-table-column fixed="right" label="操作" width="150" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">下载</el-button>
          <el-button link type="primary" size="small" @click="lookFile(scope.row)">预览</el-button>
          <el-button link type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
  <filePreview ref="filePreviewRef" />
</template>
 
<script setup>
import { ref } from 'vue'
import filePreview from '@/components/filePreview/index.vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import { deleteAttachment } from '@/api/basicData/storageAttachment.js'
 
const dialogVisible = ref(false)
const tableData = ref([])
const currentRowId = ref(null)
const { proxy } = getCurrentInstance();
const filePreviewRef = ref()
const emit = defineEmits(['refresh'])
 
const handleClose = () => {
  dialogVisible.value = false
}
 
const open = (list, rowId) => {
  dialogVisible.value = true
  tableData.value = list || []
  currentRowId.value = rowId
}
 
const downLoadFile = (row) => {
  proxy.$download.byUrl(row.url, row.originalFilename);
}
 
const lookFile = (row) => {
  filePreviewRef.value.open(row.url)
}
 
// 删除附件
const handleDelete = (row) => {
  ElMessageBox.confirm(`确认删除附件"${row.originalFilename}"吗?`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    deleteAttachment([row.storageAttachmentId]).then(() => {
      ElMessage.success('删除成功')
      // 从列表中移除已删除的附件
      const index = tableData.value.findIndex(item => item.id === row.id)
      if (index !== -1) {
        tableData.value.splice(index, 1)
      }
      // 触发刷新事件
      emit('refresh', currentRowId.value)
    }).catch(() => {
      ElMessage.error('删除失败')
    })
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
 
defineExpose({
  open
})
</script>
 
<style scoped></style>