view.jsx 20 KB

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