+2
-2
@@ -2,8 +2,8 @@
|
|||||||
"name" : "Operations",
|
"name" : "Operations",
|
||||||
"appid" : "__UNI__8A0DE5E",
|
"appid" : "__UNI__8A0DE5E",
|
||||||
"description" : "Operations(运营)的缩写,一个前后端分离的工作流/运营管理系统。",
|
"description" : "Operations(运营)的缩写,一个前后端分离的工作流/运营管理系统。",
|
||||||
"versionName" : "1.0.1",
|
"versionName" : "1.2.1",
|
||||||
"versionCode" : "101",
|
"versionCode" : 121,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
"app-plus" : {
|
"app-plus" : {
|
||||||
"usingComponents" : true,
|
"usingComponents" : true,
|
||||||
|
|||||||
+71
-25
@@ -270,34 +270,81 @@ function onScan() {
|
|||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
// 使用 5+ API 直接调用原生扫码
|
// App 端使用 5+ API 检查并申请相机权限
|
||||||
const barcode = plus.barcode.create('barcode', [plus.barcode.CODE128, plus.barcode.CODE39, plus.barcode.EAN13, plus.barcode.QR], {
|
const osName = plus.os.name
|
||||||
top: '0',
|
if (osName === 'Android') {
|
||||||
left: '0',
|
const main = plus.android.runtimeMainActivity()
|
||||||
width: '100%',
|
const ContextCompat = plus.android.importClass('androidx.core.content.ContextCompat')
|
||||||
height: '100%',
|
const Manifest = plus.android.importClass('android.Manifest$permission')
|
||||||
position: 'static',
|
const permission = Manifest.CAMERA
|
||||||
frameColor: '#007AFF',
|
const result = ContextCompat.checkSelfPermission(main, permission)
|
||||||
scanbarColor: '#007AFF'
|
const PackageManager = plus.android.importClass('android.content.pm.PackageManager')
|
||||||
})
|
if (result !== PackageManager.PERMISSION_GRANTED) {
|
||||||
barcode.onmarked = (type, result) => {
|
// 没有权限,申请权限
|
||||||
console.log('扫码结果:', type, result)
|
plus.android.requestPermissions(['android.permission.CAMERA'], (e) => {
|
||||||
barcode.close()
|
if (e.deniedAlways.length > 0) {
|
||||||
keyword.value = result
|
// 永久拒绝,引导去设置
|
||||||
doSearch()
|
uni.showModal({
|
||||||
|
title: '需要相机权限',
|
||||||
|
content: '请在系统设置中开启相机权限后再使用扫码功能',
|
||||||
|
confirmText: '去设置',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
if (plus.os.name === 'Android') {
|
||||||
|
const Intent = plus.android.importClass('android.content.Intent')
|
||||||
|
const Settings = plus.android.importClass('android.provider.Settings')
|
||||||
|
const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
const Uri = plus.android.importClass('android.net.Uri')
|
||||||
|
intent.setData(Uri.fromParts('package', main.getPackageName(), null))
|
||||||
|
main.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (e.granted.length > 0) {
|
||||||
|
// 授权成功,调用扫码
|
||||||
|
callScan()
|
||||||
|
}
|
||||||
|
}, (e) => {
|
||||||
|
console.error('申请权限失败', e)
|
||||||
|
callScan()
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
barcode.onerror = (err) => {
|
// iOS 或已有权限,直接调用扫码
|
||||||
console.error('扫码错误:', err)
|
callScan()
|
||||||
barcode.close()
|
|
||||||
uni.showToast({ title: '扫码失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
// 创建并显示扫码页面
|
|
||||||
const page = plus.webview.currentWebview()
|
|
||||||
page.append(barcode)
|
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
uni.getSetting({
|
||||||
|
success: (res) => {
|
||||||
|
if (res.authSetting['scope.camera'] === false) {
|
||||||
|
uni.showModal({
|
||||||
|
title: '需要相机权限',
|
||||||
|
content: '扫码功能需要相机权限,请在设置中开启',
|
||||||
|
success: (modalRes) => {
|
||||||
|
if (modalRes.confirm) {
|
||||||
|
uni.openSetting()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
callScan()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
callScan()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用扫码
|
||||||
|
function callScan() {
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
scanType: ['barCode', 'qrCode'],
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('扫码结果:', res)
|
console.log('扫码结果:', res)
|
||||||
keyword.value = res.result
|
keyword.value = res.result
|
||||||
@@ -306,10 +353,9 @@ function onScan() {
|
|||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('扫码失败', err)
|
console.error('扫码失败', err)
|
||||||
if (err.errMsg && err.errMsg.includes('cancel')) return
|
if (err.errMsg && err.errMsg.includes('cancel')) return
|
||||||
uni.showToast({ title: '扫码失败', icon: 'none' })
|
uni.showToast({ title: '扫码失败: ' + (err.errMsg || '未知错误'), icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// #endif
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user