shop_uniapp/store/modules/community.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-06-06 09:55:01 +08:00
import wechath5 from '@/utils/wechath5'
import {
isWeixinClient
} from '@/utils/tools'
import {
baseURL,
basePath
} from '@/config/app'
const state = {
communityItem: {}
};
const mutations = {
setCommunity(state, data) {
state.communityItem = data
}
};
const actions = {
communityShare({
state,
commit
}) {
const item = state.communityItem;
console.log(item)
// #ifdef H5
if (isWeixinClient()) {
const option = {
shareTitle: `${item.user.nickname},TA的内容超级棒`,
shareLink: `${baseURL}${basePath}/${item.url}?id=${item.id}`,
shareImage: item.image,
shareDesc: item.content
}
wechath5.share(option)
}
// #endif
// #ifdef APP-PLUS
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 0,
href: `${baseURL}${basePath}/${item.url}?id=${item.id}`,
title: `${item.user.nickname},TA的内容超级棒`,
summary: item.content,
imageUrl: item.image,
success: (res) => {
console.log('分享成功');
},
fail: (err) => {
console.log(err)
uni.showToast({
icon: 'none',
title: err.errMsg
})
}
});
// #endif
}
};
export default {
state,
mutations,
actions
};