index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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 src="js/Sortable.min.js"></script>
  128. <script type="text/javascript">
  129. var $btlist = $('#btlist');
  130. $(function() {
  131. //获取保存的ip、agvid、mapid等,如果没有数据,则设置为默认
  132. if (localStorage.getItem("ip") == "" || localStorage.getItem("ip") == null) {
  133. ip = "192.168.0.200:8888";
  134. url = "http://192.168.0.200:8888"
  135. } else {
  136. ip = localStorage.getItem("ip") + ":8888";
  137. url = "http://" + localStorage.getItem("ip") + ":8888";
  138. }
  139. if (localStorage.getItem("agvid") == "" || localStorage.getItem("agvid") == null) {
  140. agvid = 1;
  141. } else {
  142. agvid = parseInt(localStorage.getItem("agvid"))
  143. }
  144. if (localStorage.getItem("mapid") == "" || localStorage.getItem("mapid") == null) {
  145. mapid = "2020032608412704";
  146. } else {
  147. mapid = localStorage.getItem("mapid")
  148. }
  149. //IDARR = localStorage.getItem(mapid+agvid+"_id_arr");
  150. //获取按钮
  151. createList();
  152. //获取状态
  153. startLog();
  154. setInterval(function() {
  155. if (ws.readyState === 3) {
  156. startLog();
  157. }
  158. }, 1000);
  159. //设置操作按钮
  160. $("#gostart").addClass("mui-hidden");
  161. $("#moving").attr("disabled", true);
  162. $("#start").attr("disabled", true);
  163. $('#cancel').attr("disabled", true);
  164. //设置页面可以左滑右滑跳转页面
  165. var windowHeight = $(window).height(),
  166. $body = $("body");
  167. $("body").on("touchstart", function(e) {
  168. e.preventDefault();
  169. startX = e.originalEvent.changedTouches[0].pageX,
  170. startY = e.originalEvent.changedTouches[0].pageY;
  171. });
  172. $("body").on("touchmove", function(e) {
  173. e.preventDefault();
  174. moveEndX = e.originalEvent.changedTouches[0].pageX,
  175. moveEndY = e.originalEvent.changedTouches[0].pageY,
  176. X = moveEndX - startX,
  177. Y = moveEndY - startY;
  178. if (Math.abs(X) > Math.abs(Y) && X > 0) {
  179. window.location.href = "settings.html"; //right
  180. } else {
  181. //window.location.href = "tasklist.html"; //left
  182. return
  183. }
  184. });
  185. //设置拖拽排序
  186. // Sortable.create(document.getElementById('btlist'), {
  187. // animation: 150, //动画参数
  188. // // dropBubble:true,
  189. // onUpdate: function(evt){ //拖拽完毕之后发生该事件
  190. // var id_arr=[]
  191. // for(var i=0, len=evt.from.children.length; i<len; i++){
  192. // id_arr+=','+ evt.from.children[i].getAttribute('drag-id');
  193. // }
  194. // id_arr=id_arr.substr(1);
  195. // //然后请求后台ajax 这样就完成了拖拽排序
  196. // id_arr = id_arr.split(','); //["1", "4", "3", "2", "1", "11", "12"]
  197. // localStorage.setItem(mapid+agvid+'_id_arr',JSON.stringify(id_arr));
  198. // }
  199. // });
  200. })
  201. //按钮点击事件
  202. function onSelectStation(evt) {
  203. var $this = $(this);
  204. if ($("div[id='btlist']").is(':active')) {
  205. $this.removeClass('active');
  206. } else {
  207. $this.addClass('active');
  208. }
  209. if ($("div[id='btlist']").find(".active").length == 1) {
  210. $("#moving").attr("disabled", false);
  211. $this.addClass('up');
  212. $("#start").removeAttr("disabled");
  213. $("#cancel").removeAttr("disabled");
  214. } else if ($("div[id='btlist']").find(".active").length == 2) {
  215. $("#gomoving").addClass("mui-hidden");
  216. $("#gostart").removeClass("mui-hidden");
  217. $this.addClass('down');
  218. $('#start').attr("disabled", false);
  219. $("#handling").removeAttr("disabled");
  220. }
  221. if ($("div[id='btlist']").find(".active").length >= 2) {
  222. $("button[name='stbtn']").css("pointer-events", "none")
  223. } else {
  224. $("button[name='stbtn']").css("pointer-events", "auto")
  225. }
  226. };
  227. //取消按钮操作
  228. function Reset(evt) {
  229. if ($("div[id='btlist']").find(".active")) {
  230. $("#gostart").addClass("mui-hidden");
  231. $("#gomoving").removeClass("mui-hidden");
  232. $("button[name='stbtn']").removeClass('up');
  233. $("button[name='stbtn']").removeClass('down');
  234. $("button[name='stbtn']").removeClass('active');
  235. $("button[name='stbtn']").css("pointer-events", "auto");
  236. $('#start').attr("disabled", true);
  237. $('#cancel').attr("disabled", true);
  238. $('#moving').attr("disabled", true);
  239. }
  240. }
  241. //移动按钮
  242. $("#moving").click(function() {
  243. let to;
  244. $("div[id='btlist']").find(".up").each(function(evt) {
  245. to = parseInt(($(this).context).id);
  246. });
  247. SendCmd(agvid, msgTypeToStation, {
  248. "Stn": to
  249. }, function(d) {
  250. console.log("AddTransTask", d);
  251. Reset()
  252. })
  253. });
  254. //搬运按钮
  255. $("#start").click(function() {
  256. var bt_value = [];
  257. $("div[id='btlist']").find(".up").each(function(evt) {
  258. bt_value.push($(this).val());
  259. });
  260. $("div[id='btlist']").find(".down").each(function(evt) {
  261. bt_value.push($(this).val());
  262. });
  263. AddTransTask(agvid, bt_value[0], bt_value[1], function(d) {
  264. //console.log("AddTransTask", d);
  265. Reset()
  266. })
  267. });
  268. function AddTransTask(agvid, from, to, callback) {
  269. $.post(url + "/task", {
  270. id: agvid,
  271. from: from,
  272. to: to
  273. }, callback);
  274. };
  275. function SendCmd(agvid, cmd, opt, func) {
  276. let param = {
  277. "t": cmd
  278. };
  279. opt = _.extend(param, opt);
  280. //console.log("param", opt);
  281. $.post(url + "/agv/SendString/" + agvid,
  282. JSON.stringify(opt),
  283. func
  284. );
  285. }
  286. //取消按钮
  287. $("#cancel").on("click", Reset);
  288. //填充按钮列表
  289. function createList() {
  290. $.get(url + "/map/getStations/" + mapid, function(data) {
  291. trs = "";
  292. var IDARR = ["100","101","102","103","104","105","106","107"]
  293. if(IDARR == "" ||IDARR == null){
  294. for (i in data) {
  295. if (data[i].Name != "" && data[i].Name != "rect") {
  296. var ids = data[i].Id - (agvid * 100)
  297. trs += '<div class="mui-col mui-col-xs-3" drag-id="'+data[i].Id+'">' +
  298. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + ids +
  299. '" value="' + ids + '">' +
  300. data[i].Name + '</button></div>'
  301. }
  302. }
  303. }else{
  304. //id_arr = JSON.parse(IDARR);//["4","5","2","999","7","1","6","8","3"]
  305. id_arr = IDARR;
  306. for(x in id_arr){
  307. for (i in data) {
  308. if((data[i].Id == id_arr[x]) && (data[i].Name !="") && (data[i].Name != "rect")){
  309. var ids = data[i].Id - (agvid * 100)
  310. trs += '<div class="mui-col mui-col-xs-3" drag-id="'+data[i].Id+'">' +
  311. '<button type="button" class="mui-btn mui-btn-royal mui-btn-block" name="stbtn" id="' + ids +
  312. '" value="' + ids + '">' +
  313. data[i].Name + '</button></div>'
  314. }
  315. }
  316. }
  317. }
  318. $btlist.append(trs);
  319. //注册按钮点击事件click touchstart
  320. $("button[name]").on("click", onSelectStation);
  321. });
  322. }
  323. //新建ws连接,获取agv的状态
  324. let ws;
  325. function startLog() {
  326. ws = new WebSocket("ws://" + ip + "/ws/msg/" + agvid);
  327. ws.onmessage = function(e) {
  328. let result;
  329. let msg = JSON.parse(e.data);
  330. switch (msg.type) {
  331. case msgTypeStatus:
  332. // 每秒一次状态
  333. let stMap = JSON.parse(msg.data);
  334. //根据状态设置图标等
  335. showStatusValue(stMap);
  336. //当前站点按钮文字闪烁
  337. if (agvid == msg.id) {
  338. let stMap = JSON.parse(msg.data);
  339. $("#agvstatus").toggleClass("text-success");
  340. $(".mui-btn").removeClass("text-success");
  341. $("#" + stMap.Station + "").addClass("text-success");
  342. }
  343. break;
  344. //读取设置状态,可以获得电池伏数
  345. case msgTypeGetCfg:
  346. //console.log(msg.type, msg.data);
  347. break;
  348. default:
  349. //console.log(msg.type, msg.data);
  350. }
  351. };
  352. }
  353. //根据获取到的agv状态,设置速度、电量、站点、顶升、提示信息、运行按钮等的颜色和文字显示
  354. function showStatusValue(status) {
  355. for (let k in status) {
  356. let v = status[k];
  357. //电量显示
  358. if (k == "BatteryVolt") {
  359. if (v >= 5200) { //BatteryVoltFull
  360. document.getElementById("battery").src = "img/battery-100.png";
  361. }
  362. if (5000 <= v && v < 5200) { //BatteryVoltHigh
  363. document.getElementById("battery").src = "img/battery-80.png";
  364. }
  365. if (4800 <= v && v < 5000) { //BatteryVoltMid
  366. document.getElementById("battery").src = "img/battery-60.png";
  367. }
  368. if (4700 <= v && v < 4800) { //BatteryVoltLow
  369. document.getElementById("battery").src = "img/battery-40.png";
  370. }
  371. if (4500 <= v && v < 4700) { //BatteryVoltWarn
  372. document.getElementById("battery").src = "img/battery-20.png";
  373. }
  374. if (v <= 4500) { //BatteryVoltStop
  375. document.getElementById("battery").src = "img/battery-0.png";
  376. }
  377. }
  378. //目标站点
  379. if (k == "TgtStation") {
  380. if (v == "65535") {
  381. $("#tgtstation").text("0");
  382. } else {
  383. $("#tgtstation").text(v);
  384. }
  385. }
  386. //顶升状态
  387. if (k == "LiftStatus") {
  388. if (v == 1 || v == 3 || v == 5 || v == 7) {
  389. document.getElementById("liftstatus").src = "img/liftstatus-up.png";
  390. } else if (v == 0) {
  391. document.getElementById("liftstatus").src = "img/liftstatus.png";
  392. } else {
  393. if (status.Status == "1") {
  394. document.getElementById("liftstatus").src = "img/liftstatus.png";
  395. } else {
  396. document.getElementById("liftstatus").src = "img/liftstatus-down.png";
  397. }
  398. }
  399. }
  400. //停止运行注意按钮及信息提示框
  401. if (k == "Status") {
  402. document.getElementById("speed").src = "";
  403. if (v == 0) {
  404. $("#info").text("未设置");
  405. }
  406. if (v == 1) {
  407. $("#info").text("就绪");
  408. }
  409. if (v == 2) {
  410. $("#info").text("运行");
  411. document.getElementById("speed").src = "img/speed-high.png";
  412. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  413. } else {
  414. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  415. }
  416. if (v == 3 || v == 4 ||(v == 5)) {
  417. if (v == 3) {
  418. $("#info").text("停止");
  419. }
  420. if (v == 4) {
  421. $("#info").text("急停");
  422. }
  423. if (v == 5) {
  424. $("#info").text("刹车");
  425. }
  426. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  427. } else {
  428. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  429. }
  430. if (v == 6) {
  431. $("#info").text("驱动器错误");
  432. }
  433. if (v == 7) {
  434. $("#info").text("导航错误");
  435. }
  436. if (v == 8) {
  437. $("#info").text("任务错误");
  438. }
  439. if (v == 9) {
  440. document.getElementById("speed").src = "img/speed-medium.png";
  441. $("#info").text("手动控制");
  442. }
  443. if (v == 11 || v == 22) {
  444. if (v == 11) {
  445. document.getElementById("speed").src = "img/speed-medium.png";
  446. $("#info").text("前方障碍");
  447. }
  448. if (v == 22) {
  449. document.getElementById("speed").src = "img/speed-medium.png";
  450. $("#info").text("障碍减速");
  451. }
  452. document.getElementById("warning").style.backgroundImage = "url('img/btn1_bg.png')";
  453. } else {
  454. document.getElementById("warning").style.backgroundImage = "url('img/btn4_bg.png')";
  455. }
  456. if (v == 12) {
  457. $("#info").text("防撞停止");
  458. }
  459. if (v == 15) {
  460. $("#info").text("低电压停止");
  461. }
  462. if (v == 21) {
  463. $("#info").text("低电压运行");
  464. }
  465. if (v == 31) {
  466. $("#info").text("前磁导脱线");
  467. }
  468. if (v == 32) {
  469. $("#info").text("反磁导脱线");
  470. }
  471. if (v == 33) {
  472. $("#info").text("左磁导脱线");
  473. }
  474. if (v == 34) {
  475. $("#info").text("右磁导脱线");
  476. }
  477. if (v == 71) {
  478. $("#info").text("取货失败1");
  479. }
  480. if (v == 72) {
  481. $("#info").text("取货失败2");
  482. }
  483. if (v == 73) {
  484. $("#info").text("放货失败");
  485. }
  486. }
  487. }
  488. if (status.Status == "9" && status.FWlkRpm != "0") {
  489. document.getElementById("run").style.backgroundImage = "url('img/btn2_bg.png')";
  490. document.getElementById("stop").style.backgroundImage = "url('img/btn4_bg.png')";
  491. }
  492. if (status.Status == "9" && status.FWlkRpm == "0") {
  493. document.getElementById("run").style.backgroundImage = "url('img/btn4_bg.png')";
  494. document.getElementById("stop").style.backgroundImage = "url('img/btn3_bg.png')";
  495. }
  496. };
  497. </script>
  498. </html>