NewEsign.vue 2.15 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
<template>
  <div>
    <input class="editInput" placeholder="请签名" v-if="resultImg == '' || resultImg == null" @click="signOpen =true"/>
    <el-dialog title="签名" :visible.sync="signOpen" :close-on-click-modal="false" :z-index="2000">
      <div style="border: 1px solid #cccccc">
        <vue-esign ref="esign" :width="width" :height="height" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" />
        <div style="text-align: right">
          <button @click="handleReset" style="margin-right: 2px">清空</button>
          <button @click="handleGenerate">确定</button>
        </div>
      </div>
    </el-dialog>
    <div>
      <img v-if="resultImg" :src="resultImg" alt="" style="width: 100%;height: 100%" @click="reWriteSign"/>
    </div>
  </div>
</template>

<script>
  import vueEsign from 'vue-esign'
  export default {
    name: "esign",
    components:{
      vueEsign
    },
    props:{
      width:{
        type:Number
      },
      height:{
        type:Number
      },
      resultImg:{
        type:String,
        default:""
      },
      isReWrite:{
        type:Boolean,
        default:true
      }
    },
    data () {
      return {
        lineWidth: 3,
        lineColor: '#000000',
        bgColor: '',
        isCrop: false,
        signOpen:false
      }
    },
    methods: {
      handleReset () {
        this.$refs['esign'].reset() //清空画布
      },
      handleGenerate () {
        this.$refs['esign'].generate().then(res => {
            this.$emit('update:resultImg',res);
            this.signOpen = false;
            //this.resultImg = res // 得到了签字生成的base64图片
        }).catch(err => { //  没有签名,点击生成图片时调用
            this.$message({
              message: err + ' 未签名!',
              type: 'warning'
            })
        })
      },
      //重签
      reWriteSign(){
        if(this.isReWrite){
          this.signOpen = true;
        }
      }

    }
  }
</script>

<style scoped scss="lang">
  .editInput{
    border: none;
    width: 100%;
    height: 100%;
    text-align: center;
  }

  .editInput:focus{
    outline: none;
  }

</style>