Your Name 3 lat temu
rodzic
commit
276f59a089

+ 18
- 0
jsconfig.json Wyświetl plik

@@ -0,0 +1,18 @@
1
+// 本文件, 仅仅是为了支持 IDE 跳转, 与项目打包没有任何关系
2
+
3
+{
4
+  "compilerOptions": {
5
+    "experimentalDecorators": true,
6
+    "baseUrl": ".",
7
+    "paths": {      
8
+      "@/actions/*": ["./src/actions/*"],
9
+      "@/assets/*": ["./src/assets/*"],
10
+      "@/components/*": ["./src/components/*"],
11
+      "@/constants/*": ["./src/constants/*"],
12
+      "@/reducers/*": ["./src/reducers/*"],
13
+      "@/styles/*": ["./src/styles/*"],
14
+      "@/utils/*": ["./src/utils/*"],
15
+      "@/services/*": ["./src/services/*"],
16
+    }
17
+  }
18
+}

+ 0
- 12
src/layout/WrapperPerson.jsx Wyświetl plik

@@ -1,12 +0,0 @@
1
-import React from 'react'
2
-import { useSelector } from 'react-redux'
3
-import { useRouter } from '@tarojs/taro'
4
-
5
-export default (props) => {
6
-  const { person, ...extInfo } = useSelector(s => s.user.userInfo)
7
-  const router = useRouter()
8
-
9
-  return person && person.personId
10
-    ? React.cloneElement(props.children, { person, router, ...extInfo })
11
-    : null
12
-}

+ 28
- 7
src/layout/index.js Wyświetl plik

@@ -1,4 +1,5 @@
1 1
 import React, { useState, useEffect } from 'react'
2
+import Taro, { useDidShow, useRouter } from '@tarojs/taro'
2 3
 import { useSelector } from 'react-redux'
3 4
 import { View } from '@tarojs/components'
4 5
 import Overlay from '@/components/Overlay'
@@ -6,23 +7,35 @@ import Loading from '@/components/Loading'
6 7
 import AuthAvatar from '@/components/Auth/AuthAvatar'
7 8
 import AuthPhone from '@/components/Auth/AuthPhone'
8 9
 import Spin from '@/components/Spin/Spin2'
9
-import WrapperPerson from './WrapperPerson'
10 10
 import useAuth from './useAuth'
11
+import { routes } from '../routes'
11 12
 
12 13
 import './style.scss'
13 14
 
14 15
 export default (ChildComponent) => (props) => {
15
-  const { person } = useSelector(s => s.user.userInfo)
16
-  const { spinning } = useSelector(s => s.user)
17
-
16
+  const consultant = useSelector(s => s.system.consultant)
17
+  const { spinning, userInfo } = useSelector(s => s.user)
18
+  const { person, ...extInfo } = userInfo || {}
19
+  const router = useRouter()
18 20
   const [loading, setLoading] = useState(false)
19 21
   const [authPhone, authAvatar] = useAuth(person)
20 22
 
23
+  
24
+  // 主要用于埋点
25
+  useEffect(() => {
26
+    const page = routes.filter((r) => (router.path.indexOf(r.page) > -1))[0]
27
+    Taro.setStorage({ key: 'page', data: page })
28
+  }, [router.path])
29
+
21 30
   useEffect(() => {
22 31
     setLoading(!person || !person.personId)
23 32
   // eslint-disable-next-line react-hooks/exhaustive-deps
24 33
   }, [person])
25 34
 
35
+  useDidShow(() => {
36
+    console.log('componentDidShow')
37
+  })
38
+
26 39
   return (
27 40
     <>
28 41
       <Overlay visible={loading} style={{background: '#fff'}}>
@@ -39,9 +52,17 @@ export default (ChildComponent) => (props) => {
39 52
         </View>
40 53
       </Overlay>
41 54
       <Spin size={32} spinning={spinning} />
42
-      <WrapperPerson>
43
-        <ChildComponent />
44
-      </WrapperPerson>
55
+      {
56
+        person && person.personId
57
+        ? <ChildComponent
58
+            person={person}
59
+            router={router}
60
+            consultant={consultant}
61
+            {...props}
62
+            {...extInfo}
63
+        />
64
+        : null
65
+      }
45 66
     </>
46 67
   )
47 68
 }

+ 23
- 0
src/pages/index/buildingDetail/hooks/useBuildingPoster.js Wyświetl plik

@@ -0,0 +1,23 @@
1
+import { useEffect, useState } from 'react'
2
+import { getMiniQrcode } from '@/services/common'
3
+
4
+export default function useBuildingPoster(person, router, poster, paramsRef) {
5
+  const [posterData, setPosterData] = useState()
6
+
7
+  useEffect(() => {
8
+    const page = router.path
9
+    const scene = paramsRef.current
10
+
11
+    getMiniQrcode({ page, scene }).then((miniCode) => {
12
+      setPosterData({
13
+        poster,
14
+        miniCode,
15
+        name: person.name || person.nickname,
16
+        avatar: person.avatarurl,
17
+      })
18
+    })
19
+  // eslint-disable-next-line react-hooks/exhaustive-deps
20
+  }, [router.path, poster])
21
+
22
+  return posterData
23
+}

+ 32
- 0
src/pages/index/buildingDetail/hooks/useBuildingShare.js Wyświetl plik

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

+ 20
- 0
src/pages/index/buildingDetail/hooks/useParams.js Wyświetl plik

@@ -0,0 +1,20 @@
1
+import { useRef, useMemo } from 'react'
2
+import { ROLE_CODE } from '@/constants/user'
3
+
4
+export default function useParams(person, buildingInfo) {  
5
+
6
+  // 判断当前人员是否置业顾问
7
+  const consultant = person.personType === ROLE_CODE.CONSULTANT ? { id: person.personId } : {}
8
+
9
+  const paramsRef = useRef()
10
+  paramsRef.current = useMemo(() => {
11
+    return [
12
+      `id=${buildingInfo?.buildingId}`,
13
+      `from=building_share`,
14
+      `recommender=${person.personId}`,
15
+      consultant.id ? `consultant=${consultant.id}` : undefined,
16
+    ].filter(Boolean).join('&')
17
+  }, [buildingInfo?.buildingId, person.personId, consultant.id])
18
+
19
+  return paramsRef
20
+}

+ 14
- 36
src/pages/index/buildingDetail/index.jsx Wyświetl plik

@@ -1,10 +1,10 @@
1
-import { useState, useEffect, useMemo } from 'react'
2
-import Taro, { useShareAppMessage } from '@tarojs/taro'
1
+import { useState, useEffect, useMemo, useRef } from 'react'
3 2
 import withLayout from '@/layout'
4 3
 import { ScrollView } from '@tarojs/components'
5 4
 import Disclaimer from '@/components/Disclaimer'
6 5
 import { fetch } from '@/utils/request'
7 6
 import { API_ITEMS_DETAIL, API_NEWS_LIST } from '@/constants/api'
7
+import useConsultant from '@/utils/hooks/useConsultant'
8 8
 import DetailBottom from './components/DetailBottom/index'
9 9
 import BuildingDetailBanner from './components/BuildingDetailBanner/index'
10 10
 import BasicInfo from './components/BasicInfo/index'
@@ -17,6 +17,9 @@ import MarketingActivity from './components/MarketingActivity/index'
17 17
 import LivingActivity from './components/LivingActivity/index'
18 18
 import News from './components/News/index'
19 19
 import Pictures from './components/Pictures/index'
20
+import useParams from './hooks/useParams'
21
+import useBuildingShare from './hooks/useBuildingShare'
22
+import useBuildingPoster from './hooks/useBuildingPoster'
20 23
 
21 24
 import './index.scss'
22 25
 
@@ -28,27 +31,14 @@ export default withLayout((props) => {
28 31
   const [PictureList, setPictureList] = useState([])
29 32
   const [NewsList, setNewsList] = useState([])
30 33
 
31
-  const [IsPull, setPull] = useState(false)
32
-  const [PullTimer, setPullTimer] = useState(null)
34
+  // 本页面分享或者海报参数
35
+  const paramsRef = useParams(person, DetailInfo)
33 36
 
34
-  const posterData = useMemo(() => {
35
-    if (!DetailInfo?.poster) {
36
-      return undefined
37
-    }
37
+  // 分享
38
+  useBuildingShare(person, DetailInfo, router, paramsRef)
38 39
 
39
-    return {
40
-      name: person.name || person.nickname,
41
-      avatar: person.avatarurl,
42
-      poster: DetailInfo?.poster,
43
-      miniCode: DetailInfo?.poster,
44
-    }
45
-
46
-  }, [DetailInfo?.poster, person.avatarurl, person.name, person.nickname])
47
-
48
-  
49
-  useShareAppMessage((res) => {
50
-    return {}
51
-  })
40
+  // 海报
41
+  const posterData = useBuildingPoster(person, router, DetailInfo?.poster, paramsRef)
52 42
 
53 43
   useEffect(() => {
54 44
     // 获取楼盘信息
@@ -59,6 +49,7 @@ export default withLayout((props) => {
59 49
         const List = res.buildingApartment.filter(item => item.apartmentType === 'photo')
60 50
         setPictureList(List.filter(item => item.buildingImgList.length > 0))
61 51
       }
52
+
62 53
     }).catch((err) => {
63 54
       console.error(err)
64 55
     })
@@ -67,26 +58,13 @@ export default withLayout((props) => {
67 58
     fetch({ url: API_NEWS_LIST, payload: { buildingId: id, pageSize: 2, pageNum: 1 } }).then((res) => {
68 59
       setNewsList(res.records || [])
69 60
     })
70
-  }, [id])
71
-
72
-  const PageRefresh = () => { // 页面下拉刷新回调
73
-    setPull(true)
74
-  }
75
-
76
-  useEffect(() => { // 下拉刷新触发
77
-    if (IsPull) {
78
-      clearTimeout(PullTimer)
79
-      setPullTimer(setTimeout(() => {
80
-        setPull(false)
81
-      }, 2000))
82
-    }
83
-  }, [IsPull])
61
+  }, [id, router.path])
84 62
 
85 63
   return (
86 64
     <view className='Page buildingDetail flex-v'>
87 65
       <view className='flex-item'>
88 66
         <view>
89
-          <ScrollView scroll-y refresher-enabled={false} refresher-triggered={IsPull} onrefresherrefresh={PageRefresh} refresher-background='#f8f8f8'>
67
+          <ScrollView scroll-y>
90 68
             <view className='PageContent'>
91 69
 
92 70
               {/* banner */}

+ 6
- 0
src/utils/hooks/useConsultant.js Wyświetl plik

@@ -0,0 +1,6 @@
1
+import { useSelector } from 'react-redux'
2
+
3
+export default function useConsultant() {
4
+  const consultant = useSelector(s => s.system.consultant)
5
+  return consultant
6
+}

+ 18
- 17
src/utils/hooks/useShare.js Wyświetl plik

@@ -1,32 +1,33 @@
1 1
 import React, { useState } from 'react'
2 2
 import Taro, { useShareAppMessage } from '@tarojs/taro'
3
+import { shareTracking } from '@/utils/tracking'
3 4
 
4
-export default function useShare(shareRef) {
5
+export default function useShare(shareRef, trackRef) {
5 6
   useShareAppMessage((res) => {
6 7
     const {
7 8
       title = '',
8 9
       path = '',
9
-      imageUrl = '',
10
-      eventType = '',
11
-      propertyName = '',
10
+      image = '',
11
+    } = shareRef.current || {}
12
+
13
+    const {
14
+      // event = 'share',
15
+      // eventType = '',
16
+      // propertyName = '',
12 17
       consultantId = '',
13 18
       sharePersonId = '',
14 19
       targetId = '',
15 20
       buildingId = '',
16
-    } = shareRef.current || {}
21
+    } = trackRef.current || {}
17 22
 
18
-        // // 分享埋点
19
-        // shareSavePoint({
20
-        //   event: 'share',
21
-        //   eventType: 'building',
22
-        //   propertyName: '项目详情分享',
23
-        //   consultantId: consultantId,
24
-        //   sharePersonId: personId,
25
-        //   targetId: buildingId,
26
-        //   buildingId: buildingId || '',
27
-        //   data: '{}'
28
-        // }, 'project')
23
+    // 分享埋点
24
+    shareTracking({
25
+      consultantId,
26
+      sharePersonId,
27
+      targetId,
28
+      buildingId,
29
+    })
29 30
     
30
-    return shareObject
31
+    return { title, path, imageUrl: image }
31 32
   })
32 33
 }

+ 56
- 0
src/utils/tracking/addNum.js Wyświetl plik

@@ -0,0 +1,56 @@
1
+import { savePoint } from '@/services/common'
2
+import { addItemShareNum } from '@/services/item'
3
+import { addActivityShareNum, addHelpShareNum, addGroupShareNum, addHFiveShareNum } from '@/services/activity'
4
+import { addCardShareNum } from '@/services/card'
5
+import {
6
+    addIndexShareNum,
7
+    addNewsShareNum,
8
+    addHousePosterNum,
9
+    addHouseShareNum,
10
+    addLivePosterNum,
11
+    addLiveShareNum,
12
+} from '@/services/news'
13
+
14
+
15
+export default function addNum({ targetId, eventType }) {
16
+  switch (eventType) {
17
+    case 'main':
18
+        addIndexShareNum(targetId)
19
+        break;
20
+    case 'building':
21
+        addItemShareNum(targetId)
22
+        break;
23
+    case 'activity':
24
+        addActivityShareNum(targetId)
25
+        break;
26
+    case 'consultant':
27
+        addCardShareNum(targetId)
28
+        break;
29
+    case 'news':
30
+        addNewsShareNum(targetId)
31
+        break;
32
+    // case 'houseApp':
33
+    //     addHouseShareNum(targetId)
34
+    //     break;
35
+    // case 'housePoster':
36
+    //     addHousePosterNum(targetId)
37
+    //     break;
38
+    // case 'liveApp':
39
+    //     addLiveShareNum(targetId)
40
+    //     break;
41
+    // case 'livePoster':
42
+    //     addLivePosterNum(targetId)
43
+    //     break;
44
+    // case 'help':
45
+    //     addHelpShareNum(targetId)
46
+    //     break;
47
+    // case 'group':
48
+    //     addGroupShareNum(targetId)
49
+    //     break;
50
+    // case 'h5':
51
+    //     addHFiveShareNum(targetId)
52
+    //     break;
53
+    default:
54
+        return
55
+  }
56
+}

+ 31
- 0
src/utils/tracking/index.js Wyświetl plik

@@ -0,0 +1,31 @@
1
+import Taro from '@tarojs/taro'
2
+import { savePoint } from '@/services/common'
3
+import addNum from './addNum'
4
+
5
+export function shareTracking(options) {
6
+  const page = Taro.getStorageSync('page')
7
+  if (!page) return;
8
+
9
+  const { name: propertyName, type: eventType } = page
10
+  const {
11
+    event = 'share',
12
+    // eventType = '',
13
+    // propertyName = '',
14
+    consultantId = '',
15
+    sharePersonId = '',
16
+    targetId = '',
17
+    buildingId = '',
18
+  } = options
19
+
20
+  addNum({ eventType, targetId })
21
+  savePoint({
22
+    event,
23
+    eventType,
24
+    propertyName,
25
+    consultantId,
26
+    sharePersonId,
27
+    targetId,
28
+    buildingId,
29
+    data: '{}',
30
+  })
31
+}