doum
4 天以前 bcad3fe1b888ae11d437f6558b7974cfa30cfb2e
admin/src/components/common/UploadImage.vue
@@ -33,15 +33,15 @@
        </span>
      </div>
    </el-upload>
    <el-image-viewer
      v-if="showViewer"
    <el-image-viewer
      v-if="showViewer"
      :on-close="closeViewer"
      :initialIndex="tempIndex"
      :url-list="srcList"
      :z-index="3000"
    />
  </div>
</template>
<script>
@@ -55,12 +55,15 @@
      type: Array,
      default: () => []
    },
    maxNum: {
      type: Number,
      default: () => null
    },
    uploadData: Object,
  },
  data() {
    return {
      uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/public/uploadPicture',
      realList: [],
      srcList: [],
      tempIndex: 0,
@@ -70,28 +73,34 @@
  watch: {
    fileList: {
      handler(val) {
        console.log(val);
        console.log("===================",val);
        if (val.length==0) {
          this.realList = []
          this.srcList = []
        }else{
          this.realList=val
          val.forEach(item =>{
            this.srcList.push(item.url)
          })
        }
        console.log("==================srcList=",this.srcList);
      }
    }
  },
  methods: {
    beforeUpload(file) {
      this.$emit('beginUpload')
      return true
    },
     // 上传图片成功
     uploadSuccess (res, file, fileList) {
      // console.log('this.fileList', this.fileList);
     uploadSuccess (res, file, fileList) {
      console.log('this.fileList', this.fileList);
      // console.log('fileList', fileList);
      this.$emit('endUpload')
      this.realList = fileList
      this.srcList.push(res.data.url)
      // this.realList = fileList
      // this.srcList.push(res.data.url)
      // console.log('file', file);
      if (res.code === 200) {
        this.fileList.push(
@@ -110,7 +119,7 @@
      this.$message.error('上传失败')
    },
    handlePictureCardPreview(file) {
      this.tempIndex = this.srcList.findIndex(item => item == file.response.data.url )
      this.tempIndex = this.srcList.findIndex(item => item == file.url )
      this.showViewer = true
    },
    closeViewer() {
@@ -118,12 +127,12 @@
    },
    handleRemove(file) {
      console.log(this.fileList);
      let tempIndex = this.realList.findIndex(item => item.fileurl === file.response.data.imgaddr)
      let tempIndex = this.realList.findIndex(item => item.fileurl === file.fileurl)
      // debugger
      this.realList.splice(tempIndex, 1)
      this.fileList.splice(tempIndex, 1)
      this.srcList.splice(tempIndex, 1)
    },
  },
}