| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <script>
- export default {
- globalData: {
- // 胶囊距上距离
- menuTop: 0,
- // 导航栏高度
- navBarHeight: 0,
- // 胶囊距右方间距(方保持左、右间距一致)
- menuRight: 0,
- // 胶囊距底部间距(保持底部间距一致)
- menuBotton: 0,
- // 胶囊高度(自定义内容可与胶囊高度保证一致)
- menuHeight: 0,
- // 状态栏高度
- statusBarHeight: 0,
- // 安全距离
- safeAreaHeight: 0,
- // 胶囊宽度
- menuWidth: 0,
- // 窗口宽度
- windowWidth: 0,
- // 窗口宽度高度
- windowHeight: 0,
- // 常规子页面可操作区域高度
- pageContentHeight: 0,
- },
- onLaunch(options) {
- const that = this;
- // 获取系统信息
- const systemInfo = uni.getSystemInfoSync();
- // 胶囊按钮位置信息
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
- console.log(menuButtonInfo);
- // 导航栏高度 = 状态栏到胶囊的间距(胶囊距上距离-状态栏高度) * 2 + 胶囊高度 + 状态栏高度
- that.globalData.menuTop = menuButtonInfo.top - systemInfo.statusBarHeight;
- that.globalData.menuBotton = menuButtonInfo.top - systemInfo.statusBarHeight;
- that.globalData.menuWidth = menuButtonInfo.width;
- that.globalData.navBarHeight =
- (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo.height + systemInfo.statusBarHeight;
- that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
- that.globalData.menuHeight = menuButtonInfo.height;
- that.globalData.statusBarHeight = systemInfo.statusBarHeight;
- that.globalData.safeAreaHeight = systemInfo.safeAreaInsets.bottom;
- that.globalData.windowWidth = systemInfo.windowWidth;
- that.globalData.windowHeight = systemInfo.windowHeight;
- that.globalData.pageContentHeight =
- systemInfo.windowHeight -
- (that.globalData.navBarHeight + that.globalData.menuTop + that.globalData.menuBotton);
- console.log(options, "onLaunch系统信息");
- let params = {};
- if (options.query) {
- if (options.query.scene) {
- // 对 scene 进行解码
- const decodeScene = decodeURIComponent(options.query.scene);
- // 拆分参数
- const paramPairs = decodeScene.split('&');
- paramPairs.forEach((pair) => {
- const [key, value] = pair.split('=');
- params[key] = value;
- });
- console.log('解析出的 scene 参数:', params);
- // 假设链接参数中有一个名为 inviteCode 的参数
- if (params.inviteCode) {
- uni.setStorageSync('inviteCode', params.inviteCode)
- console.log('解析出的 inviteCode 参数:', params.inviteCode);
- this.slientLogin(params.inviteCode, 'inviteCode');
- } else if (params.upsellCode) {
- // 用于书籍加价的邀请码,关联订单 id 和 isbn
- uni.setStorageSync('upsellCode', params.upsellCode)
- that.globalData.upsellCode = params.upsellCode
- console.log('解析出的 upsellCode 参数:', params.upsellCode);
- this.slientLogin(params.upsellCode, 'upsellCode');
- } else {
- this.slientLogin();
- }
- }
- // 如果链接参数中有一个名为 inviteCode 的参数
- if (options.query.inviteCode) {
- uni.setStorageSync('inviteCode', options.query.inviteCode)
- this.slientLogin(options.query.inviteCode, 'inviteCode');
- }
- // 如果链接参数中有一个名为 upsellCode 的参数
- if (options.query.upsellCode) {
- uni.setStorageSync('upsellCode', options.query.upsellCode)
- that.globalData.upsellCode = options.query.upsellCode
- this.slientLogin(options.query.upsellCode, 'upsellCode');
- }
- }else{
- this.slientLogin()
- }
- },
- methods: {
- slientLogin(code2, type) {
- uni.login({
- success(res) {
- //plat integer($int32)平台 1-微信 2-支付宝
- let platform = uni.getSystemInfoSync().uniPlatform
- console.log(platform, 'platform')
- let data = { code: res.code, plat: platform === 'mp-alipay' ? 2 : 1 }
- if (type) {
- data[type] = code2
- }
- uni.setStorageSync('loginType', data)
- uni.$u.http
- .post("/user/miniLogin", data)
- .then((response) => {
- if (response.code == 200) {
- console.log(response.data, data, "登录成功");
- uni.setStorageSync("loginSuccess", response.data);
- uni.setStorageSync("token", response.data.token);
- }
- });
- },
- fail: (err) => {
- console.log(err, "wx.login登录失败");
- },
- });
- },
- },
- };
- </script>
- <style lang="scss">
- // ===
- // === 注意:此处导入的css,会作用于全部.vue文件,请适量导入
- // ===
- body {
- font-family: PingFang-SC-Regular, PingFang-SC;
- }
- page {
- background-color: $app-theme-bg-gray-deep-color;
- }
- @import "uview-ui/index.scss";
- @import "./static/css/common.scss";
- /* 解决小程序和app滚动条的问题 */
- /* #ifdef MP-WEIXIN || APP-PLUS */
- ::-webkit-scrollbar {
- display: none;
- width: 0 !important;
- height: 0 !important;
- -webkit-appearance: none;
- background: transparent;
- color: transparent;
- }
- /* #endif */
- /* 解决H5 的问题 */
- /* #ifdef H5 */
- uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
- /* 隐藏滚动条,但依旧具备可以滚动的功能 */
- display: none;
- width: 0 !important;
- height: 0 !important;
- -webkit-appearance: none;
- background: transparent;
- color: transparent;
- }
- /* #endif */
- .shu-elip-1 {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .shu-elip-2 {
- display: -webkit-box;
- overflow: hidden;
- text-overflow: ellipsis;
- word-wrap: break-word;
- white-space: normal !important;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- // 导出 scss 变量用于在 script 下使用
- .price_color {
- color: $app-theme-text-money-color;
- }
- .color_blue {
- color: $app-theme-blue;
- }
- .btnGroup {
- display: flex;
- align-items: center;
- .btn {
- margin: 0 10rpx;
- }
- }
- .mallbtn {
- min-width: 200rpx;
- line-height: 66rpx;
- padding: 0 20rpx;
- border-radius: 36rpx;
- color: #ffffff;
- margin-right: 20rpx;
- text-align: center;
- flex: 1;
- padding: 0 30rpx;
- }
- .soldOutBtn {
- @extend .mallbtn;
- background-color: $app-theme-nobuy-bg-color;
- }
- .joinCartBtn {
- @extend .mallbtn;
- background-color: $app-theme-joincart-bg-color;
- }
- .buyBtn {
- @extend .mallbtn;
- background-color: $app-theme-buybtn-bg-color;
- }
- </style>
|