国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

el-upload上傳圖片和視頻,支持預(yù)覽和刪除

這篇具有很好參考價(jià)值的文章主要介紹了el-upload上傳圖片和視頻,支持預(yù)覽和刪除。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

話不多說(shuō), 直接上代碼:

視圖層:

        <div class="contentDetail">
          <div class="contentItem">
            <div style="margin-top:5px;" class="label csAttachment">客服上傳圖片:</div>
            <el-upload
              :auto-upload="false"
              :limit="10"
              :on-change="fileChange"
              :on-remove="handleRemoveImg"
              :file-list="csImages"
              action="#"
              accept=".jpg,.jpeg,.png"
              list-type="picture-card"
            >
              <i slot="default" class="el-icon-plus"></i>
              <div slot="file" slot-scope="{ file }">
                <img :src="file.url" class="el-upload-list__item-thumbnail" alt="" />
                <div class="el-upload-list__item-actions">
                  <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                    <i class="el-icon-zoom-in"></i>
                  </span>
                  <span class="el-upload-list__item-delete" @click="handleRemoveImg(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </div>
              </div>
            </el-upload>
          </div>
        </div>
        <div class="contentDetail">
          <div class="contentItem">
            <div class="label csAttachment">客服上傳視頻:</div>
            <el-upload
              :auto-upload="false"
              :limit="3"
              :on-change="changeUploadVideo"
              :file-list="csVideos"
              class="avatar-uploader"
              action="#"
              list-type="picture-card"
            >
              <i slot="default" class="el-icon-plus"></i>
              <div slot="file" slot-scope="{ file }">
                <video
                  :src="file.url"
                  :style="{
                    width: csVideos.length > 0 ? '200px' : 0,
                    height: csVideos.length > 0 ? '120px' : 0
                  }"
                  class="video-avatar"
                  controls="controls"
                >
                  <span>您的瀏覽器不支持視頻播放</span>
                </video>
                <div class="el-upload-list__item-actions" style="z-index:101;height:50px;">
                  <span class="el-upload-list__item-delete" @click="handleRemoveVideo(file)">
                    <i class="el-icon-delete"></i>
                  </span>
                </div>
              </div>
            </el-upload>
          </div>
        </div>

邏輯層:

// 監(jiān)聽附件相關(guān)數(shù)據(jù) 
watch: {
    // 新增圖片
    fileList: {
      async handler(newList) {
        this.fileData.imgFiles = []
        if (newList.length) {
          let fileObj = {}
          await newList.map(file => {
            // 上傳的文件流轉(zhuǎn)為base64格式
            if (file.raw) {
              getBase64File(file.raw).then(res => {
                fileObj = {
                  fileName: file.name,
                  fileBase64: res
                }
                this.fileData.imgFiles.push(fileObj)
              })
            } else {
              fileObj = {
                fileBase64: file.fileBase64,
                fileName: file.name,
                type: file.type
              }
              this.fileData.imgFiles.push(fileObj)
            }
          })
        }
      }
    },
    // 刪除已上傳圖片時(shí)
    newImgList: {
      handler: function(list) {
        let obj = {
          fileBase64: '',
          fileName: '',
          type: ''
        }
        list.map(file => {
          obj = {
            fileBase64: file.fileBase64,
            fileName: file.name,
            type: file.type
          }
        })
        this.fileData.imgFiles.push(obj)
      }
    },
    
   //添加視頻
    videoList: {
      async handler(newList) {
        this.fileData.videoFiles = []
        if (newList.length) {
          let fileObj = {}
          await newList.map(file => {
            // 上傳的文件流轉(zhuǎn)為base64格式
            if (file.raw) {
              getBase64File(file.raw).then(res => {
                fileObj = {
                  fileName: file.name,
                  fileBase64: res
                }
                this.fileData.videoFiles.push(fileObj)
              })
            } else {
              fileObj = {
                fileBase64: file.fileBase64,
                fileName: file.name,
                type: file.type
              }
              this.fileData.videoFiles.push(fileObj)
            }
          })
        }
      }
    },
    // 刪除已上傳視頻時(shí)
    newVideoList: {
      handler: function(list) {
        let obj = {
          fileBase64: '',
          fileName: '',
          type: ''
        }
        list.map(file => {
          obj = {
            fileBase64: file.fileBase64,
            fileName: file.name,
            type: file.type
          }
        })
        this.fileData.videoFiles.push(obj)
      }
    }
  },  

 
// 添加圖片文件
    fileChange(file, fileList) {
      this.fileList = fileList
      this.fileList.map((item, index) => {
        const fileSize = item.size / 1024 / 1024
        if (fileSize > 20) {
          this.$message.error('單個(gè)附件大小不能超過(guò)20M')
          this.fileList.splice(index, 1)
        }
      })

      setTimeout(() => {
        this.editFile('image')
      }, 1000)
    },

 // 添加視頻文件
    changeUploadVideo(file, fileList) {
      const fileSize = file.size / 1024 / 1024 <= 50
      if (
        ['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb', 'video/mov'].indexOf(
          file.raw.type
        ) == -1 // 控制格式
      ) {
        this.$message.error('請(qǐng)上傳正確的視頻格式')
        return false
      }
      if (!fileSize) {
        this.$message.error('視頻大小不能超過(guò)50MB')
        return false
      }
      this.videoList = fileList

      setTimeout(() => {
        this.editFile('video')
      }, 1000)
    },

    // 移除圖片文件
    handleRemoveImg(file) {
      this.fileList.map((item, index) => {
        if (item.name === file.name) {
          // 回顯圖片時(shí)
          if (item.type === 2) {
            item.type = 1 // 2 保留 1 刪除
            this.newImgList = this.fileList.splice(index, 1)
            setTimeout(() => {
              this.editFile('image')
            }, 500)
          } else {
            // 新增圖片時(shí)
            this.fileList.splice(index, 1)
          }
        }
      })
    },

    // 移除視頻文件
    handleRemoveVideo(file) {
      this.videoList.map((item, index) => {
        if (item.name === file.name) {
          // 回顯視頻時(shí)
          if (item.type === 2) {
            item.type = 1 // 2 保留 1 刪除
            this.newVideoList = this.videoList.splice(index, 1)
            setTimeout(() => {
              this.editFile('video')
            }, 500)
          } else {
            // 新增視頻時(shí)
            this.videoList.splice(index, 1)
          }
        }
      })
    },

    // 預(yù)覽圖片
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.$alert(`<img src="${this.dialogImageUrl}" width="100%">`, {
        dangerouslyUseHTMLString: true,
        callback: () => {}
      })
    },


    // 編輯附件
    editFile(type) {
      const params = {
        imgFiles: this.fileData.imgFiles,
        videoFiles: this.fileData.videoFiles,
        csClass: this.summaryDetail.csClassIds[this.summaryDetail.csClassIds.length - 1],
        csFeedbackDescribe: this.summaryDetail.csFeedbackDescribe,
        id: this.summaryDetail.id,
        role: 1,
        appPhone: this.summaryDetail.appPhone,
        sn: this.summaryDetail.sn,
        qrCode: this.summaryDetail.qrCode,
        iscallBack: 1 // 是否編輯回電  1否 2是
      }
      this.$confirm('確認(rèn)修改?', '提示', {
        confirmButtonText: '確定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = true
          addSummary(params) // 后端接口
            .then(res => {
              if (res.code === 0) {
                this.getSummaryList(this.activeName)
                this.$message.success(res.msg)
              }
            })
            .catch(() => {
              this.loading = false
              // 添加修改失敗,恢復(fù)原有數(shù)據(jù)
              if (type === 'image') {
                this.csImages = handleFileFormat(this.summaryDetail.csImgFiles)
              } else {
                this.csVideos = handleFileFormat(this.summaryDetail.csVideoFiles)
              }
            })
        })
        .catch(() => {
          // 取消添加修改,恢復(fù)原有數(shù)據(jù)
          if (type === 'image') {
            this.csImages = handleFileFormat(this.summaryDetail.csImgFiles)
          } else {
            this.csVideos = handleFileFormat(this.summaryDetail.csVideoFiles)
          }
        })
    }

上傳附件沒(méi)有使用單獨(dú)的上傳接口,是調(diào)用添加記錄接口時(shí),統(tǒng)一傳參保存。添加接口請(qǐng)求成功后再回顯。

因?yàn)槲覀兊男枨笫窃谠斍轫?yè)面也能編輯圖片和視頻,所以加了`type`字段,1代表刪除,2代表保留,添加的話就不傳。如果你們的需求沒(méi)有在詳情編輯的功能,相關(guān)的邏輯可以不用管。

添加失敗或取消添加時(shí),恢復(fù)原有數(shù)據(jù)。

視頻的時(shí)候需要注意:video標(biāo)簽的層級(jí)比較高,鼠標(biāo)hover時(shí)上面的刪除圖標(biāo)顯示不出來(lái),手動(dòng)修改它們的`z-index`,比如:

el-upload上傳圖片和視頻,支持預(yù)覽和刪除,音視頻

?el-upload上傳圖片和視頻,支持預(yù)覽和刪除,音視頻

?刪除圖標(biāo)的容器寬度也修改下,否則會(huì)覆蓋視頻播放按鈕。

樣式設(shè)置:

/deep/ .el-upload--picture-card {
    width: 80px;
    height: 80px;
  }
  /deep/ .el-upload-list__item {
    width: 80px;
    height: 80px;
  }
  .avatar-uploader {
    /deep/ .el-upload--picture-card {
      display: inline-block;
      width: 200px;
      height: 120px;
    }
    /deep/ .el-upload-list__item {
      display: inline-block;
      width: 200px;
      height: 120px;
    }
  }
  video {
    display: inline-block;
    position: relative;
    z-index: 100;
  }

  /deep/ .el-icon-plus {
    position: relative;
    top: -35%;
  }
  .avatar-uploader {
    /deep/ .el-icon-plus {
      position: relative;
      top: -6%;
    }
  }

上傳前:?

el-upload上傳圖片和視頻,支持預(yù)覽和刪除,音視頻

?上傳后:

el-upload上傳圖片和視頻,支持預(yù)覽和刪除,音視頻

?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-612445.html

到了這里,關(guān)于el-upload上傳圖片和視頻,支持預(yù)覽和刪除的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 上傳圖片到騰訊云對(duì)象存儲(chǔ)桶cos 【騰訊云對(duì)象存儲(chǔ)桶】【cos】【el-upload】【vue3】【上傳頭像】【刪除】

    上傳圖片到騰訊云對(duì)象存儲(chǔ)桶cos 【騰訊云對(duì)象存儲(chǔ)桶】【cos】【el-upload】【vue3】【上傳頭像】【刪除】

    1、首先登錄騰訊云官網(wǎng)控制臺(tái) 進(jìn)入對(duì)象存儲(chǔ)頁(yè)面 2、找到跨越訪問(wèn)CIRS設(shè)置 配置規(guī)則 ?點(diǎn)擊添加規(guī)則 ?填寫信息 ?3、書寫代碼 這里用VUE3書寫 第一種用按鈕出發(fā)事件形式 4、測(cè)試 點(diǎn)擊選擇文件 選擇圖片? 等待結(jié)果 ? 第二種用el-upload 也可以把el-upload嵌套button包裝成這種形式

    2024年02月15日
    瀏覽(89)
  • vue element el-upload附件上傳、在線預(yù)覽、下載當(dāng)前預(yù)覽文件

    vue element el-upload附件上傳、在線預(yù)覽、下載當(dāng)前預(yù)覽文件

    上傳 在線預(yù)覽(iframe): payload: response: 全部代碼: 初版–01

    2024年02月14日
    瀏覽(37)
  • vue el-upload實(shí)現(xiàn)圖片和文字上傳

    vue el-upload實(shí)現(xiàn)圖片和文字上傳

    一、需求: 在表單中使用圖片上傳,每一張上傳的圖片都可以加上文字說(shuō)明通過(guò)表單一起傳到后臺(tái),最后再其他需要的地方展示出來(lái)。 ?二、實(shí)現(xiàn): 后端表單提交時(shí),圖片需要的格式是:imageList[ {?fileUrl:\\\' \\\',?imageExplain:\\\' \\\'?} ] 界面代碼 v-model=\\\"form.imageUrl\\\" :action=\\\"fileUrl\\\" 調(diào)用接

    2024年02月10日
    瀏覽(105)
  • el-upload上傳圖片到七牛云或阿里云

    (1)綁定上傳地址,上傳數(shù)據(jù)對(duì)象 (2)定義數(shù)據(jù) (3)定義方法 ????????圖片的路徑就是圖片頭加上返回的key

    2024年02月10日
    瀏覽(96)
  • vue 2.0+element ui 使用el-upload圖片上傳

    vue 2.0+element ui 使用el-upload圖片上傳

    ** ** 使用el-upload將圖片加載成Base64格式,通過(guò)form統(tǒng)一上傳給后端 1、創(chuàng)建通用component ImgComponent.vue 2、在父組件中使用 3、最后通過(guò)form統(tǒng)一submit到后端,圖片參數(shù)傳base64即可。 ps:起初在數(shù)據(jù)庫(kù)中,將存圖片的字段類型設(shè)置為BLOB,以二進(jìn)制的形勢(shì)存儲(chǔ),后面發(fā)現(xiàn)會(huì)將“:”轉(zhuǎn)

    2024年02月12日
    瀏覽(97)
  • element UI el-upload組件實(shí)現(xiàn)視頻文件上傳視頻回顯

    element UI el-upload組件實(shí)現(xiàn)視頻文件上傳視頻回顯

    項(xiàng)目中需要提供一個(gè)視頻介紹,使用Vue+Element UI中的el-upload組件實(shí)現(xiàn)視頻上傳及進(jìn)度條展示,后臺(tái)提供視頻上傳API并返回URL,?百度找了一番后最終實(shí)現(xiàn)了。 HTML JS data css 成功后的截圖 ?

    2024年02月06日
    瀏覽(111)
  • vue pc端項(xiàng)目el-upload上傳圖片時(shí)加水印

    html代碼: 畫布這時(shí)就需要在beforeUploadHandle這個(gè)方法中去生成水印,然后通過(guò)后端上傳接口,把圖片傳給后端,然后再接收后端返回的數(shù)據(jù) 下面是beforeUploadHandle方法

    2024年02月13日
    瀏覽(91)
  • elementUI+el-upload 上傳、下載、刪除文件以及文件展示列表自定義為表格展示

    elementUI+el-upload 上傳、下載、刪除文件以及文件展示列表自定義為表格展示

    官方文檔 https://element.eleme.cn/#/zh-CN/component/upload 具體參數(shù)說(shuō)明,如何實(shí)現(xiàn)上傳、下載、刪除等功能 action :文件上傳地址,我的項(xiàng)目里已經(jīng)封裝好了請(qǐng)求。使用的時(shí)候需要依據(jù)項(xiàng)目填寫。 show-file-list : 是否顯示已上傳文件列表。 headers :設(shè)置上傳的請(qǐng)求頭部。我的項(xiàng)目需要傳

    2024年01月20日
    瀏覽(102)
  • Vue中使用的el-upload時(shí)批量上傳圖片時(shí)報(bào)錯(cuò)問(wèn)題處理

    Vue中使用的el-upload時(shí)批量上傳圖片時(shí)報(bào)錯(cuò)問(wèn)題處理

    項(xiàng)目場(chǎng)景:項(xiàng)目中有一個(gè)文件上傳的場(chǎng)景,使用el-upload組件進(jìn)行上傳,單圖上傳是正常,但是在進(jìn)行批量上傳時(shí)報(bào)了錯(cuò)。 使用el-upload在進(jìn)行多圖批量上傳時(shí)系統(tǒng)提示報(bào)錯(cuò)。 報(bào)錯(cuò)提示: Uncaught TypeError: Cannot set properties of null (setting \\\'status\\\') ? ? at VueComponent.handleProgress (element-ui

    2024年02月06日
    瀏覽(379)
  • el-upload使用http-request實(shí)現(xiàn)圖片上傳,回顯,放大效果

    el-upload使用http-request實(shí)現(xiàn)圖片上傳,回顯,放大效果

    ????????在項(xiàng)目開發(fā)中,為了實(shí)現(xiàn)上傳文件的功能,我們需要用到el-upload這個(gè)組件,為了實(shí)現(xiàn)回顯放大效果,就要用到el-image這個(gè)組件了。官方文檔中介紹了上傳的兩種方法,一個(gè)是使用action,其參數(shù)必須要上傳的地址;另一個(gè)是http-request,該方法覆蓋默認(rèn)的上傳行為,可

    2024年02月08日
    瀏覽(105)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包