first commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<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>
|
||||
@@ -0,0 +1,175 @@
|
||||
<template>
|
||||
<el-card class="box-card" shadow="never">
|
||||
|
||||
<div class="signature-body" id="signature-body">
|
||||
<el-collapse-transition>
|
||||
<div v-show="showQrCode" class="qr-code-div">
|
||||
<el-link type="primary" :underline="false">{{ scan_title }}</el-link>
|
||||
<QrCode v-if="postAddress" :options="{ width: 126 }" :value="postAddress"></QrCode>
|
||||
</div>
|
||||
</el-collapse-transition>
|
||||
|
||||
<el-image fit="contain" v-show="!showQrCode" v-loading="loading"
|
||||
style="height: 100px;width: 100%" :src="qz">
|
||||
<div slot="error" class="image-slot">
|
||||
<i class="el-icon-picture-outline"></i>
|
||||
</div>
|
||||
</el-image>
|
||||
<el-link type="danger" style="font-size: 12px;margin-top: 20px" @click="refresh();clear()" icon="el-icon-edit"
|
||||
v-show="!showQrCode">重签
|
||||
</el-link>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="text-align: center">
|
||||
<el-link type="primary" style="font-size: 14px;margin-top: 20px;z-index:999" @click="openSign()" icon="el-icon-edit"
|
||||
v-if="showQrCode" :underline="false">打开签字板
|
||||
</el-link>
|
||||
</div>
|
||||
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
window.signatureInterval = null
|
||||
|
||||
module.exports = {
|
||||
name: "Signature",
|
||||
props: {
|
||||
scan_title: {
|
||||
type: String,
|
||||
default: '扫描下方二维码进行签字'
|
||||
},
|
||||
prefix: {
|
||||
type: String,
|
||||
default: 'DEFAULT'
|
||||
},
|
||||
qz: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
model: {
|
||||
prop: 'qz',
|
||||
event: 'change'
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showQrCode: false,
|
||||
loading: true,
|
||||
postAddress: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openSign() {
|
||||
window.open(this.postAddress)
|
||||
},
|
||||
refresh() {
|
||||
this.qz = ''
|
||||
},
|
||||
startRequest() {
|
||||
this.qz = ''
|
||||
clearInterval(signatureInterval)
|
||||
const ts = new Date().getTime()
|
||||
this.postAddress = 'https://zhgh.nsi.edu.cn/signature?prefix=' + this.prefix + '&id=' + ts
|
||||
//this.postAddress = 'https://zhgh.nsi.edu.cn/signature?prefix=' + this.prefix + '&id=' + ts
|
||||
|
||||
this.showQrCode = true
|
||||
|
||||
console.log(this.postAddress)
|
||||
window.signatureInterval = setInterval(() => {
|
||||
|
||||
$.get("https://zhgh.nsi.edu.cn/signature/getBase64?prefix=" + this.prefix + "&id=" + ts).then(res => {
|
||||
if (res != null) {
|
||||
this.$emit("change", res)
|
||||
this.$emit("update:qz", res)
|
||||
this.qz = res
|
||||
this.loading = false
|
||||
this.save()
|
||||
clearInterval(signatureInterval)
|
||||
}
|
||||
})
|
||||
|
||||
// const signBody = document.getElementById('signature-body')
|
||||
// const isVisible = $('#signature-body').is(":visible")
|
||||
// if (signBody && isVisible) {
|
||||
//
|
||||
// } else {
|
||||
// clearInterval(signatureInterval)
|
||||
// }
|
||||
}, 1000 * 3)
|
||||
},
|
||||
save() {
|
||||
localStorage.setItem("signature", this.qz)
|
||||
},
|
||||
clear() {
|
||||
localStorage.removeItem("signature")
|
||||
},
|
||||
getSignature() {
|
||||
return localStorage.getItem("signature")
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
debugger
|
||||
console.log('clearSignature')
|
||||
// 在组件销毁前清除定时器
|
||||
clearInterval(window.signatureInterval);
|
||||
},
|
||||
watch: {
|
||||
'qz': {
|
||||
handler(s) {
|
||||
this.loading = !s
|
||||
if (!s) {
|
||||
const qz = this.getSignature()
|
||||
|
||||
if (!qz) {
|
||||
this.$emit("change", '')
|
||||
this.$emit("update:qz", '')
|
||||
this.startRequest()
|
||||
} else {
|
||||
this.qz = qz
|
||||
this.$emit("change", qz)
|
||||
this.$emit("update:qz", qz)
|
||||
}
|
||||
|
||||
} else {
|
||||
this.qz = s
|
||||
this.showQrCode = false
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
.el-card__body {
|
||||
position: relative !important;
|
||||
}
|
||||
|
||||
.signature-body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 160px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.qr-code-div {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
z-index: 999;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user