barscreen.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <title>条屏</title>
  9. </head>
  10. <body>
  11. <div class="container">
  12. <div class="title">
  13. <div class="title-text" id="title"></div>
  14. </div>
  15. <div class="border1"></div>
  16. <div class="content">
  17. <div class="con-info">
  18. <div class="con-info-index" id="index"></div>
  19. <div class="con-info-name" id="conInfoName"></div>
  20. <div class="con-info-state" id="conInfoState">
  21. <div class="con-info-state-icon">
  22. <img id="icon" src="./image/frees.png" />
  23. </div>
  24. <div class="con-info-state-text" id="conStateText"></div>
  25. </div>
  26. </div>
  27. <div class="con-state" id="conState">
  28. <div class="con-state-icon">
  29. <img id="icon1" src="./image/frees.png" />
  30. </div>
  31. <div class="con-state-text" id="conStateText1">工作中</div>
  32. </div>
  33. <div class=""></div>
  34. <div class="con-now" id="conNowBox">
  35. 正在办理:<span id="conNow"></span>
  36. </div>
  37. <div class="con-wait" id="conWaitBox">
  38. 当前等待:<span id="conWait"></span>
  39. </div>
  40. </div>
  41. </div>
  42. </body>
  43. </html>
  44. <script>
  45. var wsApiUrl = "wss://pdjh.shizhi.tv/websocket/gw/";
  46. // *** 接口地址 ***
  47. var ettpApiUrl = "https://pdjh.shizhi.tv/machine/init/old/ettp";
  48. // var ettpApiUrl = "http://1.82.219.239:8092/machine/init/old/ettp"
  49. var stateApiUrl = "https://pdjh.shizhi.tv/machine/init/old/split/getRedis";
  50. // var stateApiUrl = "http://1.82.219.239:8092/machine/init/old/split/getRedis"
  51. // *** 参数信息 ***
  52. var url = window.location.search.slice(1).split("&");
  53. var tpname = url[0].slice(url[0].lastIndexOf("=") + 1);
  54. var sljgdm = url[1].slice(url[1].lastIndexOf("=") + 1);
  55. // 获取数据
  56. function getDatas() {
  57. if ("WebSocket" in window) {
  58. console.log("您的浏览器支持 WebSocket!");
  59. websocket();
  60. } else {
  61. console.log("您的浏览器不支持 WebSocket!");
  62. getEttpInit();
  63. }
  64. }
  65. // websocket
  66. function websocket() {
  67. // ws参数
  68. var msg = {
  69. userType: "ET条屏",
  70. machineName: tpname,
  71. sljgdm: sljgdm,
  72. };
  73. var wsUrl = wsApiUrl + "{" + JSON.stringify(msg) + "}";
  74. var connection = null;
  75. // 心跳倒计时
  76. var heartTimer = null;
  77. // 重连倒计时
  78. var reConnectTimer = null;
  79. function connectWS() {
  80. connection = new WebSocket(wsUrl);
  81. // ws 连接成功
  82. connection.onopen = wsOpen;
  83. function wsOpen(event) {
  84. heart();
  85. }
  86. connection.onclose = wsClose;
  87. function wsClose() {
  88. reConnect();
  89. console.log("%c" + "连接关闭,正在重连...", "color:" + "#fe4c40");
  90. }
  91. // 接收消息
  92. connection.onmessage = wsMessage;
  93. function wsMessage(event) {
  94. var response = JSON.parse(event.data);
  95. switch (response.code) {
  96. default:
  97. return;
  98. // 初始化
  99. case "ettpInit":
  100. updateDom(response.tpxxVO);
  101. break;
  102. //取号完成
  103. case "qhwc":
  104. for (var i = 0; i < response.tpList.length; i++) {
  105. if (response.tpList[i].tpbh == tpname) {
  106. var list = response.tpList[i].tpxxVO;
  107. updateDom(list);
  108. break;
  109. }
  110. }
  111. break;
  112. // 综合完成
  113. case "zhwc":
  114. for (var i = 0; i < response.tpList.length; i++) {
  115. if (response.tpList[i].tpbh == tpname) {
  116. var list = response.tpList[i].tpxxVO;
  117. updateDom(list);
  118. break;
  119. }
  120. }
  121. break;
  122. // 叫号完成
  123. case "jhwc":
  124. for (var i = 0; i < response.tpList.length; i++) {
  125. if (response.tpList[i].tpbh == tpname) {
  126. var list = response.tpList[i].tpxxVO;
  127. updateDom(list);
  128. break;
  129. }
  130. }
  131. break;
  132. // 心跳
  133. case "heart":
  134. clearTimeout(reConnectTimer);
  135. heartTimer = setTimeout(function () {
  136. heart();
  137. }, 10 * 1000);
  138. break;
  139. }
  140. }
  141. }
  142. // 心跳
  143. function heart() {
  144. clearTimeout(heartTimer);
  145. if (connection != null) {
  146. var heartText = {
  147. code: "heart",
  148. text: "这只是一个心跳",
  149. };
  150. connection.send(JSON.stringify(heartText));
  151. }
  152. reConnectTimer = setTimeout(function () {
  153. reConnect();
  154. }, 30 * 1000);
  155. }
  156. // 重连
  157. function reConnect() {
  158. clearTimeout(reConnectTimer);
  159. if (connection) {
  160. connection.close();
  161. connection = null;
  162. }
  163. connection = null;
  164. reConnectTimer = setTimeout(function () {
  165. connectWS();
  166. }, 3 * 1000);
  167. }
  168. connectWS();
  169. }
  170. // 条屏初始化信息
  171. function getEttpInit() {
  172. // *** 创建xhr的对象 ***
  173. var xhr = new XMLHttpRequest();
  174. xhr.open("post", ettpApiUrl);
  175. xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8");
  176. // *** 调用send函数 ***
  177. var ettpForm = JSON.stringify({
  178. machineName: tpname,
  179. sljgdm: sljgdm,
  180. userType: "ET条屏",
  181. });
  182. xhr.send(ettpForm);
  183. // *** 监听事件 ***
  184. xhr.onreadystatechange = function () {
  185. if (xhr.readyState == 4 && xhr.status === 200) {
  186. var ettpRes = JSON.parse(xhr.responseText) || {};
  187. var ettpResInfos = ettpRes.tpxxVO || {};
  188. // *** 修改内容 ***
  189. updateDom(ettpResInfos);
  190. } else {
  191. }
  192. };
  193. setTimeout(function () {
  194. getState();
  195. }, 800);
  196. }
  197. // 条屏轮询
  198. function getState() {
  199. // *** 创建xhr的对象 ***
  200. var xhr = new XMLHttpRequest();
  201. xhr.open("get", stateApiUrl + "?machineName=" + tpname);
  202. // *** 调用send函数 ***
  203. xhr.send();
  204. // *** 监听事件 ***
  205. xhr.onreadystatechange = function () {
  206. if (xhr.readyState == 4 && xhr.status === 200) {
  207. var screenarr = JSON.parse(xhr.responseText) || {};
  208. var arr = screenarr.code == "0" ? screenarr.msg : null;
  209. if (arr != null) {
  210. var stateRes = JSON.parse(arr).tpxxVO || {};
  211. // *** 修改内容 ***
  212. updateDom(stateRes);
  213. }
  214. } else {
  215. }
  216. };
  217. setTimeout(function () {
  218. getState();
  219. }, 800);
  220. }
  221. // 更新dom
  222. function updateDom(infos) {
  223. // 标题
  224. setEleCon("title", "innerHTML", infos.dttsy || "");
  225. // 窗口号码
  226. setEleCon("index", "innerHTML", infos.ckhm || "");
  227. if (
  228. infos.slyw[0] != "电子税务局线上业务受理" &&
  229. infos.slyw[0] != "综合服务"
  230. ) {
  231. setStyle("conInfoState", "display", "");
  232. setStyle("conState", "display", "none");
  233. setStyle("conNowBox", "display", "");
  234. setStyle("conWaitBox", "display", "");
  235. setStyle("conInfoName", "width", "750px");
  236. setStyle("conNowBox", "fontSize", "");
  237. setStyle("conNowBox", "marginLeft", "");
  238. // 业务名称
  239. if (infos.slyw) {
  240. setEleCon("conInfoName", "innerHTML", infos.slyw.join(" "));
  241. if (infos.slyw.join(" ").length > 5) {
  242. setStyle("conInfoName", "lineHeight", "150px");
  243. setStyle("conInfoName", "fontSize", "120px");
  244. } else {
  245. setStyle("conInfoName", "lineHeight", "300px");
  246. setStyle("conInfoName", "fontSize", "150px");
  247. }
  248. }
  249. // 修改图标及状态
  250. var srcs = {
  251. kx: "./image/frees.png",
  252. zt: "./image/wites.png",
  253. hj: "./image/xlb.png",
  254. };
  255. var textColors = {
  256. kx: "#00FFFF",
  257. zt: "#FFF700",
  258. hj: "#00FFFF",
  259. };
  260. var ckzt = infos.ckzt || "";
  261. setEleCon(
  262. "icon",
  263. "src",
  264. ckzt == "空闲" ? srcs.kx : ckzt === "暂停服务" ? srcs.zt : srcs.hj
  265. );
  266. setStyle(
  267. "conStateText",
  268. "color",
  269. ckzt === "空闲"
  270. ? textColors.kx
  271. : ckzt === "暂停服务"
  272. ? textColors.zt
  273. : textColors.kx
  274. );
  275. setEleCon("conStateText", "innerHTML", ckzt === "空闲" ? "工作中" : ckzt);
  276. // 正在办理
  277. setEleCon(
  278. "conNow",
  279. "innerHTML",
  280. ckzt != "空闲" && ckzt != "暂停服务" ? ckzt : "暂无"
  281. );
  282. // 等待人数
  283. setEleCon(
  284. "conWait",
  285. "innerHTML",
  286. ckzt != "暂停服务" && infos.ddrs != "0"
  287. ? (infos.ddrs || "0") + "人"
  288. : "暂无"
  289. );
  290. } else {
  291. setStyle("conInfoState", "display", "none");
  292. setStyle("conNowBox", "display", "none");
  293. setStyle("conWaitBox", "display", "none");
  294. if (infos.slyw[0] === "电子税务局线上业务受理") {
  295. setStyle("conInfoName", "width", "1555px");
  296. // 业务名称
  297. if (infos.slyw) {
  298. setStyle("conState", "display", "block");
  299. setEleCon("conInfoName", "innerHTML", infos.slyw.join(" "));
  300. setStyle("conInfoName", "lineHeight", "300px");
  301. setStyle("conInfoName", "fontSize", "140px");
  302. }
  303. } else if (infos.slyw[0] === "综合服务") {
  304. setStyle("conInfoName", "width", "750px");
  305. // 业务名称
  306. if (infos.slyw) {
  307. setStyle("conState", "display", "none");
  308. setEleCon("conInfoName", "innerHTML", infos.slyw.join(" "));
  309. setStyle("conInfoName", "lineHeight", "300px");
  310. if (infos.slyw.join(" ").length > 5) {
  311. setStyle("conInfoName", "fontSize", "120px");
  312. } else {
  313. setStyle("conInfoName", "fontSize", "150px");
  314. }
  315. setStyle("conInfoState", "display", "");
  316. // 修改图标及状态
  317. var srcs = {
  318. kx: "./image/frees.png",
  319. zt: "./image/wites.png",
  320. hj: "./image/xlb.png",
  321. };
  322. var textColors = {
  323. kx: "#00FFFF",
  324. zt: "#FFF700",
  325. hj: "#00FFFF",
  326. };
  327. var ckzt = infos.ckzt || "";
  328. setEleCon("icon", "src", srcs.zt);
  329. setStyle("conStateText", "color", textColors.zt);
  330. setEleCon("conStateText", "innerHTML", "暂停服务");
  331. setStyle("conNowBox", "display", "");
  332. setEleCon("conNowBox", "innerHTML", "潮汐窗口");
  333. setStyle("conNowBox", "fontSize", "180px");
  334. setStyle("conNowBox", "marginLeft", "110px");
  335. }
  336. }
  337. }
  338. }
  339. // 修改元素内容
  340. function setEleCon(id, label, value) {
  341. var ele = document.getElementById(id);
  342. ele[label] = value;
  343. }
  344. // 设置样式
  345. function setStyle(id, label, value) {
  346. var ele = document.getElementById(id);
  347. ele.style[label] = value;
  348. }
  349. // 获取元素内容
  350. function getEleCon(id) {
  351. var ele = document.getElementById(id);
  352. return ele.innerHTML;
  353. }
  354. // 获取数据
  355. getDatas();
  356. </script>
  357. <style>
  358. html,
  359. body {
  360. margin: 0;
  361. padding: 0;
  362. }
  363. .container {
  364. width: 1920px;
  365. height: 1080px;
  366. }
  367. .title {
  368. padding: 20px 0;
  369. width: 100%;
  370. height: 100px;
  371. line-height: 100px;
  372. font-size: 70px;
  373. color: #ffffff;
  374. text-align: center;
  375. font-weight: 500;
  376. font-family: PingFang SC, PingFang SC-Medium;
  377. background-image: url(./image/bar.png);
  378. }
  379. .border1 {
  380. width: 100%;
  381. height: 10px;
  382. background: #00ffff;
  383. }
  384. .content {
  385. position: relative;
  386. width: 100%;
  387. height: 930px;
  388. background-image: url(./image/bg.png);
  389. background-size: 100% 100%;
  390. }
  391. .con-info {
  392. padding-top: 50px;
  393. width: 100%;
  394. height: 300px;
  395. }
  396. .con-info-index {
  397. float: left;
  398. margin: 25px;
  399. width: 250px;
  400. height: 250px;
  401. text-align: center;
  402. line-height: 250px;
  403. font-size: 150px;
  404. font-family: DIN, DIN-Regular;
  405. color: #ffffff;
  406. border-radius: 50%;
  407. background: #ff0000;
  408. }
  409. .con-info-name {
  410. float: left;
  411. margin-right: 65px;
  412. width: 750px;
  413. height: 300px;
  414. line-height: 300px;
  415. font-size: 120px;
  416. color: #ffffff;
  417. font-family: PingFang SC, PingFang SC-Regular;
  418. font-weight: 400;
  419. text-align: left;
  420. }
  421. .con-info-state {
  422. float: left;
  423. width: 780px;
  424. height: 300px;
  425. }
  426. .con-info-state-icon {
  427. float: left;
  428. padding: 75px 0 55px 0;
  429. width: 170px;
  430. height: 170px;
  431. }
  432. .con-info-state-icon>img {
  433. width: 100%;
  434. height: 100%;
  435. }
  436. .con-info-state-text {
  437. float: left;
  438. width: 610px;
  439. height: 300px;
  440. line-height: 300px;
  441. text-align: center;
  442. font-size: 150px;
  443. font-weight: 400;
  444. }
  445. .con-state {
  446. display: none;
  447. margin-top: 70px;
  448. margin-left: 650px;
  449. width: 1000px;
  450. height: 300px;
  451. }
  452. .con-state-icon {
  453. float: left;
  454. padding: 80px 0 60px 0;
  455. width: 160px;
  456. height: 160px;
  457. }
  458. .con-state-icon>img {
  459. width: 100%;
  460. height: 100%;
  461. }
  462. .con-state-text {
  463. margin-left: 10px;
  464. float: left;
  465. width: 610px;
  466. height: 300px;
  467. line-height: 300px;
  468. color: #00ffff;
  469. text-align: left;
  470. font-size: 150px;
  471. font-weight: 400;
  472. }
  473. .con-now {
  474. padding-left: 500px;
  475. margin-top: 120px;
  476. height: 200px;
  477. font-size: 130px;
  478. line-height: 200px;
  479. font-family: Alibaba PuHuiTi, Alibaba PuHuiTi-Regular;
  480. font-weight: 400;
  481. color: #ffffff;
  482. }
  483. .con-wait {
  484. padding-left: 500px;
  485. margin-top: 40px;
  486. height: 200px;
  487. font-size: 130px;
  488. line-height: 200px;
  489. font-family: Alibaba PuHuiTi, Alibaba PuHuiTi-Regular;
  490. font-weight: 400;
  491. color: #ffffff;
  492. }
  493. </style>