33 changed files with 2245 additions and 2173 deletions
@ -0,0 +1,20 @@ |
|||||
|
function test (){ |
||||
|
console.log('test方法'); |
||||
|
} |
||||
|
|
||||
|
function IsURL(str_url) { |
||||
|
return (/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm).test(str_url); |
||||
|
} |
||||
|
|
||||
|
function AnalysisURL(url) { |
||||
|
return /^(https?:\/\/)([0-9a-z.]+)(:[0-9]+)?([/0-9a-z.]+)?(\?[0-9a-z&=]+)?(#[0-9-a-z]+)?/i.exec(url); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const permission = { |
||||
|
test:test, |
||||
|
IsURL:IsURL, |
||||
|
AnalysisURL:AnalysisURL |
||||
|
} |
||||
|
|
||||
|
module.exports = permission |
||||
@ -0,0 +1,245 @@ |
|||||
|
/// null = 未请求,1 = 已允许,0 = 拒绝|受限, 2 = 系统未开启
|
||||
|
|
||||
|
var isIOS |
||||
|
|
||||
|
function album() { |
||||
|
var result = 0; |
||||
|
var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary"); |
||||
|
var authStatus = PHPhotoLibrary.authorizationStatus(); |
||||
|
if (authStatus === 0) { |
||||
|
result = null; |
||||
|
} else if (authStatus == 3) { |
||||
|
result = 1; |
||||
|
} else { |
||||
|
result = 0; |
||||
|
} |
||||
|
plus.ios.deleteObject(PHPhotoLibrary); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function camera() { |
||||
|
var result = 0; |
||||
|
var AVCaptureDevice = plus.ios.import("AVCaptureDevice"); |
||||
|
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide'); |
||||
|
if (authStatus === 0) { |
||||
|
result = null; |
||||
|
} else if (authStatus == 3) { |
||||
|
result = 1; |
||||
|
} else { |
||||
|
result = 0; |
||||
|
} |
||||
|
plus.ios.deleteObject(AVCaptureDevice); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function location() { |
||||
|
var result = 0; |
||||
|
var cllocationManger = plus.ios.import("CLLocationManager"); |
||||
|
var enable = cllocationManger.locationServicesEnabled(); |
||||
|
var status = cllocationManger.authorizationStatus(); |
||||
|
if (!enable) { |
||||
|
result = 2; |
||||
|
} else if (status === 0) { |
||||
|
result = null; |
||||
|
} else if (status === 3 || status === 4) { |
||||
|
result = 1; |
||||
|
} else { |
||||
|
result = 0; |
||||
|
} |
||||
|
plus.ios.deleteObject(cllocationManger); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function push() { |
||||
|
var result = 0; |
||||
|
var UIApplication = plus.ios.import("UIApplication"); |
||||
|
var app = UIApplication.sharedApplication(); |
||||
|
var enabledTypes = 0; |
||||
|
if (app.currentUserNotificationSettings) { |
||||
|
var settings = app.currentUserNotificationSettings(); |
||||
|
enabledTypes = settings.plusGetAttribute("types"); |
||||
|
if (enabledTypes == 0) { |
||||
|
result = 0; |
||||
|
console.log("推送权限没有开启"); |
||||
|
} else { |
||||
|
result = 1; |
||||
|
console.log("已经开启推送功能!") |
||||
|
} |
||||
|
plus.ios.deleteObject(settings); |
||||
|
} else { |
||||
|
enabledTypes = app.enabledRemoteNotificationTypes(); |
||||
|
if (enabledTypes == 0) { |
||||
|
result = 3; |
||||
|
console.log("推送权限没有开启!"); |
||||
|
} else { |
||||
|
result = 4; |
||||
|
console.log("已经开启推送功能!") |
||||
|
} |
||||
|
} |
||||
|
plus.ios.deleteObject(app); |
||||
|
plus.ios.deleteObject(UIApplication); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function contact() { |
||||
|
var result = 0; |
||||
|
var CNContactStore = plus.ios.import("CNContactStore"); |
||||
|
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0); |
||||
|
if (cnAuthStatus === 0) { |
||||
|
result = null; |
||||
|
} else if (cnAuthStatus == 3) { |
||||
|
result = 1; |
||||
|
} else { |
||||
|
result = 0; |
||||
|
} |
||||
|
plus.ios.deleteObject(CNContactStore); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function record() { |
||||
|
var result = null; |
||||
|
var avaudiosession = plus.ios.import("AVAudioSession"); |
||||
|
var avaudio = avaudiosession.sharedInstance(); |
||||
|
var status = avaudio.recordPermission(); |
||||
|
console.log("permissionStatus:" + status); |
||||
|
if (status === 1970168948) { |
||||
|
result = null; |
||||
|
} else if (status === 1735552628) { |
||||
|
result = 1; |
||||
|
} else { |
||||
|
result = 0; |
||||
|
} |
||||
|
plus.ios.deleteObject(avaudiosession); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function calendar() { |
||||
|
var result = null; |
||||
|
var EKEventStore = plus.ios.import("EKEventStore"); |
||||
|
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0); |
||||
|
if (ekAuthStatus == 3) { |
||||
|
result = 1; |
||||
|
console.log("日历权限已经开启"); |
||||
|
} else { |
||||
|
console.log("日历权限没有开启"); |
||||
|
} |
||||
|
plus.ios.deleteObject(EKEventStore); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
function memo() { |
||||
|
var result = null; |
||||
|
var EKEventStore = plus.ios.import("EKEventStore"); |
||||
|
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1); |
||||
|
if (ekAuthStatus == 3) { |
||||
|
result = 1; |
||||
|
console.log("备忘录权限已经开启"); |
||||
|
} else { |
||||
|
console.log("备忘录权限没有开启"); |
||||
|
} |
||||
|
plus.ios.deleteObject(EKEventStore); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
function requestIOS(permissionID) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
switch (permissionID) { |
||||
|
case "push": |
||||
|
resolve(push()); |
||||
|
break; |
||||
|
case "location": |
||||
|
resolve(location()); |
||||
|
break; |
||||
|
case "record": |
||||
|
resolve(record()); |
||||
|
break; |
||||
|
case "camera": |
||||
|
resolve(camera()); |
||||
|
break; |
||||
|
case "album": |
||||
|
resolve(album()); |
||||
|
break; |
||||
|
case "contact": |
||||
|
resolve(contact()); |
||||
|
break; |
||||
|
case "calendar": |
||||
|
resolve(calendar()); |
||||
|
break; |
||||
|
case "memo": |
||||
|
resolve(memo()); |
||||
|
break; |
||||
|
default: |
||||
|
resolve(0); |
||||
|
break; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function requestAndroid(permissionID) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
plus.android.requestPermissions( |
||||
|
[permissionID], |
||||
|
function(resultObj) { |
||||
|
var result = 0; |
||||
|
for (var i = 0; i < resultObj.granted.length; i++) { |
||||
|
var grantedPermission = resultObj.granted[i]; |
||||
|
console.log('已获取的权限:' + grantedPermission); |
||||
|
result = 1 |
||||
|
} |
||||
|
for (var i = 0; i < resultObj.deniedPresent.length; i++) { |
||||
|
var deniedPresentPermission = resultObj.deniedPresent[i]; |
||||
|
console.log('拒绝本次申请的权限:' + deniedPresentPermission); |
||||
|
result = 0 |
||||
|
} |
||||
|
for (var i = 0; i < resultObj.deniedAlways.length; i++) { |
||||
|
var deniedAlwaysPermission = resultObj.deniedAlways[i]; |
||||
|
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission); |
||||
|
result = -1 |
||||
|
} |
||||
|
resolve(result); |
||||
|
}, |
||||
|
function(error) { |
||||
|
console.log('result error: ' + error.message) |
||||
|
resolve({ |
||||
|
code: error.code, |
||||
|
message: error.message |
||||
|
}); |
||||
|
} |
||||
|
); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function gotoAppPermissionSetting() { |
||||
|
if (permission.isIOS) { |
||||
|
var UIApplication = plus.ios.import("UIApplication"); |
||||
|
var application2 = UIApplication.sharedApplication(); |
||||
|
var NSURL2 = plus.ios.import("NSURL"); |
||||
|
var setting2 = NSURL2.URLWithString("app-settings:"); |
||||
|
application2.openURL(setting2); |
||||
|
plus.ios.deleteObject(setting2); |
||||
|
plus.ios.deleteObject(NSURL2); |
||||
|
plus.ios.deleteObject(application2); |
||||
|
} else { |
||||
|
var Intent = plus.android.importClass("android.content.Intent"); |
||||
|
var Settings = plus.android.importClass("android.provider.Settings"); |
||||
|
var Uri = plus.android.importClass("android.net.Uri"); |
||||
|
var mainActivity = plus.android.runtimeMainActivity(); |
||||
|
var intent = new Intent(); |
||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
||||
|
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); |
||||
|
intent.setData(uri); |
||||
|
mainActivity.startActivity(intent); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const permission = { |
||||
|
get isIOS(){ |
||||
|
return typeof isIOS === 'boolean' ? isIOS : (isIOS = uni.getSystemInfoSync().platform === 'ios') |
||||
|
}, |
||||
|
requestIOS: requestIOS, |
||||
|
requestAndroid: requestAndroid, |
||||
|
gotoAppSetting: gotoAppPermissionSetting |
||||
|
} |
||||
|
|
||||
|
module.exports = permission |
||||
@ -1,315 +0,0 @@ |
|||||
<template> |
|
||||
<div class="page-scan"> |
|
||||
<div class="base-line"> |
|
||||
<div class="pullWrap"> |
|
||||
<div class="topTitle"> |
|
||||
<div class="pullTitle"> |
|
||||
<div class="pullName">二维码绑定</div> |
|
||||
<!-- 绑定状态图标 --> |
|
||||
<img class="left-icon" src="/static/img/noBind.svg" alt="" v-if="!dataObj.qrCodeId"> |
|
||||
<img class="left-icon" src="/static/img/binded.svg" alt="" v-else> |
|
||||
<div class="right-part"> |
|
||||
<input :disabled="dataObj.qrCodeId" type="text" v-model="dataObj.qrCodeId" placeholder="请输入二维码ID" v-if="dataObj.qrCodeId"> |
|
||||
<input type="text" v-model="scanTextData.scanText" placeholder="请输入二维码ID" v-else> |
|
||||
<img src="/static/img/scan.svg" alt="" v-if="!dataObj.qrCodeId"> |
|
||||
<span @click="toScanCode" v-if="!dataObj.qrCodeId">扫码填入</span> |
|
||||
<span v-if="dataObj.qrCodeId">解绑</span> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
<!-- 扫描盒子 --> |
|
||||
<div class="scan-box" v-if="scanTextData.showScanBox"> |
|
||||
<div class="scan-cacel" @click="cancelScan" v-show="scanTextData.showScanBoxInfo"> |
|
||||
<!-- <img src="" alt=""> --> |
|
||||
取消 |
|
||||
</div> |
|
||||
<video ref="video" id="video" class="scan-video" v-show="scanTextData.showScanBoxInfo" autoplay></video> |
|
||||
<div class="scan-img" v-show="scanTextData.showScanBoxInfo"> |
|
||||
<div class="scan-frame"> |
|
||||
<span class="left-t"></span> |
|
||||
<span class="right-t"></span> |
|
||||
<span class="left-b"></span> |
|
||||
<span class="right-b"></span> |
|
||||
<span class="cross-line"></span> |
|
||||
</div> |
|
||||
</div> |
|
||||
<!-- <img src="/static/img/scan.svg" alt="" v-show="scanTextData.showScanBoxInfo"> --> |
|
||||
<div class="scan-tip" v-show="scanTextData.showScanBoxInfo"> {{scanTextData.tipMsg}} </div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</template> |
|
||||
|
|
||||
|
|
||||
<script> |
|
||||
import { BrowserMultiFormatReader } from '@zxing/library'; |
|
||||
let scanTextData = { |
|
||||
loadingShow: false, |
|
||||
codeReader: null, |
|
||||
scanText: '', |
|
||||
vin: null, |
|
||||
tipMsg: '将二维码置于屏幕中,即可识别', |
|
||||
tipShow: false |
|
||||
} |
|
||||
export default { |
|
||||
name: 'scanCodePage', |
|
||||
data() { |
|
||||
return { |
|
||||
scanTextData:{ |
|
||||
loadingShow: false, |
|
||||
codeReader: null, |
|
||||
scanText: '', |
|
||||
vin: null, |
|
||||
tipMsg: '将二维码置于屏幕中,即可识别', |
|
||||
tipShow: false, |
|
||||
|
|
||||
showScanBox:false, |
|
||||
showScanBoxInfo:false, |
|
||||
}, |
|
||||
hasBind:false |
|
||||
} |
|
||||
}, |
|
||||
methods: { |
|
||||
toScanCode(){ |
|
||||
console.log('识别二维码',this.dataObj) |
|
||||
scanTextData.codeReader = new BrowserMultiFormatReader(); |
|
||||
this.scanTextData.showScanBox = true |
|
||||
this.openScan(); |
|
||||
|
|
||||
}, |
|
||||
cancelScan(){ |
|
||||
//识别完停止使用摄像头 |
|
||||
let thisVideo = document.getElementById("video"); |
|
||||
thisVideo.srcObject.getTracks()[0].stop() |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
this.scanTextData.showScanBox = false |
|
||||
setTimeout(()=>{ |
|
||||
this.scanTextData.showScanBoxInfo = false |
|
||||
},1000) |
|
||||
}, |
|
||||
|
|
||||
async openScan() { |
|
||||
scanTextData.codeReader.getVideoInputDevices().then((videoInputDevices) => { |
|
||||
scanTextData.tipShow = true; |
|
||||
scanTextData.tipMsg = '正在调用摄像头...'; |
|
||||
console.log('videoInputDevices', videoInputDevices); |
|
||||
// 默认获取第一个摄像头设备id |
|
||||
let firstDeviceId = videoInputDevices[0].deviceId; |
|
||||
// 获取第一个摄像头设备的名称 |
|
||||
const videoInputDeviceslablestr = JSON.stringify(videoInputDevices[0].label); |
|
||||
if (videoInputDevices.length > 1) { |
|
||||
// 判断是否后置摄像头 |
|
||||
if (videoInputDeviceslablestr.indexOf('back') > -1) { |
|
||||
firstDeviceId = videoInputDevices[0].deviceId; |
|
||||
} else { |
|
||||
firstDeviceId = videoInputDevices[1].deviceId; |
|
||||
} |
|
||||
} |
|
||||
this.decodeFromInputVideoFunc(firstDeviceId); |
|
||||
}).catch(err => { |
|
||||
scanTextData.tipShow = false; |
|
||||
console.error(err); |
|
||||
}); |
|
||||
}, |
|
||||
decodeFromInputVideoFunc(firstDeviceId) { |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
scanTextData.scanText = ''; |
|
||||
scanTextData.codeReader.decodeFromInputVideoDeviceContinuously(firstDeviceId, 'video', (result, err) => { |
|
||||
scanTextData.tipMsg = '将二维码置于屏幕中,即可识别'; |
|
||||
scanTextData.scanText = ''; |
|
||||
setTimeout(()=>{ |
|
||||
this.scanTextData.showScanBoxInfo = true |
|
||||
},1000) |
|
||||
if (result) { |
|
||||
console.log('扫描结果', result.text); |
|
||||
if (result.text) { |
|
||||
console.log('扫描结果11', result.text); |
|
||||
this.scanTextData.showScanBox = false |
|
||||
this.scanTextData.showScanBoxInfo = false |
|
||||
this.scanTextData.scanText = result.text |
|
||||
//这里扫描出结果可以调用你想要的方法 |
|
||||
//识别完停止使用摄像头 |
|
||||
let thisVideo = document.getElementById("video"); |
|
||||
thisVideo.srcObject.getTracks()[0].stop() |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
} |
|
||||
}else{ |
|
||||
// console.log('没出来?',result,err) |
|
||||
} |
|
||||
if (err && !(err)) { |
|
||||
scanTextData.tipMsg = '识别失败'; |
|
||||
setTimeout(() => { |
|
||||
scanTextData.tipShow = false; |
|
||||
}, 2000) |
|
||||
console.error(err); |
|
||||
} |
|
||||
}); |
|
||||
}, |
|
||||
|
|
||||
}, |
|
||||
props:['dataObj'] |
|
||||
} |
|
||||
</script> |
|
||||
|
|
||||
|
|
||||
<style scoped lang="scss"> |
|
||||
.pullWrap { |
|
||||
width: 100%; |
|
||||
height: 100px; |
|
||||
padding-top: 50px; |
|
||||
background: #fff; |
|
||||
} |
|
||||
.topTitle { |
|
||||
width: 100%; |
|
||||
position: relative; |
|
||||
} |
|
||||
.pullTitle { |
|
||||
display: flex; |
|
||||
height: 80px; |
|
||||
line-height: 80px; |
|
||||
margin-top: -40px; |
|
||||
background: #fff; |
|
||||
align-items: center; |
|
||||
justify-content: space-between; |
|
||||
} |
|
||||
.pullName{ |
|
||||
font-size: 30px; |
|
||||
color: rgba(0,0,0,0.85); |
|
||||
} |
|
||||
img{ |
|
||||
width: 40px; |
|
||||
height: 40px; |
|
||||
} |
|
||||
.left-icon{ |
|
||||
margin:0 15px; |
|
||||
} |
|
||||
span{ |
|
||||
text-decoration: underline; |
|
||||
text-decoration-color: #42a5ff; |
|
||||
color: #42a5ff; |
|
||||
margin-left: 5px; |
|
||||
} |
|
||||
.right-part { |
|
||||
flex: 1; |
|
||||
display: flex; |
|
||||
align-items: center; |
|
||||
justify-content: space-around; |
|
||||
border-bottom: 1px solid #e5e5e5; |
|
||||
overflow: hidden; |
|
||||
text-overflow: ellipsis; |
|
||||
} |
|
||||
input{ |
|
||||
border:none; |
|
||||
flex: 1; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
.scan-index-bar{ |
|
||||
background-image: linear-gradient( -45deg, #42a5ff ,#59cfff); |
|
||||
} |
|
||||
.van-nav-bar__title{ |
|
||||
color: #fff !important; |
|
||||
} |
|
||||
.scan-box { |
|
||||
position: fixed; |
|
||||
top: 0; |
|
||||
left: 0; |
|
||||
z-index: 5; |
|
||||
height: 100%; |
|
||||
width: 100vw; |
|
||||
} |
|
||||
.scan-cacel{ |
|
||||
position: absolute; |
|
||||
top: 30px; |
|
||||
left: 30px; |
|
||||
z-index: 9; |
|
||||
color: #fff; |
|
||||
font-size: 35px; |
|
||||
|
|
||||
} |
|
||||
.scan-video{ |
|
||||
height: 100vh; |
|
||||
width: 100vw; |
|
||||
object-fit:cover; |
|
||||
} |
|
||||
.scan-img { |
|
||||
width: 500px; |
|
||||
height: 500px; |
|
||||
position: fixed; |
|
||||
top: 40%; |
|
||||
left: 50%; |
|
||||
margin-top: -200px; |
|
||||
margin-left: -250px; |
|
||||
z-index: 6; |
|
||||
} |
|
||||
.scan-frame { |
|
||||
width: 100%; |
|
||||
height: 100%; |
|
||||
position: relative; |
|
||||
} |
|
||||
.left-t,.right-t,.left-b,.right-b{ |
|
||||
position: absolute; |
|
||||
width: 80px; |
|
||||
height: 80px; |
|
||||
} |
|
||||
.left-t{ |
|
||||
top: 0; |
|
||||
left: 0; |
|
||||
border-top:2px solid #17B1B7; |
|
||||
border-left:2px solid #17B1B7; |
|
||||
} |
|
||||
.right-t{ |
|
||||
top: 0; |
|
||||
right: 0; |
|
||||
border-top:2px solid #17B1B7; |
|
||||
border-right:2px solid #17B1B7; |
|
||||
} |
|
||||
.left-b{ |
|
||||
bottom: 0; |
|
||||
left: 0; |
|
||||
border-bottom:2px solid #17B1B7; |
|
||||
border-left:2px solid #17B1B7; |
|
||||
} |
|
||||
.right-b{ |
|
||||
bottom: 0; |
|
||||
right: 0; |
|
||||
border-bottom:2px solid #17B1B7; |
|
||||
border-right:2px solid #17B1B7; |
|
||||
} |
|
||||
.cross-line{ |
|
||||
width: 600px; |
|
||||
height: 10px; |
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0),#5DDDD3,rgba(255,255,255,0)); |
|
||||
position: absolute; |
|
||||
top: 0; |
|
||||
left: -50px; |
|
||||
animation: identifier_p 5s infinite; |
|
||||
} |
|
||||
@keyframes identifier_p { |
|
||||
0%{ |
|
||||
top: 0%; |
|
||||
} |
|
||||
50%{ |
|
||||
top: 100%; |
|
||||
} |
|
||||
100%{ |
|
||||
top: 0; |
|
||||
} |
|
||||
} |
|
||||
.scan-tip{ |
|
||||
width: 100vw; |
|
||||
text-align: center; |
|
||||
margin-bottom: 10vh; |
|
||||
color: white; |
|
||||
font-size: 5vw; |
|
||||
position: absolute; |
|
||||
bottom: 50px; |
|
||||
left: 0; |
|
||||
color: #fff; |
|
||||
} |
|
||||
.page-scan{ |
|
||||
overflow-y: hidden; |
|
||||
// background-color: #363636; |
|
||||
} |
|
||||
</style> |
|
||||
@ -1,315 +0,0 @@ |
|||||
<template> |
|
||||
<div class="page-scan"> |
|
||||
<div class="base-line"> |
|
||||
<div class="pullWrap"> |
|
||||
<div class="topTitle"> |
|
||||
<div class="pullTitle"> |
|
||||
<div class="pullName">二维码绑定</div> |
|
||||
<!-- 绑定状态图标 --> |
|
||||
<img class="left-icon" src="/static/img/noBind.svg" alt="" v-if="!dataObj.qrCodeId"> |
|
||||
<img class="left-icon" src="/static/img/binded.svg" alt="" v-else> |
|
||||
<div class="right-part"> |
|
||||
<input :disabled="dataObj.qrCodeId" type="text" v-model="dataObj.qrCodeId" placeholder="请输入二维码ID" v-if="dataObj.qrCodeId"> |
|
||||
<input type="text" v-model="scanTextData.scanText" placeholder="请输入二维码ID" v-else> |
|
||||
<img src="/static/img/scan.svg" alt="" v-if="!dataObj.qrCodeId"> |
|
||||
<span @click="toScanCode" v-if="!dataObj.qrCodeId">扫码填入</span> |
|
||||
<span v-if="dataObj.qrCodeId">解绑</span> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
<!-- 扫描盒子 --> |
|
||||
<div class="scan-box" v-if="scanTextData.showScanBox"> |
|
||||
<div class="scan-cacel" @click="cancelScan" v-show="scanTextData.showScanBoxInfo"> |
|
||||
<!-- <img src="" alt=""> --> |
|
||||
取消 |
|
||||
</div> |
|
||||
<video ref="video" id="video" class="scan-video" v-show="scanTextData.showScanBoxInfo" autoplay></video> |
|
||||
<div class="scan-img" v-show="scanTextData.showScanBoxInfo"> |
|
||||
<div class="scan-frame"> |
|
||||
<span class="left-t"></span> |
|
||||
<span class="right-t"></span> |
|
||||
<span class="left-b"></span> |
|
||||
<span class="right-b"></span> |
|
||||
<span class="cross-line"></span> |
|
||||
</div> |
|
||||
</div> |
|
||||
<!-- <img src="/static/img/scan.svg" alt="" v-show="scanTextData.showScanBoxInfo"> --> |
|
||||
<div class="scan-tip" v-show="scanTextData.showScanBoxInfo"> {{scanTextData.tipMsg}} </div> |
|
||||
</div> |
|
||||
</div> |
|
||||
</template> |
|
||||
|
|
||||
|
|
||||
<script> |
|
||||
import { BrowserMultiFormatReader } from '@zxing/library'; |
|
||||
let scanTextData = { |
|
||||
loadingShow: false, |
|
||||
codeReader: null, |
|
||||
scanText: '', |
|
||||
vin: null, |
|
||||
tipMsg: '将二维码置于屏幕中,即可识别', |
|
||||
tipShow: false |
|
||||
} |
|
||||
export default { |
|
||||
name: 'scanCodePage', |
|
||||
data() { |
|
||||
return { |
|
||||
scanTextData:{ |
|
||||
loadingShow: false, |
|
||||
codeReader: null, |
|
||||
scanText: '', |
|
||||
vin: null, |
|
||||
tipMsg: '将二维码置于屏幕中,即可识别', |
|
||||
tipShow: false, |
|
||||
|
|
||||
showScanBox:false, |
|
||||
showScanBoxInfo:false, |
|
||||
}, |
|
||||
hasBind:false |
|
||||
} |
|
||||
}, |
|
||||
methods: { |
|
||||
toScanCode(){ |
|
||||
console.log('识别二维码',this.dataObj) |
|
||||
scanTextData.codeReader = new BrowserMultiFormatReader(); |
|
||||
this.scanTextData.showScanBox = true |
|
||||
this.openScan(); |
|
||||
|
|
||||
}, |
|
||||
cancelScan(){ |
|
||||
//识别完停止使用摄像头 |
|
||||
let thisVideo = document.getElementById("video"); |
|
||||
thisVideo.srcObject.getTracks()[0].stop() |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
this.scanTextData.showScanBox = false |
|
||||
setTimeout(()=>{ |
|
||||
this.scanTextData.showScanBoxInfo = false |
|
||||
},1000) |
|
||||
}, |
|
||||
|
|
||||
async openScan() { |
|
||||
scanTextData.codeReader.getVideoInputDevices().then((videoInputDevices) => { |
|
||||
scanTextData.tipShow = true; |
|
||||
scanTextData.tipMsg = '正在调用摄像头...'; |
|
||||
console.log('videoInputDevices', videoInputDevices); |
|
||||
// 默认获取第一个摄像头设备id |
|
||||
let firstDeviceId = videoInputDevices[0].deviceId; |
|
||||
// 获取第一个摄像头设备的名称 |
|
||||
const videoInputDeviceslablestr = JSON.stringify(videoInputDevices[0].label); |
|
||||
if (videoInputDevices.length > 1) { |
|
||||
// 判断是否后置摄像头 |
|
||||
if (videoInputDeviceslablestr.indexOf('back') > -1) { |
|
||||
firstDeviceId = videoInputDevices[0].deviceId; |
|
||||
} else { |
|
||||
firstDeviceId = videoInputDevices[1].deviceId; |
|
||||
} |
|
||||
} |
|
||||
this.decodeFromInputVideoFunc(firstDeviceId); |
|
||||
}).catch(err => { |
|
||||
scanTextData.tipShow = false; |
|
||||
console.error(err); |
|
||||
}); |
|
||||
}, |
|
||||
decodeFromInputVideoFunc(firstDeviceId) { |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
scanTextData.scanText = ''; |
|
||||
scanTextData.codeReader.decodeFromInputVideoDeviceContinuously(firstDeviceId, 'video', (result, err) => { |
|
||||
scanTextData.tipMsg = '将二维码置于屏幕中,即可识别'; |
|
||||
scanTextData.scanText = ''; |
|
||||
setTimeout(()=>{ |
|
||||
this.scanTextData.showScanBoxInfo = true |
|
||||
},1000) |
|
||||
if (result) { |
|
||||
console.log('扫描结果', result.text); |
|
||||
if (result.text) { |
|
||||
console.log('扫描结果11', result.text); |
|
||||
this.scanTextData.showScanBox = false |
|
||||
this.scanTextData.showScanBoxInfo = false |
|
||||
this.scanTextData.scanText = result.text |
|
||||
//这里扫描出结果可以调用你想要的方法 |
|
||||
//识别完停止使用摄像头 |
|
||||
let thisVideo = document.getElementById("video"); |
|
||||
thisVideo.srcObject.getTracks()[0].stop() |
|
||||
scanTextData.codeReader.reset(); // 重置 |
|
||||
} |
|
||||
}else{ |
|
||||
// console.log('没出来?',result,err) |
|
||||
} |
|
||||
if (err && !(err)) { |
|
||||
scanTextData.tipMsg = '识别失败'; |
|
||||
setTimeout(() => { |
|
||||
scanTextData.tipShow = false; |
|
||||
}, 2000) |
|
||||
console.error(err); |
|
||||
} |
|
||||
}); |
|
||||
}, |
|
||||
|
|
||||
}, |
|
||||
props:['dataObj'] |
|
||||
} |
|
||||
</script> |
|
||||
|
|
||||
|
|
||||
<style scoped lang="scss"> |
|
||||
.pullWrap { |
|
||||
width: 100%; |
|
||||
height: 100px; |
|
||||
padding-top: 50px; |
|
||||
background: #fff; |
|
||||
} |
|
||||
.topTitle { |
|
||||
width: 100%; |
|
||||
position: relative; |
|
||||
} |
|
||||
.pullTitle { |
|
||||
display: flex; |
|
||||
height: 80px; |
|
||||
line-height: 80px; |
|
||||
margin-top: -40px; |
|
||||
background: #fff; |
|
||||
align-items: center; |
|
||||
justify-content: space-between; |
|
||||
} |
|
||||
.pullName{ |
|
||||
font-size: 30px; |
|
||||
color: rgba(0,0,0,0.85); |
|
||||
} |
|
||||
img{ |
|
||||
width: 40px; |
|
||||
height: 40px; |
|
||||
} |
|
||||
.left-icon{ |
|
||||
margin:0 15px; |
|
||||
} |
|
||||
span{ |
|
||||
text-decoration: underline; |
|
||||
text-decoration-color: #42a5ff; |
|
||||
color: #42a5ff; |
|
||||
margin-left: 5px; |
|
||||
} |
|
||||
.right-part { |
|
||||
flex: 1; |
|
||||
display: flex; |
|
||||
align-items: center; |
|
||||
justify-content: space-around; |
|
||||
border-bottom: 1px solid #e5e5e5; |
|
||||
overflow: hidden; |
|
||||
text-overflow: ellipsis; |
|
||||
} |
|
||||
input{ |
|
||||
border:none; |
|
||||
flex: 1; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
.scan-index-bar{ |
|
||||
background-image: linear-gradient( -45deg, #42a5ff ,#59cfff); |
|
||||
} |
|
||||
.van-nav-bar__title{ |
|
||||
color: #fff !important; |
|
||||
} |
|
||||
.scan-box { |
|
||||
position: fixed; |
|
||||
top: 0; |
|
||||
left: 0; |
|
||||
z-index: 5; |
|
||||
height: 100%; |
|
||||
width: 100vw; |
|
||||
} |
|
||||
.scan-cacel{ |
|
||||
position: absolute; |
|
||||
top: 30px; |
|
||||
left: 30px; |
|
||||
z-index: 9; |
|
||||
color: #fff; |
|
||||
font-size: 35px; |
|
||||
|
|
||||
} |
|
||||
.scan-video{ |
|
||||
height: 100vh; |
|
||||
width: 100vw; |
|
||||
object-fit:cover; |
|
||||
} |
|
||||
.scan-img { |
|
||||
width: 500px; |
|
||||
height: 500px; |
|
||||
position: fixed; |
|
||||
top: 40%; |
|
||||
left: 50%; |
|
||||
margin-top: -200px; |
|
||||
margin-left: -250px; |
|
||||
z-index: 6; |
|
||||
} |
|
||||
.scan-frame { |
|
||||
width: 100%; |
|
||||
height: 100%; |
|
||||
position: relative; |
|
||||
} |
|
||||
.left-t,.right-t,.left-b,.right-b{ |
|
||||
position: absolute; |
|
||||
width: 80px; |
|
||||
height: 80px; |
|
||||
} |
|
||||
.left-t{ |
|
||||
top: 0; |
|
||||
left: 0; |
|
||||
border-top:2px solid #17B1B7; |
|
||||
border-left:2px solid #17B1B7; |
|
||||
} |
|
||||
.right-t{ |
|
||||
top: 0; |
|
||||
right: 0; |
|
||||
border-top:2px solid #17B1B7; |
|
||||
border-right:2px solid #17B1B7; |
|
||||
} |
|
||||
.left-b{ |
|
||||
bottom: 0; |
|
||||
left: 0; |
|
||||
border-bottom:2px solid #17B1B7; |
|
||||
border-left:2px solid #17B1B7; |
|
||||
} |
|
||||
.right-b{ |
|
||||
bottom: 0; |
|
||||
right: 0; |
|
||||
border-bottom:2px solid #17B1B7; |
|
||||
border-right:2px solid #17B1B7; |
|
||||
} |
|
||||
.cross-line{ |
|
||||
width: 600px; |
|
||||
height: 10px; |
|
||||
background: linear-gradient(to right, rgba(255, 255, 255, 0),#5DDDD3,rgba(255,255,255,0)); |
|
||||
position: absolute; |
|
||||
top: 0; |
|
||||
left: -50px; |
|
||||
animation: identifier_p 5s infinite; |
|
||||
} |
|
||||
@keyframes identifier_p { |
|
||||
0%{ |
|
||||
top: 0%; |
|
||||
} |
|
||||
50%{ |
|
||||
top: 100%; |
|
||||
} |
|
||||
100%{ |
|
||||
top: 0; |
|
||||
} |
|
||||
} |
|
||||
.scan-tip{ |
|
||||
width: 100vw; |
|
||||
text-align: center; |
|
||||
margin-bottom: 10vh; |
|
||||
color: white; |
|
||||
font-size: 5vw; |
|
||||
position: absolute; |
|
||||
bottom: 50px; |
|
||||
left: 0; |
|
||||
color: #fff; |
|
||||
} |
|
||||
.page-scan{ |
|
||||
overflow-y: hidden; |
|
||||
// background-color: #363636; |
|
||||
} |
|
||||
</style> |
|
||||
Loading…
Reference in new issue