最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue項(xiàng)目中實(shí)現(xiàn)圖片預(yù)覽的公用組件功能

 更新時(shí)間:2018年10月26日 16:40:57   作者:空一座舊城,守一個(gè)舊人  
小編接到查看影像的功能需求,根據(jù)需求,多個(gè)組件需要用到查看影像的功能,所以考慮做一個(gè)公用組件,通過(guò)組件傳值的方法將查看影像文件的入?yún)鬟^(guò)去。下面小編通過(guò)實(shí)例代碼給大家分享vue項(xiàng)目中實(shí)現(xiàn)圖片預(yù)覽的公用組件功能,需要的朋友參考下吧

今天產(chǎn)品提出了一個(gè)查看影像的功能需求。

在查看單據(jù)的列表中,有一列是影像字段,一開(kāi)始根據(jù)單據(jù)號(hào)調(diào)用接口查看是否有圖片附件,如果有則彈出一個(gè)全屏的彈出層,如果沒(méi)有給出提示。而且,從列表進(jìn)入詳情之后,附件那邊也會(huì)有一個(gè)查看影像的按鈕。

所以,根據(jù)需求,多個(gè)組件需要用到查看影像的功能,所以考慮做一個(gè)公用組件,通過(guò)組件傳值的方法將查看影像文件的入?yún)鬟^(guò)去。

后來(lái),產(chǎn)品要求圖片可以旋轉(zhuǎn)縮放。

廢話不多說(shuō),貼上代碼:

<template>
  <div class="filePreview">
    <el-dialog 
    class="imgList" 
    title="預(yù)覽圖片列表" 
    :visible.sync="imgListShow"
    @close="$emit('remove')" 
    fullscreen>
      <div class="allImg">
        <div style="width:200px;height:100%;margin-top:50px;overflow-y: auto;margin: 0 auto;">
          <img v-for="(item,index) in imgList" :key="item.fileid" :src='item.furl' :class="{ changeColor:changeColor == index}" @click="handlerImg(item,index)">
        </div>
      </div>
      <div style="width:70%;float:left">
      <el-pagination
        style="margin-bottom:20px;"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange1"
        :current-page.sync="currentImg"
        :page-size="1"
        layout="prev, pager, next, jumper"
        :total="num">
      </el-pagination>
      <div style="width:50%;text-align:center;margin:20px 0">
        <button @click="rotateL" icon="el-icon-arrow-left">
          <i class="el-icon-arrow-left"></i>左旋轉(zhuǎn)
        </button>
        <button @click="rotateR">右旋轉(zhuǎn)
          <i class="el-icon-arrow-right"></i>
        </button>
        <button @click="scale">
          <i class="el-icon-zoom-out"></i>縮小
        </button>
        <button @click="scale1">放大
          <i class="el-icon-zoom-in"></i>
        </button>
      </div>
      <div id="test_3" @mousemove="move" @mouseup="stop">
        <p @mousedown="start" >
          <img :src="furl" ref="singleImg" class="originStyle">
        </p>
      </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {isgetFilePath}from 'api/public_api.js'
  export default {
    data() {
      return {
        imgList:[],
        imgListShow:false,
        num:0,
        furl:'',
        currentImg:1,
        changeColor:-1,
        currentRotate: 0 ,
        currentScale:1,
        canDrag: false,
        offset_x:0,
        offset_y:0,
        mouse_x:0,
        mouse_y:0,
      }
    },
    props:['filePreviewShow','FDJH'],
    created() {
      this.imgListShow = this.filePreviewShow
      this.preview()
    },
    methods: {
      //點(diǎn)擊圖片顯示
      handlerImg(obj,index){
        this.currentRotate = 0
        this.currentScale = 1
        this.rotateScale()
        this.$refs.singleImg.style.left = 0
        this.$refs.singleImg.style.top = 0
        this.furl = obj.furl
        this.changeColor = index
        this.currentImg = index+1
      },
      //影像
      preview(){
        let data = {
          // FDJH:'000002'
          FDJH:this.FDJH
        }
        isgetFilePath(data).then(res=>{
          // console.log(res)
          if(res.TYPE == "S"){
            this.imgList = JSON.parse(res.MESSAGE)
            this.num = this.imgList.length
            if(this.imgList.length > 0){
              this.furl = this.imgList[0].furl
              this.changeColor = 0
            }else{
              this.$message.warning('影像文件為空')
            } 
          }else{
            this.$message.warning(res.MESSAGE)
          }
        })
      },
      handleSizeChange(val) {
        console.log(`每頁(yè) ${val} 條`);
      },
      handleCurrentChange1(val) {
        this.currentRotate = 0
        this.currentScale = 1
        this.rotateScale()
        this.$refs.singleImg.style.left = 0
        this.$refs.singleImg.style.top = 0
        this.furl = this.imgList[val-1].furl
        this.changeColor = val-1
      },
      start(e){
        //鼠標(biāo)左鍵點(diǎn)擊
        e.preventDefault && e.preventDefault(); //去掉圖片拖動(dòng)響應(yīng)
        if(e.button==0){
          this.canDrag=true;
          //獲取需要拖動(dòng)節(jié)點(diǎn)的坐標(biāo)
          this.offset_x = document.getElementsByClassName('originStyle')[0].offsetLeft;//x坐標(biāo)
          this.offset_y = document.getElementsByClassName('originStyle')[0].offsetTop;//y坐標(biāo)
          //獲取當(dāng)前鼠標(biāo)的坐標(biāo)
          this.mouse_x = e.pageX;
          this.mouse_y = e.pageY;
        }
      },
      move(e){
        e.preventDefault && e.preventDefault()
        if(this.canDrag==true){
          let _x = e.pageX - this.mouse_x;
          let _y = e.pageY - this.mouse_y;
          //設(shè)置移動(dòng)后的元素坐標(biāo)
          let now_x = (this.offset_x + _x ) + "px";
          let now_y = (this.offset_y + _y ) + "px";
          document.getElementsByClassName('originStyle')[0].style.top = now_y
          document.getElementsByClassName('originStyle')[0].style.left = now_x
        }
      },
      stop(e){
        this.canDrag = false;
      },
      //旋轉(zhuǎn)放大
      rotateScale(){
        this.$refs.singleImg.style.OTransform = 'rotate('+this.currentRotate+'deg)'+'scale('+this.currentScale+')'
        this.$refs.singleImg.style.webkitTransform = 'rotate('+this.currentRotate+'deg)'+'scale('+this.currentScale+')'
        this.$refs.singleImg.style.MozTransform = 'rotate('+this.currentRotate+'deg)'+'scale('+this.currentScale+')'
        this.$refs.singleImg.style.msTransform = 'rotate('+this.currentRotate+'deg)'+'scale('+this.currentScale+')'
        this.$refs.singleImg.style.transform = 'rotate('+this.currentRotate+'deg)'+'scale('+this.currentScale+')'
      },
      //旋轉(zhuǎn)
      rotateL(){
        this.currentRotate += 15
        this.rotateScale()
      },
      rotateR(){
        this.currentRotate -= 15
        this.rotateScale()
      },
      //縮放
      scale(){
        this.currentScale -= 0.1
        if(this.currentScale <= 0.1){
          this.currentScale = 0.1
          this.rotateScale()
        }else{
          this.rotateScale()
        }
      },
      scale1(){
        this.currentScale += 0.1
        this.rotateScale()
      },
    }
  }
</script>
<style rel="stylesheet/scss" lang="scss" slot-scope="scope">
  .filePreview{
    .imgList{
      .el-dialog__headerbtn{
        font-size:26px;
      }
      .el-dialog__body{
        .allImg{
          width:30%;
          float:left;
          height:600px;
          img{
            width: 150px;
            height: 150px;
            margin: 5px;
            cursor: pointer;
          }
          .changeColor{
            border:4px solid #409eff;
          }
        }
      }
    }
    .originStyle{
      position:absolute;
      left:0;top:0;
      cursor: pointer;
      // transform-origin: 50% 50%;
    }
    #test_3{
      position: relative;
      width: 600px;
      height: 400px;
      overflow: hidden;
      // overflow: scroll;
      & > p{
        position: absolute;
        cursor: move;
        transform-origin: center;
        width: 100%;
        height: 100%;
        padding: 0;
        -webkit-margin-before: 0;
        -webkit-margin-after: 0;
        left: 0;
        top: 0;
        & > img{
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
  }
</style>

后來(lái)出現(xiàn)一個(gè)問(wèn)題,有一類的單據(jù)的圖片存儲(chǔ)在數(shù)據(jù)庫(kù)中,之前的圖片都是存儲(chǔ)在服務(wù)器中,只需要傳入單據(jù)號(hào)查詢返回給我圖片路徑即可。

而存儲(chǔ)在數(shù)據(jù)庫(kù)當(dāng)中不一樣,需要拼接路徑,一下是解決方法:

preview(){

    if(this.imgList.length > 0){
      this.imgList.map(item=>{
        item.furl = process.env.APP_EXCEL_PATH+'portal/gys/querydownloadPurchaFile?fileid='+ item.FILEID +'&gysdh='+item.CREATENAME //接口加入?yún)?
      })
    }
    this.num = this.imgList.length
    this.furl = this.imgList[0].furl
    this.changeColor = 0
},

一般情況下,圖片的預(yù)覽,圖片存儲(chǔ)在服務(wù)器中,數(shù)據(jù)庫(kù)中一般只存儲(chǔ)路徑。

總結(jié)

以上所述是小編給大家介紹的vue項(xiàng)目中實(shí)現(xiàn)圖片預(yù)覽的公用組件功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • vue項(xiàng)目 npm run build 打包項(xiàng)目防止瀏覽器緩存的操作方法

    vue項(xiàng)目 npm run build 打包項(xiàng)目防止瀏覽器緩存的操作方法

    這篇文章主要介紹了vue項(xiàng)目 npm run build 打包項(xiàng)目防止瀏覽器緩存的操作方法,本文給大家推薦兩種方法,每種方法通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • vue使用Print.js打印頁(yè)面樣式不出現(xiàn)的解決

    vue使用Print.js打印頁(yè)面樣式不出現(xiàn)的解決

    這篇文章主要介紹了vue使用Print.js打印頁(yè)面樣式不出現(xiàn)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue傳值的編碼和解碼方式

    vue傳值的編碼和解碼方式

    這篇文章主要介紹了vue傳值的編碼和解碼方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 詳解使用element-ui table組件的篩選功能的一個(gè)小坑

    詳解使用element-ui table組件的篩選功能的一個(gè)小坑

    在element ui 框架中,對(duì)于table框架,有一個(gè)篩選功能,這篇文章主要介紹了詳解使用element-ui table組件的篩選功能的一個(gè)小坑,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2018-11-11
  • vue一步步實(shí)現(xiàn)alert功能

    vue一步步實(shí)現(xiàn)alert功能

    本篇文章主要介紹了vue一步步實(shí)現(xiàn)alert功能,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • Vue中props的使用詳解

    Vue中props的使用詳解

    props屬性是父子組件之間的通信橋梁。這篇文章主要介紹了Vue中props的使用,需要的朋友可以參考下
    2018-06-06
  • vue?鼠標(biāo)移入移出(hover)切換顯示圖片問(wèn)題

    vue?鼠標(biāo)移入移出(hover)切換顯示圖片問(wèn)題

    這篇文章主要介紹了vue?鼠標(biāo)移入移出(hover)切換顯示圖片問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue實(shí)現(xiàn)axios圖片上傳功能

    vue實(shí)現(xiàn)axios圖片上傳功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)axios圖片上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Vue中直接操作數(shù)組索引不奏效的問(wèn)題解讀

    Vue中直接操作數(shù)組索引不奏效的問(wèn)題解讀

    這篇文章主要介紹了Vue中直接操作數(shù)組索引不奏效的問(wèn)題解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 在vue中利用v-html按分號(hào)將文本換行的例子

    在vue中利用v-html按分號(hào)將文本換行的例子

    今天小編就為大家分享一篇在vue中利用v-html按分號(hào)將文本換行的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-11-11

最新評(píng)論

饶河县| 高安市| 桃园市| 侯马市| 双鸭山市| 板桥市| 七台河市| 东港市| 株洲县| 永宁县| 伊通| 山丹县| 龙泉市| 阿拉善盟| 阳东县| 阜阳市| 桦川县| 鹿泉市| 麻栗坡县| 古丈县| 鹤壁市| 若尔盖县| 上林县| 丰城市| 青阳县| 怀远县| 家居| 苍梧县| 伊川县| 大理市| 康乐县| 大同市| 惠水县| 普宁市| 福建省| 罗江县| 广安市| 安塞县| 广州市| 隆回县| 乡宁县|