Skip to content

Commit 3c72248

Browse files
committed
update: 完善扫码权限判断,ios 上首次还是有问题,需要客户端支持
1 parent c82c5f7 commit 3c72248

File tree

2 files changed

+69
-80
lines changed

2 files changed

+69
-80
lines changed

.editorconfig

Lines changed: 0 additions & 17 deletions
This file was deleted.

pages/API/scan-code/scan-code.vue

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,76 @@
11
<template>
2-
<view>
3-
<page-head :title="title"></page-head>
4-
<view class="uni-padding-wrap uni-common-mt">
5-
<view class="uni-title">扫码结果:</view>
6-
<view class="uni-list" v-if="result">
7-
<view class="uni-cell">
8-
<view class="scan-result">
9-
{{result}}
10-
</view>
11-
</view>
12-
</view>
13-
<view class="uni-btn-v">
14-
<button type="primary" @click="scan">扫一扫</button>
15-
</view>
16-
</view>
17-
</view>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-title">扫码结果:</view>
6+
<view class="uni-list" v-if="result">
7+
<view class="uni-cell">
8+
<view class="scan-result">
9+
{{result}}
10+
</view>
11+
</view>
12+
</view>
13+
<view class="uni-btn-v">
14+
<button type="primary" @click="scan">扫一扫</button>
15+
</view>
16+
</view>
17+
</view>
1818
</template>
1919
<script>
20-
import permision from "@/common/permission.js"
21-
export default {
22-
data() {
23-
return {
24-
title: 'scanCode',
25-
result: ''
26-
}
27-
},
28-
methods: {
29-
scan: function() {
30-
// #ifdef APP-PLUS
31-
if (this.checkPermission() !== 1) {
32-
return;
33-
}
34-
// #endif
35-
uni.scanCode({
36-
success: (res) => {
37-
this.result = res.result
38-
}
39-
});
40-
}
41-
// #ifdef APP-PLUS
42-
,
43-
checkPermission(code) {
44-
let status = permision.getSetting('camera');
45-
if (status === 0 || status === 1) {
46-
status = 1;
47-
} else {
48-
uni.showModal({
49-
content: "需要相机权限",
50-
confirmText: "设置",
51-
success: function(res) {
52-
if (res.confirm) {
53-
permision.gotoAppSetting();
54-
}
55-
}
56-
})
57-
}
58-
return status;
59-
}
60-
// #endif
61-
}
62-
}
20+
import permision from "@/common/permission.js"
21+
export default {
22+
data() {
23+
return {
24+
title: 'scanCode',
25+
result: ''
26+
}
27+
},
28+
methods: {
29+
async scan() {
30+
// #ifdef APP-PLUS
31+
let status = await this.checkPermission();
32+
if (status !== 1) {
33+
return;
34+
}
35+
// #endif
36+
uni.scanCode({
37+
success: (res) => {
38+
this.result = res.result
39+
},
40+
fail: (err) => {
41+
console.log(err)
42+
}
43+
});
44+
}
45+
// #ifdef APP-PLUS
46+
,
47+
async checkPermission(code) {
48+
let status = permision.isIOS ? await permision.requestIOS('camera') :
49+
await permision.requestAndroid('android.permission.CAMERA');
50+
51+
if (status === null || status === 1) {
52+
status = 1;
53+
} else {
54+
uni.showModal({
55+
content: "需要相机权限",
56+
confirmText: "设置",
57+
success: function(res) {
58+
if (res.confirm) {
59+
permision.gotoAppSetting();
60+
}
61+
}
62+
})
63+
}
64+
return status;
65+
}
66+
// #endif
67+
}
68+
}
6369
</script>
6470

6571
<style>
66-
.scan-result {
67-
min-height: 50upx;
68-
line-height: 50upx;
69-
}
72+
.scan-result {
73+
min-height: 50upx;
74+
line-height: 50upx;
75+
}
7076
</style>

0 commit comments

Comments
 (0)