50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
|
import util from '@/common/js/util';
|
||
|
|
||
|
// 微信分享
|
||
|
const shareToWeixin = (title, imageUrl, content) => {
|
||
|
uni.share({
|
||
|
provider: 'weixin',
|
||
|
scene: 'WXSceneSession',
|
||
|
shareData: shareData,
|
||
|
success: function (res) {
|
||
|
// 成功提示
|
||
|
util.showToastAndRedirect('分享成功', 'success');
|
||
|
|
||
|
},
|
||
|
fail: function (err) {
|
||
|
util.showToastAndRedirect('分享失败', 'error');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// QQ分享
|
||
|
const shareToQQ = (title, imageUrl, filePath) => {
|
||
|
uni.share({
|
||
|
provider: 'qq',
|
||
|
scene: 'QZoneScene',
|
||
|
title: title,
|
||
|
imageUrl: imageUrl,
|
||
|
filePath: filePath,
|
||
|
success: function (res) {
|
||
|
// 成功提示
|
||
|
util.showToastAndRedirect('分享成功', 'success');
|
||
|
|
||
|
},
|
||
|
fail: function (err) {
|
||
|
util.showToastAndRedirect('分享失败', 'error');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
export const shareToPlatform = (platform, title, imageUrl, content, filePath) => {
|
||
|
switch (platform) {
|
||
|
case 'weixin':
|
||
|
shareToWeixin(title, imageUrl, content);
|
||
|
break;
|
||
|
case 'qq':
|
||
|
shareToQQ(title, imageUrl, filePath);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|