index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * 用于 page 根目录的样式等设置
  3. */
  4. import { View, Video } from "@tarojs/components";
  5. import React from "react";
  6. import pageStyle from "./index.module.less";
  7. import { GlobalModal } from '@/components/GlobalModal/index';
  8. interface Props {
  9. children?: React.ReactChild | React.ReactChild[];
  10. style?: React.CSSProperties;
  11. styleBg?: string;
  12. onClick?: (e:any)=> void
  13. }
  14. const Index: React.FC<Props> = ({ children, styleBg, style, onClick }) => {
  15. // 自定义背景样式
  16. const bgImageStyle = {
  17. backgroundImage: `url(${styleBg})`,
  18. };
  19. const renderBg = () => {
  20. if(!styleBg) {
  21. return <></>
  22. }
  23. if(styleBg.lastIndexOf('.mp4') > -1){
  24. return <Video
  25. controls={false}
  26. showCenterPlayBtn={false}
  27. loop={true}
  28. muted={true}
  29. autoplay
  30. objectFit="cover"
  31. className={pageStyle.bg}
  32. src={styleBg}
  33. />
  34. }
  35. return <View className={pageStyle.bg} style={bgImageStyle}></View>
  36. }
  37. // 盖在背景上面的是视口高度的 渐变色
  38. const handleClick = (e:any)=> {
  39. onClick && onClick(e)
  40. }
  41. return (
  42. <View className={`relative font-normal text-14 leading-22 w-full`} onClick={handleClick}>
  43. {/* cover 背景图覆盖从上至下渐变 */}
  44. <View className={`global-linear-gradient-bg ${pageStyle.bgVerticalGradient}`}></View>
  45. {/* bg 背景图 */}
  46. {renderBg()}
  47. <View className="relative z-0 h-full w-full" style={style}>{children}</View>
  48. <GlobalModal></GlobalModal>
  49. </View>
  50. );
  51. };
  52. export default Index;