index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #systemInfo = Taro.getSystemInfoSync();
  10. #w = this.#systemInfo.windowWidth - 60;
  11. #h = (this.#w / 16) * 9;
  12. constructor(props: any) {
  13. super(props);
  14. this.state = {
  15. height: 0,
  16. data: {},
  17. };
  18. this.getData();
  19. }
  20. getImageSize = (e: any) => {
  21. const systemInfo = Taro.getSystemInfoSync();
  22. this.setState({
  23. height: (systemInfo.screenWidth / e.detail.width) * e.detail.height,
  24. });
  25. };
  26. getData = () => {
  27. Taro.showLoading({
  28. title: "加载中",
  29. });
  30. Taro.request({
  31. url:
  32. base.baseUrlEle +
  33. "/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/home.json?data=" +
  34. Date.now(),
  35. method: "GET",
  36. success: (res: any) => {
  37. if (res.statusCode !== 200)
  38. return Taro.showToast({
  39. title: "请求失败",
  40. icon: "none",
  41. });
  42. this.setState({
  43. data: res.data || {},
  44. });
  45. Taro.hideLoading();
  46. },
  47. fail: (error: any) => {
  48. Taro.hideLoading();
  49. Taro.showToast({
  50. title: JSON.stringify(error),
  51. });
  52. },
  53. });
  54. };
  55. render() {
  56. // const { } = this.props;
  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: ${this.#systemInfo.screenWidth}px;height: ${
  67. this.state.height
  68. }px;`}
  69. 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"
  70. onLoad={this.getImageSize}
  71. />
  72. <InputBox>
  73. <View className="mian">
  74. {this.#h && this.state.data.baseVideoUrl && (
  75. <Video
  76. src={this.state.data.baseVideoUrl || ""}
  77. controls={false}
  78. style={`width: ${this.#w}px;height: ${this.#h}px;`}
  79. autoplay={true}
  80. loop
  81. show-fullscreen-btn={true}
  82. show-play-btn={true}
  83. id="video"
  84. />
  85. )}
  86. {this.state.data?.textList?.map((item: any) => (
  87. <View className="body">
  88. <View className="btn">{item.title}</View>
  89. {item.content?.map((p: any) => sonEle(p))}
  90. </View>
  91. ))}
  92. </View>
  93. </InputBox>
  94. </View>
  95. );
  96. }
  97. }
  98. export { Home };