view.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * @Author: dayan_hjm
  3. * @Date: 2023-10-25 10:32:44
  4. * @Last Modified by: dayan_hjm
  5. * @Last Modified time: 2023-11-05 11:14:56
  6. */
  7. /*
  8. * @Author: dayan_hjm
  9. * @Date: 2022-10-27 11:40:02
  10. * @Last Modified by: dayan_hjm
  11. * @Last Modified time: 2023-10-25 10:32:07
  12. */
  13. import React, { useState, useEffect, Component } from "react";
  14. import styles from "./style.less";
  15. import { useHistory, useLocation, withRouter } from "react-router-dom";
  16. import { observer, observable } from "mobx-react";
  17. import { message, Space, Form, Popconfirm, Modal, Carousel, Icon, Button } from "antd";
  18. import mod from './mod';
  19. import { toJS } from "mobx";
  20. import BottomLineForSend from "./component/bottomLineForSend.jsx";
  21. import MoodSendView from "./component/moodSendView.jsx";
  22. import LeftMenoyView from "./component/leftMenoyView.jsx";
  23. import RightBottomView from "./component/rightBottomView.jsx";
  24. import OneQualified from "./component/oneQualified.jsx";
  25. import MapView from "./component/mapView.jsx";
  26. import {
  27. timeService,
  28. numberService,
  29. } from "./api";
  30. import 'animate.css';
  31. @withRouter
  32. class Home extends Component {
  33. // 构造函数,组件的实例创建时,最先执行
  34. constructor(props, context) {
  35. super(props, context);
  36. this.store = mod;
  37. this.state = {
  38. changGif: false,
  39. plannedCompletionData:[
  40. {name:'射洪',value:78.1},
  41. {name:'广东',value:12},
  42. {name:'珠海',value:65},
  43. {name:'潮汕',value:45},
  44. ],
  45. plannedCompletionNum:1,
  46. manHourData:[
  47. {name:'射洪',value:0.2},
  48. {name:'广东',value:33},
  49. {name:'珠海',value:65},
  50. {name:'潮汕',value:65},
  51. ],
  52. manHourNum:1,
  53. };
  54. this.timer = null //定时器,用于检测同步状态
  55. }
  56. componentDidMount() {
  57. this.fontMsgChange();
  58. this.getUrl();
  59. this.getUrl2()
  60. setTimeout(() => {
  61. this.videoStart();
  62. }, 200)
  63. setTimeout(() => {
  64. //替换gif
  65. this.setState({ changGif: true });
  66. }, 2000)
  67. }
  68. videoStart() {
  69. /* Chrome 浏览器的视频自动播放策略
  70. 1.始终允许静音模式下自动播放
  71. 2.在以下的情况中,带声音播放会被允许:
  72. ①用户已经与当前的域进行了交互(也就是click,tap事件)。
  73. ②在桌面设备上,用户的媒体参与度指数阈值已经超过,这意味着用户之前播放过有声视频。
  74. ③用户已经将网站添加到移动设备上的主屏幕或允在桌面上安装了PWA。
  75. 3.顶部帧可以将自动播放权限委派给其iframe,来允许自动播放声音
  76. 媒体参与度(Media Engagement)是指用户与媒体内容进行互动的程度,可以通过多个指标来衡量。这些指标主要包括观看时间、观看率、转化率、交互行为等。
  77. 可以通过:chrome://media-engagement/ 查看
  78. */
  79. const video = document.querySelector('.video2');
  80. console.log(video.play());
  81. const model = document.querySelector('.model')
  82. const btn = document.querySelector('button')
  83. // 第一种方法 引导用户去与页面交互实现播放
  84. async function play() {
  85. try {
  86. await video.play();
  87. //使用await的原因是因为video.play()方法返回的是一个Promise,所以在这里我们可以对他进行一些处理
  88. model.style.display = 'none';
  89. btn.removeEventListener('click', play);
  90. // 如果他自动播放了就隐藏按钮,消除点击事件
  91. } catch (err) {
  92. model.style.display = 'block';
  93. btn.addEventListener('click', play);
  94. // 如果Promise返回的是error就引导用户点击按钮,在调用play方法
  95. }
  96. }
  97. play();
  98. //第二种方法比较主流,类似的有网页版抖音以及B站
  99. function play() {
  100. video.muted = true;//设置视频为静音
  101. video.play();//调用播放方法
  102. const ctx = new AudioContext();
  103. const canAutoPlay = ctx.state === 'running'; //通过这个可以判断出视频能不能够自动播放 如何可以它的值就是“running” 否则为"suspended"
  104. // 如果是不能播放我们就执行下面的逻辑,其实就是类似于第一种方法,让用户与其交互
  105. ctx.close();
  106. if (canAutoPlay) {
  107. video.muted = false;
  108. model.style.display = 'none';
  109. btn.removeEventListener('click', play);
  110. }
  111. else {
  112. model.style.display = 'block';
  113. btn.addEventListener('click', play);
  114. }
  115. }
  116. play()
  117. }
  118. async getUrl(){
  119. await timeService().then(({ data=[], resultCode }) => {
  120. if (+resultCode === 0) {
  121. let plannedCompletionData = [],manHourData = [];
  122. data.map((x,i)=>{
  123. if(x.indexName == '产量计划完成率'){
  124. plannedCompletionData.push({
  125. name:x.factoryName,
  126. value:x.indexValue*100,
  127. })
  128. }else{
  129. manHourData.push({
  130. name:x.factoryName,
  131. value:x.indexValue*100,
  132. })
  133. }
  134. });
  135. this.setState({plannedCompletionData,manHourData,plannedCompletionNum:1,manHourNum:1});
  136. }
  137. });
  138. }
  139. async getUrl2(){
  140. await numberService().then(({ data=[], resultCode }) => {
  141. if (+resultCode === 0) {
  142. let totalValue = 0,yearDecline = 0,yearSend=0,productInventory=0;
  143. data.map((x,i)=>{
  144. if(x.indexName == '产值'){
  145. totalValue = x.indexValue
  146. }else if(x.indexName == '年度产量'){
  147. yearDecline = x.indexValue
  148. }else if(x.indexName == '产品库存'){
  149. yearSend = x.indexValue
  150. }else if(x.indexName == '年度产量'){
  151. productInventory = x.indexValue
  152. }
  153. });
  154. this.store.saveState({totalValue,yearDecline,yearSend,productInventory});
  155. setTimeout(() => {
  156. $(".shu1").numScroll();
  157. }, 2500)
  158. }
  159. });
  160. }
  161. componentDidCatch(){
  162. clearInterval(this.timer);
  163. this.timer = null;
  164. }
  165. fontMsgChange(){
  166. this.timer = setInterval(() => {
  167. const { plannedCompletionData,plannedCompletionNum,manHourData,manHourNum } = this.state;
  168. //产量计划完成率
  169. var p1 = document.getElementById('plannedCompletionBox');
  170. const datas_ = plannedCompletionData[plannedCompletionNum-1];
  171. var res = '<div class="topMsg_box animate__animated animate__zoomIn"><span class="topMsg_number shu1">' + datas_.value + '</span><span class="topMsg_number_2" style={{fontSize: "0.75em",color: "#fff"}}>%</span><p class="topMsg_number_p">'+datas_.name+'</p></div>';
  172. p1.innerHTML = res;
  173. //百万工时损工率
  174. var p2 = document.getElementById('manHourBox');
  175. const datas_2 = manHourData[manHourNum-1];
  176. var res2 = '<div class="topMsg_box animate__animated animate__zoomIn"><span class="topMsg_number shu1">' + datas_2.value + '</span><span class="topMsg_number_2">%</span><p class="topMsg_number_p">'+datas_2.name+'</p></div>';
  177. p2.innerHTML = res2;
  178. const num_ = plannedCompletionNum+1 >= plannedCompletionData.length ? 1 : plannedCompletionNum+1;
  179. const num_2 = manHourNum+1 >= manHourData.length ? 1 : manHourNum+1;
  180. this.setState({plannedCompletionNum:num_,manHourNum:num_2})
  181. }, 4000)
  182. }
  183. render() {
  184. const stores = this.store.state;
  185. const {totalValue,yearDecline,yearSend,productInventory} = this.store.state;
  186. let { changGif,plannedCompletionData, } = this.state;
  187. return (
  188. <div className={"home_box"}>
  189. {/* 视频播放器 */}
  190. <MapView></MapView>
  191. <div className={"video_box"}>
  192. <video src={require("@assets/imgs/dataVImg/homeVideo2.mp4").default} autoplay="autoplay" loop="loop" class="video2 center_box2 animate__animated animate__fadeIn animate__delay-2s"></video>
  193. </div>
  194. <div className={[styles.home + " home cbHome"]}>
  195. <div className="leftContent">
  196. <div class="topMsg2 animate__animated animate__fadeInDown animate__slower">
  197. <div className="topMsg">
  198. <p className="topMsg_title">总产值</p>
  199. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"}>
  200. <span className="topMsg_number" class="shu1">{totalValue}</span><span className="topMsg_number_2">万元</span>
  201. </div>
  202. </div>
  203. </div>
  204. <div class="center_box2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  205. <div className="center_box">
  206. <p className="topMsg_title">库存金额</p>
  207. <div className="topMsg_content">
  208. <LeftMenoyView></LeftMenoyView>
  209. </div>
  210. </div>
  211. </div>
  212. <div class="bottomContent2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  213. <div className="bottomContent bigDivPd">
  214. <p className="topMsg_title">月度产量/发货量</p>
  215. <div className="topMsg_content">
  216. <MoodSendView></MoodSendView>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. <div className="centerCon">
  222. <div class="topMsg3 animate__animated animate__fadeInUp animate__slower">
  223. <div className="topMsg">
  224. <div className="topMsg2">
  225. <div className="topMsg_content">
  226. <div className="center_li">
  227. <div className="right_li">
  228. <span className="topMsg_number" class="shu1">{yearDecline}</span>
  229. <p className="topMsg_line"></p>
  230. <span className="topMsg_tip">年度产量/吨</span>
  231. </div>
  232. </div>
  233. <div className="center_li">
  234. <div className="right_li">
  235. <span className="topMsg_number" class="shu1">{yearSend}</span>
  236. <p className="topMsg_line"></p>
  237. <span className="topMsg_tip">年度发货量/吨</span>
  238. </div>
  239. </div>
  240. <div className="center_li">
  241. <span className="topMsg_number" class="shu1">{productInventory}</span>
  242. <p className="topMsg_line"></p>
  243. <span className="topMsg_tip">产品库存/吨</span>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. <div class="bottomContent3 animate__animated animate__fadeInUp animate__slower">
  250. <div className="bottomContent">
  251. <p className="topMsg_title">近30天产量</p>
  252. <div className="topMsg_content">
  253. <BottomLineForSend></BottomLineForSend>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. {/* 右侧信息栏 */}
  259. <div className="rightContent">
  260. <div class="topMsg2 animate__animated animate__fadeInDown animate__slower">
  261. <div className="topMsg bigDivPd">
  262. <p className="topMsg_title">百万工时损工率</p>
  263. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"} id="manHourBox">
  264. <div className="topMsg_box">
  265. <span className="topMsg_number" class="shu1"></span><span className="topMsg_number_2"></span>
  266. <p className="topMsg_number_p"></p>
  267. </div>
  268. </div>
  269. </div>
  270. </div>
  271. <div class="topMsg_22 animate__animated animate__fadeInDown animate__slower">
  272. <div className="topMsg_2">
  273. <p className="topMsg_title">一次合格率</p>
  274. <div className="topMsg_content">
  275. <OneQualified></OneQualified>
  276. </div>
  277. </div>
  278. </div>
  279. <div class="topMsg_33 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  280. <div className="topMsg_3">
  281. <p className="topMsg_title">产量计划完成率</p>
  282. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"} id="plannedCompletionBox">
  283. <div className="topMsg_box">
  284. <span className="topMsg_number" class="shu1"></span><span className="topMsg_number_2"></span>
  285. <p className="topMsg_number_p"></p>
  286. </div>
  287. </div>
  288. </div>
  289. </div>
  290. <div class="bottomContent2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  291. <div className="bottomContent bigDivPd">
  292. <p className="topMsg_title">碳排放</p>
  293. <div className="topMsg_content">
  294. <RightBottomView></RightBottomView>
  295. </div>
  296. </div>
  297. </div>
  298. </div>
  299. <div className="bottom_box">
  300. <p style={{color:"#6a818d"}}>
  301. 更新时间:2023-10-18
  302. </p>
  303. </div>
  304. </div>
  305. </div>
  306. )
  307. }
  308. }
  309. export default Home;