diff --git a/common/scene.js b/common/scene.js new file mode 100644 index 0000000..1d93d07 --- /dev/null +++ b/common/scene.js @@ -0,0 +1,5 @@ +// 分享相关场景值 +export const V2_GOODS_SHAREBUTTON = "101"; +export const V2_GOODS_SHAREPOSTER = "102"; +export const V2_HOME_SHAREBUTTON = "103"; +export const V2_INVITE_SHAREPOSTER = "104"; \ No newline at end of file diff --git a/main.js b/main.js index ce39b2e..9aa9122 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ import Vue from 'vue' import App from './App' import mixin from '@/common/mixin.js'; import * as API from '@/common/api.js'; +import * as $scene from '@/common/scene.js'; import * as $shared from '@/common/shared.js'; import { uploadFile } from '@/common/uploadFile.js' @@ -12,6 +13,8 @@ Vue.mixin(mixin); // 将API注入全局 Vue.prototype.API = API; +// 场景值 +Vue.prototype.$scene = $scene; // 全局共享方法 Vue.prototype.$shared = $shared; diff --git a/pages/center/invite.vue b/pages/center/invite.vue index 6dc996a..09d784d 100644 --- a/pages/center/invite.vue +++ b/pages/center/invite.vue @@ -77,12 +77,13 @@ }, getWxCode() { let userInfo = uni.getStorageSync('userinfo') || {}; - const token = this.$shared.createToken(); + const token = this.$shared.createToken({user_id: userInfo.id}); let options = { route: 'home', pt: 2, id: 2, - share_id: userInfo.id + share_id: userInfo.id, + scene_code: this.$scene.V2_INVITE_SHAREPOSTER } this.generateKooken(token, options); // 谁分享了就生成一个token @@ -97,6 +98,17 @@ } }) }, + generateKooken(token, options){ + options.version = this.API.VERSION; + let values = JSON.stringify(options); + values = encodeURIComponent(values); + this.$http(this.API.API_WAREHOUSE_SET, { + key: token, + value: values + }).then(res => { + console.log("res", token, res); + }); + }, //保存二维码 getwxCodeImg() { var imgSrc = this.wxCode; //base64编码 diff --git a/pages/goodsDetail/index.vue b/pages/goodsDetail/index.vue index 6fa7f19..ff82838 100644 --- a/pages/goodsDetail/index.vue +++ b/pages/goodsDetail/index.vue @@ -142,7 +142,8 @@ backgroundImg: '', goodShare: '', s_id: '', - isShowButtonCount: 0 + isShowButtonCount: 0, + userInfo: {} } }, computed: { @@ -155,7 +156,8 @@ onLoad(options) { this.goods_id = options.id; this.pt = options.pt || 1; - this.s_id = options.share_id || '' + this.s_id = options.share_id || ''; + this.userInfo = uni.getStorageSync('userinfo') || {}; this.getGoodsDetail(); }, methods: { @@ -218,13 +220,16 @@ }) }, getWxCode() { - let userInfo = uni.getStorageSync('userinfo') || {}; - const token = this.$shared.createToken(); + const token = this.$shared.createToken({ + user_id: this.userInfo.id, + goods_id: this.goods_id + }); let options = { route: 'goods', pt: 2, id: this.goods_id, - share_id: userInfo.id + share_id: this.userInfo.id, + scene_code: this.$scene.V2_GOODS_SHAREPOSTER } this.generateKooken(token, options); // 谁分享了就生成一个token @@ -475,7 +480,9 @@ }, // 将token上传到后端 generateKooken(token, options){ + options.version = this.API.VERSION; let values = JSON.stringify(options); + values = encodeURIComponent(values); this.$http(this.API.API_WAREHOUSE_SET, { key: token, value: values @@ -485,11 +492,15 @@ } }, onShareAppMessage() { - const token = this.$shared.createToken(); + const token = this.$shared.createToken({ + user_id: this.userInfo.id, + goods_id: this.goods_id + }); let goods = this.goods_detail; let options = { id: goods.id, - route: 'goods' + route: 'goods', + scene_code: this.$scene.V2_GOODS_SHAREPOSTER } this.generateKooken(token, options); // 谁分享了就生成一个token @@ -818,7 +829,8 @@ width: 80%; height: 80%; position: fixed; - top: 50rpx; + // top: 50rpx; + top: 140rpx; left: 50%; margin-left: -40%; z-index: 100; @@ -832,7 +844,7 @@ line-height: 80rpx; text-align: center; position: fixed; - bottom: 50rpx; + bottom: 100rpx; left: 10%; background: rgba(254, 153, 3, 1); color: #fff; diff --git a/pages/index/index.vue b/pages/index/index.vue index ea3a9fc..7bfe630 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -192,6 +192,17 @@ onRefresherrefresh(){ this.isRefresher = true; this.getCategoryList({type: 'scrollRefresh'}); + }, + generateKooken(token, options){ + options.version = this.API.VERSION; + let values = JSON.stringify(options); + values = encodeURIComponent(values); + this.$http(this.API.API_WAREHOUSE_SET, { + key: token, + value: values + }).then(res => { + console.log("res", token, res); + }); } }, // page 下拉刷新 @@ -209,7 +220,8 @@ }, onShareAppMessage(){ const token = this.$shared.createToken(); - let options = {route: 'home'}; + const scene_code = this.$scene.V2_HOME_SHAREBUTTON; + let options = {route: 'home', scene_code}; this.generateKooken(token, options); // 谁分享了就生成一个token let shareInfo = { diff --git a/pages/route/index.vue b/pages/route/index.vue index c465327..5e98425 100644 --- a/pages/route/index.vue +++ b/pages/route/index.vue @@ -25,7 +25,9 @@ getTokenValue(token){ this.$http(this.API.API_WAREHOUSE_GET, {key: token}).then(res => { console.log("getTokenValue", res); - let options = JSON.parse(res.data); + let options = decodeURIComponent(res.data); + options = JSON.parse(options); + console.log("options", options) this.routeToPage(options); }).catch(err => { // 当token获取失败,则默认跳转到首页