App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <script>
  2. //#ifdef APP-PLUS
  3. var alog = uni.requireNativePlugin("AndroidLog")
  4. var device = uni.requireNativePlugin("DeviceInfo")
  5. import update from '@/utils/update.js';
  6. //#endif
  7. export default {
  8. onLaunch: function() {
  9. //#ifdef APP-PLUS
  10. update(this);
  11. //判断客户端类别
  12. const _handlePush = function(message) {
  13. //{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
  14. };
  15. //
  16. setTimeout(() => {
  17. var pinf = plus.push.getClientInfo();
  18. var cid = pinf.clientid; //客户端标识
  19. if (cid != null && cid != '' && cid != 'null') {
  20. //注册设备
  21. var deviceInfo = device.getDeviceInfo()
  22. this.$u.api.deviceReg({
  23. deviceNo: deviceInfo.deviceId,
  24. pushCid: cid
  25. })
  26. .then(res => {
  27. if (res.code == 200) {
  28. plus.nativeUI.toast('设备注册成功');
  29. } else {
  30. plus.nativeUI.toast('设备注册失败');
  31. }
  32. }).catch(err => {
  33. plus.nativeUI.toast('设备注册失败');
  34. });
  35. clearTimeout()
  36. }
  37. }, 400);
  38. //监听系统通知栏消息点击事件
  39. plus.push.addEventListener('click', _handlePush, false);
  40. //监听接收透传消息事件
  41. plus.push.addEventListener('receive', _handlePush, false);
  42. //#endif
  43. //#ifdef H5
  44. this.$u.api.deviceReg({
  45. deviceNo: '123456789',
  46. pushCid: '123456789'
  47. })
  48. .then(res => {
  49. if (res.code == 200) {
  50. uni.showToast({
  51. title: '设备注册成功',
  52. duration: 2000
  53. });
  54. } else {
  55. uni.showToast({
  56. title: '设备注册失败',
  57. duration: 2000
  58. });
  59. }
  60. }).catch(err => {
  61. uni.showToast({
  62. title: '设备注册失败',
  63. duration: 2000
  64. });
  65. });
  66. //#endif
  67. },
  68. onShow: function() {
  69. // console.log('App Show')
  70. },
  71. onHide: function() {
  72. // console.log('App Hide')
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. @import "uview-ui/index.scss";
  78. /*每个页面公共css */
  79. </style>