![]()
import ToastUtil from "@/utils/ToastUtil";
/**
* 场景。
* 可取值“WXSceneSession”分享到聊天界面,“WXSceneTimeline”分享到朋友圈,“WXSceneFavorite”分享到微信收藏
* WXSceneSession: 分享到聊天界面
* WXSceneTimeline: 分享到朋友圈
* WXSceneFavorite: 分享到微信收藏
*/
type IScene = 'WXSceneSession' | 'WXSceneTimeline' | 'WXSceneFavorite';
const ShareUtil = {
_share(options: UniNamespace.ShareOptions) {
uni.share({
...options,
provider: 'weixin'
}).then(res => {
ToastUtil.showToast({
title: "分享成功"
})
}).catch(err => {
console.log(err, 'err')
ToastUtil.showToast({
title: "分享失败",
icon: 'error'
})
})
},
/**
* 图文分享
* @param title 标题
* @param imageUrl 图片地址
* @param summary 摘要
* @param scene 场景
*/
shareImageAndText(title: string, imageUrl: string, summary?: string, scene: IScene = 'WXSceneSession') {
this._share({
type: 0,
title,
imageUrl,
summary,
scene
})
},
/**
* 纯文字分享
* @param title 标题
* @param summary 摘要
* @param scene 场景
*/
shareText(title: string, summary?: string, scene: IScene = 'WXSceneSession') {
this._share({
type: 1,
title,
summary,
scene
})
},
/**
* 纯图片分享
* @param imageUrl 图片地址
* @param title 标题
* @param summary 摘要
* @param scene 场景
*/
shareImage(imageUrl: string, title?: string, summary?: string, scene: IScene = 'WXSceneSession') {
this._share({
type: 2,
imageUrl,
title,
summary,
scene
})
},
/**
* 分享视频
* @param title 标题
* @param mediaUrl 视频地址
* @param summary 摘要
* @param scene 场景
*/
shareVideo(title: string, mediaUrl: string, summary?: string, scene: IScene = 'WXSceneSession') {
this._share({
type: 4,
mediaUrl,
title,
summary,
scene
})
}
}
export default ShareUtil
🎯 拓展阅读提示
本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧
→ 点击关注:一行梦境
文章评论