view.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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-16 10:35:01
  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, Tooltip, 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. checkToken,
  30. updateTimeService
  31. } from "./api";
  32. import 'animate.css';
  33. @withRouter
  34. class Home extends Component {
  35. // 构造函数,组件的实例创建时,最先执行
  36. constructor(props, context) {
  37. super(props, context);
  38. this.store = mod;
  39. this.state = {
  40. updateTime: '',
  41. changGif: false,
  42. plannedCompletionData: [
  43. ],
  44. plannedCompletionNum: 1,
  45. manHourData: [
  46. ],
  47. manHourNum: 1,
  48. };
  49. this.timer = null //定时器,用于检测同步状态
  50. }
  51. componentWillMount() {
  52. if(window.location.host.indexOf("localhost") == -1){
  53. this.getToken()
  54. }
  55. }
  56. async getToken() {
  57. if (!sessionStorage.getItem("tqcVToken")) {
  58. this.props.history.replace("/home/index");
  59. } else {
  60. await checkToken(sessionStorage.getItem("tqcVToken")).then(({ data, resultCode }) => {
  61. if (data?.userId) {
  62. // this.props.history.push('/')
  63. } else {
  64. this.props.history.replace("/home/index");
  65. }
  66. });
  67. }
  68. }
  69. componentDidMount() {
  70. this.fontMsgChange();
  71. this.getUrl();
  72. this.getUrl2()
  73. this.getUrl3();
  74. setTimeout(() => {
  75. this.videoStart();
  76. }, 200)
  77. setTimeout(() => {
  78. //替换gif
  79. this.setState({ changGif: true });
  80. }, 2000)
  81. }
  82. videoStart() {
  83. /* Chrome 浏览器的视频自动播放策略
  84. 1.始终允许静音模式下自动播放
  85. 2.在以下的情况中,带声音播放会被允许:
  86. ①用户已经与当前的域进行了交互(也就是click,tap事件)。
  87. ②在桌面设备上,用户的媒体参与度指数阈值已经超过,这意味着用户之前播放过有声视频。
  88. ③用户已经将网站添加到移动设备上的主屏幕或允在桌面上安装了PWA。
  89. 3.顶部帧可以将自动播放权限委派给其iframe,来允许自动播放声音
  90. 媒体参与度(Media Engagement)是指用户与媒体内容进行互动的程度,可以通过多个指标来衡量。这些指标主要包括观看时间、观看率、转化率、交互行为等。
  91. 可以通过:chrome://media-engagement/ 查看
  92. */
  93. const video = document.querySelector('.video2');
  94. console.log(video.play());
  95. const model = document.querySelector('.model')
  96. const btn = document.querySelector('button')
  97. // 第一种方法 引导用户去与页面交互实现播放
  98. async function play() {
  99. try {
  100. await video.play();
  101. //使用await的原因是因为video.play()方法返回的是一个Promise,所以在这里我们可以对他进行一些处理
  102. model.style.display = 'none';
  103. btn.removeEventListener('click', play);
  104. // 如果他自动播放了就隐藏按钮,消除点击事件
  105. } catch (err) {
  106. model.style.display = 'block';
  107. btn.addEventListener('click', play);
  108. // 如果Promise返回的是error就引导用户点击按钮,在调用play方法
  109. }
  110. }
  111. play();
  112. //第二种方法比较主流,类似的有网页版抖音以及B站
  113. function play() {
  114. video.muted = true;//设置视频为静音
  115. video.play();//调用播放方法
  116. const ctx = new AudioContext();
  117. const canAutoPlay = ctx.state === 'running'; //通过这个可以判断出视频能不能够自动播放 如何可以它的值就是“running” 否则为"suspended"
  118. // 如果是不能播放我们就执行下面的逻辑,其实就是类似于第一种方法,让用户与其交互
  119. ctx.close();
  120. if (canAutoPlay) {
  121. video.muted = false;
  122. model.style.display = 'none';
  123. btn.removeEventListener('click', play);
  124. }
  125. else {
  126. model.style.display = 'block';
  127. btn.addEventListener('click', play);
  128. }
  129. }
  130. play()
  131. }
  132. async getUrl() {
  133. await timeService().then(({ data = [], resultCode }) => {
  134. if (+resultCode === 0) {
  135. let plannedCompletionData = [], manHourData = [];
  136. data.map((x, i) => {
  137. if(x.indexValue){
  138. if (x.indexName == '产量计划完成率') {
  139. plannedCompletionData.push({
  140. name: x.factoryName,
  141. value: Number((x.indexValue * 100).toFixed(2)),
  142. })
  143. } else {
  144. manHourData.push({
  145. name: x.factoryName,
  146. value: Number((x.indexValue * 100).toFixed(2)),
  147. })
  148. }
  149. }
  150. });
  151. this.setState({ plannedCompletionData, manHourData, plannedCompletionNum: 1, manHourNum: 1 });
  152. }
  153. });
  154. }
  155. async getUrl2() {
  156. await numberService().then(({ data = [], resultCode }) => {
  157. if (+resultCode === 0) {
  158. let totalValue = 0, yearDecline = 0, yearSend = 0, productInventory = 0;
  159. data.map((x, i) => {
  160. if (x.indexName == '产值') {
  161. totalValue = x.indexValue
  162. } else if (x.indexName == '年度产量') {
  163. yearDecline = x.indexValue
  164. } else if (x.indexName == '产品库存') {
  165. yearSend = x.indexValue
  166. } else if (x.indexName == '年度发货量') {
  167. productInventory = x.indexValue
  168. }
  169. });
  170. this.store.saveState({ totalValue, yearDecline, yearSend, productInventory });
  171. setTimeout(() => {
  172. $(".shu1").numScroll();
  173. }, 2500)
  174. }
  175. });
  176. }
  177. async getUrl3() {
  178. await updateTimeService().then(({ data = [], resultCode }) => {
  179. if (+resultCode === 0) {
  180. this.setState({ updateTime: data?.[0]?.etlTime || '' })
  181. }
  182. });
  183. }
  184. componentDidCatch() {
  185. clearInterval(this.timer);
  186. this.timer = null;
  187. }
  188. fontMsgChange() {
  189. this.timer = setInterval(() => {
  190. const { plannedCompletionData, plannedCompletionNum, manHourData, manHourNum } = this.state;
  191. //产量计划完成率
  192. var p1 = document.getElementById('plannedCompletionBox');
  193. const datas_ = plannedCompletionData[plannedCompletionNum - 1];
  194. var res = '<div class="topMsg_box animate__animated animate__zoomIn"><span class="topMsg_number shu1">' + datas_?.value.toFixed(2) + '</span><span class="topMsg_number_2" style={{fontSize: "0.75em",color: "#fff"}}>%</span><p class="topMsg_number_p">' + datas_.name + '</p></div>';
  195. p1.innerHTML = res;
  196. //百万工时损工率
  197. var p2 = document.getElementById('manHourBox');
  198. const datas_2 = manHourData[manHourNum - 1];
  199. var res2 = '<div class="topMsg_box animate__animated animate__zoomIn"><span class="topMsg_number shu1">' + datas_2?.value.toFixed(2) + '</span><span class="topMsg_number_2">%</span><p class="topMsg_number_p">' + datas_2.name + '</p></div>';
  200. p2.innerHTML = res2;
  201. const num_ = plannedCompletionNum + 1 > plannedCompletionData.length ? 1 : plannedCompletionNum + 1;
  202. const num_2 = manHourNum + 1 > manHourData.length ? 1 : manHourNum + 1;
  203. this.setState({ plannedCompletionNum: num_, manHourNum: num_2 })
  204. }, 4000)
  205. }
  206. render() {
  207. const stores = this.store.state;
  208. let { totalValue, yearDecline, yearSend, productInventory } = this.store.state;
  209. let { changGif, updateTime, } = this.state;
  210. return (
  211. <div className={"home_box"}>
  212. {/* 视频播放器 */}
  213. <MapView></MapView>
  214. <div className={"video_box"}>
  215. <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>
  216. </div>
  217. <div className={[styles.home + " home cbHome"]}>
  218. <div className="leftContent">
  219. <div class="topMsg2 animate__animated animate__fadeInDown animate__slower">
  220. <div className="topMsg">
  221. <Tooltip placement="bottom" title={' ● 从1月至m-1月的产值累计,产值计算方式:∑销售单价*产量'}>
  222. <p className="topMsg_title">总产值</p>
  223. </Tooltip>
  224. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"}>
  225. <span className="topMsg_number" class="shu1">{totalValue}</span><span className="topMsg_number_2">万元</span>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="center_box2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  230. <div className="center_box">
  231. <Tooltip placement="bottom" title={' ● 即为 更新数据ETL日期当天的库存金额,百分比即为产品库存金额占总体金额的百分比'}>
  232. <p className="topMsg_title" style={{ position: "relative", zIndex: 999999 }}>库存金额</p>
  233. </Tooltip>
  234. <div className="topMsg_content">
  235. <LeftMenoyView></LeftMenoyView>
  236. </div>
  237. </div>
  238. </div>
  239. <div class="bottomContent2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  240. <div className="bottomContent bigDivPd">
  241. <Tooltip placement="bottom" title={' ● m-6至m月的产量和发货量的对比数据(含外加工)当月的数据计算至更新数据ETL日期当天'}>
  242. <p className="topMsg_title">月度产量/发货量</p>
  243. </Tooltip>
  244. <div className="topMsg_content">
  245. <MoodSendView></MoodSendView>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. <div className="centerCon">
  251. <div class="topMsg3 animate__animated animate__fadeInUp animate__slower">
  252. <div className="topMsg">
  253. <div className="topMsg2">
  254. <div className="topMsg_content">
  255. <div className="center_li">
  256. <div className="right_li">
  257. <span className="topMsg_number" class="shu1">{yearDecline}</span>
  258. <p className="topMsg_line"></p>
  259. <Tooltip placement="bottom" title={' ● 即为从当年1月1日至更新数据ETL日期当天的产量之和(含外加工)'}>
  260. <span className="topMsg_tip">年度产量/吨</span>
  261. </Tooltip>
  262. </div>
  263. </div>
  264. <div className="center_li">
  265. <div className="right_li">
  266. <span className="topMsg_number" class="shu1">{productInventory}</span>
  267. <p className="topMsg_line"></p>
  268. <Tooltip placement="bottom" title={' ● 即为从当年1月1日至更新数据ETL日期当天的发货量之和(含外加工)'}>
  269. <span className="topMsg_tip">年度发货量/吨</span>
  270. </Tooltip>
  271. </div>
  272. </div>
  273. <div className="center_li">
  274. <span className="topMsg_number" class="shu1">{yearSend}</span>
  275. <p className="topMsg_line"></p>
  276. <Tooltip placement="bottom" title={' ● 更新数据ETL日期当天的产品库存数量(含外加工)'}>
  277. <span className="topMsg_tip">产品库存/吨</span>
  278. </Tooltip>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. <div class="bottomContent3 animate__animated animate__fadeInUp animate__slower">
  285. <div className="bottomContent">
  286. <Tooltip placement="bottom" title={' ● t-31 至更新数据ETL日期当天的日产量(含外加工)'}>
  287. <p className="topMsg_title">近30天产量</p>
  288. </Tooltip>
  289. <div className="topMsg_content">
  290. <BottomLineForSend></BottomLineForSend>
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295. {/* 右侧信息栏 */}
  296. <div className="rightContent">
  297. <div class="topMsg2 animate__animated animate__fadeInDown animate__slower">
  298. <div className="topMsg bigDivPd">
  299. <Tooltip placement="bottom" title={' ● 即为1月至m-1月的百万工时损工率'}>
  300. <p className="topMsg_title">百万工时损工率</p>
  301. </Tooltip>
  302. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"} id="manHourBox">
  303. <div className="topMsg_box">
  304. <span className="topMsg_number" class="shu1"></span><span className="topMsg_number_2"></span>
  305. <p className="topMsg_number_p"></p>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <div class="topMsg_22 animate__animated animate__fadeInDown animate__slower">
  311. <div className="topMsg_2">
  312. <Tooltip placement="bottom" title={' ● m-6至m月近六个月的产品一次合格率和目标值合格率;当月的数据计算至更新数据ETL日期当天'}>
  313. <p className="topMsg_title">一次合格率</p>
  314. </Tooltip>
  315. <div className="topMsg_content">
  316. <OneQualified></OneQualified>
  317. </div>
  318. </div>
  319. </div>
  320. <div class="topMsg_33 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  321. <div className="topMsg_3">
  322. <Tooltip placement="bottom" title={' ● 即为从当年1月至m-1月的累计产量计划完成率;'}>
  323. <p className="topMsg_title">产量计划完成率</p>
  324. </Tooltip>
  325. <div className={changGif ? "topMsg_content changBg_topMsg_content" : "topMsg_content"} id="plannedCompletionBox">
  326. <div className="topMsg_box">
  327. <span className="topMsg_number" class="shu1"></span><span className="topMsg_number_2"></span>
  328. <p className="topMsg_number_p"></p>
  329. </div>
  330. </div>
  331. </div>
  332. </div>
  333. <div class="bottomContent2 animate__animated animate__fadeInDown animate__slower animate__delay-1s">
  334. <div className="bottomContent bigDivPd">
  335. <Tooltip placement="bottom" title={' ● 近三年的碳排放强度、碳排放总量数据'}>
  336. <p className="topMsg_title">碳排放</p>
  337. </Tooltip>
  338. <div className="topMsg_content">
  339. <RightBottomView></RightBottomView>
  340. </div>
  341. </div>
  342. </div>
  343. </div>
  344. <div className="bottom_box">
  345. <p style={{ color: "#6a818d",lineHeight:'2px' }}>
  346. 更新时间 : {updateTime}
  347. </p>
  348. </div>
  349. </div>
  350. </div>
  351. )
  352. }
  353. }
  354. export default Home;