App.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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({
  12. message: message.content
  13. })
  14. let content = JSON.parse(message.content)
  15. AndroidLog.info({
  16. message: content.jumpTo
  17. })
  18. };
  19. //
  20. setTimeout(() => {
  21. var pinf = plus.push.getClientInfo();
  22. var cid = pinf.clientid; //客户端标识
  23. if (cid != null && cid != '' && cid != 'null') {
  24. //注册设备
  25. var deviceInfo = device.getDeviceInfo()
  26. this.$u.api.deviceReg({
  27. deviceNo: deviceInfo.deviceId,
  28. pushCid: cid
  29. })
  30. .then(res => {
  31. if (res.code == 200) {
  32. plus.nativeUI.toast('设备注册成功');
  33. } else {
  34. plus.nativeUI.toast('设备注册失败');
  35. }
  36. }).catch(err => {
  37. plus.nativeUI.toast('设备注册失败');
  38. });
  39. clearTimeout()
  40. }
  41. }, 400);
  42. //
  43. //监听系统通知栏消息点击事件
  44. plus.push.addEventListener('click', _handlePush, false);
  45. //监听接收透传消息事件
  46. plus.push.addEventListener('receive', _handlePush, false);
  47. // this.$wxApi.config();
  48. },
  49. onShow: function() {
  50. // console.log('App Show')
  51. },
  52. onHide: function() {
  53. // console.log('App Hide')
  54. }
  55. }
  56. </script>
  57. <style lang="scss">
  58. @import "uview-ui/index.scss";
  59. /*每个页面公共css */
  60. </style>