App.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <script>
  2. import { eventBus } from '@/utils/event-bus'
  3. export default {
  4. globalData: {
  5. // 胶囊距上距离
  6. menuTop: 0,
  7. // 导航栏高度
  8. navBarHeight: 0,
  9. // 胶囊距右方间距(方保持左、右间距一致)
  10. menuRight: 0,
  11. // 胶囊距底部间距(保持底部间距一致)
  12. menuBotton: 0,
  13. // 胶囊高度(自定义内容可与胶囊高度保证一致)
  14. menuHeight: 0,
  15. // 状态栏高度
  16. statusBarHeight: 0,
  17. // 安全距离
  18. safeAreaHeight: 0,
  19. // 胶囊宽度
  20. menuWidth: 0,
  21. // 窗口宽度
  22. windowWidth: 0,
  23. // 窗口宽度高度
  24. windowHeight: 0,
  25. // 常规子页面可操作区域高度
  26. pageContentHeight: 0,
  27. // 是否是冷启动
  28. isColdLaunch: false,
  29. },
  30. onLaunch(options) {
  31. this.globalData.isColdLaunch = true;
  32. console.log('冷启动onLaunch:',this.globalData.isColdLaunch)
  33. let params = {};
  34. if (options.query) {
  35. //微信小程序的场景值解析
  36. if (options.query.scene) {
  37. // 对 scene 进行解码
  38. const decodeScene = decodeURIComponent(options.query.scene);
  39. // 拆分参数
  40. const paramPairs = decodeScene.split('&');
  41. paramPairs.forEach((pair) => {
  42. const [key, value] = pair.split('=');
  43. params[key] = value;
  44. });
  45. let keys = Object.keys(params)
  46. if (keys.length > 0) {
  47. console.log(params, "params");
  48. // 如果链接参数中有一个名为 upsellCode 的参数
  49. if (params.upsellCode) {
  50. uni.setStorageSync('upsellCode', params.upsellCode)
  51. }
  52. this.slientLogin(params);
  53. } else {
  54. this.slientLogin();
  55. }
  56. } else {
  57. this.slientLogin(options.query);
  58. // 如果链接参数中有一个名为 upsellCode 的参数
  59. if (options.query.upsellCode) {
  60. uni.setStorageSync('upsellCode', options.query.upsellCode)
  61. }
  62. }
  63. } else {
  64. this.slientLogin()
  65. }
  66. },
  67. onShow() {
  68. this.$updateCartBadge();
  69. },
  70. onUnload() {
  71. uni.removeStorageSync('loginType')
  72. },
  73. methods: {
  74. slientLogin(params = {}) {
  75. let that = this;
  76. uni.login({
  77. success(res) {
  78. //plat integer($int32)平台 1-微信 2-支付宝
  79. let platform = uni.getSystemInfoSync().uniPlatform
  80. let data = { code: res.code, plat: platform === 'mp-alipay' ? 2 : 1 }
  81. data = { ...data, ...params }
  82. uni.setStorageSync('loginType', data)
  83. console.log('登录参数:', data)
  84. uni.$u.http
  85. .post("/user/miniLogin", data)
  86. .then((response) => {
  87. if (response.code == 200) {
  88. uni.setStorageSync("loginSuccess", response.data);
  89. uni.setStorageSync("token", response.data.token);
  90. console.log("登录成功返回参数", response.data, data);
  91. eventBus.emit('loginSuccess', { response: response.data, params: data })
  92. that.globalData.isColdLaunch = false;
  93. that.$updateCartBadge();
  94. }
  95. });
  96. },
  97. fail: (err) => {
  98. console.log(err, "wx.login登录失败");
  99. },
  100. });
  101. },
  102. },
  103. };
  104. </script>
  105. <style lang="scss">
  106. // ===
  107. // === 注意:此处导入的css,会作用于全部.vue文件,请适量导入
  108. // ===
  109. body {
  110. font-family: PingFang-SC-Regular, PingFang-SC;
  111. }
  112. page {
  113. background-color: $app-theme-bg-gray-deep-color;
  114. }
  115. @import "uview-ui/index.scss";
  116. @import "./static/css/common.scss";
  117. /* 解决小程序和app滚动条的问题 */
  118. /* #ifdef MP-WEIXIN || APP-PLUS */
  119. ::-webkit-scrollbar {
  120. display: none;
  121. width: 0 !important;
  122. height: 0 !important;
  123. -webkit-appearance: none;
  124. background: transparent;
  125. color: transparent;
  126. }
  127. /* #endif */
  128. /* 解决H5 的问题 */
  129. /* #ifdef H5 */
  130. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  131. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  132. display: none;
  133. width: 0 !important;
  134. height: 0 !important;
  135. -webkit-appearance: none;
  136. background: transparent;
  137. color: transparent;
  138. }
  139. /* #endif */
  140. .shu-elip-1 {
  141. overflow: hidden;
  142. text-overflow: ellipsis;
  143. white-space: nowrap;
  144. }
  145. .shu-elip-2 {
  146. display: -webkit-box;
  147. overflow: hidden;
  148. text-overflow: ellipsis;
  149. word-wrap: break-word;
  150. white-space: normal !important;
  151. -webkit-line-clamp: 2;
  152. -webkit-box-orient: vertical;
  153. }
  154. // 导出 scss 变量用于在 script 下使用
  155. .price_color {
  156. color: $app-theme-text-money-color;
  157. }
  158. .color_blue {
  159. color: $app-theme-blue;
  160. }
  161. .btnGroup {
  162. display: flex;
  163. align-items: center;
  164. .btn {
  165. margin: 0 10rpx;
  166. }
  167. }
  168. .mallbtn {
  169. min-width: 200rpx;
  170. line-height: 66rpx;
  171. padding: 0 20rpx;
  172. border-radius: 36rpx;
  173. color: #ffffff;
  174. margin-right: 20rpx;
  175. text-align: center;
  176. flex: 1;
  177. padding: 0 30rpx;
  178. }
  179. .soldOutBtn {
  180. @extend .mallbtn;
  181. background-color: $app-theme-nobuy-bg-color;
  182. }
  183. .joinCartBtn {
  184. @extend .mallbtn;
  185. background-color: $app-theme-joincart-bg-color;
  186. }
  187. .buyBtn {
  188. @extend .mallbtn;
  189. background-color: $app-theme-buybtn-bg-color;
  190. }
  191. </style>