App.vue 5.8 KB

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