修改扫码页面
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
// 应用全局配置
|
// 应用全局配置
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// baseUrl: 'http://172.16.129.101:8080/dev-api/',
|
// baseUrl: 'http://172.16.129.101:8080/dev-api/',
|
||||||
//baseUrl: 'http://pasd.gxsdxy.cn/prod-api/',
|
baseUrl: 'https://pasd.gxsdxy.cn/prod-api/',
|
||||||
// baseUrl: 'http://172.16.129.101:8080',//172.16.129.101
|
// baseUrl: 'http://172.16.129.101:8080',//172.16.129.101
|
||||||
baseUrl: 'http://192.168.100.106:8080',
|
// baseUrl: 'http://localhost:8080',
|
||||||
// 应用信息
|
// 应用信息
|
||||||
appInfo: {
|
appInfo: {
|
||||||
// 应用名称
|
// 应用名称
|
||||||
|
|||||||
110
manifest.json
110
manifest.json
@@ -1,31 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "平安水电移动端",
|
"name" : "平安水电移动端",
|
||||||
"appid": "__UNI__3CA192A",
|
"appid" : "__UNI__3CA192A",
|
||||||
"description": "",
|
"description" : "",
|
||||||
"versionName": "1.1.0",
|
"versionName" : "1.1.0",
|
||||||
"versionCode": "100",
|
"versionCode" : "100",
|
||||||
"transformPx": false,
|
"transformPx" : false,
|
||||||
"app-plus": {
|
"app-plus" : {
|
||||||
"usingComponents": true,
|
"usingComponents" : true,
|
||||||
"nvueCompiler": "uni-app",
|
"nvueCompiler" : "uni-app",
|
||||||
"splashscreen": {
|
"splashscreen" : {
|
||||||
"alwaysShowBeforeRender": true,
|
"alwaysShowBeforeRender" : true,
|
||||||
"waiting": true,
|
"waiting" : true,
|
||||||
"autoclose": true,
|
"autoclose" : true,
|
||||||
"delay": 0
|
"delay" : 0
|
||||||
},
|
},
|
||||||
"modules": {},
|
"modules" : {},
|
||||||
"permission": {
|
"permission" : {
|
||||||
"Camera": {
|
"Camera" : {
|
||||||
"description": "需要访问相机以实现扫码功能"
|
"description" : "需要访问相机以实现扫码功能"
|
||||||
},
|
},
|
||||||
"Flashlight": {
|
"Flashlight" : {
|
||||||
"description": "需要访问闪光灯以支持扫码补光"
|
"description" : "需要访问闪光灯以支持扫码补光"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"distribute": {
|
"distribute" : {
|
||||||
"android": {
|
"android" : {
|
||||||
"permissions": [
|
"permissions" : [
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
@@ -45,49 +45,49 @@
|
|||||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>"
|
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ios": {
|
"ios" : {
|
||||||
"permissions": {
|
"permissions" : {
|
||||||
"Camera": {
|
"Camera" : {
|
||||||
"description": "需要访问相机以实现扫码功能"
|
"description" : "需要访问相机以实现扫码功能"
|
||||||
},
|
},
|
||||||
"PhotoLibraryAdd": {
|
"PhotoLibraryAdd" : {
|
||||||
"description": "需要访问相册以保存图片"
|
"description" : "需要访问相册以保存图片"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sdkConfigs": {}
|
"sdkConfigs" : {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"quickapp": {},
|
"quickapp" : {},
|
||||||
"mp-weixin": {
|
"mp-weixin" : {
|
||||||
"appid": "wx6caa681653417faa",
|
"appid" : "wx6caa681653417faa",
|
||||||
"setting": {
|
"setting" : {
|
||||||
"urlCheck": false,
|
"urlCheck" : false,
|
||||||
"es6": false,
|
"es6" : false,
|
||||||
"minified": true,
|
"minified" : true,
|
||||||
"postcss": true
|
"postcss" : true
|
||||||
},
|
},
|
||||||
"optimization": {
|
"optimization" : {
|
||||||
"subPackages": true
|
"subPackages" : true
|
||||||
},
|
},
|
||||||
"permission": {
|
"permission" : {
|
||||||
"scope.camera": {
|
"scope.camera" : {
|
||||||
"desc": "需要访问相机以实现扫码功能"
|
"desc" : "需要访问相机以实现扫码功能"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"usingComponents": true
|
"usingComponents" : true
|
||||||
},
|
},
|
||||||
"vueVersion": "2",
|
"vueVersion" : "2",
|
||||||
"h5": {
|
"h5" : {
|
||||||
"template": "static/index.html",
|
"template" : "static/index.html",
|
||||||
"devServer": {
|
"devServer" : {
|
||||||
"port": 9090,
|
"port" : 9090,
|
||||||
"https": false
|
"https" : false
|
||||||
},
|
},
|
||||||
"title": "RuoYi-App",
|
"title" : "RuoYi-App",
|
||||||
"router": {
|
"router" : {
|
||||||
"mode": "hash",
|
"mode" : "hash",
|
||||||
"base": "./"
|
"base" : "./"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,13 +95,15 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/work/inspection/scanSign/scanSign",
|
"path": "pages/work/inspection/scanSign/scanSign",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "扫一扫"
|
"navigationBarTitleText": "扫一扫",
|
||||||
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/work/inspection/scanSign/scanSign2",
|
"path": "pages/work/inspection/scanSign/scanSign2",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "扫一扫"
|
"navigationBarTitleText": "扫一扫",
|
||||||
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -154,7 +156,7 @@
|
|||||||
"text": "工作台"
|
"text": "工作台"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pagePath": "pages/work/inspection/scanSign/scanSign2",
|
"pagePath": "pages/work/inspection/scanSign/scanSign",
|
||||||
"iconPath": "static/images/tabbar/scan2.png",
|
"iconPath": "static/images/tabbar/scan2.png",
|
||||||
"selectedIconPath": "static/images/tabbar/scan2.png",
|
"selectedIconPath": "static/images/tabbar/scan2.png",
|
||||||
"text": "扫一扫"
|
"text": "扫一扫"
|
||||||
|
|||||||
@@ -1,79 +1,75 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- HTML -->
|
||||||
|
<mumu-get-qrcode @success='qrcodeSucess' @error="qrcodeError" :scanWidth="300"
|
||||||
|
:scanHeight="300"></mumu-get-qrcode>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {
|
// js
|
||||||
getInspectionManage
|
import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
|
||||||
} from '@/api/inspection/inspectionManage.js'
|
// 嫌路径长的话可以单独复制出来
|
||||||
export default {
|
export default {
|
||||||
created() {
|
components: {
|
||||||
this.requestCameraAuth()
|
mumuGetQrcode
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
requestCameraAuth() {
|
qrcodeSucess(data) {
|
||||||
const _this = this
|
console.log("二维码数据", data)
|
||||||
uni.authorize({
|
this.handleScanResult(data);
|
||||||
scope: 'scope.camera', // 请求相机权限
|
|
||||||
success: (res) => {
|
|
||||||
_this.scanQRCode();
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
// 用户拒绝授权
|
|
||||||
uni.showToast({
|
|
||||||
title: '您拒绝了授权',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
scanQRCode() {
|
qrcodeError(err) {
|
||||||
const _this = this
|
console.log(err)
|
||||||
uni.scanCode({
|
let that = this;
|
||||||
onlyFromCamera: true,
|
uni.showModal({
|
||||||
scanType: ['qrCode'],
|
title: '摄像头授权失败',
|
||||||
success(res) {
|
content: '摄像头授权失败,请检测当前浏览器是否有摄像头权限。',
|
||||||
if (res.result) {
|
success: () => {
|
||||||
// 扫描成功,处理二维码内容
|
that.redirectToWorkbench(); // 请求错误跳回工作台
|
||||||
getInspectionManage(res.result).then(res => {
|
}
|
||||||
if (res.data.inspectionStatus === "1") {
|
})
|
||||||
let inspectionPoint = res.data.inspectionPoint
|
},
|
||||||
let inspectionRequirements = res.data.inspectionRequirements
|
handleScanResult(result) {
|
||||||
// _this.$tab.redirectTo(
|
let that = this;
|
||||||
// `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}`
|
getInspectionManage(result)
|
||||||
// )
|
.then(res => {
|
||||||
uni.reLaunch({
|
if (res.data.inspectionStatus === "1") {
|
||||||
url: `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}`
|
let inspectionPoint = res.data.inspectionPoint;
|
||||||
})
|
let inspectionRequirements = res.data.inspectionRequirements;
|
||||||
} else {
|
let inspectionPointId = res.data.id
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/work/index'
|
url: `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}&inspectionPointId=${inspectionPointId}`
|
||||||
}).then(()=>{
|
|
||||||
// 扫描失败
|
|
||||||
uni.showToast({
|
|
||||||
title: '验证码已失效!!!',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 扫描失败
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '扫描失败',
|
title: '验证码已失效!',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
|
that.redirectToWorkbench(); // 验证码失效跳回工作台
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
fail(res) {
|
.catch(err => {
|
||||||
|
console.log("请求错误", err);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '调用相机失败',
|
title: '服务器错误',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
|
that.redirectToWorkbench(); // 请求错误跳回工作台
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
}
|
// 新增方法:跳转回工作台
|
||||||
|
redirectToWorkbench() {
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/work/index'
|
||||||
|
});
|
||||||
|
}, 1500); // 1.5秒后跳转,让用户看到提示信息
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,42 +1,28 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="canvasBox">
|
<view class="canvasBox">
|
||||||
<template v-if="isUse">
|
<template v-if="isUse">
|
||||||
<view class="box">
|
<view class="box" :style="`width: ${scanWidth}px; height: ${scanHeight}px;`">
|
||||||
<view class="line"></view>
|
<view class="line"></view>
|
||||||
<view class="angle"></view>
|
<view class="angle"></view>
|
||||||
</view>
|
</view>
|
||||||
<view class="box2" v-if="isUseTorch">
|
<view class="box2" v-if="isUseTorch" :style="`width: ${scanWidth}px; height: ${scanHeight}px;`">
|
||||||
<view class="track" @click="openTrack">
|
<view class="track" @click="openTrack" :style="`bottom: -${scanHeight/2 + 10}px;`">
|
||||||
<svg
|
<svg t="1653920715959" class="icon" viewBox="0 0 1024 1024" version="1.1"
|
||||||
t="1653920715959"
|
xmlns="http://www.w3.org/2000/svg" p-id="1351" width="32" height="32">
|
||||||
class="icon"
|
|
||||||
viewBox="0 0 1024 1024"
|
|
||||||
version="1.1"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
p-id="1351"
|
|
||||||
width="32"
|
|
||||||
height="32"
|
|
||||||
>
|
|
||||||
<path
|
<path
|
||||||
d="M651.353043 550.479503H378.752795L240.862609 364.315031c-3.688944-4.897391-5.660621-10.876025-5.660621-17.045466v-60.040745c0-15.773416 12.847702-28.621118 28.621118-28.621118h502.459627c15.773416 0 28.621118 12.847702 28.621118 28.621118v59.977143c0 6.105839-1.971677 12.084472-5.660621 17.045466l-137.890187 186.228074zM378.752795 598.308571v398.024348c0 15.328199 12.402484 27.667081 27.667081 27.667081h217.266087c15.328199 0 27.667081-12.402484 27.66708-27.667081V598.308571H378.752795z m136.300124 176.942112c-14.564969 0-26.331429-11.76646-26.331428-26.331428v-81.283975c0-14.564969 11.76646-26.331429 26.331428-26.331429 14.564969 0 26.331429 11.76646 26.331429 26.331429v81.283975c0 14.564969-11.76646 26.331429-26.331429 26.331428zM512 222.608696c-17.554286 0-31.801242-14.246957-31.801242-31.801243V31.801242c0-17.554286 14.246957-31.801242 31.801242-31.801242s31.801242 14.246957 31.801242 31.801242v159.006211c0 17.554286-14.246957 31.801242-31.801242 31.801243zM280.932174 205.881242c-9.47677 0-18.889938-4.197764-25.122981-12.275279L158.242981 67.991056a31.864845 31.864845 0 0 1 5.597019-44.648944 31.864845 31.864845 0 0 1 44.648944 5.597018l97.502609 125.551305a31.864845 31.864845 0 0 1-5.597019 44.648944c-5.787826 4.579379-12.656894 6.741863-19.46236 6.741863zM723.987081 205.881242c-6.805466 0-13.674534-2.162484-19.462361-6.678261a31.794882 31.794882 0 0 1-5.597018-44.648944l97.566211-125.551304a31.794882 31.794882 0 0 1 44.648944-5.597019 31.794882 31.794882 0 0 1 5.597019 44.648944l-97.566211 125.551305c-6.360248 8.077516-15.709814 12.27528-25.186584 12.275279z"
|
d="M651.353043 550.479503H378.752795L240.862609 364.315031c-3.688944-4.897391-5.660621-10.876025-5.660621-17.045466v-60.040745c0-15.773416 12.847702-28.621118 28.621118-28.621118h502.459627c15.773416 0 28.621118 12.847702 28.621118 28.621118v59.977143c0 6.105839-1.971677 12.084472-5.660621 17.045466l-137.890187 186.228074zM378.752795 598.308571v398.024348c0 15.328199 12.402484 27.667081 27.667081 27.667081h217.266087c15.328199 0 27.667081-12.402484 27.66708-27.667081V598.308571H378.752795z m136.300124 176.942112c-14.564969 0-26.331429-11.76646-26.331428-26.331428v-81.283975c0-14.564969 11.76646-26.331429 26.331428-26.331429 14.564969 0 26.331429 11.76646 26.331429 26.331429v81.283975c0 14.564969-11.76646 26.331429-26.331429 26.331428zM512 222.608696c-17.554286 0-31.801242-14.246957-31.801242-31.801243V31.801242c0-17.554286 14.246957-31.801242 31.801242-31.801242s31.801242 14.246957 31.801242 31.801242v159.006211c0 17.554286-14.246957 31.801242-31.801242 31.801243zM280.932174 205.881242c-9.47677 0-18.889938-4.197764-25.122981-12.275279L158.242981 67.991056a31.864845 31.864845 0 0 1 5.597019-44.648944 31.864845 31.864845 0 0 1 44.648944 5.597018l97.502609 125.551305a31.864845 31.864845 0 0 1-5.597019 44.648944c-5.787826 4.579379-12.656894 6.741863-19.46236 6.741863zM723.987081 205.881242c-6.805466 0-13.674534-2.162484-19.462361-6.678261a31.794882 31.794882 0 0 1-5.597018-44.648944l97.566211-125.551304a31.794882 31.794882 0 0 1 44.648944-5.597019 31.794882 31.794882 0 0 1 5.597019 44.648944l-97.566211 125.551305c-6.360248 8.077516-15.709814 12.27528-25.186584 12.275279z"
|
||||||
fill="#ffffff"
|
fill="#ffffff" p-id="1352"></path>
|
||||||
p-id="1352"
|
|
||||||
></path>
|
|
||||||
</svg>
|
</svg>
|
||||||
{{ trackStatus ? '关闭闪光灯' : '打开闪光灯' }}
|
{{ trackStatus ? '关闭闪光灯' : '打开闪光灯' }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="mask1 mask" :style="'height:' + maskHeight + 'px;'"></view>
|
<view class="mask1 mask" :style="'height:' + maskHeight + 'px;'"></view>
|
||||||
<view
|
<view class="mask2 mask"
|
||||||
class="mask2 mask"
|
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"></view>
|
||||||
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"
|
|
||||||
></view>
|
|
||||||
<view class="mask3 mask" :style="'height:' + maskHeight + 'px;'"></view>
|
<view class="mask3 mask" :style="'height:' + maskHeight + 'px;'"></view>
|
||||||
<view
|
<view class="mask4 mask"
|
||||||
class="mask4 mask"
|
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"></view>
|
||||||
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"
|
|
||||||
></view>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<slot name="error">
|
<slot name="error">
|
||||||
@@ -52,385 +38,389 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import jsQR from './jsQR.js'
|
import jsQR from './jsQR.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
continue: {
|
continue: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false // false 监听一次 true 持续监听
|
default: false // false 监听一次 true 持续监听
|
||||||
|
},
|
||||||
|
exact: {
|
||||||
|
type: String,
|
||||||
|
default: 'environment' // environment 后摄像头 user 前摄像头
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String,
|
||||||
|
default: 'whole' // whole 全屏 balf 半屏
|
||||||
|
},
|
||||||
|
definition: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false // fasle 正常 true 高清
|
||||||
|
},
|
||||||
|
scanWidth: {
|
||||||
|
type: Number,
|
||||||
|
default: 200 // 扫描框宽度
|
||||||
|
},
|
||||||
|
scanHeight: {
|
||||||
|
type: Number,
|
||||||
|
default: 200 // 扫描框高度
|
||||||
|
}
|
||||||
},
|
},
|
||||||
exact: {
|
data() {
|
||||||
type: String,
|
return {
|
||||||
default: 'environment' // environment 后摄像头 user 前摄像头
|
windowWidth: 0,
|
||||||
|
windowHeight: 0,
|
||||||
|
video: null,
|
||||||
|
canvas2d: null,
|
||||||
|
canvas2d2: null,
|
||||||
|
canvasWidth: this.scanWidth,
|
||||||
|
canvasHeight: this.scanHeight,
|
||||||
|
maskWidth: 0,
|
||||||
|
maskHeight: 0,
|
||||||
|
inter: 0,
|
||||||
|
|
||||||
|
track: null,
|
||||||
|
isUseTorch: false,
|
||||||
|
trackStatus: false,
|
||||||
|
|
||||||
|
isParse: false,
|
||||||
|
isUse: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
size: {
|
mounted() {
|
||||||
type: String,
|
if (origin.indexOf('https') === -1) throw '请在 https 环境中使用摄像头组件。'
|
||||||
default: 'whole' // whole 全屏 balf 半屏
|
|
||||||
|
this.windowWidth = document.documentElement.clientWidth || document.body.clientWidth
|
||||||
|
this.windowHeight = document.documentElement.clientHeight || document.body.clientHeight
|
||||||
|
this.windowHeight = this.size === 'whole' ? this.windowHeight : this.windowHeight / 2
|
||||||
|
this.isParse = true
|
||||||
|
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.createMsk()
|
||||||
|
this.openScan()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
definition: {
|
destroyed() {
|
||||||
type: Boolean,
|
this.closeCamera()
|
||||||
default: false // fasle 正常 true 高清
|
},
|
||||||
}
|
methods: {
|
||||||
},
|
openScan() {
|
||||||
data() {
|
const width = this.transtion(this.windowHeight)
|
||||||
return {
|
const height = this.transtion(this.windowWidth)
|
||||||
windowWidth: 0,
|
const videoParam = {
|
||||||
windowHeight: 0,
|
audio: false,
|
||||||
video: null,
|
video: {
|
||||||
canvas2d: null,
|
facingMode: {
|
||||||
canvas2d2: null,
|
exact: this.exact
|
||||||
canvasWidth: 200,
|
},
|
||||||
canvasHeight: 200,
|
width,
|
||||||
maskWidth: 0,
|
height
|
||||||
maskHeight: 0,
|
}
|
||||||
inter: 0,
|
|
||||||
|
|
||||||
track: null,
|
|
||||||
isUseTorch: false,
|
|
||||||
trackStatus: false,
|
|
||||||
|
|
||||||
isParse: false,
|
|
||||||
isUse: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
if (origin.indexOf('https') === -1) throw '请在 https 环境中使用摄像头组件。'
|
|
||||||
|
|
||||||
this.windowWidth = document.documentElement.clientWidth || document.body.clientWidth
|
|
||||||
this.windowHeight = document.documentElement.clientHeight || document.body.clientHeight
|
|
||||||
this.windowHeight = this.size === 'whole' ? this.windowHeight : this.windowHeight / 2
|
|
||||||
this.isParse = true
|
|
||||||
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.createMsk()
|
|
||||||
this.openScan()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
destroyed() {
|
|
||||||
this.closeCamera()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
openScan() {
|
|
||||||
const width = this.transtion(this.windowHeight)
|
|
||||||
const height = this.transtion(this.windowWidth)
|
|
||||||
const videoParam = {
|
|
||||||
audio: false,
|
|
||||||
video: {
|
|
||||||
facingMode: { exact: this.exact },
|
|
||||||
width,
|
|
||||||
height
|
|
||||||
}
|
}
|
||||||
}
|
navigator.mediaDevices
|
||||||
navigator.mediaDevices
|
.getUserMedia(videoParam)
|
||||||
.getUserMedia(videoParam)
|
.then(stream => {
|
||||||
.then(stream => {
|
this.video = document.createElement('video')
|
||||||
this.video = document.createElement('video')
|
this.video.width = this.windowWidth
|
||||||
this.video.width = this.windowWidth
|
this.video.height = this.windowHeight
|
||||||
this.video.height = this.windowHeight
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas')
|
const canvas = document.createElement('canvas')
|
||||||
canvas.id = 'canvas'
|
canvas.id = 'canvas'
|
||||||
canvas.width = this.transtion(this.canvasWidth)
|
canvas.width = this.transtion(this.canvasWidth)
|
||||||
canvas.height = this.transtion(this.canvasHeight)
|
canvas.height = this.transtion(this.canvasHeight)
|
||||||
canvas.style = 'display:none;'
|
canvas.style = 'display:none;'
|
||||||
//canvas.style = 'position: fixed;top: 0;z-index: 999;left:0'
|
//canvas.style = 'position: fixed;top: 0;z-index: 999;left:0'
|
||||||
this.canvas2d = canvas.getContext('2d')
|
this.canvas2d = canvas.getContext('2d')
|
||||||
|
|
||||||
// 设置当前宽高 满屏
|
// 设置当前宽高 满屏
|
||||||
const canvasBox = document.querySelector('.canvasBox')
|
const canvasBox = document.querySelector('.canvasBox')
|
||||||
canvasBox.append(this.video)
|
canvasBox.append(this.video)
|
||||||
canvasBox.append(canvas)
|
canvasBox.append(canvas)
|
||||||
canvasBox.style = `width:${this.windowWidth}px;height:${this.windowHeight}px;`
|
canvasBox.style = `width:${this.windowWidth}px;height:${this.windowHeight}px;`
|
||||||
|
|
||||||
// 创建第二个canvas
|
// 创建第二个canvas
|
||||||
const canvas2 = document.createElement('canvas')
|
const canvas2 = document.createElement('canvas')
|
||||||
canvas2.id = 'canvas2'
|
canvas2.id = 'canvas2'
|
||||||
canvas2.width = this.canvasWidth
|
canvas2.width = this.canvasWidth
|
||||||
canvas2.height = this.canvasHeight
|
canvas2.height = this.canvasHeight
|
||||||
canvas2.style = 'position: absolute;top: 50%;left: 50%;z-index: 20;transform: translate(-50%, -50%);'
|
canvas2.style =
|
||||||
this.canvas2d2 = canvas2.getContext('2d')
|
'position: absolute;top: 50%;left: 50%;z-index: 20;transform: translate(-50%, -50%);'
|
||||||
canvasBox.append(canvas2)
|
this.canvas2d2 = canvas2.getContext('2d')
|
||||||
|
canvasBox.append(canvas2)
|
||||||
|
|
||||||
this.video.srcObject = stream
|
this.video.srcObject = stream
|
||||||
this.video.setAttribute('playsinline', true)
|
this.video.setAttribute('playsinline', true)
|
||||||
this.video.play()
|
this.video.play()
|
||||||
this.tick()
|
this.tick()
|
||||||
|
|
||||||
this.track = stream.getVideoTracks()[0]
|
this.track = stream.getVideoTracks()[0]
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.isUseTorch = this.track.getCapabilities().torch || null
|
this.isUseTorch = this.track.getCapabilities().torch || null
|
||||||
}, 500)
|
}, 500)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.isUse = false
|
this.isUse = false
|
||||||
this.$emit('error', err)
|
this.$emit('error', err)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
closeCamera() {
|
closeCamera() {
|
||||||
this.isParse = false
|
this.isParse = false
|
||||||
if (this.video && this.video.srcObject) {
|
if (this.video && this.video.srcObject) {
|
||||||
this.video.srcObject.getTracks().forEach(track => {
|
this.video.srcObject.getTracks().forEach(track => {
|
||||||
track.stop()
|
track.stop()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
if (!this.isParse) return
|
if (!this.isParse) return
|
||||||
if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {
|
if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {
|
||||||
this.canvas2d.drawImage(
|
this.canvas2d.drawImage(
|
||||||
this.video,
|
this.video,
|
||||||
this.transtion(this.maskWidth),
|
this.transtion(this.maskWidth),
|
||||||
this.transtion(this.maskHeight),
|
this.transtion(this.maskHeight),
|
||||||
this.transtion(200),
|
this.transtion(this.scanWidth),
|
||||||
this.transtion(200),
|
this.transtion(this.scanHeight),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
this.transtion(this.canvasWidth),
|
this.transtion(this.canvasWidth),
|
||||||
this.transtion(this.canvasHeight)
|
this.transtion(this.canvasHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
const imageData = this.canvas2d.getImageData(
|
const imageData = this.canvas2d.getImageData(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
this.transtion(this.canvasWidth),
|
this.transtion(this.canvasWidth),
|
||||||
this.transtion(this.canvasHeight)
|
this.transtion(this.canvasHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
const code = jsQR(imageData.data, imageData.width, imageData.height, {
|
const code = jsQR(imageData.data, imageData.width, imageData.height, {
|
||||||
inversionAttempts: 'dontInvert'
|
inversionAttempts: 'dontInvert'
|
||||||
})
|
})
|
||||||
|
|
||||||
this.canvas2d2.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
|
this.canvas2d2.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
|
||||||
if (code) {
|
if (code) {
|
||||||
this.drawLine(code.location.topLeftCorner, code.location.topRightCorner)
|
this.drawLine(code.location.topLeftCorner, code.location.topRightCorner)
|
||||||
this.drawLine(code.location.topRightCorner, code.location.bottomRightCorner)
|
this.drawLine(code.location.topRightCorner, code.location.bottomRightCorner)
|
||||||
this.drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner)
|
this.drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner)
|
||||||
this.drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner)
|
this.drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner)
|
||||||
if (code.data) {
|
if (code.data) {
|
||||||
this.getData(code.data)
|
this.getData(code.data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
requestAnimationFrame(this.tick)
|
||||||
|
},
|
||||||
|
drawLine(begin, end, color = '#FF3B58') {
|
||||||
|
this.canvas2d2.beginPath()
|
||||||
|
this.canvas2d2.moveTo(this.nutranstion(begin.x), this.nutranstion(begin.y))
|
||||||
|
this.canvas2d2.lineTo(this.nutranstion(end.x), this.nutranstion(end.y))
|
||||||
|
this.canvas2d2.lineWidth = 4
|
||||||
|
this.canvas2d2.strokeStyle = color
|
||||||
|
this.canvas2d2.stroke()
|
||||||
|
},
|
||||||
|
|
||||||
|
getData(data) {
|
||||||
|
this.$emit('success', data)
|
||||||
|
if (!this.continue) {
|
||||||
|
this.closeCamera()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
openTrack() {
|
||||||
|
this.trackStatus = !this.trackStatus
|
||||||
|
this.track.applyConstraints({
|
||||||
|
advanced: [{
|
||||||
|
torch: this.trackStatus
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
createMsk() {
|
||||||
|
this.maskWidth = this.windowWidth / 2 - this.scanWidth / 2
|
||||||
|
this.maskHeight = this.windowHeight / 2 - this.scanHeight / 2
|
||||||
|
},
|
||||||
|
|
||||||
|
transtion(number) {
|
||||||
|
return this.definition ? number * 2.8 : number * 1.8
|
||||||
|
},
|
||||||
|
nutranstion(number) {
|
||||||
|
return this.definition ? number / 2.8 : number / 1.8
|
||||||
}
|
}
|
||||||
requestAnimationFrame(this.tick)
|
|
||||||
},
|
|
||||||
drawLine(begin, end, color = '#FF3B58') {
|
|
||||||
this.canvas2d2.beginPath()
|
|
||||||
this.canvas2d2.moveTo(this.nutranstion(begin.x), this.nutranstion(begin.y))
|
|
||||||
this.canvas2d2.lineTo(this.nutranstion(end.x), this.nutranstion(end.y))
|
|
||||||
this.canvas2d2.lineWidth = 4
|
|
||||||
this.canvas2d2.strokeStyle = color
|
|
||||||
this.canvas2d2.stroke()
|
|
||||||
},
|
|
||||||
|
|
||||||
getData(data) {
|
|
||||||
this.$emit('success', data)
|
|
||||||
if (!this.continue) {
|
|
||||||
this.closeCamera()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
openTrack() {
|
|
||||||
this.trackStatus = !this.trackStatus
|
|
||||||
this.track.applyConstraints({
|
|
||||||
advanced: [{ torch: this.trackStatus }]
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
createMsk() {
|
|
||||||
this.maskWidth = this.windowWidth / 2 - this.canvasWidth / 2
|
|
||||||
this.maskHeight = this.windowHeight / 2 - this.canvasHeight / 2
|
|
||||||
},
|
|
||||||
|
|
||||||
transtion(number) {
|
|
||||||
return this.definition ? number * 2.8 : number * 1.8
|
|
||||||
},
|
|
||||||
nutranstion(number) {
|
|
||||||
return this.definition ? number / 2.8 : number / 1.8
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
page {
|
page {
|
||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.canvasBox {
|
.canvasBox {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
background-image: linear-gradient(
|
background-image: linear-gradient(0deg,
|
||||||
0deg,
|
transparent 24%,
|
||||||
transparent 24%,
|
rgba(32, 255, 77, 0.1) 25%,
|
||||||
rgba(32, 255, 77, 0.1) 25%,
|
rgba(32, 255, 77, 0.1) 26%,
|
||||||
rgba(32, 255, 77, 0.1) 26%,
|
transparent 27%,
|
||||||
transparent 27%,
|
transparent 74%,
|
||||||
transparent 74%,
|
rgba(32, 255, 77, 0.1) 75%,
|
||||||
rgba(32, 255, 77, 0.1) 75%,
|
rgba(32, 255, 77, 0.1) 76%,
|
||||||
rgba(32, 255, 77, 0.1) 76%,
|
transparent 77%,
|
||||||
transparent 77%,
|
transparent),
|
||||||
transparent
|
linear-gradient(90deg,
|
||||||
),
|
transparent 24%,
|
||||||
linear-gradient(
|
rgba(32, 255, 77, 0.1) 25%,
|
||||||
90deg,
|
rgba(32, 255, 77, 0.1) 26%,
|
||||||
transparent 24%,
|
transparent 27%,
|
||||||
rgba(32, 255, 77, 0.1) 25%,
|
transparent 74%,
|
||||||
rgba(32, 255, 77, 0.1) 26%,
|
rgba(32, 255, 77, 0.1) 75%,
|
||||||
transparent 27%,
|
rgba(32, 255, 77, 0.1) 76%,
|
||||||
transparent 74%,
|
transparent 77%,
|
||||||
rgba(32, 255, 77, 0.1) 75%,
|
transparent);
|
||||||
rgba(32, 255, 77, 0.1) 76%,
|
background-size: 3rem 3rem;
|
||||||
transparent 77%,
|
background-position: -1rem -1rem;
|
||||||
transparent
|
z-index: 10;
|
||||||
);
|
background-color: #1110;
|
||||||
background-size: 3rem 3rem;
|
}
|
||||||
background-position: -1rem -1rem;
|
|
||||||
z-index: 10;
|
|
||||||
background-color: #1110;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
.box {
|
||||||
width: 200px;
|
position: absolute;
|
||||||
height: 200px;
|
left: 50%;
|
||||||
position: absolute;
|
top: 50%;
|
||||||
left: 50%;
|
transform: translate(-50%, -50%);
|
||||||
top: 50%;
|
overflow: hidden;
|
||||||
transform: translate(-50%, -50%);
|
border: 0.1rem solid rgba(0, 255, 51, 0.2);
|
||||||
overflow: hidden;
|
z-index: 11;
|
||||||
border: 0.1rem solid rgba(0, 255, 51, 0.2);
|
}
|
||||||
z-index: 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
.line {
|
.line {
|
||||||
height: calc(100% - 2px);
|
height: calc(100% - 2px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: linear-gradient(180deg, rgba(0, 255, 51, 0) 43%, #00ff33 211%);
|
background: linear-gradient(180deg, rgba(0, 255, 51, 0) 43%, #00ff33 211%);
|
||||||
border-bottom: 3px solid #00ff33;
|
border-bottom: 3px solid #00ff33;
|
||||||
transform: translateY(-100%);
|
|
||||||
animation: radar-beam 2s infinite alternate;
|
|
||||||
animation-timing-function: cubic-bezier(0.53, 0, 0.43, 0.99);
|
|
||||||
animation-delay: 1.4s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box:after,
|
|
||||||
.box:before,
|
|
||||||
.angle:after,
|
|
||||||
.angle:before {
|
|
||||||
content: '';
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
width: 3vw;
|
|
||||||
height: 3vw;
|
|
||||||
z-index: 12;
|
|
||||||
border: 0.2rem solid transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box:after,
|
|
||||||
.box:before {
|
|
||||||
top: 0;
|
|
||||||
border-top-color: #00ff33;
|
|
||||||
}
|
|
||||||
|
|
||||||
.angle:after,
|
|
||||||
.angle:before {
|
|
||||||
bottom: 0;
|
|
||||||
border-bottom-color: #00ff33;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box:before,
|
|
||||||
.angle:before {
|
|
||||||
left: 0;
|
|
||||||
border-left-color: #00ff33;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box:after,
|
|
||||||
.angle:after {
|
|
||||||
right: 0;
|
|
||||||
border-right-color: #00ff33;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes radar-beam {
|
|
||||||
0% {
|
|
||||||
transform: translateY(-100%);
|
transform: translateY(-100%);
|
||||||
|
animation: radar-beam 2s infinite alternate;
|
||||||
|
animation-timing-function: cubic-bezier(0.53, 0, 0.43, 0.99);
|
||||||
|
animation-delay: 1.4s;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
.box:after,
|
||||||
transform: translateY(0);
|
.box:before,
|
||||||
|
.angle:after,
|
||||||
|
.angle:before {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
width: 3vw;
|
||||||
|
height: 3vw;
|
||||||
|
z-index: 12;
|
||||||
|
border: 0.2rem solid transparent;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.msg {
|
.box:after,
|
||||||
text-align: center;
|
.box:before {
|
||||||
padding: 20rpx 0;
|
top: 0;
|
||||||
}
|
border-top-color: #00ff33;
|
||||||
|
}
|
||||||
|
|
||||||
.box2 {
|
.angle:after,
|
||||||
width: 300px;
|
.angle:before {
|
||||||
height: 200px;
|
bottom: 0;
|
||||||
position: absolute;
|
border-bottom-color: #00ff33;
|
||||||
left: 50%;
|
}
|
||||||
top: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
z-index: 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
.track {
|
.box:before,
|
||||||
position: absolute;
|
.angle:before {
|
||||||
bottom: -100px;
|
left: 0;
|
||||||
left: 50%;
|
border-left-color: #00ff33;
|
||||||
transform: translateX(-50%);
|
}
|
||||||
z-index: 20;
|
|
||||||
color: #fff;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mask {
|
.box:after,
|
||||||
position: absolute;
|
.angle:after {
|
||||||
z-index: 10;
|
right: 0;
|
||||||
background-color: rgba(0, 0, 0, 0.55);
|
border-right-color: #00ff33;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mask1 {
|
@keyframes radar-beam {
|
||||||
top: 0;
|
0% {
|
||||||
left: 0;
|
transform: translateY(-100%);
|
||||||
right: 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.mask2 {
|
100% {
|
||||||
right: 0;
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.mask3 {
|
.msg {
|
||||||
right: 0;
|
text-align: center;
|
||||||
left: 0;
|
padding: 20rpx 0;
|
||||||
bottom: 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.mask4 {
|
.box2 {
|
||||||
left: 0;
|
position: absolute;
|
||||||
}
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
|
||||||
.error {
|
.track {
|
||||||
color: #fff;
|
position: absolute;
|
||||||
padding: 40rpx;
|
left: 50%;
|
||||||
font-size: 24rpx;
|
transform: translateX(-50%);
|
||||||
background-color: #333333;
|
z-index: 20;
|
||||||
position: fixed;
|
color: #fff;
|
||||||
top: 50%;
|
display: flex;
|
||||||
left: 50%;
|
flex-direction: column;
|
||||||
transform: translate(-50%, -50%);
|
align-items: center;
|
||||||
width: 550rpx;
|
}
|
||||||
border-radius: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.error .on1 {
|
.mask {
|
||||||
font-size: 30rpx;
|
position: absolute;
|
||||||
}
|
z-index: 10;
|
||||||
</style>
|
background-color: rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask1 {
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask2 {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask3 {
|
||||||
|
right: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mask4 {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #fff;
|
||||||
|
padding: 40rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
background-color: #333333;
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
width: 550rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error .on1 {
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user