新版交易所前段管理后台
1
PC-20250623MANY\Administrator
2025-07-06 0363875eb333c67529c8b27221a6da45d1a50bfa
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
<template>
  <div>
    <el-upload
      :action="$http.adornUrl('/admin/file/upload/element')"
      :headers="{Authorization: $cookie.get('Authorization')}"
      :on-remove="handleRemove"
      :on-success="handleUploadSuccess"
      :before-remove="beforeRemove"
      :file-list="fileList"
      multiple>
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
  </div>
</template>
 
<script>
  export default {
    data () {
      return {
        resourcesUrl: process.env.VUE_APP_RESOURCES_URL
      }
    },
    props: {
      value: {
        default: '',
        type: String
      }
    },
    computed: {
      fileList () {
        let res = []
        if (this.value) {
          let fileArray = this.value.split(',')
          for (let i = 0; i < fileArray.length; i++) {
            res.push({name: fileArray[i], url: this.resourcesUrl + fileArray[i], response: fileArray[i]})
          }
        }
        this.$emit('input', this.value)
        return res
      }
    },
    methods: {
      // 图片上传
      handleUploadSuccess (response, file, fileList) {
        let files = fileList.map(file => {
          return file.response
        }).join(',')
        this.$emit('change', files)
      },
      // 限制图片上传大小
      beforeAvatarUpload (file) {
        const isLt2M = file.size / 1024 / 1024 < 2
        if (!isLt2M) {
          this.$message.error('上传图片大小不能超过 2MB!')
        }
        return isLt2M
      },
      handleRemove (file, fileList) {
        let files = fileList.map(file => {
          return file.response
        }).join(',')
        this.$emit('change', files)
      },
      beforeRemove (file, fileList) {
        return this.$confirm(`确定移除 ${file.name}?`)
      }
    }
  }
</script>
 
<style lang="scss">
</style>