App.vue 1.4 KB

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