App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "@/uni_modules/uview-ui/index.scss";
  4. </style>
  5. <script>
  6. import {
  7. mapMutations
  8. } from 'vuex';
  9. import * as config from '@/config'
  10. import appUpdate from 'common/appUpdate.js'
  11. import app_push from './components/APPPush/app_push.js'
  12. export default {
  13. methods: {
  14. ...mapMutations(['login']),
  15. },
  16. onLaunch: function() {
  17. // #ifdef APP-PLUS
  18. let type = uni.getSystemInfoSync().platform
  19. console.log(type)
  20. if (type == "android") {
  21. appUpdate()
  22. }
  23. var that = this
  24. plus.push.getClientInfoAsync((info) => {
  25. var name = 'clientId'
  26. var value = info.clientid
  27. that.$store.commit('$uStore', {
  28. name,
  29. value
  30. });
  31. uni.setStorageSync("clientId", info.clientid)
  32. console.log("info.clientid", info.clientid)
  33. }, err => {});
  34. // 监听在线消息事件
  35. plus.push.addEventListener("receive", function(msg) {
  36. var title = msg.content.split(':')[0]
  37. var content = msg.content.split(':')[1]
  38. let params = {
  39. inApp: true, // app内横幅提醒
  40. voice: true, // 声音提醒
  41. vibration: true, // 振动提醒
  42. messageType: "",
  43. messageTitle: title,
  44. messageContent: content,
  45. messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  46. }
  47. console.log("msg", msg)
  48. new app_push({
  49. ...params
  50. }).show();
  51. var userInfo = uni.getStorageSync("userInfo")
  52. var that = this
  53. that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  54. if (res.data.data) {
  55. let name = 'myTip';
  56. let value = res.data.data.task;
  57. that.$store.commit('$uStore', {
  58. name,
  59. value
  60. });
  61. if (value != 0 && value) {
  62. uni.setTabBarBadge({
  63. index: 4,
  64. text: value + ""
  65. })
  66. }
  67. name = 'taskTip';
  68. value = res.data.data.task;
  69. that.$store.commit('$uStore', {
  70. name,
  71. value
  72. });
  73. // name = 'contractTip';
  74. // value = res.data.data.contractTip;
  75. // that.$store.commit('$uStore', {
  76. // name,
  77. // value
  78. // });
  79. }
  80. })
  81. //其它逻辑
  82. }, false);
  83. //监听系统通知栏消息点击事件
  84. plus.push.addEventListener('click', function(msg) {
  85. //处理点击消息的业务逻辑代码
  86. if (msg.content && msg.content.contains("任务")) {
  87. uni.navigateTo({
  88. url: '/pages/task/my_task'
  89. })
  90. } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  91. uni.navigateTo({
  92. url: '/pageB/contract/contract'
  93. })
  94. }
  95. }, false);
  96. // #endif
  97. this.$socket.initWebIM(this.$ws, true, true)
  98. let userInfo = uni.getStorageSync('userInfo') || '';
  99. if (userInfo.id) {
  100. //更新登陆状态
  101. uni.getStorage({
  102. key: 'userInfo',
  103. success: (res) => {
  104. this.login(res.data);
  105. }
  106. });
  107. }
  108. },
  109. onShow: function() {
  110. console.log('App Show')
  111. },
  112. onHide: function() {
  113. console.log('App Hide')
  114. },
  115. }
  116. </script>
  117. <style>
  118. /*每个页面公共css */
  119. </style>