Skip to content

Commit a09b9f7

Browse files
committed
update: 仅app平台加载权限API,修复相机,相册权限判断不准确问题
1 parent 0305c5f commit a09b9f7

File tree

5 files changed

+154
-142
lines changed

5 files changed

+154
-142
lines changed

pages/API/add-phone-contact/add-phone-contact.vue

Lines changed: 92 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,100 @@
11
<template>
2-
<view>
3-
<page-head :title="title"></page-head>
4-
<view class="uni-common-mt">
5-
<view class="uni-list">
6-
<view class="uni-list-cell">
7-
<view class="uni-list-cell-left">
8-
<view class="uni-label">名称</view>
9-
</view>
10-
<view class="uni-list-cell-db">
11-
<input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"></input>
12-
</view>
13-
</view>
14-
<view class="uni-list-cell">
15-
<view class="uni-list-cell-left">
16-
<view class="uni-label">手机号</view>
17-
</view>
18-
<view class="uni-list-cell-db">
19-
<input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"></input>
20-
</view>
21-
</view>
22-
</view>
23-
<view class="uni-padding-wrap">
24-
<view class="uni-btn-v">
25-
<button type="primary" class="btn-setstorage" @tap="add">添加联系人</button>
26-
</view>
27-
</view>
28-
</view>
29-
</view>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-common-mt">
5+
<view class="uni-list">
6+
<view class="uni-list-cell">
7+
<view class="uni-list-cell-left">
8+
<view class="uni-label">名称</view>
9+
</view>
10+
<view class="uni-list-cell-db">
11+
<input class="uni-input" type="text" placeholder="请输入联系人名称" name="name" :value="name" @input="nameChange"></input>
12+
</view>
13+
</view>
14+
<view class="uni-list-cell">
15+
<view class="uni-list-cell-left">
16+
<view class="uni-label">手机号</view>
17+
</view>
18+
<view class="uni-list-cell-db">
19+
<input class="uni-input" type="text" placeholder="请输入联系人手机号" name="phone" :value="phone" @input="phoneChange"></input>
20+
</view>
21+
</view>
22+
</view>
23+
<view class="uni-padding-wrap">
24+
<view class="uni-btn-v">
25+
<button type="primary" class="btn-setstorage" @tap="add">添加联系人</button>
26+
</view>
27+
</view>
28+
</view>
29+
</view>
3030
</template>
3131
<script>
32-
import permision from "@/common/permission.js"
33-
export default {
34-
data() {
35-
return {
36-
title: 'addPhoneContact',
37-
name: '',
38-
phone: ''
39-
}
40-
},
41-
methods: {
42-
nameChange: function(e) {
43-
this.name = e.detail.value
44-
},
45-
phoneChange: function(e) {
46-
this.phone = e.detail.value
47-
},
48-
add() {
49-
// #ifdef APP-PLUS
50-
if (this.checkPermission() !== 1) {
51-
return;
52-
}
53-
// #endif
32+
// #ifdef APP-PLUS
33+
import permision from "@/common/permission.js"
34+
// #endif
35+
export default {
36+
data() {
37+
return {
38+
title: 'addPhoneContact',
39+
name: '',
40+
phone: ''
41+
}
42+
},
43+
methods: {
44+
nameChange: function(e) {
45+
this.name = e.detail.value
46+
},
47+
phoneChange: function(e) {
48+
this.phone = e.detail.value
49+
},
50+
add() {
51+
// #ifdef APP-PLUS
52+
if (this.checkPermission() !== 1) {
53+
return;
54+
}
55+
// #endif
5456
55-
uni.addPhoneContact({
56-
firstName: this.name,
57-
mobilePhoneNumber: this.phone,
58-
success: function() {
59-
uni.showModal({
60-
content: '已成功添加联系人!',
61-
showCancel: false
62-
})
63-
},
64-
fail: function() {
65-
uni.showModal({
66-
content: '添加联系人失败!',
67-
showCancel: false
68-
})
69-
}
70-
});
71-
}
72-
// #ifdef APP-PLUS
73-
,
74-
async checkPermission() {
75-
let status = permision.isIOS ? await permision.requestIOS('contact') :
76-
await permision.requestAndroid('android.permission.WRITE_CONTACTS');
57+
uni.addPhoneContact({
58+
firstName: this.name,
59+
mobilePhoneNumber: this.phone,
60+
success: function() {
61+
uni.showModal({
62+
content: '已成功添加联系人!',
63+
showCancel: false
64+
})
65+
},
66+
fail: function() {
67+
uni.showModal({
68+
content: '添加联系人失败!',
69+
showCancel: false
70+
})
71+
}
72+
});
73+
}
74+
// #ifdef APP-PLUS
75+
,
76+
async checkPermission() {
77+
let status = permision.isIOS ? await permision.requestIOS('contact') :
78+
await permision.requestAndroid('android.permission.WRITE_CONTACTS');
7779
78-
if (status === null || status === 1) {
79-
status = 1;
80-
} else {
81-
uni.showModal({
82-
content: "需要联系人权限",
83-
confirmText: "设置",
84-
success: function(res) {
85-
if (res.confirm) {
86-
permision.gotoAppSetting();
87-
}
88-
}
89-
})
90-
}
91-
return status;
92-
}
93-
// #endif
94-
}
95-
}
80+
if (status === null || status === 1) {
81+
status = 1;
82+
} else {
83+
uni.showModal({
84+
content: "需要联系人权限",
85+
confirmText: "设置",
86+
success: function(res) {
87+
if (res.confirm) {
88+
permision.gotoAppSetting();
89+
}
90+
}
91+
})
92+
}
93+
return status;
94+
}
95+
// #endif
96+
}
97+
}
9698
</script>
9799

98100
<style>

pages/API/get-location/get-location.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
</template>
3333
<script>
3434
import uniPopup from '@/components/uni-popup/uni-popup.vue'
35-
import permision from "@/common/permission.js"
3635
var util = require('../../../common/util.js');
37-
var formatLocation = util.formatLocation;
36+
var formatLocation = util.formatLocation;
37+
// #ifdef APP-PLUS
38+
import permision from "@/common/permission.js"
39+
// #endif
3840
3941
export default {
4042
components: {

pages/API/image/image.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@
6565
</view>
6666
</view>
6767
</template>
68-
<script>
69-
import permision from "@/common/permission.js"
68+
<script>
69+
// #ifdef APP-PLUS
70+
import permision from "@/common/permission.js"
71+
// #endif
7072
var sourceType = [
7173
['camera'],
7274
['album'],
@@ -170,7 +172,7 @@
170172
},
171173
async checkPermission(code) {
172174
let type = code ? code - 1 : this.sourceTypeIndex;
173-
let status = permision.isIOS ? await permision.requestIOS(sourceType[type]) :
175+
let status = permision.isIOS ? await permision.requestIOS(sourceType[type][0]) :
174176
await permision.requestAndroid(type === 0 ? 'android.permission.CAMERA' :
175177
'android.permission.READ_EXTERNAL_STORAGE');
176178

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

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,62 @@
1313
</view>
1414
</template>
1515
<script>
16-
import permision from '@/common/permission.js';
17-
export default {
18-
data() {
19-
return {
20-
title: 'scanCode',
21-
result: ''
22-
};
23-
},
24-
methods: {
25-
async scan() {
26-
// #ifdef APP-PLUS
27-
let status = await this.checkPermission();
28-
if (status !== 1) {
29-
return;
30-
}
31-
// #endif
32-
uni.scanCode({
33-
success: res => {
34-
this.result = res.result;
35-
},
36-
fail: err => {
37-
console.log(err);
38-
}
39-
});
16+
// #ifdef APP-PLUS
17+
import permision from "@/common/permission.js"
18+
// #endif
19+
export default {
20+
data() {
21+
return {
22+
title: 'scanCode',
23+
result: ''
24+
};
4025
},
41-
// #ifdef APP-PLUS
42-
async checkPermission(code) {
43-
let status = permision.isIOS ? await permision.requestIOS('camera') : await permision.requestAndroid('android.permission.CAMERA');
44-
45-
if (status === null || 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-
}
26+
methods: {
27+
async scan() {
28+
// #ifdef APP-PLUS
29+
let status = await this.checkPermission();
30+
if (status !== 1) {
31+
return;
32+
}
33+
// #endif
34+
uni.scanCode({
35+
success: res => {
36+
this.result = res.result;
37+
},
38+
fail: err => {
39+
console.log(err);
5540
}
5641
});
5742
}
58-
return status;
43+
// #ifdef APP-PLUS
44+
,
45+
async checkPermission(code) {
46+
let status = permision.isIOS ? await permision.requestIOS('camera') : await permision.requestAndroid(
47+
'android.permission.CAMERA');
48+
49+
if (status === null || status === 1) {
50+
status = 1;
51+
} else {
52+
uni.showModal({
53+
content: '需要相机权限',
54+
confirmText: '设置',
55+
success: function(res) {
56+
if (res.confirm) {
57+
permision.gotoAppSetting();
58+
}
59+
}
60+
});
61+
}
62+
return status;
63+
}
64+
// #endif
5965
}
60-
// #endif
61-
}
62-
};
66+
};
6367
</script>
6468

6569
<style>
66-
.scan-result {
67-
min-height: 50upx;
68-
line-height: 50upx;
69-
}
70+
.scan-result {
71+
min-height: 50upx;
72+
line-height: 50upx;
73+
}
7074
</style>

pages/API/voice/voice.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@
5858
</view>
5959
</template>
6060
<script>
61+
// #ifdef APP-PLUS
62+
import permision from "@/common/permission.js"
63+
// #endif
6164
var util = require('../../../common/util.js')
62-
import permision from "@/common/permission.js"
6365
var playTimeInterval = null;
6466
var recordTimeInterval = null;
6567
var recorderManager = null;

0 commit comments

Comments
 (0)