App.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script>
  2. var AndroidLog = uni.requireNativePlugin("AndroidLog")
  3. var device = uni.requireNativePlugin("DeviceInfo")
  4. export default {
  5. onLaunch: function() {
  6. //判断客户端类别
  7. const _handlePush = function(message) {
  8. // console.log("接收到推送消息:" ,message);
  9. // alert(message)
  10. //{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
  11. AndroidLog.info({message: message.content})
  12. let content = JSON.parse(message.content)
  13. AndroidLog.info({message: content.jumpTo})
  14. };
  15. setTimeout(()=>{
  16. var pinf = plus.push.getClientInfo();
  17. var cid = pinf.clientid;//客户端标识
  18. if(cid != null && cid != '' && cid != 'null'){
  19. //注册设备
  20. var deviceInfo = device.getDeviceInfo()
  21. this.$u.api.deviceReg({deviceNo:deviceInfo.deviceId,pushCid: cid})
  22. .then(res=>{
  23. if (res.code == 200){
  24. plus.nativeUI.toast('设备注册成功');
  25. }else{
  26. plus.nativeUI.toast('设备注册失败');
  27. }
  28. }).catch(err=>{
  29. plus.nativeUI.toast('设备注册失败');
  30. });
  31. clearTimeout()
  32. }
  33. }, 400);
  34. //监听系统通知栏消息点击事件
  35. plus.push.addEventListener('click', _handlePush,false);
  36. //监听接收透传消息事件
  37. plus.push.addEventListener('receive', _handlePush,false);
  38. // this.$wxApi.config();
  39. },
  40. onShow: function() {
  41. // console.log('App Show')
  42. },
  43. onHide: function() {
  44. // console.log('App Hide')
  45. }
  46. }
  47. </script>
  48. <style lang="scss">
  49. @import "uview-ui/index.scss";
  50. /*每个页面公共css */
  51. </style>