oaFlow.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. layui.define(['tool'], function (exports) {
  2. const layer = layui.layer;
  3. const form = layui.form;
  4. const tool = layui.tool;
  5. const dropdown = layui.dropdown;
  6. const opts={
  7. "flowBox":'flowBox',
  8. "flowBar":'flowBar',
  9. "callback": null
  10. };
  11. const obj = {
  12. loading:false,
  13. size:1.0,
  14. //节点模版
  15. nodeApend: function (types,nodeId) {
  16. let nodeHtml = '';
  17. if(types == 1){
  18. //审核人
  19. nodeHtml = `<div><div class="node-wrap">
  20. <div class="node-wrap-box">
  21. <div class="node-title" style="background:#ffb800;">
  22. <span class="user-edit">审核人</span>
  23. <i class="remove-node" data-id="${nodeId}">✖</i>
  24. </div>
  25. <div>
  26. <span>请设置审核人</span>
  27. <i class="select-icon"><?xml version="1.0" encoding="UTF-8"?><svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12L31 24L19 36" stroke="#333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></i>
  28. </div>
  29. </div>
  30. <div class="node-add-btn-box">
  31. <div class="add-node-btn">
  32. <button class="add-node">+</button>
  33. </div>
  34. </div>
  35. </div><div>`;
  36. }
  37. else if(types == 2){
  38. //抄送人
  39. nodeHtml = `<div><div class="node-wrap">
  40. <div class="node-wrap-box">
  41. <div class="node-title" style="background:#1e9fff;">
  42. <span class="user-edit">抄送人</span>
  43. <i class="remove-node" data-id="${nodeId}">✖</i>
  44. </div>
  45. <div>
  46. <span>请设置抄送人</span>
  47. <i class="select-icon"><?xml version="1.0" encoding="UTF-8"?><svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12L31 24L19 36" stroke="#333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></i>
  48. </div>
  49. </div>
  50. <div class="node-add-btn-box">
  51. <div class="add-node-btn">
  52. <button class="add-node">+</button>
  53. </div>
  54. </div>
  55. </div><div>`;
  56. }
  57. else if(types==3){
  58. //条件分支
  59. nodeHtml = `<div class="branch-wrap">
  60. <div class="branch-box-wrap">
  61. <div class="branch-box">
  62. <span class="add-branch" title="添加条件">添加条件分支</span>
  63. <div class="col-box">
  64. <div class="condition-node">
  65. <div class="condition-node-box">
  66. <div class="condition-judge">
  67. <div class="condition-title">
  68. <input type="text" class="condition-input" placeholder="条件1">
  69. <span class="condition-priority">优先级1</span>
  70. <i class="remove-node" data-id="${nodeId}">✖</i>
  71. </div>
  72. <div>
  73. 请设置条件
  74. </div>
  75. </div>
  76. <div class="node-add-btn-box">
  77. <div class="add-node-btn">
  78. <button class="add-node">+</button>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="top-left-cover-line"></div>
  84. <div class="bottom-left-cover-line"></div>
  85. </div>
  86. <div class="col-box">
  87. <div class="condition-node">
  88. <div class="condition-node-box">
  89. <div class="condition-judge">
  90. <div class="condition-title">
  91. <input type="text" class="condition-input" placeholder="其他情况">
  92. <span class="condition-priority">优先级2</span>
  93. </div>
  94. <div>
  95. 如存在未满足其他分支条件的情况,则进入此分支
  96. </div>
  97. </div>
  98. <div class="node-add-btn-box">
  99. <div class="add-node-btn">
  100. <button class="add-node">+</button>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. <div class="top-right-cover-line"></div>
  106. <div class="bottom-right-cover-line"></div>
  107. </div>
  108. </div>
  109. <div class="node-add-btn-box">
  110. <div class="add-node-btn">
  111. <button class="add-node">+</button>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>`;
  117. }
  118. else{
  119. //条件内容
  120. nodeHtml = `<div class="col-box">
  121. <div class="condition-node">
  122. <div class="condition-node-box">
  123. <div class="condition-judge">
  124. <div class="condition-title">
  125. <input type="text" class="condition-input" placeholder="条件1">
  126. <span class="condition-priority">优先级1</span>
  127. <i class="remove-node" data-id="${nodeId}">✖</i>
  128. </div>
  129. <div>
  130. 请设置条件
  131. </div>
  132. </div>
  133. <div class="node-add-btn-box">
  134. <div class="add-node-btn">
  135. <button class="add-node">+</button>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>`;
  141. }
  142. return nodeHtml;
  143. },
  144. init: function (options) {
  145. this.settings = $.extend({}, opts, options);
  146. let me = this;
  147. let flowBox = $('#'+me.settings.flowBox);
  148. let flowBar = $('#'+me.settings.flowBar);
  149. //添加节点
  150. flowBox.on("click",".add-node",function(e){
  151. let that = $(this);
  152. dropdown.render({
  153. elem: that,
  154. show: true, // 外部事件触发即显示
  155. data: [{
  156. title: '审 核 人',
  157. id: '1',
  158. templet: function(d){
  159. return '<i style="vertical-align: sub; color:red"><?xml version="1.0" encoding="UTF-8"?><svg width="20" height="20" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 36L8.00461 28.0426C8.00551 27.4906 8.45313 27.0432 9.00519 27.0426C12.3391 27.0426 15.6731 27.0426 19.0071 27.0426C19.9286 27.0426 19.9237 26.2252 19.9237 24.2792C19.9237 22.3332 15.0221 20.6941 15.0221 13.8528C15.0221 7.01151 20.0999 5 24.32 5C28.5401 5 33.1366 7.01151 33.1366 13.8528C33.1366 20.6941 28.2607 21.7818 28.2607 24.2792C28.2607 26.7765 28.2607 27.0426 29.0413 27.0426C32.3609 27.0426 35.6806 27.0426 39.0003 27.0426C39.5525 27.0426 40.0003 27.4904 40.0003 28.0426V36H8Z" fill="none" stroke="#ffb800" stroke-width="4" stroke-linejoin="round"/><path d="M8 42H40" stroke="#ffb800" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg></i> ' + d.title;
  160. }
  161. }, {
  162. title: '抄 送 人',
  163. id: '2',
  164. templet: function(d){
  165. return '<i style="vertical-align: sub; color:red"><?xml version="1.0" encoding="UTF-8"?><svg width="20" height="20" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M43 5L29.7 43L22.1 25.9L5 18.3L43 5Z" stroke="#1e9fff" stroke-width="4" stroke-linejoin="round"/><path d="M43.0001 5L22.1001 25.9" stroke="#1e9fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg></i> ' + d.title;
  166. }
  167. }, {
  168. title: '条件分支',
  169. id: '3',
  170. templet: function(d){
  171. return '<i style="vertical-align: sub; color:red"><?xml version="1.0" encoding="UTF-8"?><svg width="20" height="20" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M24 33V15" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><rect x="10" y="9" width="28" height="6" fill="none" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 32L14 25H33.9743L40 32" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><rect x="4" y="33" width="8" height="8" fill="none" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><rect x="20" y="33" width="8" height="8" fill="none" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><rect x="36" y="33" width="8" height="8" fill="none" stroke="#16b777" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg></i> ' + d.title;
  172. }
  173. }],
  174. click: function(data, othis){
  175. let timestamp = new Date().getTime();
  176. that.parent().parent().parent().parent().after(me.nodeApend(data.id,timestamp));
  177. }
  178. });
  179. });
  180. //添加条件
  181. flowBox.on("click",".add-branch",function(e){
  182. let timestamp = new Date().getTime();
  183. $(this).parent().find(".col-box").first().after(me.nodeApend(4,timestamp));
  184. let branchWrap = $($(this).parents(".branch-wrap")[0]);
  185. let colBbox = branchWrap.find('.col-box');
  186. colBbox.each(function(index,item){
  187. $(item).find('.condition-priority').html('优先级'+(index+1));
  188. if(index<colBbox.length-1){
  189. $(item).find('.condition-input').attr('placeholder','条件'+(index+1));
  190. }
  191. });
  192. })
  193. //删除节点、条件
  194. flowBox.on("click",".remove-node",function(e){
  195. if($(this).parents().hasClass("condition-judge")){
  196. let idx =$(this).closest('.col-box').index();
  197. let branchWrap = $($(this).parents(".branch-wrap")[0]);
  198. let colBbox = branchWrap.find('.col-box');
  199. if(colBbox.length==2 || idx==1){
  200. layer.confirm('确定需要删除整个条件分支?', {icon: 3}, function(){
  201. branchWrap.remove();
  202. layer.closeAll();
  203. });
  204. }
  205. else{
  206. $(this).closest(".col-box").remove();
  207. colBbox = branchWrap.find('.col-box');
  208. colBbox.each(function(index,item){
  209. $(item).find('.condition-priority').html('优先级'+(index+1));
  210. if(index<colBbox.length-1){
  211. $(item).find('.condition-input').attr('placeholder','条件'+(index+1));
  212. }
  213. });
  214. }
  215. }else if($(this).parents().hasClass("node-wrap")){
  216. $(this).closest(".node-wrap").parent().remove();
  217. }
  218. })
  219. //放大、缩小
  220. flowBar.on("click",".zoom-ctrl",function(e){
  221. let type = $(this).data('type'),size=1;
  222. if(type==1){
  223. size = me.size - 0.25;
  224. }
  225. else{
  226. size = me.size + 0.25;
  227. }
  228. if(size<=0){
  229. layer.msg('已经是最小了');
  230. return false;
  231. }
  232. else if(size>3){
  233. layer.msg('已经是最大了');
  234. return false;
  235. }
  236. me.size = size;
  237. flowBox.css("transform","scale("+size+")");
  238. flowBar.find('.zoom-num').html((size*100)+'%');
  239. })
  240. }
  241. };
  242. exports('oaFlow', obj);
  243. });