| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161 |
- // 移除双击节点或连线编辑节点名或连线名
- // 追加不给决策节点连线
- // 移除连线方式,把原有的可改变设置开始端与结束端的方式移除。改为拖动连线方式,并且只能设置结束端的连线。
- // 流程图的连线规则,决策节点、结束节点,不能拖出连线
- // 开始节点只能有一条出的连线
- // 添加连线规则,结束端不能是开始节点
- // 改源代码加的打开模态框事件
- //定义一个区域图类:
- function GooFlow(bgDiv, property, vue) {
- if(navigator.userAgent.indexOf("MSIE 8.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0 || navigator.userAgent.indexOf("MSIE 6.0") > 0)
- GooFlow.prototype.useSVG = "";
- else GooFlow.prototype.useSVG = "1";
- //初始化区域图的对象
- this.$id = bgDiv.attr("id");
- this.$bgDiv = bgDiv; //最父框架的DIV
- this.$bgDiv.addClass("GooFlow");
- if(GooFlow.prototype.color.font) {
- this.$bgDiv.css("color", GooFlow.prototype.color.font);
- }
- if(GooFlow.prototype.color.main) {
- this.$bgDiv.append('<style>.GooFlow_tool_btndown{background:' + GooFlow.prototype.color.main + '}</style>');
- }
- var width = (property.width || 800);
- var height = (property.height || 500);
- this.$toolWidth = 0; // 追加工具栏的宽度
- this.$bgDiv.css({
- width: width + "px",
- height: height + "px"
- });
- this.$tool = null; //左侧工具栏对象
- this.$toolTitle; // 当前选中的节点标题
- this.$toolName; // 当前选中的节点名
- this.$Type; // 当前选中的节点名
- this.$head = null; //顶部标签及工具栏按钮
- this.$name = "newFlow_1"; //流程图的名称
- this.$key = 'newFlow_1';
- this.$nodeRemark = {}; //每一种结点或按钮的说明文字,JSON格式,key为类名,value为用户自定义文字说明
- this.$nowType = "cursor"; //当前要绘制的对象类型
- this.$lineData = {};
- this.$lineCount = 0;
- this.$nodeData = {};
- this.$nodeCount = 0;
- this.$areaData = {};
- this.$areaCount = 0;
- this.$lineDom = {};
- this.$nodeDom = {};
- this.$areaDom = {};
- this.$max = property.initNum || 1; //计算默认ID值的起始SEQUENCE
- this.$focus = ""; //当前被选定的结点/转换线ID,如果没选中或者工作区被清空,则为""
- this.$focuslineid = ""; // 选中线的id
- this.$cursor = "default"; //鼠标指针在工作区内的样式
- this.$editable = false; //工作区是否可编辑
- this.$deletedItem = {}; //在流程图的编辑操作中被删除掉的元素ID集合,元素ID为KEY,元素类型(node,line.area)为VALUE
- this.$workExtendStep = 200; //在自动/手动扩展可编辑区时,一次扩展后宽/高增加多少像素
- this.$headHeight = 0;
- var tmp = "";
- this.$vue = vue; // 自定义与 Vue 使用,可回调当前 Vue
- this.$haveGroup = property.haveGroup;
- this.$haveHead = property.haveHead;
- this.$toolBtnsAndName = property.toolBtnsAndName;
- this.$headClearance = (property.headClearance || 4) // 头间隙
- this.$end = false
- /**----------------------头部工具栏(开始)-------------------------------------**/
- if(this.$haveHead) {
- tmp = "<div class='GooFlow_head' " + (GooFlow.prototype.color.main ? "style='border-bottom-color:" + GooFlow.prototype.color.main + "'" : "") + ">";
- if(property.headLabel) {
- this.$name = property.initLabelText || this.$name;
- tmp += "<label title='" + this.$name + "' " +
- (GooFlow.prototype.color.main ? "style='background:" + GooFlow.prototype.color.main + "'" : "") + ">" + this.$name + "</label>";
- }
- for(var x = 0; x < property.headBtns.length; ++x) {
- tmp += "<a href='javascript:void(0)' class='GooFlow_head_btn'><i class='ico_" + property.headBtns[x] + "'></i></a>"
- }
- tmp += "</div>";
- this.$head = $(tmp);
- this.$bgDiv.append(this.$head);
- this.$headHeight = 28;
- //以下是当工具栏按钮被点击时触发的事件自定义(虚函数),格式为function(),因为可直接用THIS操作对象本身,不用传参;用户可自行重定义:
- this.onBtnNewClick = null; //新建流程图按钮被点中
- this.onBtnOpenClick = null; //打开流程图按钮定义
- this.onBtnSaveClick = null; //保存流程图按钮定义
- this.onFreshClick = null; //重载流程图按钮定义
- this.onPrintClick = null; //打印流程图按钮定义
- // 是否有顶部的操作按钮
- if(property.headBtns) {
- /**
- * 顶部工具栏的点击事件
- */
- this.$head.on("click", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- var tar = e.target;
- if(tar.tagName == "DIV" || tar.tagName == "SPAN") return;
- else if(tar.tagName == "A") tar = tar.childNodes[0];
- var This = e.data.inthis;
- //定义顶部操作栏按钮的事件
- switch($(tar).attr("class")) {
- case "ico_new":
- if(This.onBtnNewClick != null) This.onBtnNewClick();// 新建流程图
- break;
- case "ico_open":
- if(This.onBtnOpenClick != null) This.onBtnOpenClick();// 打开流程图
- break;
- case "ico_save":
- if(This.onBtnSaveClick != null) This.onBtnSaveClick();// 保存流程图
- break;
- case "ico_undo":
- This.undo();// 撤回
- break;
- case "ico_redo":
- This.redo();// 重做
- break;
- case "ico_reload":
- if(This.onFreshClick != null) This.onFreshClick();// 重载流程图
- break;
- case "ico_print":
- if(This.onPrintClick != null) This.onPrintClick();// 打印流程图
- break;
- }
- });
- }
- }
- /**----------------------头部工具栏(结束)-------------------------------------**/
- /**----------------------左边工具栏(开始)-------------------------------------**/
- if(property.haveTool) {
- this.$toolWidth = (property.toolWidth || 60); // 有左边工具栏才设置宽度,默认 60
- var toolNodeWidth = this.$toolWidth - 10;
- 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>");
- this.$tool = this.$bgDiv.find(".GooFlow_tool div");
- // 左边工具栏的图片设置
- //未加代码:加入绘图工具按钮
- this.$tool.append(
- "<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>" +
- "<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>" +
- "<span/>" +
- "<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>" +
- "<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>" +
- "<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>" +
- "<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>" +
- "<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>" +
- "<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>"
- );
- // 读取后台数据生成的工具
- if(this.$toolBtnsAndName && this.$toolBtnsAndName.length > 0) {
- tmp = "<span/>";
- for(var i = 0; i < this.$toolBtnsAndName.length; ++i) {
- var icon = 'spaceicon icon-node2';
- // 任务节点
- if('task' == this.$toolBtnsAndName[i].type) {
- icon = 'spaceicon icon-node2';
- }
- // 动态并行节点
- else if ('foreach' == this.$toolBtnsAndName[i].type) {
- icon = 'spaceicon icon-dynamic_parallel';
- }
- // 加入自定义按钮
- tmp += "<a href='javascript:void(0)' type='" + this.$toolBtnsAndName[i].type +
- "' title='" + this.$toolBtnsAndName[i].title +
- "' id='" + this.$id + "_btn_" + this.$toolBtnsAndName[i].type + "_" + i +
- "' class='GooFlow_tool_btn' style='width:" + toolNodeWidth + "px;' data-name='" + this.$toolBtnsAndName[i].name +
- "'><i class='" + icon + "'/>" + this.$toolBtnsAndName[i].title + "</a>";
- }
- this.$tool.append(tmp);
- }
- //加入区域划分框工具开关按钮
- // if(this.$haveGroup)
- // 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>");
- this.$nowType = "cursor";
- /**----------------------左边工具栏的拖动到 GooFlow 的画布区域(开始)-------------------------------------**/
- // 拖动工具栏的节点到 GooFlow 的画布区域
- this.$tool.find('a').on("mousedown", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- var tar;
- switch(e.target.tagName) { // 获取标签的名称,如:<div></div>,则是DIV或div
- case "SPAN":
- return false;
- case "DIV":
- return false;
- case "I":
- tar = e.target.parentNode; //获取父标签
- break;
- case "A":
- tar = e.target;
- };
- var type = $(tar).attr("type");
- switch(type) {
- case "undo": // 撤回
- case "redo": // 重做
- case "cursor": // 选择
- case "direct": // 连线
- return false;
- }
- e.data.inthis.switchToolBtn(type, $(tar).attr('id'));
- var This = e.data.inthis;
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- var X, Y;
- X = ev.x - t.left;
- Y = ev.y - t.top;
- var vX = X - 0,
- vY = Y - 0;
-
- var width = This.getWidth(null, This.$nowType)
- var height = This.getHeight(null, This.$nowType)
- var td = "<td></td><td>" + This.$toolTitle + "</td>";
- if('end' == This.$nowType) {
- td = "<td><i class='spaceicon icon-finish'></i></td>";
- }
- $('<table cellspacing="1" style="width:' + width + 'px;height:' + height + 'px;"><tbody><tr>' + td + '</tr></tbody></table>').prependTo(This.$ghost);
-
- var isMove = false;// 是否移动中,
- // 从左边工具栏拖动到画布还未释放时事件(未释放事件)
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- var ev = mousePosition(e);
- if(X == ev.x - vX && Y == ev.y - vY) return false;
- X = ev.x - (width / 2);
- Y = ev.y - (height / 2);
- if(isMove && This.$ghost.css("display") == "none") {
- This.$ghost.css({
- display: "block",
- width: width + "px",
- height: height + "px",
- top: t.top - This.$workArea[0].parentNode.scrollTop + "px",
- left: t.left - This.$workArea[0].parentNode.scrollLeft + "px",
- cursor: "move",
- 'border-radius': '20px'
- });
- if(This.$nowType == 'decision') {
- This.$ghost.css({
- 'border-radius': ''
- });
- }
- }
- if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
- X = t.left - This.$workArea[0].parentNode.scrollLeft;
- else if(X + This.$workArea[0].parentNode.scrollLeft + width > t.left + This.$workArea.width())
- X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - width;
- if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
- Y = t.top - This.$workArea[0].parentNode.scrollTop;
- else if(Y + This.$workArea[0].parentNode.scrollTop + height > t.top + This.$workArea.height())
- Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - height;
- This.$ghost.css({
- left: X + "px",
- top: Y + "px"
- });
- isMove = true;
- }
- // 已释放时事件
- document.onmouseup = function(e) {
- if(isMove) {
- var nodeItemJson = {
- id: "node_" + This.$max,
- name: This.$toolName,
- title: This.$toolTitle,
- left: X + This.$workArea[0].parentNode.scrollLeft - t.left,
- top: Y + This.$workArea[0].parentNode.scrollTop - t.top,
- type: type
- };
- // 节点名不能使用任务类型的名称
- This.addNode("node_" + This.$max, nodeItemJson);
- This.$max++;
- }
- This.$ghost.empty().hide();
- This.switchToolBtn("cursor");
- document.onmousemove = null;
- document.onmouseup = null;
- }
- return false;
- });
- /**----------------------左边工具栏的拖动到 GooFlow 的画布区域(结束)-------------------------------------**/
-
- /**----------------------左边工具栏的点击选中事件(开始)-------------------------------------**/
- //绑定各个按钮的点击事件
- this.$tool.on("click", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- var tar;
- switch(e.target.tagName) { // 获取标签的名称,如:<div></div>,则是DIV或div
- case "SPAN":
- return false;
- case "DIV":
- return false;
- case "I":
- tar = e.target.parentNode; //获取父标签
- break;
- case "A":
- tar = e.target;
- };
- var type = $(tar).attr("type");
- switch(type) {
- case "undo": // 撤回
- e.data.inthis.undo();
- return false;
- case "redo": // 重做
- e.data.inthis.redo();
- return false;
- }
- e.data.inthis.switchToolBtn(type, $(tar).attr('id'));
- return false;
- });
- /**----------------------左边工具栏的点击选中事件(结束)-------------------------------------**/
- this.$editable = true; //只有具有工具栏时可编辑
- }
- /**----------------------左边工具栏(结束)-------------------------------------**/
- width = width - this.$toolWidth;
- height = height - this.$headHeight - (this.$haveHead ? 5 : 8);
- this.$bgDiv.append("<div class='GooFlow_work' style='width:" + width + "px;height:" + (height) + "px;" + (this.$haveHead ? "" : "margin-top:" + this.$headClearance + "px") + "'></div>");
- this.$workArea = $("<div class='GooFlow_work_inner' style='width:" + width + "px;height:" + height + "px'></div>")
- .attr({
- "unselectable": "on",
- "onselectstart": 'return false',
- "onselect": 'document.selection.empty()'
- });
- this.$bgDiv.children(".GooFlow_work").append(this.$workArea);
- this.$draw = null; //画矢量线条的容器
- this.initDraw("draw_" + this.$id, width, height);
- this.$group = null;
- if(this.$haveGroup)
- this.initGroup(width, height);
- this.initExpendFunc();
- if(this.$editable) {
- // 工作区间
- this.$workArea.on("click", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- if(!e.data.inthis.$editable) return;
- var type = e.data.inthis.$nowType;
- // 移除选中状态
- if(type == "cursor") {
- var t = $(e.target);
- var n = t.prop("tagName");
- if(n == "svg" || (n == "DIV" && t.prop("class").indexOf("GooFlow_work") > -1) || n == "LABEL") {
- e.data.inthis.blurItem();
- e.data.inthis.$vue.clearCurrentFocus();
- }
- var tmp = document.getElementById("GooFlow_tmp_line");
- if(tmp) {
- tmp.remove()
- }
- return;
- } else if(type == "direct" || type == "group") return;
- })
- //划线或改线时用的绑定
- this.$workArea.mousemove({
- inthis: this
- }, function(e) {
- if(e.data.inthis.$nowType != "direct" && !e.data.inthis.$mpTo.data("p")) return;
- var lineStart = $(this).data("lineStart");
- var lineEnd = $(this).data("lineEnd");
- if(!lineStart && !lineEnd) return;
- var ev = mousePosition(e),
- t = getElCoordinate(this);
- var X, Y;
- X = ev.x - t.left + this.parentNode.scrollLeft;
- Y = ev.y - t.top + this.parentNode.scrollTop;
- var line = document.getElementById("GooFlow_tmp_line");
- if (line == null || line.childNodes == null) return
- if(lineStart) {
- if(GooFlow.prototype.useSVG != "") {
- line.childNodes[0].setAttribute("d", "M " + lineStart.x + " " + lineStart.y + " L " + X + " " + Y);
- line.childNodes[1].setAttribute("d", "M " + lineStart.x + " " + lineStart.y + " L " + X + " " + Y);
- if(line.childNodes[1].getAttribute("marker-end") == "url(\"#arrow2\")")
- line.childNodes[1].setAttribute("marker-end", "url(#arrow3)");
- else line.childNodes[1].setAttribute("marker-end", "url(#arrow2)");
- } else line.points.value = lineStart.x + "," + lineStart.y + " " + X + "," + Y;
- } else if(lineEnd) {
- if(GooFlow.prototype.useSVG != "") {
- line.childNodes[0].setAttribute("d", "M " + X + " " + Y + " L " + lineEnd.x + " " + lineEnd.y);
- line.childNodes[1].setAttribute("d", "M " + X + " " + Y + " L " + lineEnd.x + " " + lineEnd.y);
- if(line.childNodes[1].getAttribute("marker-end") == "url(\"#arrow2\")")
- line.childNodes[1].setAttribute("marker-end", "url(#arrow3)");
- else line.childNodes[1].setAttribute("marker-end", "url(#arrow2)");
- } else line.points.value = X + "," + Y + " " + lineEnd.x + "," + lineEnd.y;
- }
- });
- this.$workArea.mouseup({
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- if(This.$nowType != "direct" && !This.$mpTo.data("p")) return;
- var tmp = document.getElementById("GooFlow_tmp_line");
- if(tmp) {
- $(this).css("cursor", "auto").removeData("lineStart").removeData("lineEnd");
- This.$mpTo.hide().removeData("p");
- This.$mpFrom.hide().removeData("p");
- This.$draw.removeChild(tmp);
- This.focusItem(This.$focus, false);
- } else {
- This.$lineOper.removeData("tid");
- }
- });
- //为了结点而增加的一些集体delegate绑定
- this.initWorkForNode();
- //对结点进行移动或者RESIZE时用来显示的遮罩层
- this.$ghost = $("<div class='rs_ghost'></div>").attr({
- "unselectable": "on",
- "onselectstart": 'return false',
- "onselect": 'document.selection.empty()'
- });
- this.$bgDiv.append(this.$ghost);
- this.$textArea = $("<textarea></textarea>");
- this.$bgDiv.append(this.$textArea);
- this.$lineMove = $('<div class="GooFlow_linemove" style="display:none"></div>'); //操作折线时的移动框
- this.$workArea.append(this.$lineMove);
- this.$lineMove.on("mousedown", {
- inthis: this
- }, function(e) {
- if(e.button == 2) return false;
- var lm = $(this);
- lm.css({
- "background-color": "#333"
- });
- var This = e.data.inthis;
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- var X, Y;
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- var p = This.$lineMove.position();
- var vX = X - p.left,
- vY = Y - p.top;
- var isMove = false;
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- var ev = mousePosition(e);
- var ps = This.$lineMove.position();
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- if(This.$lineMove.data("type") == "lr") {
- X = X - vX;
- if(X < 0) X = 0;
- else if(X > This.$workArea.width())
- X = This.$workArea.width();
- This.$lineMove.css({
- left: X + "px"
- });
- } else if(This.$lineMove.data("type") == "tb") {
- Y = Y - vY;
- if(Y < 0) Y = 0;
- else if(Y > This.$workArea.height())
- Y = This.$workArea.height();
- This.$lineMove.css({
- top: Y + "px"
- });
- }
- isMove = true;
- }
- document.onmouseup = function(e) {
- if(isMove) {
- var p = This.$lineMove.position();
- if(This.$lineMove.data("type") == "lr")
- This.setLineM(This.$lineMove.data("tid"), p.left + 3);
- else if(This.$lineMove.data("type") == "tb")
- This.setLineM(This.$lineMove.data("tid"), p.top + 3);
- }
- This.$lineMove.css({
- "background-color": "transparent"
- });
- if(This.$focus == This.$lineMove.data("tid")) {
- This.focusItem(This.$lineMove.data("tid"));
- }
- document.onmousemove = null;
- document.onmouseup = null;
- }
- });
- //选定一条转换线后出现的浮动操作栏,有改变线的样式和删除线等按钮。
- 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>"); //选定线时显示的操作框
- this.$workArea.parent().append(this.$lineOper);
- this.$lineOper.on("click", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- if(e.target.tagName != "I") return;
- var This = e.data.inthis;
- // var id = $(this).data("tid");
- var id = This.$focuslineid;
- switch($(e.target).attr("class")) {
- case "b_x":
- This.delLine(id);
- this.style.display = "none";
- break;
- case "b_l1":
- This.setLineType(id, "lr");
- break;
- case "b_l2":
- This.setLineType(id, "tb");
- break;
- case "b_l3":
- This.setLineType(id, "sl");
- break;
- }
- });
- //新增移动线两个端点至新的结点功能移动功能,这里要提供移动用的DOM
- this.$mpFrom = $("<div class='GooFlow_line_mp' style='display:none'></div>");
- this.$mpTo = $("<div class='GooFlow_line_mp' style='display:none'></div>");
- this.$workArea.append(this.$mpFrom).append(this.$mpTo);
- this.initLinePointsChg();
- //下面绑定当结点/线/分组块的一些操作事件,这些事件可直接通过this访问对象本身
- //当操作某个单元(结点/线/分组块)被添加时,触发的方法,返回FALSE可阻止添加事件的发生
- //格式function(id,type,json):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,json即addNode,addLine或addArea方法的第二个传参json.
- this.onItemAdd = null;
- //当操作某个单元(结点/线/分组块)被删除时,触发的方法,返回FALSE可阻止删除事件的发生
- //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值
- this.onItemDel = null;
- //当操作某个单元(结点/分组块)被移动时,触发的方法,返回FALSE可阻止移动事件的发生
- //格式function(id,type,left,top):id是单元的唯一标识ID,type是单元的种类,有"node","area"两种取值,线line不支持移动,left是新的左边距坐标,top是新的顶边距坐标
- this.onItemMove = null;
- //当操作某个单元(结点/线/分组块)被重命名时,触发的方法,返回FALSE可阻止重命名事件的发生
- //格式function(id,name,type):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值,name是新的名称
- this.onItemRename = null;
- //当操作某个单元(结点/线)被由不选中变成选中时,触发的方法,返回FALSE可阻止选中事件的发生
- //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被选中
- this.onItemFocus = null;
- //当操作某个单元(结点/线)被由选中变成不选中时,触发的方法,返回FALSE可阻止取消选中事件的发生
- //格式function(id,type):id是单元的唯一标识ID,type是单元的种类,有"node","line"两种取值,"area"不支持被取消选中
- this.onItemBlur = null;
- //当操作某个单元(结点/分组块)被重定义大小或造型时,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
- //格式function(id,type,width,height):id是单元的唯一标识ID,type是单元的种类,有"node","line","area"三种取值;width是新的宽度,height是新的高度
- this.onItemResize = null;
- //当移动某条折线中段的位置,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
- //格式function(id,M):id是单元的唯一标识ID,M是中段的新X(或Y)的坐标
- this.onLineMove = null;
- //当变换某条连接线的类型,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
- //格式function(id,type):id是单元的唯一标识ID,type是连接线的新类型,"sl":直线,"lr":中段可左右移动的折线,"tb":中段可上下移动的折线
- this.onLineSetType = null;
- //当变换某条连接线的端点变更连接的结点时,触发的方法,返回FALSE可阻止重定大小/造型事件的发生
- //格式function(id,newStart,newEnd):id是连线单元的唯一标识ID,newStart,newEnd分别是起始结点的ID和到达结点的ID
- this.onLinePointMove = null;
- //当用重色标注某个结点/转换线时触发的方法,返回FALSE可阻止重定大小/造型事件的发生
- //格式function(id,type,mark):id是单元的唯一标识ID,type是单元类型("node"结点,"line"转换线),mark为布尔值,表示是要标注TRUE还是取消标注FALSE
- this.onItemMark = null;
- if(property.useOperStack && this.$editable) { //如果要使用堆栈记录操作并提供“撤销/重做”的功能,只在编辑状态下有效
- this.$undoStack = [];
- this.$redoStack = [];
- this.$isUndo = 0;
- ///////////////以下是构造撤销操作/重做操作的方法
- //为了节省浏览器内存空间,undo/redo中的操作缓存栈,最多只可放40步操作;超过40步时,将自动删掉最旧的一个缓存
- this.pushOper = function(funcName, paras) {
- var len = this.$undoStack.length;
- if(this.$isUndo == 1) {
- this.$redoStack.push([funcName, paras]);
- this.$isUndo = false;
- if(this.$redoStack.length > 40) this.$redoStack.shift();
- } else {
- this.$undoStack.push([funcName, paras]);
- if(this.$undoStack.length > 40) this.$undoStack.shift();
- if(this.$isUndo == 0) {
- this.$redoStack.splice(0, this.$redoStack.length);
- }
- this.$isUndo = 0;
- }
- };
- //将外部的方法加入到GooFlow对象的事务操作堆栈中,在过后的undo/redo操作中可以进行控制,一般用于对流程图以外的附加信息进行编辑的事务撤销/重做控制;
- //传参func为要执行方法对象,jsonPara为外部方法仅有的一个面向字面的JSON传参,由JSON对象带入所有要传的信息;
- //提示:为了让外部方法能够被UNDO/REDO,需要在编写这些外部方法实现时,加入对该方法执行后效果回退的另一个执行方法的pushExternalOper
- this.pushExternalOper = function(func, jsonPara) {
- this.pushOper("externalFunc", [func, jsonPara]);
- };
- //撤销上一步操作
- this.undo = function() {
- if(this.$undoStack.length == 0) return;
- this.blurItem();
- var tmp = this.$undoStack.pop();
- this.$isUndo = 1;
- if(tmp[0] == "externalFunc") {
- tmp[1][0](tmp[1][1]);
- } else {
- //传参的数量,最多支持6个.
- switch(tmp[1].length) {
- case 0:
- this[tmp[0]]();
- break;
- case 1:
- this[tmp[0]](tmp[1][0]);
- break;
- case 2:
- this[tmp[0]](tmp[1][0], tmp[1][1]);
- break;
- case 3:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2]);
- break;
- case 4:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3]);
- break;
- case 5:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4]);
- break;
- case 6:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4], tmp[1][5]);
- break;
- }
- }
- };
- //重做最近一次被撤销的操作
- this.redo = function() {
- if(this.$redoStack.length == 0) return;
- this.blurItem();
- var tmp = this.$redoStack.pop();
- this.$isUndo = 2;
- if(tmp[0] == "externalFunc") {
- tmp[1][0](tmp[1][1]);
- } else {
- //传参的数量,最多支持6个.
- switch(tmp[1].length) {
- case 0:
- this[tmp[0]]();
- break;
- case 1:
- this[tmp[0]](tmp[1][0]);
- break;
- case 2:
- this[tmp[0]](tmp[1][0], tmp[1][1]);
- break;
- case 3:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2]);
- break;
- case 4:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3]);
- break;
- case 5:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4]);
- break;
- case 6:
- this[tmp[0]](tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3], tmp[1][4], tmp[1][5]);
- break;
- }
- }
- };
- }
- $(document).keydown({
- inthis: this
- }, function(e) {
- //绑定键盘操作
- var This = e.data.inthis;
- if(This.$focus == "") return;
- switch(e.keyCode) {
- case 46: //删除
- This.delNode(This.$focus, true);
- This.delLine(This.$focus);
- break;
- }
- });
- }
- }
- GooFlow.prototype = {
- // 获取节点的初始宽度(生成节点时使用)
- getWidth: function(oldWidth, type) {
- if(!oldWidth) {
- if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
- oldWidth = 34;
- } else if(type.indexOf("fork") != -1) {
- oldWidth = 56;
- } else if(type.indexOf("join") != -1) {
- oldWidth = 44;
- } else if(type.indexOf('decision') != -1) {
- oldWidth = 44;
- } else {
- oldWidth = 104;
- }
- }
- return oldWidth
- },
- // 获取节点的初始高度(生成节点时使用)
- getHeight: function(oldHeight, type) {
- if(!oldHeight) {
- if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
- oldHeight = 34;
- } else if(type.indexOf("fork") != -1) {
- oldHeight = 42;
- } else if(type.indexOf("join") != -1) {
- oldHeight = 44;
- } else if(type.indexOf("task") != -1) {
- oldHeight = 40;
- } else if(type.indexOf('decision') != -1) {
- oldHeight = 44;
- } else {
- oldHeight = 36;
- }
- }
- return oldHeight
- },
- // 根据节点类型获取最小宽度(拖动节点时使用)
- getNodeTypeMinWidth: function(oldWidth, type) {
- if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
- oldWidth = oldWidth < 34 ? 34 : oldWidth;
- } else if(type.indexOf("fork") != -1) {
- oldWidth = oldWidth < 56 ? 56 : oldWidth;
- } else if(type.indexOf("join") != -1) {
- oldWidth = oldWidth < 44 ? 44 : oldWidth;
- } else if(type.indexOf('decision') != -1) {
- oldWidth = oldWidth < 44 ? 44 : oldWidth;
- } else {
- oldWidth = oldWidth < 104 ? 104 : oldWidth;
- }
-
- if (oldWidth % 2 != 0) {
- oldWidth++
- }
-
- return oldWidth
- },
- // 根据节点类型获取最小高度(拖动节点时使用)
- getNodeTypeMinHeight: function(oldHeight, type) {
- if(type.indexOf("start") != -1 || type.indexOf("end") != -1) {
- oldHeight = oldHeight < 34 ? 34 : oldHeight;
- } else if(type.indexOf("fork") != -1) {
- oldHeight = oldHeight < 42 ? 42 : oldHeight;
- } else if(type.indexOf("join") != -1) {
- oldHeight = oldHeight < 44 ? 44 : oldHeight;
- } else if(type.indexOf("task") != -1) {
- oldHeight = oldHeight < 40 ? 40 : oldHeight;
- } else if(type.indexOf('decision') != -1) {
- oldHeight = oldHeight < 44 ? 44 : oldHeight;
- } else {
- oldHeight = oldHeight < 36 ? 36 : oldHeight;
- }
-
- if (oldHeight % 2 != 0) {
- oldHeight++
- }
-
- return oldHeight
- },
- // 窗口改变宽度时,重新调整 GooFlow 的画布窗口
- resizeGooFlow: function(width, height) {
- this.$bgDiv.css({
- width: width + "px",
- height: height + "px"
- });
- width = width - this.$toolWidth;
- height = height - this.$headHeight - (this.$haveHead ? 5 : 8);
- this.$bgDiv.find('.GooFlow_work').css({
- width: width + "px",
- height: height + "px"
- });
- this.$bgDiv.find('.GooFlow_tool_div').css({
- height: height + "px"
- });
- this.$bgDiv.find('.GooFlow_work_inner').css({
- width: width + "px",
- height: height + "px"
- })
- if(this.$haveGroup)
- this.$bgDiv.find('.GooFlow_work_group').css({
- width: width + "px",
- height: height + "px"
- })
- this.$bgDiv.find('#' + this.$draw.id).css({
- width: width + "px",
- height: height + "px"
- })
- },
- useSVG: "",
- getSvgMarker: function(id, color) {
- var m = document.createElementNS("http://www.w3.org/2000/svg", "marker");
- m.setAttribute("id", id);
- m.setAttribute("viewBox", "0 0 6 6");
- m.setAttribute("refX", 5);
- m.setAttribute("refY", 3);
- m.setAttribute("markerUnits", "strokeWidth");
- m.setAttribute("markerWidth", 6);
- m.setAttribute("markerHeight", 6);
- m.setAttribute("orient", "auto");
- var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
- path.setAttribute("d", "M 0 0 L 6 3 L 0 6 z");
- path.setAttribute("fill", color);
- path.setAttribute("stroke-width", 0);
- m.appendChild(path);
- return m;
- },
- /**
- * 初始化画布的工作区域
- * @param {Object} id 画布的 id
- * @param {Object} width 画布的宽度
- * @param {Object} height 画布的高度
- */
- initDraw: function(id, width, height) {
- // 画布区域使用 svg 还是传统的 html 标签,低版本的浏览器不支持 svg
- if(GooFlow.prototype.useSVG != "") {
- this.$draw = document.createElementNS("http://www.w3.org/2000/svg", "svg"); //可创建带有指定命名空间的元素节点
- this.$workArea.prepend(this.$draw);
- var defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
- this.$draw.appendChild(defs);
- // 生成箭头的颜色
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow1", GooFlow.prototype.color.line || "#74bccb"));
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow2", GooFlow.prototype.color.mark || "#ff8800"));
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow3", GooFlow.prototype.color.mark || "#ff8800"));
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow4", GooFlow.prototype.color.mark || "#65c239"));// 已审的颜色
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow5", GooFlow.prototype.color.mark || "#409efe"));// 审核中的颜色
- defs.appendChild(GooFlow.prototype.getSvgMarker("arrow6", GooFlow.prototype.color.mark || "#8f929a"));// 未审的颜色
- } else {
- this.$draw = document.createElement("v:group");
- this.$draw.coordsize = width + "," + height;
- this.$workArea.prepend("<div class='GooFlow_work_vml' style='position:relative;width:" + width + "px;height:" + height + "px'></div>");
- this.$workArea.children("div")[0].insertBefore(this.$draw, null);
- }
- this.$draw.id = id;
- this.$draw.style.width = width + "px";
- this.$draw.style.height = +height + "px";
- //绑定连线的点击选中以及双击编辑事件
- var tmpClk = null;
- if(GooFlow.prototype.useSVG != "") tmpClk = "g";
- else tmpClk = "PolyLine";
- if(!this.$editable) return;
- $(this.$draw).delegate(tmpClk, "click", {
- inthis: this
- }, function(e) {
- e.data.inthis.focusItem(this.id, true);
- });
- // 改为拖动流转线
- $(this.$draw).delegate(tmpClk, "mousedown", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- This.focusItem(this.id, true);
- var isMove = false;
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- if(!isMove) {
- This.$mpTo.mousedown()
- }
- isMove = true;
- }
- document.onmouseup = function(e) {
- if(isMove) {
- This.blurItem();
- }
- document.onmousemove = null;
- document.onmouseup = null;
- }
- });
- // $(this.$draw).delegate(tmpClk, "dblclick", {
- // inthis: this
- // }, function(e) {
- // var oldTxt, x, y, from, to;
- // var This = e.data.inthis;
- // if(GooFlow.prototype.useSVG != "") {
- // oldTxt = this.childNodes[2].textContent;
- // from = this.getAttribute("from").split(",");
- // to = this.getAttribute("to").split(",");
- // } else {
- // oldTxt = this.childNodes[1].innerHTML;
- // var n = this.getAttribute("fromTo").split(",");
- // from = [n[0], n[1]];
- // to = [n[2], n[3]];
- // }
- // if(This.$lineData[this.id].type == "lr") {
- // from[0] = This.$lineData[this.id].M;
- // to[0] = from[0];
- // } else if(This.$lineData[this.id].type == "tb") {
- // from[1] = This.$lineData[this.id].M;
- // to[1] = from[1];
- // }
- // x = (parseInt(from[0], 10) + parseInt(to[0], 10)) / 2 - 64;
- // y = (parseInt(from[1], 10) + parseInt(to[1], 10)) / 2 - 18;
- // var t = getElCoordinate(This.$workArea[0]);
- // This.$textArea.val(oldTxt).css({
- // display: "block",
- // width: 130,
- // height: 26,
- // left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
- // top: t.top + y - This.$workArea[0].parentNode.scrollTop
- // }).data("id", This.$focus).focus();
- // This.$workArea.parent().one("mousedown", function(e) {
- // if(e.button == 2) return false;
- // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "line");
- // This.$textArea.val("").removeData("id").hide();
- // });
- // });
- },
- initGroup: function(width, height) {
- this.$group = $("<div class='GooFlow_work_group' style='width:" + width + "px;height:" + height + "px'></div>"); //存放背景区域的容器
- this.$workArea.prepend(this.$group);
- if(!this.$editable) return;
- //区域划分框操作区的事件绑定
- this.$group.on("mousedown", {
- inthis: this
- }, function(e) { //绑定RESIZE功能以及移动功能
- if(e.button == 2) return false;
- var This = e.data.inthis;
- if(This.$nowType != "group") return;
- if(!e) e = window.event;
- var cursor = $(e.target).css("cursor");
- var id = e.target.parentNode;
- switch(cursor) {
- case "nw-resize":
- id = id.parentNode;
- break;
- case "w-resize":
- id = id.parentNode;
- break;
- case "n-resize":
- id = id.parentNode;
- break;
- case "move":
- break;
- default:
- return;
- }
- id = id.id;
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- var X, Y;
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- if(cursor != "move") {
- This.$ghost.css({
- display: "block",
- width: This.$areaData[id].width + "px",
- height: This.$areaData[id].height + "px",
- top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
- left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
- cursor: cursor
- });
- var vX = (This.$areaData[id].left + This.$areaData[id].width) - X;
- var vY = (This.$areaData[id].top + This.$areaData[id].height) - Y;
- } else {
- var vX = X - This.$areaData[id].left;
- var vY = Y - This.$areaData[id].top;
- }
- var isMove = false;
- This.$ghost.css("cursor", cursor);
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- var ev = mousePosition(e);
- if(cursor != "move") {
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].left + vX;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$areaData[id].top + vY;
- if(X < 200) X = 200;
- if(Y < 100) Y = 100;
- switch(cursor) {
- case "nw-resize":
- This.$ghost.css({
- width: X + "px",
- height: Y + "px"
- });
- break;
- case "w-resize":
- This.$ghost.css({
- width: X + "px"
- });
- break;
- case "n-resize":
- This.$ghost.css({
- height: Y + "px"
- });
- break;
- }
- } else {
- if(This.$ghost.css("display") == "none") {
- This.$ghost.css({
- display: "block",
- width: This.$areaData[id].width + "px",
- height: This.$areaData[id].height + "px",
- top: This.$areaData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
- left: This.$areaData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
- cursor: cursor
- });
- }
- X = ev.x - vX;
- Y = ev.y - vY;
- if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
- X = t.left - This.$workArea[0].parentNode.scrollLeft;
- else if(X + This.$workArea[0].parentNode.scrollLeft + This.$areaData[id].width > t.left + This.$workArea.width())
- X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$areaData[id].width;
- if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
- Y = t.top - This.$workArea[0].parentNode.scrollTop;
- else if(Y + This.$workArea[0].parentNode.scrollTop + This.$areaData[id].height > t.top + This.$workArea.height())
- Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$areaData[id].height;
- This.$ghost.css({
- left: X + "px",
- top: Y + "px"
- });
- }
- isMove = true;
- }
- document.onmouseup = function(e) {
- This.$ghost.empty().hide();
- document.onmousemove = null;
- document.onmouseup = null;
- if(!isMove) return;
- if(cursor != "move")
- This.resizeArea(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
- else
- This.moveArea(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
- return false;
- }
- });
- //绑定修改文字说明功能
- // this.$group.on("dblclick", {
- // inthis: this
- // }, function(e) {
- // var This = e.data.inthis;
- // if(This.$nowType != "group") return;
- // if(!e) e = window.event;
- // if(e.target.tagName != "LABEL") return false;
- // var oldTxt = e.target.innerHTML;
- // var p = e.target.parentNode;
- // var x = parseInt(p.style.left, 10) + 18,
- // y = parseInt(p.style.top, 10) + 1;
- // var t = getElCoordinate(This.$workArea[0]);
- // This.$textArea.val(oldTxt).css({
- // display: "block",
- // width: 120,
- // height: 26,
- // left: t.left + x - This.$workArea[0].parentNode.scrollLeft,
- // top: t.top + y - This.$workArea[0].parentNode.scrollTop
- // }).data("id", p.id).focus();
- // This.$workArea.parent().one("mouseup", function(e) {
- // if(e.button == 2) return false;
- // if(This.$textArea.css("display") == "block") {
- // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "area");
- // This.$textArea.val("").removeData("id").hide();
- // }
- // return false;
- // });
- // return false;
- // });
- //绑定点击事件
- this.$group.mouseup({
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- if(This.$textArea.css("display") == "block") {
- This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "area");
- This.$textArea.val("").removeData("id").hide();
- return false;
- };
- if(This.$nowType != "group") return;
- if(!e) e = window.event;
- switch($(e.target).attr("class")) {
- case "rs_close":
- This.delArea(e.target.parentNode.parentNode.id);
- return false; //删除该分组区域
- case "bg":
- return;
- }
- switch(e.target.tagName) {
- case "LABEL":
- return false;
- case "I": //绑定变色功能
- var id = e.target.parentNode.id;
- switch(This.$areaData[id].color) {
- case "red":
- This.setAreaColor(id, "yellow");
- break;
- case "yellow":
- This.setAreaColor(id, "blue");
- break;
- case "blue":
- This.setAreaColor(id, "green");
- break;
- case "green":
- This.setAreaColor(id, "red");
- break;
- }
- return false;
- }
- if(e.data.inthis.$ghost.css("display") == "none") {
- var X, Y;
- var ev = mousePosition(e),
- t = getElCoordinate(this);
- X = ev.x - t.left + this.parentNode.parentNode.scrollLeft;
- Y = ev.y - t.top + this.parentNode.parentNode.scrollTop;
- var color = ["red", "yellow", "blue", "green"];
- e.data.inthis.addArea("node_" + This.$max, {
- name: "area_" + e.data.inthis.$max,
- left: X,
- top: Y,
- color: color[e.data.inthis.$max % 4],
- width: 200,
- height: 100
- });
- e.data.inthis.$max++;
- return false;
- }
- });
- },
- //加入手动扩展编辑区功能,一次扩展200px
- initExpendFunc: function() {
- this.$workArea.append('<div class="Gooflow_extend_right"></div><div class="Gooflow_extend_bottom"></div>');
- this.$workArea.children(".Gooflow_extend_right").on("click", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- var w = This.$workArea.width() + This.$workExtendStep;
- var h = This.$workArea.height();
- This.$workArea.css({
- width: w + "px"
- });
- if(GooFlow.prototype.useSVG == "") {
- This.$draw.coordsize = w + "," + h;
- }
- This.$draw.style.width = w + "px";
- if(This.$group != null) {
- This.$group.css({
- width: w + "px"
- });
- }
- var parentDiv = This.$workArea.parent()[0];
- parentDiv.scrollLeft = parentDiv.scrollWidth;
- return false;
- });
- this.$workArea.children(".Gooflow_extend_bottom").on("click", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis
- var w = This.$workArea.width();
- var h = This.$workArea.height() + This.$workExtendStep;
- This.$workArea.css({
- height: h + "px"
- });
- if(GooFlow.prototype.useSVG == "") {
- This.$draw.coordsize = w + "," + h;
- }
- This.$draw.style.height = h + "px";
- if(This.$group != null) {
- This.$group.css({
- height: h + "px"
- });
- }
- var parentDiv = This.$workArea.parent()[0];
- parentDiv.scrollTop = parentDiv.scrollHeight;
- return false;
- });
- },
- //初始化用来改变连线的连接端点的两个小方块的操作事件
- initLinePointsChg: function() {
- this.$mpFrom.on("mousedown", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- This.switchToolBtn("cursor");
- var ps = This.$mpFrom.data("p").split(",");
- var pe = This.$mpTo.data("p").split(",");
- $(this).hide();
- This.$workArea.data("lineEnd", {
- "x": pe[0],
- "y": pe[1],
- "id": This.$lineData[This.$lineOper.data("tid")].to
- }).css("cursor", "crosshair");
- var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [ps[0], ps[1]], [pe[0], pe[1]], true, true);
- This.$draw.appendChild(line);
- return false;
- });
- this.$mpTo.on("mousedown", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- This.switchToolBtn("cursor");
- if (!This.$mpFrom.data("p") || !This.$mpTo.data("p") || !This.$lineOper.data("tid")) {
- var tmp = document.getElementById("GooFlow_tmp_line");
- if(tmp) {
- This.$draw.removeChild(tmp);
- }
- return
- }
- var ps = This.$mpFrom.data("p").split(",");
- var pe = This.$mpTo.data("p").split(",");
- $(this).hide();
- This.$workArea.data("lineStart", {
- "x": ps[0],
- "y": ps[1],
- "id": This.$lineData[This.$lineOper.data("tid")].from
- }).css("cursor", "crosshair");
- var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [ps[0], ps[1]], [pe[0], pe[1]], true, true);
- This.$draw.appendChild(line);
- return false;
- });
- },
- /**
- * 每一种类型结点及其按钮的说明文字
- * @param {Object} remark 工具栏的按钮的说明文字 json map 类型
- */
- // setNodeRemarks: function(remark) {
- // if(this.$tool == null) return;
- // this.$tool.children("a").each(function() {
- // this.title = remark[$(this).attr("id").split("btn_")[1]];
- // });
- // this.$nodeRemark = remark;
- // },
- /**
- * 切换左边工具栏按钮,传参TYPE表示切换成哪种类型的按钮
- * @param {Object} type 工具类型
- * @param {Object} id 工具的 id,如果:有传 id 则根据指定的 id ,没有:则根据类型来获取固定规则的 id
- */
- switchToolBtn: function(type, id) {
- this.$tool.find('a').attr("class", "GooFlow_tool_btn") // 移除工具栏的 a 标签 样式
- if(this.$nowType == "group") {
- this.$workArea.prepend(this.$group);
- for(var key in this.$areaDom) this.$areaDom[key].addClass("lock").children("div:eq(1)").css("display", "none");
- }
- this.$nowType = type;
- var tmpid = id ? id : this.$id + "_btn_" + this.$nowType
- this.$tool.find('#' + tmpid).attr("class", "GooFlow_tool_btndown") // 添加当前选择的样式
- this.$toolTitle = this.$tool.find('#' + tmpid).attr('title')
- this.$toolName = this.$tool.find('#' + tmpid).attr('data-name')
- this.$Type = this.$tool.find('#' + tmpid).attr('type')
- if(this.$nowType == "group") {
- this.blurItem();
- this.$workArea.append(this.$group);
- for(var key in this.$areaDom) this.$areaDom[key].removeClass("lock").children("div:eq(1)").css("display", "");
- } else if(this.$nowType == "direct") {
- this.blurItem();
- }
- if(this.$textArea.css("display") == "none") this.$textArea.removeData("id").val("").hide();
- },
- /**
- * 增加决策的线
- * @param {Object} id 节点 id
- * @param {Object} lines 决策节点出现的线集合,数组
- */
- addDecisionLine: function(id, lines) {
- // 删除当前决策节点已选的类型的线
- for(var key in this.$lineData) {
- if(id == this.$lineData[key].from) {
- this.delLine(key)
- }
- }
- if(lines == null) return
- // 添加已选的类型的线
- for(var i = 0; i < lines.length; i++) {
- var lineid = "node_" + this.$max
- this.$max++;
- //设置$lineData[id]
- this.$lineData[lineid] = {
- type: 'sl',
- from: id,
- to: null,
- name: lines[i],
- marked: false,
- decision: true,
- coordX: i * (Number(i + 1 + '0') + 150) - 100,
- coordY: 150
- }
- //设置$lineData[id]完毕
- var n1 = this.$nodeData[this.$lineData[lineid].from] //获取开始/结束结点的数据
- //开始计算线端点坐标
- var res = GooFlow.prototype.calcStartEnd(n1, n1);
- if(!res) return;
- res.end[0] = res.end[0] + this.$lineData[lineid].coordX
- res.end[1] = res.end[1] + this.$lineData[lineid].coordY
- this.$lineDom[lineid] = GooFlow.prototype.drawLine(lineid, res.start, res.end, this.$lineData[lineid].marked, false, this.$lineData[lineid].name);
- this.$draw.appendChild(this.$lineDom[lineid]);
- var nodes = this.$lineDom[lineid].childNodes
- this.$lineDom[lineid].childNodes[nodes.length - 1].textContent = this.$lineData[lineid].name;
- ++this.$lineCount;
- if(this.$editable) {
- this.$lineData[lineid].alt = true;
- if(this.$deletedItem[lineid]) delete this.$deletedItem[lineid]; //在回退删除操作时,去掉该元素的删除记录
- }
- }
- },
- //增加一个流程结点,传参为一个JSON,有id,name,top,left,width,height,type(结点类型)等属性
- addNode: function(id, json) {
- if(this.onItemAdd != null && !this.onItemAdd(id, "node", json)) return;
- if(this.$undoStack && this.$editable) {
- this.pushOper("delNode", [id]);
- }
- var mark = json.marked ? " item_mark" : "";
- json.width = this.getWidth(json.width, json.type)
- json.height = this.getHeight(json.height, json.type)
- if(json.type.indexOf("start") < 0 && json.type.indexOf("end") < 0) {
- if(!json.top || json.top < 0) json.top = 0;
- if(!json.left || json.left < 0) json.left = 0;
- var rs_div = "<div style='display:none'>"
- rs_div += (json.type.indexOf("fork") != -1 || json.type.indexOf("join") != -1) ?
- "<div class='rs_close'></div>" :
- "<div class='rs_close'></div><div class='rs_bottom'></div><div class='rs_right'></div><div class='rs_rb'></div>"
- rs_div += "</div>"
- if (json.type.indexOf("fork") != -1) {
- json.title = '分支'
- }
- if (json.type.indexOf("join") != -1) {
- json.title = '汇合'
- }
-
- // 这里是回显时的样式控制
- var foreachClass = "";// 动态审核节点,也是动态分支节点,样式与其他节点不同,多加 class 样式,不使用背景颜色
- var bgc = "";
- if (json.audit_state == '已审') {
- if (json.type.indexOf("foreach") != -1) {
- foreachClass = " flow_foreach_green ";
- }
- else {
- bgc = 'background-color: #65c239;';
- }
- } else if (json.audit_state == '审核中') {
- if (json.type.indexOf("foreach") != -1) {
- foreachClass = " flow_foreach_blue ";
- }
- else {
- bgc = 'background-color: #409efe;';
- }
- } else if (json.audit_state == '未审') {
- if (json.type.indexOf("foreach") != -1) {
- foreachClass = " flow_foreach_gray ";
- }
- else {
- bgc = 'background-color: #8f929a;';
- }
- }
- // 添加节点(不包含开始与结束节点)
- this.$nodeDom[id] = $(
- "<div class='GooFlow_item" + mark + " flow_" + json.type + foreachClass + "' id='" + id + "' style='top:" + json.top + "px;left:" + json.left + "px;" + bgc + "'>" +
- "<table cellspacing='1' style='width:" + (json.width - 2) + "px;height:" + (json.height - 2) + "px;'>" +
- "<tr>" +
- "<td></td>" +
- "<td>" + json.title + "</td>" +
- "</tr>" +
- "</table>" + rs_div +
- "</div>"
- );
- } else { // 开始或者结束节点
- var rs_div = ""
- if(json.type.indexOf("end") != -1) {
- if(this.$end == true) {
- rs_div = "<div style='display:none'><div class='rs_close'></div></div>"
- }
- this.$end = true
- }
- var nodeCss = json.type.indexOf("start") != -1 ? 'spaceicon icon-start' : 'spaceicon icon-finish'
- // 已移除《开始》《结束》节点中的关闭按钮
- 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>");
- }
- if(GooFlow.prototype.color.node) {
- if(json.type.indexOf("start") > -1 || json.type.indexOf("end") > -1) { // 开始与结束节点的样式
- this.$nodeDom[id].css({
- "background-color": GooFlow.prototype.color.mix,
- "border-color": GooFlow.prototype.color.mix
- });
- if(GooFlow.prototype.color.mixFont) {
- this.$nodeDom[id].find("td:eq(1)").css("color", GooFlow.prototype.color.mixFont);
- this.$nodeDom[id].find(".span").css("color", GooFlow.prototype.color.mixFont);
- }
- } else {
- this.$nodeDom[id].css({
- "background-color": GooFlow.prototype.color.node,
- "border-color": GooFlow.prototype.color.node
- });
- }
- if(mark && GooFlow.prototype.color.mark) {
- this.$nodeDom[id].css({
- "border-color": GooFlow.prototype.color.mark
- });
- }
- }
- if(json.type.indexOf("end") > -1) {
- this.$nodeDom[id].addClass("item_mix");
- }
- var ua = navigator.userAgent.toLowerCase();
- if(ua.indexOf('msie') != -1 && ua.indexOf('8.0') != -1)
- this.$nodeDom[id].css("filter", "progid:DXImageTransform.Microsoft.Shadow(color=#94AAC2,direction=135,strength=2)");
- this.$workArea.append(this.$nodeDom[id]);
- this.$nodeData[id] = json;
- ++this.$nodeCount;
- if(this.$editable) {
- this.$nodeData[id].alt = true;
- if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
- }
- },
- initWorkForNode: function() {
- //绑定点击事件
- this.$workArea.delegate(".GooFlow_item", "click", {
- inthis: this
- }, function(e) {
- e.data.inthis.focusItem(this.id, true);
- $(this).removeClass("item_mark");
- var node = e.data.inthis.$focus;
- var nodeData = e.data.inthis.$nodeData[node];
- e.data.inthis.$vue.openNodeAttrCall(e.data.inthis, nodeData);
- // 改源代码加的打开模态框事件
- });
- //绑定用鼠标移动事件
- this.$workArea.delegate(".GooFlow_item table", "mousedown", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- if(e.button == 2) return false;
- var This = e.data.inthis;
- if(This.$nowType == "direct") return;
- var Dom = $(this).parents(".GooFlow_item");
- var id = Dom.attr("id");
- This.focusItem(id, true);
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- Dom.children("table").clone().prependTo(This.$ghost);
- var X, Y;
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- var vX = X - This.$nodeData[id].left,
- vY = Y - This.$nodeData[id].top;
- var isMove = false;
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- var ev = mousePosition(e);
- if(X == ev.x - vX && Y == ev.y - vY) return false;
- X = ev.x - vX;
- Y = ev.y - vY;
- if(isMove && This.$ghost.css("display") == "none") {
- var node = This.$focus;
- var nodeData = This.$nodeData[node];
- This.$vue.openNodeAttrCall(This, nodeData);
- // 改源代码加的打开模态框事件
- This.$ghost.css({
- display: "block",
- width: This.$nodeData[id].width + "px",
- height: This.$nodeData[id].height + "px",
- top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
- left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
- cursor: "move",
- 'border-radius': '20px'
- });
- if(This.$nodeData[id].type == 'decision') {
- This.$ghost.css({
- 'border-radius': ''
- });
- }
- }
- if(X < t.left - This.$workArea[0].parentNode.scrollLeft)
- X = t.left - This.$workArea[0].parentNode.scrollLeft;
- else if(X + This.$workArea[0].parentNode.scrollLeft + This.$nodeData[id].width > t.left + This.$workArea.width())
- X = t.left + This.$workArea.width() - This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].width;
- if(Y < t.top - This.$workArea[0].parentNode.scrollTop)
- Y = t.top - This.$workArea[0].parentNode.scrollTop;
- else if(Y + This.$workArea[0].parentNode.scrollTop + This.$nodeData[id].height > t.top + This.$workArea.height())
- Y = t.top + This.$workArea.height() - This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].height;
- This.$ghost.css({
- left: X + "px",
- top: Y + "px"
- });
- isMove = true;
- }
- document.onmouseup = function(e) {
- // 改为同一个标签中存在《点击事件》与《拖动事件》
- if(isMove) {
- This.moveNode(id, X + This.$workArea[0].parentNode.scrollLeft - t.left, Y + This.$workArea[0].parentNode.scrollTop - t.top);
- } else {
- Dom.click();
- }
- This.$ghost.empty().hide();
- document.onmousemove = null;
- document.onmouseup = null;
- }
- });
- if(!this.$editable) return;
- //绑定鼠标覆盖/移出事件
- this.$workArea.delegate(".GooFlow_item", "mouseenter", {
- inthis: this
- }, function(e) {
- if(e.data.inthis.$nowType != "direct" && !document.getElementById("GooFlow_tmp_line")) return;
- $(this).addClass("item_mark").addClass("crosshair").css("border-color", GooFlow.prototype.color.mark || "#ff8800");
- });
- this.$workArea.delegate(".GooFlow_item", "mouseleave", {
- inthis: this
- }, function(e) {
- if(e.data.inthis.$nowType != "direct" && !document.getElementById("GooFlow_tmp_line")) return;
- $(this).removeClass("item_mark").removeClass("crosshair");
- if(this.id == e.data.inthis.$focus) {
- $(this).css("border-color", GooFlow.prototype.color.line || "#74bccb");
- } else {
- $(this).css("border-color", GooFlow.prototype.color.node || "#A1DCEB");
- }
- });
- //绑定连线时确定初始点
- this.$workArea.delegate(".GooFlow_item", "mousedown", {
- inthis: this
- }, function(e) {
- if(e.button == 2) return false;
- var This = e.data.inthis;
- if(This.$nowType != "direct") return;
-
- // 流程图的连线规则,决策节点、结束节点,不能拖出连线
- if(This.$nodeData[this.id].type == 'decision' || This.$nodeData[this.id].type == 'end') return;// 追加不给决策、结束节点连线
-
- // 开始节点只能有一条出的连线
- if (This.$nodeData[this.id].type == 'start') {
- for (var line in This.$lineData) {
- if (This.$lineData[line].from == this.id) return
- }
- }
-
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- var X, Y;
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- This.$workArea.data("lineStart", {
- "x": X,
- "y": Y,
- "id": this.id
- }).css("cursor", "crosshair");
- var line = GooFlow.prototype.drawLine("GooFlow_tmp_line", [X, Y], [X, Y], true, true);
- This.$draw.appendChild(line);
- });
- //绑定连线时确定结束点
- this.$workArea.delegate(".GooFlow_item", "mouseup", {
- inthis: this
- }, function(e) {
- var This = e.data.inthis;
- if(This.$nowType != "direct" && !This.$mpTo.data("p")) return;
- var lineStart = This.$workArea.data("lineStart");
- var lineEnd = This.$workArea.data("lineEnd");
- if(lineStart && !This.$mpTo.data("p")) {
- This.addLine("node_" + This.$max, {
- from: lineStart.id,
- to: this.id,
- name: ""
- });
- This.$max++;
- } else {
- if(lineStart) {
- This.moveLinePoints(This.$focus, lineStart.id, this.id);
- } else if(lineEnd) {
- This.moveLinePoints(This.$focus, this.id, lineEnd.id);
- }
- if(!This.$nodeData[this.id].marked) {
- $(this).removeClass("item_mark");
- if(this.id != This.$focus) {
- $(this).css("border-color", GooFlow.prototype.color.node);
- } else {
- $(this).css("border-color", GooFlow.prototype.color.line);
- }
- }
- }
- });
- //绑定双击编辑事件,不提供直接编辑节点名
- // this.$workArea.delegate(".GooFlow_item > .span", "dblclick", {
- // inthis: this
- // }, function(e) {
- // var oldTxt = this.innerHTML;
- // var This = e.data.inthis;
- // var id = this.parentNode.id;
- // var t = getElCoordinate(This.$workArea[0]);
- // This.$textArea.val(oldTxt).css({
- // display: "block",
- // height: $(this).height() + 6,
- // width: 100,
- // left: t.left + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft - 26,
- // top: t.top + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop + 26
- // })
- // .data("id", This.$focus).focus();
- // This.$workArea.parent().one("mousedown", function(e) {
- // if(e.button == 2) return false;
- // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "node");
- // This.$textArea.val("").removeData("id").hide();
- // });
- // });
- // this.$workArea.delegate(".ico + td", "dblclick", {
- // inthis: this
- // }, function(e) {
- // var oldTxt = this.innerHTML;
- // var This = e.data.inthis;
- // var id = $(this).parents(".GooFlow_item").attr("id");
- // var t = getElCoordinate(This.$workArea[0]);
- // This.$textArea.val(oldTxt).css({
- // display: "block",
- // width: $(this).width() + 26,
- // height: $(this).height() + 6,
- // left: t.left + 26 + This.$nodeData[id].left - This.$workArea[0].parentNode.scrollLeft,
- // top: t.top + 2 + This.$nodeData[id].top - This.$workArea[0].parentNode.scrollTop
- // })
- // .data("id", This.$focus).focus();
- // This.$workArea.parent().one("mousedown", function(e) {
- // if(e.button == 2) return false;
- // This.setNodeName(This.$textArea.data("id"), This.$textArea.val(), "node");
- // This.$textArea.val("").removeData("id").hide();
- // });
- // });
- //绑定结点的删除功能
- this.$workArea.delegate(".rs_close", "click", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- e.data.inthis.delNode(e.data.inthis.$focus);
- return false;
- });
- //绑定结点的RESIZE功能
- this.$workArea.delegate(".GooFlow_item > div > div[class!=rs_close]", "mousedown", {
- inthis: this
- }, function(e) {
- if(!e) e = window.event;
- if(e.button == 2) return false;
- var cursor = $(this).css("cursor");
- if(cursor == "pointer") {
- return;
- }
- var This = e.data.inthis;
- var id = This.$focus;
- This.switchToolBtn("cursor");
- e.cancelBubble = true;
- e.stopPropagation();
- var ev = mousePosition(e),
- t = getElCoordinate(This.$workArea[0]);
- This.$ghost.css({
- display: "block",
- width: This.$nodeData[id].width + "px",
- height: This.$nodeData[id].height + "px",
- top: This.$nodeData[id].top + t.top - This.$workArea[0].parentNode.scrollTop + "px",
- left: This.$nodeData[id].left + t.left - This.$workArea[0].parentNode.scrollLeft + "px",
- cursor: cursor
- });
- var X, Y;
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop;
- var vX = (This.$nodeData[id].left + This.$nodeData[id].width) - X;
- var vY = (This.$nodeData[id].top + This.$nodeData[id].height) - Y;
- var isMove = false;
- This.$ghost.css("cursor", cursor);
- document.onmousemove = function(e) {
- if(!e) e = window.event;
- var ev = mousePosition(e);
- X = ev.x - t.left + This.$workArea[0].parentNode.scrollLeft - This.$nodeData[id].left + vX;
- Y = ev.y - t.top + This.$workArea[0].parentNode.scrollTop - This.$nodeData[id].top + vY;
- X = This.getNodeTypeMinWidth(X, This.$nodeData[id].type);
- Y = This.getNodeTypeMinHeight(Y, This.$nodeData[id].type);
- isMove = true;
- switch(cursor) {
- case "nw-resize":
- This.$ghost.css({
- width: X + "px",
- height: Y + "px"
- });
- break;
- case "w-resize":
- This.$ghost.css({
- width: X + "px"
- });
- break;
- case "n-resize":
- This.$ghost.css({
- height: Y + "px"
- });
- break;
- }
- }
- document.onmouseup = function(e) {
- document.onmousemove = null;
- document.onmouseup = null;
- This.$ghost.hide();
- if(!isMove) return;
- if(!e) e = window.event;
- This.resizeNode(id, This.$ghost.outerWidth(), This.$ghost.outerHeight());
- This.focusItem(id, true); // 重新选中当前节点
- }
- });
- },
- //获取结点/连线/分组区域的详细信息
- getItemInfo: function(id, type) {
- switch(type) {
- case "node":
- return this.$nodeData[id] || null;
- case "line":
- return this.$lineData[id] || null;
- case "area":
- return this.$areaData[id] || null;
- }
- },
- //取消所有结点/连线被选定的状态
- blurItem: function() {
- if(this.$focus != "") {
- var jq = $("#" + this.$focus);
- if(jq.prop("tagName") == "DIV") {
- if(this.onItemBlur != null && !this.onItemBlur(this.$focus, "node")) return false;
- jq.removeClass("item_focus").children("div:eq(0)").css("display", "none");
- if(this.$nodeData[this.$focus].marked) {
- jq.addClass("item_mark").css("border-color", GooFlow.prototype.color.mark || '#ff8800');
- }
- } else {
- if(this.onItemBlur != null && !this.onItemBlur(this.$focus, "line")) return false;
- var nodes = jq[0].childNodes;
- if (nodes.length == 4) nodes[2].setAttribute("fill", "#74bccb")
- if(GooFlow.prototype.useSVG != "") {
- if(!this.$lineData[this.$focus].marked) {
- jq[0].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
- jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow1)");
- }
- } else {
- if(!this.$lineData[this.$focus].marked) {
- jq[0].strokeColor = GooFlow.prototype.color.line || "#74bccb";
- }
- }
- this.$lineMove.hide().removeData("type").removeData("tid");
- if(this.$editable) {
- this.$lineOper.hide().removeData("tid");
- this.$mpFrom.hide().removeData("p");
- this.$mpTo.hide().removeData("p");
- }
- }
- }
- this.$focus = "";
- return true;
- },
- //选定某个结点/转换线 bool:TRUE决定了要触发选中事件,FALSE则不触发选中事件,多用在程序内部调用。
- focusItem: function(id, bool) {
- var jq = $("#" + id);
- if(jq.length == 0) return;
- if(!this.blurItem()) return; //先执行"取消选中",如果返回FLASE,则也会阻止选定事件继续进行.
- if(jq.prop("tagName") == "DIV") {
- if(bool && this.onItemFocus != null && !this.onItemFocus(id, "node")) return;
- jq.addClass("item_focus");
- if(GooFlow.prototype.color.line) {
- jq.css("border-color", GooFlow.prototype.color.line);
- }
- if(this.$editable) jq.children("div:eq(0)").css("display", "block");
- this.$workArea.append(jq);
- } else { //如果是连接线
- if(this.onItemFocus != null && !this.onItemFocus(id, "line")) return;
- var nodes = jq[0].childNodes;
- if (nodes.length == 4) nodes[2].setAttribute("fill", "#ff8800")
- if(GooFlow.prototype.useSVG != "") {
- jq[0].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
- jq[0].childNodes[1].setAttribute("marker-end", "url(#arrow2)");
- } else {
- jq[0].strokeColor = GooFlow.prototype.color.mark || "#ff8800";
- }
- if(!this.$editable) return;
- var x, y, from, to, n;
- if(GooFlow.prototype.useSVG != "") {
- from = jq.attr("from").split(",");
- to = jq.attr("to").split(",");
- n = [from[0], from[1], to[0], to[1]];
- } else {
- n = jq[0].getAttribute("fromTo").split(",");
- from = [n[0], n[1]];
- to = [n[2], n[3]];
- }
- from[0] = parseInt(from[0], 10);
- from[1] = parseInt(from[1], 10);
- to[0] = parseInt(to[0], 10);
- to[1] = parseInt(to[1], 10);
-
- if (!this.$lineData[id]) return
-
- if(this.$lineData[id].type == "lr") {
- from[0] = this.$lineData[id].M;
- to[0] = from[0];
- this.$lineMove.css({
- width: "5px",
- height: (to[1] - from[1]) * (to[1] > from[1] ? 1 : -1) + "px",
- left: from[0] - 3 + "px",
- top: (to[1] > from[1] ? from[1] : to[1]) + 1 + "px",
- cursor: "e-resize",
- display: "block"
- }).data({
- "type": "lr",
- "tid": id
- });
- } else if(this.$lineData[id].type == "tb") {
- from[1] = this.$lineData[id].M;
- to[1] = from[1];
- this.$lineMove.css({
- width: (to[0] - from[0]) * (to[0] > from[0] ? 1 : -1) + "px",
- height: "5px",
- left: (to[0] > from[0] ? from[0] : to[0]) + 1 + "px",
- top: from[1] - 3 + "px",
- cursor: "s-resize",
- display: "block"
- }).data({
- "type": "tb",
- "tid": id
- });
- }
- x = (from[0] + to[0]) / 2 - 40;
- y = (from[1] + to[1]) / 2 + 4;
- // this.$lineOper.css({
- // display: "block",
- // left: x + "px",
- // top: y + "px"
- // }).data("tid", id);
- this.$focuslineid = id;
- this.$lineOper.data("tid", id);
- // 改为支持(不能移动开始端点的,只能移动结束端点)
- if(this.$lineData[id].to == null) {
- // 没有连接到结束端点时,不出现可设置连接线的
- } else if(this.$lineData[id].decision) {
- // 连接了结束端点,到该节点不支持修改开始端点,(可设置线,但不能删除该连接线)
- this.$lineOper.css({
- display: "block",
- left: x + "px",
- top: y + "px",
- width: '64px'
- });
- // 移除可删除连接线的按钮
- this.$lineOper.find('.b_x').remove();
- } else {
- // 追加可删除连接线的按钮
- if(this.$lineOper.find('.b_x').length == 0) {
- this.$lineOper.append("<i class='b_x'></i>");
- }
- this.$lineOper.css({
- display: "block",
- left: x + "px",
- top: y + "px",
- width: '82px'
- });
- }
- if(this.$editable) {
- this.$mpFrom.data("p", n[0] + "," + n[1]);
- this.$mpTo.data("p", n[2] + "," + n[3]);
- // if (this.$lineData[id].to != null && !this.$lineData[id].decision) {
- // // 不能移动开始端点的,这里只出现可移动的小方块
- // this.$mpFrom.css({
- // display: "block",
- // left: (n[0] - 10) + "px",
- // top: n[1] - 10 + "px"
- // })
- // }
- // this.$mpTo.css({
- // display: "block",
- // left: n[2] - 11 + "px",
- // top: n[3] - 11 + "px"
- // }).data("p", n[2] + "," + n[3]);
- }
- this.$draw.appendChild(jq[0]);
- this.$vue.clearCurrentFocus();
- }
- this.$focus = id;
- this.switchToolBtn("cursor");
- },
- //移动结点到一个新的位置
- moveNode: function(id, left, top) {
- if(!this.$nodeData[id]) return;
- if(this.onItemMove != null && !this.onItemMove(id, "node", left, top)) return;
- if(this.$undoStack) {
- var paras = [id, this.$nodeData[id].left, this.$nodeData[id].top];
- this.pushOper("moveNode", paras);
- }
- if(left < 0) left = 0;
- if(top < 0) top = 0;
- $("#" + id).css({
- left: left + "px",
- top: top + "px"
- });
- this.$nodeData[id].left = left;
- this.$nodeData[id].top = top;
- //重画转换线
- this.resetLines(id, this.$nodeData[id]);
- if(this.$editable) {
- this.$nodeData[id].alt = true;
- }
- },
- //设置结点/连线/分组区域的文字信息
- setNodeName: function(id, title, type) {
- var oldName;
- if(type == "node") { //如果是结点
- if(!this.$nodeData[id]) return;
- // 阻止name相同时不执行
- // if(this.$nodeData[id].title == title) return;
- if(this.onItemRename != null && !this.onItemRename(id, title, "node")) return;
- oldName = this.$nodeData[id].title;
- this.$nodeData[id].title = title;
- if(this.$nodeData[id].type.indexOf("round") > 1) {
- this.$nodeDom[id].children(".span").text(title);
- } else {
- this.$nodeDom[id].find("td:eq(1)").text(title);
- var width = this.$nodeDom[id].width();
- var height = this.$nodeDom[id].height();
- this.$nodeDom[id].children("table").css({
- width: width + "px",
- height: height + "px"
- });
- this.$nodeData[id].width = width;
- this.$nodeData[id].height = height;
- }
- if(this.$editable) {
- this.$nodeData[id].alt = true;
- }
- //重画转换线
- this.resetLines(id, this.$nodeData[id]);
- } else if(type == "line") { //如果是线
- if(!this.$lineData[id]) return;
- if(this.$lineData[id].title == title) return;
- if(this.onItemRename != null && !this.onItemRename(id, title, "line")) return;
- oldName = this.$lineData[id].title;
- this.$lineData[id].title = title;
- if(GooFlow.prototype.useSVG != "") {
- this.$lineDom[id].childNodes[2].textContent = title;
- } else {
- this.$lineDom[id].childNodes[1].innerHTML = title;
- var n = this.$lineDom[id].getAttribute("fromTo").split(",");
- var x;
- if(this.$lineData[id].type != "lr") {
- x = (n[2] - n[0]) / 2;
- } else {
- var Min = n[2] > n[0] ? n[0] : n[2];
- if(Min > this.$lineData[id].M) Min = this.$lineData[id].M;
- x = this.$lineData[id].M - Min;
- }
- if(x < 0) x = x * -1;
- this.$lineDom[id].childNodes[1].style.left = x - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4 + "px";
- }
- if(this.$editable) {
- this.$lineData[id].alt = true;
- }
- } else if(type == "area") { //如果是分组区域
- if(!this.$areaData[id]) return;
- if(this.$areaData[id].title == title) return;
- if(this.onItemRename != null && !this.onItemRename(id, title, "area")) return;
- oldName = this.$areaData[id].title;
- this.$areaData[id].title = title;
- this.$areaDom[id].children("label").text(title);
- if(this.$editable) {
- this.$areaData[id].alt = true;
- }
- }
- if(this.$undoStack) {
- var paras = [id, oldName, type];
- this.pushOper("setNodeName", paras);
- }
- },
- //设置结点的尺寸,仅支持非开始/结束结点
- resizeNode: function(id, width, height) {
- if(!this.$nodeData[id]) return;
- if(this.onItemResize != null && !this.onItemResize(id, "node", width, height)) return;
- if(this.$nodeData[id].type == "start" || this.$nodeData[id].type == "end") return;
- if(this.$undoStack) {
- var paras = [id, this.$nodeData[id].width, this.$nodeData[id].height];
- this.pushOper("resizeNode", paras);
- }
- this.$nodeDom[id].children("table").css({
- width: width - 2 + "px",
- height: height - 2 + "px"
- });
- //width=this.$nodeDom[id].outerWidth();
- //height=this.$nodeDom[id].outerHeight();
- //this.$nodeDom[id].children("table").css({width:width-2+"px",height:height-2+"px"});
- this.$nodeData[id].width = width;
- this.$nodeData[id].height = height;
- if(this.$editable) {
- this.$nodeData[id].alt = true;
- }
- //重画转换线
- this.resetLines(id, this.$nodeData[id]);
- },
- //删除结点
- delNode: function(id, trigger) {
- if(!this.$nodeData[id]) return;
- if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
- //先删除可能的连线
- for(var k in this.$lineData) {
- if(this.$lineData[k].from == id || this.$lineData[k].to == id) {
-
- if (this.$lineData[k].to == id && this.$lineData[k].decision) {
- this.$lineData[k].type = "sl"; // 重新设置为直线
- this.$lineData[k].to = null;
- this.resetLines(this.$lineData[k].from, this.$nodeData[this.$lineData[k].from]);
- continue
- }
- //this.$draw.removeChild(this.$lineDom[k]);
- //delete this.$lineData[k];
- //delete this.$lineDom[k];
- this.delLine(k, false);
- }
- }
- //再删除结点本身
- if(this.$undoStack) {
- var paras = [id, this.$nodeData[id]];
- this.pushOper("addNode", paras);
- }
- delete this.$nodeData[id];
- this.$nodeDom[id].remove();
- delete this.$nodeDom[id];
- --this.$nodeCount;
- if(this.$focus == id) this.$focus = "";
- if(this.$editable) {
- //在回退新增操作时,如果节点ID以this.$id+"_node_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
- if(id.indexOf(this.$id + "_node_") < 0)
- this.$deletedItem[id] = "node";
- }
- this.$vue.clearCurrentFocus();
- },
- /**
- * 设置流程图的名称
- * @param {Object} name 名称
- */
- setTitle: function(name) {
- this.$name = name;
- // if(this.$head) this.$head.children("label").attr("title", name).text(name);
- },
- /**
- * 自定义流程图的 key
- * @param {Object} key
- */
- setKey: function(key) {
- this.$key = key;
- },
- /**
- * 载入一组数据
- * @param {Object} data
- */
- loadData: function(data) {
- var t = this.$editable;
- this.$editable = false;
- if(data == null || data == undefined) {
- data = {
- name: "",
- nodes: {
- "node_1": {
- "id": "node_1",
- "title": "开始",
- "left": parseInt(Math.random() * 400),
- "top": parseInt(Math.random() * 400),
- "type": "start",
- "alt": true
- },
- "node_2": {
- "id": "node_2",
- "title": "结束",
- "left": parseInt(Math.random() * 400),
- "top": parseInt(Math.random() * 400),
- "type": "end",
- "alt": true
- }
- },
- initNum: 3
- }
- }
- if(data.name) this.setTitle(data.name);
- if(data.initNum) this.$max = data.initNum;
- for(var i in data.nodes)
- this.addNode(i, data.nodes[i]);
- for(var j in data.lines)
- this.addLine(j, data.lines[j]);
- for(var k in data.areas)
- this.addArea(k, data.areas[k]);
- this.$editable = t;
- this.$deletedItem = {};
- //自行重构工作区,使之大小自适应
- var width = this.$workArea.width();
- var height = this.$workArea.height();
- var maxW = 0,
- maxH = 0;
- for(var key in this.$nodeData) {
- var item = this.$nodeData[key];
- if(maxW < item.width + item.left) {
- maxW = item.width + item.left;
- }
- if(maxH < item.height + item.top) {
- maxH = item.height + item.top;
- }
- }
- for(var key in this.$areaData) {
- var item = this.$areaData[key];
- if(maxW < item.width + item.left) {
- maxW = item.width + item.left;
- }
- if(maxH < item.height + item.top) {
- maxH = item.height + item.top;
- }
- }
- for(var key in this.$lineData) {
- var item = this.$lineData[key];
- if(item.M && item.type == "lt" && maxW < item.M) {
- maxW = M + 4;
- }
- if(item.M && item.type == "tb" && maxH < item.M) {
- maxH = M + 4;
- }
- }
- while(maxW > width) {
- width += this.$workExtendStep;
- }
- while(maxH > height) {
- height += this.$workExtendStep;
- }
- this.$workArea.css({
- height: height + "px",
- width: width + "px"
- });
- if(GooFlow.prototype.useSVG == "") {
- this.$draw.coordsize = width + "," + height;
- }
- this.$draw.style.width = width + "px";
- this.$draw.style.height = +height + "px";
- if(this.$group != null) {
- this.$group.css({
- height: height + "px",
- width: width + "px"
- });
- }
- },
- /**
- * 用 AJAX 方式,远程读取一组数据
- * 参数 para 为 JSON 结构,与 JQUERY 中 $.ajax() 方法的传参一样
- * @param {Object} para JSON 结构的参数
- */
- loadDataAjax: function(para) {
- var This = this;
- $.ajax({
- type: para.type,
- url: para.url,
- dataType: "json",
- data: para.data,
- success: function(msg) {
- if(para.dataFilter) para.dataFilter(msg, "json");
- This.loadData(msg);
- if(para.success) para.success(msg);
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- if(para.error) para.error(textStatus, errorThrown);
- }
- })
- },
- /**
- * 导出 json 结构的数据
- * 把画好的整个流程图导出到一个变量中(其实也可以直接访问GooFlow对象的$nodeData,$lineData,$areaData这三个JSON属性)
- */
- exportData: function() {
- var ret = {
- name: this.$name,
- key: this.$key,
- nodes: this.$nodeData,
- lines: this.$lineData,
- areas: this.$areaData,
- initNum: this.$max
- };
- for(var k1 in ret.nodes) {
- if(!ret.nodes[k1].marked) {
- delete ret.nodes[k1]["marked"];
- }
- }
- for(var k2 in ret.lines) {
- if(!ret.lines[k2].marked) {
- delete ret.lines[k2]["marked"];
- }
- }
- return ret;
- },
- /**
- * 只把本次编辑流程图中作了变更(包括增删改)的元素导出到一个变量中,以方便用户每次编辑载入的流程图后只获取变更过的数据
- */
- exportAlter: function() {
- var ret = {
- nodes: {},
- lines: {},
- areas: {}
- };
- for(var k1 in this.$nodeData) {
- if(this.$nodeData[k1].alt) {
- ret.nodes[k1] = this.$nodeData[k1];
- }
- }
- for(var k2 in this.$lineData) {
- if(this.$lineData[k2].alt) {
- ret.lines[k2] = this.$lineData[k2];
- }
- }
- for(var k3 in this.$areaData) {
- if(this.$areaData[k3].alt) {
- ret.areas[k3] = this.$areaData[k3];
- }
- }
- ret.deletedItem = this.$deletedItem;
- return ret;
- },
- /**
- * 变更元素的ID,一般用于快速保存后,将后台返回新元素的ID更新到页面中;type为元素类型(节点,连线,区块)
- * @param {Object} oldId 旧 id
- * @param {Object} newId 新 id
- * @param {Object} type 类型(节点 node ,连线 line ,区块 area)
- */
- transNewId: function(oldId, newId, type) {
- var tmp;
- switch(type) {
- case "node":
- if(this.$nodeData[oldId]) {
- tmp = this.$nodeData[oldId];
- delete this.$nodeData[oldId];
- this.$nodeData[newId] = tmp;
- tmp = this.$nodeDom[oldId].attr("id", newId);
- delete this.$nodeDom[oldId];
- this.$nodeDom[newId] = tmp;
- }
- break;
- case "line":
- if(this.$lineData[oldId]) {
- tmp = this.$lineData[oldId];
- delete this.$lineData[oldId];
- this.$lineData[newId] = tmp;
- tmp = this.$lineDom[oldId].attr("id", newId);
- delete this.$lineDom[oldId];
- this.$lineDom[newId] = tmp;
- }
- break;
- case "area":
- if(this.$areaData[oldId]) {
- tmp = this.$areaData[oldId];
- delete this.$areaData[oldId];
- this.$areaData[newId] = tmp;
- tmp = this.$areaDom[oldId].attr("id", newId);
- delete this.$areaDom[oldId];
- this.$areaDom[newId] = tmp;
- }
- break;
- }
- },
- /**
- * 清空工作区及已载入的数据
- */
- clearData: function() {
- for(var key in this.$nodeData) {
- this.delNode(key);
- }
- for(var key in this.$lineData) {
- this.delLine(key);
- }
- for(var key in this.$areaData) {
- this.delArea(key);
- }
- this.$deletedItem = {};
- },
- /**
- * 销毁自己(当前画布)
- */
- destrory: function() {
- this.$bgDiv.empty();
- this.$lineData = null;
- this.$nodeData = null;
- this.$lineDom = null;
- this.$nodeDom = null;
- this.$areaDom = null;
- this.$areaData = null;
- this.$nodeCount = 0;
- this.$areaCount = 0;
- this.$areaCount = 0;
- this.$deletedItem = {};
- },
- ///////////以下为有关画线的方法
- /**
- * 绘制一条箭头线,并返回线的DOM(直线)
- * @param {Object} id
- * @param {Object} sp 开始端的参数,为数组格式,数组中有 X 轴与 Y 轴的坐标点,第一个是 X 轴,第二个是 Y 轴
- * @param {Object} ep 结束端端参数,为数组格式,数组中有 X 轴与 Y 轴的坐标点,第一个是 X 轴,第二个是 Y 轴
- * @param {Object} mark 线的标识
- * @param {Object} dash
- * @param {Object} name
- */
- drawLine: function(id, sp, ep, mark, dash, name, auditState) {
- var line;
- if(GooFlow.prototype.useSVG != "") {
- line = document.createElementNS("http://www.w3.org/2000/svg", "g");
- var hi = document.createElementNS("http://www.w3.org/2000/svg", "path");
- var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
- if(id != "") line.setAttribute("id", id);
- line.setAttribute("from", sp[0] + "," + sp[1]);
- line.setAttribute("to", ep[0] + "," + ep[1]);
- hi.setAttribute("visibility", "hidden");
- hi.setAttribute("stroke-width", 9);
- hi.setAttribute("fill", "none");
- hi.setAttribute("stroke", "white");
- hi.setAttribute("d", "M " + sp[0] + " " + sp[1] + " L " + ep[0] + " " + ep[1]);
- hi.setAttribute("pointer-events", "stroke");
- path.setAttribute("d", "M " + sp[0] + " " + sp[1] + " L " + ep[0] + " " + ep[1]);
- path.setAttribute("stroke-width", mark ? 2.4 : 2);
- path.setAttribute("stroke-linecap", "round");
- path.setAttribute("fill", "none");
- if(dash) path.setAttribute("style", "stroke-dasharray:6,5");
- if(mark) {
- path.setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
- path.setAttribute("marker-end", "url(#arrow2)");
- } else {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
- path.setAttribute("marker-end", "url(#arrow1)");
- }
- if (auditState == '已审') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#65c239");
- path.setAttribute("marker-end", "url(#arrow4)");
- } else if (auditState == '审核中') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#409efe");
- path.setAttribute("marker-end", "url(#arrow5)");
- } else if (auditState == '未审') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#8f929a");
- path.setAttribute("marker-end", "url(#arrow6)");
- }
-
- line.appendChild(hi);
- line.appendChild(path);
- line.style.cursor = "crosshair";
- if(id != "" && id != "GooFlow_tmp_line") {
- var x = (ep[0] + sp[0]) / 2;
- var y = (ep[1] + sp[1]) / 2;
- if(name) {
- var rx;
- if(name.length == 1) {
- rx = 15
- } else {
- rx = 15 + (name.length - 1) * 6
- }
- var ellipse = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
- ellipse.setAttribute("class", "node");
- ellipse.setAttribute("rx", rx);
- ellipse.setAttribute("ry", 12);
- ellipse.setAttribute("cx", x);
- ellipse.setAttribute("cy", y - 4);
- ellipse.setAttribute("fill", "#75bccb");
-
- if (auditState == '已审') {
- ellipse.setAttribute("fill", "#65c239");
- } else if (auditState == '审核中') {
- ellipse.setAttribute("fill", "#409efe");
- } else if (auditState == '未审') {
- ellipse.setAttribute("fill", "#8f929a");
- }
-
- line.appendChild(ellipse);
- }
- var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
- text.setAttribute("fill", GooFlow.prototype.color.lineFont || "#fff");
- line.appendChild(text);
- text.setAttribute("text-anchor", "middle");
- text.setAttribute("x", x);
- text.setAttribute("y", y);
- line.style.cursor = "pointer";
- text.style.cursor = "text";
- }
- } else {
- line = document.createElement("v:polyline");
- if(id != "") line.id = id;
- //line.style.position="absolute";
- line.points.value = sp[0] + "," + sp[1] + " " + ep[0] + "," + ep[1];
- line.setAttribute("fromTo", sp[0] + "," + sp[1] + "," + ep[0] + "," + ep[1]);
- line.strokeWeight = "2";
- line.stroke.EndArrow = "Block";
- line.style.cursor = "crosshair";
- if(id != "" && id != "GooFlow_tmp_line") {
- var text = document.createElement("div");
- //text.innerHTML=id;
- line.appendChild(text);
- var x = (ep[0] - sp[0]) / 2;
- var y = (ep[1] - sp[1]) / 2;
- if(x < 0) x = x * -1;
- if(y < 0) y = y * -1;
- text.style.left = x + "px";
- text.style.top = y - 6 + "px";
- line.style.cursor = "pointer";
- }
- if(dash) line.stroke.dashstyle = "Dash";
- if(mark) line.strokeColor = GooFlow.prototype.color.mark || "#ff8800";
- else line.strokeColor = GooFlow.prototype.color.line || "#74bccb";
- line.fillColor = GooFlow.prototype.color.line || "#74bccb";
- }
- return line;
- },
- /**
- * 画一条只有两个中点的折线(折线)
- * @param {Object} id
- * @param {Object} sp
- * @param {Object} m1
- * @param {Object} m2
- * @param {Object} ep
- * @param {Object} mark
- * @param {Object} name
- * @param {Object} auditState
- */
- drawPoly: function(id, sp, m1, m2, ep, mark, name, auditState) {
- var poly, strPath;
- if(GooFlow.prototype.useSVG != "") {
- poly = document.createElementNS("http://www.w3.org/2000/svg", "g");
- var hi = document.createElementNS("http://www.w3.org/2000/svg", "path");
- var path = document.createElementNS("http://www.w3.org/2000/svg", "path");
- if(id != "") poly.setAttribute("id", id);
- poly.setAttribute("from", sp[0] + "," + sp[1]);
- poly.setAttribute("to", ep[0] + "," + ep[1]);
- hi.setAttribute("visibility", "hidden");
- hi.setAttribute("stroke-width", 9);
- hi.setAttribute("fill", "none");
- hi.setAttribute("stroke", "white");
- strPath = "M " + sp[0] + " " + sp[1];
- if(m1[0] != sp[0] || m1[1] != sp[1])
- strPath += " L " + m1[0] + " " + m1[1];
- if(m2[0] != ep[0] || m2[1] != ep[1])
- strPath += " L " + m2[0] + " " + m2[1];
- strPath += " L " + ep[0] + " " + ep[1];
- hi.setAttribute("d", strPath);
- hi.setAttribute("pointer-events", "stroke");
- path.setAttribute("d", strPath);
- path.setAttribute("stroke-width", mark ? 2.4 : 2);
- path.setAttribute("stroke-linecap", "round");
- path.setAttribute("fill", "none");
- if(mark) {
- path.setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
- path.setAttribute("marker-end", "url(#arrow2)");
- } else {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
- path.setAttribute("marker-end", "url(#arrow1)");
- }
-
- if (auditState == '已审') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#65c239");
- path.setAttribute("marker-end", "url(#arrow4)");
- } else if (auditState == '审核中') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#409efe");
- path.setAttribute("marker-end", "url(#arrow5)");
- } else if (auditState == '未审') {
- path.setAttribute("stroke", GooFlow.prototype.color.line || "#8f929a");
- path.setAttribute("marker-end", "url(#arrow6)");
- }
-
- poly.appendChild(hi);
- poly.appendChild(path);
- var x = (m2[0] + m1[0]) / 2;
- var y = (m2[1] + m1[1]) / 2;
- if(name) {
- var rx;
- if(name.length == 1) {
- rx = 15
- } else {
- rx = 15 + (name.length - 1) * 6
- }
- var ellipse = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
- ellipse.setAttribute("class", "node");
- ellipse.setAttribute("rx", rx);
- ellipse.setAttribute("ry", 12);
- ellipse.setAttribute("cx", x);
- ellipse.setAttribute("cy", y - 4);
- ellipse.setAttribute("fill", "#75bccb");
-
- if (auditState == '已审') {
- ellipse.setAttribute("fill", "#65c239");
- } else if (auditState == '审核中') {
- ellipse.setAttribute("fill", "#409efe");
- } else if (auditState == '未审') {
- ellipse.setAttribute("fill", "#8f929a");
- }
-
- poly.appendChild(ellipse);
- }
- var text = document.createElementNS("http://www.w3.org/2000/svg", "text");
- text.setAttribute("fill", GooFlow.prototype.color.lineFont || "#fff");
- poly.appendChild(text);
- text.setAttribute("text-anchor", "middle");
- text.setAttribute("x", x);
- text.setAttribute("y", y);
- text.style.cursor = "text";
- poly.style.cursor = "pointer";
- } else {
- poly = document.createElement("v:Polyline");
- if(id != "") poly.id = id;
- poly.filled = "false";
- strPath = sp[0] + "," + sp[1];
- if(m1[0] != sp[0] || m1[1] != sp[1])
- strPath += " " + m1[0] + "," + m1[1];
- if(m2[0] != ep[0] || m2[1] != ep[1])
- strPath += " " + m2[0] + "," + m2[1];
- strPath += " " + ep[0] + "," + ep[1];
- poly.points.value = strPath;
- poly.setAttribute("fromTo", sp[0] + "," + sp[1] + "," + ep[0] + "," + ep[1]);
- poly.strokeWeight = mark ? "2.4" : "2";
- poly.stroke.EndArrow = "Block";
- var text = document.createElement("div");
- //text.innerHTML=id;
- poly.appendChild(text);
- var x = (m2[0] - m1[0]) / 2;
- var y = (m2[1] - m1[1]) / 2;
- if(x < 0) x = x * -1;
- if(y < 0) y = y * -1;
- text.style.left = x + "px";
- text.style.top = y - 4 + "px";
- poly.style.cursor = "pointer";
- if(mark) poly.strokeColor = GooFlow.prototype.color.mark || "#ff8800";
- else poly.strokeColor = GooFlow.prototype.color.line || "#74bccb";
- }
- return poly;
- },
- //计算两个结点间要连直线的话,连线的开始坐标和结束坐标
- calcStartEnd: function(n1, n2) {
- var X_1, Y_1, X_2, Y_2;
- //X判断:
- var x11 = n1.left,
- x12 = n1.left + n1.width,
- x21 = n2.left,
- x22 = n2.left + n2.width;
- //结点2在结点1左边
- if(x11 >= x22) {
- X_1 = x11;
- X_2 = x22;
- }
- //结点2在结点1右边
- else if(x12 <= x21) {
- X_1 = x12;
- X_2 = x21;
- }
- //结点2在结点1水平部分重合
- else if(x11 <= x21 && x12 >= x21 && x12 <= x22) {
- X_1 = (x12 + x21) / 2;
- X_2 = X_1;
- } else if(x11 >= x21 && x12 <= x22) {
- X_1 = (x11 + x12) / 2;
- X_2 = X_1;
- } else if(x21 >= x11 && x22 <= x12) {
- X_1 = (x21 + x22) / 2;
- X_2 = X_1;
- } else if(x11 <= x22 && x12 >= x22) {
- X_1 = (x11 + x22) / 2;
- X_2 = X_1;
- }
- //Y判断:
- var y11 = n1.top,
- y12 = n1.top + n1.height,
- y21 = n2.top,
- y22 = n2.top + n2.height;
- //结点2在结点1上边
- if(y11 >= y22) {
- Y_1 = y11;
- Y_2 = y22;
- }
- //结点2在结点1下边
- else if(y12 <= y21) {
- Y_1 = y12;
- Y_2 = y21;
- }
- //结点2在结点1垂直部分重合
- else if(y11 <= y21 && y12 >= y21 && y12 <= y22) {
- Y_1 = (y12 + y21) / 2;
- Y_2 = Y_1;
- } else if(y11 >= y21 && y12 <= y22) {
- Y_1 = (y11 + y12) / 2;
- Y_2 = Y_1;
- } else if(y21 >= y11 && y22 <= y12) {
- Y_1 = (y21 + y22) / 2;
- Y_2 = Y_1;
- } else if(y11 <= y22 && y12 >= y22) {
- Y_1 = (y11 + y22) / 2;
- Y_2 = Y_1;
- }
- return {
- "start": [X_1, Y_1],
- "end": [X_2, Y_2]
- };
- },
- //计算两个结点间要连折线的话,连线的所有坐标
- calcPolyPoints: function(n1, n2, type, M) {
- //开始/结束两个结点的中心
- var SP = {
- x: n1.left + n1.width / 2,
- y: n1.top + n1.height / 2
- };
- var EP = {
- x: n2.left + n2.width / 2,
- y: n2.top + n2.height / 2
- };
- var sp = [],
- m1 = [],
- m2 = [],
- ep = [];
- //如果是允许中段可左右移动的折线,则参数M为可移动中段线的X坐标
- //粗略计算起始点
- sp = [SP.x, SP.y];
- ep = [EP.x, EP.y];
- if(type == "lr") {
- //粗略计算2个中点
- m1 = [M, SP.y];
- m2 = [M, EP.y];
- //再具体分析修改开始点和中点1
- if(m1[0] > n1.left && m1[0] < n1.left + n1.width) {
- m1[1] = (SP.y > EP.y ? n1.top : n1.top + n1.height);
- sp[0] = m1[0];
- sp[1] = m1[1];
- } else {
- sp[0] = (m1[0] < n1.left ? n1.left : n1.left + n1.width)
- }
- //再具体分析中点2和结束点
- if(m2[0] > n2.left && m2[0] < n2.left + n2.width) {
- m2[1] = (SP.y > EP.y ? n2.top + n2.height : n2.top);
- ep[0] = m2[0];
- ep[1] = m2[1];
- } else {
- ep[0] = (m2[0] < n2.left ? n2.left : n2.left + n2.width)
- }
- }
- //如果是允许中段可上下移动的折线,则参数M为可移动中段线的Y坐标
- else if(type == "tb") {
- //粗略计算2个中点
- m1 = [SP.x, M];
- m2 = [EP.x, M];
- //再具体分析修改开始点和中点1
- if(m1[1] > n1.top && m1[1] < n1.top + n1.height) {
- m1[0] = (SP.x > EP.x ? n1.left : n1.left + n1.width);
- sp[0] = m1[0];
- sp[1] = m1[1];
- } else {
- sp[1] = (m1[1] < n1.top ? n1.top : n1.top + n1.height)
- }
- //再具体分析中点2和结束点
- if(m2[1] > n2.top && m2[1] < n2.top + n2.height) {
- m2[0] = (SP.x > EP.x ? n2.left + n2.width : n2.left);
- ep[0] = m2[0];
- ep[1] = m2[1];
- } else {
- ep[1] = (m2[1] < n2.top ? n2.top : n2.top + n2.height);
- }
- }
- return {
- start: sp,
- m1: m1,
- m2: m2,
- end: ep
- };
- },
- //初始化折线中段的X/Y坐标,mType='rb'时为X坐标,mType='tb'时为Y坐标
- getMValue: function(n1, n2, mType) {
- if(mType == "lr") {
- return(n1.left + n1.width / 2 + n2.left + n2.width / 2) / 2;
- } else if(mType == "tb") {
- return(n1.top + n1.height / 2 + n2.top + n2.height / 2) / 2;
- }
- },
- //原lineData已经设定好的情况下,只在绘图工作区画一条线的页面元素
- addLineDom: function(id, lineData) {
- var n1 = this.$nodeData[lineData.from],
- n2 = this.$nodeData[lineData.to]; //获取开始/结束结点的数据
- // if(!n1 || !n2) return;
- //开始计算线端点坐标
- var res;
- if(lineData.type && lineData.type != "sl")
- res = GooFlow.prototype.calcPolyPoints(n1, n2, lineData.type, lineData.M);
- else
- res = GooFlow.prototype.calcStartEnd(n1, n2); //3
- if(!res) return;
- if(lineData.type == "sl")
- this.$lineDom[id] = GooFlow.prototype.drawLine(id, res.start, res.end, lineData.marked, false, lineData.name, lineData.audit_state);
- else
- this.$lineDom[id] = GooFlow.prototype.drawPoly(id, res.start, res.m1, res.m2, res.end, lineData.marked, lineData.name, lineData.audit_state);
- this.$draw.appendChild(this.$lineDom[id]);
- var nodes = this.$lineDom[id].childNodes;
- if(GooFlow.prototype.useSVG == "") {
- this.$lineDom[id].childNodes[1].innerHTML = lineData.name;
- if(lineData.type != "sl") {
- var Min = (res.start[0] > res.end[0] ? res.end[0] : res.start[0]);
- if(Min > res.m2[0]) Min = res.m2[0];
- if(Min > res.m1[0]) Min = res.m1[0];
- this.$lineDom[id].childNodes[1].style.left = (res.m2[0] + res.m1[0]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4;
- Min = (res.start[1] > res.end[1] ? res.end[1] : res.start[1]);
- if(Min > res.m2[1]) Min = res.m2[1];
- if(Min > res.m1[1]) Min = res.m1[1];
- this.$lineDom[id].childNodes[1].style.top = (res.m2[1] + res.m1[1]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetHeight / 2;
- } else
- this.$lineDom[id].childNodes[1].style.left =
- ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[id].childNodes[1].offsetWidth) / 2 + 4;
- } else this.$lineDom[id].childNodes[nodes.length - 1].textContent = lineData.name;
- },
- //增加一条线
- addLine: function(id, json) {
- if(this.onItemAdd != null && !this.onItemAdd(id, "line", json)) return;
- if(this.$undoStack && this.$editable) {
- this.pushOper("delLine", [id]);
- }
- if(json.from == json.to) return;
- var n1 = this.$nodeData[json.from],
- n2 = this.$nodeData[json.to]; //获取开始/结束结点的数据
- if(!n1 || !n2) return;
- //避免两个节点间不能有一条以上同向接连线
- for(var k in this.$lineData) {
- if((json.from == this.$lineData[k].from && json.to == this.$lineData[k].to))
- return;
- }
-
- // 添加连线规则,结束端不能是开始节点
- if (n2.type == "start") {
- return
- }
-
- //设置$lineData[id]
- this.$lineData[id] = {};
- if(json.type) {
- this.$lineData[id].type = json.type;
- this.$lineData[id].M = json.M;
- } else this.$lineData[id].type = "sl"; //默认为直线
- this.$lineData[id].from = json.from;
- this.$lineData[id].to = json.to;
- this.$lineData[id].name = json.name;
- this.$lineData[id].decision = json.decision;
- this.$lineData[id].coordX = json.coordX;
- this.$lineData[id].coordY = json.coordY;
- this.$lineData[id].audit_state = json.audit_state;// 这是流程图时使用的
- if(json.marked) this.$lineData[id].marked = json.marked;
- else this.$lineData[id].marked = false;
- //设置$lineData[id]完毕
- this.addLineDom(id, this.$lineData[id]);
- ++this.$lineCount;
- if(this.$editable) {
- this.$lineData[id].alt = true;
- if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
- }
- },
- //重构所有连向某个结点的线的显示,传参结构为$nodeData数组的一个单元结构
- resetLines: function(id, node) {
- for(var i in this.$lineData) {
- var other = null; //获取结束/开始结点的数据
- var res;
- if(this.$lineData[i].from == id) { //找结束点
- other = this.$nodeData[this.$lineData[i].to] || null;
- // if(other == null) continue;
- var flag = false
- if(other == null) {
- other = node;
- flag = true
- }
- if(this.$lineData[i].type == "sl")
- res = GooFlow.prototype.calcStartEnd(node, other);
- else
- res = GooFlow.prototype.calcPolyPoints(node, other, this.$lineData[i].type, this.$lineData[i].M)
- if(!res) break;
- if(flag) {
- // 没有结束的连线,所以要指定坐标点
- res.end[0] = res.end[0] + this.$lineData[i].coordX
- res.end[1] = res.end[1] + this.$lineData[i].coordY
- }
- } else if(this.$lineData[i].to == id) { //找开始点
- other = this.$nodeData[this.$lineData[i].from] || null;
- if(other == null) continue;
- if(this.$lineData[i].type == "sl")
- res = GooFlow.prototype.calcStartEnd(other, node);
- else
- res = GooFlow.prototype.calcPolyPoints(other, node, this.$lineData[i].type, this.$lineData[i].M);
- if(!res) break;
- }
- if(other == null) continue;
- this.$draw.removeChild(this.$lineDom[i]);
- if(this.$lineData[i].type == "sl") {
- this.$lineDom[i] = GooFlow.prototype.drawLine(i, res.start, res.end, this.$lineData[i].marked, false, this.$lineData[i].name);
- } else {
- this.$lineDom[i] = GooFlow.prototype.drawPoly(i, res.start, res.m1, res.m2, res.end, this.$lineData[i].marked, this.$lineData[i].name);
- }
- this.$draw.appendChild(this.$lineDom[i]);
- var nodes = this.$lineDom[i].childNodes
- if(GooFlow.prototype.useSVG == "") {
- this.$lineDom[i].childNodes[1].innerHTML = this.$lineData[i].name;
- if(this.$lineData[i].type != "sl") {
- var Min = (res.start[0] > res.end[0] ? res.end[0] : res.start[0]);
- if(Min > res.m2[0]) Min = res.m2[0];
- if(Min > res.m1[0]) Min = res.m1[0];
- this.$lineDom[i].childNodes[1].style.left = (res.m2[0] + res.m1[0]) / 2 - Min - this.$lineDom[i].childNodes[1].offsetWidth / 2 + 4;
- Min = (res.start[1] > res.end[1] ? res.end[1] : res.start[1]);
- if(Min > res.m2[1]) Min = res.m2[1];
- if(Min > res.m1[1]) Min = res.m1[1];
- this.$lineDom[i].childNodes[1].style.top = (res.m2[1] + res.m1[1]) / 2 - Min - this.$lineDom[i].childNodes[1].offsetHeight / 2 - 4;
- } else
- this.$lineDom[i].childNodes[1].style.left =
- ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[i].childNodes[1].offsetWidth) / 2 + 4;
- } else this.$lineDom[i].childNodes[nodes.length - 1].textContent = this.$lineData[i].name;
- }
- },
- //重新设置连线的样式 newType= "sl":直线, "lr":中段可左右移动型折线, "tb":中段可上下移动型折线
- setLineType: function(id, newType, M) {
- if(!newType || newType == null || newType == "" || newType == this.$lineData[id].type) return false;
- if(this.onLineSetType != null && !this.onLineSetType(id, newType)) return;
- if(this.$undoStack) {
- var paras = [id, this.$lineData[id].type, this.$lineData[id].M];
- this.pushOper("setLineType", paras);
- }
- var from = this.$lineData[id].from;
- var to = this.$lineData[id].to;
- this.$lineData[id].type = newType;
- var res;
- //如果是变成折线
- if(newType != "sl") {
- var res = GooFlow.prototype.calcPolyPoints(this.$nodeData[from], this.$nodeData[to], this.$lineData[id].type, this.$lineData[id].M);
- if(M) {
- this.setLineM(id, M, true);
- } else {
- this.setLineM(id, this.getMValue(this.$nodeData[from], this.$nodeData[to], newType), true);
- }
- }
- //如果是变回直线
- else {
- delete this.$lineData[id].M;
- this.$lineMove.hide().removeData("type").removeData("tid");
- res = GooFlow.prototype.calcStartEnd(this.$nodeData[from], this.$nodeData[to]);
- if(!res) return;
- this.$draw.removeChild(this.$lineDom[id]);
- this.$lineDom[id] = GooFlow.prototype.drawLine(id, res.start, res.end, this.$lineData[id].marked, false, this.$lineData[id].name);
- this.$draw.appendChild(this.$lineDom[id]);
- var nodes = this.$lineDom[id].childNodes
- if(GooFlow.prototype.useSVG == "") {
- this.$lineDom[id].childNodes[1].innerHTML = this.$lineData[id].name;
- this.$lineDom[id].childNodes[1].style.left =
- ((res.end[0] - res.start[0]) * (res.end[0] > res.start[0] ? 1 : -1) - this.$lineDom[id].childNodes[1].offsetWidth) / 2 + 4;
- } else
- this.$lineDom[id].childNodes[nodes.length - 1].textContent = this.$lineData[id].name;
- }
- if(this.$focus == id) {
- this.focusItem(id);
- }
- if(this.$editable) {
- this.$lineData[id].alt = true;
- }
- },
- //设置折线中段的X坐标值(可左右移动时)或Y坐标值(可上下移动时)
- setLineM: function(id, M, noStack) {
- if(!this.$lineData[id] || M < 0 || !this.$lineData[id].type || this.$lineData[id].type == "sl") return false;
- if(this.onLineMove != null && !this.onLineMove(id, M)) return false;
- if(this.$undoStack && !noStack) {
- var paras = [id, this.$lineData[id].M];
- this.pushOper("setLineM", paras);
- }
- var from = this.$lineData[id].from;
- var to = this.$lineData[id].to;
- this.$lineData[id].M = M;
- var ps = GooFlow.prototype.calcPolyPoints(this.$nodeData[from], this.$nodeData[to], this.$lineData[id].type, this.$lineData[id].M);
- this.$draw.removeChild(this.$lineDom[id]);
- this.$lineDom[id] = GooFlow.prototype.drawPoly(id, ps.start, ps.m1, ps.m2, ps.end, this.$lineData[id].marked, this.$lineData[id].name);
- this.$draw.appendChild(this.$lineDom[id]);
- var nodes = this.$lineDom[id].childNodes
- if(GooFlow.prototype.useSVG == "") {
- this.$lineDom[id].childNodes[1].innerHTML = this.$lineData[id].name;
- var Min = (ps.start[0] > ps.end[0] ? ps.end[0] : ps.start[0]);
- if(Min > ps.m2[0]) Min = ps.m2[0];
- if(Min > ps.m1[0]) Min = ps.m1[0];
- this.$lineDom[id].childNodes[1].style.left = (ps.m2[0] + ps.m1[0]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetWidth / 2 + 4;
- Min = (ps.start[1] > ps.end[1] ? ps.end[1] : ps.start[1]);
- if(Min > ps.m2[1]) Min = ps.m2[1];
- if(Min > ps.m1[1]) Min = ps.m1[1];
- this.$lineDom[id].childNodes[1].style.top = (ps.m2[1] + ps.m1[1]) / 2 - Min - this.$lineDom[id].childNodes[1].offsetHeight / 2 - 4;
- } else this.$lineDom[id].childNodes[nodes.length - 1].textContent = this.$lineData[id].name;
- if(this.$editable) {
- this.$lineData[id].alt = true;
- }
- },
- //删除转换线
- delLine: function(id, trigger) {
- if(!this.$lineData[id]) return;
- if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
- if(this.$undoStack) {
- var paras = [id, this.$lineData[id]];
- this.pushOper("addLine", paras);
- }
- this.$draw.removeChild(this.$lineDom[id]);
- delete this.$lineData[id];
- delete this.$lineDom[id];
- if(this.$focus == id) this.$focus = "";
- --this.$lineCount;
- if(this.$editable) {
- //在回退新增操作时,如果节点ID以this.$id+"_line_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
- if(id.indexOf(this.$id + "_line_") < 0)
- this.$deletedItem[id] = "line";
- this.$mpFrom.hide().removeData("p");
- this.$mpTo.hide().removeData("p");
- }
- if(this.$lineOper) {
- this.$lineOper.hide().removeData("tid");
- }
- },
- //变更连线两个端点所连的结点
- //参数:要变更端点的连线ID,新的开始结点ID、新的结束结点ID;如果开始/结束结点ID是传入null或者"",则表示原端点不变
- moveLinePoints: function(lineId, newStart, newEnd, noStack) {
- if(newStart == newEnd) return;
- if(!lineId || !this.$lineData[lineId]) return;
- if(newStart == null || newStart == "")
- newStart = this.$lineData[lineId].from;
- if(newEnd == null || newEnd == "")
- newEnd = this.$lineData[lineId].to;
- //避免两个节点间不能有一条以上同向接连线
- for(var k in this.$lineData) {
- if((newStart == this.$lineData[k].from && newEnd == this.$lineData[k].to))
- return;
- }
- if(this.onLinePointMove != null && !this.onLinePointMove(id, newStart, newEnd)) return;
- if(this.$undoStack && !noStack) {
- var paras = [lineId, this.$lineData[lineId].from, this.$lineData[lineId].to];
- this.pushOper("moveLinePoints", paras);
- }
- if(newStart != null && newStart != "") {
- this.$lineData[lineId].from = newStart;
- }
- if(newEnd != null && newEnd != "") {
- this.$lineData[lineId].to = newEnd;
- }
- //重建转换线
- this.$draw.removeChild(this.$lineDom[lineId]);
- this.addLineDom(lineId, this.$lineData[lineId]);
- if(this.$editable) {
- this.$lineData[lineId].alt = true;
- }
- },
- //用颜色标注/取消标注一个结点或转换线,常用于显示重点或流程的进度。
- //这是一个在编辑模式中无用,但是在纯浏览模式中非常有用的方法,实际运用中可用于跟踪流程的进度。
- markItem: function(id, type, mark) {
- if(type == "node") {
- if(!this.$nodeData[id]) return;
- if(this.onItemMark != null && !this.onItemMark(id, "node", mark)) return;
- this.$nodeData[id].marked = mark || false;
- if(mark) {
- this.$nodeDom[id].addClass("item_mark").css("border-color", GooFlow.prototype.color.mark);
- } else {
- this.$nodeDom[id].removeClass("item_mark");
- if(id != this.$focus) this.$nodeDom[id].css("border-color", "transparent");
- }
- } else if(type == "line") {
- if(!this.$lineData[id]) return;
- if(this.onItemMark != null && !this.onItemMark(id, "line", mark)) return;
- this.$lineData[id].marked = mark || false;
- if(GooFlow.prototype.useSVG != "") {
- if(mark) {
- this.$lineDom[id].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.mark || "#ff8800");
- this.$lineDom[id].childNodes[1].setAttribute("marker-end", "url(#arrow2)");
- this.$lineDom[id].childNodes[1].setAttribute("stroke-width", 2.4);
- } else {
- this.$lineDom[id].childNodes[1].setAttribute("stroke", GooFlow.prototype.color.line || "#74bccb");
- this.$lineDom[id].childNodes[1].setAttribute("marker-end", "url(#arrow1)");
- this.$lineDom[id].childNodes[1].setAttribute("stroke-width", 2);
- }
- } else {
- if(mark) {
- this.$lineDom[id].strokeColor = GooFlow.prototype.color.mark || "#ff8800";
- this.$lineDom[id].strokeWeight = "2.4";
- } else {
- this.$lineDom[id].strokeColor = GooFlow.prototype.color.line || "#74bccb";
- this.$lineDom[id].strokeWeight = "2";
- }
- }
- }
- if(this.$undoStatck) {
- var paras = [id, type, !mark];
- this.pushOper("markItem", paras);
- }
- },
- ////////////////////////以下为区域分组块操作
- moveArea: function(id, left, top) {
- if(!this.$areaData[id]) return;
- if(this.onItemMove != null && !this.onItemMove(id, "area", left, top)) return;
- if(this.$undoStack) {
- var paras = [id, this.$areaData[id].left, this.$areaData[id].top];
- this.pushOper("moveNode", paras);
- }
- if(left < 0) left = 0;
- if(top < 0) top = 0;
- $("#" + id).css({
- left: left + "px",
- top: top + "px"
- });
- this.$areaData[id].left = left;
- this.$areaData[id].top = top;
- if(this.$editable) {
- this.$areaData[id].alt = true;
- }
- },
- //删除区域分组
- delArea: function(id, trigger) {
- if(!this.$areaData[id]) return;
- if(this.$undoStack) {
- var paras = [id, this.$areaData[id]];
- this.pushOper("addArea", paras);
- }
- if(false != trigger && this.onItemDel != null && !this.onItemDel(id, "node")) return;
- delete this.$areaData[id];
- this.$areaDom[id].remove();
- delete this.$areaDom[id];
- --this.$areaCount;
- if(this.$editable) {
- //在回退新增操作时,如果节点ID以this.$id+"_area_"开头,则表示为本次编辑时新加入的节点,这些节点的删除不用加入到$deletedItem中
- if(id.indexOf(this.$id + "_area_") < 0)
- this.$deletedItem[id] = "area";
- }
- },
- //设置区域分组的颜色
- setAreaColor: function(id, color) {
- if(!this.$areaData[id]) return;
- if(this.$undoStack) {
- var paras = [id, this.$areaData[id].color];
- this.pushOper("setAreaColor", paras);
- }
- if(color == "red" || color == "yellow" || color == "blue" || color == "green") {
- this.$areaDom[id].removeClass("area_" + this.$areaData[id].color).addClass("area_" + color);
- this.$areaData[id].color = color;
- }
- if(this.$editable) {
- this.$areaData[id].alt = true;
- }
- },
- //设置区域分块的尺寸
- resizeArea: function(id, width, height) {
- if(!this.$areaData[id]) return;
- if(this.onItemResize != null && !this.onItemResize(id, "area", width, height)) return;
- if(this.$undoStack) {
- var paras = [id, this.$areaData[id].width, this.$areaData[id].height];
- this.pushOper("resizeArea", paras);
- }
- this.$areaDom[id].children(".bg").css({
- width: width + "px",
- height: height + "px"
- });
- //width=this.$areaDom[id].outerWidth();
- //height=this.$areaDom[id].outerHeight();
- //this.$areaDom[id].children("bg").css({width:width+"px",height:height+"px"});
- this.$areaData[id].width = width;
- this.$areaData[id].height = height;
- if(this.$editable) {
- this.$areaData[id].alt = true;
- }
- },
- addArea: function(id, json) {
- if(this.onItemAdd != null && !this.onItemAdd(id, "area", json)) return;
- if(this.$undoStack && this.$editable) {
- this.pushOper("delArea", [id]);
- }
- 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>" +
- "<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>");
- this.$areaData[id] = json;
- this.$group.append(this.$areaDom[id]);
- if(this.$nowType != "group") this.$areaDom[id].children("div:eq(1)").css("display", "none");
- ++this.$areaCount;
- if(this.$editable) {
- this.$areaData[id].alt = true;
- if(this.$deletedItem[id]) delete this.$deletedItem[id]; //在回退删除操作时,去掉该元素的删除记录
- }
- },
- //重构整个流程图设计器的宽高
- reinitSize: function(width, height) {
- var w = (width || 800);
- var h = (height || 500);
- this.$bgDiv.css({
- height: h + "px",
- width: w + "px"
- });
- var headHeight = 0,
- hack = 8;
- if(this.$head != null) {
- headHeight = 26;
- hack = 5;
- }
- if(this.$tool != null) {
- this.$tool.css({
- height: h - headHeight - hack + "px"
- });
- w -= 31;
- }
- w -= 9;
- h = h - headHeight - (this.$head != null ? 5 : 8);
- this.$workArea.parent().css({
- height: h + "px",
- width: w + "px"
- });
- if(this.$workArea.width() > w) {
- w = this.$workArea.width();
- }
- if(this.$workArea.height() > h) {
- h = this.$workArea.height();
- }
- this.$workArea.css({
- height: h + "px",
- width: w + "px"
- });
- if(GooFlow.prototype.useSVG == "") {
- this.$draw.coordsize = w + "," + h;
- }
- this.$draw.style.width = w + "px";
- this.$draw.style.height = +h + "px";
- if(this.$group != null) {
- this.$group.css({
- height: h + "px",
- width: w + "px"
- });
- }
- }
- }
- GooFlow.prototype.color = {};
- //将此类的构造函数加入至JQUERY对象中
- jQuery.extend({
- createGooFlow: function(bgDiv, property, vue) {
- return new GooFlow(bgDiv, property, vue);
- }
- });
|