NewPageHeader.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import React, { useEffect, useState } from 'react'
  2. import { Link, useHistory, useLocation } from 'react-router-dom'
  3. import useRequest from '@ahooksjs/use-request'
  4. import { Avatar, Button, Col, Row, message } from 'antd'
  5. import QrcodeIcon from 'assets/qrcode-icon.svg'
  6. import AppletImg from 'assets/applet.png'
  7. import OfficialImg from 'assets/official.png'
  8. // import LogoImg from 'assets/logo.png'
  9. import { useLogin2p } from './Login2p/Login2pContext'
  10. import { useMedia } from 'Context/Media/MediaContext'
  11. import ApplyPermission from 'Material/components/ApplyPermission'
  12. import HeadSearch from 'Search/components/HeadSearch'
  13. import { INewPermissionType, ITryType } from 'Material/components/NoPermission'
  14. import { MaterialService } from 'Material/Material.service'
  15. import styles from './styles/NewPage.module.scss'
  16. // 凡是vmp.tsx中Route的key={'new'},都来一套
  17. const urlList = [
  18. { path: '/column', key: 'community' },
  19. { path: '/community', key: 'community' },
  20. { path: '/activity', key: 'activity' },
  21. { path: '/indepth', key: 'indepth' },
  22. { path: '/material', key: 'material' },
  23. { path: '/my', key: 'newest' },
  24. { path: '/search', key: 'newest' },
  25. { path: '/', key: 'newest' }
  26. ]
  27. const NewPage: React.FC = props => {
  28. const location = useLocation()
  29. const history = useHistory()
  30. const media = useMedia()
  31. // const personalized = usePersonalized()
  32. const login2p = useLogin2p()
  33. const [activityKey, setActivityKey] = useState<string>('newest')
  34. const [hoverKey, setHoverKey] = useState<string>('newest')
  35. const [searchWord, setSearchWord] = useState<string>()
  36. const [visibleApply, setVisibleApply] = useState(false)
  37. const [isShowMenu, setIsShowMenu] = useState<boolean>(false)
  38. const [isShowMobileMenu, setIsShowMobileMenu] = useState<boolean>(false) // 识别报告详情页+活动详情页,适配移动菜单
  39. const handleToMy = () => {
  40. history.push('/my')
  41. }
  42. // const headMenu = [
  43. // { key: 'newest', path: '/', label: '最新' },
  44. // { key: 'material', path: '/material', label: '素材库' },
  45. // { key: 'indepth', path: '/indepth', label: '深度研究' },
  46. // { key: 'activity', path: '/activity', label: '活动' },
  47. // { key: 'community', path: '/community', label: '研选社区' }
  48. // ]
  49. const { run: applyTry } = useRequest(MaterialService.postApplyTry, {
  50. manual: true,
  51. onSuccess: res => {
  52. res.data.Success
  53. ? message.success('已提交给您的对口销售,请耐心等待。')
  54. : message.info(res.data.Msg || res.data.ErrMsg)
  55. }
  56. })
  57. useEffect(() => {
  58. handleChangeMenuKey(location)
  59. history.listen(location => {
  60. window.scrollTo(0, 0)
  61. handleChangeMenuKey(location)
  62. })
  63. // eslint-disable-next-line react-hooks/exhaustive-deps
  64. }, [])
  65. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  66. const handleChangeMenuKey = (location: any) => {
  67. if (location.pathname.includes('/search')) {
  68. const searchArr = location.pathname.split('/')
  69. setSearchWord(searchArr[2])
  70. } else {
  71. setSearchWord(undefined)
  72. }
  73. const findKey = urlList.find(item => location.pathname.includes(item.path))?.key
  74. setActivityKey(findKey ? findKey : 'newest')
  75. setHoverKey(findKey ? findKey : 'newest')
  76. // 识别报告详情页+活动详情页,适配移动菜单
  77. if (media.isSmallMax) {
  78. const routhStr = ['/material/info', '/activity/info', '/activity/detail', '/internal/article', '/column/detail']
  79. let flag = false
  80. routhStr.forEach(item => {
  81. if (location.pathname.includes(item)) {
  82. setIsShowMobileMenu(true)
  83. flag = true
  84. }
  85. })
  86. if (!flag) {
  87. setIsShowMobileMenu(false)
  88. }
  89. } else {
  90. setIsShowMobileMenu(false)
  91. }
  92. }
  93. // const handleClickMenu = (item: { key: string; path: string; label: string }) => {
  94. // setActivityKey(item.key)
  95. // setHoverKey(item.key)
  96. // setSearchWord(undefined)
  97. // history.push(item.path)
  98. // }
  99. // const handleMenuOver = (key: string) => {
  100. // setHoverKey(key)
  101. // }
  102. /** 搜索框的事件 */
  103. const handleToDoSearch = (value: string) => {
  104. setSearchWord(value)
  105. history.push(`/search/${value}`)
  106. }
  107. const handleMobileLogout = () => {
  108. localStorage.removeItem('token')
  109. localStorage.removeItem('smtoken')
  110. window.location.reload()
  111. }
  112. // 提交申请权限
  113. const handleToApplyPower = () => {
  114. if (!login2p.jwt) return
  115. // HasPermission=2,4,6,已提交过申请的,提示:您已提交过申请,请等待销售与您联系。
  116. if (
  117. login2p.userInfo?.HasPermission === INewPermissionType.HasApplyQY ||
  118. login2p.userInfo?.HasPermission === INewPermissionType.HasApplyFICC ||
  119. login2p.userInfo?.HasPermission === INewPermissionType.HasApplyPotential
  120. ) {
  121. message.info('您已提交过申请,请等待销售与您联系。')
  122. return
  123. }
  124. // HasPermission=3,5,不弹表单,直接提交申请
  125. if (
  126. login2p.userInfo?.HasPermission === INewPermissionType.NoApplyQY ||
  127. login2p.userInfo?.HasPermission === INewPermissionType.NoApplyFICC
  128. ) {
  129. applyTry({ ApplyMethod: 1 })
  130. return
  131. }
  132. // HasPermission=7,弹表单填写,提交申请
  133. setVisibleApply(true)
  134. }
  135. const handleOKApply = () => {
  136. setVisibleApply(false)
  137. }
  138. return (
  139. <div className={styles['newpage-header']} style={{ minWidth: isShowMobileMenu ? 'auto' : '1024px' }}>
  140. {isShowMobileMenu ? (
  141. <div className={styles['newpage-mobile-header']}>
  142. <div className="newpage-mobile-menu-wrapper">
  143. <Link to="/" className={styles['logo-wrapper']}>
  144. <img
  145. src="https://hzstatic.hzinsights.com/cygx_web/ico/logo_inedx.png"
  146. className={styles.headerLogo}
  147. alt="logo"
  148. />
  149. </Link>
  150. {login2p.jwt ? (
  151. <img
  152. src={login2p.userInfo?.Headimgurl}
  153. alt="头像"
  154. className="mobile-menu-person-img"
  155. onClick={() => setIsShowMenu(!isShowMenu)}
  156. />
  157. ) : (
  158. <Link to={`/login2p?next=${location.pathname}`}>
  159. <Button type="primary" className="mobile-login2p-btn">
  160. 登录
  161. </Button>
  162. </Link>
  163. )}
  164. {/* <MenuOutlined className="mobile-menu-icon" onClick={() => setIsShowMenu(!isShowMenu)} /> */}
  165. </div>
  166. {isShowMenu ? (
  167. <div className="newpage-mobile-menu-list">
  168. {/* <div className="mobile-search">
  169. <HeadSearch onSearch={handleToDoSearch} defaultKeyword={searchWord} className="mobile-search-reset" />
  170. </div>
  171. {login2p.jwt ? (
  172. <>
  173. <div className="mobile-center-wrapper" onClick={() => setIsOpen(!isOpen)}>
  174. <div>
  175. <img
  176. src={login2p.userInfo?.Headimgurl || auth.userInfo?.avatar}
  177. alt="头像"
  178. className="mobile-person-img"
  179. />
  180. <div className="mobile-person-name"> {login2p.userInfo?.UserName || auth.userInfo?.name}</div>
  181. </div>
  182. {isOpen ? <UpOutlined /> : <DownOutlined />}
  183. </div>
  184. {isOpen ? (
  185. <div className="mobile-person-content">
  186. <div className="mobile-person-phone">{login2p.userInfo?.Mobile || auth.userInfo?.phone_number}</div>
  187. <div className="mobile-person-company">{login2p.userInfo?.CompanyName || '弘则研究'}</div>
  188. <div className="mobile-person-power">
  189. {login2p.userInfo?.PermissionName?.map((item, index) => (
  190. <div className={item ? 'mobile-person-power-one' : ''} key={index}>
  191. {item}
  192. </div>
  193. ))}
  194. </div>
  195. </div>
  196. ) : null}
  197. </>
  198. ) : null}
  199. {headMenu.map(item => (
  200. <div
  201. className={`mobile-header-item ${activityKey === item.key ? 'mobile-header-act' : ''} `}
  202. key={item.key}
  203. onClick={handleClickMenu.bind(this, item)}
  204. onMouseOver={handleMenuOver.bind(this, item.key)}
  205. >
  206. {item.label}
  207. </div>
  208. ))}
  209. <div className="mobile-header-item" onClick={handleToMy}>
  210. 个人中心
  211. </div> */}
  212. {login2p.jwt ? (
  213. <div className="mobile-header-item g-flex g-flex-between">
  214. <div>{login2p.userInfo?.Mobile}</div>
  215. <div onClick={handleMobileLogout}>退出</div>
  216. </div>
  217. ) : null}
  218. {/* (
  219. <div className="mobile-header-item" onClick={login2p.logout}>
  220. <Link to={`/login2p?next=${location.pathname}`}>
  221. <Button type="primary" className="mobile-login2p-btn">
  222. 登录
  223. </Button>
  224. </Link>
  225. </div>
  226. ) */}
  227. </div>
  228. ) : null}
  229. </div>
  230. ) : (
  231. <Row wrap={false} justify="space-around" align="middle">
  232. <Col className={styles['reset-padding']}>
  233. <Link to="/" className={styles['logo-wrapper']}>
  234. <img
  235. src="https://hzstatic.hzinsights.com/cygx_web/ico/logo_inedx.png"
  236. className={styles.headerLogo}
  237. alt="logo"
  238. />
  239. {/* <span className={styles['header-text']}>查研观向</span> */}
  240. </Link>
  241. </Col>
  242. <Col className={styles['reset-padding']}>
  243. {/* <div className={styles['header-menu-wrapper']} onMouseLeave={() => setHoverKey(activityKey)}>
  244. {headMenu.map(item => (
  245. <div
  246. className={`${styles['header-item']} ${activityKey === item.key ? styles['header-act'] : ''} ${
  247. hoverKey === item.key ? styles['header-underline'] : ''
  248. }`}
  249. key={item.key}
  250. onClick={handleClickMenu.bind(this, item)}
  251. onMouseOver={handleMenuOver.bind(this, item.key)}
  252. >
  253. {item.label}
  254. </div>
  255. ))}
  256. </div> */}
  257. </Col>
  258. <Col flex="auto" className={`${styles['reset-padding']} ${styles['search-header']}`}>
  259. {/* <SearchOutlined className={styles.fz19} onClick={handleOpenSearch} /> */}
  260. <HeadSearch
  261. onSearch={handleToDoSearch}
  262. defaultKeyword={searchWord}
  263. placeholder="搜索"
  264. className={styles['search-header-max']}
  265. />
  266. </Col>
  267. <Col className={styles['reset-padding']}>
  268. <div className={styles['qrcode-wrapper']}>
  269. <img src={QrcodeIcon} alt="图片" className="qrcode-img" />
  270. <div className="qrcode-box">
  271. <div className="qrcode-smbox">
  272. <img src={AppletImg} alt="二维码" className="qrcode-code" />
  273. <div className="g-ta-ct">
  274. 手机扫码
  275. <br />
  276. 体验微信小程序功能
  277. </div>
  278. </div>
  279. <div className="qrcode-smbox">
  280. <img src={OfficialImg} alt="二维码" className="qrcode-code" />
  281. <div className="g-ta-ct">关注【买方研选】公众号 及时获取报告和活动通知</div>
  282. </div>
  283. </div>
  284. </div>
  285. </Col>
  286. <Col className={styles['reset-padding']}>
  287. {login2p.jwt ? (
  288. <div className={styles['center-wrapper']}>
  289. <Avatar src={login2p.userInfo?.Headimgurl} shape={'circle'} className="header-avatar" />
  290. <div className="person-center-wrapper">
  291. <div className="person-wrapper">
  292. <img src={login2p.userInfo?.Headimgurl} alt="头像" className="person-img" />
  293. <div className="person-content">
  294. <div className="person-name"> {login2p.userInfo?.UserName || '--'}</div>
  295. <div className="person-phone">{login2p.userInfo?.Mobile}</div>
  296. <div className="person-company">{login2p.userInfo?.CompanyName || '--'}</div>
  297. </div>
  298. </div>
  299. <div className="person-power-wraper">
  300. {login2p.userInfo?.HasPermission === INewPermissionType.OK ? (
  301. <div className="person-haspower">
  302. <div className="person-haspower-label">{login2p.userInfo?.PermissionStatus}</div>
  303. <div className="person-haspower-text">
  304. <div>
  305. {login2p.userInfo?.StartDate}~{login2p.userInfo?.EndDate}
  306. </div>
  307. {login2p.userInfo?.PermissionStatus.includes('试用') ? null : (
  308. <div>
  309. 剩余研选点数:
  310. <span className="hightlight-text">{login2p.userInfo?.CompanyPointsNum || 0}</span>
  311. </div>
  312. )}
  313. </div>
  314. </div>
  315. ) : (
  316. <div className="person-nopower">
  317. <span>暂无权限,可点击</span>
  318. <div className="person-nopower-btn" onClick={handleToApplyPower}>
  319. 申请
  320. </div>
  321. </div>
  322. )}
  323. </div>
  324. {/* <div className="person-power">
  325. {login2p.userInfo?.PermissionName?.map((item, index) => (
  326. <div className={item ? 'person-power-one' : ''} key={index}>
  327. {item}
  328. </div>
  329. ))}
  330. </div> */}
  331. <div className="divide-line" />
  332. <div className="person-line person-center-link" onClick={handleToMy}>
  333. 个人中心
  334. </div>
  335. <div className="person-line person-exit" onClick={login2p.logout}>
  336. 退出
  337. </div>
  338. </div>
  339. </div>
  340. ) : (
  341. <Link to={`/login2p?next=${location.pathname}`}>
  342. <Button type="primary" className={styles['login2p-btn']}>
  343. 登录
  344. </Button>
  345. </Link>
  346. )}
  347. </Col>
  348. </Row>
  349. )}
  350. {/* todo */}
  351. <ApplyPermission visible={visibleApply} handleClose={handleOKApply} />
  352. </div>
  353. )
  354. }
  355. export default NewPage