index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React, { useCallback, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { forwardRef, useImperativeHandle } from 'react'
  4. import { useSelector } from 'react-redux'
  5. import { RootState } from '@/store'
  6. type Props = {
  7. style: React.CSSProperties
  8. ref: any
  9. }
  10. function Shuxing({ style }: Props, ref: any) {
  11. const { myData, myLangue } = useSelector((state: RootState) => state.A0Layout)
  12. const [currentIndex, setCurrentIndex] = useState(0)
  13. const [isShowDetail, setIsShowDetail] = useState(false)
  14. // 让父组件调用,查看当前层级
  15. const sonGetStaFu = useCallback(() => {
  16. return isShowDetail
  17. }, [isShowDetail])
  18. const sonSetStaFu = useCallback(() => {
  19. setIsShowDetail(false)
  20. }, [])
  21. // 可以让父组件调用子组件的方法
  22. useImperativeHandle(ref, () => ({
  23. sonGetStaFu,
  24. sonSetStaFu
  25. }))
  26. return (
  27. <div className={styles.Shuxing} style={style}>
  28. {!isShowDetail && (
  29. <div className='mainContent'>
  30. <div className='mainTitle'>
  31. {myLangue === 'EN' ?
  32. 'The Northern Dynasties were a chaotic era marked by regime changes and constant warfare, but also a grand stage for ethnic integration. Shanxi, situated in the middle reaches of the Yellow River and guarding the gateway to the Central Plains, witnessed the clash between nomadic and agricultural societies, and the coexistence of Han and non-Han cultural influences. Various ethnic groups learned from and integrated with each other within this geographically connected land. Northern Dynasties inscriptions, such as the Cheng Zhe Stele, possess a dual nature, bearing witness to the diverse behaviors of the people in the delicate balance between institutions and customs, beliefs and funeral practices. This also showcases the rich expressiveness of history and the allure of the multifaceted and integrated development of the Chinese nation.' : ' 北朝,是政权更迭与战火交织的乱世,亦是民族融合的壮阔舞台。山西地处黄河中游扼守中原门户,游牧与农耕在此碰撞,胡风汉韵于此共生,各民族在表里山河中互鉴互融。北朝如程哲碑有双面性质的碑刻,在制度与习俗、信仰与丧葬的微妙平衡中见证了信仰与现实在民众中的群像行为,也为我们展现出历史丰富表现力与中华民族多元融合发展的吸引力。'}
  33. </div>
  34. <div className='imgBox'>
  35. {myData.shuxing.map((item, index) => (
  36. <div
  37. className='item'
  38. key={index}
  39. onClick={() => {
  40. setCurrentIndex(index)
  41. setIsShowDetail(true)
  42. }}
  43. >
  44. <div className='pic'>
  45. <img src={item.img} alt='' />
  46. </div>
  47. <div className='name songFont'>{item.name}</div>
  48. <div className='time'>{item.time}</div>
  49. </div>
  50. ))}
  51. </div>
  52. </div>
  53. )}
  54. {isShowDetail && (
  55. <div className='detailContent'>
  56. <div className='detailContainner'>
  57. <div className='left'>
  58. <div className='detailTitle songFont'>{myData.shuxing[currentIndex].name}</div>
  59. <div className='detailTime'>
  60. <div className='label'>年代:</div>&emsp;<p>{myData.shuxing[currentIndex].time}</p>
  61. </div>
  62. <div className='detailSize'>
  63. <div className='label'>尺寸:</div>&emsp;<p>{myData.shuxing[currentIndex].size}</p>
  64. </div>
  65. <div className='detailDesc'>
  66. <div className='label'>描述:</div>&emsp;
  67. <p>{myData.shuxing[currentIndex].desc}</p>
  68. </div>
  69. </div>
  70. <div className='right'>
  71. <img
  72. className='diwen'
  73. draggable={false}
  74. src={require(`@/assets/img/A7_diwen${currentIndex}.png`)}
  75. alt=''
  76. />
  77. <img src={myData.shuxing[currentIndex].img} alt='' />
  78. </div>
  79. </div>
  80. <div className='bottom'>
  81. {myData.shuxing.map((item, index) => (
  82. <div
  83. className={`item ${index === currentIndex ? 'itemAc' : ''}`}
  84. key={index}
  85. onClick={() => setCurrentIndex(index)}
  86. >
  87. <img src={item.img} alt='' />
  88. </div>
  89. ))}
  90. </div>
  91. </div>
  92. )}
  93. </div>
  94. )
  95. }
  96. export default forwardRef(Shuxing)