| 
									
										
										
										
											2024-10-09 13:34:36 +08:00
										 |  |  |  | <template> | 
					
						
							|  |  |  |  | 	<view class="content"> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	</view> | 
					
						
							|  |  |  |  | </template> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2024-10-25 18:52:01 +08:00
										 |  |  |  | 	import {getToken,getUserInfo} from "@/utils/auth"; | 
					
						
							| 
									
										
										
										
											2024-11-13 10:34:57 +08:00
										 |  |  |  |   import request from '@/utils/request'; | 
					
						
							|  |  |  |  |   let innerAudioContext =''; | 
					
						
							| 
									
										
										
										
											2024-10-31 13:57:02 +08:00
										 |  |  |  |     const keepAlivePlugin = uni.requireNativePlugin('Ba-KeepAlive') | 
					
						
							| 
									
										
										
										
											2024-10-09 13:34:36 +08:00
										 |  |  |  | 	export default { | 
					
						
							|  |  |  |  | 		data() { | 
					
						
							|  |  |  |  | 			return { | 
					
						
							| 
									
										
										
										
											2024-11-13 10:34:57 +08:00
										 |  |  |  |         // 是否正在播放
 | 
					
						
							|  |  |  |  |         ifPlay:false, | 
					
						
							| 
									
										
										
										
											2024-10-30 18:14:19 +08:00
										 |  |  |  | 				keepLive: { | 
					
						
							|  |  |  |  | 					channelId: 'Ba-KeepAlive', | 
					
						
							|  |  |  |  | 					channelName: "Ba-KeepAlive", | 
					
						
							|  |  |  |  | 					title: "汽修小助手正在运行", | 
					
						
							|  |  |  |  | 					content: "汽修小助手正在运行", | 
					
						
							|  |  |  |  | 					dataResult: "", | 
					
						
							|  |  |  |  | 					type: undefined | 
					
						
							|  |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-10-09 13:34:36 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-11-15 16:25:48 +08:00
										 |  |  |  |     onLoad() { | 
					
						
							|  |  |  |  |       // #ifdef APP
 | 
					
						
							|  |  |  |  |       //保活技术
 | 
					
						
							|  |  |  |  |       this.register() | 
					
						
							|  |  |  |  |       // #endif
 | 
					
						
							|  |  |  |  |       if (getToken()) { | 
					
						
							| 
									
										
										
										
											2024-11-13 10:34:57 +08:00
										 |  |  |  |         this.getNoReadNum() | 
					
						
							| 
									
										
										
										
											2024-10-17 15:22:37 +08:00
										 |  |  |  |         //跳转首页
 | 
					
						
							| 
									
										
										
										
											2024-10-25 18:52:01 +08:00
										 |  |  |  |         //判断是否是仓管,仓管需要跳单独的首页
 | 
					
						
							|  |  |  |  |         let userInfo = getUserInfo() | 
					
						
							| 
									
										
										
										
											2024-11-15 16:25:48 +08:00
										 |  |  |  |         if (userInfo.roleCodes.includes('repair_warehouse')) { | 
					
						
							| 
									
										
										
										
											2024-10-25 18:52:01 +08:00
										 |  |  |  |           //仓管
 | 
					
						
							|  |  |  |  |           uni.navigateTo({ | 
					
						
							|  |  |  |  |             url: '/pages-warehouse/home/home' | 
					
						
							|  |  |  |  |           }) | 
					
						
							| 
									
										
										
										
											2024-11-15 16:25:48 +08:00
										 |  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2024-10-25 18:52:01 +08:00
										 |  |  |  |           uni.navigateTo({ | 
					
						
							|  |  |  |  |             url: '/pages-home/home/home' | 
					
						
							|  |  |  |  |           }) | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-11-15 16:25:48 +08:00
										 |  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2024-10-17 15:22:37 +08:00
										 |  |  |  |         uni.navigateTo({ | 
					
						
							|  |  |  |  |           url: '/pages/login/login' | 
					
						
							|  |  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2024-11-15 16:25:48 +08:00
										 |  |  |  |       } | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     onShow(){ | 
					
						
							|  |  |  |  |       if (getToken()) { | 
					
						
							|  |  |  |  |         //判断是否是仓管,仓管需要跳单独的首页
 | 
					
						
							|  |  |  |  |         let userInfo = getUserInfo() | 
					
						
							|  |  |  |  |         if (userInfo.roleCodes.includes('repair_warehouse')) { | 
					
						
							|  |  |  |  |           //仓管
 | 
					
						
							|  |  |  |  |           uni.navigateTo({ | 
					
						
							|  |  |  |  |             url: '/pages-warehouse/home/home' | 
					
						
							|  |  |  |  |           }) | 
					
						
							|  |  |  |  |         } else { | 
					
						
							|  |  |  |  |           uni.navigateTo({ | 
					
						
							|  |  |  |  |             url: '/pages-home/home/home' | 
					
						
							|  |  |  |  |           }) | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       } else { | 
					
						
							|  |  |  |  |         uni.navigateTo({ | 
					
						
							|  |  |  |  |           url: '/pages/login/login' | 
					
						
							|  |  |  |  |         }) | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2024-10-09 13:34:36 +08:00
										 |  |  |  | 		methods: { | 
					
						
							| 
									
										
										
										
											2024-10-30 18:14:19 +08:00
										 |  |  |  | 			register() { //注册
 | 
					
						
							|  |  |  |  | 				console.log(keepAlivePlugin, 'keepAlive'); | 
					
						
							|  |  |  |  | 				keepAlivePlugin.register({ | 
					
						
							|  |  |  |  | 						channelId: this.keepLive.channelId, | 
					
						
							|  |  |  |  | 						channelName: this.keepLive.channelName, | 
					
						
							|  |  |  |  | 						title: this.keepLive.title, | 
					
						
							|  |  |  |  | 						content: this.keepLive.content, | 
					
						
							|  |  |  |  | 					}, | 
					
						
							|  |  |  |  | 					(res) => { | 
					
						
							|  |  |  |  | 						console.log('保活注册', res); | 
					
						
							|  |  |  |  | 					}); | 
					
						
							|  |  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2024-11-13 10:34:57 +08:00
										 |  |  |  |       /** | 
					
						
							|  |  |  |  |        * 获取未读消息数量 | 
					
						
							|  |  |  |  |        * @returns {Promise<void>} | 
					
						
							|  |  |  |  |        */ | 
					
						
							|  |  |  |  |       async getNoReadNum(){ | 
					
						
							|  |  |  |  |         await request({ | 
					
						
							|  |  |  |  |           url: "/admin-api/system/notify-message/get-unread-count", | 
					
						
							|  |  |  |  |           method: "GET" | 
					
						
							|  |  |  |  |         }).then((res) => { | 
					
						
							|  |  |  |  |           if(res.code==200 && res.data>0){ | 
					
						
							|  |  |  |  |               this.dianyidain() | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |         }) | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |       dianyidain() { | 
					
						
							|  |  |  |  |         if(!this.ifPlay){ | 
					
						
							|  |  |  |  |           console.log('执行了,dianyidain'); | 
					
						
							|  |  |  |  |           if(innerAudioContext!=""){ | 
					
						
							|  |  |  |  |             try { | 
					
						
							|  |  |  |  |               console.log('调用前先销毁'); | 
					
						
							|  |  |  |  |               innerAudioContext.stop(); | 
					
						
							|  |  |  |  |               innerAudioContext.destroy(); | 
					
						
							|  |  |  |  |               innerAudioContext=""; | 
					
						
							|  |  |  |  |             }catch (e){ | 
					
						
							|  |  |  |  |               console.log('销毁出错'); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |           innerAudioContext = uni.createInnerAudioContext(); | 
					
						
							|  |  |  |  |           this.ifPlay=true | 
					
						
							|  |  |  |  |           // #ifdef APP-PLUS
 | 
					
						
							|  |  |  |  |           innerAudioContext.src = '../../static/msgV.mp3'; | 
					
						
							|  |  |  |  |           // #endif
 | 
					
						
							|  |  |  |  |           // #ifndef APP-PLUS
 | 
					
						
							|  |  |  |  |           innerAudioContext.src = 'https://www.nuoyunr.com/lananRsc/rescue/msgV.mp3'; | 
					
						
							|  |  |  |  |           // #endif
 | 
					
						
							|  |  |  |  |           // 设置播放次数和计数器
 | 
					
						
							|  |  |  |  |           const playCount = 4; | 
					
						
							|  |  |  |  |           let currentCount = 0; | 
					
						
							|  |  |  |  |           // 初次播放
 | 
					
						
							|  |  |  |  |           innerAudioContext.play(); | 
					
						
							|  |  |  |  |           // 震动
 | 
					
						
							|  |  |  |  |           uni.vibrateLong({ | 
					
						
							|  |  |  |  |             success: function () { | 
					
						
							|  |  |  |  |               console.log('success'); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           }); | 
					
						
							|  |  |  |  |           innerAudioContext.onError((err) => { | 
					
						
							|  |  |  |  |             console.error('播放错误', err); | 
					
						
							|  |  |  |  |             this.ifPlay=false | 
					
						
							|  |  |  |  |             innerAudioContext.stop(); | 
					
						
							|  |  |  |  |             innerAudioContext.destroy(); // 播放错误后释放实例
 | 
					
						
							|  |  |  |  |           }); | 
					
						
							|  |  |  |  |           // 监听音频播放结束事件
 | 
					
						
							|  |  |  |  |           innerAudioContext.onEnded(() => { | 
					
						
							|  |  |  |  |             // 播放计数加一
 | 
					
						
							|  |  |  |  |             currentCount++; | 
					
						
							|  |  |  |  |             // 判断是否达到播放次数上限
 | 
					
						
							|  |  |  |  |             if (currentCount < playCount) { | 
					
						
							|  |  |  |  |               // 继续播放
 | 
					
						
							|  |  |  |  |               innerAudioContext.play(); | 
					
						
							|  |  |  |  |               // 震动
 | 
					
						
							|  |  |  |  |               uni.vibrateLong({ | 
					
						
							|  |  |  |  |                 success: function () { | 
					
						
							|  |  |  |  |                   console.log('success'); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |               }); | 
					
						
							|  |  |  |  |             } else { | 
					
						
							|  |  |  |  |               // 播放完成,可以在这里添加额外的逻辑
 | 
					
						
							|  |  |  |  |               console.log('播放完成'); | 
					
						
							|  |  |  |  |               this.ifPlay=false | 
					
						
							|  |  |  |  |               //及时释放资源
 | 
					
						
							|  |  |  |  |               innerAudioContext.stop(); | 
					
						
							|  |  |  |  |               innerAudioContext.destroy(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           }); | 
					
						
							|  |  |  |  |         }else{ | 
					
						
							|  |  |  |  |           console.log('正在播放音频,拒绝播放请求'); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2024-10-09 13:34:36 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | </script> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | <style> | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-17 15:22:37 +08:00
										 |  |  |  | </style> |