This commit is contained in:
@jyuhsin
2025-12-18 13:03:11 +08:00
parent 5e13af047f
commit 82650e7e9a
3 changed files with 16 additions and 4 deletions
@@ -48,6 +48,13 @@ module.exports = {
rotate() {
signature.getRotateCanvas(90)
},
isLikelyMobile() {
const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
const isSmallScreen = window.screen.width <= 768;
const hasMobileUA = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
return hasMobileUA || (isTouchDevice && isSmallScreen);
},
save() {
if (signature.isEmpty()) {
alert("请签字后再保存")
@@ -56,7 +63,11 @@ module.exports = {
// const png = signature.getPNG()
//旋转一下 横过来
const rotateCanvas = signature.getRotateCanvas(-90)
this.$emit("save", rotateCanvas.toDataURL())
if (this.isLikelyMobile()) {
this.$emit("save", rotateCanvas.toDataURL())
} else {
this.$emit("save", signature.toDataURL())
}
}
},
mounted() {
@@ -69,8 +69,9 @@ module.exports = {
// 可选:轮询或 watch ready 状态
const checkReady = () => {
if (window.webSocketPubSub.ws.readyState === 1) {
this.loading = false; // 允许签字
if (webSocketPubSub.ws && webSocketPubSub.ws.readyState === WebSocket.OPEN) {
console.info("ws.readyState is open");
this.loading = false;
} else {
setTimeout(checkReady, 100);
}
@@ -202,7 +202,7 @@
// )
// 连接建立时不立即发送 join,等待订阅完成
this.ping()
console.log('websocket open success')
console.info('websocket open success')
}
}