App.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "@/uni_modules/uview-ui/index.scss";
  4. @import 'static/css/common.scss';
  5. </style>
  6. <script>
  7. import {
  8. mapMutations
  9. } from 'vuex';
  10. import * as config from '@/config'
  11. import appUpdate from 'common/appUpdate.js'
  12. import app_push from './components/APPPush/app_push.js'
  13. import permision from "@/js_sdk/wa-permission/permission.js"
  14. export default {
  15. methods: {
  16. ...mapMutations(['login']),
  17. // vue的method里编写如下代码
  18. // async requestAndroidPermission(permisionID) {
  19. // var result = await permision.requestAndroidPermission(permisionID)
  20. // var strStatus
  21. // if (result == 1) {
  22. // strStatus = "已获得授权"
  23. // } else if (result == 0) {
  24. // strStatus = "未获得授权"
  25. // // permision.gotoAppPermissionSetting()
  26. // // 引导设置,判断是否有运输中订单,有订单,必须授权
  27. // } else {
  28. // strStatus = "被永久拒绝权限"
  29. // // permision.gotoAppPermissionSetting()
  30. // }
  31. // },
  32. },
  33. onLaunch: function() {
  34. uni.getSystemInfo({
  35. success:function(e){
  36. Vue.prototype.statusBar = e.statusBarHeight
  37. // #ifndef MP
  38. if(e.platform == 'android') {
  39. Vue.prototype.customBar = e.statusBarHeight + 50
  40. }else {
  41. Vue.prototype.customBar = e.statusBarHeight + 45
  42. }
  43. // #endif
  44. // #ifdef MP-WEIXIN
  45. let custom = wx.getMenuButtonBoundingClientRect()
  46. Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
  47. // #endif
  48. // #ifdef MP-ALIPAY
  49. Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
  50. // #endif
  51. }
  52. })
  53. // #ifdef APP-PLUS
  54. // let isOpenLocation= permision.checkSystemEnableLocation()
  55. // console.log("isOpenLocation",isOpenLocation)
  56. // this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  57. let type = uni.getSystemInfoSync().platform
  58. console.log(type)
  59. if (type == "android") {
  60. // appUpdate()
  61. }
  62. var that = this
  63. // plus.push.getClientInfoAsync((info) => {
  64. // var name = 'clientId'
  65. // var value = info.clientid
  66. // that.$store.commit('$uStore', {
  67. // name,
  68. // value
  69. // });
  70. // uni.setStorageSync("clientId", info.clientid)
  71. // console.log("info.clientid", info.clientid)
  72. // }, err => {});
  73. // 监听在线消息事件
  74. plus.push.addEventListener("receive", function(msg) {
  75. var title = msg.content.split(':')[0]
  76. var content = msg.content.split(':')[1]
  77. let params = {
  78. inApp: true, // app内横幅提醒
  79. voice: true, // 声音提醒
  80. vibration: true, // 振动提醒
  81. messageType: "",
  82. messageTitle: title,
  83. messageContent: content,
  84. messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  85. }
  86. console.log("msg", msg)
  87. new app_push({
  88. ...params
  89. }).show();
  90. var userInfo = uni.getStorageSync("userInfo")
  91. var that = this
  92. that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  93. if (res.data.data) {
  94. let name = 'myTip';
  95. let value = res.data.data.task;
  96. that.$store.commit('$uStore', {
  97. name,
  98. value
  99. });
  100. if (value != 0 && value) {
  101. uni.setTabBarBadge({
  102. index: 4,
  103. text: value + ""
  104. })
  105. }
  106. name = 'taskTip';
  107. value = res.data.data.task;
  108. that.$store.commit('$uStore', {
  109. name,
  110. value
  111. });
  112. // name = 'contractTip';
  113. // value = res.data.data.contractTip;
  114. // that.$store.commit('$uStore', {
  115. // name,
  116. // value
  117. // });
  118. }
  119. })
  120. //其它逻辑
  121. }, false);
  122. //监听系统通知栏消息点击事件
  123. plus.push.addEventListener('click', function(msg) {
  124. //处理点击消息的业务逻辑代码
  125. if (msg.content && msg.content.contains("任务")) {
  126. uni.navigateTo({
  127. url: '/pages/task/my_task'
  128. })
  129. } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  130. uni.navigateTo({
  131. url: '/pageB/contract/contract'
  132. })
  133. }
  134. }, false);
  135. // #endif
  136. this.$socket.initWebIM(this.$ws, true, true)
  137. let userInfo = uni.getStorageSync('userInfo') || '';
  138. if (userInfo.id) {
  139. //更新登陆状态
  140. uni.getStorage({
  141. key: 'userInfo',
  142. success: (res) => {
  143. this.login(res.data);
  144. }
  145. });
  146. }
  147. },
  148. onShow: function() {
  149. console.log('App Show')
  150. },
  151. onHide: function() {
  152. console.log('App Hide')
  153. },
  154. }
  155. </script>
  156. <style>
  157. /*每个页面公共css */
  158. </style>