GooFlow.js 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161
  1. // 移除双击节点或连线编辑节点名或连线名
  2. // 追加不给决策节点连线
  3. // 移除连线方式,把原有的可改变设置开始端与结束端的方式移除。改为拖动连线方式,并且只能设置结束端的连线。
  4. // 流程图的连线规则,决策节点、结束节点,不能拖出连线
  5. // 开始节点只能有一条出的连线
  6. // 添加连线规则,结束端不能是开始节点
  7. // 改源代码加的打开模态框事件
  8. //定义一个区域图类:
  9. function GooFlow(bgDiv, property, vue) {
  10. if(navigator.userAgent.indexOf("MSIE 8.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0 || navigator.userAgent.indexOf("MSIE 6.0") > 0)
  11. GooFlow.prototype.useSVG = "";
  12. else GooFlow.prototype.useSVG = "1";
  13. //初始化区域图的对象
  14. this.$id = bgDiv.attr("id");
  15. this.$bgDiv = bgDiv; //最父框架的DIV
  16. this.$bgDiv.addClass("GooFlow");
  17. if(GooFlow.prototype.color.font) {
  18. this.$bgDiv.css("color", GooFlow.prototype.color.font);
  19. }
  20. if(GooFlow.prototype.color.main) {
  21. this.$bgDiv.append('<style>.GooFlow_tool_btndown{background:' + GooFlow.prototype.color.main + '}</style>');
  22. }
  23. var width = (property.width || 800);
  24. var height = (property.height || 500);
  25. this.$toolWidth = 0; // 追加工具栏的宽度
  26. this.$bgDiv.css({
  27. width: width + "px",
  28. height: height + "px"
  29. });
  30. this.$tool = null; //左侧工具栏对象
  31. this.$toolTitle; // 当前选中的节点标题
  32. this.$toolName; // 当前选中的节点名
  33. this.$Type; // 当前选中的节点名
  34. this.$head = null; //顶部标签及工具栏按钮
  35. this.$name = "newFlow_1"; //流程图的名称
  36. this.$key = 'newFlow_1';
  37. this.$nodeRemark = {}; //每一种结点或按钮的说明文字,JSON格式,key为类名,value为用户自定义文字说明
  38. this.$nowType = "cursor"; //当前要绘制的对象类型
  39. this.$lineData = {};
  40. this.$lineCount = 0;
  41. this.$nodeData = {};
  42. this.$nodeCount = 0;
  43. this.$areaData = {};
  44. this.$areaCount = 0;
  45. this.$lineDom = {};
  46. this.$nodeDom = {};
  47. this.$areaDom = {};
  48. this.$max = property.initNum || 1; //计算默认ID值的起始SEQUENCE
  49. this.$focus = ""; //当前被选定的结点/转换线ID,如果没选中或者工作区被清空,则为""
  50. this.$focuslineid = ""; // 选中线的id
  51. this.$cursor = "default"; //鼠标指针在工作区内的样式
  52. this.$editable = false; //工作区是否可编辑
  53. this.$deletedItem = {}; //在流程图的编辑操作中被删除掉的元素ID集合,元素ID为KEY,元素类型(node,line.area)为VALUE
  54. this.$workExtendStep = 200; //在自动/手动扩展可编辑区时,一次扩展后宽/高增加多少像素
  55. this.$headHeight = 0;
  56. var tmp = "";
  57. this.$vue = vue; // 自定义与 Vue 使用,可回调当前 Vue
  58. this.$haveGroup = property.haveGroup;
  59. this.$haveHead = property.haveHead;
  60. this.$toolBtnsAndName = property.toolBtnsAndName;
  61. this.$headClearance = (property.headClearance || 4) // 头间隙
  62. this.$end = false
  63. /**----------------------头部工具栏(开始)-------------------------------------**/
  64. if(this.$haveHead) {
  65. tmp = "<div class='GooFlow_head' " + (GooFlow.prototype.color.main ? "style='border-bottom-color:" + GooFlow.prototype.color.main + "'" : "") + ">";
  66. if(property.headLabel) {
  67. this.$name = property.initLabelText || this.$name;
  68. tmp += "<label title='" + this.$name + "' " +
  69. (GooFlow.prototype.color.main ? "style='background:" + GooFlow.prototype.color.main + "'" : "") + ">" + this.$name + "</label>";
  70. }
  71. for(var x = 0; x < property.headBtns.length; ++x) {
  72. tmp += "<a href='javascript:void(0)' class='GooFlow_head_btn'><i class='ico_" + property.headBtns[x] + "'></i></a>"
  73. }
  74. tmp += "</div>";
  75. this.$head = $(tmp);
  76. this.$bgDiv.append(this.$head);
  77. this.$headHeight = 28;
  78. //以下是当工具栏按钮被点击时触发的事件自定义(虚函数),格式为function(),因为可直接用THIS操作对象本身,不用传参;用户可自行重定义:
  79. this.onBtnNewClick = null; //新建流程图按钮被点中
  80. this.onBtnOpenClick = null; //打开流程图按钮定义
  81. this.onBtnSaveClick = null; //保存流程图按钮定义
  82. this.onFreshClick = null; //重载流程图按钮定义
  83. this.onPrintClick = null; //打印流程图按钮定义
  84. // 是否有顶部的操作按钮
  85. if(property.headBtns) {
  86. /**
  87. * 顶部工具栏的点击事件
  88. */
  89. this.$head.on("click", {
  90. inthis: this
  91. }, function(e) {
  92. if(!e) e = window.event;
  93. var tar = e.target;
  94. if(tar.tagName == "DIV" || tar.tagName == "SPAN") return;
  95. else if(tar.tagName == "A") tar = tar.childNodes[0];
  96. var This = e.data.inthis;
  97. //定义顶部操作栏按钮的事件
  98. switch($(tar).attr("class")) {
  99. case "ico_new":
  100. if(This.onBtnNewClick != null) This.onBtnNewClick();// 新建流程图
  101. break;
  102. case "ico_open":
  103. if(This.onBtnOpenClick != null) This.onBtnOpenClick();// 打开流程图
  104. break;
  105. case "ico_save":
  106. if(This.onBtnSaveClick != null) This.onBtnSaveClick();// 保存流程图
  107. break;
  108. case "ico_undo":
  109. This.undo();// 撤回
  110. break;
  111. case "ico_redo":
  112. This.redo();// 重做
  113. break;
  114. case "ico_reload":
  115. if(This.onFreshClick != null) This.onFreshClick();// 重载流程图
  116. break;
  117. case "ico_print":
  118. if(This.onPrintClick != null) This.onPrintClick();// 打印流程图
  119. break;
  120. }
  121. });
  122. }
  123. }
  124. /**----------------------头部工具栏(结束)-------------------------------------**/
  125. /**----------------------左边工具栏(开始)-------------------------------------**/
  126. if(property.haveTool) {
  127. this.$toolWidth = (property.toolWidth || 60); // 有左边工具栏才设置宽度,默认 60
  128. var toolNodeWidth = this.$toolWidth - 10;
  129. this.$bgDiv.append("<div class='GooFlow_tool'" + (this.$haveHead ? "" : " style='margin-top:" + this.$headClearance + "px'") + "><div style='height:" + (height - this.$headHeight - (this.$haveHead ? 5 : 8)) + "px;' class='GooFlow_tool_div'></div></div>");
  130. this.$tool = this.$bgDiv.find(".GooFlow_tool div");
  131. // 左边工具栏的图片设置
  132. //未加代码:加入绘图工具按钮
  133. this.$tool.append(
  134. "<a href='javascript:void(0)' type='undo' title='撤回' class='GooFlow_tool_btn' id='" + this.$id + "_btn_undo' style='width:" + toolNodeWidth + "px;' ><i class='spaceicon icon-restore'/>撤回</a>" +
  135. "<a href='javascript:void(0)' type='redo' title='重做' class='GooFlow_tool_btn' id='" + this.$id + "_btn_redo' style='width:" + toolNodeWidth + "px;' ><i class='spaceicon icon-reload'/>重做</a>" +
  136. "<span/>" +
  137. "<a href='javascript:void(0)' type='cursor' title='选择' class='GooFlow_tool_btndown' id='" + this.$id + "_btn_cursor' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-choose'/>选择</a>" +
  138. "<a href='javascript:void(0)' type='direct' title='连线' class='GooFlow_tool_btn' id='" + this.$id + "_btn_direct' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-arrows'/>连线</a>" +
  139. "<a href='javascript:void(0)' type='fork' title='分支' class='GooFlow_tool_btn' id='" + this.$id + "_btn_fork' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-branch'/>分支</a>" +
  140. "<a href='javascript:void(0)' type='join' title='汇合' class='GooFlow_tool_btn' id='" + this.$id + "_btn_join' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-join'/>汇合</a>" +
  141. "<a href='javascript:void(0)' type='decision' title='决策' class='GooFlow_tool_btn' id='" + this.$id + "_btn_decision' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-decision'/>决策</a>" +
  142. "<a href='javascript:void(0)' type='end' title='结束' class='GooFlow_tool_btn' id='" + this.$id + "_btn_end' style='width:" + toolNodeWidth + "px;'><i class='spaceicon icon-finish'/>结束</a>"
  143. );
  144. // 读取后台数据生成的工具
  145. if(this.$toolBtnsAndName && this.$toolBtnsAndName.length > 0) {
  146. tmp = "<span/>";
  147. for(var i = 0; i < this.$toolBtnsAndName.length; ++i) {
  148. var icon = 'spaceicon icon-node2';
  149. // 任务节点
  150. if('task' == this.$toolBtnsAndName[i].type) {
  151. icon = 'spaceicon icon-node2';
  152. }
  153. // 动态并行节点
  154. else if ('foreach' == this.$toolBtnsAndName[i].type) {
  155. icon = 'spaceicon icon-dynamic_parallel';
  156. }
  157. // 加入自定义按钮
  158. tmp += "<a href='javascript:void(0)' type='" + this.$toolBtnsAndName[i].type +
  159. "' title='" + this.$toolBtnsAndName[i].title +
  160. "' id='" + this.$id + "_btn_" + this.$toolBtnsAndName[i].type + "_" + i +
  161. "' class='GooFlow_tool_btn' style='width:" + toolNodeWidth + "px;' data-name='" + this.$toolBtnsAndName[i].name +
  162. "'><i class='" + icon + "'/>" + this.$toolBtnsAndName[i].title + "</a>";
  163. }
  164. this.$tool.append(tmp);
  165. }
  166. //加入区域划分框工具开关按钮
  167. // if(this.$haveGroup)
  168. // this.$tool.append("<span/><a href='javascript:void(0)' type='group' class='GooFlow_tool_btn' id='" + this.$id + "_btn_group'><i class='ico_group'/></a>");
  169. this.$nowType = "cursor";
  170. /**----------------------左边工具栏的拖动到 GooFlow 的画布区域(开始)-------------------------------------**/
  171. // 拖动工具栏的节点到 GooFlow 的画布区域
  172. this.$tool.find('a').on("mousedown", {
  173. inthis: this
  174. }, function(e) {
  175. if(!e) e = window.event;
  176. var tar;
  177. switch(e.target.tagName) { // 获取标签的名称,如:<div></div>,则是DIV或div
  178. case "SPAN":
  179. return false;
  180. case "DIV":
  181. return false;
  182. case "I":
  183. tar = e.target.parentNode; //获取父标签
  184. break;
  185. case "A":
  186. tar = e.target;
  187. };
  188. var type = $(tar).attr("type");
  189. switch(type) {
  190. case "undo": // 撤回
  191. case "redo": // 重做
  192. case "cursor": // 选择
  193. case "direct": // 连线
  194. return false;
  195. }
  196. e.data.inthis.switchToolBtn(type, $(tar).attr('id'));
  197. var This = e.data.inthis;
  198. var ev = mousePosition(e),
  199. t = getElCoordinate(This.$workArea[0]);
  200. var X, Y;
  201. X = ev.x - t.left;
  202. Y = ev.y - t.top;
  203. var vX = X - 0,
  204. vY = Y - 0;
  205. var width = This.getWidth(null, This.$nowType)
  206. var height = This.getHeight(null, This.$nowType)
  207. var td = "<td></td><td>" + This.$toolTitle + "</td>";
  208. if('end' == This.$nowType) {
  209. td = "<td><i class='spaceicon icon-finish'></i></td>";
  210. }
  211. $('<table cellspacing="1" style="width:' + width + 'px;height:' + height + 'px;"><tbody><tr>' + td + '</tr></tbody></table>').prependTo(This.$ghost);
  212. var isMove = false;// 是否移动中,
  213. // 从左边工具栏拖动到画布还未释放时事件(未释放事件)
  214. document.onmousemove = function(e) {
  215. if(!e) e = window.event;
  216. var ev = mousePosition(e);
  217. if(X == ev.x - vX && Y == ev.y - vY) return false;
  218. X = ev.x - (width / 2);
  219. Y = ev.y - (height / 2);
  220. if(isMove && This.$ghost.css("display") == "none") {
  221. This.$ghost.css({
  222. display: "block",
  223. width: width + "px",
  224. height: height + "px",
  225. top: t.top - This.$workArea[0].parentNode.scrollTop + "px",
  226. left: t.left - This.$workArea[0].parentNode.scrollLeft + "px",
  227. cursor: "move",
  228. 'border-radius': '20px'
  229. });
  230. if(This.$nowType == 'decision') {
  231. This.$ghost.css({
  232. 'border-radius': ''
  233. });
  234. }
  235. }
  236. if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
  237. X = t.left - This.$workArea[0].parentNode.scrollLeft;
  238. else if(X + This.$workArea[0].parentNode.scrollLeft + width > t.left + This.$workArea.width())
  239. X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - width;
  240. if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
  241. Y = t.top - This.$workArea[0].parentNode.scrollTop;
  242. else if(Y + This.$workArea[0].parentNode.scrollTop + height > t.top + This.$workArea.height())
  243. Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - height;
  244. This.$ghost.css({
  245. left: X + "px",
  246. top: Y + "px"
  247. });
  248. isMove = true;
  249. }
  250. // 已释放时事件
  251. document.onmouseup = function(e) {
  252. if(isMove) {
  253. var nodeItemJson = {
  254. id: "node_" + This.$max,
  255. name: This.$toolName,
  256. title: This.$toolTitle,
  257. left: X + This.$workArea[0].parentNode.scrollLeft - t.left,
  258. top: Y + This.$workArea[0].parentNode.scrollTop - t.top,
  259. type: type
  260. };
  261. // 节点名不能使用任务类型的名称
  262. This.addNode("node_" + This.$max, nodeItemJson);
  263. This.$max++;
  264. }
  265. This.$ghost.empty().hide();
  266. This.switchToolBtn("cursor");
  267. document.onmousemove = null;
  268. document.onmouseup = null;
  269. }
  270. return false;
  271. });
  272. /**----------------------左边工具栏的拖动到 GooFlow 的画布区域(结束)-------------------------------------**/
  273. /**----------------------左边工具栏的点击选中事件(开始)-------------------------------------**/
  274. //绑定各个按钮的点击事件
  275. this.$tool.on("click", {
  276. inthis: this
  277. }, function(e) {
  278. if(!e) e = window.event;
  279. var tar;
  280. switch(e.target.tagName) { // 获取标签的名称,如:<div></div>,则是DIV或div
  281. case "SPAN":
  282. return false;
  283. case "DIV":
  284. return false;
  285. case "I":
  286. tar = e.target.parentNode; //获取父标签
  287. break;
  288. case "A":
  289. tar = e.target;
  290. };
  291. var type = $(tar).attr("type");
  292. switch(type) {
  293. case "undo": // 撤回
  294. e.data.inthis.undo();
  295. return false;
  296. case "redo": // 重做
  297. e.data.inthis.redo();
  298. return false;
  299. }
  300. e.data.inthis.switchToolBtn(type, $(tar).attr('id'));
  301. return false;
  302. });
  303. /**----------------------左边工具栏的点击选中事件(结束)-------------------------------------**/
  304. this.$editable = true; //只有具有工具栏时可编辑
  305. }
  306. /**----------------------左边工具栏(结束)-------------------------------------**/
  307. width = width - this.$toolWidth;
  308. height = height - this.$headHeight - (this.$haveHead ? 5 : 8);
  309. this.$bgDiv.append("<div class='GooFlow_work' style='width:" + width + "px;height:" + (height) + "px;" + (this.$haveHead ? "" : "margin-top:" + this.$headClearance + "px") + "'></div>");
  310. this.$workArea = $("<div class='GooFlow_work_inner' style='width:" + width + "px;height:" + height + "px'></div>")
  311. .attr({
  312. "unselectable": "on",
  313. "onselectstart": 'return false',
  314. "onselect": 'document.selection.empty()'
  315. });
  316. this.$bgDiv.children(".GooFlow_work").append(this.$workArea);
  317. this.$draw = null; //画矢量线条的容器
  318. this.initDraw("draw_" + this.$id, width, height);
  319. this.$group = null;
  320. if(this.$haveGroup)
  321. this.initGroup(width, height);
  322. this.initExpendFunc();
  323. if(this.$editable) {
  324. // 工作区间
  325. this.$workArea.on("click", {
  326. inthis: this
  327. }, function(e) {
  328. if(!e) e = window.event;
  329. if(!e.data.inthis.$editable) return;
  330. var type = e.data.inthis.$nowType;
  331. // 移除选中状态
  332. if(type == "cursor") {
  333. var t = $(e.target);
  334. var n = t.prop("tagName");
  335. if(n == "svg" || (n == "DIV" && t.prop("class").indexOf("GooFlow_work") > -1) || n == "LABEL") {
  336. e.data.inthis.blurItem();
  337. e.data.inthis.$vue.clearCurrentFocus();
  338. }
  339. var tmp = document.getElementById("GooFlow_tmp_line");
  340. if(tmp) {
  341. tmp.remove()
  342. }
  343. return;
  344. } else if(type == "direct" || type == "group") return;
  345. })
  346. //划线或改线时用的绑定
  347. this.$workArea.mousemove({
  348. inthis: this
  349. }, function(e) {
  350. if(e.data.inthis.$nowType != "direct" && !e.data.inthis.$mpTo.data("p")) return;
  351. var lineStart = $(this).data("lineStart");
  352. var lineEnd = $(this).data("lineEnd");
  353. if(!lineStart && !lineEnd) return;
  354. var ev = mousePosition(e),
  355. t = getElCoordinate(this);
  356. var X, Y;
  357. X = ev.x - t.left + this.parentNode.scrollLeft;
  358. Y = ev.y - t.top + this.parentNode.scrollTop;
  359. var line = document.getElementById("GooFlow_tmp_line");
  360. if (line == null || line.childNodes == null) return
  361. if(lineStart) {
  362. if(GooFlow.prototype.useSVG != "") {
  363. line.childNodes[0].setAttribute("d", "M " + lineStart.x + " " + lineStart.y + " L " + X + " " + Y);
  364. line.childNodes[1].setAttribute("d", "M " + lineStart.x + " " + lineStart.y + " L " + X + " " + Y);
  365. if(line.childNodes[1].getAttribute("marker-end") == "url(\"#arrow2\")")
  366. line.childNodes[1].setAttribute("marker-end", "url(#arrow3)");
  367. else line.childNodes[1].setAttribute("marker-end", "url(#arrow2)");
  368. } else line.points.value = lineStart.x + "," + lineStart.y + " " + X + "," + Y;
  369. } else if(lineEnd) {
  370. if(GooFlow.prototype.useSVG != "") {
  371. line.childNodes[0].setAttribute("d", "M " + X + " " + Y + " L " + lineEnd.x + " " + lineEnd.y);
  372. line.childNodes[1].setAttribute("d", "M " + X + " " + Y + " L " + lineEnd.x + " " + lineEnd.y);
  373. if(line.childNodes[1].getAttribute("marker-end") == "url(\"#arrow2\")")
  374. line.childNodes[1].setAttribute("marker-end", "url(#arrow3)");
  375. else line.childNodes[1].setAttribute("marker-end", "url(#arrow2)");
  376. } else line.points.value = X + "," + Y + " " + lineEnd.x + "," + lineEnd.y;
  377. }
  378. });
  379. this.$workArea.mouseup({
  380. inthis: this
  381. }, function(e) {
  382. var This = e.data.inthis;
  383. if(This.$nowType != "direct" && !This.$mpTo.data("p")) return;
  384. var tmp = document.getElementById("GooFlow_tmp_line");
  385. if(tmp) {
  386. $(this).css("cursor", "auto").removeData("lineStart").removeData("lineEnd");
  387. This.$mpTo.hide().removeData("p");
  388. This.$mpFrom.hide().removeData("p");
  389. This.$draw.removeChild(tmp);
  390. This.focusItem(This.$focus, false);
  391. } else {
  392. This.$lineOper.removeData("tid");
  393. }
  394. });
  395. //为了结点而增加的一些集体delegate绑定
  396. this.initWorkForNode();
  397. //对结点进行移动或者RESIZE时用来显示的遮罩层
  398. this.$ghost = $("<div class='rs_ghost'></div>").attr({
  399. "unselectable": "on",
  400. "onselectstart": 'return false',
  401. "onselect": 'document.selection.empty()'
  402. });
  403. this.$bgDiv.append(this.$ghost);
  404. this.$textArea = $("<textarea></textarea>");
  405. this.$bgDiv.append(this.$textArea);
  406. this.$lineMove = $('<div class="GooFlow_linemove" style="display:none"></div>'); //操作折线时的移动框
  407. this.$workArea.append(this.$lineMove);
  408. this.$lineMove.on("mousedown", {
  409. inthis: this
  410. }, function(e) {
  411. if(e.button == 2) return false;
  412. var lm = $(this);
  413. lm.css({
  414. "background-color": "#333"
  415. });
  416. var This = e.data.inthis;
  417. var ev = mousePosition(e),
  418. t = getElCoordinate(This.$workArea[0]);
  419. var X, Y;
  420. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  421. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  422. var p = This.$lineMove.position();
  423. var vX = X - p.left,
  424. vY = Y - p.top;
  425. var isMove = false;
  426. document.onmousemove = function(e) {
  427. if(!e) e = window.event;
  428. var ev = mousePosition(e);
  429. var ps = This.$lineMove.position();
  430. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  431. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  432. if(This.$lineMove.data("type") == "lr") {
  433. X = X - vX;
  434. if(X < 0) X = 0;
  435. else if(X > This.$workArea.width())
  436. X = This.$workArea.width();
  437. This.$lineMove.css({
  438. left: X + "px"
  439. });
  440. } else if(This.$lineMove.data("type") == "tb") {
  441. Y = Y - vY;
  442. if(Y < 0) Y = 0;
  443. else if(Y > This.$workArea.height())
  444. Y = This.$workArea.height();
  445. This.$lineMove.css({
  446. top: Y + "px"
  447. });
  448. }
  449. isMove = true;
  450. }
  451. document.onmouseup = function(e) {
  452. if(isMove) {
  453. var p = This.$lineMove.position();
  454. if(This.$lineMove.data("type") == "lr")
  455. This.setLineM(This.$lineMove.data("tid"), p.left + 3);
  456. else if(This.$lineMove.data("type") == "tb")
  457. This.setLineM(This.$lineMove.data("tid"), p.top + 3);
  458. }
  459. This.$lineMove.css({
  460. "background-color": "transparent"
  461. });
  462. if(This.$focus == This.$lineMove.data("tid")) {
  463. This.focusItem(This.$lineMove.data("tid"));
  464. }
  465. document.onmousemove = null;
  466. document.onmouseup = null;
  467. }
  468. });
  469. //选定一条转换线后出现的浮动操作栏,有改变线的样式和删除线等按钮。
  470. this.$lineOper = $("<div class='GooFlow_line_oper' style='display:none'><i class='b_l1'></i><i class='b_l2'></i><i class='b_l3'></i><i class='b_x'></i></div>"); //选定线时显示的操作框
  471. this.$workArea.parent().append(this.$lineOper);
  472. this.$lineOper.on("click", {
  473. inthis: this
  474. }, function(e) {
  475. if(!e) e = window.event;
  476. if(e.target.tagName != "I") return;
  477. var This = e.data.inthis;
  478. // var id = $(this).data("tid");
  479. var id = This.$focuslineid;
  480. switch($(e.target).attr("class")) {
  481. case "b_x":
  482. This.delLine(id);
  483. this.style.display = "none";
  484. break;
  485. case "b_l1":
  486. This.setLineType(id, "lr");
  487. break;
  488. case "b_l2":
  489. This.setLineType(id, "tb");
  490. break;
  491. case "b_l3":
  492. This.setLineType(id, "sl");
  493. break;
  494. }
  495. });
  496. //新增移动线两个端点至新的结点功能移动功能,这里要提供移动用的DOM
  497. this.$mpFrom = $("<div class='GooFlow_line_mp' style='display:none'></div>");
  498. this.$mpTo = $("<div class='GooFlow_line_mp' style='display:none'></div>");
  499. this.$workArea.append(this.$mpFrom).append(this.$mpTo);
  500. this.initLinePointsChg();
  501. //下面绑定当结点/线/分组块的一些操作事件,这些事件可直接通过this访问对象本身
  502. //当操作某个单元(结点/线/分组块)被添加时,触发的方法,返回FALSE可阻止添加事件的发生
  503. //格式function(id,type,json):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,json即addNode,addLine或addArea方法的第二个传参json.
  504. this.onItemAdd = null;
  505. //当操作某个单元(结点/线/分组块)被删除时,触发的方法,返回FALSE可阻止删除事件的发生
  506. //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值
  507. this.onItemDel = null;
  508. //当操作某个单元(结点/分组块)被移动时,触发的方法,返回FALSE可阻止移动事件的发生
  509. //格式function(id,type,left,top):id是单元的唯一标识ID,type是单元的种类,有"node","area"两种取值,线line不支持移动,left是新的左边距坐标,top是新的顶边距坐标
  510. this.onItemMove = null;
  511. //当操作某个单元(结点/线/分组块)被重命名时,触发的方法,返回FALSE可阻止重命名事件的发生
  512. //格式function(id,name,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,name是新的名称
  513. this.onItemRename = null;
  514. //当操作某个单元(结点/线)被由不选中变成选中时,触发的方法,返回FALSE可阻止选中事件的发生
  515. //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被选中
  516. this.onItemFocus = null;
  517. //当操作某个单元(结点/线)被由选中变成不选中时,触发的方法,返回FALSE可阻止取消选中事件的发生
  518. //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被取消选中
  519. this.onItemBlur = null;
  520. //当操作某个单元(结点/分组块)被重定义大小或造型时,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
  521. //格式function(id,type,width,height):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值;width是新的宽度,height是新的高度
  522. this.onItemResize = null;
  523. //当移动某条折线中段的位置,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
  524. //格式function(id,M):id是单元的唯一标识ID,M是中段的新X(或Y)的坐标
  525. this.onLineMove = null;
  526. //当变换某条连接线的类型,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
  527. //格式function(id,type):id是单元的唯一标识ID,type是连接线的新类型,"sl":直线,"lr":中段可左右移动的折线,"tb":中段可上下移动的折线
  528. this.onLineSetType = null;
  529. //当变换某条连接线的端点变更连接的结点时,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
  530. //格式function(id,newStart,newEnd):id是连线单元的唯一标识ID,newStart,newEnd分别是起始结点的ID和到达结点的ID
  531. this.onLinePointMove = null;
  532. //当用重色标注某个结点/转换线时触发的方法,返回FALSE可阻止重定大小/造型事件的发生
  533. //格式function(id,type,mark):id是单元的唯一标识ID,type是单元类型("node"结点,"line"转换线),mark为布尔值,表示是要标注TRUE还是取消标注FALSE
  534. this.onItemMark = null;
  535. if(property.useOperStack && this.$editable) { //如果要使用堆栈记录操作并提供“撤销/重做”的功能,只在编辑状态下有效
  536. this.$undoStack = [];
  537. this.$redoStack = [];
  538. this.$isUndo = 0;
  539. ///////////////以下是构造撤销操作/重做操作的方法
  540. //为了节省浏览器内存空间,undo/redo中的操作缓存栈,最多只可放40步操作;超过40步时,将自动删掉最旧的一个缓存
  541. this.pushOper = function(funcName, paras) {
  542. var len = this.$undoStack.length;
  543. if(this.$isUndo == 1) {
  544. this.$redoStack.push([funcName, paras]);
  545. this.$isUndo = false;
  546. if(this.$redoStack.length > 40) this.$redoStack.shift();
  547. } else {
  548. this.$undoStack.push([funcName, paras]);
  549. if(this.$undoStack.length > 40) this.$undoStack.shift();
  550. if(this.$isUndo == 0) {
  551. this.$redoStack.splice(0, this.$redoStack.length);
  552. }
  553. this.$isUndo = 0;
  554. }
  555. };
  556. //将外部的方法加入到GooFlow对象的事务操作堆栈中,在过后的undo/redo操作中可以进行控制,一般用于对流程图以外的附加信息进行编辑的事务撤销/重做控制;
  557. //传参func为要执行方法对象,jsonPara为外部方法仅有的一个面向字面的JSON传参,由JSON对象带入所有要传的信息;
  558. //提示:为了让外部方法能够被UNDO/REDO,需要在编写这些外部方法实现时,加入对该方法执行后效果回退的另一个执行方法的pushExternalOper
  559. this.pushExternalOper = function(func, jsonPara) {
  560. this.pushOper("externalFunc", [func, jsonPara]);
  561. };
  562. //撤销上一步操作
  563. this.undo = function() {
  564. if(this.$undoStack.length == 0) return;
  565. this.blurItem();
  566. var tmp = this.$undoStack.pop();
  567. this.$isUndo = 1;
  568. if(tmp[0] == "externalFunc") {
  569. tmp[1][0](tmp[1][1]);
  570. } else {
  571. //传参的数量,最多支持6个.
  572. switch(tmp[1].length) {
  573. case 0:
  574. this[tmp[0]]();
  575. break;
  576. case 1:
  577. this[tmp[0]](tmp[1][0]);
  578. break;
  579. case 2:
  580. this[tmp[0]](tmp[1][0], tmp[1][1]);
  581. break;
  582. case 3:
  583. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2]);
  584. break;
  585. case 4:
  586. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3]);
  587. break;
  588. case 5:
  589. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4]);
  590. break;
  591. case 6:
  592. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4], tmp[1][5]);
  593. break;
  594. }
  595. }
  596. };
  597. //重做最近一次被撤销的操作
  598. this.redo = function() {
  599. if(this.$redoStack.length == 0) return;
  600. this.blurItem();
  601. var tmp = this.$redoStack.pop();
  602. this.$isUndo = 2;
  603. if(tmp[0] == "externalFunc") {
  604. tmp[1][0](tmp[1][1]);
  605. } else {
  606. //传参的数量,最多支持6个.
  607. switch(tmp[1].length) {
  608. case 0:
  609. this[tmp[0]]();
  610. break;
  611. case 1:
  612. this[tmp[0]](tmp[1][0]);
  613. break;
  614. case 2:
  615. this[tmp[0]](tmp[1][0], tmp[1][1]);
  616. break;
  617. case 3:
  618. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2]);
  619. break;
  620. case 4:
  621. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3]);
  622. break;
  623. case 5:
  624. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4]);
  625. break;
  626. case 6:
  627. this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4], tmp[1][5]);
  628. break;
  629. }
  630. }
  631. };
  632. }
  633. $(document).keydown({
  634. inthis: this
  635. }, function(e) {
  636. //绑定键盘操作
  637. var This = e.data.inthis;
  638. if(This.$focus == "") return;
  639. switch(e.keyCode) {
  640. case 46: //删除
  641. This.delNode(This.$focus, true);
  642. This.delLine(This.$focus);
  643. break;
  644. }
  645. });
  646. }
  647. }
  648. GooFlow.prototype = {
  649. // 获取节点的初始宽度(生成节点时使用)
  650. getWidth: function(oldWidth, type) {
  651. if(!oldWidth) {
  652. if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
  653. oldWidth = 34;
  654. } else if(type.indexOf("fork") != -1) {
  655. oldWidth = 56;
  656. } else if(type.indexOf("join") != -1) {
  657. oldWidth = 44;
  658. } else if(type.indexOf('decision') != -1) {
  659. oldWidth = 44;
  660. } else {
  661. oldWidth = 104;
  662. }
  663. }
  664. return oldWidth
  665. },
  666. // 获取节点的初始高度(生成节点时使用)
  667. getHeight: function(oldHeight, type) {
  668. if(!oldHeight) {
  669. if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
  670. oldHeight = 34;
  671. } else if(type.indexOf("fork") != -1) {
  672. oldHeight = 42;
  673. } else if(type.indexOf("join") != -1) {
  674. oldHeight = 44;
  675. } else if(type.indexOf("task") != -1) {
  676. oldHeight = 40;
  677. } else if(type.indexOf('decision') != -1) {
  678. oldHeight = 44;
  679. } else {
  680. oldHeight = 36;
  681. }
  682. }
  683. return oldHeight
  684. },
  685. // 根据节点类型获取最小宽度(拖动节点时使用)
  686. getNodeTypeMinWidth: function(oldWidth, type) {
  687. if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
  688. oldWidth = oldWidth < 34 ? 34 : oldWidth;
  689. } else if(type.indexOf("fork") != -1) {
  690. oldWidth = oldWidth < 56 ? 56 : oldWidth;
  691. } else if(type.indexOf("join") != -1) {
  692. oldWidth = oldWidth < 44 ? 44 : oldWidth;
  693. } else if(type.indexOf('decision') != -1) {
  694. oldWidth = oldWidth < 44 ? 44 : oldWidth;
  695. } else {
  696. oldWidth = oldWidth < 104 ? 104 : oldWidth;
  697. }
  698. if (oldWidth % 2 != 0) {
  699. oldWidth++
  700. }
  701. return oldWidth
  702. },
  703. // 根据节点类型获取最小高度(拖动节点时使用)
  704. getNodeTypeMinHeight: function(oldHeight, type) {
  705. if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
  706. oldHeight = oldHeight < 34 ? 34 : oldHeight;
  707. } else if(type.indexOf("fork") != -1) {
  708. oldHeight = oldHeight < 42 ? 42 : oldHeight;
  709. } else if(type.indexOf("join") != -1) {
  710. oldHeight = oldHeight < 44 ? 44 : oldHeight;
  711. } else if(type.indexOf("task") != -1) {
  712. oldHeight = oldHeight < 40 ? 40 : oldHeight;
  713. } else if(type.indexOf('decision') != -1) {
  714. oldHeight = oldHeight < 44 ? 44 : oldHeight;
  715. } else {
  716. oldHeight = oldHeight < 36 ? 36 : oldHeight;
  717. }
  718. if (oldHeight % 2 != 0) {
  719. oldHeight++
  720. }
  721. return oldHeight
  722. },
  723. // 窗口改变宽度时,重新调整 GooFlow 的画布窗口
  724. resizeGooFlow: function(width, height) {
  725. this.$bgDiv.css({
  726. width: width + "px",
  727. height: height + "px"
  728. });
  729. width = width - this.$toolWidth;
  730. height = height - this.$headHeight - (this.$haveHead ? 5 : 8);
  731. this.$bgDiv.find('.GooFlow_work').css({
  732. width: width + "px",
  733. height: height + "px"
  734. });
  735. this.$bgDiv.find('.GooFlow_tool_div').css({
  736. height: height + "px"
  737. });
  738. this.$bgDiv.find('.GooFlow_work_inner').css({
  739. width: width + "px",
  740. height: height + "px"
  741. })
  742. if(this.$haveGroup)
  743. this.$bgDiv.find('.GooFlow_work_group').css({
  744. width: width + "px",
  745. height: height + "px"
  746. })
  747. this.$bgDiv.find('#' + this.$draw.id).css({
  748. width: width + "px",
  749. height: height + "px"
  750. })
  751. },
  752. useSVG: "",
  753. getSvgMarker: function(id, color) {
  754. var m = document.createElementNS("http://www.w3.org/2000/svg", "marker");
  755. m.setAttribute("id", id);
  756. m.setAttribute("viewBox", "0 0 6 6");
  757. m.setAttribute("refX", 5);
  758. m.setAttribute("refY", 3);
  759. m.setAttribute("markerUnits", "strokeWidth");
  760. m.setAttribute("markerWidth", 6);
  761. m.setAttribute("markerHeight", 6);
  762. m.setAttribute("orient", "auto");
  763. var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
  764. path.setAttribute("d", "M 0 0 L 6 3 L 0 6 z");
  765. path.setAttribute("fill", color);
  766. path.setAttribute("stroke-width", 0);
  767. m.appendChild(path);
  768. return m;
  769. },
  770. /**
  771. * 初始化画布的工作区域
  772. * @param {Object} id 画布的 id
  773. * @param {Object} width 画布的宽度
  774. * @param {Object} height 画布的高度
  775. */
  776. initDraw: function(id, width, height) {
  777. // 画布区域使用 svg 还是传统的 html 标签,低版本的浏览器不支持 svg
  778. if(GooFlow.prototype.useSVG != "") {
  779. this.$draw = document.createElementNS("http://www.w3.org/2000/svg", "svg"); //可创建带有指定命名空间的元素节点
  780. this.$workArea.prepend(this.$draw);
  781. var defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
  782. this.$draw.appendChild(defs);
  783. // 生成箭头的颜色
  784. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow1", GooFlow.prototype.color.line || "#74bccb"));
  785. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow2", GooFlow.prototype.color.mark || "#ff8800"));
  786. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow3", GooFlow.prototype.color.mark || "#ff8800"));
  787. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow4", GooFlow.prototype.color.mark || "#65c239"));// 已审的颜色
  788. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow5", GooFlow.prototype.color.mark || "#409efe"));// 审核中的颜色
  789. defs.appendChild(GooFlow.prototype.getSvgMarker("arrow6", GooFlow.prototype.color.mark || "#8f929a"));// 未审的颜色
  790. } else {
  791. this.$draw = document.createElement("v:group");
  792. this.$draw.coordsize = width + "," + height;
  793. this.$workArea.prepend("<div class='GooFlow_work_vml' style='position:relative;width:" + width + "px;height:" + height + "px'></div>");
  794. this.$workArea.children("div")[0].insertBefore(this.$draw, null);
  795. }
  796. this.$draw.id = id;
  797. this.$draw.style.width = width + "px";
  798. this.$draw.style.height = +height + "px";
  799. //绑定连线的点击选中以及双击编辑事件
  800. var tmpClk = null;
  801. if(GooFlow.prototype.useSVG != "") tmpClk = "g";
  802. else tmpClk = "PolyLine";
  803. if(!this.$editable) return;
  804. $(this.$draw).delegate(tmpClk, "click", {
  805. inthis: this
  806. }, function(e) {
  807. e.data.inthis.focusItem(this.id, true);
  808. });
  809. // 改为拖动流转线
  810. $(this.$draw).delegate(tmpClk, "mousedown", {
  811. inthis: this
  812. }, function(e) {
  813. var This = e.data.inthis;
  814. This.focusItem(this.id, true);
  815. var isMove = false;
  816. document.onmousemove = function(e) {
  817. if(!e) e = window.event;
  818. if(!isMove) {
  819. This.$mpTo.mousedown()
  820. }
  821. isMove = true;
  822. }
  823. document.onmouseup = function(e) {
  824. if(isMove) {
  825. This.blurItem();
  826. }
  827. document.onmousemove = null;
  828. document.onmouseup = null;
  829. }
  830. });
  831. // $(this.$draw).delegate(tmpClk, "dblclick", {
  832. // inthis: this
  833. // }, function(e) {
  834. // var oldTxt, x, y, from, to;
  835. // var This = e.data.inthis;
  836. // if(GooFlow.prototype.useSVG != "") {
  837. // oldTxt = this.childNodes[2].textContent;
  838. // from = this.getAttribute("from").split(",");
  839. // to = this.getAttribute("to").split(",");
  840. // } else {
  841. // oldTxt = this.childNodes[1].innerHTML;
  842. // var n = this.getAttribute("fromTo").split(",");
  843. // from = [n[0], n[1]];
  844. // to = [n[2], n[3]];
  845. // }
  846. // if(This.$lineData[this.id].type == "lr") {
  847. // from[0] = This.$lineData[this.id].M;
  848. // to[0] = from[0];
  849. // } else if(This.$lineData[this.id].type == "tb") {
  850. // from[1] = This.$lineData[this.id].M;
  851. // to[1] = from[1];
  852. // }
  853. // x = (parseInt(from[0], 10) + parseInt(to[0], 10)) / 2 - 64;
  854. // y = (parseInt(from[1], 10) + parseInt(to[1], 10)) / 2 - 18;
  855. // var t = getElCoordinate(This.$workArea[0]);
  856. // This.$textArea.val(oldTxt).css({
  857. // display: "block",
  858. // width: 130,
  859. // height: 26,
  860. // left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
  861. // top: t.top + y - This.$workArea[0].parentNode.scrollTop
  862. // }).data("id", This.$focus).focus();
  863. // This.$workArea.parent().one("mousedown", function(e) {
  864. // if(e.button == 2) return false;
  865. // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "line");
  866. // This.$textArea.val("").removeData("id").hide();
  867. // });
  868. // });
  869. },
  870. initGroup: function(width, height) {
  871. this.$group = $("<div class='GooFlow_work_group' style='width:" + width + "px;height:" + height + "px'></div>"); //存放背景区域的容器
  872. this.$workArea.prepend(this.$group);
  873. if(!this.$editable) return;
  874. //区域划分框操作区的事件绑定
  875. this.$group.on("mousedown", {
  876. inthis: this
  877. }, function(e) { //绑定RESIZE功能以及移动功能
  878. if(e.button == 2) return false;
  879. var This = e.data.inthis;
  880. if(This.$nowType != "group") return;
  881. if(!e) e = window.event;
  882. var cursor = $(e.target).css("cursor");
  883. var id = e.target.parentNode;
  884. switch(cursor) {
  885. case "nw-resize":
  886. id = id.parentNode;
  887. break;
  888. case "w-resize":
  889. id = id.parentNode;
  890. break;
  891. case "n-resize":
  892. id = id.parentNode;
  893. break;
  894. case "move":
  895. break;
  896. default:
  897. return;
  898. }
  899. id = id.id;
  900. var ev = mousePosition(e),
  901. t = getElCoordinate(This.$workArea[0]);
  902. var X, Y;
  903. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  904. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  905. if(cursor != "move") {
  906. This.$ghost.css({
  907. display: "block",
  908. width: This.$areaData[id].width + "px",
  909. height: This.$areaData[id].height + "px",
  910. top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
  911. left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
  912. cursor: cursor
  913. });
  914. var vX = (This.$areaData[id].left + This.$areaData[id].width) - X;
  915. var vY = (This.$areaData[id].top + This.$areaData[id].height) - Y;
  916. } else {
  917. var vX = X - This.$areaData[id].left;
  918. var vY = Y - This.$areaData[id].top;
  919. }
  920. var isMove = false;
  921. This.$ghost.css("cursor", cursor);
  922. document.onmousemove = function(e) {
  923. if(!e) e = window.event;
  924. var ev = mousePosition(e);
  925. if(cursor != "move") {
  926. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].left + vX;
  927. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$areaData[id].top + vY;
  928. if(X < 200) X = 200;
  929. if(Y < 100) Y = 100;
  930. switch(cursor) {
  931. case "nw-resize":
  932. This.$ghost.css({
  933. width: X + "px",
  934. height: Y + "px"
  935. });
  936. break;
  937. case "w-resize":
  938. This.$ghost.css({
  939. width: X + "px"
  940. });
  941. break;
  942. case "n-resize":
  943. This.$ghost.css({
  944. height: Y + "px"
  945. });
  946. break;
  947. }
  948. } else {
  949. if(This.$ghost.css("display") == "none") {
  950. This.$ghost.css({
  951. display: "block",
  952. width: This.$areaData[id].width + "px",
  953. height: This.$areaData[id].height + "px",
  954. top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
  955. left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
  956. cursor: cursor
  957. });
  958. }
  959. X = ev.x - vX;
  960. Y = ev.y - vY;
  961. if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
  962. X = t.left - This.$workArea[0].parentNode.scrollLeft;
  963. else if(X + This.$workArea[0].parentNode.scrollLeft + This.$areaData[id].width > t.left + This.$workArea.width())
  964. X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].width;
  965. if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
  966. Y = t.top - This.$workArea[0].parentNode.scrollTop;
  967. else if(Y + This.$workArea[0].parentNode.scrollTop + This.$areaData[id].height > t.top + This.$workArea.height())
  968. Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$areaData[id].height;
  969. This.$ghost.css({
  970. left: X + "px",
  971. top: Y + "px"
  972. });
  973. }
  974. isMove = true;
  975. }
  976. document.onmouseup = function(e) {
  977. This.$ghost.empty().hide();
  978. document.onmousemove = null;
  979. document.onmouseup = null;
  980. if(!isMove) return;
  981. if(cursor != "move")
  982. This.resizeArea(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
  983. else
  984. This.moveArea(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
  985. return false;
  986. }
  987. });
  988. //绑定修改文字说明功能
  989. // this.$group.on("dblclick", {
  990. // inthis: this
  991. // }, function(e) {
  992. // var This = e.data.inthis;
  993. // if(This.$nowType != "group") return;
  994. // if(!e) e = window.event;
  995. // if(e.target.tagName != "LABEL") return false;
  996. // var oldTxt = e.target.innerHTML;
  997. // var p = e.target.parentNode;
  998. // var x = parseInt(p.style.left, 10) + 18,
  999. // y = parseInt(p.style.top, 10) + 1;
  1000. // var t = getElCoordinate(This.$workArea[0]);
  1001. // This.$textArea.val(oldTxt).css({
  1002. // display: "block",
  1003. // width: 120,
  1004. // height: 26,
  1005. // left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
  1006. // top: t.top + y - This.$workArea[0].parentNode.scrollTop
  1007. // }).data("id", p.id).focus();
  1008. // This.$workArea.parent().one("mouseup", function(e) {
  1009. // if(e.button == 2) return false;
  1010. // if(This.$textArea.css("display") == "block") {
  1011. // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "area");
  1012. // This.$textArea.val("").removeData("id").hide();
  1013. // }
  1014. // return false;
  1015. // });
  1016. // return false;
  1017. // });
  1018. //绑定点击事件
  1019. this.$group.mouseup({
  1020. inthis: this
  1021. }, function(e) {
  1022. var This = e.data.inthis;
  1023. if(This.$textArea.css("display") == "block") {
  1024. This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "area");
  1025. This.$textArea.val("").removeData("id").hide();
  1026. return false;
  1027. };
  1028. if(This.$nowType != "group") return;
  1029. if(!e) e = window.event;
  1030. switch($(e.target).attr("class")) {
  1031. case "rs_close":
  1032. This.delArea(e.target.parentNode.parentNode.id);
  1033. return false; //删除该分组区域
  1034. case "bg":
  1035. return;
  1036. }
  1037. switch(e.target.tagName) {
  1038. case "LABEL":
  1039. return false;
  1040. case "I": //绑定变色功能
  1041. var id = e.target.parentNode.id;
  1042. switch(This.$areaData[id].color) {
  1043. case "red":
  1044. This.setAreaColor(id, "yellow");
  1045. break;
  1046. case "yellow":
  1047. This.setAreaColor(id, "blue");
  1048. break;
  1049. case "blue":
  1050. This.setAreaColor(id, "green");
  1051. break;
  1052. case "green":
  1053. This.setAreaColor(id, "red");
  1054. break;
  1055. }
  1056. return false;
  1057. }
  1058. if(e.data.inthis.$ghost.css("display") == "none") {
  1059. var X, Y;
  1060. var ev = mousePosition(e),
  1061. t = getElCoordinate(this);
  1062. X = ev.x - t.left + this.parentNode.parentNode.scrollLeft;
  1063. Y = ev.y - t.top + this.parentNode.parentNode.scrollTop;
  1064. var color = ["red", "yellow", "blue", "green"];
  1065. e.data.inthis.addArea("node_" + This.$max, {
  1066. name: "area_" + e.data.inthis.$max,
  1067. left: X,
  1068. top: Y,
  1069. color: color[e.data.inthis.$max % 4],
  1070. width: 200,
  1071. height: 100
  1072. });
  1073. e.data.inthis.$max++;
  1074. return false;
  1075. }
  1076. });
  1077. },
  1078. //加入手动扩展编辑区功能,一次扩展200px
  1079. initExpendFunc: function() {
  1080. this.$workArea.append('<div class="Gooflow_extend_right"></div><div class="Gooflow_extend_bottom"></div>');
  1081. this.$workArea.children(".Gooflow_extend_right").on("click", {
  1082. inthis: this
  1083. }, function(e) {
  1084. var This = e.data.inthis;
  1085. var w = This.$workArea.width() + This.$workExtendStep;
  1086. var h = This.$workArea.height();
  1087. This.$workArea.css({
  1088. width: w + "px"
  1089. });
  1090. if(GooFlow.prototype.useSVG == "") {
  1091. This.$draw.coordsize = w + "," + h;
  1092. }
  1093. This.$draw.style.width = w + "px";
  1094. if(This.$group != null) {
  1095. This.$group.css({
  1096. width: w + "px"
  1097. });
  1098. }
  1099. var parentDiv = This.$workArea.parent()[0];
  1100. parentDiv.scrollLeft = parentDiv.scrollWidth;
  1101. return false;
  1102. });
  1103. this.$workArea.children(".Gooflow_extend_bottom").on("click", {
  1104. inthis: this
  1105. }, function(e) {
  1106. var This = e.data.inthis
  1107. var w = This.$workArea.width();
  1108. var h = This.$workArea.height() + This.$workExtendStep;
  1109. This.$workArea.css({
  1110. height: h + "px"
  1111. });
  1112. if(GooFlow.prototype.useSVG == "") {
  1113. This.$draw.coordsize = w + "," + h;
  1114. }
  1115. This.$draw.style.height = h + "px";
  1116. if(This.$group != null) {
  1117. This.$group.css({
  1118. height: h + "px"
  1119. });
  1120. }
  1121. var parentDiv = This.$workArea.parent()[0];
  1122. parentDiv.scrollTop = parentDiv.scrollHeight;
  1123. return false;
  1124. });
  1125. },
  1126. //初始化用来改变连线的连接端点的两个小方块的操作事件
  1127. initLinePointsChg: function() {
  1128. this.$mpFrom.on("mousedown", {
  1129. inthis: this
  1130. }, function(e) {
  1131. var This = e.data.inthis;
  1132. This.switchToolBtn("cursor");
  1133. var ps = This.$mpFrom.data("p").split(",");
  1134. var pe = This.$mpTo.data("p").split(",");
  1135. $(this).hide();
  1136. This.$workArea.data("lineEnd", {
  1137. "x": pe[0],
  1138. "y": pe[1],
  1139. "id": This.$lineData[This.$lineOper.data("tid")].to
  1140. }).css("cursor", "crosshair");
  1141. var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [ps[0], ps[1]], [pe[0], pe[1]], true, true);
  1142. This.$draw.appendChild(line);
  1143. return false;
  1144. });
  1145. this.$mpTo.on("mousedown", {
  1146. inthis: this
  1147. }, function(e) {
  1148. var This = e.data.inthis;
  1149. This.switchToolBtn("cursor");
  1150. if (!This.$mpFrom.data("p") || !This.$mpTo.data("p") || !This.$lineOper.data("tid")) {
  1151. var tmp = document.getElementById("GooFlow_tmp_line");
  1152. if(tmp) {
  1153. This.$draw.removeChild(tmp);
  1154. }
  1155. return
  1156. }
  1157. var ps = This.$mpFrom.data("p").split(",");
  1158. var pe = This.$mpTo.data("p").split(",");
  1159. $(this).hide();
  1160. This.$workArea.data("lineStart", {
  1161. "x": ps[0],
  1162. "y": ps[1],
  1163. "id": This.$lineData[This.$lineOper.data("tid")].from
  1164. }).css("cursor", "crosshair");
  1165. var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [ps[0], ps[1]], [pe[0], pe[1]], true, true);
  1166. This.$draw.appendChild(line);
  1167. return false;
  1168. });
  1169. },
  1170. /**
  1171. * 每一种类型结点及其按钮的说明文字
  1172. * @param {Object} remark 工具栏的按钮的说明文字 json map 类型
  1173. */
  1174. // setNodeRemarks: function(remark) {
  1175. // if(this.$tool == null) return;
  1176. // this.$tool.children("a").each(function() {
  1177. // this.title = remark[$(this).attr("id").split("btn_")[1]];
  1178. // });
  1179. // this.$nodeRemark = remark;
  1180. // },
  1181. /**
  1182. * 切换左边工具栏按钮,传参TYPE表示切换成哪种类型的按钮
  1183. * @param {Object} type 工具类型
  1184. * @param {Object} id 工具的 id,如果:有传 id 则根据指定的 id ,没有:则根据类型来获取固定规则的 id
  1185. */
  1186. switchToolBtn: function(type, id) {
  1187. this.$tool.find('a').attr("class", "GooFlow_tool_btn") // 移除工具栏的 a 标签 样式
  1188. if(this.$nowType == "group") {
  1189. this.$workArea.prepend(this.$group);
  1190. for(var key in this.$areaDom) this.$areaDom[key].addClass("lock").children("div:eq(1)").css("display", "none");
  1191. }
  1192. this.$nowType = type;
  1193. var tmpid = id ? id : this.$id + "_btn_" + this.$nowType
  1194. this.$tool.find('#' + tmpid).attr("class", "GooFlow_tool_btndown") // 添加当前选择的样式
  1195. this.$toolTitle = this.$tool.find('#' + tmpid).attr('title')
  1196. this.$toolName = this.$tool.find('#' + tmpid).attr('data-name')
  1197. this.$Type = this.$tool.find('#' + tmpid).attr('type')
  1198. if(this.$nowType == "group") {
  1199. this.blurItem();
  1200. this.$workArea.append(this.$group);
  1201. for(var key in this.$areaDom) this.$areaDom[key].removeClass("lock").children("div:eq(1)").css("display", "");
  1202. } else if(this.$nowType == "direct") {
  1203. this.blurItem();
  1204. }
  1205. if(this.$textArea.css("display") == "none") this.$textArea.removeData("id").val("").hide();
  1206. },
  1207. /**
  1208. * 增加决策的线
  1209. * @param {Object} id 节点 id
  1210. * @param {Object} lines 决策节点出现的线集合,数组
  1211. */
  1212. addDecisionLine: function(id, lines) {
  1213. // 删除当前决策节点已选的类型的线
  1214. for(var key in this.$lineData) {
  1215. if(id == this.$lineData[key].from) {
  1216. this.delLine(key)
  1217. }
  1218. }
  1219. if(lines == null) return
  1220. // 添加已选的类型的线
  1221. for(var i = 0; i < lines.length; i++) {
  1222. var lineid = "node_" + this.$max
  1223. this.$max++;
  1224. //设置$lineData[id]
  1225. this.$lineData[lineid] = {
  1226. type: 'sl',
  1227. from: id,
  1228. to: null,
  1229. name: lines[i],
  1230. marked: false,
  1231. decision: true,
  1232. coordX: i * (Number(i + 1 + '0') + 150) - 100,
  1233. coordY: 150
  1234. }
  1235. //设置$lineData[id]完毕
  1236. var n1 = this.$nodeData[this.$lineData[lineid].from] //获取开始/结束结点的数据
  1237. //开始计算线端点坐标
  1238. var res = GooFlow.prototype.calcStartEnd(n1, n1);
  1239. if(!res) return;
  1240. res.end[0] = res.end[0] + this.$lineData[lineid].coordX
  1241. res.end[1] = res.end[1] + this.$lineData[lineid].coordY
  1242. this.$lineDom[lineid] = GooFlow.prototype.drawLine(lineid, res.start, res.end, this.$lineData[lineid].marked, false, this.$lineData[lineid].name);
  1243. this.$draw.appendChild(this.$lineDom[lineid]);
  1244. var nodes = this.$lineDom[lineid].childNodes
  1245. this.$lineDom[lineid].childNodes[nodes.length - 1].textContent = this.$lineData[lineid].name;
  1246. ++this.$lineCount;
  1247. if(this.$editable) {
  1248. this.$lineData[lineid].alt = true;
  1249. if(this.$deletedItem[lineid]) delete this.$deletedItem[lineid]; //在回退删除操作时,去掉该元素的删除记录
  1250. }
  1251. }
  1252. },
  1253. //增加一个流程结点,传参为一个JSON,有id,name,top,left,width,height,type(结点类型)等属性
  1254. addNode: function(id, json) {
  1255. if(this.onItemAdd != null && !this.onItemAdd(id, "node", json)) return;
  1256. if(this.$undoStack && this.$editable) {
  1257. this.pushOper("delNode", [id]);
  1258. }
  1259. var mark = json.marked ? " item_mark" : "";
  1260. json.width = this.getWidth(json.width, json.type)
  1261. json.height = this.getHeight(json.height, json.type)
  1262. if(json.type.indexOf("start") < 0 && json.type.indexOf("end") < 0) {
  1263. if(!json.top || json.top < 0) json.top = 0;
  1264. if(!json.left || json.left < 0) json.left = 0;
  1265. var rs_div = "<div style='display:none'>"
  1266. rs_div += (json.type.indexOf("fork") != -1 || json.type.indexOf("join") != -1) ?
  1267. "<div class='rs_close'></div>" :
  1268. "<div class='rs_close'></div><div class='rs_bottom'></div><div class='rs_right'></div><div class='rs_rb'></div>"
  1269. rs_div += "</div>"
  1270. if (json.type.indexOf("fork") != -1) {
  1271. json.title = '分支'
  1272. }
  1273. if (json.type.indexOf("join") != -1) {
  1274. json.title = '汇合'
  1275. }
  1276. // 这里是回显时的样式控制
  1277. var foreachClass = "";// 动态审核节点,也是动态分支节点,样式与其他节点不同,多加 class 样式,不使用背景颜色
  1278. var bgc = "";
  1279. if (json.audit_state == '已审') {
  1280. if (json.type.indexOf("foreach") != -1) {
  1281. foreachClass = " flow_foreach_green ";
  1282. }
  1283. else {
  1284. bgc = 'background-color: #65c239;';
  1285. }
  1286. } else if (json.audit_state == '审核中') {
  1287. if (json.type.indexOf("foreach") != -1) {
  1288. foreachClass = " flow_foreach_blue ";
  1289. }
  1290. else {
  1291. bgc = 'background-color: #409efe;';
  1292. }
  1293. } else if (json.audit_state == '未审') {
  1294. if (json.type.indexOf("foreach") != -1) {
  1295. foreachClass = " flow_foreach_gray ";
  1296. }
  1297. else {
  1298. bgc = 'background-color: #8f929a;';
  1299. }
  1300. }
  1301. // 添加节点(不包含开始与结束节点)
  1302. this.$nodeDom[id] = $(
  1303. "<div class='GooFlow_item" + mark + " flow_" + json.type + foreachClass + "' id='" + id + "' style='top:" + json.top + "px;left:" + json.left + "px;" + bgc + "'>" +
  1304. "<table cellspacing='1' style='width:" + (json.width - 2) + "px;height:" + (json.height - 2) + "px;'>" +
  1305. "<tr>" +
  1306. "<td></td>" +
  1307. "<td>" + json.title + "</td>" +
  1308. "</tr>" +
  1309. "</table>" + rs_div +
  1310. "</div>"
  1311. );
  1312. } else { // 开始或者结束节点
  1313. var rs_div = ""
  1314. if(json.type.indexOf("end") != -1) {
  1315. if(this.$end == true) {
  1316. rs_div = "<div style='display:none'><div class='rs_close'></div></div>"
  1317. }
  1318. this.$end = true
  1319. }
  1320. var nodeCss = json.type.indexOf("start") != -1 ? 'spaceicon icon-start' : 'spaceicon icon-finish'
  1321. // 已移除《开始》《结束》节点中的关闭按钮
  1322. this.$nodeDom[id] = $("<div class='GooFlow_item item_round" + mark + " flow_" + json.type + "' id='" + id + "' style='top:" + json.top + "px;left:" + json.left + "px'><table cellspacing='0' style='width:" + (json.width) + "px;height:" + (json.height) + "px;'><tr><td><i class='" + nodeCss + "'></i></td></tr></table>" + rs_div + "</div>");
  1323. }
  1324. if(GooFlow.prototype.color.node) {
  1325. if(json.type.indexOf("start") > -1 || json.type.indexOf("end") > -1) { // 开始与结束节点的样式
  1326. this.$nodeDom[id].css({
  1327. "background-color": GooFlow.prototype.color.mix,
  1328. "border-color": GooFlow.prototype.color.mix
  1329. });
  1330. if(GooFlow.prototype.color.mixFont) {
  1331. this.$nodeDom[id].find("td:eq(1)").css("color", GooFlow.prototype.color.mixFont);
  1332. this.$nodeDom[id].find(".span").css("color", GooFlow.prototype.color.mixFont);
  1333. }
  1334. } else {
  1335. this.$nodeDom[id].css({
  1336. "background-color": GooFlow.prototype.color.node,
  1337. "border-color": GooFlow.prototype.color.node
  1338. });
  1339. }
  1340. if(mark && GooFlow.prototype.color.mark) {
  1341. this.$nodeDom[id].css({
  1342. "border-color": GooFlow.prototype.color.mark
  1343. });
  1344. }
  1345. }
  1346. if(json.type.indexOf("end") > -1) {
  1347. this.$nodeDom[id].addClass("item_mix");
  1348. }
  1349. var ua = navigator.userAgent.toLowerCase();
  1350. if(ua.indexOf('msie') != -1 && ua.indexOf('8.0') != -1)
  1351. this.$nodeDom[id].css("filter", "progid:DXImageTransform.Microsoft.Shadow(color=#94AAC2,direction=135,strength=2)");
  1352. this.$workArea.append(this.$nodeDom[id]);
  1353. this.$nodeData[id] = json;
  1354. ++this.$nodeCount;
  1355. if(this.$editable) {
  1356. this.$nodeData[id].alt = true;
  1357. if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
  1358. }
  1359. },
  1360. initWorkForNode: function() {
  1361. //绑定点击事件
  1362. this.$workArea.delegate(".GooFlow_item", "click", {
  1363. inthis: this
  1364. }, function(e) {
  1365. e.data.inthis.focusItem(this.id, true);
  1366. $(this).removeClass("item_mark");
  1367. var node = e.data.inthis.$focus;
  1368. var nodeData = e.data.inthis.$nodeData[node];
  1369. e.data.inthis.$vue.openNodeAttrCall(e.data.inthis, nodeData);
  1370. // 改源代码加的打开模态框事件
  1371. });
  1372. //绑定用鼠标移动事件
  1373. this.$workArea.delegate(".GooFlow_item table", "mousedown", {
  1374. inthis: this
  1375. }, function(e) {
  1376. if(!e) e = window.event;
  1377. if(e.button == 2) return false;
  1378. var This = e.data.inthis;
  1379. if(This.$nowType == "direct") return;
  1380. var Dom = $(this).parents(".GooFlow_item");
  1381. var id = Dom.attr("id");
  1382. This.focusItem(id, true);
  1383. var ev = mousePosition(e),
  1384. t = getElCoordinate(This.$workArea[0]);
  1385. Dom.children("table").clone().prependTo(This.$ghost);
  1386. var X, Y;
  1387. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  1388. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  1389. var vX = X - This.$nodeData[id].left,
  1390. vY = Y - This.$nodeData[id].top;
  1391. var isMove = false;
  1392. document.onmousemove = function(e) {
  1393. if(!e) e = window.event;
  1394. var ev = mousePosition(e);
  1395. if(X == ev.x - vX && Y == ev.y - vY) return false;
  1396. X = ev.x - vX;
  1397. Y = ev.y - vY;
  1398. if(isMove && This.$ghost.css("display") == "none") {
  1399. var node = This.$focus;
  1400. var nodeData = This.$nodeData[node];
  1401. This.$vue.openNodeAttrCall(This, nodeData);
  1402. // 改源代码加的打开模态框事件
  1403. This.$ghost.css({
  1404. display: "block",
  1405. width: This.$nodeData[id].width + "px",
  1406. height: This.$nodeData[id].height + "px",
  1407. top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
  1408. left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
  1409. cursor: "move",
  1410. 'border-radius': '20px'
  1411. });
  1412. if(This.$nodeData[id].type == 'decision') {
  1413. This.$ghost.css({
  1414. 'border-radius': ''
  1415. });
  1416. }
  1417. }
  1418. if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
  1419. X = t.left - This.$workArea[0].parentNode.scrollLeft;
  1420. else if(X + This.$workArea[0].parentNode.scrollLeft + This.$nodeData[id].width > t.left + This.$workArea.width())
  1421. X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].width;
  1422. if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
  1423. Y = t.top - This.$workArea[0].parentNode.scrollTop;
  1424. else if(Y + This.$workArea[0].parentNode.scrollTop + This.$nodeData[id].height > t.top + This.$workArea.height())
  1425. Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].height;
  1426. This.$ghost.css({
  1427. left: X + "px",
  1428. top: Y + "px"
  1429. });
  1430. isMove = true;
  1431. }
  1432. document.onmouseup = function(e) {
  1433. // 改为同一个标签中存在《点击事件》与《拖动事件》
  1434. if(isMove) {
  1435. This.moveNode(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
  1436. } else {
  1437. Dom.click();
  1438. }
  1439. This.$ghost.empty().hide();
  1440. document.onmousemove = null;
  1441. document.onmouseup = null;
  1442. }
  1443. });
  1444. if(!this.$editable) return;
  1445. //绑定鼠标覆盖/移出事件
  1446. this.$workArea.delegate(".GooFlow_item", "mouseenter", {
  1447. inthis: this
  1448. }, function(e) {
  1449. if(e.data.inthis.$nowType != "direct" && !document.getElementById("GooFlow_tmp_line")) return;
  1450. $(this).addClass("item_mark").addClass("crosshair").css("border-color", GooFlow.prototype.color.mark || "#ff8800");
  1451. });
  1452. this.$workArea.delegate(".GooFlow_item", "mouseleave", {
  1453. inthis: this
  1454. }, function(e) {
  1455. if(e.data.inthis.$nowType != "direct" && !document.getElementById("GooFlow_tmp_line")) return;
  1456. $(this).removeClass("item_mark").removeClass("crosshair");
  1457. if(this.id == e.data.inthis.$focus) {
  1458. $(this).css("border-color", GooFlow.prototype.color.line || "#74bccb");
  1459. } else {
  1460. $(this).css("border-color", GooFlow.prototype.color.node || "#A1DCEB");
  1461. }
  1462. });
  1463. //绑定连线时确定初始点
  1464. this.$workArea.delegate(".GooFlow_item", "mousedown", {
  1465. inthis: this
  1466. }, function(e) {
  1467. if(e.button == 2) return false;
  1468. var This = e.data.inthis;
  1469. if(This.$nowType != "direct") return;
  1470. // 流程图的连线规则,决策节点、结束节点,不能拖出连线
  1471. if(This.$nodeData[this.id].type == 'decision' || This.$nodeData[this.id].type == 'end') return;// 追加不给决策、结束节点连线
  1472. // 开始节点只能有一条出的连线
  1473. if (This.$nodeData[this.id].type == 'start') {
  1474. for (var line in This.$lineData) {
  1475. if (This.$lineData[line].from == this.id) return
  1476. }
  1477. }
  1478. var ev = mousePosition(e),
  1479. t = getElCoordinate(This.$workArea[0]);
  1480. var X, Y;
  1481. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  1482. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  1483. This.$workArea.data("lineStart", {
  1484. "x": X,
  1485. "y": Y,
  1486. "id": this.id
  1487. }).css("cursor", "crosshair");
  1488. var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [X, Y], [X, Y], true, true);
  1489. This.$draw.appendChild(line);
  1490. });
  1491. //绑定连线时确定结束点
  1492. this.$workArea.delegate(".GooFlow_item", "mouseup", {
  1493. inthis: this
  1494. }, function(e) {
  1495. var This = e.data.inthis;
  1496. if(This.$nowType != "direct" && !This.$mpTo.data("p")) return;
  1497. var lineStart = This.$workArea.data("lineStart");
  1498. var lineEnd = This.$workArea.data("lineEnd");
  1499. if(lineStart && !This.$mpTo.data("p")) {
  1500. This.addLine("node_" + This.$max, {
  1501. from: lineStart.id,
  1502. to: this.id,
  1503. name: ""
  1504. });
  1505. This.$max++;
  1506. } else {
  1507. if(lineStart) {
  1508. This.moveLinePoints(This.$focus, lineStart.id, this.id);
  1509. } else if(lineEnd) {
  1510. This.moveLinePoints(This.$focus, this.id, lineEnd.id);
  1511. }
  1512. if(!This.$nodeData[this.id].marked) {
  1513. $(this).removeClass("item_mark");
  1514. if(this.id != This.$focus) {
  1515. $(this).css("border-color", GooFlow.prototype.color.node);
  1516. } else {
  1517. $(this).css("border-color", GooFlow.prototype.color.line);
  1518. }
  1519. }
  1520. }
  1521. });
  1522. //绑定双击编辑事件,不提供直接编辑节点名
  1523. // this.$workArea.delegate(".GooFlow_item > .span", "dblclick", {
  1524. // inthis: this
  1525. // }, function(e) {
  1526. // var oldTxt = this.innerHTML;
  1527. // var This = e.data.inthis;
  1528. // var id = this.parentNode.id;
  1529. // var t = getElCoordinate(This.$workArea[0]);
  1530. // This.$textArea.val(oldTxt).css({
  1531. // display: "block",
  1532. // height: $(this).height() + 6,
  1533. // width: 100,
  1534. // left: t.left + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft - 26,
  1535. // top: t.top + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop + 26
  1536. // })
  1537. // .data("id", This.$focus).focus();
  1538. // This.$workArea.parent().one("mousedown", function(e) {
  1539. // if(e.button == 2) return false;
  1540. // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "node");
  1541. // This.$textArea.val("").removeData("id").hide();
  1542. // });
  1543. // });
  1544. // this.$workArea.delegate(".ico + td", "dblclick", {
  1545. // inthis: this
  1546. // }, function(e) {
  1547. // var oldTxt = this.innerHTML;
  1548. // var This = e.data.inthis;
  1549. // var id = $(this).parents(".GooFlow_item").attr("id");
  1550. // var t = getElCoordinate(This.$workArea[0]);
  1551. // This.$textArea.val(oldTxt).css({
  1552. // display: "block",
  1553. // width: $(this).width() + 26,
  1554. // height: $(this).height() + 6,
  1555. // left: t.left + 26 + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft,
  1556. // top: t.top + 2 + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop
  1557. // })
  1558. // .data("id", This.$focus).focus();
  1559. // This.$workArea.parent().one("mousedown", function(e) {
  1560. // if(e.button == 2) return false;
  1561. // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "node");
  1562. // This.$textArea.val("").removeData("id").hide();
  1563. // });
  1564. // });
  1565. //绑定结点的删除功能
  1566. this.$workArea.delegate(".rs_close", "click", {
  1567. inthis: this
  1568. }, function(e) {
  1569. if(!e) e = window.event;
  1570. e.data.inthis.delNode(e.data.inthis.$focus);
  1571. return false;
  1572. });
  1573. //绑定结点的RESIZE功能
  1574. this.$workArea.delegate(".GooFlow_item > div > div[class!=rs_close]", "mousedown", {
  1575. inthis: this
  1576. }, function(e) {
  1577. if(!e) e = window.event;
  1578. if(e.button == 2) return false;
  1579. var cursor = $(this).css("cursor");
  1580. if(cursor == "pointer") {
  1581. return;
  1582. }
  1583. var This = e.data.inthis;
  1584. var id = This.$focus;
  1585. This.switchToolBtn("cursor");
  1586. e.cancelBubble = true;
  1587. e.stopPropagation();
  1588. var ev = mousePosition(e),
  1589. t = getElCoordinate(This.$workArea[0]);
  1590. This.$ghost.css({
  1591. display: "block",
  1592. width: This.$nodeData[id].width + "px",
  1593. height: This.$nodeData[id].height + "px",
  1594. top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
  1595. left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
  1596. cursor: cursor
  1597. });
  1598. var X, Y;
  1599. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
  1600. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
  1601. var vX = (This.$nodeData[id].left + This.$nodeData[id].width) - X;
  1602. var vY = (This.$nodeData[id].top + This.$nodeData[id].height) - Y;
  1603. var isMove = false;
  1604. This.$ghost.css("cursor", cursor);
  1605. document.onmousemove = function(e) {
  1606. if(!e) e = window.event;
  1607. var ev = mousePosition(e);
  1608. X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].left + vX;
  1609. Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].top + vY;
  1610. X = This.getNodeTypeMinWidth(X, This.$nodeData[id].type);
  1611. Y = This.getNodeTypeMinHeight(Y, This.$nodeData[id].type);
  1612. isMove = true;
  1613. switch(cursor) {
  1614. case "nw-resize":
  1615. This.$ghost.css({
  1616. width: X + "px",
  1617. height: Y + "px"
  1618. });
  1619. break;
  1620. case "w-resize":
  1621. This.$ghost.css({
  1622. width: X + "px"
  1623. });
  1624. break;
  1625. case "n-resize":
  1626. This.$ghost.css({
  1627. height: Y + "px"
  1628. });
  1629. break;
  1630. }
  1631. }
  1632. document.onmouseup = function(e) {
  1633. document.onmousemove = null;
  1634. document.onmouseup = null;
  1635. This.$ghost.hide();
  1636. if(!isMove) return;
  1637. if(!e) e = window.event;
  1638. This.resizeNode(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
  1639. This.focusItem(id, true); // 重新选中当前节点
  1640. }
  1641. });
  1642. },
  1643. //获取结点/连线/分组区域的详细信息
  1644. getItemInfo: function(id, type) {
  1645. switch(type) {
  1646. case "node":
  1647. return this.$nodeData[id] || null;
  1648. case "line":
  1649. return this.$lineData[id] || null;
  1650. case "area":
  1651. return this.$areaData[id] || null;
  1652. }
  1653. },
  1654. //取消所有结点/连线被选定的状态
  1655. blurItem: function() {
  1656. if(this.$focus != "") {
  1657. var jq = $("#" + this.$focus);
  1658. if(jq.prop("tagName") == "DIV") {
  1659. if(this.onItemBlur != null && !this.onItemBlur(this.$focus, "node")) return false;
  1660. jq.removeClass("item_focus").children("div:eq(0)").css("display", "none");
  1661. if(this.$nodeData[this.$focus].marked) {
  1662. jq.addClass("item_mark").css("border-color", GooFlow.prototype.color.mark || '#ff8800');
  1663. }
  1664. } else {
  1665. if(this.onItemBlur != null && !this.onItemBlur(this.$focus, "line")) return false;
  1666. var nodes = jq[0].childNodes;
  1667. if (nodes.length == 4) nodes[2].setAttribute("fill", "#74bccb")
  1668. if(GooFlow.prototype.useSVG != "") {
  1669. if(!this.$lineData[this.$focus].marked) {
  1670. jq[0].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
  1671. jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow1)");
  1672. }
  1673. } else {
  1674. if(!this.$lineData[this.$focus].marked) {
  1675. jq[0].strokeColor = GooFlow.prototype.color.line || "#74bccb";
  1676. }
  1677. }
  1678. this.$lineMove.hide().removeData("type").removeData("tid");
  1679. if(this.$editable) {
  1680. this.$lineOper.hide().removeData("tid");
  1681. this.$mpFrom.hide().removeData("p");
  1682. this.$mpTo.hide().removeData("p");
  1683. }
  1684. }
  1685. }
  1686. this.$focus = "";
  1687. return true;
  1688. },
  1689. //选定某个结点/转换线 bool:TRUE决定了要触发选中事件,FALSE则不触发选中事件,多用在程序内部调用。
  1690. focusItem: function(id, bool) {
  1691. var jq = $("#" + id);
  1692. if(jq.length == 0) return;
  1693. if(!this.blurItem()) return; //先执行"取消选中",如果返回FLASE,则也会阻止选定事件继续进行.
  1694. if(jq.prop("tagName") == "DIV") {
  1695. if(bool && this.onItemFocus != null && !this.onItemFocus(id, "node")) return;
  1696. jq.addClass("item_focus");
  1697. if(GooFlow.prototype.color.line) {
  1698. jq.css("border-color", GooFlow.prototype.color.line);
  1699. }
  1700. if(this.$editable) jq.children("div:eq(0)").css("display", "block");
  1701. this.$workArea.append(jq);
  1702. } else { //如果是连接线
  1703. if(this.onItemFocus != null && !this.onItemFocus(id, "line")) return;
  1704. var nodes = jq[0].childNodes;
  1705. if (nodes.length == 4) nodes[2].setAttribute("fill", "#ff8800")
  1706. if(GooFlow.prototype.useSVG != "") {
  1707. jq[0].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
  1708. jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow2)");
  1709. } else {
  1710. jq[0].strokeColor = GooFlow.prototype.color.mark || "#ff8800";
  1711. }
  1712. if(!this.$editable) return;
  1713. var x, y, from, to, n;
  1714. if(GooFlow.prototype.useSVG != "") {
  1715. from = jq.attr("from").split(",");
  1716. to = jq.attr("to").split(",");
  1717. n = [from[0], from[1], to[0], to[1]];
  1718. } else {
  1719. n = jq[0].getAttribute("fromTo").split(",");
  1720. from = [n[0], n[1]];
  1721. to = [n[2], n[3]];
  1722. }
  1723. from[0] = parseInt(from[0], 10);
  1724. from[1] = parseInt(from[1], 10);
  1725. to[0] = parseInt(to[0], 10);
  1726. to[1] = parseInt(to[1], 10);
  1727. if (!this.$lineData[id]) return
  1728. if(this.$lineData[id].type == "lr") {
  1729. from[0] = this.$lineData[id].M;
  1730. to[0] = from[0];
  1731. this.$lineMove.css({
  1732. width: "5px",
  1733. height: (to[1] - from[1]) * (to[1] > from[1] ? 1 : -1) + "px",
  1734. left: from[0] - 3 + "px",
  1735. top: (to[1] > from[1] ? from[1] : to[1]) + 1 + "px",
  1736. cursor: "e-resize",
  1737. display: "block"
  1738. }).data({
  1739. "type": "lr",
  1740. "tid": id
  1741. });
  1742. } else if(this.$lineData[id].type == "tb") {
  1743. from[1] = this.$lineData[id].M;
  1744. to[1] = from[1];
  1745. this.$lineMove.css({
  1746. width: (to[0] - from[0]) * (to[0] > from[0] ? 1 : -1) + "px",
  1747. height: "5px",
  1748. left: (to[0] > from[0] ? from[0] : to[0]) + 1 + "px",
  1749. top: from[1] - 3 + "px",
  1750. cursor: "s-resize",
  1751. display: "block"
  1752. }).data({
  1753. "type": "tb",
  1754. "tid": id
  1755. });
  1756. }
  1757. x = (from[0] + to[0]) / 2 - 40;
  1758. y = (from[1] + to[1]) / 2 + 4;
  1759. // this.$lineOper.css({
  1760. // display: "block",
  1761. // left: x + "px",
  1762. // top: y + "px"
  1763. // }).data("tid", id);
  1764. this.$focuslineid = id;
  1765. this.$lineOper.data("tid", id);
  1766. // 改为支持(不能移动开始端点的,只能移动结束端点)
  1767. if(this.$lineData[id].to == null) {
  1768. // 没有连接到结束端点时,不出现可设置连接线的
  1769. } else if(this.$lineData[id].decision) {
  1770. // 连接了结束端点,到该节点不支持修改开始端点,(可设置线,但不能删除该连接线)
  1771. this.$lineOper.css({
  1772. display: "block",
  1773. left: x + "px",
  1774. top: y + "px",
  1775. width: '64px'
  1776. });
  1777. // 移除可删除连接线的按钮
  1778. this.$lineOper.find('.b_x').remove();
  1779. } else {
  1780. // 追加可删除连接线的按钮
  1781. if(this.$lineOper.find('.b_x').length == 0) {
  1782. this.$lineOper.append("<i class='b_x'></i>");
  1783. }
  1784. this.$lineOper.css({
  1785. display: "block",
  1786. left: x + "px",
  1787. top: y + "px",
  1788. width: '82px'
  1789. });
  1790. }
  1791. if(this.$editable) {
  1792. this.$mpFrom.data("p", n[0] + "," + n[1]);
  1793. this.$mpTo.data("p", n[2] + "," + n[3]);
  1794. // if (this.$lineData[id].to != null && !this.$lineData[id].decision) {
  1795. // // 不能移动开始端点的,这里只出现可移动的小方块
  1796. // this.$mpFrom.css({
  1797. // display: "block",
  1798. // left: (n[0] - 10) + "px",
  1799. // top: n[1] - 10 + "px"
  1800. // })
  1801. // }
  1802. // this.$mpTo.css({
  1803. // display: "block",
  1804. // left: n[2] - 11 + "px",
  1805. // top: n[3] - 11 + "px"
  1806. // }).data("p", n[2] + "," + n[3]);
  1807. }
  1808. this.$draw.appendChild(jq[0]);
  1809. this.$vue.clearCurrentFocus();
  1810. }
  1811. this.$focus = id;
  1812. this.switchToolBtn("cursor");
  1813. },
  1814. //移动结点到一个新的位置
  1815. moveNode: function(id, left, top) {
  1816. if(!this.$nodeData[id]) return;
  1817. if(this.onItemMove != null && !this.onItemMove(id, "node", left, top)) return;
  1818. if(this.$undoStack) {
  1819. var paras = [id, this.$nodeData[id].left, this.$nodeData[id].top];
  1820. this.pushOper("moveNode", paras);
  1821. }
  1822. if(left < 0) left = 0;
  1823. if(top < 0) top = 0;
  1824. $("#" + id).css({
  1825. left: left + "px",
  1826. top: top + "px"
  1827. });
  1828. this.$nodeData[id].left = left;
  1829. this.$nodeData[id].top = top;
  1830. //重画转换线
  1831. this.resetLines(id, this.$nodeData[id]);
  1832. if(this.$editable) {
  1833. this.$nodeData[id].alt = true;
  1834. }
  1835. },
  1836. //设置结点/连线/分组区域的文字信息
  1837. setNodeName: function(id, title, type) {
  1838. var oldName;
  1839. if(type == "node") { //如果是结点
  1840. if(!this.$nodeData[id]) return;
  1841. // 阻止name相同时不执行
  1842. // if(this.$nodeData[id].title == title) return;
  1843. if(this.onItemRename != null && !this.onItemRename(id, title, "node")) return;
  1844. oldName = this.$nodeData[id].title;
  1845. this.$nodeData[id].title = title;
  1846. if(this.$nodeData[id].type.indexOf("round") > 1) {
  1847. this.$nodeDom[id].children(".span").text(title);
  1848. } else {
  1849. this.$nodeDom[id].find("td:eq(1)").text(title);
  1850. var width = this.$nodeDom[id].width();
  1851. var height = this.$nodeDom[id].height();
  1852. this.$nodeDom[id].children("table").css({
  1853. width: width + "px",
  1854. height: height + "px"
  1855. });
  1856. this.$nodeData[id].width = width;
  1857. this.$nodeData[id].height = height;
  1858. }
  1859. if(this.$editable) {
  1860. this.$nodeData[id].alt = true;
  1861. }
  1862. //重画转换线
  1863. this.resetLines(id, this.$nodeData[id]);
  1864. } else if(type == "line") { //如果是线
  1865. if(!this.$lineData[id]) return;
  1866. if(this.$lineData[id].title == title) return;
  1867. if(this.onItemRename != null && !this.onItemRename(id, title, "line")) return;
  1868. oldName = this.$lineData[id].title;
  1869. this.$lineData[id].title = title;
  1870. if(GooFlow.prototype.useSVG != "") {
  1871. this.$lineDom[id].childNodes[2].textContent = title;
  1872. } else {
  1873. this.$lineDom[id].childNodes[1].innerHTML = title;
  1874. var n = this.$lineDom[id].getAttribute("fromTo").split(",");
  1875. var x;
  1876. if(this.$lineData[id].type != "lr") {
  1877. x = (n[2] - n[0]) / 2;
  1878. } else {
  1879. var Min = n[2] > n[0] ? n[0] : n[2];
  1880. if(Min > this.$lineData[id].M) Min = this.$lineData[id].M;
  1881. x = this.$lineData[id].M - Min;
  1882. }
  1883. if(x < 0) x = x * -1;
  1884. this.$lineDom[id].childNodes[1].style.left = x - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4 + "px";
  1885. }
  1886. if(this.$editable) {
  1887. this.$lineData[id].alt = true;
  1888. }
  1889. } else if(type == "area") { //如果是分组区域
  1890. if(!this.$areaData[id]) return;
  1891. if(this.$areaData[id].title == title) return;
  1892. if(this.onItemRename != null && !this.onItemRename(id, title, "area")) return;
  1893. oldName = this.$areaData[id].title;
  1894. this.$areaData[id].title = title;
  1895. this.$areaDom[id].children("label").text(title);
  1896. if(this.$editable) {
  1897. this.$areaData[id].alt = true;
  1898. }
  1899. }
  1900. if(this.$undoStack) {
  1901. var paras = [id, oldName, type];
  1902. this.pushOper("setNodeName", paras);
  1903. }
  1904. },
  1905. //设置结点的尺寸,仅支持非开始/结束结点
  1906. resizeNode: function(id, width, height) {
  1907. if(!this.$nodeData[id]) return;
  1908. if(this.onItemResize != null && !this.onItemResize(id, "node", width, height)) return;
  1909. if(this.$nodeData[id].type == "start" || this.$nodeData[id].type == "end") return;
  1910. if(this.$undoStack) {
  1911. var paras = [id, this.$nodeData[id].width, this.$nodeData[id].height];
  1912. this.pushOper("resizeNode", paras);
  1913. }
  1914. this.$nodeDom[id].children("table").css({
  1915. width: width - 2 + "px",
  1916. height: height - 2 + "px"
  1917. });
  1918. //width=this.$nodeDom[id].outerWidth();
  1919. //height=this.$nodeDom[id].outerHeight();
  1920. //this.$nodeDom[id].children("table").css({width:width-2+"px",height:height-2+"px"});
  1921. this.$nodeData[id].width = width;
  1922. this.$nodeData[id].height = height;
  1923. if(this.$editable) {
  1924. this.$nodeData[id].alt = true;
  1925. }
  1926. //重画转换线
  1927. this.resetLines(id, this.$nodeData[id]);
  1928. },
  1929. //删除结点
  1930. delNode: function(id, trigger) {
  1931. if(!this.$nodeData[id]) return;
  1932. if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
  1933. //先删除可能的连线
  1934. for(var k in this.$lineData) {
  1935. if(this.$lineData[k].from == id || this.$lineData[k].to == id) {
  1936. if (this.$lineData[k].to == id && this.$lineData[k].decision) {
  1937. this.$lineData[k].type = "sl"; // 重新设置为直线
  1938. this.$lineData[k].to = null;
  1939. this.resetLines(this.$lineData[k].from, this.$nodeData[this.$lineData[k].from]);
  1940. continue
  1941. }
  1942. //this.$draw.removeChild(this.$lineDom[k]);
  1943. //delete this.$lineData[k];
  1944. //delete this.$lineDom[k];
  1945. this.delLine(k, false);
  1946. }
  1947. }
  1948. //再删除结点本身
  1949. if(this.$undoStack) {
  1950. var paras = [id, this.$nodeData[id]];
  1951. this.pushOper("addNode", paras);
  1952. }
  1953. delete this.$nodeData[id];
  1954. this.$nodeDom[id].remove();
  1955. delete this.$nodeDom[id];
  1956. --this.$nodeCount;
  1957. if(this.$focus == id) this.$focus = "";
  1958. if(this.$editable) {
  1959. //在回退新增操作时,如果节点ID以this.$id+"_node_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
  1960. if(id.indexOf(this.$id + "_node_") < 0)
  1961. this.$deletedItem[id] = "node";
  1962. }
  1963. this.$vue.clearCurrentFocus();
  1964. },
  1965. /**
  1966. * 设置流程图的名称
  1967. * @param {Object} name 名称
  1968. */
  1969. setTitle: function(name) {
  1970. this.$name = name;
  1971. // if(this.$head) this.$head.children("label").attr("title", name).text(name);
  1972. },
  1973. /**
  1974. * 自定义流程图的 key
  1975. * @param {Object} key
  1976. */
  1977. setKey: function(key) {
  1978. this.$key = key;
  1979. },
  1980. /**
  1981. * 载入一组数据
  1982. * @param {Object} data
  1983. */
  1984. loadData: function(data) {
  1985. var t = this.$editable;
  1986. this.$editable = false;
  1987. if(data == null || data == undefined) {
  1988. data = {
  1989. name: "",
  1990. nodes: {
  1991. "node_1": {
  1992. "id": "node_1",
  1993. "title": "开始",
  1994. "left": parseInt(Math.random() * 400),
  1995. "top": parseInt(Math.random() * 400),
  1996. "type": "start",
  1997. "alt": true
  1998. },
  1999. "node_2": {
  2000. "id": "node_2",
  2001. "title": "结束",
  2002. "left": parseInt(Math.random() * 400),
  2003. "top": parseInt(Math.random() * 400),
  2004. "type": "end",
  2005. "alt": true
  2006. }
  2007. },
  2008. initNum: 3
  2009. }
  2010. }
  2011. if(data.name) this.setTitle(data.name);
  2012. if(data.initNum) this.$max = data.initNum;
  2013. for(var i in data.nodes)
  2014. this.addNode(i, data.nodes[i]);
  2015. for(var j in data.lines)
  2016. this.addLine(j, data.lines[j]);
  2017. for(var k in data.areas)
  2018. this.addArea(k, data.areas[k]);
  2019. this.$editable = t;
  2020. this.$deletedItem = {};
  2021. //自行重构工作区,使之大小自适应
  2022. var width = this.$workArea.width();
  2023. var height = this.$workArea.height();
  2024. var maxW = 0,
  2025. maxH = 0;
  2026. for(var key in this.$nodeData) {
  2027. var item = this.$nodeData[key];
  2028. if(maxW < item.width + item.left) {
  2029. maxW = item.width + item.left;
  2030. }
  2031. if(maxH < item.height + item.top) {
  2032. maxH = item.height + item.top;
  2033. }
  2034. }
  2035. for(var key in this.$areaData) {
  2036. var item = this.$areaData[key];
  2037. if(maxW < item.width + item.left) {
  2038. maxW = item.width + item.left;
  2039. }
  2040. if(maxH < item.height + item.top) {
  2041. maxH = item.height + item.top;
  2042. }
  2043. }
  2044. for(var key in this.$lineData) {
  2045. var item = this.$lineData[key];
  2046. if(item.M && item.type == "lt" && maxW < item.M) {
  2047. maxW = M + 4;
  2048. }
  2049. if(item.M && item.type == "tb" && maxH < item.M) {
  2050. maxH = M + 4;
  2051. }
  2052. }
  2053. while(maxW > width) {
  2054. width += this.$workExtendStep;
  2055. }
  2056. while(maxH > height) {
  2057. height += this.$workExtendStep;
  2058. }
  2059. this.$workArea.css({
  2060. height: height + "px",
  2061. width: width + "px"
  2062. });
  2063. if(GooFlow.prototype.useSVG == "") {
  2064. this.$draw.coordsize = width + "," + height;
  2065. }
  2066. this.$draw.style.width = width + "px";
  2067. this.$draw.style.height = +height + "px";
  2068. if(this.$group != null) {
  2069. this.$group.css({
  2070. height: height + "px",
  2071. width: width + "px"
  2072. });
  2073. }
  2074. },
  2075. /**
  2076. * 用 AJAX 方式,远程读取一组数据
  2077. * 参数 para 为 JSON 结构,与 JQUERY 中 $.ajax() 方法的传参一样
  2078. * @param {Object} para JSON 结构的参数
  2079. */
  2080. loadDataAjax: function(para) {
  2081. var This = this;
  2082. $.ajax({
  2083. type: para.type,
  2084. url: para.url,
  2085. dataType: "json",
  2086. data: para.data,
  2087. success: function(msg) {
  2088. if(para.dataFilter) para.dataFilter(msg, "json");
  2089. This.loadData(msg);
  2090. if(para.success) para.success(msg);
  2091. },
  2092. error: function(XMLHttpRequest, textStatus, errorThrown) {
  2093. if(para.error) para.error(textStatus, errorThrown);
  2094. }
  2095. })
  2096. },
  2097. /**
  2098. * 导出 json 结构的数据
  2099. * 把画好的整个流程图导出到一个变量中(其实也可以直接访问GooFlow对象的$nodeData,$lineData,$areaData这三个JSON属性)
  2100. */
  2101. exportData: function() {
  2102. var ret = {
  2103. name: this.$name,
  2104. key: this.$key,
  2105. nodes: this.$nodeData,
  2106. lines: this.$lineData,
  2107. areas: this.$areaData,
  2108. initNum: this.$max
  2109. };
  2110. for(var k1 in ret.nodes) {
  2111. if(!ret.nodes[k1].marked) {
  2112. delete ret.nodes[k1]["marked"];
  2113. }
  2114. }
  2115. for(var k2 in ret.lines) {
  2116. if(!ret.lines[k2].marked) {
  2117. delete ret.lines[k2]["marked"];
  2118. }
  2119. }
  2120. return ret;
  2121. },
  2122. /**
  2123. * 只把本次编辑流程图中作了变更(包括增删改)的元素导出到一个变量中,以方便用户每次编辑载入的流程图后只获取变更过的数据
  2124. */
  2125. exportAlter: function() {
  2126. var ret = {
  2127. nodes: {},
  2128. lines: {},
  2129. areas: {}
  2130. };
  2131. for(var k1 in this.$nodeData) {
  2132. if(this.$nodeData[k1].alt) {
  2133. ret.nodes[k1] = this.$nodeData[k1];
  2134. }
  2135. }
  2136. for(var k2 in this.$lineData) {
  2137. if(this.$lineData[k2].alt) {
  2138. ret.lines[k2] = this.$lineData[k2];
  2139. }
  2140. }
  2141. for(var k3 in this.$areaData) {
  2142. if(this.$areaData[k3].alt) {
  2143. ret.areas[k3] = this.$areaData[k3];
  2144. }
  2145. }
  2146. ret.deletedItem = this.$deletedItem;
  2147. return ret;
  2148. },
  2149. /**
  2150. * 变更元素的ID,一般用于快速保存后,将后台返回新元素的ID更新到页面中;type为元素类型(节点,连线,区块)
  2151. * @param {Object} oldId 旧 id
  2152. * @param {Object} newId 新 id
  2153. * @param {Object} type 类型(节点 node ,连线 line ,区块 area)
  2154. */
  2155. transNewId: function(oldId, newId, type) {
  2156. var tmp;
  2157. switch(type) {
  2158. case "node":
  2159. if(this.$nodeData[oldId]) {
  2160. tmp = this.$nodeData[oldId];
  2161. delete this.$nodeData[oldId];
  2162. this.$nodeData[newId] = tmp;
  2163. tmp = this.$nodeDom[oldId].attr("id", newId);
  2164. delete this.$nodeDom[oldId];
  2165. this.$nodeDom[newId] = tmp;
  2166. }
  2167. break;
  2168. case "line":
  2169. if(this.$lineData[oldId]) {
  2170. tmp = this.$lineData[oldId];
  2171. delete this.$lineData[oldId];
  2172. this.$lineData[newId] = tmp;
  2173. tmp = this.$lineDom[oldId].attr("id", newId);
  2174. delete this.$lineDom[oldId];
  2175. this.$lineDom[newId] = tmp;
  2176. }
  2177. break;
  2178. case "area":
  2179. if(this.$areaData[oldId]) {
  2180. tmp = this.$areaData[oldId];
  2181. delete this.$areaData[oldId];
  2182. this.$areaData[newId] = tmp;
  2183. tmp = this.$areaDom[oldId].attr("id", newId);
  2184. delete this.$areaDom[oldId];
  2185. this.$areaDom[newId] = tmp;
  2186. }
  2187. break;
  2188. }
  2189. },
  2190. /**
  2191. * 清空工作区及已载入的数据
  2192. */
  2193. clearData: function() {
  2194. for(var key in this.$nodeData) {
  2195. this.delNode(key);
  2196. }
  2197. for(var key in this.$lineData) {
  2198. this.delLine(key);
  2199. }
  2200. for(var key in this.$areaData) {
  2201. this.delArea(key);
  2202. }
  2203. this.$deletedItem = {};
  2204. },
  2205. /**
  2206. * 销毁自己(当前画布)
  2207. */
  2208. destrory: function() {
  2209. this.$bgDiv.empty();
  2210. this.$lineData = null;
  2211. this.$nodeData = null;
  2212. this.$lineDom = null;
  2213. this.$nodeDom = null;
  2214. this.$areaDom = null;
  2215. this.$areaData = null;
  2216. this.$nodeCount = 0;
  2217. this.$areaCount = 0;
  2218. this.$areaCount = 0;
  2219. this.$deletedItem = {};
  2220. },
  2221. ///////////以下为有关画线的方法
  2222. /**
  2223. * 绘制一条箭头线,并返回线的DOM(直线)
  2224. * @param {Object} id
  2225. * @param {Object} sp 开始端的参数,为数组格式,数组中有 X 轴与 Y 轴的坐标点,第一个是 X 轴,第二个是 Y 轴
  2226. * @param {Object} ep 结束端端参数,为数组格式,数组中有 X 轴与 Y 轴的坐标点,第一个是 X 轴,第二个是 Y 轴
  2227. * @param {Object} mark 线的标识
  2228. * @param {Object} dash
  2229. * @param {Object} name
  2230. */
  2231. drawLine: function(id, sp, ep, mark, dash, name, auditState) {
  2232. var line;
  2233. if(GooFlow.prototype.useSVG != "") {
  2234. line = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2235. var hi = document.createElementNS("http://www.w3.org/2000/svg", "path");
  2236. var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
  2237. if(id != "") line.setAttribute("id", id);
  2238. line.setAttribute("from", sp[0] + "," + sp[1]);
  2239. line.setAttribute("to", ep[0] + "," + ep[1]);
  2240. hi.setAttribute("visibility", "hidden");
  2241. hi.setAttribute("stroke-width", 9);
  2242. hi.setAttribute("fill", "none");
  2243. hi.setAttribute("stroke", "white");
  2244. hi.setAttribute("d", "M " + sp[0] + " " + sp[1] + " L " + ep[0] + " " + ep[1]);
  2245. hi.setAttribute("pointer-events", "stroke");
  2246. path.setAttribute("d", "M " + sp[0] + " " + sp[1] + " L " + ep[0] + " " + ep[1]);
  2247. path.setAttribute("stroke-width", mark ? 2.4 : 2);
  2248. path.setAttribute("stroke-linecap", "round");
  2249. path.setAttribute("fill", "none");
  2250. if(dash) path.setAttribute("style", "stroke-dasharray:6,5");
  2251. if(mark) {
  2252. path.setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
  2253. path.setAttribute("marker-end", "url(#arrow2)");
  2254. } else {
  2255. path.setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
  2256. path.setAttribute("marker-end", "url(#arrow1)");
  2257. }
  2258. if (auditState == '已审') {
  2259. path.setAttribute("stroke", GooFlow.prototype.color.line || "#65c239");
  2260. path.setAttribute("marker-end", "url(#arrow4)");
  2261. } else if (auditState == '审核中') {
  2262. path.setAttribute("stroke", GooFlow.prototype.color.line || "#409efe");
  2263. path.setAttribute("marker-end", "url(#arrow5)");
  2264. } else if (auditState == '未审') {
  2265. path.setAttribute("stroke", GooFlow.prototype.color.line || "#8f929a");
  2266. path.setAttribute("marker-end", "url(#arrow6)");
  2267. }
  2268. line.appendChild(hi);
  2269. line.appendChild(path);
  2270. line.style.cursor = "crosshair";
  2271. if(id != "" && id != "GooFlow_tmp_line") {
  2272. var x = (ep[0] + sp[0]) / 2;
  2273. var y = (ep[1] + sp[1]) / 2;
  2274. if(name) {
  2275. var rx;
  2276. if(name.length == 1) {
  2277. rx = 15
  2278. } else {
  2279. rx = 15 + (name.length - 1) * 6
  2280. }
  2281. var ellipse = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
  2282. ellipse.setAttribute("class", "node");
  2283. ellipse.setAttribute("rx", rx);
  2284. ellipse.setAttribute("ry", 12);
  2285. ellipse.setAttribute("cx", x);
  2286. ellipse.setAttribute("cy", y - 4);
  2287. ellipse.setAttribute("fill", "#75bccb");
  2288. if (auditState == '已审') {
  2289. ellipse.setAttribute("fill", "#65c239");
  2290. } else if (auditState == '审核中') {
  2291. ellipse.setAttribute("fill", "#409efe");
  2292. } else if (auditState == '未审') {
  2293. ellipse.setAttribute("fill", "#8f929a");
  2294. }
  2295. line.appendChild(ellipse);
  2296. }
  2297. var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
  2298. text.setAttribute("fill", GooFlow.prototype.color.lineFont || "#fff");
  2299. line.appendChild(text);
  2300. text.setAttribute("text-anchor", "middle");
  2301. text.setAttribute("x", x);
  2302. text.setAttribute("y", y);
  2303. line.style.cursor = "pointer";
  2304. text.style.cursor = "text";
  2305. }
  2306. } else {
  2307. line = document.createElement("v:polyline");
  2308. if(id != "") line.id = id;
  2309. //line.style.position="absolute";
  2310. line.points.value = sp[0] + "," + sp[1] + " " + ep[0] + "," + ep[1];
  2311. line.setAttribute("fromTo", sp[0] + "," + sp[1] + "," + ep[0] + "," + ep[1]);
  2312. line.strokeWeight = "2";
  2313. line.stroke.EndArrow = "Block";
  2314. line.style.cursor = "crosshair";
  2315. if(id != "" && id != "GooFlow_tmp_line") {
  2316. var text = document.createElement("div");
  2317. //text.innerHTML=id;
  2318. line.appendChild(text);
  2319. var x = (ep[0] - sp[0]) / 2;
  2320. var y = (ep[1] - sp[1]) / 2;
  2321. if(x < 0) x = x * -1;
  2322. if(y < 0) y = y * -1;
  2323. text.style.left = x + "px";
  2324. text.style.top = y - 6 + "px";
  2325. line.style.cursor = "pointer";
  2326. }
  2327. if(dash) line.stroke.dashstyle = "Dash";
  2328. if(mark) line.strokeColor = GooFlow.prototype.color.mark || "#ff8800";
  2329. else line.strokeColor = GooFlow.prototype.color.line || "#74bccb";
  2330. line.fillColor = GooFlow.prototype.color.line || "#74bccb";
  2331. }
  2332. return line;
  2333. },
  2334. /**
  2335. * 画一条只有两个中点的折线(折线)
  2336. * @param {Object} id
  2337. * @param {Object} sp
  2338. * @param {Object} m1
  2339. * @param {Object} m2
  2340. * @param {Object} ep
  2341. * @param {Object} mark
  2342. * @param {Object} name
  2343. * @param {Object} auditState
  2344. */
  2345. drawPoly: function(id, sp, m1, m2, ep, mark, name, auditState) {
  2346. var poly, strPath;
  2347. if(GooFlow.prototype.useSVG != "") {
  2348. poly = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2349. var hi = document.createElementNS("http://www.w3.org/2000/svg", "path");
  2350. var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
  2351. if(id != "") poly.setAttribute("id", id);
  2352. poly.setAttribute("from", sp[0] + "," + sp[1]);
  2353. poly.setAttribute("to", ep[0] + "," + ep[1]);
  2354. hi.setAttribute("visibility", "hidden");
  2355. hi.setAttribute("stroke-width", 9);
  2356. hi.setAttribute("fill", "none");
  2357. hi.setAttribute("stroke", "white");
  2358. strPath = "M " + sp[0] + " " + sp[1];
  2359. if(m1[0] != sp[0] || m1[1] != sp[1])
  2360. strPath += " L " + m1[0] + " " + m1[1];
  2361. if(m2[0] != ep[0] || m2[1] != ep[1])
  2362. strPath += " L " + m2[0] + " " + m2[1];
  2363. strPath += " L " + ep[0] + " " + ep[1];
  2364. hi.setAttribute("d", strPath);
  2365. hi.setAttribute("pointer-events", "stroke");
  2366. path.setAttribute("d", strPath);
  2367. path.setAttribute("stroke-width", mark ? 2.4 : 2);
  2368. path.setAttribute("stroke-linecap", "round");
  2369. path.setAttribute("fill", "none");
  2370. if(mark) {
  2371. path.setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
  2372. path.setAttribute("marker-end", "url(#arrow2)");
  2373. } else {
  2374. path.setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
  2375. path.setAttribute("marker-end", "url(#arrow1)");
  2376. }
  2377. if (auditState == '已审') {
  2378. path.setAttribute("stroke", GooFlow.prototype.color.line || "#65c239");
  2379. path.setAttribute("marker-end", "url(#arrow4)");
  2380. } else if (auditState == '审核中') {
  2381. path.setAttribute("stroke", GooFlow.prototype.color.line || "#409efe");
  2382. path.setAttribute("marker-end", "url(#arrow5)");
  2383. } else if (auditState == '未审') {
  2384. path.setAttribute("stroke", GooFlow.prototype.color.line || "#8f929a");
  2385. path.setAttribute("marker-end", "url(#arrow6)");
  2386. }
  2387. poly.appendChild(hi);
  2388. poly.appendChild(path);
  2389. var x = (m2[0] + m1[0]) / 2;
  2390. var y = (m2[1] + m1[1]) / 2;
  2391. if(name) {
  2392. var rx;
  2393. if(name.length == 1) {
  2394. rx = 15
  2395. } else {
  2396. rx = 15 + (name.length - 1) * 6
  2397. }
  2398. var ellipse = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
  2399. ellipse.setAttribute("class", "node");
  2400. ellipse.setAttribute("rx", rx);
  2401. ellipse.setAttribute("ry", 12);
  2402. ellipse.setAttribute("cx", x);
  2403. ellipse.setAttribute("cy", y - 4);
  2404. ellipse.setAttribute("fill", "#75bccb");
  2405. if (auditState == '已审') {
  2406. ellipse.setAttribute("fill", "#65c239");
  2407. } else if (auditState == '审核中') {
  2408. ellipse.setAttribute("fill", "#409efe");
  2409. } else if (auditState == '未审') {
  2410. ellipse.setAttribute("fill", "#8f929a");
  2411. }
  2412. poly.appendChild(ellipse);
  2413. }
  2414. var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
  2415. text.setAttribute("fill", GooFlow.prototype.color.lineFont || "#fff");
  2416. poly.appendChild(text);
  2417. text.setAttribute("text-anchor", "middle");
  2418. text.setAttribute("x", x);
  2419. text.setAttribute("y", y);
  2420. text.style.cursor = "text";
  2421. poly.style.cursor = "pointer";
  2422. } else {
  2423. poly = document.createElement("v:Polyline");
  2424. if(id != "") poly.id = id;
  2425. poly.filled = "false";
  2426. strPath = sp[0] + "," + sp[1];
  2427. if(m1[0] != sp[0] || m1[1] != sp[1])
  2428. strPath += " " + m1[0] + "," + m1[1];
  2429. if(m2[0] != ep[0] || m2[1] != ep[1])
  2430. strPath += " " + m2[0] + "," + m2[1];
  2431. strPath += " " + ep[0] + "," + ep[1];
  2432. poly.points.value = strPath;
  2433. poly.setAttribute("fromTo", sp[0] + "," + sp[1] + "," + ep[0] + "," + ep[1]);
  2434. poly.strokeWeight = mark ? "2.4" : "2";
  2435. poly.stroke.EndArrow = "Block";
  2436. var text = document.createElement("div");
  2437. //text.innerHTML=id;
  2438. poly.appendChild(text);
  2439. var x = (m2[0] - m1[0]) / 2;
  2440. var y = (m2[1] - m1[1]) / 2;
  2441. if(x < 0) x = x * -1;
  2442. if(y < 0) y = y * -1;
  2443. text.style.left = x + "px";
  2444. text.style.top = y - 4 + "px";
  2445. poly.style.cursor = "pointer";
  2446. if(mark) poly.strokeColor = GooFlow.prototype.color.mark || "#ff8800";
  2447. else poly.strokeColor = GooFlow.prototype.color.line || "#74bccb";
  2448. }
  2449. return poly;
  2450. },
  2451. //计算两个结点间要连直线的话,连线的开始坐标和结束坐标
  2452. calcStartEnd: function(n1, n2) {
  2453. var X_1, Y_1, X_2, Y_2;
  2454. //X判断:
  2455. var x11 = n1.left,
  2456. x12 = n1.left + n1.width,
  2457. x21 = n2.left,
  2458. x22 = n2.left + n2.width;
  2459. //结点2在结点1左边
  2460. if(x11 >= x22) {
  2461. X_1 = x11;
  2462. X_2 = x22;
  2463. }
  2464. //结点2在结点1右边
  2465. else if(x12 <= x21) {
  2466. X_1 = x12;
  2467. X_2 = x21;
  2468. }
  2469. //结点2在结点1水平部分重合
  2470. else if(x11 <= x21 && x12 >= x21 && x12 <= x22) {
  2471. X_1 = (x12 + x21) / 2;
  2472. X_2 = X_1;
  2473. } else if(x11 >= x21 && x12 <= x22) {
  2474. X_1 = (x11 + x12) / 2;
  2475. X_2 = X_1;
  2476. } else if(x21 >= x11 && x22 <= x12) {
  2477. X_1 = (x21 + x22) / 2;
  2478. X_2 = X_1;
  2479. } else if(x11 <= x22 && x12 >= x22) {
  2480. X_1 = (x11 + x22) / 2;
  2481. X_2 = X_1;
  2482. }
  2483. //Y判断:
  2484. var y11 = n1.top,
  2485. y12 = n1.top + n1.height,
  2486. y21 = n2.top,
  2487. y22 = n2.top + n2.height;
  2488. //结点2在结点1上边
  2489. if(y11 >= y22) {
  2490. Y_1 = y11;
  2491. Y_2 = y22;
  2492. }
  2493. //结点2在结点1下边
  2494. else if(y12 <= y21) {
  2495. Y_1 = y12;
  2496. Y_2 = y21;
  2497. }
  2498. //结点2在结点1垂直部分重合
  2499. else if(y11 <= y21 && y12 >= y21 && y12 <= y22) {
  2500. Y_1 = (y12 + y21) / 2;
  2501. Y_2 = Y_1;
  2502. } else if(y11 >= y21 && y12 <= y22) {
  2503. Y_1 = (y11 + y12) / 2;
  2504. Y_2 = Y_1;
  2505. } else if(y21 >= y11 && y22 <= y12) {
  2506. Y_1 = (y21 + y22) / 2;
  2507. Y_2 = Y_1;
  2508. } else if(y11 <= y22 && y12 >= y22) {
  2509. Y_1 = (y11 + y22) / 2;
  2510. Y_2 = Y_1;
  2511. }
  2512. return {
  2513. "start": [X_1, Y_1],
  2514. "end": [X_2, Y_2]
  2515. };
  2516. },
  2517. //计算两个结点间要连折线的话,连线的所有坐标
  2518. calcPolyPoints: function(n1, n2, type, M) {
  2519. //开始/结束两个结点的中心
  2520. var SP = {
  2521. x: n1.left + n1.width / 2,
  2522. y: n1.top + n1.height / 2
  2523. };
  2524. var EP = {
  2525. x: n2.left + n2.width / 2,
  2526. y: n2.top + n2.height / 2
  2527. };
  2528. var sp = [],
  2529. m1 = [],
  2530. m2 = [],
  2531. ep = [];
  2532. //如果是允许中段可左右移动的折线,则参数M为可移动中段线的X坐标
  2533. //粗略计算起始点
  2534. sp = [SP.x, SP.y];
  2535. ep = [EP.x, EP.y];
  2536. if(type == "lr") {
  2537. //粗略计算2个中点
  2538. m1 = [M, SP.y];
  2539. m2 = [M, EP.y];
  2540. //再具体分析修改开始点和中点1
  2541. if(m1[0] > n1.left && m1[0] < n1.left + n1.width) {
  2542. m1[1] = (SP.y > EP.y ? n1.top : n1.top + n1.height);
  2543. sp[0] = m1[0];
  2544. sp[1] = m1[1];
  2545. } else {
  2546. sp[0] = (m1[0] < n1.left ? n1.left : n1.left + n1.width)
  2547. }
  2548. //再具体分析中点2和结束点
  2549. if(m2[0] > n2.left && m2[0] < n2.left + n2.width) {
  2550. m2[1] = (SP.y > EP.y ? n2.top + n2.height : n2.top);
  2551. ep[0] = m2[0];
  2552. ep[1] = m2[1];
  2553. } else {
  2554. ep[0] = (m2[0] < n2.left ? n2.left : n2.left + n2.width)
  2555. }
  2556. }
  2557. //如果是允许中段可上下移动的折线,则参数M为可移动中段线的Y坐标
  2558. else if(type == "tb") {
  2559. //粗略计算2个中点
  2560. m1 = [SP.x, M];
  2561. m2 = [EP.x, M];
  2562. //再具体分析修改开始点和中点1
  2563. if(m1[1] > n1.top && m1[1] < n1.top + n1.height) {
  2564. m1[0] = (SP.x > EP.x ? n1.left : n1.left + n1.width);
  2565. sp[0] = m1[0];
  2566. sp[1] = m1[1];
  2567. } else {
  2568. sp[1] = (m1[1] < n1.top ? n1.top : n1.top + n1.height)
  2569. }
  2570. //再具体分析中点2和结束点
  2571. if(m2[1] > n2.top && m2[1] < n2.top + n2.height) {
  2572. m2[0] = (SP.x > EP.x ? n2.left + n2.width : n2.left);
  2573. ep[0] = m2[0];
  2574. ep[1] = m2[1];
  2575. } else {
  2576. ep[1] = (m2[1] < n2.top ? n2.top : n2.top + n2.height);
  2577. }
  2578. }
  2579. return {
  2580. start: sp,
  2581. m1: m1,
  2582. m2: m2,
  2583. end: ep
  2584. };
  2585. },
  2586. //初始化折线中段的X/Y坐标,mType='rb'时为X坐标,mType='tb'时为Y坐标
  2587. getMValue: function(n1, n2, mType) {
  2588. if(mType == "lr") {
  2589. return(n1.left + n1.width / 2 + n2.left + n2.width / 2) / 2;
  2590. } else if(mType == "tb") {
  2591. return(n1.top + n1.height / 2 + n2.top + n2.height / 2) / 2;
  2592. }
  2593. },
  2594. //原lineData已经设定好的情况下,只在绘图工作区画一条线的页面元素
  2595. addLineDom: function(id, lineData) {
  2596. var n1 = this.$nodeData[lineData.from],
  2597. n2 = this.$nodeData[lineData.to]; //获取开始/结束结点的数据
  2598. // if(!n1 || !n2) return;
  2599. //开始计算线端点坐标
  2600. var res;
  2601. if(lineData.type && lineData.type != "sl")
  2602. res = GooFlow.prototype.calcPolyPoints(n1, n2, lineData.type, lineData.M);
  2603. else
  2604. res = GooFlow.prototype.calcStartEnd(n1, n2); //3
  2605. if(!res) return;
  2606. if(lineData.type == "sl")
  2607. this.$lineDom[id] = GooFlow.prototype.drawLine(id, res.start, res.end, lineData.marked, false, lineData.name, lineData.audit_state);
  2608. else
  2609. this.$lineDom[id] = GooFlow.prototype.drawPoly(id, res.start, res.m1, res.m2, res.end, lineData.marked, lineData.name, lineData.audit_state);
  2610. this.$draw.appendChild(this.$lineDom[id]);
  2611. var nodes = this.$lineDom[id].childNodes;
  2612. if(GooFlow.prototype.useSVG == "") {
  2613. this.$lineDom[id].childNodes[1].innerHTML = lineData.name;
  2614. if(lineData.type != "sl") {
  2615. var Min = (res.start[0] > res.end[0] ? res.end[0] : res.start[0]);
  2616. if(Min > res.m2[0]) Min = res.m2[0];
  2617. if(Min > res.m1[0]) Min = res.m1[0];
  2618. this.$lineDom[id].childNodes[1].style.left = (res.m2[0] + res.m1[0]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4;
  2619. Min = (res.start[1] > res.end[1] ? res.end[1] : res.start[1]);
  2620. if(Min > res.m2[1]) Min = res.m2[1];
  2621. if(Min > res.m1[1]) Min = res.m1[1];
  2622. this.$lineDom[id].childNodes[1].style.top = (res.m2[1] + res.m1[1]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetHeight / 2;
  2623. } else
  2624. this.$lineDom[id].childNodes[1].style.left =
  2625. ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[id].childNodes[1].offsetWidth) / 2 + 4;
  2626. } else this.$lineDom[id].childNodes[nodes.length - 1].textContent = lineData.name;
  2627. },
  2628. //增加一条线
  2629. addLine: function(id, json) {
  2630. if(this.onItemAdd != null && !this.onItemAdd(id, "line", json)) return;
  2631. if(this.$undoStack && this.$editable) {
  2632. this.pushOper("delLine", [id]);
  2633. }
  2634. if(json.from == json.to) return;
  2635. var n1 = this.$nodeData[json.from],
  2636. n2 = this.$nodeData[json.to]; //获取开始/结束结点的数据
  2637. if(!n1 || !n2) return;
  2638. //避免两个节点间不能有一条以上同向接连线
  2639. for(var k in this.$lineData) {
  2640. if((json.from == this.$lineData[k].from && json.to == this.$lineData[k].to))
  2641. return;
  2642. }
  2643. // 添加连线规则,结束端不能是开始节点
  2644. if (n2.type == "start") {
  2645. return
  2646. }
  2647. //设置$lineData[id]
  2648. this.$lineData[id] = {};
  2649. if(json.type) {
  2650. this.$lineData[id].type = json.type;
  2651. this.$lineData[id].M = json.M;
  2652. } else this.$lineData[id].type = "sl"; //默认为直线
  2653. this.$lineData[id].from = json.from;
  2654. this.$lineData[id].to = json.to;
  2655. this.$lineData[id].name = json.name;
  2656. this.$lineData[id].decision = json.decision;
  2657. this.$lineData[id].coordX = json.coordX;
  2658. this.$lineData[id].coordY = json.coordY;
  2659. this.$lineData[id].audit_state = json.audit_state;// 这是流程图时使用的
  2660. if(json.marked) this.$lineData[id].marked = json.marked;
  2661. else this.$lineData[id].marked = false;
  2662. //设置$lineData[id]完毕
  2663. this.addLineDom(id, this.$lineData[id]);
  2664. ++this.$lineCount;
  2665. if(this.$editable) {
  2666. this.$lineData[id].alt = true;
  2667. if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
  2668. }
  2669. },
  2670. //重构所有连向某个结点的线的显示,传参结构为$nodeData数组的一个单元结构
  2671. resetLines: function(id, node) {
  2672. for(var i in this.$lineData) {
  2673. var other = null; //获取结束/开始结点的数据
  2674. var res;
  2675. if(this.$lineData[i].from == id) { //找结束点
  2676. other = this.$nodeData[this.$lineData[i].to] || null;
  2677. // if(other == null) continue;
  2678. var flag = false
  2679. if(other == null) {
  2680. other = node;
  2681. flag = true
  2682. }
  2683. if(this.$lineData[i].type == "sl")
  2684. res = GooFlow.prototype.calcStartEnd(node, other);
  2685. else
  2686. res = GooFlow.prototype.calcPolyPoints(node, other, this.$lineData[i].type, this.$lineData[i].M)
  2687. if(!res) break;
  2688. if(flag) {
  2689. // 没有结束的连线,所以要指定坐标点
  2690. res.end[0] = res.end[0] + this.$lineData[i].coordX
  2691. res.end[1] = res.end[1] + this.$lineData[i].coordY
  2692. }
  2693. } else if(this.$lineData[i].to == id) { //找开始点
  2694. other = this.$nodeData[this.$lineData[i].from] || null;
  2695. if(other == null) continue;
  2696. if(this.$lineData[i].type == "sl")
  2697. res = GooFlow.prototype.calcStartEnd(other, node);
  2698. else
  2699. res = GooFlow.prototype.calcPolyPoints(other, node, this.$lineData[i].type, this.$lineData[i].M);
  2700. if(!res) break;
  2701. }
  2702. if(other == null) continue;
  2703. this.$draw.removeChild(this.$lineDom[i]);
  2704. if(this.$lineData[i].type == "sl") {
  2705. this.$lineDom[i] = GooFlow.prototype.drawLine(i, res.start, res.end, this.$lineData[i].marked, false, this.$lineData[i].name);
  2706. } else {
  2707. this.$lineDom[i] = GooFlow.prototype.drawPoly(i, res.start, res.m1, res.m2, res.end, this.$lineData[i].marked, this.$lineData[i].name);
  2708. }
  2709. this.$draw.appendChild(this.$lineDom[i]);
  2710. var nodes = this.$lineDom[i].childNodes
  2711. if(GooFlow.prototype.useSVG == "") {
  2712. this.$lineDom[i].childNodes[1].innerHTML = this.$lineData[i].name;
  2713. if(this.$lineData[i].type != "sl") {
  2714. var Min = (res.start[0] > res.end[0] ? res.end[0] : res.start[0]);
  2715. if(Min > res.m2[0]) Min = res.m2[0];
  2716. if(Min > res.m1[0]) Min = res.m1[0];
  2717. this.$lineDom[i].childNodes[1].style.left = (res.m2[0] + res.m1[0]) / 2 - Min - this.$lineDom[i].childNodes[1].offsetWidth / 2 + 4;
  2718. Min = (res.start[1] > res.end[1] ? res.end[1] : res.start[1]);
  2719. if(Min > res.m2[1]) Min = res.m2[1];
  2720. if(Min > res.m1[1]) Min = res.m1[1];
  2721. this.$lineDom[i].childNodes[1].style.top = (res.m2[1] + res.m1[1]) / 2 - Min - this.$lineDom[i].childNodes[1].offsetHeight / 2 - 4;
  2722. } else
  2723. this.$lineDom[i].childNodes[1].style.left =
  2724. ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[i].childNodes[1].offsetWidth) / 2 + 4;
  2725. } else this.$lineDom[i].childNodes[nodes.length - 1].textContent = this.$lineData[i].name;
  2726. }
  2727. },
  2728. //重新设置连线的样式 newType= "sl":直线, "lr":中段可左右移动型折线, "tb":中段可上下移动型折线
  2729. setLineType: function(id, newType, M) {
  2730. if(!newType || newType == null || newType == "" || newType == this.$lineData[id].type) return false;
  2731. if(this.onLineSetType != null && !this.onLineSetType(id, newType)) return;
  2732. if(this.$undoStack) {
  2733. var paras = [id, this.$lineData[id].type, this.$lineData[id].M];
  2734. this.pushOper("setLineType", paras);
  2735. }
  2736. var from = this.$lineData[id].from;
  2737. var to = this.$lineData[id].to;
  2738. this.$lineData[id].type = newType;
  2739. var res;
  2740. //如果是变成折线
  2741. if(newType != "sl") {
  2742. var res = GooFlow.prototype.calcPolyPoints(this.$nodeData[from], this.$nodeData[to], this.$lineData[id].type, this.$lineData[id].M);
  2743. if(M) {
  2744. this.setLineM(id, M, true);
  2745. } else {
  2746. this.setLineM(id, this.getMValue(this.$nodeData[from], this.$nodeData[to], newType), true);
  2747. }
  2748. }
  2749. //如果是变回直线
  2750. else {
  2751. delete this.$lineData[id].M;
  2752. this.$lineMove.hide().removeData("type").removeData("tid");
  2753. res = GooFlow.prototype.calcStartEnd(this.$nodeData[from], this.$nodeData[to]);
  2754. if(!res) return;
  2755. this.$draw.removeChild(this.$lineDom[id]);
  2756. this.$lineDom[id] = GooFlow.prototype.drawLine(id, res.start, res.end, this.$lineData[id].marked, false, this.$lineData[id].name);
  2757. this.$draw.appendChild(this.$lineDom[id]);
  2758. var nodes = this.$lineDom[id].childNodes
  2759. if(GooFlow.prototype.useSVG == "") {
  2760. this.$lineDom[id].childNodes[1].innerHTML = this.$lineData[id].name;
  2761. this.$lineDom[id].childNodes[1].style.left =
  2762. ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[id].childNodes[1].offsetWidth) / 2 + 4;
  2763. } else
  2764. this.$lineDom[id].childNodes[nodes.length - 1].textContent = this.$lineData[id].name;
  2765. }
  2766. if(this.$focus == id) {
  2767. this.focusItem(id);
  2768. }
  2769. if(this.$editable) {
  2770. this.$lineData[id].alt = true;
  2771. }
  2772. },
  2773. //设置折线中段的X坐标值(可左右移动时)或Y坐标值(可上下移动时)
  2774. setLineM: function(id, M, noStack) {
  2775. if(!this.$lineData[id] || M < 0 || !this.$lineData[id].type || this.$lineData[id].type == "sl") return false;
  2776. if(this.onLineMove != null && !this.onLineMove(id, M)) return false;
  2777. if(this.$undoStack && !noStack) {
  2778. var paras = [id, this.$lineData[id].M];
  2779. this.pushOper("setLineM", paras);
  2780. }
  2781. var from = this.$lineData[id].from;
  2782. var to = this.$lineData[id].to;
  2783. this.$lineData[id].M = M;
  2784. var ps = GooFlow.prototype.calcPolyPoints(this.$nodeData[from], this.$nodeData[to], this.$lineData[id].type, this.$lineData[id].M);
  2785. this.$draw.removeChild(this.$lineDom[id]);
  2786. this.$lineDom[id] = GooFlow.prototype.drawPoly(id, ps.start, ps.m1, ps.m2, ps.end, this.$lineData[id].marked, this.$lineData[id].name);
  2787. this.$draw.appendChild(this.$lineDom[id]);
  2788. var nodes = this.$lineDom[id].childNodes
  2789. if(GooFlow.prototype.useSVG == "") {
  2790. this.$lineDom[id].childNodes[1].innerHTML = this.$lineData[id].name;
  2791. var Min = (ps.start[0] > ps.end[0] ? ps.end[0] : ps.start[0]);
  2792. if(Min > ps.m2[0]) Min = ps.m2[0];
  2793. if(Min > ps.m1[0]) Min = ps.m1[0];
  2794. this.$lineDom[id].childNodes[1].style.left = (ps.m2[0] + ps.m1[0]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4;
  2795. Min = (ps.start[1] > ps.end[1] ? ps.end[1] : ps.start[1]);
  2796. if(Min > ps.m2[1]) Min = ps.m2[1];
  2797. if(Min > ps.m1[1]) Min = ps.m1[1];
  2798. this.$lineDom[id].childNodes[1].style.top = (ps.m2[1] + ps.m1[1]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetHeight / 2 - 4;
  2799. } else this.$lineDom[id].childNodes[nodes.length - 1].textContent = this.$lineData[id].name;
  2800. if(this.$editable) {
  2801. this.$lineData[id].alt = true;
  2802. }
  2803. },
  2804. //删除转换线
  2805. delLine: function(id, trigger) {
  2806. if(!this.$lineData[id]) return;
  2807. if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
  2808. if(this.$undoStack) {
  2809. var paras = [id, this.$lineData[id]];
  2810. this.pushOper("addLine", paras);
  2811. }
  2812. this.$draw.removeChild(this.$lineDom[id]);
  2813. delete this.$lineData[id];
  2814. delete this.$lineDom[id];
  2815. if(this.$focus == id) this.$focus = "";
  2816. --this.$lineCount;
  2817. if(this.$editable) {
  2818. //在回退新增操作时,如果节点ID以this.$id+"_line_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
  2819. if(id.indexOf(this.$id + "_line_") < 0)
  2820. this.$deletedItem[id] = "line";
  2821. this.$mpFrom.hide().removeData("p");
  2822. this.$mpTo.hide().removeData("p");
  2823. }
  2824. if(this.$lineOper) {
  2825. this.$lineOper.hide().removeData("tid");
  2826. }
  2827. },
  2828. //变更连线两个端点所连的结点
  2829. //参数:要变更端点的连线ID,新的开始结点ID、新的结束结点ID;如果开始/结束结点ID是传入null或者"",则表示原端点不变
  2830. moveLinePoints: function(lineId, newStart, newEnd, noStack) {
  2831. if(newStart == newEnd) return;
  2832. if(!lineId || !this.$lineData[lineId]) return;
  2833. if(newStart == null || newStart == "")
  2834. newStart = this.$lineData[lineId].from;
  2835. if(newEnd == null || newEnd == "")
  2836. newEnd = this.$lineData[lineId].to;
  2837. //避免两个节点间不能有一条以上同向接连线
  2838. for(var k in this.$lineData) {
  2839. if((newStart == this.$lineData[k].from && newEnd == this.$lineData[k].to))
  2840. return;
  2841. }
  2842. if(this.onLinePointMove != null && !this.onLinePointMove(id, newStart, newEnd)) return;
  2843. if(this.$undoStack && !noStack) {
  2844. var paras = [lineId, this.$lineData[lineId].from, this.$lineData[lineId].to];
  2845. this.pushOper("moveLinePoints", paras);
  2846. }
  2847. if(newStart != null && newStart != "") {
  2848. this.$lineData[lineId].from = newStart;
  2849. }
  2850. if(newEnd != null && newEnd != "") {
  2851. this.$lineData[lineId].to = newEnd;
  2852. }
  2853. //重建转换线
  2854. this.$draw.removeChild(this.$lineDom[lineId]);
  2855. this.addLineDom(lineId, this.$lineData[lineId]);
  2856. if(this.$editable) {
  2857. this.$lineData[lineId].alt = true;
  2858. }
  2859. },
  2860. //用颜色标注/取消标注一个结点或转换线,常用于显示重点或流程的进度。
  2861. //这是一个在编辑模式中无用,但是在纯浏览模式中非常有用的方法,实际运用中可用于跟踪流程的进度。
  2862. markItem: function(id, type, mark) {
  2863. if(type == "node") {
  2864. if(!this.$nodeData[id]) return;
  2865. if(this.onItemMark != null && !this.onItemMark(id, "node", mark)) return;
  2866. this.$nodeData[id].marked = mark || false;
  2867. if(mark) {
  2868. this.$nodeDom[id].addClass("item_mark").css("border-color", GooFlow.prototype.color.mark);
  2869. } else {
  2870. this.$nodeDom[id].removeClass("item_mark");
  2871. if(id != this.$focus) this.$nodeDom[id].css("border-color", "transparent");
  2872. }
  2873. } else if(type == "line") {
  2874. if(!this.$lineData[id]) return;
  2875. if(this.onItemMark != null && !this.onItemMark(id, "line", mark)) return;
  2876. this.$lineData[id].marked = mark || false;
  2877. if(GooFlow.prototype.useSVG != "") {
  2878. if(mark) {
  2879. this.$lineDom[id].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
  2880. this.$lineDom[id].childNodes[1].setAttribute("marker-end", "url(#arrow2)");
  2881. this.$lineDom[id].childNodes[1].setAttribute("stroke-width", 2.4);
  2882. } else {
  2883. this.$lineDom[id].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
  2884. this.$lineDom[id].childNodes[1].setAttribute("marker-end", "url(#arrow1)");
  2885. this.$lineDom[id].childNodes[1].setAttribute("stroke-width", 2);
  2886. }
  2887. } else {
  2888. if(mark) {
  2889. this.$lineDom[id].strokeColor = GooFlow.prototype.color.mark || "#ff8800";
  2890. this.$lineDom[id].strokeWeight = "2.4";
  2891. } else {
  2892. this.$lineDom[id].strokeColor = GooFlow.prototype.color.line || "#74bccb";
  2893. this.$lineDom[id].strokeWeight = "2";
  2894. }
  2895. }
  2896. }
  2897. if(this.$undoStatck) {
  2898. var paras = [id, type, !mark];
  2899. this.pushOper("markItem", paras);
  2900. }
  2901. },
  2902. ////////////////////////以下为区域分组块操作
  2903. moveArea: function(id, left, top) {
  2904. if(!this.$areaData[id]) return;
  2905. if(this.onItemMove != null && !this.onItemMove(id, "area", left, top)) return;
  2906. if(this.$undoStack) {
  2907. var paras = [id, this.$areaData[id].left, this.$areaData[id].top];
  2908. this.pushOper("moveNode", paras);
  2909. }
  2910. if(left < 0) left = 0;
  2911. if(top < 0) top = 0;
  2912. $("#" + id).css({
  2913. left: left + "px",
  2914. top: top + "px"
  2915. });
  2916. this.$areaData[id].left = left;
  2917. this.$areaData[id].top = top;
  2918. if(this.$editable) {
  2919. this.$areaData[id].alt = true;
  2920. }
  2921. },
  2922. //删除区域分组
  2923. delArea: function(id, trigger) {
  2924. if(!this.$areaData[id]) return;
  2925. if(this.$undoStack) {
  2926. var paras = [id, this.$areaData[id]];
  2927. this.pushOper("addArea", paras);
  2928. }
  2929. if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
  2930. delete this.$areaData[id];
  2931. this.$areaDom[id].remove();
  2932. delete this.$areaDom[id];
  2933. --this.$areaCount;
  2934. if(this.$editable) {
  2935. //在回退新增操作时,如果节点ID以this.$id+"_area_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
  2936. if(id.indexOf(this.$id + "_area_") < 0)
  2937. this.$deletedItem[id] = "area";
  2938. }
  2939. },
  2940. //设置区域分组的颜色
  2941. setAreaColor: function(id, color) {
  2942. if(!this.$areaData[id]) return;
  2943. if(this.$undoStack) {
  2944. var paras = [id, this.$areaData[id].color];
  2945. this.pushOper("setAreaColor", paras);
  2946. }
  2947. if(color == "red" || color == "yellow" || color == "blue" || color == "green") {
  2948. this.$areaDom[id].removeClass("area_" + this.$areaData[id].color).addClass("area_" + color);
  2949. this.$areaData[id].color = color;
  2950. }
  2951. if(this.$editable) {
  2952. this.$areaData[id].alt = true;
  2953. }
  2954. },
  2955. //设置区域分块的尺寸
  2956. resizeArea: function(id, width, height) {
  2957. if(!this.$areaData[id]) return;
  2958. if(this.onItemResize != null && !this.onItemResize(id, "area", width, height)) return;
  2959. if(this.$undoStack) {
  2960. var paras = [id, this.$areaData[id].width, this.$areaData[id].height];
  2961. this.pushOper("resizeArea", paras);
  2962. }
  2963. this.$areaDom[id].children(".bg").css({
  2964. width: width + "px",
  2965. height: height + "px"
  2966. });
  2967. //width=this.$areaDom[id].outerWidth();
  2968. //height=this.$areaDom[id].outerHeight();
  2969. //this.$areaDom[id].children("bg").css({width:width+"px",height:height+"px"});
  2970. this.$areaData[id].width = width;
  2971. this.$areaData[id].height = height;
  2972. if(this.$editable) {
  2973. this.$areaData[id].alt = true;
  2974. }
  2975. },
  2976. addArea: function(id, json) {
  2977. if(this.onItemAdd != null && !this.onItemAdd(id, "area", json)) return;
  2978. if(this.$undoStack && this.$editable) {
  2979. this.pushOper("delArea", [id]);
  2980. }
  2981. this.$areaDom[id] = $("<div id='" + id + "' class='GooFlow_area area_" + json.color + "' style='top:" + json.top + "px;left:" + json.left + "px'><div class='bg' style='width:" + (json.width) + "px;height:" + (json.height) + "px'></div>" +
  2982. "<label>" + json.name + "</label><i></i><div><div class='rs_bottom'></div><div class='rs_right'></div><div class='rs_rb'></div><div class='rs_close'></div></div></div>");
  2983. this.$areaData[id] = json;
  2984. this.$group.append(this.$areaDom[id]);
  2985. if(this.$nowType != "group") this.$areaDom[id].children("div:eq(1)").css("display", "none");
  2986. ++this.$areaCount;
  2987. if(this.$editable) {
  2988. this.$areaData[id].alt = true;
  2989. if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
  2990. }
  2991. },
  2992. //重构整个流程图设计器的宽高
  2993. reinitSize: function(width, height) {
  2994. var w = (width || 800);
  2995. var h = (height || 500);
  2996. this.$bgDiv.css({
  2997. height: h + "px",
  2998. width: w + "px"
  2999. });
  3000. var headHeight = 0,
  3001. hack = 8;
  3002. if(this.$head != null) {
  3003. headHeight = 26;
  3004. hack = 5;
  3005. }
  3006. if(this.$tool != null) {
  3007. this.$tool.css({
  3008. height: h - headHeight - hack + "px"
  3009. });
  3010. w -= 31;
  3011. }
  3012. w -= 9;
  3013. h = h - headHeight - (this.$head != null ? 5 : 8);
  3014. this.$workArea.parent().css({
  3015. height: h + "px",
  3016. width: w + "px"
  3017. });
  3018. if(this.$workArea.width() > w) {
  3019. w = this.$workArea.width();
  3020. }
  3021. if(this.$workArea.height() > h) {
  3022. h = this.$workArea.height();
  3023. }
  3024. this.$workArea.css({
  3025. height: h + "px",
  3026. width: w + "px"
  3027. });
  3028. if(GooFlow.prototype.useSVG == "") {
  3029. this.$draw.coordsize = w + "," + h;
  3030. }
  3031. this.$draw.style.width = w + "px";
  3032. this.$draw.style.height = +h + "px";
  3033. if(this.$group != null) {
  3034. this.$group.css({
  3035. height: h + "px",
  3036. width: w + "px"
  3037. });
  3038. }
  3039. }
  3040. }
  3041. GooFlow.prototype.color = {};
  3042. //将此类的构造函数加入至JQUERY对象中
  3043. jQuery.extend({
  3044. createGooFlow: function(bgDiv, property, vue) {
  3045. return new GooFlow(bgDiv, property, vue);
  3046. }
  3047. });