App.vue 2.0 KB

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