App.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script>
  2. //#ifdef APP-PLUS
  3. import skJGPush from '@/libs/jgPush.js'
  4. //#endif
  5. import {openMessagePage} from '@/libs/tools.js'
  6. export default {
  7. globalData: {
  8. baseUrl: '',
  9. token: '',
  10. changeOrg:'',
  11. version: '', // 当前版本号
  12. buildType: 'uat', // 打包环境对应类型,pro 生产 uat 预发布 dev 本地开发
  13. envTips: '', // 环境文字提示
  14. theme: 'default', // 主题,default
  15. },
  16. onLaunch: function() {
  17. console.log('App launch')
  18. const App = getApp({ allowDefault: true })
  19. App.globalData.token = this.$store.state.vuex_token;
  20. App.globalData.changeOrg = this.$store.state.vuex_changeOrg;
  21. const theme = App.globalData.theme
  22. const envText = {pro:'生产环境',dev:'开发环境',uat:'预发布环境'}
  23. let buildType = App.globalData.buildType
  24. let baseUrl = this.$config(buildType+'_URL')
  25. App.globalData.baseUrl = baseUrl
  26. App.globalData.envTips = envText[buildType]
  27. this.$store.state.vuex_theme = App.globalData.theme
  28. this.$store.state.vuex_tempData = ''
  29. // 消息推送
  30. //#ifdef APP-PLUS
  31. let bgAudioManager = uni.getBackgroundAudioManager();
  32. if(uni.getSystemInfoSync().platform == "ios"){
  33. // 请求定位权限
  34. let locationServicesEnabled = skJGPush.locationServicesEnabled()
  35. let locationAuthorizationStatus = skJGPush.getLocationAuthorizationStatus()
  36. console.log('locationAuthorizationStatus',locationAuthorizationStatus)
  37. if (locationServicesEnabled == true && locationAuthorizationStatus < 3) {
  38. skJGPush.requestLocationAuthorization((result)=>{
  39. console.log('定位权限',result.status)
  40. })
  41. }
  42. skJGPush.requestNotificationAuthorization((result)=>{
  43. let status = result.status
  44. console.log(result,'通知权限')
  45. if (status < 2) {
  46. uni.showModal({
  47. title: '提示',
  48. content: '您未打开通知权限,应用将无法收到消息通知,确定开启通知权限吗?',
  49. success: function (res) {
  50. if (res.confirm) {
  51. skJGPush.openSettingsForNotification()
  52. } else if (res.cancel) {
  53. console.log('用户点击取消');
  54. }
  55. }
  56. });
  57. }
  58. })
  59. }else{
  60. // 极光推送-init
  61. skJGPush.initJPushService()
  62. }
  63. // 极光推送-打开debug
  64. skJGPush.openDebug()
  65. skJGPush.initCrashHandler()
  66. // 极光推送-获取rid
  67. skJGPush.getRegistrationID(result => {
  68. console.log('【业务getRegistrationID】', result)
  69. })
  70. // 极光推送-通知事件回调
  71. skJGPush.addNotificationListener(result => {
  72. console.log('【业务addNotificationListener】', result)
  73. // 点击通知
  74. if(result.notificationEventType == 'notificationOpened'){
  75. this.setRead(result)
  76. }else if(result.notificationEventType == 'notificationArrived'){
  77. // 安卓铃声
  78. if(bgAudioManager&&uni.getSystemInfoSync().platform != "ios"){
  79. bgAudioManager.src = '/static/notes.mp3';
  80. bgAudioManager.play()
  81. }else{
  82. uni.vibrateLong({
  83. success: function () {
  84. console.log('vibrateLong success');
  85. }
  86. });
  87. }
  88. }else{
  89. // 清空角标
  90. skJGPush.setBadge(0)
  91. }
  92. })
  93. // 极光推送-标签别名事件回调
  94. skJGPush.addTagAliasListener(result => {
  95. console.log('【业务addTagAliasListener】', result)
  96. })
  97. // 连接状态
  98. skJGPush.addConnectEventListener(result => {
  99. console.log('【连接状态】', result)
  100. })
  101. //#endif
  102. },
  103. onShow: function() {
  104. console.log('App Show')
  105. },
  106. onHide: function() {
  107. console.log('App Hide')
  108. },
  109. methods:{
  110. async setRead(item){
  111. const api = await import("@/api/user.js")
  112. const token = getApp({ allowDefault: true }).globalData.token
  113. if(token){
  114. api.setReadNotice({'noticeId': item.extras.noticeId}).then(res => {
  115. console.log(res,'setRead')
  116. openMessagePage(item)
  117. })
  118. }else{
  119. uni.$emit("openMessage",item)
  120. }
  121. },
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. @import "./static/iconfont/iconfont.css";
  127. page{
  128. background-color: #F8F8F8;
  129. }
  130. </style>