NewPageHeader.tsx 17 KB

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