Forráskód Böngészése

维护一个电话监听的状态

chenyidong 4 hónap óta
szülő
commit
0201ddf5a7
5 módosított fájl, 108 hozzáadás és 5 törlés
  1. 2 1
      App.vue
  2. 24 0
      pages/circumstances/index.vue
  3. 4 3
      pages/setting/index.vue
  4. 73 1
      store/modules/call.js
  5. 5 0
      store/modules/user.js

+ 2 - 1
App.vue

@@ -59,7 +59,8 @@
59
 			});
59
 			});
60
 
60
 
61
 			// this.addFlags();
61
 			// this.addFlags();
62
-
62
+			
63
+			this.$store.dispatch("call/startPhoneListener");
63
 
64
 
64
 
65
 
65
 			// #endif
66
 			// #endif

+ 24 - 0
pages/circumstances/index.vue

@@ -138,6 +138,17 @@
138
 					<icon-img :value="hasReadPhoneNumbersPermission"></icon-img>
138
 					<icon-img :value="hasReadPhoneNumbersPermission"></icon-img>
139
 				</view>
139
 				</view>
140
 			</view>
140
 			</view>
141
+			<!-- 电话监听状态 -->
142
+			<view class="option_item">
143
+				<view class="item_left">
144
+					<text class="label">电话监听</text>
145
+				</view>
146
+				<view class="item-right">
147
+					<text v-if="isPhoneListening">监听中</text>
148
+					<text class="btn" v-else @click="togglePhoneListener">点击开始</text>
149
+					<icon-img :value="isPhoneListening"></icon-img>
150
+				</view>
151
+			</view>
141
 			<view class="option_item">
152
 			<view class="option_item">
142
 				<view class="item_left">
153
 				<view class="item_left">
143
 					<text class="label">定位服务</text>
154
 					<text class="label">定位服务</text>
@@ -229,6 +240,7 @@
229
 				hasCallPhonePermission: (state) => state.call.hasCallPhonePermission,
240
 				hasCallPhonePermission: (state) => state.call.hasCallPhonePermission,
230
 				hasReadCallLogPermission: (state) => state.call.hasReadCallLogPermission,
241
 				hasReadCallLogPermission: (state) => state.call.hasReadCallLogPermission,
231
 				hasReadPhoneNumbersPermission: (state) => state.call.hasReadPhoneNumbersPermission,
242
 				hasReadPhoneNumbersPermission: (state) => state.call.hasReadPhoneNumbersPermission,
243
+				isPhoneListening: (state) => state.call.isPhoneListening,
232
 			}),
244
 			}),
233
 		},
245
 		},
234
 		data() {
246
 		data() {
@@ -263,6 +275,18 @@
263
 			toSystemRecorderSettings() {
275
 			toSystemRecorderSettings() {
264
 				this.$store.dispatch('call/toSystemRecorderSettings');
276
 				this.$store.dispatch('call/toSystemRecorderSettings');
265
 			},
277
 			},
278
+			// 切换电话监听状态
279
+			togglePhoneListener() {
280
+				this.$store.dispatch('call/togglePhoneListener')
281
+					.then(() => {
282
+						const status = this.isPhoneListening ? '已停止' : '已启动';
283
+						uni.$u.toast(`电话监听${status}`);
284
+					})
285
+					.catch(error => {
286
+						uni.$u.toast('操作失败,请重试');
287
+						console.error('切换电话监听状态失败:', error);
288
+					});
289
+			},
266
 			// 注册
290
 			// 注册
267
 			handleRegisterFun() {
291
 			handleRegisterFun() {
268
 				this.$store
292
 				this.$store

+ 4 - 3
pages/setting/index.vue

@@ -64,9 +64,10 @@
64
 				this.showModal = true;
64
 				this.showModal = true;
65
 			},
65
 			},
66
 			confirm() {
66
 			confirm() {
67
-				// 如果有没保存的催记直接清掉
68
-				this.$store.commit("follow/SET_FORM", {});
69
-				this.$store.commit("follow/SET_PARAMS", {});
67
+				// 停止电话监听
68
+				this.$store.dispatch("call/stopPhoneListener").catch(error => {
69
+					console.error('退出登录时停止电话监听失败:', error);
70
+				});
70
 				
71
 				
71
 				this.$store.dispatch("user/logout").then(()=>{
72
 				this.$store.dispatch("user/logout").then(()=>{
72
 					uni.$u.toast("退出成功");
73
 					uni.$u.toast("退出成功");

+ 73 - 1
store/modules/call.js

@@ -8,7 +8,7 @@ import {
8
 	allRecorderFilesAction
8
 	allRecorderFilesAction
9
 } from '@/uni_modules/yao-lister';
9
 } from '@/uni_modules/yao-lister';
10
 import permision from "@/js_sdk/wa-permission/permission.js";
10
 import permision from "@/js_sdk/wa-permission/permission.js";
11
-import { formatPhoneNumber } from '../../utils/util';
11
+import { formatPhoneNumber, simpleDebounce } from '../../utils/util';
12
 
12
 
13
 export default {
13
 export default {
14
 	namespaced: true,
14
 	namespaced: true,
@@ -20,6 +20,7 @@ export default {
20
 		hasCallPhonePermission: false, // 拨打电话权限
20
 		hasCallPhonePermission: false, // 拨打电话权限
21
 		hasReadCallLogPermission: false, // 读取通话记录权限
21
 		hasReadCallLogPermission: false, // 读取通话记录权限
22
 		hasReadPhoneNumbersPermission: false, // 读取电话号码权限
22
 		hasReadPhoneNumbersPermission: false, // 读取电话号码权限
23
+		isPhoneListening: false, // 电话监听状态
23
 		form: {
24
 		form: {
24
 			clueId: undefined,
25
 			clueId: undefined,
25
 			fileUrl : undefined,
26
 			fileUrl : undefined,
@@ -52,6 +53,9 @@ export default {
52
 		SET_READ_PHONE_NUMBERS_PERMISSION: (state, value) => {
53
 		SET_READ_PHONE_NUMBERS_PERMISSION: (state, value) => {
53
 			state.hasReadPhoneNumbersPermission = value;
54
 			state.hasReadPhoneNumbersPermission = value;
54
 		},
55
 		},
56
+		SET_PHONE_LISTENING_STATUS: (state, value) => {
57
+			state.isPhoneListening = value;
58
+		},
55
 		SET_CALLER_PHONE: (state, phoneNumber) => {
59
 		SET_CALLER_PHONE: (state, phoneNumber) => {
56
 			state.form.caller = phoneNumber;
60
 			state.form.caller = phoneNumber;
57
 		},
61
 		},
@@ -303,6 +307,74 @@ export default {
303
 		// 打开系统设置
307
 		// 打开系统设置
304
 		handleOpenSet() {
308
 		handleOpenSet() {
305
 			permision.gotoAppPermissionSetting('android.permission.RECORD_AUDIO');
309
 			permision.gotoAppPermissionSetting('android.permission.RECORD_AUDIO');
310
+		},
311
+
312
+		// 启动电话监听
313
+		startPhoneListener({ commit, dispatch , state }) {
314
+			try {
315
+				if(state.isPhoneListening){
316
+					// 已经开启监听就不要了
317
+					return;
318
+				}
319
+				dispatch("checkAllPermissions").finally(()=>{
320
+					startPhoneListener(res => {
321
+						simpleDebounce(()=>{
322
+							// 毕竟重复监听 套一个防抖
323
+							dispatch("handleCallBack");
324
+						},500)
325
+						// 14:44:54.429 空闲状态,  监听结果============================== at store/modules/call.js:324
326
+						
327
+						// 14:47:29.570 state=12== 2 13417106969
328
+						
329
+						// 14:47:29.570 phoneState 通话中
330
+						
331
+						// 14:47:29.571 通话中,  监听结果============================== at store/modules/call.js:324
332
+						
333
+						// 14:47:35.712 state=12== 0 13417106969
334
+						
335
+						// 14:47:35.713 phoneState 空闲状态
336
+						
337
+						// 14:47:35.728 空闲状态,  监听结果============================== at store/modules/call.js:324
338
+						
339
+						// 14:47:36.220 state=12== 0 13417106969
340
+						
341
+						// 14:47:36.220 phoneState 空闲状态
342
+						
343
+						// 14:47:36.220 空闲状态,  监听结果============================== at store/modules/call.js:324
344
+						console.log(res, "监听结果==============================");
345
+						commit('SET_PHONE_LISTENING_STATUS', true);
346
+					});
347
+				});
348
+			} catch (error) {
349
+				console.error('启动电话监听失败:', error);
350
+				commit('SET_PHONE_LISTENING_STATUS', false);
351
+				throw error;
352
+			}
353
+		},
354
+		handleCallBack(){
355
+			
356
+		},
357
+		// 停止电话监听
358
+		stopPhoneListener({ commit }) {
359
+			try {
360
+				stopPhoneListener(res => {
361
+					console.log(res, "3123123123");
362
+					commit('SET_PHONE_LISTENING_STATUS', false);
363
+				});
364
+			} catch (error) {
365
+				console.error('停止电话监听失败:', error);
366
+				commit('SET_PHONE_LISTENING_STATUS', false);
367
+				throw error;
368
+			}
369
+		},
370
+
371
+		// 切换电话监听状态
372
+		togglePhoneListener({ state, dispatch }) {
373
+			if (state.isPhoneListening) {
374
+				return dispatch('stopPhoneListener');
375
+			} else {
376
+				return dispatch('startPhoneListener');
377
+			}
306
 		}
378
 		}
307
 	},
379
 	},
308
 }
380
 }

+ 5 - 0
store/modules/user.js

@@ -143,6 +143,11 @@ export default {
143
 			dispatch
143
 			dispatch
144
 		}) {
144
 		}) {
145
 			return uni.$u.api.logout().then(() => {
145
 			return uni.$u.api.logout().then(() => {
146
+				// 停止电话监听
147
+				dispatch("call/stopPhoneListener", null, { root: true }).catch(error => {
148
+					console.error('退出登录时停止电话监听失败:', error);
149
+				});
150
+				
146
 				commit("SET_TOKEN", "");
151
 				commit("SET_TOKEN", "");
147
 				commit("SET_USERINFO", {});
152
 				commit("SET_USERINFO", {});
148
 				dispatch("app/logoutCloseData", null, {
153
 				dispatch("app/logoutCloseData", null, {