useBuildingShare.js 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. import { useRef, useEffect } from 'react'
  2. import useShare from '@/utils/hooks/useShare'
  3. import { ROLE_CODE } from '@/constants/user'
  4. export default function useBuildingShare(person, buildingInfo, router, paramsRef) {
  5. const shareRef = useRef()
  6. const trackRef = useRef()
  7. useEffect(() => {
  8. if (buildingInfo?.buildingId) {
  9. const shareContents = (buildingInfo.shareContents || [])[0] || {}
  10. shareRef.current = {
  11. title: shareContents.shareContentTitle || buildingInfo.buildingName,
  12. path: `${router.path}?${paramsRef.current}`,
  13. image: shareContents.shareContentImg,
  14. }
  15. }
  16. // 判断当前人员是否置业顾问
  17. const consultant = person.personType === ROLE_CODE.CONSULTANT ? { id: person.personId } : {}
  18. trackRef.current = {
  19. targetId: buildingInfo?.buildingId,
  20. consultantId: consultant.id,
  21. sharePersonId: person.personId,
  22. buildingId: buildingInfo?.buildingId,
  23. }
  24. // eslint-disable-next-line react-hooks/exhaustive-deps
  25. }, [buildingInfo, router.path])
  26. useShare(shareRef, trackRef)
  27. }