mall-app-t/peach/platform/share.js

54 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-05-22 15:42:13 +08:00
import $store from '@/peach/store'
// 设置分享信息参数
const getShareInfo = (
scene = {
title: '', // 自定义分享标题
desc: '', // 自定义描述
image: '', // 自定义分享图片
params: {}, // 自定义分享参数
},
poster = {
// 自定义海报数据
type: 'user',
}
) => {
let shareInfo = {
title: '', // 分享标题
desc: '', // 描述
image: '', // 分享图片
path: '', // 分享页面+参数
link: '', // 分享Url+参数
query: '', // 分享参数
poster, // 海报所需数据
}
const app = $store('app')
const shareConfig = app.platform.share
// 自动拼接分享用户参数
// const query = buildSpmQuery(scene.params)
// shareInfo.query = query
// 配置分享链接地址
// shareInfo.link = buildSpmLink(query, shareConfig.linkAddress)
// 配置转发参数
if (shareConfig.methods.includes('forward')) {
if (shareConfig.forwardInfo.title === '' || shareConfig.forwardInfo.image === '') {
console.log('请在平台设置中配置转发信息')
}
// 设置自定义分享信息
shareInfo.title = scene.title || shareConfig.forwardInfo.title
shareInfo.image = $url.cdn(scene.image || shareConfig.forwardInfo.image)
shareInfo.desc = scene.desc || shareConfig.forwardInfo.subtitle
shareInfo.path = buildSpmPath(query)
}
return shareInfo
}
export default {
getShareInfo,
}