yangys
2024-01-13 b8d63989635bc9fb58357f76333796e21409985b
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
<template>
  <div>
    <el-upload
      class="upload-demo"
      ref="upload"
      action="/api/mdc/utilization/import19"
      :on-change="handleChange"
      name="file"
      accept=".xls,.xlsx"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :on-success="handleSuccess"
      :file-list="fileList"
      :auto-upload="false">
      <el-button style="margin-left: 10px; margin-top: 30px;" slot="trigger" size="small" type="primary">选择文件</el-button>
      <el-button style="margin-left: 10px; margin-top: 30px;" size="small" type="success" @click="submitUpload">导入文件</el-button>
    </el-upload>
  </div>
</template>
 
<script>
export default {
  name: 'Upload',
  data() {
    return {
      fileList: []
    }
  },
  methods: {
    submitUpload(event) {
      event.preventDefault()
      this.$refs.upload.submit()
    },
    handleChange(file, fileList) {
      this.fileList = fileList
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleSuccess(response, file, fileList) {
      fileList.pop(file)
      if (response.result === 'SUCCESS') {
        this.$message.success('导入成功')
      } else {
        this.$message.success('导入失败')
      }
    }
  }
}
</script>
 
<style scoped>
 
</style>