readActions.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**
  2. *$id:Action 。JS,V 2017-12-19
  3. *$author shen.zhi
  4. */
  5. /**
  6. * 构建了用户界面操作的对象。
  7. */
  8. var baseGraph,baseXml;
  9. function Actions(editorUi)
  10. {
  11. this.editorUi = editorUi;
  12. this.actions = new Object();
  13. this.init();
  14. };
  15. /**
  16. * 添加默认的行为。
  17. */
  18. Actions.prototype.init = function()
  19. {
  20. var ui = this.editorUi;
  21. var editor = ui.editor;
  22. var graph = editor.graph;
  23. baseGraph = graph;
  24. doChangeMap();
  25. var path = $("#path").val();
  26. this.addAction('deviceInfo', function(){
  27. var cell = graph.getSelectionCell();
  28. var rem = cell.getRemark();
  29. if(rem==null||rem==""){
  30. alert("可能无绑定系统设备,暂无设备信息!");
  31. }else{
  32. $.post($("#path").val()+"/GetDeviceInfoOfMapServlet",{"devInfo":rem},function(text){
  33. $("#deviceInfo",window.parent.document).html(text);
  34. $("#deviceInfo",window.parent.document).css("font-size","12px");
  35. $("#deviceInfo tr",window.parent.document).attr("height","23");
  36. $("#deviceInfo td[align=right]",window.parent.document).css("padding-right","15px");
  37. window.parent.openDialog("de");
  38. });
  39. }
  40. }, null, null, '');
  41. this.addAction('cpuInfo', function() {
  42. var cellVal = graph.getSelectionCell().getRemark();
  43. if(cellVal==null||cellVal==""){
  44. alert("可能无绑定系统设备,暂无监控信息!");
  45. }else{
  46. $("#idVal",window.parent.document).val(cellVal);
  47. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/runningMonitor.jsp");
  48. window.parent.openDialog("jk");
  49. }
  50. }, null, null, '');
  51. /*this.addAction('haInfo', function() {
  52. var cellVal = graph.getSelectionCell().getRemark();
  53. if(cellVal==null||cellVal==""){
  54. alert("可能无绑定系统设备,暂无监控信息!");
  55. }else{
  56. $("#idVal").val(cellVal.substr(0,cellVal.indexOf("—")));
  57. $("#oneFram").attr("src",path+"/monitorCenter/devices/mapData/haStatusRunningMonitor.jsp");
  58. $("#jkInfo").dialog({
  59. title:"监控——HA状态"
  60. });
  61. $("#jkInfo").dialog("open");
  62. }
  63. }, null, null, '');*/
  64. this.addAction('memInfo', function() {
  65. var cellVal = graph.getSelectionCell().getRemark();
  66. if(cellVal==null||cellVal==""){
  67. alert("可能无绑定系统设备,暂无监控信息!");
  68. }else{
  69. $("#idVal",window.parent.document).val(cellVal);
  70. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/memRunningMonitor.jsp");
  71. window.parent.openDialog("jk");
  72. }
  73. }, null, null, '');
  74. this.addAction('sessionInfo', function() {
  75. var cellVal = graph.getSelectionCell().getRemark();
  76. if(cellVal==null||cellVal==""){
  77. alert("可能无绑定系统设备,暂无监控信息!");
  78. }else{
  79. $("#idVal",window.parent.document).val(cellVal);
  80. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/sessionRunningMonitor.jsp");
  81. window.parent.openDialog("jk");
  82. }
  83. }, null, null, '');
  84. this.addAction('userInfo', function() {
  85. var cellVal = graph.getSelectionCell().getRemark();
  86. if(cellVal==null||cellVal==""){
  87. alert("可能无绑定系统设备,暂无监控信息!");
  88. }else{
  89. $("#idVal",window.parent.document).val(cellVal);
  90. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/onLineRunningMonitor.jsp");
  91. window.parent.openDialog("jk");
  92. }
  93. }, null, null, '');
  94. this.addAction('diskInfo', function() {
  95. var cellVal = graph.getSelectionCell().getRemark();
  96. if(cellVal==null||cellVal==""){
  97. alert("可能无绑定系统设备,暂无监控信息!");
  98. }else{
  99. $("#idVal",window.parent.document).val(cellVal);
  100. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/diskRunningMonitor.jsp");
  101. window.parent.openDialog("jk");
  102. }
  103. }, null, null, '');
  104. this.addAction('ifInfo', function() {
  105. var cellVal = graph.getSelectionCell().getRemark();
  106. if(cellVal==null||cellVal==""){
  107. alert("可能无绑定系统设备,暂无监控信息!");
  108. }else{
  109. $("#idVal",window.parent.document).val(cellVal);
  110. $("#oneFram",window.parent.document).attr("src",path+"/monitorCenter/devices/mapData/ifInfoRunningMonitor.jsp");
  111. window.parent.openDialog("jk");
  112. }
  113. }, null, null, '');
  114. this.addAction('gdSyslog', function() {
  115. var cellVal = graph.getSelectionCell().getRemark();
  116. if(cellVal==null||cellVal==""){
  117. alert("可能无绑定系统设备,暂无日志信息!");
  118. }else{
  119. $("#oneFram",window.parent.document).attr("src",path+"/com/visec/monitorCenter/syslog/fixlog/action/FixLogAction.do?mhd=toPathUser&fid="+cellVal+"&rm=0");
  120. window.parent.openDialog("log");
  121. }
  122. }, null, null, '');
  123. this.addAction('fgdSyslog', function() {
  124. var cellVal = graph.getSelectionCell().getRemark();
  125. if(cellVal==null||cellVal==""){
  126. alert("可能无绑定系统设备,暂无日志信息!");
  127. }else{
  128. var id = cellVal;
  129. $("#idVal",window.parent.document).val(id);
  130. $("#oneFram",window.parent.document).attr("src",path+"/com/visec/monitorCenter/syslog/varlog/action/VarlogAction.do?mhd=toListOfMap&dev_id="+id);
  131. window.parent.openDialog("log");
  132. }
  133. }, null, null, '');
  134. this.addAction('fitPage', mxUtils.bind(this, function()
  135. {
  136. if (!graph.pageVisible)
  137. {
  138. this.get('pageView').funct();
  139. }
  140. var fmt = graph.pageFormat;
  141. var ps = graph.pageScale;
  142. var cw = graph.container.clientWidth - 20;
  143. var ch = graph.container.clientHeight - 20;
  144. var scale = Math.floor(100 * Math.min(cw / fmt.width / ps, ch / fmt.height / ps)) / 100;
  145. graph.zoomTo(scale);
  146. graph.container.scrollLeft = Math.round(graph.view.translate.x * scale - Math.max(10, (graph.container.clientWidth - fmt.width * ps * scale) / 2));
  147. graph.container.scrollTop = Math.round(graph.view.translate.y * scale - Math.max(10, (graph.container.clientHeight - fmt.height * ps * scale) / 2));
  148. }));
  149. this.addAction('fitPageWidth', mxUtils.bind(this, function()
  150. {
  151. if (!graph.pageVisible)
  152. {
  153. this.get('pageView').funct();
  154. }
  155. var fmt = graph.pageFormat;
  156. var ps = graph.pageScale;
  157. var cw = graph.container.clientWidth - 20;
  158. var scale = Math.floor(100 * cw / fmt.width / ps) / 100;
  159. graph.zoomTo(scale);
  160. graph.container.scrollLeft = Math.round(graph.view.translate.x * scale - Math.max(10, (graph.container.clientWidth - fmt.width * ps * scale) / 2));
  161. graph.container.scrollTop = Math.round(graph.view.translate.y * scale - Math.max(10, (graph.container.clientHeight - fmt.height * ps * scale) / 2));
  162. }));
  163. this.put('customZoom', new Action(mxResources.get('custom'), function()
  164. {
  165. var value = mxUtils.prompt(mxResources.get('enterValue') + ' (%)', parseInt(graph.getView().getScale() * 100));
  166. if (value != null && value.length > 0 && !isNaN(parseInt(value)))
  167. {
  168. graph.zoomTo(parseInt(value) / 100);
  169. }
  170. }));
  171. // Option actions
  172. var action = null;
  173. action = this.addAction('grid', function()
  174. {
  175. graph.setGridEnabled(!graph.isGridEnabled());
  176. editor.updateGraphComponents();
  177. }, null, null, 'Ctrl+Shift+G');
  178. action.setToggleAction(true);
  179. action.setSelectedCallback(function() { return graph.isGridEnabled(); });
  180. action = this.addAction('guides', function() { graph.graphHandler.guidesEnabled = !graph.graphHandler.guidesEnabled; });
  181. action.setToggleAction(true);
  182. action.setSelectedCallback(function() { return graph.graphHandler.guidesEnabled; });
  183. action = this.addAction('tooltips', function()
  184. {
  185. graph.tooltipHandler.setEnabled(!graph.tooltipHandler.isEnabled());
  186. });
  187. action.setToggleAction(true);
  188. action.setSelectedCallback(function() { return graph.tooltipHandler.isEnabled(); });
  189. action = this.addAction('navigation', function()
  190. {
  191. graph.foldingEnabled = !graph.foldingEnabled;
  192. graph.view.revalidate();
  193. });
  194. action.setToggleAction(true);
  195. action.setSelectedCallback(function() { return graph.foldingEnabled; });
  196. action = this.addAction('scrollbars', function()
  197. {
  198. graph.scrollbars = !graph.scrollbars;
  199. editor.updateGraphComponents();
  200. if (!graph.scrollbars)
  201. {
  202. var t = graph.view.translate;
  203. graph.view.setTranslate(t.x - graph.container.scrollLeft / graph.view.scale, t.y - graph.container.scrollTop / graph.view.scale);
  204. graph.container.scrollLeft = 0;
  205. graph.container.scrollTop = 0;
  206. graph.sizeDidChange();
  207. }
  208. else
  209. {
  210. var dx = graph.view.translate.x;
  211. var dy = graph.view.translate.y;
  212. graph.view.translate.x = 0;
  213. graph.view.translate.y = 0;
  214. graph.sizeDidChange();
  215. graph.container.scrollLeft -= Math.round(dx * graph.view.scale);
  216. graph.container.scrollTop -= Math.round(dy * graph.view.scale);
  217. }
  218. }, !mxClient.IS_TOUCH);
  219. action.setToggleAction(true);
  220. action.setSelectedCallback(function() { return graph.container.style.overflow == 'auto'; });
  221. action = this.addAction('pageView', mxUtils.bind(this, function()
  222. {
  223. graph.pageVisible = !graph.pageVisible;
  224. graph.pageBreaksVisible = graph.pageVisible;
  225. graph.preferPageSize = graph.pageBreaksVisible;
  226. graph.view.validate();
  227. graph.sizeDidChange();
  228. editor.updateGraphComponents();
  229. editor.outline.update();
  230. if (mxUtils.hasScrollbars(graph.container))
  231. {
  232. if (graph.pageVisible)
  233. {
  234. graph.container.scrollLeft -= 20;
  235. graph.container.scrollTop -= 20;
  236. }
  237. else
  238. {
  239. graph.container.scrollLeft += 20;
  240. graph.container.scrollTop += 20;
  241. }
  242. }
  243. }));
  244. action.setToggleAction(true);
  245. action.setSelectedCallback(function() { return graph.pageVisible; });
  246. this.put('pageBackgroundColor', new Action(mxResources.get('backgroundColor'), function()
  247. {
  248. var apply = function(color)
  249. {
  250. graph.background = color;
  251. editor.updateGraphComponents();
  252. };
  253. var cd = new ColorDialog(ui, graph.background || 'none', apply);
  254. ui.showDialog(cd.container, 220, 360, true, false);
  255. if (!mxClient.IS_TOUCH)
  256. {
  257. cd.colorInput.focus();
  258. }
  259. }));
  260. action = this.addAction('connect', function()
  261. {
  262. graph.setConnectable(!graph.connectionHandler.isEnabled());
  263. }, null, null, 'Ctrl+Q');
  264. action.setToggleAction(true);
  265. action.setSelectedCallback(function() { return graph.connectionHandler.isEnabled(); });
  266. // Font style actions
  267. var toggleFontStyle = mxUtils.bind(this, function(key, style)
  268. {
  269. this.addAction(key, function()
  270. {
  271. graph.toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE, style);
  272. });
  273. });
  274. };
  275. /**
  276. * 寄存器的作用在给定的名称。
  277. */
  278. Actions.prototype.addAction = function(key, funct, enabled, iconCls, shortcut)
  279. {
  280. return this.put(key, new Action(mxResources.get(key), funct, enabled, iconCls, shortcut));
  281. };
  282. /**
  283. * 寄存器的作用在给定的名称。
  284. */
  285. Actions.prototype.put = function(name, action)
  286. {
  287. this.actions[name] = action;
  288. return action;
  289. };
  290. /**
  291. * 返回给定名称或空如果没有这样的行动存在的动作。
  292. */
  293. Actions.prototype.get = function(name)
  294. {
  295. return this.actions[name];
  296. };
  297. /**
  298. * Constructs a new action for the given parameters.
  299. */
  300. function Action(label, funct, enabled, iconCls, shortcut)
  301. {
  302. mxEventSource.call(this);
  303. this.label = label;
  304. this.funct = funct;
  305. this.enabled = (enabled != null) ? enabled : true;
  306. this.iconCls = iconCls;
  307. this.shortcut = shortcut;
  308. };
  309. //Action inherits from mxEventSource
  310. mxUtils.extend(Action, mxEventSource);
  311. /**
  312. * Sets the enabled state of the action and fires a stateChanged event.
  313. */
  314. Action.prototype.setEnabled = function(value)
  315. {
  316. if (this.enabled != value)
  317. {
  318. this.enabled = value;
  319. this.fireEvent(new mxEventObject('stateChanged'));
  320. }
  321. };
  322. /**
  323. * Sets the enabled state of the action and fires a stateChanged event.
  324. */
  325. Action.prototype.setToggleAction = function(value)
  326. {
  327. this.toggleAction = value;
  328. };
  329. /**
  330. * Sets the enabled state of the action and fires a stateChanged event.
  331. */
  332. Action.prototype.setSelectedCallback = function(funct)
  333. {
  334. this.selectedCallback = funct;
  335. };
  336. /**
  337. * 套动作启用状态和火灾statechanged事件。
  338. */
  339. Action.prototype.isSelected = function()
  340. {
  341. return this.selectedCallback();
  342. };
  343. //加载拓扑图像 顺便添加警告信息
  344. function doChangeMap(){
  345. $.post($("#path").val()+"/SaveToXmlServlet",{"tp":$("#mapTp").val(),"type":"get"},function(text){
  346. if(text=="0"){
  347. alert("文件加载失败!");
  348. }else{
  349. var xml = text;
  350. var doc = mxUtils.parseXml(xml);
  351. baseXml = doc;
  352. var nodes = doc.documentElement.getElementsByTagName('mxCell');
  353. var id,value,index=0;
  354. for(var i = 0;i<nodes.length;i++){
  355. value = nodes[i].getAttribute('value');
  356. id = nodes[i].getAttribute('id');
  357. if(value==null||value==""){
  358. continue;
  359. }
  360. //判断边
  361. if(nodes[i].getAttribute('edge')=="1"){
  362. //增加线条样式
  363. //nodes[i].setAttribute('style',"entryX=0;entryY=0.5;edgeStyle=entityRelationEdgeStyle;endSize=9;endArrow=block;strokeColor=#FF3333;strokeWidth=2;dashed=1");
  364. continue;
  365. }
  366. index = value.indexOf("\n");
  367. if(index>0){
  368. nodes[i].setAttribute('value',value.substr(0,index));
  369. nodes[i].setAttribute('text',value.substr(index+1).replace("\n"," / "));
  370. continue;
  371. }
  372. nodes[i].setAttribute('text',value);
  373. }
  374. //装载加入到显示区域
  375. var codec = new mxCodec(doc);
  376. codec.decode(doc.documentElement, baseGraph.getModel());
  377. //baseGraph.getModel().beginUpdate();
  378. //baseGraph.getModel().endUpdate();
  379. //doLoadAlert();
  380. }
  381. });
  382. }
  383. window.setInterval("doLoadAlert()",8000);
  384. //检测警告信息
  385. function doLoadAlert(){
  386. var model = baseGraph.getModel();
  387. if(baseXml != null && baseXml.documentElement != null){
  388. var nodes = baseXml.documentElement.getElementsByTagName('mxCell');
  389. var val,val2,id,result="";
  390. for(var i = 0;i<nodes.length;i++){
  391. if(nodes[i].getAttribute('edge')=="1"){
  392. continue;
  393. }
  394. val = nodes[i].getAttribute('text');
  395. if(val != null && val != ""){
  396. if(val.indexOf("/")>0){
  397. val2=val.substring(val.lastIndexOf(":")+2);
  398. val=val.substring(val.indexOf(":")+1,val.indexOf("/")-2);
  399. }
  400. if(checkIP(val)){
  401. id = nodes[i].getAttribute("id");
  402. result+=id+"-"+val+"-"+val2+"=";
  403. }
  404. }
  405. }
  406. //ping操作获取状态
  407. $.post($("#path").val()+"/CheckMapIpServlet",{"ip":result},function(text){
  408. var data = text.split("#");
  409. var ifData = $.parseJSON(data[1]);
  410. var statData = data[0].split("=");
  411. model.beginUpdate();
  412. try{
  413. var sd = null,ce = null;
  414. $.each(statData,function(index,sds){
  415. if(sds!=null && sds!=""){
  416. sd = sds.split("-");
  417. ce = model.getCell(sd[0]);
  418. //判断业务口和通讯口都中断
  419. if(sd[1]!="0" && sd[2]!="0"){
  420. baseGraph.addCellOverlay(ce, new mxCellOverlay(baseGraph.warningImage,'警告: 网络连接不通'));
  421. //显示数据流向
  422. //showDataLine(nodes,sd[0],model);
  423. }
  424. //判断通讯口中断业务口正常
  425. if(sd[1]!="0" && sd[2]=="0"){
  426. baseGraph.addCellOverlay(ce, new mxCellOverlay(baseGraph.warningImage,'警告: 通讯口连接不通'));
  427. //显示数据流向
  428. //showDataLine(nodes,sd[0],model);
  429. //显示流量信息
  430. showIf(ce,ifData,sd[0]);
  431. }
  432. //判断通讯口正常业务口中断
  433. if(sd[1]=="0" && sd[2]!="0"){
  434. baseGraph.addCellOverlay(ce, new mxCellOverlay(baseGraph.warningImage,'警告: 业务口连接不通'));
  435. //显示数据流向
  436. //showDataLine(nodes,sd[0],model);
  437. //显示流量信息
  438. showIf(ce,ifData,sd[0]);
  439. }
  440. }
  441. });
  442. }finally{
  443. model.endUpdate();
  444. }
  445. });
  446. }
  447. }
  448. //显示流量方法
  449. function showIf(ce,ifData,ceId){
  450. $.each(ifData,function(ind,vo){
  451. if(ceId==vo.tempId){
  452. ce.setValue(vo.name+vo.remark);
  453. return false;
  454. }
  455. });
  456. }
  457. //显示数据流向
  458. function showDataLine(nodes,ceId,model){
  459. for(var i = 0;i<nodes.length;i++){
  460. if(nodes[i].getAttribute('edge')!="1"){
  461. continue;
  462. }
  463. var cee = model.getCell(nodes[i].getAttribute('id')).getTerminal(1);
  464. if(cee!=null){
  465. if(cee.getId()==ceId){
  466. nodes[i].setAttribute('value',"AA");
  467. //alert(nodes[i].getAttribute('value'))
  468. //nodes[i].setAttribute('style',"entryX=0;entryY=0.5;edgeStyle=entityRelationEdgeStyle;endSize=9;endArrow=block;strokeColor=#FF3333;strokeWidth=2;dashed=1");
  469. }
  470. }
  471. }
  472. }
  473. //添加告警标识
  474. function addAlert(text,cell){
  475. baseGraph.getModel().beginUpdate();
  476. try{
  477. if(text=="0"){
  478. baseGraph.addCellOverlay(cell, new mxCellOverlay(baseGraph.warningImage,'警告: 网络连接不通'));
  479. }else{
  480. baseGraph.removeCellOverlays(cell);//删除当前元素的警告标识
  481. }
  482. }finally{
  483. baseGraph.getModel().endUpdate();
  484. }
  485. }
  486. //验证是否为IP地址
  487. function checkIP(ip){
  488. var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;//正则表达式
  489. if(re.test(ip))
  490. {
  491. if( RegExp.$1<256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)
  492. return true;
  493. }else{
  494. return false;
  495. }
  496. }