App.vue 6.0 KB

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