【代码优化】分享优化
parent
a2ba10f796
commit
5cc6d99891
|
|
@ -209,6 +209,7 @@
|
||||||
import { isEmpty } from 'lodash-es';
|
import { isEmpty } from 'lodash-es';
|
||||||
import CombinationApi from '@/sheep/api/promotion/combination';
|
import CombinationApi from '@/sheep/api/promotion/combination';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import { SharePageEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');
|
const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');
|
||||||
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
|
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
|
||||||
|
|
@ -234,7 +235,7 @@
|
||||||
image: sheep.$url.cdn(state.data.headRecord.picUrl),
|
image: sheep.$url.cdn(state.data.headRecord.picUrl),
|
||||||
desc: state.data.goods?.subtitle,
|
desc: state.data.goods?.subtitle,
|
||||||
params: {
|
params: {
|
||||||
page: '5',
|
page: SharePageEnum.GROUPON_DETAIL.value,
|
||||||
query: state.data.headRecord.id,
|
query: state.data.headRecord.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,12 @@
|
||||||
import commissionMenu from './components/commission-menu.vue';
|
import commissionMenu from './components/commission-menu.vue';
|
||||||
import commissionAuth from './components/commission-auth.vue';
|
import commissionAuth from './components/commission-auth.vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
|
import { SharePageEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
const shareInfo = computed(() => {
|
const shareInfo = computed(() => {
|
||||||
return sheep.$platform.share.getShareInfo({
|
return sheep.$platform.share.getShareInfo({
|
||||||
params: {
|
params: {
|
||||||
page: '6',
|
page: SharePageEnum.POINT.value,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
type: 'user',
|
type: 'user',
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,7 @@
|
||||||
import { useDurationTime, formatGoodsSwiper, fen2yuan } from '@/sheep/hooks/useGoods';
|
import { useDurationTime, formatGoodsSwiper, fen2yuan } from '@/sheep/hooks/useGoods';
|
||||||
import CombinationApi from '@/sheep/api/promotion/combination';
|
import CombinationApi from '@/sheep/api/promotion/combination';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import { SharePageEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-bg.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-bg.png');
|
||||||
const btnBg = sheep.$url.css('/static/img/shop/goods/groupon-btn.png');
|
const btnBg = sheep.$url.css('/static/img/shop/goods/groupon-btn.png');
|
||||||
|
|
@ -239,7 +240,7 @@
|
||||||
title: state.activity.name,
|
title: state.activity.name,
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
params: {
|
params: {
|
||||||
page: '3',
|
page: SharePageEnum.GROUPON.value,
|
||||||
query: state.activity.id,
|
query: state.activity.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@
|
||||||
import countDown from '@/sheep/components/countDown/index.vue';
|
import countDown from '@/sheep/components/countDown/index.vue';
|
||||||
import OrderApi from '@/sheep/api/trade/order';
|
import OrderApi from '@/sheep/api/trade/order';
|
||||||
import activity from '@/sheep/api/promotion/activity';
|
import activity from '@/sheep/api/promotion/activity';
|
||||||
|
import { SharePageEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
const bgColor = {
|
const bgColor = {
|
||||||
bgColor: '#E93323',
|
bgColor: '#E93323',
|
||||||
|
|
@ -318,7 +319,7 @@
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
desc: state.goodsInfo.introduction,
|
desc: state.goodsInfo.introduction,
|
||||||
params: {
|
params: {
|
||||||
page: '2',
|
page: SharePageEnum.GOODS.value,
|
||||||
query: state.goodsInfo.id,
|
query: state.goodsInfo.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@
|
||||||
import detailCommentCard from './components/detail/detail-comment-card.vue';
|
import detailCommentCard from './components/detail/detail-comment-card.vue';
|
||||||
import detailContentCard from './components/detail/detail-content-card.vue';
|
import detailContentCard from './components/detail/detail-content-card.vue';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
import { PromotionActivityTypeEnum } from '@/sheep/util/const';
|
import { PromotionActivityTypeEnum, SharePageEnum } from '@/sheep/util/const';
|
||||||
import PointApi from '@/sheep/api/promotion/point';
|
import PointApi from '@/sheep/api/promotion/point';
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/score-bg.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/score-bg.png');
|
||||||
|
|
@ -180,8 +180,7 @@
|
||||||
title: activity.value.name,
|
title: activity.value.name,
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
params: {
|
params: {
|
||||||
// TODO @puhui:page 相关,要不搞个枚举,然后都弄过去;
|
page: SharePageEnum.POINT.value,
|
||||||
page: '6',
|
|
||||||
query: activity.value.id,
|
query: activity.value.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@
|
||||||
import detailProgress from './components/detail/detail-progress.vue';
|
import detailProgress from './components/detail/detail-progress.vue';
|
||||||
import SeckillApi from '@/sheep/api/promotion/seckill';
|
import SeckillApi from '@/sheep/api/promotion/seckill';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
import { getTimeStatusEnum, TimeStatusEnum } from '@/sheep/util/const';
|
import { getTimeStatusEnum, SharePageEnum, TimeStatusEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/seckill-bg.png');
|
||||||
const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
|
const btnBg = sheep.$url.css('/static/img/shop/goods/seckill-btn.png');
|
||||||
|
|
@ -206,7 +206,7 @@
|
||||||
title: activity.value.name,
|
title: activity.value.name,
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
params: {
|
params: {
|
||||||
page: '4',
|
page: SharePageEnum.SECKILL.value,
|
||||||
query: activity.value.id,
|
query: activity.value.id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { isEmpty } from 'lodash-es';
|
import { isEmpty } from 'lodash-es';
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
import { onShareAppMessage, onShareTimeline, onShow } from '@dcloudio/uni-app';
|
import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
@ -197,17 +197,17 @@
|
||||||
// 微信小程序分享好友
|
// 微信小程序分享好友
|
||||||
onShareAppMessage(() => {
|
onShareAppMessage(() => {
|
||||||
return {
|
return {
|
||||||
title: shareInfo.value.forward.title,
|
title: shareInfo.value.title,
|
||||||
path: shareInfo.value.forward.path,
|
path: shareInfo.value.forward.path,
|
||||||
imageUrl: shareInfo.value.forward.image,
|
imageUrl: shareInfo.value.image,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
// 微信小程序分享朋友圈
|
// 微信小程序分享朋友圈
|
||||||
onShareTimeline(() => {
|
onShareTimeline(() => {
|
||||||
return {
|
return {
|
||||||
title: shareInfo.value.forward.title,
|
title: shareInfo.value.title,
|
||||||
query: shareInfo.value.forward.path,
|
query: shareInfo.value.forward.path,
|
||||||
imageUrl: shareInfo.value.forward.image,
|
imageUrl: shareInfo.value.image,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ import $platform from '@/sheep/platform';
|
||||||
import $router from '@/sheep/router';
|
import $router from '@/sheep/router';
|
||||||
import $url from '@/sheep/url';
|
import $url from '@/sheep/url';
|
||||||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||||
|
import { SharePageEnum } from '@/sheep/util/const';
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
|
import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
|
||||||
// #endif
|
// #endif
|
||||||
|
|
@ -37,6 +39,9 @@ const getShareInfo = (
|
||||||
poster, // 海报所需数据
|
poster, // 海报所需数据
|
||||||
forward: {} // 转发所需参数
|
forward: {} // 转发所需参数
|
||||||
};
|
};
|
||||||
|
shareInfo.title = scene.title;
|
||||||
|
shareInfo.image = $url.cdn(scene.image);
|
||||||
|
shareInfo.desc = scene.desc;
|
||||||
|
|
||||||
const app = $store('app');
|
const app = $store('app');
|
||||||
const shareConfig = app.platform.share;
|
const shareConfig = app.platform.share;
|
||||||
|
|
@ -50,15 +55,8 @@ const getShareInfo = (
|
||||||
// 配置页面地址带参数
|
// 配置页面地址带参数
|
||||||
shareInfo.path = buildSpmPath();
|
shareInfo.path = buildSpmPath();
|
||||||
|
|
||||||
// 配置转发参数
|
// 配置页面转发参数
|
||||||
if (shareConfig.methods.includes('forward')) {
|
if (shareConfig.methods.includes('forward')) {
|
||||||
if (shareConfig.forwardInfo.title === '' || shareConfig.forwardInfo.image === '') {
|
|
||||||
console.log('请在平台设置中配置默认转发信息');
|
|
||||||
}
|
|
||||||
// 设置自定义分享信息
|
|
||||||
shareInfo.forward.title = scene.title || shareConfig.forwardInfo.title;
|
|
||||||
shareInfo.forward.image = $url.cdn(scene.image || shareConfig.forwardInfo.image);
|
|
||||||
shareInfo.forward.desc = scene.desc || shareConfig.forwardInfo.subtitle;
|
|
||||||
shareInfo.forward.path = buildSpmPath(query);
|
shareInfo.forward.path = buildSpmPath(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +77,7 @@ const buildSpmQuery = (params) => {
|
||||||
shareId = user.userInfo.id;
|
shareId = user.userInfo.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let page = '1'; // 页面类型: 1=首页(默认),2=商品,3=拼团商品,4=秒杀商品,5=邀请参团,6=分销邀请...按需扩展
|
let page = SharePageEnum.HOME.value; // 页面类型,默认首页
|
||||||
if (typeof params.page !== 'undefined') {
|
if (typeof params.page !== 'undefined') {
|
||||||
page = params.page;
|
page = params.page;
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +98,7 @@ const buildSpmQuery = (params) => {
|
||||||
const buildSpmPath = (query) => {
|
const buildSpmPath = (query) => {
|
||||||
// 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,
|
// 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,
|
||||||
// 不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
|
// 不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
|
||||||
|
// 页面分享时参数使用 ? 拼接
|
||||||
return typeof query === 'undefined' ? `pages/index/index` : `pages/index/index?${query}`;
|
return typeof query === 'undefined' ? `pages/index/index` : `pages/index/index?${query}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -123,44 +122,44 @@ const decryptSpm = (spm) => {
|
||||||
let query;
|
let query;
|
||||||
shareParams.shareId = shareParamsArray[0];
|
shareParams.shareId = shareParamsArray[0];
|
||||||
switch (shareParamsArray[1]) {
|
switch (shareParamsArray[1]) {
|
||||||
case '1':
|
case SharePageEnum.HOME.value:
|
||||||
// 默认首页不跳转
|
// 默认首页不跳转
|
||||||
shareParams.page = '/pages/index/index';
|
shareParams.page = SharePageEnum.HOME.page;
|
||||||
break;
|
break;
|
||||||
case '2':
|
case SharePageEnum.GOODS.value:
|
||||||
// 普通商品
|
// 普通商品
|
||||||
shareParams.page = '/pages/goods/index';
|
shareParams.page = SharePageEnum.GOODS.page;
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: shareParamsArray[2],
|
id: shareParamsArray[2],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case '3':
|
case SharePageEnum.GROUPON.value:
|
||||||
// 拼团商品
|
// 拼团商品
|
||||||
shareParams.page = '/pages/goods/groupon';
|
shareParams.page = SharePageEnum.GROUPON.page;
|
||||||
query = shareParamsArray[2].split(',');
|
query = shareParamsArray[2].split(',');
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: query[0],
|
id: query[0],
|
||||||
activity_id: query[1],
|
activity_id: query[1],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case '4':
|
case SharePageEnum.SECKILL.value:
|
||||||
// 秒杀商品
|
// 秒杀商品
|
||||||
shareParams.page = '/pages/goods/seckill';
|
shareParams.page = SharePageEnum.SECKILL.page;
|
||||||
query = shareParamsArray[2].split(',');
|
query = shareParamsArray[2].split(',');
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: query[0],
|
id: query[0],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case '5':
|
case SharePageEnum.GROUPON_DETAIL.value:
|
||||||
// 参与拼团
|
// 参与拼团
|
||||||
shareParams.page = '/pages/activity/groupon/detail';
|
shareParams.page = SharePageEnum.GROUPON_DETAIL.page;
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: shareParamsArray[2],
|
id: shareParamsArray[2],
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case '6':
|
case SharePageEnum.POINT.value:
|
||||||
// 积分商品
|
// 积分商品
|
||||||
shareParams.page = '/pages/goods/point';
|
shareParams.page = SharePageEnum.POINT.page;
|
||||||
shareParams.query = {
|
shareParams.query = {
|
||||||
id: shareParamsArray[2],
|
id: shareParamsArray[2],
|
||||||
};
|
};
|
||||||
|
|
@ -177,7 +176,7 @@ const decryptSpm = (spm) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shareParams.page !== '/pages/index/index') {
|
if (shareParams.page !== SharePageEnum.HOME.page) {
|
||||||
$router.go(shareParams.page, shareParams.query);
|
$router.go(shareParams.page, shareParams.query);
|
||||||
}
|
}
|
||||||
return shareParams;
|
return shareParams;
|
||||||
|
|
|
||||||
|
|
@ -134,3 +134,39 @@ export const getTimeStatusEnum = (startTime, endTime) => {
|
||||||
return TimeStatusEnum.STARTED;
|
return TimeStatusEnum.STARTED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* 分享页枚举
|
||||||
|
* 按需扩展
|
||||||
|
* */
|
||||||
|
export const SharePageEnum = {
|
||||||
|
HOME: {
|
||||||
|
name: '首页',
|
||||||
|
page: '/pages/index/index',
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
GOODS: {
|
||||||
|
name: '普通商品页',
|
||||||
|
page: '/pages/goods/index',
|
||||||
|
value: '2'
|
||||||
|
},
|
||||||
|
GROUPON: {
|
||||||
|
name: '拼团商品页',
|
||||||
|
page: '/pages/goods/groupon',
|
||||||
|
value: '3'
|
||||||
|
},
|
||||||
|
SECKILL: {
|
||||||
|
name: '秒杀商品页',
|
||||||
|
page: '/pages/goods/seckill',
|
||||||
|
value: '4'
|
||||||
|
},
|
||||||
|
GROUPON_DETAIL: {
|
||||||
|
name: '参与拼团页',
|
||||||
|
page: '/pages/activity/groupon/detail',
|
||||||
|
value: '5'
|
||||||
|
},
|
||||||
|
POINT: {
|
||||||
|
name: '积分商品页',
|
||||||
|
page: '/pages/goods/point',
|
||||||
|
value: '6'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue