common.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // 通用分页
  2. var curPage = 1; // 当前页码
  3. var totalCount, pageSize, totalPage; // 总记录数,每页显示数,总页数
  4. totalPage = Math.floor(totalCount / pageSize) + 1;
  5. var likeSearch = '', typeSearch = '';
  6. function getData(page, module) {
  7. $.ajax({
  8. url : basePath + 'WFP?module=' + module + '&action=list',
  9. type : 'POST',
  10. data : {
  11. begin : (page - 1) * 20 + 1,
  12. limit : 20,
  13. likeSearch : likeSearch,
  14. typeSearch : typeSearch
  15. },
  16. success : function(json) {
  17. $("#tableContent").empty();
  18. $("#tableContent").height($("#tableContent").height());
  19. $("#sectionMain").children().hide();
  20. var obj = JSON.parse(json);
  21. total = obj.totalCount;
  22. pageSize = obj.limit;
  23. $.each(obj.data, function(index) {
  24. createTableContent(obj.data[index], module);
  25. });
  26. // 分页
  27. html = '';
  28. var lastPage = Math.ceil(total / pageSize);
  29. if (page > 1)
  30. html += '<li><a title="上一页" style="cursor:pointer" onclick="getData(' + (page - 1) + ',\''
  31. + module + '\')">&laquo;</a></li>';
  32. for ( var i = page - 2; i < page + 3; i++) {
  33. if (i > 0 && i <= lastPage) {
  34. html += '<li';
  35. if (i == page)
  36. html += ' class="active"';
  37. html += '><a style="cursor:pointer" onclick="getData(' + i + ',\'' + module
  38. + '\')">' + i + '</a></li>';
  39. }
  40. }
  41. if (lastPage != 0 && page != lastPage)
  42. html += '<li><a title="下一页" style="cursor:pointer" onclick="getData(' + (page + 1) + ',\''
  43. + module + '\')">&raquo;</a></li>';
  44. $("#pagination").html(html);
  45. $("#tableContent").find("a:first-child").trigger("click");
  46. }
  47. });
  48. }
  49. // 生成模版table内容
  50. function createTableContent(item, module) {
  51. var html = '';
  52. if (module === 'template') {
  53. html = '<a id="'
  54. + item.id
  55. + '" name="'
  56. + item.name
  57. + '" data-xml=\''
  58. + item.bpmnStr
  59. + '\' onclick="openTemp(this,\''
  60. + item.name
  61. + '\',\''
  62. + item.glCount
  63. + '\',\''
  64. + item.label
  65. + '\',\''
  66. + module
  67. + '\')" style="cursor:pointer" class="mbData list-group-item">'
  68. + '<small class="pull-right text-muted">' + item.createDateStr
  69. + '</small><div id="mbName" class="inline" data-toggle="tooltip" title="'+item.name+'" style="width:43%;font-weight:bold;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">' + item.name + '</div>'
  70. + '<div class="inline pull-right" style="width:35px"><b class="badge bg-default pull-left" style="font-weight:400;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;" data-toggle="tooltip" title="'
  71. + item.glCount + '">' +item.glCount + '</b></div>'
  72. + '<div class="inline" data-toggle="tooltip" title="'+item.label+'" style="width:100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">' + item.label + '</div></a>';
  73. $('#tableContent').append(html);
  74. } else if (module === 'definition') {
  75. //alert(item.templateName);
  76. html = '<a id="'+ item.id+ '" name="'+ item.name+ '" data-templateid = "'+item.glTemplateId+'"'
  77. + 'data-xml="" onclick="openTemp(this,\''
  78. + item.name
  79. + '\',\''
  80. + item.templateName
  81. + '\',\''
  82. + item.id
  83. + '\',\''
  84. + module
  85. + '\')" style="cursor:pointer" class="mbData list-group-item">'
  86. + '<small class="pull-right text-muted">'
  87. + item.createDateStr
  88. + '</small><div id="" class="inline" data-toggle="tooltip" title="'+item.name+'" style="width:100%;font-weight:bold;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">'
  89. + item.name
  90. + '</div>'
  91. +
  92. '<br /><div class="inline" data-toggle="tooltip" title="'+item.id+'" style="width:48%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">'
  93. + item.id
  94. + '</div><div class="inline pull-right" style="max-width:48%"><b class="badge bg-default pull-left" style="max-width:100%;background-color:white;color:black;font-weight:400;border:1px solid rgb(35, 212, 181);overflow: hidden;text-overflow: ellipsis;white-space: nowrap;" data-toggle="tooltip" title="'
  95. + item.templateName + '">' +item.templateName + '</b></div></a>';
  96. $('#tableContent').append(html);
  97. }else if (module === 'instance'){
  98. var status = '';
  99. switch(item.status)
  100. {
  101. case '2':
  102. status = '待办';
  103. break;
  104. case '5':
  105. status = '已办';
  106. break;
  107. case '99':
  108. status = '回退';
  109. break;
  110. case '3':
  111. status = '结束';
  112. break;
  113. }
  114. html = '<a id="'+ item.id+ '" name="'+ item.processdefinitionName+ '" data-templateId="'+item.templateId+'" data-nodeToId="" data-xml="" onclick="openTemp(this,\''
  115. + item.processdefinitionName
  116. + '\',\''
  117. + status
  118. + '\',\''
  119. + item.memo
  120. + '\',\''
  121. + module
  122. + '\')" style="cursor:pointer" class="mbData list-group-item">'
  123. + '<small class="pull-right text-muted">' + item.createDateStr+ '</small><div id="" class="inline" data-toggle="tooltip" title="'+item.processdefinitionName+'" style="width:49%;font-weight:bold;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">' + item.processdefinitionName + '</div>'
  124. + '<br /><div id="" class="inline" data-toggle="tooltip" title="'+item.memo+'" style="width:80%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">' + item.memo + '</div><span class="badge pull-right" style="display:inline-block;background-color:white;color:black;font-weight:400;border:1px solid rgb(35, 212, 181)" >' + status + '</span></a>';
  125. $('#tableContent').append(html);
  126. }
  127. }
  128. // 渲染具体的定义
  129. function openTemp(obj, name, glCount, label, module) {
  130. $("#sectionMain").children().show();
  131. $('#tempName').attr('title', name);
  132. $('#tempDesc').attr('title', label);
  133. $('#tempRelate').attr('title', glCount);
  134. $('#tableContent').children().removeClass('active');
  135. $(obj).addClass('active');
  136. $('#tempName').html(name);
  137. $('#tempRelate').html(glCount);
  138. $('#tempDesc').html(label);
  139. if(module === 'template'){
  140. showBpmn();
  141. }else if(module === 'definition'){
  142. if($(obj).find('.pull-right b').html()!=''){
  143. $('#unRelateDefinitionBtn').show();
  144. }else{
  145. $('#unRelateDefinitionBtn').hide();
  146. }
  147. var definitionId = $('#tableContent .active').attr('id');
  148. url = basePath + 'player/design/show.jsp?id='+ definitionId;
  149. $("#bpmnShow").attr('src',url);
  150. }else if(module === 'instance'){
  151. var instanceId = $('#tableContent .active').attr('id');
  152. url = basePath + 'player/design/play.jsp?id='+instanceId;
  153. $("#bpmnPlay").attr('src',url);
  154. }
  155. }
  156. // 渲染流程模版图
  157. function showBpmn() {
  158. var bpmnXml = $('#tableContent .active').attr('data-xml');
  159. $("#bpmnShow")[0].contentWindow.setXml(bpmnXml);
  160. }
  161. // 打开模态窗
  162. function openModal(title, url, height, width, button, isClickClose) {
  163. var html = '';
  164. var buttonHtml = '';
  165. if (button != null) {
  166. for (i = 0; i < button.length; i++) {
  167. if (button[i].type === 'close') {
  168. buttonHtml += '<button id="modalClose" type="button" class="btn btn-default" onclick="closeModal()">关闭</button>';
  169. } else if (button[i].type === 'save') {
  170. buttonHtml += '<button type="button" class="btn btn-primary" onclick="actChildFun(\'saveModel\')">保存</button>';
  171. } else {
  172. buttonHtml += '<button type="button" class="btn btn-primary" onclick="'
  173. + button[i].fun + '">' + button[i].text + '</button>';
  174. }
  175. }
  176. }
  177. html += '<div class="modal fade" id="myModal" style="display:flex"><div class="modal-content" ';
  178. html += 'style="margin:auto;height:' + height + 'px;width:' + width
  179. + 'px">';
  180. html += '<div class="modal-header"><button id="modalCloseIcon" type="button" class="close" onclick="closeModal()" >&times;</button><h4 class="modal-title" id="myModalLabel">';
  181. html += title + '</h4></div><div class="modal-body">';
  182. html += '<iframe id="myModalIFrame" src="' + url + '" style="height:';
  183. if(button==null||button.length==0){
  184. html += (height - 56);
  185. }else{
  186. html += (height - 120);
  187. }
  188. html += 'px;width:' + width
  189. + 'px;margin:-15px;margin-bottom:-20px;border:none"></iframe>';
  190. if(button!=null&&button.length!=0)
  191. html += '</div><div class="modal-footer">' + buttonHtml + '</div>';
  192. html += '</div></div>';
  193. $('body').append(html);
  194. $('body').find("#myModal").modal({backdrop: 'static', keyboard: false});
  195. }
  196. // 关闭模态窗
  197. function closeModal() {
  198. $('.modal-backdrop').remove();
  199. $('#myModal').remove();
  200. }
  201. // 触发子页面的方法
  202. function actChildFun(funName) {
  203. var funText = '$("#myModalIFrame")[0].contentWindow.' + funName + '()';
  204. eval(funText);
  205. }
  206. // 生成通用的保存、关闭按钮
  207. function createSaveAndClsBtn(isSave, isCls) {
  208. var btns = new Array();
  209. if (isSave) {
  210. var btn = new Object();
  211. btn.type = 'save';
  212. btns.push(btn);
  213. }
  214. if (isCls) {
  215. var btn = new Object();
  216. btn.type = 'close';
  217. btns.push(btn);
  218. }
  219. return btns;
  220. }
  221. function getCounts(module) {
  222. $.ajax({
  223. url : basePath + 'WFP?module=' + module + '&action=counts',
  224. type : 'POST',
  225. success : function(json) {
  226. var obj = JSON.parse(json);
  227. if(module === 'instance'){
  228. $('#temTotal').html(obj.total);
  229. $('#temTodo').html(obj.todo);
  230. $('#temDone').html(obj.done);
  231. $('#temBack').html(obj.back);
  232. $('#temEnd').html(obj.end);
  233. }
  234. $('#temCount').html(obj.total);
  235. $('#temRelateCount').html(obj.gls);
  236. $('#temUnrelateCount').html(obj.notGls);
  237. }
  238. });
  239. }
  240. //修复IE9下height100%不生效的样式问题
  241. function resetSectionHeight(){
  242. $('#sectionMain').height($(parent.document).height()-50);
  243. }