Authored by 肖亚东

分享功能开发 — review by 李其昌

import event from '../../utils/event.js'
const CANCEL_SHARE = 'user-canel-share';
const SHARE_FRIENDS = 'user-share-friends';
const SHARE_MOMENTS = 'user-share-moments';
const SHARE_CANCEL = 'user-canel-share';
Component({
/**
... ... @@ -25,32 +27,17 @@ Component({
*/
methods: {
onShare: function(event) {
let index = event.currentTarget.dataset.index;
if (index == 1) {//微信好友
} else if (index == 2) {//朋友圈
onShare: function(e) {
let type = e.currentTarget.dataset.type;
if (type == 'friends') {//微信好友或群
event.emit(SHARE_FRIENDS);
} else if (type == 'moments') {//朋友圈
event.emit(SHARE_MOMENTS);
}
console.log('====================================');
console.log(index);
console.log('====================================');
},
onCancel: function() {
console.log('====================================');
console.log(22);
console.log('====================================');
event.on(CANCEL_SHARE, () => {
});
let prePage = getCurrentPages();
console.log(prePage);
if (prePage.length > 0 && prePage[prePage.length - 1].onCancel != undefined) {
prePage[prePage.length - 1].onCancel();
}
event.emit(SHARE_CANCEL);
}
}
})
... ...
... ... @@ -2,14 +2,15 @@
<view class='cover-view' bindtap='onCancel'></view>
<view class='main-view'>
<view class='share-view'>
<view class='item' bindtap='onShare' data-index="1">
<button class='item left' bindtap='onShare' open-type="share" hover-class="none" plain='true' data-type="friends">
<image class='icon' src='../../assets/images/wechat_friend@3x.png'></image>
<text class='title'>微信好友</text>
</view>
<view class='item' bindtap='onShare' data-index="2">
</button>
<button class='item right' bindtap='onShare' hover-class="none" plain='true' data-type="moments">
<image class='icon' src='../../assets/images/wechat@3x.png'></image>
<text class='title'>朋友圈</text>
</view>
</button>
</view>
<view class='line'></view>
<view class='cancel' bindtap='onCancel'>取消</view>
... ...
... ... @@ -26,8 +26,6 @@
.main-view .share-view {
height: 262rpx;
display: flex;
justify-content: space-evenly;
align-items: center;
}
.main-view .line {
height: 2rpx;
... ... @@ -46,17 +44,31 @@
justify-content: center;
}
.left {
margin-left: 183rpx;
}
.right {
margin-right: 183rpx;
}
.main-view .share-view .item {
width: 100rpx;
height: 100%;
border-radius: 0;
border-style: none;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-view .share-view .item .icon {
width: 90rpx;
height: 90rpx;
margin-top: 62rpx;
margin-top: 20rpx;
}
.main-view .share-view .item .title {
margin-top: 16rpx;
width: 150rpx;
font-family: PingFang-SC-Regular;
font-size: 24rpx;
color: #000000;
... ...
... ... @@ -13,6 +13,9 @@ import collectOff from '../../static/images/collect-off.png';
import './index.scss';
import event from '../../utils/event'
const SHARE_FRIENDS = 'user-share-friends';
const SHARE_MOMENTS = 'user-share-moments';
const SHARE_CANCEL = 'user-canel-share';
@connect(({ productDetail }) => ({
productDetail
}), (dispatch) => ({
... ... @@ -75,6 +78,13 @@ export default class ProductDetail extends Component {
this.getProductData(id);
this.getRecommendGoods(id);
this.getFavoriteState(id);
event.on(SHARE_CANCEL, () => {
this.onCancelCallback();
});
event.on(SHARE_MOMENTS, () => {
this.shareMomentsCallback();
});
}
getProductData(id) {
... ... @@ -174,16 +184,51 @@ export default class ProductDetail extends Component {
}
}
onShareAppMessage(res) {
console.log(res);
if (res.from === 'menu') {
// 用户点击右上角分享
return {
title: '', // 分享标题
desc: '', // 分享描述
path: '',
imageUrl: '',
success: function() {},
fail: function() {}
};
} else if (res.from === 'button') {
// 用户点击分享按钮
return {
title: '', // 分享标题
desc: '', // 分享描述
path: '',
imageUrl: '',
success: function() {},
fail: function() {}
};
}
}
//点击分享按钮
onClickShare(id, e) {
let {showSharesheet} = this.props;
showSharesheet(true);
}
onCancel() {
//点击组件的取消回调处理
onCancelCallback() {
let {showSharesheet} = this.props;
showSharesheet(false);
}
//点击组件的分享朋友圈回调处理
shareMomentsCallback() {
console.log('====================================');
console.log('分享到朋友圈');
console.log('====================================');
}
onClickBuy() {
let {showSizeBox} = this.props;
... ...