workflow.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. function graphTrace(options) {
  2. var _defaults = {
  3. srcEle: this,
  4. pid: $(this).attr('pid'),
  5. pdid: $(this).attr('pdid')
  6. };
  7. var opts = $.extend(true, _defaults, options);
  8. // 处理使用js跟踪当前节点坐标错乱问题
  9. $('#changeImg').live('click', function() {
  10. $('#workflowTraceDialog').dialog('close');
  11. if ($('#imgDialog').length > 0) {
  12. $('#imgDialog').remove();
  13. }
  14. $('<div/>', {
  15. 'id': 'imgDialog',
  16. title: '此对话框显示的图片是由引擎自动生成的,并用红色标记当前的节点<button id="diagram-viewer">Diagram-Viewer</button>',
  17. html: "<img src='" + ctx + '/workflow/process/trace/auto/' + opts.pid + "' />"
  18. }).appendTo('body').dialog({
  19. modal: true,
  20. resizable: false,
  21. dragable: false,
  22. width: document.documentElement.clientWidth * 0.95,
  23. height: document.documentElement.clientHeight * 0.95
  24. });
  25. });
  26. /*
  27. 用官方开发的Diagram-Viewer跟踪
  28. */
  29. $('#diagram-viewer').live('click', function() {
  30. $('#workflowTraceDialog').dialog('close');
  31. if ($('#imgDialog').length > 0) {
  32. $('#imgDialog').remove();
  33. }
  34. var url = ctx + '/diagram-viewer/index.html?processDefinitionId=' + opts.pdid + '&processInstanceId=' + opts.pid;
  35. $('<div/>', {
  36. 'id': 'imgDialog',
  37. title: '此对话框显示的图片是由引擎自动生成的,并用红色标记当前的节点',
  38. html: '<iframe src="' + url + '" width="100%" height="' + document.documentElement.clientHeight * 0.90 + '" />'
  39. }).appendTo('body').dialog({
  40. modal: true,
  41. resizable: false,
  42. dragable: false,
  43. width: document.documentElement.clientWidth * 0.95,
  44. height: document.documentElement.clientHeight * 0.95
  45. });
  46. });
  47. // 获取图片资源
  48. var imageUrl = ctx + "/workflow/resource/process-instance?pid=" + opts.pid + "&type=image";
  49. $.getJSON(ctx + '/workflow/process/trace?pid=' + opts.pid, function(infos) {
  50. var positionHtml = "";
  51. // 生成图片
  52. var varsArray = new Array();
  53. $.each(infos, function(i, v) {
  54. var $positionDiv = $('<div/>', {
  55. 'class': 'activity-attr'
  56. }).css({
  57. position: 'absolute',
  58. left: (v.x - 1),
  59. top: (v.y - 1),
  60. width: (v.width - 2),
  61. height: (v.height - 2),
  62. backgroundColor: 'black',
  63. opacity: 0,
  64. zIndex: $.fn.qtip.zindex - 1
  65. });
  66. // 节点边框
  67. var $border = $('<div/>', {
  68. 'class': 'activity-attr-border'
  69. }).css({
  70. position: 'absolute',
  71. left: (v.x - 1),
  72. top: (v.y - 1),
  73. width: (v.width - 4),
  74. height: (v.height - 3),
  75. zIndex: $.fn.qtip.zindex - 2
  76. });
  77. if (v.currentActiviti) {
  78. $border.addClass('ui-corner-all-12').css({
  79. border: '3px solid red'
  80. });
  81. }
  82. positionHtml += $positionDiv.outerHTML() + $border.outerHTML();
  83. varsArray[varsArray.length] = v.vars;
  84. });
  85. if ($('#workflowTraceDialog').length == 0) {
  86. $('<div/>', {
  87. id: 'workflowTraceDialog',
  88. title: '查看流程(按ESC键可以关闭)<button id="changeImg">如果坐标错乱请点击这里</button><button id="diagram-viewer">Diagram-Viewer</button>',
  89. html: "<div><img src='" + imageUrl + "' style='position:absolute; left:0px; top:0px;' />" +
  90. "<div id='processImageBorder'>" +
  91. positionHtml +
  92. "</div>" +
  93. "</div>"
  94. }).appendTo('body');
  95. } else {
  96. $('#workflowTraceDialog img').attr('src', imageUrl);
  97. $('#workflowTraceDialog #processImageBorder').html(positionHtml);
  98. }
  99. // 设置每个节点的data
  100. $('#workflowTraceDialog .activity-attr').each(function(i, v) {
  101. $(this).data('vars', varsArray[i]);
  102. });
  103. // 打开对话框
  104. $('#workflowTraceDialog').dialog({
  105. modal: true,
  106. resizable: false,
  107. dragable: false,
  108. open: function() {
  109. $('#workflowTraceDialog').dialog('option', 'title', '查看流程(按ESC键可以关闭)<button id="changeImg">如果坐标错乱请点击这里</button><button id="diagram-viewer">Diagram-Viewer</button>');
  110. $('#workflowTraceDialog').css('padding', '0.2em');
  111. $('#workflowTraceDialog .ui-accordion-content').css('padding', '0.2em').height($('#workflowTraceDialog').height() - 75);
  112. // 此处用于显示每个节点的信息,如果不需要可以删除
  113. $('.activity-attr').qtip({
  114. content: function() {
  115. var vars = $(this).data('vars');
  116. var tipContent = "<table class='need-border'>";
  117. $.each(vars, function(varKey, varValue) {
  118. if (varValue) {
  119. tipContent += "<tr><td class='label'>" + varKey + "</td><td>" + varValue + "<td/></tr>";
  120. }
  121. });
  122. tipContent += "</table>";
  123. return tipContent;
  124. },
  125. position: {
  126. at: 'bottom left',
  127. adjust: {
  128. x: 3
  129. }
  130. }
  131. });
  132. // end qtip
  133. },
  134. close: function() {
  135. $('#workflowTraceDialog').remove();
  136. },
  137. width: document.documentElement.clientWidth * 0.95,
  138. height: document.documentElement.clientHeight * 0.95
  139. });
  140. });
  141. }