spring
2025-03-17 2bfe437d8b30fb7d80a38875b00ebf2b222ea05f
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <div>
    <div style="margin-bottom: 10px">
      <el-upload ref='upload' :action="fileAction" :auto-upload="true" :before-upload="fileBeforeUpload"
        :data="{ id: currentId }" :headers="uploadHeader" :on-error="onError" :on-success="handleSuccessUp"
        :show-file-list="false" accept='.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'
        style="width: 80px !important;">
        <el-button size="small" style="height: 38px" type="primary">附件上传</el-button>
      </el-upload>
    </div>
    <lims-table :tableData="tableDataFile" :column="columnFile" height="500px" key="tableDataFile"
      :tableLoading="tableLoadingFile"></lims-table>
  </div>
</template>
 
<script>
import limsTable from "@/components/Table/lims-table.vue";
import { fileList, delFile } from "@/api/structural/workshop.js"
export default {
  components: {
    limsTable,
  },
  props: ['currentId'],
  computed: {
    fileAction() {
      return this.javaApi + '/workShop/uploadFile'
    },
  },
  data() {
    return {
      columnFile: [
        {
          dataType: 'tag',
          label: '类型',
          prop: 'type',
          formatData: (params) => {
            if (params == 1) {
              return '图片'
            } else if (params == 2) {
              return '文件'
            } else {
              return ''
            }
          },
          formatType: (params) => {
            if (params == 1) {
              return 'success'
            } else if (params == 2) {
              return 'warning'
            } else {
              return ''
            }
          }
        },
        { label: '附件名称', prop: 'fileName' },
        { label: '上传人', prop: 'name' },
        { label: '上传时间', prop: 'createTime' },
        {
          dataType: 'action',
          fixed: 'right',
          label: '操作',
          width: '170px',
          operation: [
            {
              name: '下载',
              type: 'text',
              clickFun: (row) => {
                this.handleDown(row);
              }
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.delete(row);
              }
            },
          ]
        }
      ],
      tableDataFile: [],
      tableLoadingFile: false,
    }
  },
  mounted() {
    this.getFileList()
  },
  methods: {
    // 查询附件查看列表回调
    getFileList() {
      this.tableLoadingFile = true
      fileList({ id: this.currentId }).then(res => {
        this.tableLoadingFile = false
        if (res.code === 200) {
          this.tableDataFile = res.data
        }
      }).catch(err => {
        this.tableLoadingFile = false
      })
    },
    fileBeforeUpload(file) {
      let flag = true
      console.log('file----', file)
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        flag = false
      }
      if (!flag) {
        return Promise.reject(flag); //正确的终止
      }
    },
    handleSuccessUp(response,) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.getFileList()
      }
    },
    // 下载附件的文件
    handleDown(row) {
      downFile({
        id: row.id,
      }).then(res => {
        this.$download.saveAs(res.data.fileUrl, row.fileName);
      }).catch(error => {
 
      })
    },
    // 删除附件文件
    delete(row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoadingFile = true
        delFile({ id: row.id }).then(res => {
          this.tableLoadingFile = false
          this.$message.success('删除成功')
          this.getFileList()
        }).catch(err => {
          this.tableLoadingFile = false
          console.log('err---', err);
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      })
    },
    onError(err, file, fileList, type) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
  }
}
</script>
 
<style scoped></style>