Skip to content

Commit c82c5f7

Browse files
committed
fix: 未完善的权限判断 列表双击打开多次问题 移除tabbar页面loading
1 parent aab37be commit c82c5f7

10 files changed

Lines changed: 135 additions & 67 deletions

File tree

common/permission.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function location() {
4141
result = 2;
4242
} else if (status === 0) {
4343
result = null;
44-
} else if (status === 3) {
44+
} else if (status === 3 || status === 4) {
4545
result = 1;
4646
} else {
4747
result = 0;
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
<template>
22
<view class="uni-padding-wrap">
33
<page-head :title="title"></page-head>
4-
<button class="button" @click="setTabBarBadge">
5-
{{ !hasSetTabBarBadge ? '设置tab徽标' : '移除tab徽标' }}
6-
</button>
7-
<button class="button" @click="showTabBarRedDot">
8-
{{ !hasShownTabBarRedDot ? '显示红点' : '移除红点'}}
9-
</button>
10-
<button class="button" @click="customStyle">
11-
{{ !hasCustomedStyle ? '自定义Tab样式' : '移除自定义样式'}}
12-
</button>
13-
<button class="button" @click="customItem">
14-
{{ !hasCustomedItem ? '自定义Tab信息' : '移除自定义信息' }}
15-
</button>
16-
<button class="button" @click="hideTabBar">
17-
{{ !hasHiddenTabBar ? '隐藏TabBar' : '显示TabBar' }}
18-
</button>
4+
<button class="button" @click="setTabBarBadge">{{ !hasSetTabBarBadge ? '设置tab徽标' : '移除tab徽标' }}</button>
5+
<button class="button" @click="showTabBarRedDot">{{ !hasShownTabBarRedDot ? '显示红点' : '移除红点'}}</button>
6+
<button class="button" @click="customStyle">{{ !hasCustomedStyle ? '自定义Tab样式' : '移除自定义样式'}}</button>
7+
<button class="button" @click="customItem">{{ !hasCustomedItem ? '自定义Tab信息' : '移除自定义信息' }}</button>
8+
<button class="button" @click="hideTabBar">{{ !hasHiddenTabBar ? '隐藏TabBar' : '显示TabBar' }}</button>
199
<view class="btn-area">
2010
<button class="button" type="primary" @click="navigateBack">返回上一级</button>
2111
</view>
@@ -156,6 +146,8 @@
156146
<style>
157147
.button {
158148
margin-top: 30upx;
149+
margin-left: 0;
150+
margin-right: 0;
159151
}
160152

161153
.btn-area {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
this.type = '';
6060
},
6161
async getLocation() {
62-
// #ifdef APP-PLUS
63-
if (this.checkPermission() !== 1) {
62+
// #ifdef APP-PLUS
63+
let status = await this.checkPermission();
64+
if (status !== 1) {
6465
return;
6566
}
6667
// #endif
@@ -130,7 +131,7 @@
130131
},
131132
async checkPermission() {
132133
let status = permision.isIOS ? await permision.requestIOS('location') :
133-
await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
134+
await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
134135
135136
if (status === null || status === 1) {
136137
status = 1;

pages/API/image/image.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@
111111
chooseImage: async function() {
112112
// #ifdef APP-PLUS
113113
// TODO 选择相机或相册时 需要弹出actionsheet,目前无法获得是相机还是相册,在失败回调中处理
114-
if (this.sourceTypeIndex !== 2) {
115-
if (this.checkPermission() === 0) {
116-
return;
114+
if (this.sourceTypeIndex !== 2) {
115+
let status = await this.checkPermission();
116+
if (status !== 1) {
117+
return;
117118
}
118119
}
119120
// #endif

pages/API/voice/voice.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
recorderManager = uni.getRecorderManager();
9595
recorderManager.onStart(() => {
9696
console.log('recorder start');
97+
98+
this.recording = true;
99+
recordTimeInterval = setInterval(() => {
100+
this.recordTime += 1;
101+
this.formatedRecordTime = util.formatTime(this.recordTime);
102+
}, 1000)
97103
});
98104
recorderManager.onStop((res) => {
99105
console.log('on stop');
@@ -102,21 +108,20 @@
102108
this.hasRecord = true;
103109
this.recording = false;
104110
});
111+
recorderManager.onError(() => {
112+
console.log('recorder onError');
113+
});
105114
},
106115
methods: {
107-
startRecord() { //开始录音
116+
async startRecord() { //开始录音
108117
// #ifdef APP-PLUS
109-
if (this.checkPermission() !== 1) {
118+
let status = await this.checkPermission();
119+
if (status !== 1) {
110120
return;
111121
}
112122
// #endif
113123
114-
this.recording = true;
115-
recordTimeInterval = setInterval(() => {
116-
this.recordTime += 1;
117-
this.formatedRecordTime = util.formatTime(this.recordTime);
118-
}, 1000)
119-
124+
// TODO ios 在没有请求过权限之前无法得知是否有相关权限,这种状态下需要直接调用录音,但没有状态或回调判断用户拒绝
120125
recorderManager.start({
121126
format: 'mp3'
122127
});

pages/tabBar/API/API.nvue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</template>
3030
<script>
3131
import uLink from '@/components/uLink.vue'
32-
import setTabBar from '@/components/api-set-tabbar.vue';
32+
import setTabBar from '@/components/api-set-tabbar.nvue';
3333
export default {
3434
components: {
3535
uLink,
@@ -328,7 +328,8 @@
328328
];
329329
return {
330330
showSetTabBarPage: false,
331-
list: list
331+
list: list,
332+
navigateFlag: false
332333
};
333334
},
334335
onShareAppMessage() {
@@ -343,16 +344,11 @@
343344
});
344345
},
345346
onLoad() {
346-
// #ifdef APP-PLUS
347-
plus.nativeUI.showWaiting('加载中……');
348-
// #endif
349347
},
350348
onReady() {
351-
// #ifdef APP-PLUS
352-
plus.nativeUI.closeWaiting();
353-
// #endif
354349
},
355350
onShow() {
351+
this.navigateFlag = false;
356352
this.leaveSetTabBarPage();
357353
},
358354
onHide() {
@@ -373,6 +369,10 @@
373369
}
374370
},
375371
goDetailPage(e) {
372+
if (this.navigateFlag) {
373+
return;
374+
}
375+
this.navigateFlag = true;
376376
if (e === 'set-tabbar') {
377377
this.showSetTabBarPage = true;
378378
return;
@@ -383,6 +383,9 @@
383383
});
384384
},
385385
leaveSetTabBarPage() {
386+
setTimeout(() => {
387+
this.navigateFlag = false;
388+
}, 200)
386389
this.showSetTabBarPage = false;
387390
}
388391
}

pages/tabBar/component/component.nvue

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
pages: ['web-view']
111111
},
112112
// #endif
113-
]
113+
],
114+
navigateFlag: false
114115
}
115116
},
116117
onShareAppMessage() {
@@ -139,16 +140,22 @@
139140
}
140141
},
141142
goDetailPage(e) {
142-
if (true)
143-
if (typeof e === 'string') {
144-
uni.navigateTo({
145-
url: '/pages/component/' + e + '/' + e
146-
})
147-
} else {
148-
uni.navigateTo({
149-
url: e.url
150-
})
151-
}
143+
if (this.navigateFlag) {
144+
return;
145+
}
146+
this.navigateFlag = true;
147+
if (typeof e === 'string') {
148+
uni.navigateTo({
149+
url: '/pages/component/' + e + '/' + e
150+
})
151+
} else {
152+
uni.navigateTo({
153+
url: e.url
154+
})
155+
}
156+
setTimeout(() => {
157+
this.navigateFlag = false;
158+
}, 200)
152159
}
153160
}
154161
}

pages/tabBar/extUI/extUI.nvue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
name: "Tag 标签",
118118
url: "tag"
119119
}
120-
]
120+
],
121+
navigateFlag: false
121122
};
122123
},
123124
onLoad() {
@@ -137,9 +138,16 @@
137138
},
138139
methods: {
139140
goDetailPage(path) {
141+
if (this.navigateFlag) {
142+
return;
143+
}
144+
this.navigateFlag = true;
140145
uni.navigateTo({
141146
url: '/pages/extUI/' + path + '/' + path
142147
});
148+
setTimeout(() => {
149+
this.navigateFlag = false;
150+
}, 200)
143151
}
144152
}
145153
}

pages/tabBar/template/template.nvue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,13 @@
166166
url: 'vant-button'
167167
}
168168
// #endif
169-
]
169+
],
170+
navigateFlag: false
170171
}
171172
},
172173
onLoad() {
173-
// #ifdef APP-PLUS
174-
plus.nativeUI.showWaiting('加载中……');
175-
// #endif
176174
},
177175
onReady() {
178-
// #ifdef APP-PLUS
179-
plus.nativeUI.closeWaiting();
180-
// #endif
181176
},
182177
onShareAppMessage() {
183178
return {
@@ -205,11 +200,18 @@
205200
}
206201
},
207202
goDetailPage(e) {
203+
if (this.navigateFlag) {
204+
return;
205+
}
206+
this.navigateFlag = true;
208207
let path = e.url ? e.url : e;
209208
let url = ~path.indexOf('platform') ? path : '/pages/template/' + path + '/' + path;
210209
uni.navigateTo({
211210
url: url
212211
});
212+
setTimeout(() => {
213+
this.navigateFlag = false;
214+
}, 200)
213215
return false;
214216
}
215217
}

platforms/app-plus/speech/speech.vue

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
2-
<view>
3-
<page-head :title="title"></page-head>
4-
<view class="uni-padding-wrap uni-common-mt">
5-
<view class="uni-textarea">
6-
<textarea :value="value" placeholder="语音识别内容展示区域" disabled />
7-
</view>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<view class="uni-textarea">
6+
<textarea :value="value" placeholder="语音识别内容展示区域" disabled />
7+
</view>
88
<view class="uni-common-mt uni-btn-v">
99
<button type="primary" @tap="startRecognize">开始语音识别</button>
1010
<button type="primary" @tap="startRecognizeEnglish">开始语音识别(英语)</button>
@@ -13,6 +13,7 @@
1313
</view>
1414
</template>
1515
<script>
16+
import permision from "@/common/permission.js"
1617
export default {
1718
data() {
1819
return {
@@ -24,7 +25,15 @@
2425
this.value = ""
2526
},
2627
methods: {
27-
startRecognize: function () {
28+
async startRecognize () {
29+
// #ifdef APP-PLUS
30+
let status = await this.checkPermission();
31+
if (status !== 1) {
32+
return;
33+
}
34+
// #endif
35+
36+
// TODO ios 在没有请求过权限之前无法得知是否有相关权限,这种状态下需要直接调用语音,会弹出正在识别的toast
2837
var options = {};
2938
var that = this;
3039
options.engine = 'baidu';
@@ -36,7 +45,15 @@
3645
console.log("语音识别失败:" + e.message);
3746
});
3847
},
39-
startRecognizeEnglish: function () {
48+
async startRecognizeEnglish () {
49+
// #ifdef APP-PLUS
50+
let status = await this.checkPermission();
51+
if (status !== 1) {
52+
return;
53+
}
54+
// #endif
55+
56+
// TODO ios 在没有请求过权限之前无法得知是否有相关权限,这种状态下需要直接调用语音,会弹出正在识别的toast
4057
var options = {};
4158
var that = this;
4259
options.engine = 'baidu';
@@ -49,10 +66,42 @@
4966
console.log("语音识别失败:" + e.message);
5067
});
5168
}
69+
// #ifdef APP-PLUS
70+
,
71+
async checkPermission() {
72+
let status = permision.isIOS ? await permision.requestIOS('record') :
73+
await permision.requestAndroid('android.permission.RECORD_AUDIO');
74+
75+
if (status === null || status === 1) {
76+
status = 1;
77+
} else if (status === 2) {
78+
uni.showModal({
79+
content: "系统麦克风已关闭",
80+
confirmText: "设置",
81+
success: function(res) {
82+
if (res.confirm) {
83+
permision.gotoiOSSetting();
84+
}
85+
}
86+
})
87+
} else {
88+
uni.showModal({
89+
content: "需要麦克风权限",
90+
confirmText: "设置",
91+
success: function(res) {
92+
if (res.confirm) {
93+
permision.gotoAppSetting();
94+
}
95+
}
96+
})
97+
}
98+
return status;
99+
}
100+
// #endif
52101
}
53102
}
54103
</script>
55104

56105
<style>
57-
58-
</style>
106+
107+
</style>

0 commit comments

Comments
 (0)