二维码组件更新
This commit is contained in:
parent
af22fef13c
commit
ae44e8de17
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<!-- 该组件无实际 DOM 结构 -->
|
||||
<div style="display: none;"></div>
|
||||
<!-- 该组件无实际 DOM 结构 -->
|
||||
<div style="display: none"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
|
@ -10,55 +10,65 @@ const emit = defineEmits(['scanSuccess', 'scanError'])
|
|||
|
||||
// 扫描二维码方法
|
||||
const scanQrCode = () => {
|
||||
console.log("扫一扫");
|
||||
console.log("window对象", window);
|
||||
console.log('扫一扫')
|
||||
console.log('window对象', window)
|
||||
|
||||
document.addEventListener("deviceready", onDeviceReady.bind(this), false);
|
||||
document.addEventListener('deviceready', onDeviceReady.bind(this), false)
|
||||
|
||||
function onDeviceReady() {
|
||||
// Cordova is now initialized. Have fun!
|
||||
console.log(
|
||||
"Running cordova-" +
|
||||
window.cordova.platformId +
|
||||
"@" +
|
||||
window.cordova.version
|
||||
);
|
||||
window.cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
emit('scanSuccess', result)
|
||||
console.log("success");
|
||||
console.log(result);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
emit('scanError', new Error(`扫描失败: ${error}`))
|
||||
console.log("error");
|
||||
console.log(error);
|
||||
},
|
||||
{
|
||||
preferFrontCamera: false, // 是否默认使用前置摄像头(同时支持 iOS 和 Android)
|
||||
showFlipCameraButton: true, // 是否显示前后摄像头切换按钮(同时支持 iOS 和 Android)
|
||||
showTorchButton: true, // 是否显示打开关闭闪光灯按钮(同时支持 iOS 和 Android)
|
||||
torchOn: false, // 是否默认打开闪关灯(仅支持 Android)
|
||||
saveHistory: true, // 是否记录扫码历史(仅支持 Android)
|
||||
prompt: "请扫描二维码", // 扫码界面下方提示语(仅支持 Android)
|
||||
resultDisplayDuration: 500, // 扫码文本在扫码界面上显示多少毫秒。0完全禁用。默认1500(仅Android)
|
||||
formats: "QR_CODE,PDF_417", // 支持的格式,默认为除PDF_417和RSS_EXPANDED之外的所有格式
|
||||
orientation: "portrait", // 设置为横向或纵向(portrait|landscape),默认跟随手机旋转(仅Android)
|
||||
disableAnimations: true, // 禁用动画(仅支持 iOS)
|
||||
disableSuccessBeep: false, // 禁用成功蜂鸣声(同时支持 iOS 和 Android)
|
||||
}
|
||||
);
|
||||
}
|
||||
function onDeviceReady() {
|
||||
// Cordova is now initialized. Have fun!
|
||||
// console.log('Running cordova-' + window.cordova.platformId + '@' + window.cordova.version)
|
||||
window.cordova.plugins.zxingScan.startScan(
|
||||
(successResult) => {
|
||||
console.log('🚀 ~ 二维码 ~ successResult:', successResult)
|
||||
emit('scanSuccess', successResult)
|
||||
},
|
||||
(error) => {
|
||||
console.log('🚀 ~ 二维码 ~ error:', error)
|
||||
emit('scanError', new Error(`扫描失败: ${error}`))
|
||||
},
|
||||
{
|
||||
isPlayBeep: true, //是否播放扫描声音
|
||||
isShake: true, //是否震动
|
||||
fullScreenScan: true, //是否全屏
|
||||
},
|
||||
)
|
||||
// window.cordova.plugins.barcodeScanner.scan(
|
||||
// function (result) {
|
||||
// emit('scanSuccess', result)
|
||||
// console.log('success')
|
||||
// console.log(result)
|
||||
// }.bind(this),
|
||||
// function (error) {
|
||||
// emit('scanError', new Error(`扫描失败: ${error}`))
|
||||
// console.log('error')
|
||||
// console.log(error)
|
||||
// },
|
||||
// {
|
||||
// preferFrontCamera: false, // 是否默认使用前置摄像头(同时支持 iOS 和 Android)
|
||||
// showFlipCameraButton: true, // 是否显示前后摄像头切换按钮(同时支持 iOS 和 Android)
|
||||
// showTorchButton: true, // 是否显示打开关闭闪光灯按钮(同时支持 iOS 和 Android)
|
||||
// torchOn: false, // 是否默认打开闪关灯(仅支持 Android)
|
||||
// saveHistory: true, // 是否记录扫码历史(仅支持 Android)
|
||||
// prompt: '请扫描二维码', // 扫码界面下方提示语(仅支持 Android)
|
||||
// resultDisplayDuration: 500, // 扫码文本在扫码界面上显示多少毫秒。0完全禁用。默认1500(仅Android)
|
||||
// formats: 'QR_CODE,PDF_417', // 支持的格式,默认为除PDF_417和RSS_EXPANDED之外的所有格式
|
||||
// orientation: 'portrait', // 设置为横向或纵向(portrait|landscape),默认跟随手机旋转(仅Android)
|
||||
// disableAnimations: true, // 禁用动画(仅支持 iOS)
|
||||
// disableSuccessBeep: false, // 禁用成功蜂鸣声(同时支持 iOS 和 Android)
|
||||
// },
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露扫描方法
|
||||
defineExpose({
|
||||
scanQrCode
|
||||
scanQrCode,
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (!window.cordova) {
|
||||
console.warn('Cordova 未加载,二维码扫描功能可能不可用')
|
||||
}
|
||||
if (!window.cordova) {
|
||||
console.warn('Cordova 未加载,二维码扫描功能可能不可用')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<!-- 该组件无实际 DOM 结构 -->
|
||||
<div style="display: none;"></div>
|
||||
<!-- 该组件无实际 DOM 结构 -->
|
||||
<div style="display: none"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
|
@ -10,55 +10,65 @@ const emit = defineEmits(['scanSuccessBox', 'scanErrorBox'])
|
|||
|
||||
// 扫描二维码方法
|
||||
const scanQrCode = () => {
|
||||
console.log("扫一扫");
|
||||
console.log("window对象", window);
|
||||
console.log('扫一扫')
|
||||
console.log('window对象', window)
|
||||
|
||||
document.addEventListener("deviceready", onDeviceReady.bind(this), false);
|
||||
document.addEventListener('deviceready', onDeviceReady.bind(this), false)
|
||||
|
||||
function onDeviceReady() {
|
||||
// Cordova is now initialized. Have fun!
|
||||
console.log(
|
||||
"Running cordova-" +
|
||||
window.cordova.platformId +
|
||||
"@" +
|
||||
window.cordova.version
|
||||
);
|
||||
window.cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
emit('scanSuccessBox', result)
|
||||
console.log("success");
|
||||
console.log(result);
|
||||
}.bind(this),
|
||||
function (error) {
|
||||
emit('scanErrorBox', new Error(`扫描失败: ${error}`))
|
||||
console.log("error");
|
||||
console.log(error);
|
||||
},
|
||||
{
|
||||
preferFrontCamera: false, // 是否默认使用前置摄像头(同时支持 iOS 和 Android)
|
||||
showFlipCameraButton: true, // 是否显示前后摄像头切换按钮(同时支持 iOS 和 Android)
|
||||
showTorchButton: true, // 是否显示打开关闭闪光灯按钮(同时支持 iOS 和 Android)
|
||||
torchOn: false, // 是否默认打开闪关灯(仅支持 Android)
|
||||
saveHistory: true, // 是否记录扫码历史(仅支持 Android)
|
||||
prompt: "请扫描二维码", // 扫码界面下方提示语(仅支持 Android)
|
||||
resultDisplayDuration: 500, // 扫码文本在扫码界面上显示多少毫秒。0完全禁用。默认1500(仅Android)
|
||||
formats: "QR_CODE,PDF_417", // 支持的格式,默认为除PDF_417和RSS_EXPANDED之外的所有格式
|
||||
orientation: "portrait", // 设置为横向或纵向(portrait|landscape),默认跟随手机旋转(仅Android)
|
||||
disableAnimations: true, // 禁用动画(仅支持 iOS)
|
||||
disableSuccessBeep: false, // 禁用成功蜂鸣声(同时支持 iOS 和 Android)
|
||||
}
|
||||
);
|
||||
}
|
||||
function onDeviceReady() {
|
||||
window.cordova.plugins.zxingScan.startScan(
|
||||
(successResult) => {
|
||||
console.log('🚀 ~ 二维码 ~ successResult:', successResult)
|
||||
emit('scanSuccessBox', successResult)
|
||||
},
|
||||
(error) => {
|
||||
console.log('🚀 ~ 二维码 ~ error:', error)
|
||||
emit('scanErrorBox', new Error(`扫描失败: ${error}`))
|
||||
},
|
||||
{
|
||||
isPlayBeep: true, //是否播放扫描声音
|
||||
isShake: true, //是否震动
|
||||
fullScreenScan: true, //是否全屏
|
||||
},
|
||||
)
|
||||
// Cordova is now initialized. Have fun!
|
||||
// console.log('Running cordova-' + window.cordova.platformId + '@' + window.cordova.version)
|
||||
// window.cordova.plugins.barcodeScanner.scan(
|
||||
// function (result) {
|
||||
// emit('scanSuccessBox', result)
|
||||
// console.log('success')
|
||||
// console.log(result)
|
||||
// }.bind(this),
|
||||
// function (error) {
|
||||
// emit('scanErrorBox', new Error(`扫描失败: ${error}`))
|
||||
// console.log('error')
|
||||
// console.log(error)
|
||||
// },
|
||||
// {
|
||||
// preferFrontCamera: false, // 是否默认使用前置摄像头(同时支持 iOS 和 Android)
|
||||
// showFlipCameraButton: true, // 是否显示前后摄像头切换按钮(同时支持 iOS 和 Android)
|
||||
// showTorchButton: true, // 是否显示打开关闭闪光灯按钮(同时支持 iOS 和 Android)
|
||||
// torchOn: false, // 是否默认打开闪关灯(仅支持 Android)
|
||||
// saveHistory: true, // 是否记录扫码历史(仅支持 Android)
|
||||
// prompt: '请扫描二维码', // 扫码界面下方提示语(仅支持 Android)
|
||||
// resultDisplayDuration: 500, // 扫码文本在扫码界面上显示多少毫秒。0完全禁用。默认1500(仅Android)
|
||||
// formats: 'QR_CODE,PDF_417', // 支持的格式,默认为除PDF_417和RSS_EXPANDED之外的所有格式
|
||||
// orientation: 'portrait', // 设置为横向或纵向(portrait|landscape),默认跟随手机旋转(仅Android)
|
||||
// disableAnimations: true, // 禁用动画(仅支持 iOS)
|
||||
// disableSuccessBeep: false, // 禁用成功蜂鸣声(同时支持 iOS 和 Android)
|
||||
// },
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露扫描方法
|
||||
defineExpose({
|
||||
scanQrCode
|
||||
scanQrCode,
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (!window.cordova) {
|
||||
console.warn('Cordova 未加载,二维码扫描功能可能不可用')
|
||||
}
|
||||
if (!window.cordova) {
|
||||
console.warn('Cordova 未加载,二维码扫描功能可能不可用')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue