share.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { shareCircle, shareDesignerHome } from '@/core/libs/requests'
  2. import { messages } from '@/core/libs/messages'
  3. export const useShare = () => {
  4. const shareAppMessage = async ({ from, target }) => {
  5. console.log('target::::::::', from, target)
  6. const res: Page.CustomShareContent = {}
  7. if (from === 'button') {
  8. if (target.dataset.type === 'homepage') {
  9. if (target.dataset.level && target.dataset.level < 2) {
  10. uni.showToast({ title: '普通会员无法分享', icon: 'none' })
  11. throw new Error('禁止分享')
  12. }
  13. await shareDesignerHome({
  14. stylistId: target.dataset.options.homepageId,
  15. bizId: target.dataset.options.userId,
  16. })
  17. res.title = target.dataset.shareContent.title
  18. res.imageUrl = target.dataset.shareContent.imageUrl
  19. res.path = target.dataset.shareContent.path
  20. } else {
  21. if (['1', '2'].includes(target.dataset.options.circleType)) {
  22. if (!target.dataset.options.levelId || target.dataset.options.levelId < 2) {
  23. uni.showToast({ title: '无法分享普通会员等级作者的圈子内容', icon: 'none' }).then()
  24. throw new Error('禁止分享')
  25. }
  26. await shareCircle(target.dataset.options.id)
  27. }
  28. res.path = `/pages-sub/home/moment/index?id=${target.dataset.options.id}&isShared=true&circleType=${target.dataset.options.circleType}`
  29. res.imageUrl = target.dataset.options.bannerUrls[0]
  30. res.title = `${target.dataset.options.stylistName}: ${target.dataset.options.circleType == '2' ? '设计案例-' + target.dataset.options.caseName : target.dataset.options.circleDesc}`
  31. }
  32. }
  33. if (from === 'menu') {
  34. console.log('menu::::::::', from, target)
  35. res.title = messages.home.shareTitle
  36. }
  37. return res
  38. }
  39. return { shareAppMessage }
  40. }