diff --git a/src/App.vue b/src/App.vue index 6792a14..483c10f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,13 +29,10 @@ export default { // #endif }, onShow(option) { - let invite_code = option.query.invite_code || strToParams(decodeURIComponent(option.query.scene)).invite_code + let invite_code = option.query.invite_code || strToParams(decodeURIComponent(option.query.scene)).invite_code||'' uni.setStorageSync('INVITE_CODE',invite_code) /* #ifdef MP-WEIXIN */ - if(!invite_code){ - wxMnpLogin() - } - + // wxMnpLogin(invite_code) /* #endif */ }, onHide: function () { diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index a221165..867800a 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -121,7 +121,7 @@ export default { const invite_code = uni.getStorageSync('INVITE_CODE'); // const code = await getWxCode(); if(!this.$store.getters.token){ - await wxMnpLogin() + await wxMnpLogin(invite_code) } const params = {} if(!!invite_code) params.inviter_code = invite_code @@ -130,6 +130,7 @@ export default { code:code, ...params }); + //invite_code%3D1%26order_pre%3D1 await this.LOGIN(resData.token); // await this.LOGIN('555|bZL3mr19Tpgs4jRvpKkguoH865lL2zGLa35WdU7Z') if(!!this.redirec) this.$u.route({ diff --git a/src/pages/product_details/index.vue b/src/pages/product_details/index.vue index 5513611..4cbe18b 100644 --- a/src/pages/product_details/index.vue +++ b/src/pages/product_details/index.vue @@ -382,6 +382,9 @@ export default { isFirstLoading: true, isNull: false, loading: false, + // 商品SPU-ID + productId: '', + // 选择的SKU-ID skuId: '', number: 1, products: {}, @@ -482,7 +485,7 @@ export default { if (showShrough) { this.showShrough = showShrough; } - this.skuId = skuId; + this.productId = skuId; this.getProducts(); this.$store.dispatch('goods/getCartList'); }, @@ -495,7 +498,7 @@ export default { let code = this.user.code ? this.user.code : ''; let shareObj = { title: this.detail.name, - path: `/pages/product_details/index?skuId=${this.skuId}&invite_code=${code}`, + path: `/pages/product_details/index?product=${this.productId}&invite_code=${code}`, imageUrl: this.detail.cover, }; return shareObj; @@ -604,8 +607,9 @@ export default { async getProducts() { try { this.loading = true; - const resData = await this.$api.get(`/v1/product/products/${this.skuId}`); + const resData = await this.$api.get(`/v1/product/products/${this.productId}`); this.products = resData; + this.skuId = this.products?.sku.id if (resData?.sku?.is_bargaing) { this.bargainOrderLog(); @@ -649,7 +653,7 @@ export default { this.loading = true; const resData = await this.$api.get(`/v1/product/sku/${this.skuId}`); this.products = resData; - + if (resData?.sku?.is_bargaing) { this.bargainOrderLog(); } diff --git a/src/pages/welcome/index.vue b/src/pages/welcome/index.vue index e5324d4..35dcd92 100644 --- a/src/pages/welcome/index.vue +++ b/src/pages/welcome/index.vue @@ -18,18 +18,39 @@ onLoad(e) { const scene = strToParams(decodeURIComponent(e.scene)) this.scene=scene - uni.setStorageSync('INVITE_CODE', scene.invite_code) + // 优先存储 invite_code + if (scene.invite_code) { + uni.setStorageSync('INVITE_CODE', scene.invite_code) + } + + // 产品详细页 if (scene.product) { uni.redirectTo({ url: '/pages/product_details/index?skuId=' + scene.product }) - uni.setStorageSync('INVITE_CODE', scene.code) - } else if (scene.order_pre) { - }else if(scene.invite_code){ + } + // 扫码下单 + else if (scene.order_pre) { + // setTimeout(async () => { + // uni.showLoading({ + // title: '加载中', + // mask: true + // }); + // const obj = { + // id: scene.order_pre + // } + // const { order_id } = await this.$api.post(`/v1/order-pre/order`, obj) + // uni.hideLoading() + // uni.redirectTo({ + // url: '/pages/order_details/index?id=' + order_id + // }) + // }, 1000) + } + // 默认跳转首页 + else { uni.redirectTo({ url: '/pages/index/index' }) - uni.setStorageSync('INVITE_CODE', scene.invite_code) } }, onShow() { diff --git a/src/utils/login.js b/src/utils/login.js index 2edd37c..37c8b09 100644 --- a/src/utils/login.js +++ b/src/utils/login.js @@ -19,10 +19,10 @@ export function getWxCode() { } //小程序静默登录 -export async function wxMnpLogin(){ +export async function wxMnpLogin(invite_code){ store.commit('user/LOGOUT') const code = await getWxCode() - const invite_code= uni.getStorageSync('INVITE_CODE')||null + invite_code=invite_code?invite_code: uni.getStorageSync('INVITE_CODE') await silentLogin({code,invite_code}) }