App.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. // 兼容商品详情二维码跳转
  53. if (params.isbn) {
  54. // 将 isbn 存入全局或缓存,以便 detail 页面如果在 onLoad 没拿到时可以使用
  55. uni.setStorageSync('scene_isbn', params.isbn);
  56. }
  57. // 兼容红包二维码跳转
  58. if (params.bianhao) {
  59. uni.setStorageSync('scene_bianhao', params.bianhao);
  60. }
  61. this.slientLogin(params);
  62. } else {
  63. this.slientLogin();
  64. }
  65. } else {
  66. this.slientLogin(options.query);
  67. // 如果链接参数中有一个名为 upsellCode 的参数
  68. if (options.query.upsellCode) {
  69. uni.setStorageSync('upsellCode', options.query.upsellCode)
  70. }
  71. }
  72. } else {
  73. this.slientLogin()
  74. }
  75. },
  76. onShow() {
  77. this.$updateCartBadge();
  78. },
  79. onUnload() {
  80. uni.removeStorageSync('loginType')
  81. },
  82. methods: {
  83. slientLogin(params = {}) {
  84. let that = this;
  85. uni.login({
  86. success(res) {
  87. //plat integer($int32)平台 1-微信 2-支付宝
  88. let platform = uni.getSystemInfoSync().uniPlatform
  89. let data = { code: res.code, plat: platform === 'mp-alipay' ? 2 : 1 }
  90. data = { ...data, ...params }
  91. uni.setStorageSync('loginType', data)
  92. console.log('登录参数:', data)
  93. uni.$u.http
  94. .post("/user/miniLogin", data)
  95. .then((response) => {
  96. if (response.code == 200) {
  97. uni.setStorageSync("loginSuccess", response.data);
  98. uni.setStorageSync("token", response.data.token);
  99. console.log("登录成功返回参数", response.data, data);
  100. eventBus.emit('loginSuccess', { response: response.data, params: data })
  101. that.globalData.isColdLaunch = false;
  102. that.$updateCartBadge();
  103. }
  104. });
  105. },
  106. fail: (err) => {
  107. console.log(err, "wx.login登录失败");
  108. },
  109. });
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss">
  115. // ===
  116. // === 注意:此处导入的css,会作用于全部.vue文件,请适量导入
  117. // ===
  118. body {
  119. font-family: PingFang-SC-Regular, PingFang-SC;
  120. }
  121. page {
  122. background-color: $app-theme-bg-gray-deep-color;
  123. }
  124. @import "uview-ui/index.scss";
  125. @import "./static/css/common.scss";
  126. /* 解决小程序和app滚动条的问题 */
  127. /* #ifdef MP-WEIXIN || APP-PLUS */
  128. ::-webkit-scrollbar {
  129. display: none;
  130. width: 0 !important;
  131. height: 0 !important;
  132. -webkit-appearance: none;
  133. background: transparent;
  134. color: transparent;
  135. }
  136. /* #endif */
  137. /* 解决H5 的问题 */
  138. /* #ifdef H5 */
  139. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  140. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  141. display: none;
  142. width: 0 !important;
  143. height: 0 !important;
  144. -webkit-appearance: none;
  145. background: transparent;
  146. color: transparent;
  147. }
  148. /* #endif */
  149. .shu-elip-1 {
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. white-space: nowrap;
  153. }
  154. .shu-elip-2 {
  155. display: -webkit-box;
  156. overflow: hidden;
  157. text-overflow: ellipsis;
  158. word-wrap: break-word;
  159. white-space: normal !important;
  160. -webkit-line-clamp: 2;
  161. -webkit-box-orient: vertical;
  162. }
  163. // 导出 scss 变量用于在 script 下使用
  164. .price_color {
  165. color: $app-theme-text-money-color;
  166. }
  167. .color_blue {
  168. color: $app-theme-blue;
  169. }
  170. .btnGroup {
  171. display: flex;
  172. align-items: center;
  173. .btn {
  174. margin: 0 10rpx;
  175. }
  176. }
  177. .mallbtn {
  178. min-width: 200rpx;
  179. line-height: 66rpx;
  180. padding: 0 20rpx;
  181. border-radius: 36rpx;
  182. color: #ffffff;
  183. margin-right: 20rpx;
  184. text-align: center;
  185. flex: 1;
  186. padding: 0 30rpx;
  187. }
  188. .soldOutBtn {
  189. @extend .mallbtn;
  190. background-color: $app-theme-nobuy-bg-color;
  191. }
  192. .joinCartBtn {
  193. @extend .mallbtn;
  194. background-color: $app-theme-joincart-bg-color;
  195. }
  196. .buyBtn {
  197. @extend .mallbtn;
  198. background-color: $app-theme-buybtn-bg-color;
  199. }
  200. </style>