App.vue 4.9 KB

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