App.vue 4.8 KB

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