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