index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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: 5px;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" style="height: 245px;text-align: center;background: url(img/top_bg.png) no-repeat 0 0;background-size:100%;">
  62. <div class="mui-col mui-col-xs-12" style="padding-top: 10px;height: 30px;">
  63. <div style=" width: 50%;float: left;">
  64. <img id="speed" src="" style="margin-left: -80px;width: 13%;">
  65. </div>
  66. <div style=" width: 50%;float: left;">
  67. <img id="battery" src="img/battery-100.png" style="margin-right: -80px;width: 23%;">
  68. </div>
  69. </div>
  70. <div class="mui-col mui-col-xs-12">
  71. <div id="tgts" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: left;margin-left: 23px;">
  72. <div style="margin-left: -60px;margin-top: 15px;">
  73. <a style="color: #FFFFFF;font-size: 18px;">目标</a><br>
  74. </div>
  75. <div style="margin-left: -60px;margin-top: 10px;">
  76. <a style="color: #FFFFFF;font-size: 18px;">站点</a><br>
  77. </div>
  78. <div style="margin-left: 40px;margin-top: -35px;">
  79. <a id="tgtstation" style="color: #FFFFFF;font-size: 50px;"></a><br>
  80. </div>
  81. </div>
  82. <div id="jack" style="width: 120px;height:90px;border-radius: 12px;border: 2px solid #298890;float: right;margin-right: 20px;">
  83. <div style="margin-left: -60px;margin-top: 15px;">
  84. <a style="color: #FFFFFF;font-size: 18px;">顶升</a><br>
  85. </div>
  86. <div style="margin-left: -60px;margin-top: 10px;">
  87. <a style="color: #FFFFFF;font-size: 18px;">状态</a><br>
  88. </div>
  89. <div style="margin-left: 50px;margin-top: -53px;">
  90. <img id="liftstatus" src="img/liftstatus.png" width="60%">
  91. </div>
  92. </div>
  93. </div>
  94. <div class="mui-col mui-col-xs-12" style="height: 40px;padding-left: 15px;">
  95. <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>
  96. <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>
  97. <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>
  98. </div>
  99. <div class="mui-col mui-col-xs-12">
  100. <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>
  101. </div>
  102. </div>
  103. <div class="mui-col mui-col-xs-12" style="background: url(img/btlist6_bg.png) no-repeat 10px 0;margin-top: 5px;">
  104. <div id="btlist" style="padding:5px 0 0 15px;min-height:190px;overflow-y:auto;max-height:190px">
  105. </div>
  106. </div>
  107. <div class="mui-col mui-col-xs-12" style="text-align: center;margin: 22px 0 0 0;">
  108. <div class="mui-col mui-col-xs-3" id="gomoving">
  109. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="moving" style="border:1px solid #4a5a6a;">移动</button>
  110. </div>
  111. <div class="mui-col mui-col-xs-3" id="gostart">
  112. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="start" style="border:1px solid #4a5a6a;">搬运</button>
  113. </div>
  114. <div class="mui-col mui-col-xs-3">
  115. <button type="button" class="mui-btn mui-btn-royal mui-btn-block operation" id="cancel" style="border:1px solid #4a5a6a;">取消</button>
  116. </div>
  117. </div>
  118. <div class="mui-col mui-col-xs-12" style="padding: 0;border-bottom:0px solid #525663;">
  119. <div style="height: 25px;background: url(img/bottom_bg.png) no-repeat 0 10px;"></div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </body>
  125. <script src="js/jquery.min.js"></script>
  126. <script src="js/msg.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. trs = "";
  275. for (i in data) {
  276. if (data[i].Name != "" && data[i].Name != "rect") {
  277. trs += '<div class="mui-col mui-col-xs-3" drag-id="' + data[i].Id + '">' +
  278. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + data[i].Id +
  279. '" value="' + data[i].Id + '">' +
  280. data[i].Name + '</button></div>'
  281. }
  282. }
  283. $btlist.append(trs);
  284. //注册按钮点击事件click touchstart
  285. $("button[name]").on("click", onSelectStation);
  286. });
  287. }
  288. //新建ws连接,获取agv的状态
  289. let ws;
  290. function startLog() {
  291. ws = new WebSocket("ws://" + ip + "/ws/msg/" + agvid);
  292. ws.onmessage = function(e) {
  293. let result;
  294. let msg = JSON.parse(e.data);
  295. switch (msg.type) {
  296. case msgTypeStatus:
  297. // 每秒一次状态
  298. let stMap = JSON.parse(msg.data);
  299. //根据状态设置图标等
  300. showStatusValue(stMap);
  301. //当前站点按钮文字闪烁
  302. if (agvid == msg.id) {
  303. let stMap = JSON.parse(msg.data);
  304. $("#agvstatus").toggleClass("text-success");
  305. $(".mui-btn").removeClass("text-success");
  306. $("#" + stMap.Station + "").addClass("text-success");
  307. }
  308. break;
  309. //读取设置状态,可以获得电池伏数
  310. case msgTypeGetCfg:
  311. //console.log(msg.type, msg.data);
  312. break;
  313. default:
  314. //console.log(msg.type, msg.data);
  315. }
  316. };
  317. }
  318. //根据获取到的agv状态,设置速度、电量、站点、顶升、提示信息、运行按钮等的颜色和文字显示
  319. function showStatusValue(status) {
  320. for (let k in status) {
  321. let v = status[k];
  322. //电量显示
  323. if (k == "BatteryVolt") {
  324. if (v >= 5200) { //BatteryVoltFull
  325. document.getElementById("battery").src = "img/battery-100.png";
  326. }
  327. if (5000 <= v && v < 5200) { //BatteryVoltHigh
  328. document.getElementById("battery").src = "img/battery-80.png";
  329. }
  330. if (4800 <= v && v < 5000) { //BatteryVoltMid
  331. document.getElementById("battery").src = "img/battery-60.png";
  332. }
  333. if (4700 <= v && v < 4800) { //BatteryVoltLow
  334. document.getElementById("battery").src = "img/battery-40.png";
  335. }
  336. if (4500 <= v && v < 4700) { //BatteryVoltWarn
  337. document.getElementById("battery").src = "img/battery-20.png";
  338. }
  339. if (v <= 4500) { //BatteryVoltStop
  340. document.getElementById("battery").src = "img/battery-0.png";
  341. }
  342. }
  343. //目标站点
  344. if (k == "TgtStation") {
  345. if (v == "65535") {
  346. $("#tgtstation").text("0");
  347. } else {
  348. $("#tgtstation").text(v);
  349. }
  350. }
  351. //顶升状态
  352. if (k == "LiftStatus") {
  353. if (v == 1 || v == 3 || v == 5 || v == 7) {
  354. document.getElementById("liftstatus").src = "img/liftstatus-up.png";
  355. } else if (v == 0) {
  356. document.getElementById("liftstatus").src = "img/liftstatus.png";
  357. } else {
  358. if (status.Status == "1") {
  359. document.getElementById("liftstatus").src = "img/liftstatus.png";
  360. } else {
  361. document.getElementById("liftstatus").src = "img/liftstatus-down.png";
  362. }
  363. }
  364. }
  365. //停止运行注意按钮及信息提示框
  366. if (k == "Status") {
  367. document.getElementById("speed").src = "";
  368. if (v == 0) {
  369. $("#info").text("未设置");
  370. }
  371. if (v == 1) {
  372. $("#info").text("就绪");
  373. }
  374. if (v == 2) {
  375. $("#info").text("运行");
  376. document.getElementById("speed").src = "img/speed-high.png";
  377. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  378. } else {
  379. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  380. }
  381. if (v == 3 || v == 4 ||(v == 5)) {
  382. if (v == 3) {
  383. $("#info").text("停止");
  384. }
  385. if (v == 4) {
  386. $("#info").text("急停");
  387. }
  388. if (v == 5) {
  389. $("#info").text("刹车");
  390. }
  391. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  392. } else {
  393. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  394. }
  395. if (v == 6) {
  396. $("#info").text("驱动器错误");
  397. }
  398. if (v == 7) {
  399. $("#info").text("导航错误");
  400. }
  401. if (v == 8) {
  402. $("#info").text("任务错误");
  403. }
  404. if (v == 9) {
  405. document.getElementById("speed").src = "img/speed-medium.png";
  406. $("#info").text("手动控制");
  407. }
  408. if (v == 11 || v == 22) {
  409. if (v == 11) {
  410. document.getElementById("speed").src = "img/speed-medium.png";
  411. $("#info").text("前方障碍");
  412. }
  413. if (v == 22) {
  414. document.getElementById("speed").src = "img/speed-medium.png";
  415. $("#info").text("障碍减速");
  416. }
  417. document.getElementById("warning").style.backgroundImage = "url('img/btn1_bg.png')";
  418. } else {
  419. document.getElementById("warning").style.backgroundImage = "url('img/btn4_bg.png')";
  420. }
  421. if (v == 12) {
  422. $("#info").text("防撞停止");
  423. }
  424. if (v == 15) {
  425. $("#info").text("低电压停止");
  426. }
  427. if (v == 21) {
  428. $("#info").text("低电压运行");
  429. }
  430. if (v == 31) {
  431. $("#info").text("前磁导脱线");
  432. }
  433. if (v == 32) {
  434. $("#info").text("反磁导脱线");
  435. }
  436. if (v == 33) {
  437. $("#info").text("左磁导脱线");
  438. }
  439. if (v == 34) {
  440. $("#info").text("右磁导脱线");
  441. }
  442. if (v == 71) {
  443. $("#info").text("取货失败1");
  444. }
  445. if (v == 72) {
  446. $("#info").text("取货失败2");
  447. }
  448. if (v == 73) {
  449. $("#info").text("放货失败");
  450. }
  451. }
  452. }
  453. if (status.Status == "9" && status.FWlkRpm != "0") {
  454. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  455. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  456. }
  457. if (status.Status == "9" && status.FWlkRpm == "0") {
  458. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  459. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  460. }
  461. };
  462. </script>
  463. </html>