Esign.vue 1.52 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
<template>
  <div style="border: 1px solid #cccccc">
    <div v-if="resultImg == ''">
      <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>
    <div>
      <img v-if="resultImg" :src="resultImg" alt="" />
    </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:""
      }
    },
    data () {
      return {
        lineWidth: 3,
        lineColor: '#000000',
        bgColor: '',
        isCrop: false,
      }
    },
    methods: {
      handleReset () {
        this.$refs['esign'].reset() //清空画布
      },
      handleGenerate () {
        this.$refs['esign'].generate().then(res => {
            this.$emit('update:resultImg',res);
            this.$emit('aaa');
            //this.resultImg = res // 得到了签字生成的base64图片
        }).catch(err => { //  没有签名,点击生成图片时调用
            this.$message({
              message: err + ' 未签名!',
              type: 'warning'
            })
        })
      }
    }
  }
</script>

<style scoped>

</style>