Commit 0862a107 authored by beisir's avatar beisir

feat:更改 分享通信方式

parent a95d9fd0
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
import MpBridge from '@/service/mp'; import MpBridge from '@/service/mp';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import { registeredEvents } from '@/service/sa.service'; import { registeredEvents } from '@/service/sa.service';
import { EventBus } from '@/service/utils.service';
export default { export default {
name: 'GroupShare', name: 'GroupShare',
components: {}, components: {},
...@@ -53,10 +52,7 @@ export default { ...@@ -53,10 +52,7 @@ export default {
this.shareDialogConfirm(); this.shareDialogConfirm();
} }
const nativeBridge = this.nativeBridge; const nativeBridge = this.nativeBridge;
const name = this.$route.name; this.$store.dispatch('goods_send_shareinfo', { ev, nativeBridge });
console.log(`shareClickItem${name}`);
console.log(name);
EventBus.$emit(`shareClickItem${name}`, { ev, nativeBridge });
registeredEvents('H5_GroupZeroYuanPurchaseActivityPageSharePopupWindowBtnClick', { registeredEvents('H5_GroupZeroYuanPurchaseActivityPageSharePopupWindowBtnClick', {
sku_no: '', sku_no: '',
buttons_name: '', // 按钮名称 buttons_name: '', // 按钮名称
......
...@@ -15,7 +15,7 @@ module.exports = [ ...@@ -15,7 +15,7 @@ module.exports = [
path: '/groupBuy/list', path: '/groupBuy/list',
name: 'groupBuyList', name: 'groupBuyList',
component: () => import('../views/goodsList/index.vue'), component: () => import('../views/goodsList/index.vue'),
meta: { title: '0元购大牌' } meta: { title: '0元购大牌', keepLive: true }
}, },
{ {
path: '/orderList/:status', path: '/orderList/:status',
......
...@@ -11,7 +11,8 @@ const state = { ...@@ -11,7 +11,8 @@ const state = {
isPrimordialBrowser: false, // 是否是原生浏览器 isPrimordialBrowser: false, // 是否是原生浏览器
isWeixinBrowser: false, // 是否是微信浏览器 isWeixinBrowser: false, // 是否是微信浏览器
showShare: false, // 是否打开底部分享showShare showShare: false, // 是否打开底部分享showShare
shareInfo: {} // 分享信息 shareInfo: {}, // 分享信息
goodsShareInfo: null
}; };
// getters // getters
...@@ -45,6 +46,9 @@ const actions = { ...@@ -45,6 +46,9 @@ const actions = {
}, },
goods_share_close({ commit }) { goods_share_close({ commit }) {
commit(types.GOODS_SHARE_CLOSE); commit(types.GOODS_SHARE_CLOSE);
},
goods_send_shareinfo({ commit }, options) {
commit(types.GOODS_SEND_SHAREINFO, options);
} }
}; };
...@@ -121,6 +125,9 @@ const mutations = { ...@@ -121,6 +125,9 @@ const mutations = {
}, },
[types.GOODS_SHARE_CLOSE](state) { [types.GOODS_SHARE_CLOSE](state) {
state.showShare = false; state.showShare = false;
},
[types.GOODS_SEND_SHAREINFO](state, options) {
state.goodsShareInfo = options;
} }
}; };
......
...@@ -9,3 +9,4 @@ export const DEL_KEEP_ALIVE = 'DEL_KEEP_ALIVE'; ...@@ -9,3 +9,4 @@ export const DEL_KEEP_ALIVE = 'DEL_KEEP_ALIVE';
export const CLEAR_KEEP_ALIVE = 'CLEAR_KEEP_ALIVE'; export const CLEAR_KEEP_ALIVE = 'CLEAR_KEEP_ALIVE';
export const GOODS_SHARE_OPEN = 'GOODS_SHARE_OPEN'; export const GOODS_SHARE_OPEN = 'GOODS_SHARE_OPEN';
export const GOODS_SHARE_CLOSE = 'GOODS_SHARE_CLOSE'; export const GOODS_SHARE_CLOSE = 'GOODS_SHARE_CLOSE';
export const GOODS_SEND_SHAREINFO = 'GOODS_SEND_SHAREINFO';
...@@ -82,10 +82,12 @@ import groupSwiper from '@/components/groupSwiper'; ...@@ -82,10 +82,12 @@ import groupSwiper from '@/components/groupSwiper';
import { handleRemainTime, handleDateFormat } from './components/utils'; import { handleRemainTime, handleDateFormat } from './components/utils';
import localStorage from '@/service/localStorage.service'; import localStorage from '@/service/localStorage.service';
import goodsCheckMixin from '@/mixins/goodsCheck.mixin'; import goodsCheckMixin from '@/mixins/goodsCheck.mixin';
import { setAppTitleColor, EventBus } from '@/service/utils.service'; import { setAppTitleColor } from '@/service/utils.service';
import { registeredEvents } from '@/service/sa.service'; import { registeredEvents } from '@/service/sa.service';
import { isNull } from '@/service/validation.service';
import config from '@/config'; import config from '@/config';
console.log(config.localHost); console.log(config.localHost);
let topicIndex;
export default { export default {
// eslint-disable-next-line vue/name-property-casing // eslint-disable-next-line vue/name-property-casing
name: 'groupBuyList', name: 'groupBuyList',
...@@ -115,6 +117,9 @@ export default { ...@@ -115,6 +117,9 @@ export default {
isShowShare() { isShowShare() {
return this.$store.state.pay.isPrimordialBrowser; return this.$store.state.pay.isPrimordialBrowser;
}, },
goodsShareInfo() {
return this.$store.state.pay.goodsShareInfo;
},
isShowSwiper() { isShowSwiper() {
const { hasStart, hasStop } = this.goodsTemp; const { hasStart, hasStop } = this.goodsTemp;
return (!hasStart && !hasStop) || (hasStart && hasStop); return (!hasStart && !hasStop) || (hasStart && hasStop);
...@@ -128,21 +133,19 @@ export default { ...@@ -128,21 +133,19 @@ export default {
return +new Date(endTime || 0); return +new Date(endTime || 0);
} }
}, },
watch: {
goodsShareInfo: {
immediate: false,
handler(val) {
this.onShareEventChange(val);
}
}
},
created() { created() {
this.reload = true; this.reload = true;
// console.log(this.isShowShare);
// console.log(this.activityId);
// this.hasLogin = !!localStorage.get('vccToken');
}, },
mounted() { mounted() {
this.showLoops = true; this.showLoops = true;
this.$nextTick(() => {
this.$refs.swipeRota && this.$refs.swipeRota.onSlidePrevChange();
});
this.showLoading = true;
this.onShareEventChange();
console.log('开启EventBus');
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
const { activityId } = to.query; const { activityId } = to.query;
...@@ -153,30 +156,25 @@ export default { ...@@ -153,30 +156,25 @@ export default {
}); });
return; return;
} else { } else {
if (isNull(topicIndex)) {
getActivityList(to.query, next); getActivityList(to.query, next);
} else {
next();
}
} }
}, },
beforeDestroy() { // beforeDestroy() {
console.log('关闭EventBus'); // },
const name = this.$route.name; deactivated() {
EventBus.$off(`shareClickItem${name}`);
clearTimeout((this.$refs.swipeRota && this.$refs.swipeRota.timer) || null); clearTimeout((this.$refs.swipeRota && this.$refs.swipeRota.timer) || null);
this.showLoops = false; this.showLoops = false;
}, },
// deactivated() { activated() {
// clearTimeout((this.$refs.swipeRota && this.$refs.swipeRota.timer) || null); this.showLoops = true;
// this.showLoops = false; this.$nextTick(() => {
// }, this.$refs.swipeRota && this.$refs.swipeRota.onSlidePrevChange();
// activated() { });
// this.showLoops = true; },
// this.$nextTick(() => {
// this.$refs.swipeRota && this.$refs.swipeRota.onSlidePrevChange();
// });
// console.log('开启EventBus');
// // this.setTitleColor(this.goodsTemp.bgcolor);
// // store.commit('changeTitle', this.goodsTemp.title || '活动页');
// },
methods: { methods: {
animationEventStart() { animationEventStart() {
this.showSwipe = false; this.showSwipe = false;
...@@ -202,13 +200,10 @@ export default { ...@@ -202,13 +200,10 @@ export default {
activity_id activity_id
}); });
}, },
onShareEventChange() { async onShareEventChange({ ev, nativeBridge }) {
const vm = this; const vm = this;
const name = this.$route.name;
EventBus.$on(`shareClickItem${name}`, async function({ ev, nativeBridge }) {
let shareDic = await vm.getShareData(); let shareDic = await vm.getShareData();
if (ev === 'pic') { if (ev === 'pic') {
// 分享海报跳转小程序海报分享页面
nativeBridge.openNewUrl({ nativeBridge.openNewUrl({
newUrl: `/pages/goodshare/index?url=${encodeURIComponent( newUrl: `/pages/goodshare/index?url=${encodeURIComponent(
JSON.stringify(shareDic.posterUrl) JSON.stringify(shareDic.posterUrl)
...@@ -216,7 +211,6 @@ export default { ...@@ -216,7 +211,6 @@ export default {
}); });
} }
if (ev === 'weixin') { if (ev === 'weixin') {
console.log(shareDic);
// 分享朋友派发微信postMessage事件 // 分享朋友派发微信postMessage事件
nativeBridge.run({ nativeBridge.run({
event: 'showShareView', event: 'showShareView',
...@@ -225,17 +219,22 @@ export default { ...@@ -225,17 +219,22 @@ export default {
} }
}); });
} }
});
}, },
async getShareData() { async getShareData() {
const { sharePosterTemplateUrl, shareTitle, shareSubTitle, shareIconUrl } = this.goodsTemp; const {
sharePosterTemplateUrl,
shareTitle,
shareSubTitle,
shareIconUrl,
img
} = this.goodsTemp;
const link = `${config.localHost}/groupBuy/list?activityId=${this.activityId}`; const link = `${config.localHost}/groupBuy/list?activityId=${this.activityId}`;
return Promise.resolve({ return Promise.resolve({
title: shareTitle, title: shareTitle,
desc: shareSubTitle, desc: shareSubTitle,
link: `pages/webview/webview?url=${encodeURIComponent(JSON.stringify(link))}`, // 页面地址 link: `pages/webview/webview?url=${encodeURIComponent(JSON.stringify(link))}`, // 页面地址
imgUrl: shareIconUrl, // 图片地 imgUrl: shareIconUrl || img, // 图片地
posterUrl: sharePosterTemplateUrl posterUrl: sharePosterTemplateUrl
}); });
}, },
...@@ -261,7 +260,7 @@ export default { ...@@ -261,7 +260,7 @@ export default {
} }
}, },
async getGoodsList() { async getGoodsList(cover) {
const { pageSize, pageNo, activityId } = this; const { pageSize, pageNo, activityId } = this;
const { goodsSpecialIds, templateDetailIds } = this.goodsTemp; const { goodsSpecialIds, templateDetailIds } = this.goodsTemp;
this.loading = true; this.loading = true;
...@@ -277,7 +276,7 @@ export default { ...@@ -277,7 +276,7 @@ export default {
if (res.size) { if (res.size) {
this.loading = false; this.loading = false;
this.showLoading = false; this.showLoading = false;
this.goodsList = res.items || []; this.goodsList = cover ? res.items : [...this.goodsList, ...res.items] || [];
if (!res.hasNext) { if (!res.hasNext) {
this.finished = true; this.finished = true;
} else { } else {
...@@ -327,10 +326,11 @@ async function getActivityList(urlQuery, next) { ...@@ -327,10 +326,11 @@ async function getActivityList(urlQuery, next) {
t.groupBuyUserInfoList = t.groupBuyUserInfoList.reverse(); t.groupBuyUserInfoList = t.groupBuyUserInfoList.reverse();
store.commit('CHANGE_TITLE', t.title || '活动页'); store.commit('CHANGE_TITLE', t.title || '活动页');
nextFns(vm => { nextFns(vm => {
topicIndex = 0;
vm.activityId = activityId; vm.activityId = activityId;
vm.goodsTemp = t; vm.goodsTemp = t;
localStorage.set('activityId', activityId); localStorage.set('activityId', activityId);
vm.getGoodsList(); vm.getGoodsList(true);
vm.reload = false; vm.reload = false;
}); });
} else { } else {
......
...@@ -82,10 +82,23 @@ export default { ...@@ -82,10 +82,23 @@ export default {
orderStatusInfo: {} orderStatusInfo: {}
}; };
}, },
computed: {
goodsShareInfo() {
return this.$store.state.pay.goodsShareInfo;
}
},
watch: {
goodsShareInfo: {
immediate: false,
handler(val) {
this.onShareEventChange(val);
}
}
},
mounted() { mounted() {
this.getstatusQuery(); this.getstatusQuery();
this.getList(); this.getList();
this.onShareEventChange(); // this.onShareEventChange();
}, },
beforeDestroy() { beforeDestroy() {
console.log('订单页EventBusClose'); console.log('订单页EventBusClose');
...@@ -118,17 +131,14 @@ export default { ...@@ -118,17 +131,14 @@ export default {
imgUrl: shareInfo.skuImg // 图片地 imgUrl: shareInfo.skuImg // 图片地
}); });
}, },
onShareEventChange() { async onShareEventChange({ ev, nativeBridge }) {
const vm = this; const vm = this;
const name = this.$route.name;
console.log(`shareClickItem${name}`);
EventBus.$on(`shareClickItem${name}`, async function({ ev, nativeBridge }) {
console.log('订单页EventBusOpen'); console.log('订单页EventBusOpen');
const shareDic = await vm.getShareData(vm.sharePicData); const shareDic = await vm.getShareData(vm.sharePicData);
console.log(shareDic); console.log(shareDic);
if (ev === 'pic') { if (ev === 'pic') {
vm.$refs.sharePic.createAndUploadPic();
// 分享海报跳转小程序海报分享页面 // 分享海报跳转小程序海报分享页面
vm.$refs.sharePic.createAndUploadPic();
} }
if (ev === 'weixin') { if (ev === 'weixin') {
// 分享朋友派发微信postMessage事件 // 分享朋友派发微信postMessage事件
...@@ -139,7 +149,6 @@ export default { ...@@ -139,7 +149,6 @@ export default {
} }
}); });
} }
});
}, },
getstatusQuery() { getstatusQuery() {
const { status } = this.$route.params || {}; const { status } = this.$route.params || {};
...@@ -153,9 +162,9 @@ export default { ...@@ -153,9 +162,9 @@ export default {
handleLoad() { handleLoad() {
this.getList(); this.getList();
}, },
async openShareEvent() { async openShareEvent(info) {
try { try {
const [res] = await groupBuyApi.getGroupShareInfo('1440884214932389888'); const [res] = await groupBuyApi.getGroupShareInfo(info.orderNo);
console.log(res); console.log(res);
this.sharePicData = res; this.sharePicData = res;
this.$store.dispatch('goods_share_open'); this.$store.dispatch('goods_share_open');
...@@ -164,11 +173,10 @@ export default { ...@@ -164,11 +173,10 @@ export default {
} }
}, },
handleOptionClick(info) { handleOptionClick(info) {
console.log(info);
this.currentOrder = info; this.currentOrder = info;
switch (info.eventType) { switch (info.eventType) {
case 'share': case 'share':
this.openShareEvent(); this.openShareEvent(info);
break; break;
default: default:
this.currentOrder = {}; this.currentOrder = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment