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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<template> <div class="showBtn"> <van-button type="primary" @click="show=true">客户确认签名</van-button> </div>
<van-popup v-model:show="show" position="bottom">
<div class="sign"> <div class="text">请客户在虚线区域内签名</div> <div class="signBorder"> <vueEsign ref="esign" v-bind="signConfig" class="signMain" /> </div> <!-- signBorder --> <div class="btns"> <div class="item" @click="handleReset">清空重写</div> <div class="item" @click="handleGenerate">确认提交</div> </div> <!-- btns --> </div>
</van-popup> </template>
<script lang="ts" setup> import { reactive, ref } from "vue"; import vueEsign from "vue-esign"; import { Toast } from "vant"; import {useState} from '@/store/state'; const show = ref<boolean>(false); const State = useState(); const emit = defineEmits(['signImg']);
interface Esign { reset: any | undefined; generate: any | undefined; } const signConfig = reactive({ lineWidth: 6, lineColor: "#000000", bgColor: "#ffffff00",//这里配置的是透明背景色 resultImg: "", isCrop: false, isClearBgColor: false, height:340 }); const esign = ref<Esign>({ reset: undefined, generate: undefined }); const signImg = ref("");
const handleReset = () => { esign.value.reset(); };
const handleGenerate = () => { Toast.loading({ message: "合同生成中,请稍候!", duration: 0, forbidClick: true, }); try { esign.value .generate() .then((res: string) => { signImg.value = res; emit("signImg", res);//将signImg生成的base64图片回传 }) .catch((err: any) => { Toast.fail("请签名!"); }); } catch (error) { Toast.fail("合同生成失败,请重试!"); } }; </script>
<style lang="scss" scoped> .sign { position: fixed; bottom: 0; left: 0; width: 100%; background: white; z-index: 111; box-shadow: 0px -5px 20px rgba($color: #000000, $alpha: 0.15); .signImg { display: block; width: 100%; } .signBorder { border: 2px dotted rgba($color: #000000, $alpha: 0.2); margin: 5px; } .text { color: gray; text-align: center; font-size: 12px; padding: 10px; } .btns { padding: 10px; display: flex; .item { margin: 10px; flex: 1; color: white; border: none; text-align: center; font-size: 14px; padding: 10px; border-radius: 100px; &:nth-child(1) { background: #ff2b2b; } &:nth-child(2) { background: #1c73ff; } &:active { opacity: 0.8; } } } } .showBtn{ position: fixed; bottom: 0; width: 100%; z-index: 11; padding: 10px; background: white; box-shadow: 0px 0px 10px rgba($color: #000000, $alpha: 0.2); text-align: right; button{ width: 100%; position: relative; } } </style>
|