community.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import wechath5 from '@/utils/wechath5'
  2. import {
  3. isWeixinClient
  4. } from '@/utils/tools'
  5. import {
  6. baseURL,
  7. basePath
  8. } from '@/config/app'
  9. const state = {
  10. communityItem: {}
  11. };
  12. const mutations = {
  13. setCommunity(state, data) {
  14. state.communityItem = data
  15. }
  16. };
  17. const actions = {
  18. // 分享种草文章
  19. communityShare({
  20. state,
  21. commit
  22. }) {
  23. const item = state.communityItem;
  24. console.log(item)
  25. // #ifdef H5
  26. if (isWeixinClient()) {
  27. const option = {
  28. shareTitle: `${item.user.nickname},TA的内容超级棒`,
  29. shareLink: `${baseURL}${basePath}/${item.url}?id=${item.id}`,
  30. shareImage: item.image,
  31. shareDesc: item.content
  32. }
  33. wechath5.share(option)
  34. }
  35. // #endif
  36. // #ifdef APP-PLUS
  37. uni.share({
  38. provider: "weixin",
  39. scene: "WXSceneSession",
  40. type: 0,
  41. href: `${baseURL}${basePath}/${item.url}?id=${item.id}`,
  42. title: `${item.user.nickname},TA的内容超级棒`,
  43. summary: item.content,
  44. imageUrl: item.image,
  45. success: (res) => {
  46. console.log('分享成功');
  47. },
  48. fail: (err) => {
  49. console.log(err)
  50. uni.showToast({
  51. icon: 'none',
  52. title: err.errMsg
  53. })
  54. }
  55. });
  56. // #endif
  57. }
  58. };
  59. export default {
  60. state,
  61. mutations,
  62. actions
  63. };