index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>森之洋</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <!--标准mui.css-->
  10. <link rel="stylesheet" type="text/css" href="css/mui.min.css">
  11. <!--App自定义的css-->
  12. <link rel="stylesheet" type="text/css" href="css/app.css" />
  13. <style>
  14. .mui-btn-block {
  15. margin-bottom: 0;
  16. }
  17. .mui-content-padded {
  18. margin: 2px;
  19. }
  20. .mui-col {
  21. display: inline-block;
  22. padding: 2px;
  23. }
  24. /*滚动条样式*/
  25. ::-webkit-scrollbar {
  26. width: 10px;
  27. background-color: #F5F5F5;
  28. }
  29. /*定义滚动条轨道 内阴影+圆角*/
  30. ::-webkit-scrollbar-track {
  31. background-color: #103643;
  32. }
  33. /*定义滑块 内阴影+圆角*/
  34. ::-webkit-scrollbar-thumb {
  35. background-color: #0b6d78;
  36. }
  37. .mui-btn-royal {
  38. background-color: rgba(141, 157, 199, 0.5);
  39. border: 1px solid rgba(141, 157, 199, 0.5)
  40. }
  41. .active {
  42. background-color: #d4d4d4;
  43. color: white;
  44. }
  45. .up {
  46. background: #0087c5 url(img/top.svg) no-repeat 50% 10%;
  47. }
  48. .down {
  49. background: #0087c5 url(img/bottom.svg) no-repeat 50% 10%;
  50. }
  51. .text-success {
  52. color: #27c24c
  53. }
  54. .mui-col-xs-3 {
  55. width: 23%;
  56. }
  57. .mui-col-xs-2 {
  58. width: 23%;
  59. }
  60. </style>
  61. </head>
  62. <body style="background: url(img/bg.png) no-repeat 0px 0px">
  63. <div class="mui-content" style="background: #2e3342;background-color: rgba(255,255,255,0)">
  64. <div class="mui-content-padded">
  65. <div class="mui-row">
  66. <div class="mui-col mui-col-xs-12">
  67. <span id="agvstatus" style="position: fixed;">·</span>
  68. <div id="title"
  69. style="text-align: center;padding-bottom: 2px;background: url(img/title_bg.png) no-repeat 0 7px;background-size:100%;">
  70. <a style="color: #FFFFFF;font-size: 20px;">森之洋</a>
  71. </div>
  72. </div>
  73. <div class="mui-col mui-col-xs-12" id="btt"
  74. style="min-height:490px;overflow-y:auto;max-height:490px;">
  75. <div class="mui-col mui-col-xs-12"
  76. style="height: 235px;text-align: center;background: url(img/top_bg2.png) no-repeat 0 -10px;background-size:100%;">
  77. <!-- <div class="mui-col mui-col-xs-12" style="height: 235px;text-align: center;background: url(img/top_bg2.png) no-repeat 0 0;background-size:100%;"> -->
  78. <div class="mui-col mui-col-xs-12" style="padding-top: 10px;height: 30px;">
  79. <div style=" width: 50%;float: left;">
  80. <img id="speed" src="" style="margin-left: -80px;width: 13%;">
  81. </div>
  82. <div style=" width: 50%;float: left;">
  83. <img id="battery" src="img/battery-100.png" style="margin-right: -80px;width: 23%;">
  84. </div>
  85. </div>
  86. <div class="mui-col mui-col-xs-12" style="margin-top: -5px;">
  87. <div id="tgts"
  88. style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: left;margin-left: 23px;">
  89. <div style="margin-left: -60px;margin-top: 15px;">
  90. <a style="color: #FFFFFF;font-size: 18px;">目标</a><br>
  91. </div>
  92. <div style="margin-left: -60px;margin-top: 10px;">
  93. <a style="color: #FFFFFF;font-size: 18px;">站点</a><br>
  94. </div>
  95. <div style="margin-left: 40px;margin-top: -35px;">
  96. <a id="tgtstation" style="color: #FFFFFF;font-size: 50px;"></a><br>
  97. </div>
  98. </div>
  99. <div id="jack"
  100. style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: right;margin-right: 20px;">
  101. <div style="margin-left: -60px;margin-top: 15px;">
  102. <a style="color: #FFFFFF;font-size: 18px;">顶升</a><br>
  103. </div>
  104. <div style="margin-left: -60px;margin-top: 10px;">
  105. <a style="color: #FFFFFF;font-size: 18px;">状态</a><br>
  106. </div>
  107. <div style="margin-left: 50px;margin-top: -53px;">
  108. <img id="liftstatus" src="img/liftstatus.png" width="60%">
  109. </div>
  110. </div>
  111. </div>
  112. <div class="mui-col mui-col-xs-12"
  113. style="height: 40px;padding-left: 15px;margin-top: -5px;">
  114. <div id="stop"
  115. style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">
  116. 停止</div>
  117. <div id="run"
  118. style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">
  119. 运行</div>
  120. <div id="warning"
  121. style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">
  122. 注意</div>
  123. </div>
  124. <div class="mui-col mui-col-xs-12">
  125. <div id="info"
  126. style="width: 89%;height: 30px;margin-left: 19px;color:#fff;font-size:15px;line-height: 30px;background-color: #0b6d78;border-radius: 3px;text-align: center;padding-left: 5px;">
  127. </div>
  128. </div>
  129. </div>
  130. <div class="mui-col mui-col-xs-12" style="margin-top: -5px;">
  131. <div class="mui-col mui-col-xs-12">
  132. <div id="workstatus"
  133. style="margin-top: -15px;width: 89%;height: 55px;line-height: 55px;margin-left: 19px;color:#fff;font-size:15px;background-color: #0b6d78;border-radius: 3px;text-align: center;padding-left: 5px;">
  134. 前序工作状态:<span id="status"></span>
  135. </div>
  136. </div>
  137. <div id="btlist" style="padding-left: 15px;padding-right: 15px;height:175px">
  138. <div class="mui-col mui-col-xs-12 client" style="padding-top:10px">
  139. <button type="button" class="mui-btn mui-btn-primary mui-btn-block mui-hidden"
  140. id="Call"></button>
  141. </div>
  142. <div id="Caches" class="mui-col mui-col-xs-12 client mui-hidden" style="padding-top:10px">
  143. <button type="button" class="mui-btn mui-btn-primary mui-btn-block"
  144. id="Cache">缓存工位</button>
  145. </div>
  146. <div class="mui-col mui-col-xs-12 client" style="padding-top:10px">
  147. <button type="button" class="mui-btn mui-btn-success mui-btn-block mui-hidden"
  148. id="Finish">完成</button>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <div class="mui-col mui-col-xs-12" style="text-align:center;margin-top: 5px;">
  154. <div class="mui-col mui-col-xs-2">
  155. <a href="settings.html" style="color: #9fb3b4;"><span
  156. class="mui-icon mui-icon-settings"></span></a>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </body>
  163. <script src="js/jquery.min.js"></script>
  164. <script src="js/msg.js"></script>
  165. <script src="js/mui.min.js"></script>
  166. <script type="text/javascript">
  167. var $btlist = $('#btlist');
  168. let ip, url, agvid, mapid, site, AcceptId, msgAcceptId;
  169. $(function() {
  170. //获取保存的ip、agvid、mapid等,如果没有数据,则设置为默认
  171. if (localStorage.getItem("ip") == "" || localStorage.getItem("ip") == null) {
  172. ip = "192.168.111.240:8888";
  173. url = "http://192.168.111.240:8888"
  174. } else {
  175. ip = localStorage.getItem("ip") + ":8888";
  176. url = "http://" + localStorage.getItem("ip") + ":8888";
  177. }
  178. if (localStorage.getItem("agvid") == "" || localStorage.getItem("agvid") == null) {
  179. agvid = 1;
  180. } else {
  181. agvid = parseInt(localStorage.getItem("agvid"))
  182. }
  183. if (localStorage.getItem("mapid") == "" || localStorage.getItem("mapid") == null) {
  184. mapid = "2020032608412704";
  185. } else {
  186. mapid = localStorage.getItem("mapid")
  187. }
  188. if (localStorage.getItem("site") == "" || localStorage.getItem("site") == null) {
  189. site = ""
  190. $("#Call").addClass("mui-hidden");
  191. } else {
  192. site = localStorage.getItem("site");
  193. $("#Call").removeClass("mui-hidden");
  194. $("#Call").html(site);
  195. if (site == "下料工位") {
  196. // 缓存工位按钮
  197. $("#Caches").removeClass("mui-hidden")
  198. } else {
  199. $("#Caches").addClass("mui-hidden")
  200. }
  201. }
  202. AcceptId = localStorage.getItem("AcceptId")
  203. $("#Finish").attr("disabled", true);
  204. startLog();
  205. setInterval(function() {
  206. if (ws.readyState === 3) {
  207. startLog();
  208. }
  209. }, 1000);
  210. })
  211. //完成按钮
  212. $("#Finish").click(function() {
  213. DoneTermTask(agvid, AcceptId, function(d) {
  214. if (d == "ok") {
  215. mui.toast("任务发送成功...")
  216. } else {
  217. if (d == "") {
  218. if (msgAcceptId === AcceptId) {
  219. mui.toast("当前工位任务执行中...")
  220. }
  221. if (msgAcceptId == (AcceptId - 1)) {
  222. mui.toast("前序工位任务执行中...")
  223. }
  224. }
  225. mui.toast("请稍后重试...")
  226. }
  227. })
  228. })
  229. //缓存工位
  230. $("#Cache").click(function() {
  231. let from, to;
  232. from = 3;
  233. to = 4;
  234. AddTermTask(agvid, AcceptId, from, to, function(d) {
  235. if (d == "ok") {
  236. mui.toast("任务发送成功...")
  237. } else {
  238. mui.toast("请稍后重试...")
  239. }
  240. })
  241. });
  242. //上下箱工位、清扫工位、下料工位
  243. $("#Call").click(function() {
  244. let from, to;
  245. if (site === "上下箱工位") {
  246. from = 4;
  247. to = 1;
  248. }
  249. if (site === "清扫工位") {
  250. from = 1;
  251. to = 2;
  252. }
  253. if (site === "下料工位") {
  254. from = 2;
  255. to = 3;
  256. }
  257. AddTermTask(agvid, AcceptId, from, to, function(d) {
  258. if (d == "ok") {
  259. mui.toast("任务发送成功...")
  260. } else {
  261. mui.toast("请稍后重试...")
  262. }
  263. })
  264. });
  265. function DoneTermTask(agvid, AcceptId, callback) {
  266. $.post(url + "/task/term/done", {
  267. id: agvid,
  268. acceptId: AcceptId
  269. }, callback);
  270. };
  271. function AddTermTask(agvid, AcceptId, from, to, callback) {
  272. $.post(url + "/task/term/send", {
  273. id: agvid,
  274. acceptId: AcceptId,
  275. from: from,
  276. to: to
  277. }, callback);
  278. };
  279. //新建ws连接,获取agv的状态
  280. let ws;
  281. function startLog() {
  282. ws = new WebSocket("ws://" + ip + "/ws/msg/" + agvid);
  283. ws.onmessage = function(e) {
  284. let result;
  285. let msg = JSON.parse(e.data);
  286. // console.log("msg",msg)
  287. switch (msg.type) {
  288. case msgTypeStatus:
  289. // 每秒一次状态
  290. let stMap = JSON.parse(msg.data);
  291. //根据状态设置图标等
  292. showStatusValue(stMap);
  293. //当前站点按钮文字闪烁
  294. if (agvid == msg.id) {
  295. let stMap = JSON.parse(msg.data);
  296. $("#agvstatus").toggleClass("text-success");
  297. }
  298. // 当前工作站点id
  299. msgAcceptId = stMap.AcceptId;
  300. if (msgAcceptId == AcceptId) {
  301. $("#Finish").removeClass("mui-hidden");
  302. $("#Finish").attr("disabled", false);
  303. } else {
  304. $("#Finish").addClass("mui-hidden");
  305. $("#Finish").attr("disabled", true);
  306. }
  307. if ((msgAcceptId == 1 && AcceptId == 2) || (msgAcceptId == 2 && AcceptId == 3) || (msgAcceptId ==
  308. 3 && AcceptId == 1)) {
  309. $("#status").html("工作中", +msgAcceptId);
  310. document.getElementById("workstatus").style.backgroundColor = "red"; // "#9C9C9C" ;// ;
  311. } else {
  312. $("#status").html("未工作");
  313. document.getElementById("workstatus").style.backgroundColor = "green"; // "#9C9C9C" ;//
  314. }
  315. break;
  316. //读取设置状态,可以获得电池伏数
  317. case msgTypeGetCfg:
  318. //console.log(msg.type, msg.data);
  319. break;
  320. default:
  321. //console.log(msg.type, msg.data);
  322. }
  323. }
  324. }
  325. //根据获取到的agv状态,设置速度、电量、站点、顶升、提示信息、运行按钮等的颜色和文字显示
  326. function showStatusValue(status) {
  327. for (let k in status) {
  328. let v = status[k];
  329. //电量显示
  330. if (k == "BatteryVolt") {
  331. if (v >= 5200) { //BatteryVoltFull
  332. document.getElementById("battery").src = "img/battery-100.png";
  333. }
  334. if (5000 <= v && v < 5200) { //BatteryVoltHigh
  335. document.getElementById("battery").src = "img/battery-80.png";
  336. }
  337. if (4800 <= v && v < 5000) { //BatteryVoltMid
  338. document.getElementById("battery").src = "img/battery-60.png";
  339. }
  340. if (4700 <= v && v < 4800) { //BatteryVoltLow
  341. document.getElementById("battery").src = "img/battery-40.png";
  342. }
  343. if (4500 <= v && v < 4700) { //BatteryVoltWarn
  344. document.getElementById("battery").src = "img/battery-20.png";
  345. }
  346. if (v <= 4500) { //BatteryVoltStop
  347. document.getElementById("battery").src = "img/battery-0.png";
  348. }
  349. }
  350. //目标站点
  351. if (k == "TgtStation") {
  352. if (v == "65535") {
  353. $("#tgtstation").text("0");
  354. } else {
  355. $("#tgtstation").text(v);
  356. }
  357. }
  358. //顶升状态
  359. if (k == "LiftStatus") {
  360. if (v == 1 || v == 3 || v == 5 || v == 7) {
  361. document.getElementById("liftstatus").src = "img/liftstatus-up.png";
  362. } else if (v == 0) {
  363. document.getElementById("liftstatus").src = "img/liftstatus.png";
  364. } else {
  365. if (status.Status == "1") {
  366. document.getElementById("liftstatus").src = "img/liftstatus.png";
  367. } else {
  368. document.getElementById("liftstatus").src = "img/liftstatus-down.png";
  369. }
  370. }
  371. }
  372. //停止运行注意按钮及信息提示框
  373. if (k == "Status") {
  374. document.getElementById("speed").src = "";
  375. if (v == 0) {
  376. $("#info").text("未设置");
  377. }
  378. if (v == 1) {
  379. $("#info").text("就绪");
  380. }
  381. if (v == 2) {
  382. $("#info").text("运行");
  383. document.getElementById("speed").src = "img/speed-high.png";
  384. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  385. } else {
  386. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  387. }
  388. if (v == 3 || v == 4 || (v == 5)) {
  389. if (v == 3) {
  390. $("#info").text("停止");
  391. }
  392. if (v == 4) {
  393. $("#info").text("急停");
  394. }
  395. if (v == 5) {
  396. $("#info").text("防撞停止");
  397. }
  398. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  399. } else {
  400. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  401. }
  402. if (v == 6) {
  403. $("#info").text("驱动器错误");
  404. }
  405. if (v == 7) {
  406. $("#info").text("导航错误");
  407. }
  408. if (v == 8) {
  409. $("#info").text("任务错误");
  410. }
  411. if (v == 9) {
  412. document.getElementById("speed").src = "img/speed-medium.png";
  413. $("#info").text("手动控制");
  414. }
  415. if (v == 11 || v == 22) {
  416. if (v == 11) {
  417. document.getElementById("speed").src = "img/speed-medium.png";
  418. $("#info").text("前方障碍");
  419. }
  420. if (v == 22) {
  421. document.getElementById("speed").src = "img/speed-medium.png";
  422. $("#info").text("障碍减速");
  423. }
  424. document.getElementById("warning").style.backgroundImage = "url('img/btn1_bg.png')";
  425. } else {
  426. document.getElementById("warning").style.backgroundImage = "url('img/btn4_bg.png')";
  427. }
  428. if (v == 12) {
  429. $("#info").text("防撞停止");
  430. }
  431. if (v == 15) {
  432. $("#info").text("低电压停止");
  433. }
  434. if (v == 21) {
  435. $("#info").text("低电压运行");
  436. }
  437. if (v == 31) {
  438. $("#info").text("前磁导脱线");
  439. }
  440. if (v == 32) {
  441. $("#info").text("后磁导脱线");
  442. }
  443. if (v == 33) {
  444. $("#info").text("左磁导脱线");
  445. }
  446. if (v == 34) {
  447. $("#info").text("右磁导脱线");
  448. }
  449. if (v == 71) {
  450. $("#info").text("取货失败1");
  451. }
  452. if (v == 72) {
  453. $("#info").text("取货失败2");
  454. }
  455. if (v == 73) {
  456. $("#info").text("放货失败");
  457. }
  458. }
  459. }
  460. if (status.Status == "9" && status.FWlkRpm != "0") {
  461. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  462. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  463. }
  464. if (status.Status == "9" && status.FWlkRpm == "0") {
  465. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  466. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  467. }
  468. };
  469. $(function() {
  470. GetTermTask(agvid, function(d) {
  471. console.log("GetTermTask: ", d)
  472. })
  473. })
  474. function GetTermTask(agvid, callback) {
  475. $.post(url + "/task/term/get", {
  476. id: agvid,
  477. }, callback);
  478. }
  479. </script>
  480. </html>