App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. },
  6. onShow: function(options) {
  7. // console.log('app-options===>', options)
  8. if (Object.keys(options.query).length > 0) {
  9. if (options.query.invitationCode) {
  10. uni.setStorageSync('invitationCode', options.query.invitationCode);
  11. }
  12. }
  13. console.log('App Show')
  14. // #ifdef MP-WEIXIN
  15. //小程序更新
  16. if (uni.getUpdateManager) {
  17. const updateManager = uni.getUpdateManager();
  18. updateManager.onCheckForUpdate(function(res) {
  19. // 请求完新版本信息的回调
  20. // console.log(res.hasUpdate);
  21. });
  22. updateManager.onUpdateReady(function(res) {
  23. uni.showModal({
  24. title: '更新提示',
  25. content: '新版本已经准备好,是否重启应用?',
  26. success(res) {
  27. if (res.confirm) {
  28. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  29. updateManager.applyUpdate();
  30. }
  31. }
  32. });
  33. });
  34. updateManager.onUpdateFailed(function(res) {
  35. // 新的版本下载失败
  36. uni.showModal({
  37. title: '已经有新版本了哟~',
  38. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
  39. showCancel: false
  40. });
  41. });
  42. }
  43. // #endif
  44. // #ifdef APP-PLUS
  45. this.getPush();
  46. // #endif
  47. },
  48. onHide: function() {
  49. console.log('App Hide')
  50. },
  51. methods: {
  52. getPush() {
  53. // #ifdef APP-PLUS
  54. plus.push.setAutoNotification(true); //设置通知栏显示通知必须设置
  55. //从系统消息中心点击消息启动应用事件
  56. let that = this;
  57. let platform = uni.getSystemInfoSync().platform;
  58. plus.push.addEventListener(
  59. "click",
  60. (data) => {
  61. if (platform == "ios" && data.type == "click") {
  62. //苹果离线点击事件
  63. let obj = data.payload.payload.message_body;
  64. let item = data.payload.payload;
  65. that.jump(item, obj);
  66. }
  67. if (platform == "ios") {
  68. //苹果在线点击事件
  69. let item = JSON.parse(data.payload);
  70. let obj = item.message_body;
  71. that.jump(item, obj);
  72. }
  73. if (platform == "android") {
  74. //安卓在线点击事件
  75. let item = data.payload;
  76. let obj = item.message_body;
  77. that.jump(item, obj);
  78. }
  79. },
  80. false
  81. );
  82. //应用从推送服务器接收到推送消息事件
  83. plus.push.addEventListener(
  84. "receive",
  85. (res) => {
  86. if (platform == "android") {
  87. //安卓在线推送
  88. // item = res.payload
  89. const options = {
  90. cover: false,
  91. title: res.title,
  92. };
  93. plus.push.createMessage(res.content, res.payload, options);
  94. } else {
  95. //苹果在线推送事件
  96. if (res.aps == null || res.type == "receive") {
  97. const options = {
  98. cover: false,
  99. title: res.title,
  100. };
  101. plus.push.createMessage(
  102. res.content,
  103. JSON.stringify(res.payload),
  104. options
  105. );
  106. }
  107. }
  108. },
  109. false
  110. );
  111. // #endif
  112. },
  113. //跳转
  114. jump(item, obj) {
  115. // const then = this;
  116. console.log("item===>", item)
  117. // console.log("obj===>", obj)
  118. let messageName = {
  119. 'PAY_MESSAGE': {
  120. name: "支付消息",
  121. type: 1
  122. },
  123. 'LOGISTICS_MESSAGE': {
  124. name: "物流消息",
  125. type: 2
  126. },
  127. 'RIGHTS_MESSAGE': {
  128. name: "售后消息",
  129. type: 3
  130. },
  131. };
  132. let item1 = messageName[item.type] || null;
  133. console.log("item1===>", item1)
  134. if(!item1) return
  135. // 跳转到消息列表页面
  136. uni.navigateTo({
  137. url: `/pages/user/eventDetails?type=${item1.type || ''}&name=${item1.name || ''}`,
  138. });
  139. },
  140. }
  141. }
  142. </script>
  143. <style lang="scss">
  144. /*每个页面公共css */
  145. @import "@/static/font/iconfont.css";
  146. @import "@/static/style/basics.scss";
  147. @import "@/uni_modules/uv-ui-tools/index.scss";
  148. @import "@/static/style/common.scss";
  149. view{
  150. box-sizing: border-box;
  151. }
  152. .u-btn-two {
  153. width: 100%;
  154. height: 70rpx;
  155. background: #fa6138;
  156. border-radius: 45rpx;
  157. /* border: 1px solid #0B844A; */
  158. font-size: 30rpx;
  159. color: #ffffff;
  160. text-align: center;
  161. line-height: 70rpx;
  162. margin: 0;
  163. }
  164. .u-plr30 {
  165. padding: 0 30rpx;
  166. }
  167. .u-FFF {
  168. color: #fff;
  169. }
  170. </style>