App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. /**
  17. * 监听返回
  18. */
  19. onBackPress(e) {
  20. if (e.from == "backbutton") {
  21. let routes = getCurrentPages();
  22. let curRoute = routes[routes.length - 1].options;
  23. routes.forEach((item) => {
  24. if (
  25. item.route == "pages/tabbar/cart/cartList" ||
  26. item.route.indexOf("pages/product/goods") != -1
  27. ) {
  28. uni.redirectTo({
  29. url: item.route,
  30. });
  31. }
  32. });
  33. if (curRoute.addId) {
  34. uni.reLaunch({
  35. url: "/pages/tabbar/cart/cartList",
  36. });
  37. } else {
  38. uni.navigateBack();
  39. }
  40. return true; //阻止默认返回行为
  41. }
  42. },
  43. methods: {
  44. ...mapMutations(["login"]),
  45. },
  46. onLaunch: function () {
  47. // #ifdef APP-PLUS
  48. this.checkArguments(); // 检测启动参数
  49. APPUpdate();
  50. // 重点是以下: 一定要监听后台恢复 !一定要
  51. plus.globalEvent.addEventListener("newintent", (e) => {
  52. this.checkArguments(); // 检测启动参数
  53. });
  54. // #endif
  55. },
  56. onShow() {
  57. // #ifndef H5
  58. this.getClipboard();
  59. // #endif
  60. },
  61. methods: {
  62. // TODO 开屏广告 后续优化添加
  63. launch() {
  64. try {
  65. // 获取本地存储中launchFlag标识 开屏广告
  66. const value = uni.getStorageSync("launchFlag");
  67. if (!value) {
  68. // this.$u.route("/pages/index/agreement");
  69. } else {
  70. //app启动时打开启动广告页
  71. var w = plus.webview.open(
  72. "/hybrid/html/advertise/advertise.html",
  73. "本地地址",
  74. {
  75. top: 0,
  76. bottom: 0,
  77. zindex: 999,
  78. },
  79. "fade-in",
  80. 500
  81. );
  82. //设置定时器,4s后关闭启动广告页
  83. setTimeout(function () {
  84. plus.webview.close(w);
  85. APPUpdate();
  86. }, 3000);
  87. }
  88. } catch (e) {
  89. // error
  90. uni.setStorage({
  91. key: "launchFlag",
  92. data: true,
  93. success: function () {
  94. console.log("error时存储launchFlag");
  95. },
  96. });
  97. }
  98. },
  99. /**
  100. * 获取粘贴板数据
  101. */
  102. async getClipboard() {
  103. let res = await getClipboardData();
  104. /**
  105. * 解析粘贴板数据
  106. */
  107. if (res.indexOf(config.shareLink) != -1) {
  108. uni.showModal({
  109. title: "提示",
  110. content: "检测到一个分享链接是否跳转?",
  111. confirmText: "跳转",
  112. success: function (callback) {
  113. if (callback.confirm) {
  114. const path = res.split(config.shareLink)[1];
  115. if (path.indexOf("tabbar") != -1) {
  116. uni.switchTab({
  117. url: path,
  118. });
  119. } else {
  120. uni.navigateTo({
  121. url: path,
  122. });
  123. }
  124. }
  125. },
  126. });
  127. }
  128. },
  129. /**
  130. * h5中打开app获取跳转app的链接并跳转
  131. */
  132. checkArguments() {
  133. // #ifdef APP-PLUS
  134. setTimeout(() => {
  135. const args = plus.runtime.arguments;
  136. if (args) {
  137. const argsStr = decodeURIComponent(args);
  138. const path = argsStr.split("//")[1];
  139. if (path.indexOf("tabbar") != -1) {
  140. uni.switchTab({
  141. url: `/${path}`,
  142. });
  143. } else {
  144. uni.navigateTo({
  145. url: `/${path}`,
  146. });
  147. }
  148. }
  149. });
  150. // #endif
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="scss">
  156. @import "uview-ui/index.scss";
  157. @import "./static/font/iconfont/iconfont.css";
  158. // -------适配底部安全区 苹果x系列刘海屏
  159. // #ifdef MP-WEIXIN
  160. .mp-iphonex-bottom {
  161. padding-bottom: constant(safe-area-inset-bottom);
  162. padding-bottom: env(safe-area-inset-bottom);
  163. box-sizing: content-box;
  164. height: auto !important;
  165. padding-top: 10rpx;
  166. }
  167. // #endif
  168. body {
  169. background-color: $bg-color;
  170. }
  171. /************************ */
  172. .w200 {
  173. width: 200rpx !important;
  174. }
  175. .flex1 {
  176. flex: 1; //必须父级设置flex
  177. }
  178. </style>