index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import React from "react";
  2. import { View, Video, Text, Image } from "@tarojs/components";
  3. import Taro from "@tarojs/taro";
  4. import "./index.scss";
  5. import base from "../../config/base";
  6. import { InputBox } from "../../component/input/index";
  7. class Home extends React.Component<any, any> {
  8. static defaultProps = {};
  9. constructor(props: any) {
  10. super(props);
  11. this.state = {
  12. height: 0,
  13. data: {},
  14. };
  15. this.getData();
  16. }
  17. getImageSize = (e: any) => {
  18. const systemInfo = Taro.getSystemInfoSync();
  19. this.setState({
  20. height: (systemInfo.screenWidth / e.detail.width) * e.detail.height,
  21. });
  22. };
  23. getData = () => {
  24. Taro.showLoading({
  25. title: "加载中",
  26. });
  27. Taro.request({
  28. url:
  29. base.baseUrlEle +
  30. "/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/home.json?data=" +
  31. Date.now(),
  32. method: "GET",
  33. success: (res: any) => {
  34. if (res.statusCode !== 200)
  35. return Taro.showToast({
  36. title: "请求失败",
  37. icon: "none",
  38. });
  39. this.setState({
  40. data: res.data || {},
  41. });
  42. Taro.hideLoading();
  43. },
  44. fail: (error: any) => {
  45. Taro.hideLoading();
  46. Taro.showToast({
  47. title: JSON.stringify(error),
  48. });
  49. },
  50. });
  51. };
  52. render() {
  53. // const { } = this.props;
  54. const systemInfo = Taro.getSystemInfoSync();
  55. const w = systemInfo.screenWidth - 60;
  56. const h = (w / 16) * 9;
  57. const sonEle = (item) => (
  58. <View>
  59. <Text className="label">· {item.title} </Text>
  60. <View className="content">{item.content}</View>
  61. </View>
  62. );
  63. return (
  64. <View className="home">
  65. <Image
  66. style={`width: ${systemInfo.screenWidth}px;height: ${this.state.height}px;`}
  67. src="https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/home_top.jpg"
  68. onLoad={this.getImageSize}
  69. />
  70. <InputBox>
  71. <View className="mian">
  72. {h && this.state.data.baseVideoUrl && (
  73. <Video
  74. src={this.state.data.baseVideoUrl || ""}
  75. controls={false}
  76. style={`width: ${w}px;height: ${h}px;`}
  77. autoplay={true}
  78. loop
  79. muted
  80. show-fullscreen-btn={true} show-play-btn={true}
  81. id="video"
  82. />
  83. )}
  84. {this.state.data?.textList?.map((item: any) => (
  85. <View className="body">
  86. <View className="btn">{item.title}</View>
  87. {item.content?.map((p: any) => sonEle(p))}
  88. </View>
  89. ))}
  90. </View>
  91. </InputBox>
  92. </View>
  93. );
  94. }
  95. }
  96. export { Home };