|
|
|
@ -1,13 +1,25 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<view class="easy-scancode" v-if="show">
|
|
|
|
<view class="easy-scancode" v-if="show">
|
|
|
|
<view id="reader"></view>
|
|
|
|
<view id="reader"></view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 装饰区域 -->
|
|
|
|
|
|
|
|
<view class="scan-mask">
|
|
|
|
|
|
|
|
<view class="scan-box">
|
|
|
|
|
|
|
|
<view class="line"></view>
|
|
|
|
|
|
|
|
<view class="corner top-left"></view>
|
|
|
|
|
|
|
|
<view class="corner top-right"></view>
|
|
|
|
|
|
|
|
<view class="corner bottom-left"></view>
|
|
|
|
|
|
|
|
<view class="corner bottom-right"></view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 扫码提示区域 -->
|
|
|
|
|
|
|
|
<view class="scan-tip-overlay">
|
|
|
|
|
|
|
|
<view class="scan-tip"> 请将二维码放入框内 </view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
<view class="scan-back">
|
|
|
|
<view class="scan-back">
|
|
|
|
<button class="action-btn" @tap="stop">返回</button>
|
|
|
|
<button class="action-btn" @tap="stop">返回</button>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<!-- 扫码提示区域 -->
|
|
|
|
|
|
|
|
<view class="scan-tip-overlay">
|
|
|
|
|
|
|
|
<view class="scan-tip"> 请将二维码放入框内 </view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,7 +34,7 @@ export default {
|
|
|
|
fail: () => {},
|
|
|
|
fail: () => {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
show: false,
|
|
|
|
show: false,
|
|
|
|
html5QrCode: null,
|
|
|
|
html5QrCode: null
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
@ -95,15 +107,12 @@ export default {
|
|
|
|
that.html5QrCode = new Html5Qrcode("reader");
|
|
|
|
that.html5QrCode = new Html5Qrcode("reader");
|
|
|
|
|
|
|
|
|
|
|
|
let windowInfo = uni.getWindowInfo();
|
|
|
|
let windowInfo = uni.getWindowInfo();
|
|
|
|
// console.log(windowInfo);
|
|
|
|
|
|
|
|
const width = windowInfo&&windowInfo.windowWidth?windowInfo.windowWidth:375;
|
|
|
|
const width = windowInfo&&windowInfo.windowWidth?windowInfo.windowWidth:375;
|
|
|
|
const height = windowInfo&&windowInfo.windowHeight?windowInfo.windowHeight:720;
|
|
|
|
const height = windowInfo&&windowInfo.windowHeight?windowInfo.windowHeight:720;
|
|
|
|
|
|
|
|
|
|
|
|
// 横屏
|
|
|
|
// 横屏
|
|
|
|
const aspectRatio = width / height;
|
|
|
|
const aspectRatio = width / height;
|
|
|
|
// 竖屏
|
|
|
|
// 竖屏
|
|
|
|
const reverseAspectRatio = height / width;
|
|
|
|
const reverseAspectRatio = height / width;
|
|
|
|
|
|
|
|
|
|
|
|
const mobileAspectRatio =
|
|
|
|
const mobileAspectRatio =
|
|
|
|
reverseAspectRatio > 1.5
|
|
|
|
reverseAspectRatio > 1.5
|
|
|
|
? reverseAspectRatio + (reverseAspectRatio * 12) / 100
|
|
|
|
? reverseAspectRatio + (reverseAspectRatio * 12) / 100
|
|
|
|
@ -116,10 +125,15 @@ export default {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
cameraId = devices[0].id;
|
|
|
|
cameraId = devices[0].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 计算二维码扫描框大小 - 使用宽度/高度中较小的值来确保方框适合屏幕
|
|
|
|
|
|
|
|
// 并在扫描区域周围留出一些边距
|
|
|
|
// 计算二维码扫描框大小 - 使用宽度/高度中较小的值来确保方框适合屏幕
|
|
|
|
|
|
|
|
// 并在扫描区域周围留出一些边距
|
|
|
|
const qrboxSize = Math.min(width, height) * 0.7;
|
|
|
|
const qrboxSize = Math.min(width, height) * 0.7;
|
|
|
|
console.log(qrboxSize);
|
|
|
|
console.log(qrboxSize);
|
|
|
|
|
|
|
|
console.log(aspectRatio);
|
|
|
|
|
|
|
|
console.log(width,mobileAspectRatio);
|
|
|
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
// 使用这个来开始扫描
|
|
|
|
// 使用这个来开始扫描
|
|
|
|
that.html5QrCode
|
|
|
|
that.html5QrCode
|
|
|
|
.start(
|
|
|
|
.start(
|
|
|
|
@ -127,18 +141,32 @@ export default {
|
|
|
|
facingMode: "environment",
|
|
|
|
facingMode: "environment",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fps: 10, // 可选,二维码扫描的每秒帧数
|
|
|
|
fps: 10, // 可选,二维码扫描的每秒帧数
|
|
|
|
aspectRatio: aspectRatio,
|
|
|
|
aspectRatio: aspectRatio,
|
|
|
|
qrbox: { width: qrboxSize, height: qrboxSize }, // 可选,如果你想要边界框UI
|
|
|
|
qrbox: { width: qrboxSize, height: qrboxSize }, // 可选,如果你想要边界框UI
|
|
|
|
videoConstraints: {
|
|
|
|
videoConstraints: {
|
|
|
|
facingMode: "environment",
|
|
|
|
facingMode: "environment",
|
|
|
|
aspectRatio: width < 600 ? mobileAspectRatio : aspectRatio,
|
|
|
|
aspectRatio: width < 600 ? mobileAspectRatio : aspectRatio,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
autofocus:true, //自动对焦 但使用的时候没有体会到
|
|
|
|
// fps: 15, // 帧率:平衡性能与流畅度
|
|
|
|
colorDark: '#0000ff', //加深二维码黑色部分的颜色提高识别度
|
|
|
|
// aspectRatio: 1.0, // 1:1比例,更适合二维码
|
|
|
|
colorLight: '#ffffff',//这个应该是提高非黑即白部分的亮度 提高识别度
|
|
|
|
// qrbox: {
|
|
|
|
visualFeedback:true, //开启视觉反馈 没有体会到
|
|
|
|
// width: 280,
|
|
|
|
halfSample:true,//缩小二维码提高识别精度吧
|
|
|
|
// height: 280
|
|
|
|
|
|
|
|
// }, // 扫描框尺寸
|
|
|
|
|
|
|
|
// videoConstraints: {
|
|
|
|
|
|
|
|
// focusMode: "continuous", // 尝试启用连续对焦
|
|
|
|
|
|
|
|
// width: { ideal: 1280 }, // 理想分辨率
|
|
|
|
|
|
|
|
// height: { ideal: 720 },
|
|
|
|
|
|
|
|
// frameRate: { ideal: 30 }
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// disableFlip: false, // 允许图像翻转检测
|
|
|
|
|
|
|
|
// rememberLastUsedCamera: true, // 记住上次使用的摄像头
|
|
|
|
|
|
|
|
// showTorchButtonIfSupported: true,
|
|
|
|
|
|
|
|
// showZoomSliderIfSupported: true,
|
|
|
|
|
|
|
|
// defaultZoomValueIfSupported: 2,
|
|
|
|
|
|
|
|
// // 高级配置
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(decodedText, decodedResult) => {
|
|
|
|
(decodedText, decodedResult) => {
|
|
|
|
// 当码被读取时执行操作
|
|
|
|
// 当码被读取时执行操作
|
|
|
|
@ -180,15 +208,14 @@ export default {
|
|
|
|
z-index: 1000;
|
|
|
|
z-index: 1000;
|
|
|
|
top: 0;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
left: 0;
|
|
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
|
|
background-color: rgba(0, 0, 0, 0.4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#reader {
|
|
|
|
#reader {
|
|
|
|
top: 50%;
|
|
|
|
top: 50%;
|
|
|
|
left: 0;
|
|
|
|
left: 0;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
transform: translateY(-50%);
|
|
|
|
width: 100vw;
|
|
|
|
position: relative;
|
|
|
|
height: 100vh;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.scan-tip-overlay {
|
|
|
|
.scan-tip-overlay {
|
|
|
|
@ -227,4 +254,80 @@ export default {
|
|
|
|
padding: 10px;
|
|
|
|
padding: 10px;
|
|
|
|
border-radius: 5px;
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 装饰层 */
|
|
|
|
|
|
|
|
.scan-mask {
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
inset: 0;
|
|
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.3);
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.scan-box {
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
width: 480rpx;
|
|
|
|
|
|
|
|
height: 480rpx;
|
|
|
|
|
|
|
|
box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.4);
|
|
|
|
|
|
|
|
/* 形成中间镂空感 */
|
|
|
|
|
|
|
|
background: transparent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.corner {
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
width: 30rpx;
|
|
|
|
|
|
|
|
height: 30rpx;
|
|
|
|
|
|
|
|
border: 6rpx solid #ffffff;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.top-left {
|
|
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
|
|
border-right: none;
|
|
|
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.top-right {
|
|
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
border-left: none;
|
|
|
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.bottom-left {
|
|
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
|
|
border-right: none;
|
|
|
|
|
|
|
|
border-top: none;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.bottom-right {
|
|
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
border-left: none;
|
|
|
|
|
|
|
|
border-top: none;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.line {
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
height: 2px;
|
|
|
|
|
|
|
|
background: linear-gradient(to right, transparent, #ffffff, transparent);
|
|
|
|
|
|
|
|
animation: scanMove 2s infinite linear;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes scanMove {
|
|
|
|
|
|
|
|
0% {
|
|
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100% {
|
|
|
|
|
|
|
|
top: 100%;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|
|