App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <script setup>
  2. import config from "./config";
  3. import { getToken, setToken, removeToken } from "@/utils/auth";
  4. import { defineComponent, getCurrentInstance, inject, nextTick, onMounted, watchEffect } from "vue";
  5. import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
  6. let tab = inject("$tab");
  7. const { proxy } = getCurrentInstance();
  8. function initApp() {
  9. //初始化获取安全区高度
  10. proxy.$settingStore.systemHeightTop();
  11. //隐藏自带tabbar
  12. uni.hideTabBar();
  13. //#ifdef APP-PLUS
  14. plus.screen.lockOrientation("portrait-primary"); //设置不可横屏
  15. pushListener(); //开启消息推送监听
  16. proxy.$setting.clearBadge(0); // 清除数字
  17. //#endif
  18. }
  19. /**
  20. * @消息推送监听
  21. */
  22. function pushMessage() {
  23. uni.onPushMessage((res) => {
  24. const platform = uni.getSystemInfoSync().platform;
  25. console.log("收到推送消息:", res); //监听推送消息
  26. if (res.type === "click") {
  27. if (platform == "android") {
  28. } else {
  29. }
  30. } else if (res.type === "receive") {
  31. if (platform == "android") {
  32. } else {
  33. }
  34. }
  35. });
  36. }
  37. /**
  38. * @消息推送监听
  39. */
  40. function pushListener() {
  41. //获取应用的CID
  42. uni.getPushClientId({
  43. success: (res) => {
  44. console.log(res.cid);
  45. },
  46. fail(err) {
  47. console.log(err);
  48. },
  49. });
  50. const platform = uni.getSystemInfoSync().platform;
  51. // 点击推送信息
  52. plus.push.addEventListener("click", (res) => {
  53. console.log(res);
  54. if (res.aps) {
  55. if ("url" in res.payload) {
  56. } else {
  57. }
  58. console.log(res.payload);
  59. }
  60. });
  61. // 接收推送信息 在线
  62. plus.push.addEventListener("receive", (res) => {
  63. console.log(res);
  64. if (platform == "android") {
  65. } else {
  66. uni.createPushMessage({
  67. title: res.title,
  68. content: res.content,
  69. });
  70. }
  71. });
  72. }
  73. watchEffect(() => {
  74. //#ifdef APP-PLUS || MP-WEIXIN
  75. if (uni.getStorageSync("serveUrl")) {
  76. config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  77. }
  78. //#endif
  79. });
  80. onLaunch(() => {
  81. console.log("App Launch");
  82. //初始化默认主题
  83. if (!proxy.$settingStore.$state.themeColor) {
  84. proxy.$settingStore.SET_THEMECOLOR(proxy.$constData.themeList[0]);
  85. } else {
  86. proxy.$settingStore.SET_THEMECOLOR(proxy.$settingStore.$state.themeColor);
  87. }
  88. initApp();
  89. });
  90. onLoad(() => {});
  91. onReady(() => {});
  92. onShow(() => {
  93. console.log("App Show");
  94. });
  95. onHide(() => {
  96. console.log("App Hide");
  97. });
  98. </script>
  99. <style lang="scss">
  100. @import "@/static/scss/index.scss";
  101. </style>
  102. <style lang="scss">
  103. @import "@/uni_modules/uview-plus/index.scss";
  104. uni-page-body,
  105. uni-page-refresh {
  106. height: 100%;
  107. }
  108. //默认返回按钮样式
  109. :deep(.uni-page-head-btn) {
  110. background-color: rgba(0, 0, 0, 0) !important;
  111. }
  112. //默认头部导航title样式
  113. :deep(.uni-page-head__title) {
  114. font-size: $uni-font-size-lg;
  115. font-weight: bold;
  116. }
  117. //uview-plus导航栏title样式
  118. :deep(.u-navbar__content__title) {
  119. font-size: $uni-font-size-lg;
  120. font-weight: bold;
  121. }
  122. :deep(.u-nav-slot .u-navbar__content__title) {
  123. font-size: 18px;
  124. }
  125. </style>