first commit
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
<template>
|
||||
<div class="signature-wrap">
|
||||
<canvas id="canvas"></canvas>
|
||||
<div class="action-buttons">
|
||||
<button @click="clear" class="action-button-danger" type="button">清空</button>
|
||||
<button @click="undo" class="action-button-warning" type="button">撤销</button>
|
||||
<button @click="save" class="action-button-primary" type="button">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// function a() {
|
||||
// // 检查当前屏幕方向
|
||||
// if (window.orientation === 0 || window.orientation === 180) {
|
||||
// // 竖屏状态
|
||||
// console.log("竖屏状态")
|
||||
// alert("当前不支持竖屏,请将设备调整为横屏!")
|
||||
// } else {
|
||||
// // 横屏状态,执行禁止旋转的操作
|
||||
// alert("当前不支持横屏,请将设备调整为竖屏!")
|
||||
// // 可以在这里使内容固定在竖屏方向
|
||||
// const innerWidth = window.innerWidth
|
||||
// const innerHeight = window.innerHeight
|
||||
// alert(innerHeight)
|
||||
// alert(innerWidth)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// window.addEventListener("orientationchange", a)
|
||||
// a()
|
||||
|
||||
let signature = null
|
||||
module.exports = {
|
||||
name: "sysSignature",
|
||||
data() {
|
||||
return {
|
||||
content: null,
|
||||
initialized: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
clear() {
|
||||
signature.clear()
|
||||
},
|
||||
undo() {
|
||||
signature.undo()
|
||||
},
|
||||
rotate() {
|
||||
signature.getRotateCanvas(90)
|
||||
},
|
||||
save() {
|
||||
if (signature.isEmpty()) {
|
||||
alert("请签字后再保存")
|
||||
return
|
||||
}
|
||||
// const png = signature.getPNG()
|
||||
//旋转一下 横过来
|
||||
const rotateCanvas = signature.getRotateCanvas(-90)
|
||||
this.$emit("save", rotateCanvas.toDataURL())
|
||||
},
|
||||
|
||||
initSignature() {
|
||||
if (this.initialized) return;
|
||||
|
||||
const canvas = document.getElementById("canvas");
|
||||
if (!canvas) return;
|
||||
|
||||
// 检查 canvas 是否已有有效尺寸
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
if (rect.width <= 0 || rect.height <= 0) {
|
||||
// 尺寸无效,稍后重试
|
||||
setTimeout(() => this.initSignature(), 50);
|
||||
return;
|
||||
}
|
||||
|
||||
const padding = 30;
|
||||
const width = window.innerWidth - padding;
|
||||
const height = window.innerHeight - padding;
|
||||
|
||||
// 设置 CSS 尺寸
|
||||
canvas.style.width = `${width}px`;
|
||||
canvas.style.height = `${height}px`;
|
||||
|
||||
// 高清绘制
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = width * dpr;
|
||||
canvas.height = height * dpr;
|
||||
|
||||
// 销毁旧实例(防止重复)
|
||||
if (signature) {
|
||||
signature.clear();
|
||||
}
|
||||
|
||||
signature = new SmoothSignature(canvas, {
|
||||
width: width,
|
||||
height: height,
|
||||
scale: dpr,
|
||||
minWidth: 4,
|
||||
maxWidth: 10,
|
||||
color: "#000000"
|
||||
});
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 延迟初始化,确保 DOM 渲染完成
|
||||
this.$nextTick(() => {
|
||||
this.initSignature();
|
||||
});
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
signature = null;
|
||||
this.initialized = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.signature-wrap {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 15px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.signature-wrap .action {
|
||||
width: 50px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.signature-wrap .action-buttons {
|
||||
white-space: nowrap;
|
||||
transform: rotate(90deg);
|
||||
display: flex;
|
||||
column-gap: 10px;
|
||||
position: fixed;
|
||||
bottom: 0px;
|
||||
left: 60px;
|
||||
transform: rotate(90deg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
row-gap: 20px;
|
||||
}
|
||||
|
||||
.action-buttons button {
|
||||
color: #ffffff;
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
box-sizing: border-box;
|
||||
height: auto;
|
||||
padding: 3px 12px;
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
line-height: 1.4;
|
||||
text-align: center;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s ease;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.action-button-primary {
|
||||
background-color: #1677ff;
|
||||
border: 1px solid #1677ff;
|
||||
}
|
||||
|
||||
.action-button-danger {
|
||||
background-color: #ff3141;
|
||||
border: 1px solid #ff3141;
|
||||
}
|
||||
|
||||
.action-button-warning {
|
||||
background-color: #ff8f1f;
|
||||
border: 1px solid #ff8f1f;
|
||||
}
|
||||
|
||||
.signature-wrap canvas {
|
||||
flex: 1;
|
||||
border-radius: 10px;
|
||||
border: 2px dashed #ccc;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,136 @@
|
||||
<template>
|
||||
<div class="h5-signature">
|
||||
<div v-if="!showSignaturePanel" class="main-panel">
|
||||
<slot v-if="$slots.default"></slot>
|
||||
<template v-else>
|
||||
<van-button @click="openSignature" class="open-button" size="middle" plain native-type="button">打开签字板</van-button>
|
||||
<van-image :src="signatureContent">
|
||||
<template v-slot:error>请点击下方打开签字板按钮进行签字</template>
|
||||
</van-image>
|
||||
</template>
|
||||
</div>
|
||||
<van-popup v-model="showSignaturePanel" :style="{ height: '100vh', width: '100vw', display: 'flex', 'align-items': 'center' }">
|
||||
<signature v-if="showSignaturePanel" @save="save"></signature>
|
||||
</van-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
module.exports = {
|
||||
name: "h5",
|
||||
components: {
|
||||
signature: httpVueLoader("/components/sign/index.vue?v=" + new Date().getTime())
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ""
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: {
|
||||
handler(val) {
|
||||
if (!val) {
|
||||
this.signatureContent = val
|
||||
return
|
||||
}
|
||||
if (val.startsWith("/signature/getSignData?") || val.startsWith('data:image/png;')) {
|
||||
this.signatureContent = val
|
||||
} else {
|
||||
this.signatureContent = '/signature/getSignData?path=' + val
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
signatureContent: null,
|
||||
showSignaturePanel: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openSignature() {
|
||||
this.showSignaturePanel = true
|
||||
},
|
||||
|
||||
save(signature) {
|
||||
$.post("/mobile/common/signing/update", {sign: signature})
|
||||
.then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$toast.success("保存成功")
|
||||
this.showSignaturePanel = false
|
||||
this.getMySign()
|
||||
} else {
|
||||
this.$toast.fail("保存失败")
|
||||
}
|
||||
})
|
||||
},
|
||||
base64ToFile(base64Data, filename) {
|
||||
// 将base64的数据部分提取出来
|
||||
const parts = base64Data.split(";base64,")
|
||||
const contentType = parts[0].split(":")[1]
|
||||
const raw = window.atob(parts[1])
|
||||
const rawLength = raw.length
|
||||
const uInt8Array = new Uint8Array(rawLength)
|
||||
|
||||
for (let i = 0; i < rawLength; ++i) {
|
||||
uInt8Array[i] = raw.charCodeAt(i)
|
||||
}
|
||||
|
||||
// 使用Blob对象创建File对象
|
||||
const blob = new Blob([uInt8Array], { type: contentType })
|
||||
blob.lastModifiedDate = new Date()
|
||||
blob.name = filename
|
||||
return new File([blob], filename, { type: contentType })
|
||||
},
|
||||
async getMySign() {
|
||||
const data = await $.get("/mobile/common/signing/getMySign")
|
||||
if (data) {
|
||||
if (data.startsWith("/signature/getSignData?") || data.startsWith('data:image/png;')) {
|
||||
this.signatureContent = data
|
||||
} else {
|
||||
this.signatureContent = '/signature/getSignData?path=' + data
|
||||
}
|
||||
this.$emit("input", data)
|
||||
}
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
await this.getMySign()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.h5-signature {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-panel {
|
||||
position: relative;
|
||||
flex-direction: column-reverse;
|
||||
display: flex;
|
||||
row-gap: 10px;
|
||||
}
|
||||
|
||||
.main-panel .van-image {
|
||||
min-height: 150px;
|
||||
display: block;
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.main-panel .open-button {
|
||||
margin: 0 auto;
|
||||
width: 90%;
|
||||
height: 36px;
|
||||
border-radius: 12px;
|
||||
color: white;
|
||||
background: rgb(33, 109, 179);
|
||||
border-color: rgb(33, 109, 179);
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,211 @@
|
||||
<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="imageUrl">
|
||||
<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'
|
||||
},
|
||||
qz: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
is_value_base64: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
model: {
|
||||
prop: 'qz',
|
||||
event: 'change'
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showQrCode: false,
|
||||
loading: true,
|
||||
postAddress: '',
|
||||
imageUrl: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
refresh() {
|
||||
this.qz = ''
|
||||
},
|
||||
getImageUrl(data) {
|
||||
if (!data) {
|
||||
return
|
||||
}
|
||||
if (data.startsWith("/signature/getSignData?") || data.startsWith('data:image/png;')) {
|
||||
this.imageUrl = data
|
||||
} else {
|
||||
this.imageUrl = '/signature/getSignData?path=' + data
|
||||
}
|
||||
|
||||
localStorage.setItem("signature", data)
|
||||
localStorage.setItem("signatureWelfare", data)
|
||||
clearInterval(signatureInterval)
|
||||
},
|
||||
startRequest() {
|
||||
this.imageUrl = ''
|
||||
clearInterval(signatureInterval)
|
||||
const ts = new Date().getTime() + (Math.floor(Math.random() * (1000 - 1 + 1)) + 1).toString()
|
||||
console.log(ts)
|
||||
this.postAddress = location.protocol + '//' + location.host + '/signature?id=' + ts
|
||||
// this.postAddress = 'https://zhgh.hmc.edu.cn/signature?id=' + ts
|
||||
|
||||
this.showQrCode = true
|
||||
|
||||
console.log(this.postAddress)
|
||||
window.signatureInterval = setInterval(() => {
|
||||
$.get("/signature/getBase64?id=" + ts).then(res => {
|
||||
if (res != null) {
|
||||
this.$emit("change", res)
|
||||
this.$emit("update:qz", res)
|
||||
console.log(res)
|
||||
this.getImageUrl(res)
|
||||
this.qz = res
|
||||
this.loading = false
|
||||
this.save()
|
||||
clearInterval(signatureInterval)
|
||||
}
|
||||
})
|
||||
}, 1000 * 3)
|
||||
},
|
||||
async save() {
|
||||
if (this.is_value_base64) {
|
||||
localStorage.setItem("signature", this.qz)
|
||||
} else {
|
||||
return localStorage.setItem("signatureWelfare", this.qz)
|
||||
}
|
||||
},
|
||||
clear() {
|
||||
if (this.is_value_base64) {
|
||||
localStorage.removeItem("signature")
|
||||
} else {
|
||||
localStorage.removeItem("signatureWelfare")
|
||||
}
|
||||
|
||||
},
|
||||
getSignature() {
|
||||
if (this.is_value_base64) {
|
||||
return localStorage.getItem("signature")
|
||||
} else {
|
||||
return localStorage.getItem("signatureWelfare")
|
||||
}
|
||||
},
|
||||
async getMySign() {
|
||||
setTimeout(() => {
|
||||
if (this.qz) {
|
||||
this.getImageUrl(this.qz)
|
||||
} else {
|
||||
$.get("/mobile/common/signing/getMySign").then(data => {
|
||||
if (data) {
|
||||
this.getImageUrl(data)
|
||||
this.$emit("change", data)
|
||||
this.$emit("update:qz", data)
|
||||
this.qz = data
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}, 500)
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getMySign()
|
||||
},
|
||||
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