view.jsx 19 KB

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