App.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <script setup>
  2. /*----------------------------------依赖引入-----------------------------------*/
  3. import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
  4. import { defineComponent, getCurrentInstance, inject, nextTick, onMounted, watchEffect, ref } from "vue";
  5. /*----------------------------------接口引入-----------------------------------*/
  6. /*----------------------------------组件引入-----------------------------------*/
  7. /*----------------------------------store引入-----------------------------------*/
  8. /*----------------------------------公共方法引入-----------------------------------*/
  9. import config from "./config";
  10. import { storageSystem } from "@/utils/storage";
  11. /*----------------------------------公共变量-----------------------------------*/
  12. const { proxy } = getCurrentInstance();
  13. /*----------------------------------变量声明-----------------------------------*/
  14. function initApp() {
  15. //初始化默认主题
  16. proxy.$settingStore.initThemeColor();
  17. //初始化获取安全区高度
  18. proxy.$settingStore.systemHeightTop();
  19. //隐藏自带tabbar
  20. uni.hideTabBar();
  21. //#ifdef APP-PLUS
  22. plus.screen.lockOrientation("portrait-primary"); //设置不可横屏
  23. proxy.$settingStore.pushListener(); //开启消息推送监听
  24. setInterval(proxy.$settingStore.baseAppInfo(), 1000 * 60 * 5); //动态获取用户设备信息
  25. //#endif
  26. }
  27. // 设置手机通知权限
  28. function setPermissions() {
  29. // #ifdef APP-PLUS
  30. if (plus.os.name == "Android") {
  31. // 判断是Android
  32. var main = plus.android.runtimeMainActivity();
  33. var pkName = main.getPackageName();
  34. var uid = main.getApplicationInfo().plusGetAttribute("uid");
  35. var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
  36. //android.support.v4升级为androidx
  37. if (NotificationManagerCompat == null) {
  38. NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
  39. }
  40. var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
  41. // 未开通‘允许通知’权限,则弹窗提醒开通,并点击确认后,跳转到系统设置页面进行设置
  42. if (!areNotificationsEnabled) {
  43. uni.showModal({
  44. title: "通知权限开启提醒",
  45. content: "您还没有开启通知权限,无法接受到消息通知,请前往设置!",
  46. showCancel: false,
  47. confirmText: "去设置",
  48. success: function (res) {
  49. if (res.confirm) {
  50. var Intent = plus.android.importClass("android.content.Intent");
  51. var Build = plus.android.importClass("android.os.Build");
  52. //android 8.0引导
  53. if (Build.VERSION.SDK_INT >= 26) {
  54. var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
  55. intent.putExtra("android.provider.extra.APP_PACKAGE", pkName);
  56. } else if (Build.VERSION.SDK_INT >= 21) {
  57. //android 5.0-7.0
  58. var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
  59. intent.putExtra("app_package", pkName);
  60. intent.putExtra("app_uid", uid);
  61. } else {
  62. //(<21)其他--跳转到该应用管理的详情页
  63. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  64. var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
  65. intent.setData(uri);
  66. }
  67. // 跳转到该应用的系统通知设置页
  68. main.startActivity(intent);
  69. }
  70. },
  71. });
  72. }
  73. } else if (plus.os.name == "iOS") {
  74. // 判断是ISO
  75. var isOn = undefined;
  76. var types = 0;
  77. var app = plus.ios.invoke("UIApplication", "sharedApplication");
  78. var settings = plus.ios.invoke(app, "currentUserNotificationSettings");
  79. if (settings) {
  80. types = settings.plusGetAttribute("types");
  81. plus.ios.deleteObject(settings);
  82. } else {
  83. types = plus.ios.invoke(app, "enabledRemoteNotificationTypes");
  84. }
  85. plus.ios.deleteObject(app);
  86. isOn = 0 != types;
  87. if (isOn == false) {
  88. uni.showModal({
  89. title: "通知权限开启提醒",
  90. content: "您还没有开启通知权限,无法接受到消息通知,请前往设置!",
  91. showCancel: false,
  92. confirmText: "去设置",
  93. success: function (res) {
  94. if (res.confirm) {
  95. var app = plus.ios.invoke("UIApplication", "sharedApplication");
  96. var setting = plus.ios.invoke("NSURL", "URLWithString:", "app-settings:");
  97. plus.ios.invoke(app, "openURL:", setting);
  98. plus.ios.deleteObject(setting);
  99. plus.ios.deleteObject(app);
  100. }
  101. },
  102. });
  103. }
  104. }
  105. // #endif
  106. }
  107. watchEffect(() => {
  108. //#ifdef APP-PLUS || MP-WEIXIN
  109. if (uni.getStorageSync("serveUrl")) {
  110. config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  111. }
  112. //#endif
  113. });
  114. onLaunch(() => {
  115. console.log("App Launch");
  116. initApp();
  117. });
  118. onLoad(() => {});
  119. onReady(() => {});
  120. onShow(() => {
  121. console.log("App Show");
  122. });
  123. onHide(() => {
  124. console.log("App Hide");
  125. });
  126. </script>
  127. <style lang="scss">
  128. @import "@/static/scss/index.scss";
  129. </style>
  130. <style lang="scss">
  131. @import "@/uni_modules/uview-plus/index.scss";
  132. uni-page-body,
  133. uni-page-refresh {
  134. height: 100%;
  135. }
  136. //默认返回按钮样式
  137. :deep(.uni-page-head-btn) {
  138. background-color: rgba(0, 0, 0, 0) !important;
  139. }
  140. //默认头部导航title样式
  141. :deep(.uni-page-head__title) {
  142. font-size: $uni-font-size-lg;
  143. font-weight: bold;
  144. }
  145. </style>