pushUtils.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var alog = uni.requireNativePlugin("AndroidLog")
  2. let speaker = uni.requireNativePlugin("SpeechPlug");
  3. const _handlePush = function(message) {
  4. //{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
  5. try {
  6. alog.info({msg: '接收到消息:' + message});
  7. const value = uni.getStorageSync('pushreg_switch');
  8. if (value) {
  9. return;
  10. }
  11. const roadinfoCache = uni.getStorageSync('payee_roadinfo');
  12. alog.info({msg: '本地路段信息:' + roadinfoCache});
  13. if (!roadinfoCache){
  14. return;
  15. }
  16. let content = JSON.parse(message.content);
  17. const roadinfo = JSON.parse(roadinfoCache) ;
  18. if(content.roadNo && roadinfo.roadNo && content.roadNo == roadinfo.roadNo){
  19. if (content.type === 1){
  20. deviceParkIn(content)
  21. }else if (content.type === 2){
  22. deviceParkOut(content)
  23. }
  24. }
  25. } catch(e){
  26. }
  27. };
  28. // content 消息格式: JSON格式
  29. // type: 1-设备入场 2-设备出场 3-用户已经支付
  30. // speakMsg: 语音播报内容
  31. // popNode: 弹出框内容
  32. // jumpTo: 页面跳转地址
  33. // data: {} 其他参数,JSON格式
  34. function deviceParkIn(content){
  35. if(content.speakMsg){
  36. speaker.speakAction(content.speakMsg)
  37. }
  38. // const value = uni.getStorageSync('pushModel_switch');
  39. // if (value) {
  40. // return;
  41. // }
  42. // uni.setStorageSync('pushModel_switch', '1');
  43. // uni.showModal({
  44. // title: '温馨提示',
  45. // content: content.popNode,
  46. // success: (res) => {
  47. // if(res.confirm){
  48. // uni.navigateTo({
  49. // url: content.jumpTo
  50. // });
  51. // }
  52. // } ,
  53. // complete:()=>{
  54. // uni.removeStorageSync('pushModel_switch');
  55. // }
  56. // });
  57. }
  58. function deviceParkOut(content){
  59. if(content.speakMsg){
  60. speaker.speakAction(content.speakMsg)
  61. }
  62. }
  63. function pushreg(vue){
  64. //添加推送开关
  65. uni.setStorageSync('pushreg_switch', '1');
  66. //监听系统通知栏消息点击事件
  67. plus.push.addEventListener('click', _handlePush, false);
  68. //监听接收透传消息事件
  69. plus.push.addEventListener('receive', _handlePush, false);
  70. }
  71. export default pushreg