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