index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React, { useCallback, useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import classNames from 'classnames'
  4. import { baseURL, myData } from '@/utils/http'
  5. import { domDelOwnFu } from '@/utils/utilsSome'
  6. type Props = {
  7. isShow: boolean //是否显示
  8. iconSrc: string //icon 图标
  9. parentFu: () => void //点击继续的方法(调用父亲)
  10. bgImg?: string
  11. num?: number
  12. }
  13. function BaseImg({ isShow, iconSrc, parentFu, bgImg, num = 30 }: Props) {
  14. const [loding, setLoding] = useState(myData.isLdong ? 0 : 100)
  15. const timeRR = useRef(-1)
  16. useEffect(() => {
  17. clearInterval(timeRR.current)
  18. timeRR.current = window.setInterval(() => {
  19. if (loding >= 100) {
  20. clearInterval(timeRR.current)
  21. return
  22. }
  23. setLoding(loding + 2)
  24. }, num)
  25. }, [loding, num])
  26. const btnStartFu = useCallback(() => {
  27. if (loding >= 100) {
  28. parentFu()
  29. // 0.5s之后删除自己
  30. setTimeout(() => {
  31. domDelOwnFu('#BaseImg')
  32. }, 500)
  33. }
  34. }, [loding, parentFu])
  35. return (
  36. <div
  37. id='BaseImg'
  38. className={classNames(styles.BaseImg, isShow ? styles.BaseImgHide : '')}
  39. style={{ backgroundImage: `url(${bgImg ? bgImg : ''})` }}
  40. >
  41. <img className='BIlogo' src={iconSrc} alt='' />
  42. <div className='BIbaseBtn' onClick={btnStartFu}>
  43. {/* anpg动图 */}
  44. <div className='BIcon'>
  45. <img src={`${baseURL}visit/arrow.png`} alt='' />
  46. </div>
  47. <img src={`${baseURL}visit/btn.png`} alt='' />
  48. <div className='BIBtxt'>{loding >= 100 ? '点击继续' : '加载中'}</div>
  49. {loding >= 100 ? null : (
  50. <div className='BIBxian'>
  51. <div>
  52. <div style={{ width: loding + '%' }}></div>
  53. </div>
  54. </div>
  55. )}
  56. </div>
  57. </div>
  58. )
  59. }
  60. const MemoBaseImg = React.memo(BaseImg)
  61. export default MemoBaseImg