k94314517
2025-06-25 f6722e13ba28cd292c162df9292bb3418ba12bec
company/src/components/common/UploadFile.vue
@@ -5,14 +5,14 @@
      class="upload-demo"
      :accept="uploadData.fileType"
      :action="uploadImgUrl"
      :limit="1"
      :limit="limit"
      :before-remove="removes"
      :on-exceed="handleExceed"
      :on-success="handleFileSuccess"
      :on-error="uploadError"
      :before-upload="beforeFileUpload"
      :file-list="fileList">
    <el-button size="small" type="primary"  >点击上传</el-button>
    <el-button  size="small" type="primary"  >点击上传</el-button>
    <div style="display: inline-block;position: absolute"  slot="tip" class="el-upload__tip" v-if="showTips">{{'(只能上传'+uploadData.fileType +'文件,且不超过5mb)'}}</div>
  </el-upload>
  </div>
@@ -42,10 +42,15 @@
      type: String,
      default: 'width: 190px; height: 190px;'
    },
    uploadData: Object
    uploadData: Object,
    limit: {
      type: Number,
      default: () => 1
    }
  },
  data() {
    return {
      uploaded:false,
      // fileList:[],
      uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/public/upload?folder='+this.uploadData.folder
    }
@@ -54,6 +59,11 @@
    fileList (nv,ov) {
      if(this.fileList ==null){
        this.fileList = new Array();
      }
      if(this.fileList.length == 0){
        this.uploaded = false
      }else{
        this.uploaded=true
      }
     // alert(this.fileList)
    },
@@ -64,8 +74,10 @@
    }
  },
  methods: {
    removes() {
      this.$emit('remove')
    removes(e) {
      this.uploaded=false
      console.log(e.imgaddr)
      this.$emit('remove', e.imgaddr)
    },
    // 上传图片
    handleExceed(){
@@ -74,6 +86,7 @@
    handleFileSuccess(res, file) {
      if (res.code == 200) {
        let { data } = res
        this.uploaded = true
        // this.fileList = [{name: data.originname, url: data.url }]
        this.$message.success('上传成功')
        this.$emit('uploadSuccess', { fileurl: data.imgaddr,  fileurlFull: data.url, name: data.originname ,index:this.fileIndex})