147 lines
3.2 KiB
Vue
147 lines
3.2 KiB
Vue
<template>
|
|
<el-card class="box-card" shadow="never">
|
|
|
|
<div class="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="signature">
|
|
<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>
|
|
|
|
|
|
</el-card>
|
|
</template>
|
|
|
|
<script>
|
|
|
|
window.signatureInterval = null
|
|
|
|
module.exports = {
|
|
name: "Signature",
|
|
props: {
|
|
scan_title: {
|
|
type: String,
|
|
default: '扫描下方二维码进行签字'
|
|
},
|
|
prefix: {
|
|
type: String,
|
|
default: 'DEFAULT'
|
|
},
|
|
signature: {
|
|
type: String,
|
|
default: ''
|
|
}
|
|
},
|
|
model: {
|
|
prop: 'signature',
|
|
event: 'change'
|
|
},
|
|
data() {
|
|
return {
|
|
showQrCode: false,
|
|
loading: true,
|
|
postAddress: '',
|
|
}
|
|
},
|
|
methods: {
|
|
refresh() {
|
|
this.signature = ''
|
|
},
|
|
startRequest() {
|
|
this.signature = ''
|
|
clearInterval(signatureInterval)
|
|
const ts = new Date().getTime()
|
|
this.postAddress = location.protocol + '//' + location.host + '/signature?prefix=' + this.prefix + '&id=' + ts
|
|
|
|
this.showQrCode = true
|
|
|
|
console.log(this.postAddress)
|
|
window.signatureInterval = setInterval(() => {
|
|
$.get(base + "/signature/getBase64?prefix=" + this.prefix + "&id=" + ts).then(res => {
|
|
if (res != null) {
|
|
this.$emit("change", res)
|
|
this.signature = res
|
|
this.loading = false
|
|
this.save()
|
|
clearInterval(signatureInterval)
|
|
}
|
|
})
|
|
}, 1000 * 3)
|
|
},
|
|
save() {
|
|
localStorage.setItem("signature", this.signature)
|
|
},
|
|
clear() {
|
|
localStorage.removeItem("signature")
|
|
},
|
|
getSignature() {
|
|
return localStorage.getItem("signature")
|
|
}
|
|
},
|
|
watch: {
|
|
'signature': {
|
|
handler(s) {
|
|
this.loading = !s
|
|
if (!s) {
|
|
const signature = this.getSignature()
|
|
|
|
if (!signature) {
|
|
this.$emit("change", '')
|
|
this.startRequest()
|
|
} else {
|
|
this.signature = signature
|
|
this.$emit("change", signature)
|
|
}
|
|
|
|
} else {
|
|
this.signature = 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> |