view.jsx 19 KB

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