123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import React, { useState, useEffect } from 'react'
- import Taro, { useDidShow, useRouter } from '@tarojs/taro'
- import { useSelector } from 'react-redux'
- import { View } from '@tarojs/components'
- import Overlay from '@/components/Overlay'
- import Loading from '@/components/Loading'
- import AuthAvatar from '@/components/Auth/AuthAvatar'
- import AuthPhone from '@/components/Auth/AuthPhone'
- import Spin from '@/components/Spin/Spin2'
- import FixedConsultant from '@/components/FixedConsultant'
- import FirstScreen from '@/components/FirstScreen'
- import { report as reportCustomer } from '@/utils/customer'
- import nav2Target from '@/utils/nav2Target'
- import { ROLE_CODE } from '@/constants/user'
- import useAuth from './useAuth'
- import useScreen from './useScreen'
- import { routes } from '../routes'
-
- import './style.scss'
-
- export default (ChildComponent) => (props) => {
- const consultant = useSelector(s => s.system.consultant)
- const city = useSelector(s => s.city.curCity)
- const { spinning, userInfo } = useSelector(s => s.user)
- const { person, ...extInfo } = userInfo || {}
- const router = useRouter()
- const page = routes.filter((r) => (router.path.indexOf(r.page) > -1))[0]
- const [loading, setLoading] = useState(false)
- const [authPhone, authAvatar] = useAuth(person, page)
-
- const { id } = router.params
- const showConsultant = page.shortcut && page.shortcut.consultant
-
- // 页面分享
- const [shareContent, setShareContent] = useState({})
- // 页面埋点
- const [trackData, setTrackData] = useState({})
- // 开屏广告
- const [screenInfo, screenVisible, toggleShowScreen] = useScreen(city.id, person)
-
- const handleScreen = () => {
- toggleShowScreen()
- nav2Target(screenInfo)
- }
-
- // 报备客户
- useEffect(() => {
- reportCustomer(person, consultant, false).catch(() => {})
- }, [person, consultant])
-
- // 请求埋点设置
- useEffect(() => {
- if (id) {
- setShareContent({})
- }
- } ,[id, page.type])
-
- // 埋点数据
- useEffect(() => {
- const consultantId = person?.personType === ROLE_CODE.CONSULTANT ? person.personId : undefined
-
- setTrackData({
- eventType: page.type,
- propertyName: page.name,
- consultantId,
- sharePersonId: person?.personId,
- targetId: id,
- })
- }, [person, page, id])
-
- // 主要用于埋点
- useEffect(() => {
- Taro.setStorage({ key: 'page', data: page })
- }, [page])
-
- useEffect(() => {
- setLoading(!person || !person.personId)
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [person])
-
- return (
- <>
- <Overlay visible={loading} style={{background: '#fff'}}>
- <Loading />
- </Overlay>
- <Overlay visible={authPhone} aligin='bottom'>
- <View className='auth-wrapper'>
- <AuthPhone consultant={consultant} router={router} page={page} />
- </View>
- </Overlay>
- <Overlay visible={!authPhone && authAvatar} aligin='bottom'>
- <View className='auth-wrapper'>
- <AuthAvatar />
- </View>
- </Overlay>
- <Spin size={32} spinning={spinning} />
- {
- person && !!person.personId && (
- <ChildComponent
- person={person}
- router={router}
- consultant={consultant}
- page={page}
- city={city}
- shareContent={shareContent}
- trackData={trackData}
- {...props}
- {...extInfo}
- />
- )
- }
- {
- !!showConsultant && (<FixedConsultant consultant={consultant} />)
- }
- <FirstScreen
- info={screenInfo}
- visible={false}
- onClick={handleScreen}
- onClose={toggleShowScreen}
- />
- </>
- )
- }
|