Files
2026-09-08 19:49:21 +08:00

81 lines
1.9 KiB
Vue

<template>
<div id="canvas" style="position: relative;border: 1px dashed #d5d2d2;width: 100%">
<van-button plain type="danger" hairline size="small" class="clearBtn" @click="reset">清空重签</van-button>
</div>
</template>
<script>
module.exports = {
props: {
my_sign: {
type: String
}
},
watch: {
// 编辑申请异步回填签字数据后,自动将签字图片导入当前画布。
my_sign(value) {
if (value) {
this.importSign(value)
}
}
},
methods: {
// 将已有签字图片导入 jSignature 画布,供编辑页面继续查看或修改。
importSign(sign) {
if (sign && $('#canvas').jSignature) {
$('#canvas').jSignature('importData', sign)
}
},
reset() {
$('#canvas').jSignature('reset')
this.$emit("update:my_sign", null)
},
checkNull() {
return $('#canvas').jSignature('getData', 'native').length === 0
},
submitSign() {
this.$emit("update:my_sign", $('#canvas').jSignature('getData'))
},
async updateSign() {
const data = await $.post("/mobile/common/signing/update", {sign: $('#canvas').jSignature('getData')})
},
async getMySign() {
const data = await $.get("/mobile/common/signing/getMySign")
// 已有申请签字时优先保留申请本身的签字,避免默认签字覆盖编辑内容。
if (data && !this.my_sign) {
this.importSign(data)
this.$nextTick(() => {
})
}
}
},
created() {
// this.getMySign()
},
async mounted() {
$("#canvas").jSignature({
width: '100%',
height: 300,
"decor-color": "transparent",
lineWidth: '3'
});
if (this.my_sign) {
this.importSign(this.my_sign)
}
}
}
</script>
<style>
.clearBtn {
position: absolute !important;
bottom: 5px;
right: 5px;
color: red;
z-index: 99;
}
</style>