pushUtils.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. const value = uni.getStorageSync('pushreg_switch');
  7. if (value) {
  8. return;
  9. }
  10. let content = JSON.parse(message.content);
  11. if (content.type === 1){
  12. deviceParkIn(content)
  13. }else if (content.type === 2){
  14. deviceParkOut(content)
  15. }
  16. } catch(e){
  17. }
  18. };
  19. // content 消息格式: JSON格式
  20. // type: 1-设备入场 2-设备出场 3-用户已经支付
  21. // speakMsg: 语音播报内容
  22. // popNode: 弹出框内容
  23. // jumpTo: 页面跳转地址
  24. // data: {} 其他参数,JSON格式
  25. function deviceParkIn(content){
  26. if(content.speakMsg){
  27. speaker.speakAction(content.speakMsg)
  28. }
  29. // const value = uni.getStorageSync('pushModel_switch');
  30. // if (value) {
  31. // return;
  32. // }
  33. // uni.setStorageSync('pushModel_switch', '1');
  34. // uni.showModal({
  35. // title: '温馨提示',
  36. // content: content.popNode,
  37. // success: (res) => {
  38. // if(res.confirm){
  39. // uni.navigateTo({
  40. // url: content.jumpTo
  41. // });
  42. // }
  43. // } ,
  44. // complete:()=>{
  45. // uni.removeStorageSync('pushModel_switch');
  46. // }
  47. // });
  48. }
  49. function deviceParkOut(content){
  50. if(content.speakMsg){
  51. speaker.speakAction(content.speakMsg)
  52. }
  53. }
  54. function pushreg(vue){
  55. //添加推送开关
  56. uni.setStorageSync('pushreg_switch', '1');
  57. //监听系统通知栏消息点击事件
  58. plus.push.addEventListener('click', _handlePush, false);
  59. //监听接收透传消息事件
  60. plus.push.addEventListener('receive', _handlePush, false);
  61. }
  62. export default pushreg