index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>华力机电SIMANC</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: 0;
  27. background-color: #F5F5F5;
  28. }
  29. .mui-btn-royal {
  30. background-color: rgba(141, 157, 199, 0.5);
  31. border: 1px solid rgba(141, 157, 199, 0.5)
  32. }
  33. .active {
  34. background-color: #d4d4d4;
  35. color: white;
  36. }
  37. .up {
  38. background: #0087c5 url(img/top.svg) no-repeat 50% 10%;
  39. }
  40. .down {
  41. background: #0087c5 url(img/bottom.svg) no-repeat 50% 10%;
  42. }
  43. .text-success {
  44. color: #27c24c
  45. }
  46. .mui-col-xs-3 {
  47. width: 24%;
  48. }
  49. </style>
  50. </head>
  51. <body style="background: url(img/bg.png) no-repeat 0px 0px">
  52. <div class="mui-content" style="background: #2e3342;background-color: rgba(255,255,255,0)">
  53. <div class="mui-content-padded">
  54. <div class="mui-row">
  55. <div class="mui-col mui-col-xs-12">
  56. <span id="agvstatus" style="position: fixed;">·</span>
  57. <div id="title" style="text-align: center;padding-bottom: 2px;background: url(img/title_bg.png) no-repeat 0 7px;background-size:100%;">
  58. <a style="color: #FFFFFF;font-size: 20px;">华力西曼克</a>
  59. </div>
  60. </div>
  61. <div class="mui-col mui-col-xs-12" id="btt" style="min-height:480px;overflow-y:auto;max-height:480px">
  62. <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%;">
  63. <div class="mui-col mui-col-xs-12" style="padding-top: 10px;height: 30px;">
  64. <div style=" width: 50%;float: left;">
  65. <img id="speed" src="" style="margin-left: -80px;width: 13%;">
  66. </div>
  67. <div style=" width: 50%;float: left;">
  68. <img id="battery" src="img/battery-100.png" style="margin-right: -80px;width: 23%;">
  69. </div>
  70. </div>
  71. <div class="mui-col mui-col-xs-12" style="margin-top: -5px;">
  72. <div id="tgts" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: left;margin-left: 23px;">
  73. <div style="margin-left: -60px;margin-top: 15px;">
  74. <a style="color: #FFFFFF;font-size: 18px;">目标</a><br>
  75. </div>
  76. <div style="margin-left: -60px;margin-top: 10px;">
  77. <a style="color: #FFFFFF;font-size: 18px;">站点</a><br>
  78. </div>
  79. <div style="margin-left: 40px;margin-top: -35px;">
  80. <a id="tgtstation" style="color: #FFFFFF;font-size: 50px;"></a><br>
  81. </div>
  82. </div>
  83. <div id="jack" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: right;margin-right: 20px;">
  84. <div style="margin-left: -60px;margin-top: 15px;">
  85. <a style="color: #FFFFFF;font-size: 18px;">顶升</a><br>
  86. </div>
  87. <div style="margin-left: -60px;margin-top: 10px;">
  88. <a style="color: #FFFFFF;font-size: 18px;">状态</a><br>
  89. </div>
  90. <div style="margin-left: 50px;margin-top: -53px;">
  91. <img id="liftstatus" src="img/liftstatus.png" width="60%">
  92. </div>
  93. </div>
  94. </div>
  95. <div class="mui-col mui-col-xs-12" style="height: 40px;padding-left: 15px;margin-top: -5px;">
  96. <div id="stop" style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">停止</div>
  97. <div id="run" style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">运行</div>
  98. <div id="warning" style="width: 30%;height: 40px;line-height:40px;float: left;margin-left: 5px;background: url(img/btn4_bg.png);color: #FFFFFF;text-align: center;">注意</div>
  99. </div>
  100. <div class="mui-col mui-col-xs-12">
  101. <div id="info" style="width: 89%;height: 35px;margin-left: 19px;color:#fff;font-size:15px;line-height: 30px;background-color: #0b6d78;border-radius: 3px;text-align: center;padding-left: 5px;"></div>
  102. </div>
  103. </div>
  104. <div class="mui-col mui-col-xs-12" style="margin-top: -5px;">
  105. <div id="btlist" style="padding-left: 15px;height:190px">
  106. </div>
  107. </div>
  108. </div>
  109. <div class="mui-col mui-col-xs-12" style="text-align:center;margin-top: 10px;">
  110. <div class="mui-col mui-col-xs-3" id="gomoving">
  111. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="moving" style="border:1px solid #4a5a6a;">移动</button>
  112. </div>
  113. <div class="mui-col mui-col-xs-3" id="gostart">
  114. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="start" style="border:1px solid #4a5a6a;">搬运</button>
  115. </div>
  116. <div class="mui-col mui-col-xs-3">
  117. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="cancel" style="border:1px solid #4a5a6a;">取消</button>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </body>
  124. <script src="js/jquery.min.js"></script>
  125. <script src="js/msg.js"></script>
  126. <script src="js/Sortable.min.js"></script>
  127. <script type="text/javascript">
  128. var $btlist = $('#btlist');
  129. $(function() {
  130. //获取保存的ip、agvid、mapid等,如果没有数据,则设置为默认
  131. if (localStorage.getItem("ip") == "" || localStorage.getItem("ip") == null) {
  132. ip = "192.168.0.200:8888";
  133. url = "http://192.168.0.200:8888"
  134. } else {
  135. ip = localStorage.getItem("ip") + ":8888";
  136. url = "http://" + localStorage.getItem("ip") + ":8888";
  137. }
  138. if (localStorage.getItem("agvid") == "" || localStorage.getItem("agvid") == null) {
  139. agvid = 1;
  140. } else {
  141. agvid = parseInt(localStorage.getItem("agvid"))
  142. }
  143. if (localStorage.getItem("mapid") == "" || localStorage.getItem("mapid") == null) {
  144. mapid = "2020032608412704";
  145. } else {
  146. mapid = localStorage.getItem("mapid")
  147. }
  148. //获取按钮
  149. createList();
  150. //获取状态
  151. startLog();
  152. setInterval(function() {
  153. if (ws.readyState === 3) {
  154. startLog();
  155. }
  156. }, 1000);
  157. //设置操作按钮
  158. $("#gostart").addClass("mui-hidden");
  159. $("#moving").attr("disabled", true);
  160. $("#start").attr("disabled", true);
  161. $('#cancel').attr("disabled", true);
  162. //设置页面可以左滑右滑跳转页面
  163. var windowHeight = $(window).height(),
  164. $body = $("body");
  165. $("body").on("touchstart", function(e) {
  166. e.preventDefault();
  167. startX = e.originalEvent.changedTouches[0].pageX,
  168. startY = e.originalEvent.changedTouches[0].pageY;
  169. });
  170. $("body").on("touchmove", function(e) {
  171. e.preventDefault();
  172. moveEndX = e.originalEvent.changedTouches[0].pageX,
  173. moveEndY = e.originalEvent.changedTouches[0].pageY,
  174. X = moveEndX - startX,
  175. Y = moveEndY - startY;
  176. if (Math.abs(X) > Math.abs(Y) && X > 0) {
  177. window.location.href = "settings.html"; //right
  178. } else {
  179. //window.location.href = "tasklist.html"; //left
  180. return
  181. }
  182. });
  183. })
  184. //按钮点击事件
  185. function onSelectStation(evt) {
  186. var $this = $(this);
  187. if ($("div[id='btlist']").is(':active')) {
  188. $this.removeClass('active');
  189. } else {
  190. $this.addClass('active');
  191. }
  192. if ($("div[id='btlist']").find(".active").length == 1) {
  193. $("#moving").attr("disabled", false);
  194. $this.addClass('up');
  195. $("#start").removeAttr("disabled");
  196. $("#cancel").removeAttr("disabled");
  197. } else if ($("div[id='btlist']").find(".active").length == 2) {
  198. $("#gomoving").addClass("mui-hidden");
  199. $("#gostart").removeClass("mui-hidden");
  200. $this.addClass('down');
  201. $('#start').attr("disabled", false);
  202. $("#handling").removeAttr("disabled");
  203. }
  204. if ($("div[id='btlist']").find(".active").length >= 2) {
  205. $("button[name='stbtn']").css("pointer-events", "none")
  206. } else {
  207. $("button[name='stbtn']").css("pointer-events", "auto")
  208. }
  209. };
  210. //取消按钮操作
  211. function Reset(evt) {
  212. if ($("div[id='btlist']").find(".active")) {
  213. $("#gostart").addClass("mui-hidden");
  214. $("#gomoving").removeClass("mui-hidden");
  215. $("button[name='stbtn']").removeClass('up');
  216. $("button[name='stbtn']").removeClass('down');
  217. $("button[name='stbtn']").removeClass('active');
  218. $("button[name='stbtn']").css("pointer-events", "auto");
  219. $('#start').attr("disabled", true);
  220. $('#cancel').attr("disabled", true);
  221. $('#moving').attr("disabled", true);
  222. }
  223. }
  224. //移动按钮
  225. $("#moving").click(function() {
  226. let to;
  227. $("div[id='btlist']").find(".up").each(function(evt) {
  228. to = parseInt(($(this).context).id);
  229. });
  230. SendCmd(agvid, msgTypeToStation, {
  231. "Stn": to
  232. }, function(d) {
  233. console.log("AddTransTask", d);
  234. Reset()
  235. })
  236. });
  237. //搬运按钮
  238. $("#start").click(function() {
  239. var bt_value = [];
  240. $("div[id='btlist']").find(".up").each(function(evt) {
  241. bt_value.push($(this).val());
  242. });
  243. $("div[id='btlist']").find(".down").each(function(evt) {
  244. bt_value.push($(this).val());
  245. });
  246. AddTransTask(agvid, bt_value[0], bt_value[1], function(d) {
  247. //console.log("AddTransTask", d);
  248. Reset()
  249. })
  250. });
  251. function AddTransTask(agvid, from, to, callback) {
  252. $.post(url + "/task", {
  253. id: agvid,
  254. from: from,
  255. to: to
  256. }, callback);
  257. };
  258. function SendCmd(agvid, cmd, opt, func) {
  259. let param = {
  260. "t": cmd
  261. };
  262. opt = _.extend(param, opt);
  263. //console.log("param", opt);
  264. $.post(url + "/agv/SendString/" + agvid,
  265. JSON.stringify(opt),
  266. func
  267. );
  268. }
  269. //取消按钮
  270. $("#cancel").on("click", Reset);
  271. //填充按钮列表
  272. function createList() {
  273. $.get(url + "/map/getStations/" + mapid, function(data) {
  274. IDARR = localStorage.getItem(mapid+agvid+"ARR");
  275. trs = "";
  276. if(IDARR == "" ||IDARR == undefined){
  277. ARRS = [];
  278. for (i in data) {
  279. if (data[i].Name != "" && data[i].Name != "rect") {
  280. var ids = data[i].Id - (agvid * 100)
  281. ARRS.push(parseInt(data[i].Id));
  282. trs += '<div class="mui-col mui-col-xs-3" drag-id="'+ids+'">' +
  283. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + ids +
  284. '" value="' + ids + '">' +
  285. data[i].Name + '</button></div>'
  286. }
  287. }
  288. ARR = ARRS.join(",");
  289. localStorage.setItem(mapid + agvid + 'ARR', ARR);
  290. } else {
  291. arr = IDARR.split(",");// 在每个逗号(,)处进行分解。
  292. var id_arr = arr.sort(function(a, b){return a - b});//按从小到大排序
  293. for (x in id_arr) {
  294. for (i in data) {
  295. if((data[i].Name != "") && data[i].Name != "rect"){
  296. var ids = data[i].Id - (agvid * 100)
  297. if ((data[i].Id == id_arr[x])) {
  298. trs += '<div class="mui-col mui-col-xs-3" drag-id="'+ids+'">' +
  299. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + ids +
  300. '" value="' + ids + '">' +
  301. data[i].Name + '</button></div>'
  302. }
  303. }
  304. }
  305. }
  306. }
  307. $btlist.append(trs);
  308. //注册按钮点击事件click touchstart
  309. $("button[name]").on("touchstart", onSelectStation);
  310. });
  311. }
  312. //新建ws连接,获取agv的状态
  313. let ws;
  314. function startLog() {
  315. ws = new WebSocket("ws://" + ip + "/ws/msg/" + agvid);
  316. ws.onmessage = function(e) {
  317. let result;
  318. let msg = JSON.parse(e.data);
  319. switch (msg.type) {
  320. case msgTypeStatus:
  321. // 每秒一次状态
  322. let stMap = JSON.parse(msg.data);
  323. //根据状态设置图标等
  324. showStatusValue(stMap);
  325. //当前站点按钮文字闪烁
  326. if (agvid == msg.id) {
  327. let stMap = JSON.parse(msg.data);
  328. $("#agvstatus").toggleClass("text-success");
  329. $(".mui-btn").removeClass("text-success");
  330. $("#" + stMap.Station + "").addClass("text-success");
  331. }
  332. break;
  333. //读取设置状态,可以获得电池伏数
  334. case msgTypeGetCfg:
  335. //console.log(msg.type, msg.data);
  336. break;
  337. default:
  338. //console.log(msg.type, msg.data);
  339. }
  340. };
  341. }
  342. //根据获取到的agv状态,设置速度、电量、站点、顶升、提示信息、运行按钮等的颜色和文字显示
  343. function showStatusValue(status) {
  344. for (let k in status) {
  345. let v = status[k];
  346. //电量显示
  347. if (k == "BatteryVolt") {
  348. if (v >= 5200) { //BatteryVoltFull
  349. document.getElementById("battery").src = "img/battery-100.png";
  350. }
  351. if (5000 <= v && v < 5200) { //BatteryVoltHigh
  352. document.getElementById("battery").src = "img/battery-80.png";
  353. }
  354. if (4800 <= v && v < 5000) { //BatteryVoltMid
  355. document.getElementById("battery").src = "img/battery-60.png";
  356. }
  357. if (4700 <= v && v < 4800) { //BatteryVoltLow
  358. document.getElementById("battery").src = "img/battery-40.png";
  359. }
  360. if (4500 <= v && v < 4700) { //BatteryVoltWarn
  361. document.getElementById("battery").src = "img/battery-20.png";
  362. }
  363. if (v <= 4500) { //BatteryVoltStop
  364. document.getElementById("battery").src = "img/battery-0.png";
  365. }
  366. }
  367. //目标站点
  368. if (k == "TgtStation") {
  369. if (v == "65535") {
  370. $("#tgtstation").text("0");
  371. } else {
  372. $("#tgtstation").text(v);
  373. }
  374. }
  375. //顶升状态
  376. if (k == "LiftStatus") {
  377. if (v == 1 || v == 3 || v == 5 || v == 7) {
  378. document.getElementById("liftstatus").src = "img/liftstatus-up.png";
  379. } else if (v == 0) {
  380. document.getElementById("liftstatus").src = "img/liftstatus.png";
  381. } else {
  382. if (status.Status == "1") {
  383. document.getElementById("liftstatus").src = "img/liftstatus.png";
  384. } else {
  385. document.getElementById("liftstatus").src = "img/liftstatus-down.png";
  386. }
  387. }
  388. }
  389. //停止运行注意按钮及信息提示框
  390. if (k == "Status") {
  391. document.getElementById("speed").src = "";
  392. if (v == 0) {
  393. $("#info").text("未设置");
  394. }
  395. if (v == 1) {
  396. $("#info").text("就绪");
  397. }
  398. if (v == 2) {
  399. $("#info").text("运行");
  400. document.getElementById("speed").src = "img/speed-high.png";
  401. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  402. } else {
  403. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  404. }
  405. if (v == 3 || v == 4 ||(v == 5)) {
  406. if (v == 3) {
  407. $("#info").text("停止");
  408. }
  409. if (v == 4) {
  410. $("#info").text("急停");
  411. }
  412. if (v == 5) {
  413. $("#info").text("刹车");
  414. }
  415. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  416. } else {
  417. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  418. }
  419. if (v == 6) {
  420. $("#info").text("驱动器错误");
  421. }
  422. if (v == 7) {
  423. $("#info").text("导航错误");
  424. }
  425. if (v == 8) {
  426. $("#info").text("任务错误");
  427. }
  428. if (v == 9) {
  429. document.getElementById("speed").src = "img/speed-medium.png";
  430. $("#info").text("手动控制");
  431. }
  432. if (v == 11 || v == 22) {
  433. if (v == 11) {
  434. document.getElementById("speed").src = "img/speed-medium.png";
  435. $("#info").text("前方障碍");
  436. }
  437. if (v == 22) {
  438. document.getElementById("speed").src = "img/speed-medium.png";
  439. $("#info").text("障碍减速");
  440. }
  441. document.getElementById("warning").style.backgroundImage = "url('img/btn1_bg.png')";
  442. } else {
  443. document.getElementById("warning").style.backgroundImage = "url('img/btn4_bg.png')";
  444. }
  445. if (v == 12) {
  446. $("#info").text("防撞停止");
  447. }
  448. if (v == 15) {
  449. $("#info").text("低电压停止");
  450. }
  451. if (v == 21) {
  452. $("#info").text("低电压运行");
  453. }
  454. if (v == 31) {
  455. $("#info").text("前磁导脱线");
  456. }
  457. if (v == 32) {
  458. $("#info").text("后磁导脱线");
  459. }
  460. if (v == 33) {
  461. $("#info").text("左磁导脱线");
  462. }
  463. if (v == 34) {
  464. $("#info").text("右磁导脱线");
  465. }
  466. if (v == 71) {
  467. $("#info").text("取货失败1");
  468. }
  469. if (v == 72) {
  470. $("#info").text("取货失败2");
  471. }
  472. if (v == 73) {
  473. $("#info").text("放货失败");
  474. }
  475. }
  476. }
  477. if (status.Status == "9" && status.FWlkRpm != "0") {
  478. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  479. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  480. }
  481. if (status.Status == "9" && status.FWlkRpm == "0") {
  482. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  483. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  484. }
  485. };
  486. </script>
  487. </html>