App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <script>
  2. /**
  3. * vuex管理登录状态,具体可以参考官方登录模板示例
  4. */
  5. import { mapMutations } from "vuex";
  6. import APPUpdate from "@/plugins/APPUpdate";
  7. import { getClipboardData } from "@/js_sdk/h5-copy/h5-copy.js";
  8. import config from "@/config/config";
  9. // 悬浮球
  10. export default {
  11. data() {
  12. return {
  13. config,
  14. };
  15. },
  16. methods: {
  17. ...mapMutations(["login"]),
  18. },
  19. onLaunch: function () {
  20. // #ifdef APP-PLUS
  21. this.checkArguments(); // 检测启动参数
  22. APPUpdate();
  23. // 重点是以下: 一定要监听后台恢复 !一定要
  24. plus.globalEvent.addEventListener("newintent", (e) => {
  25. this.checkArguments(); // 检测启动参数
  26. });
  27. // #endif
  28. },
  29. onShow() {
  30. // #ifndef H5
  31. this.getClipboard();
  32. // #endif
  33. },
  34. methods: {
  35. // 开屏广告
  36. launch() {
  37. try {
  38. // 获取本地存储中launchFlag标识 开屏广告
  39. const value = uni.getStorageSync("launchFlag");
  40. if (!value) {
  41. this.$u.route("/pages/index/agreement");
  42. } else {
  43. //app启动时打开启动广告页
  44. var w = plus.webview.open(
  45. "/hybrid/html/advertise/advertise.html",
  46. "本地地址",
  47. {
  48. top: 0,
  49. bottom: 0,
  50. zindex: 999,
  51. },
  52. "fade-in",
  53. 500
  54. );
  55. //设置定时器,4s后关闭启动广告页
  56. setTimeout(function () {
  57. plus.webview.close(w);
  58. APPUpdate();
  59. }, 3000);
  60. }
  61. } catch (e) {
  62. // error
  63. uni.setStorage({
  64. key: "launchFlag",
  65. data: true,
  66. success: function () {
  67. console.log("error时存储launchFlag");
  68. },
  69. });
  70. }
  71. },
  72. /**
  73. * 获取粘贴板数据
  74. */
  75. async getClipboard() {
  76. let res = await getClipboardData();
  77. /**
  78. * 解析粘贴板数据
  79. */
  80. if (res.indexOf(config.shareLink) != -1) {
  81. uni.showModal({
  82. title: "提示",
  83. content: "检测到一个分享链接是否跳转?",
  84. confirmText: "跳转",
  85. success: function (callback) {
  86. if (callback.confirm) {
  87. const path = res.split(config.shareLink)[1];
  88. if (path.indexOf("tabbar") != -1) {
  89. uni.switchTab({
  90. url: path,
  91. });
  92. } else {
  93. uni.navigateTo({
  94. url: path,
  95. });
  96. }
  97. }
  98. },
  99. });
  100. }
  101. },
  102. /**
  103. * h5中打开app获取跳转app的链接并跳转
  104. */
  105. checkArguments() {
  106. // #ifdef APP-PLUS
  107. setTimeout(() => {
  108. const args = plus.runtime.arguments;
  109. if (args) {
  110. const argsStr = decodeURIComponent(args);
  111. const path = argsStr.split("//")[1];
  112. if (path.indexOf("tabbar") != -1) {
  113. uni.switchTab({
  114. url: `/${path}`,
  115. });
  116. } else {
  117. uni.navigateTo({
  118. url: `/${path}`,
  119. });
  120. }
  121. }
  122. });
  123. // #endif
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="scss">
  129. @import "uview-ui/index.scss";
  130. @import "./static/font/iconfont/iconfont.css";
  131. // -------适配底部安全区 苹果x系列刘海屏
  132. // #ifdef MP-WEIXIN
  133. .mp-iphonex-bottom {
  134. padding-bottom: constant(safe-area-inset-bottom);
  135. padding-bottom: env(safe-area-inset-bottom);
  136. box-sizing: content-box;
  137. height: auto !important;
  138. padding-top: 10rpx;
  139. }
  140. // #endif
  141. body {
  142. background-color: $bg-color;
  143. }
  144. /************************ */
  145. .w200 {
  146. width: 200rpx !important;
  147. }
  148. .flex1 {
  149. flex: 1; //必须父级设置flex
  150. }
  151. </style>