dtree.js 251 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947
  1. /**
  2. *@Name dtree 树形组件
  3. *@Author 智慧的小西瓜
  4. *@DOCS http://www.wisdomelon.com/DTreeHelper/
  5. *@License https://www.layui.com/
  6. *@LASTTIME 2019/10/24
  7. *@VERSION v2.5.6
  8. */
  9. layui.define(['jquery','layer','form'], function(exports) {
  10. var $ = layui.$,
  11. layer = layui.layer,
  12. form = layui.form;
  13. // 树的公共定义样式汇总
  14. var LI_NAV_CHILD = "dtree-nav-ul-sid", LI_NAV_ITEM = "dtree-nav-item",
  15. LI_DIV_ITEM = "dtree-nav-div", DTREEFONTSPECIAL="dtreefont-special", NONETITLE="dtree-none-text",
  16. LI_DIV_MENUBAR = "dtree-menubar",
  17. LI_DIV_TOOLBAR = "dtree-toolbar", TOOLBAR_TOOL = "dtree-toolbar-tool", TOOLBAR_TOOL_EM = "dtree-toolbar-fixed",
  18. LI_DIV_CHECKBAR = "dtree-nav-checkbox-div",
  19. LI_CLICK_CHECKBAR = "d-click-checkbar", //绑定点击复选框时需要用到
  20. LI_DIV_TEXT_CLASS = "t-click", UL_ROOT="dtree",
  21. LI_NAV_FIRST_LINE = "dtree-nav-first-line", LI_NAV_LINE = "dtree-nav-line", LI_NAV_LAST_LINE = "dtree-nav-last-line";
  22. // 树的公共指定
  23. var NAV_THIS = "dtree-nav-this", //当前节点
  24. NAV_SHOW = "dtree-nav-show", //显示子节点
  25. NAV_HIDE = "dtree-nav-hide", //隐藏节点
  26. NAV_DIS = "dtree-disabled", //禁用节点
  27. ICON_HIDE = "dtree-icon-hide", //隐藏图标
  28. $BODY = $("body"), //body选择器
  29. $WIN = $(window), //window窗口
  30. $DOC = $(document), //当前文档
  31. MOD_NAME = "dtree", //模块名称
  32. VERSION = "v2.5.6", //版本
  33. OPTIONS = {}, //全局属性配置
  34. DTrees = {}; //当前被实例化的树的集合
  35. // 树的自定义图标
  36. var DTREEFONT = "dtreefont", //默认使用图标字体
  37. LI_DIV_CHECKBAR_ON = "dtree-icon-fuxuankuangxuanzhong", //复选框选中图标
  38. LI_DIV_CHECKBAR_OUT = "dtree-icon-fuxuankuang", //复选框未选中图标
  39. LI_DIV_CHECKBAR_NOALL = "dtree-icon-fuxuankuang-banxuan", //复选框半选图标
  40. LI_DIV_MENUBAR_DOWN = "dtree-icon-move-down", //menubar的展开全部的图标
  41. LI_DIV_MENUBAR_UP = "dtree-icon-move-up", //menubar的收缩全部的图标
  42. LI_DIV_MENUBAR_REFRESH = "dtree-icon-refresh", //menubar的刷新图标
  43. LI_DIV_MENUBAR_CHECKALL = "dtree-icon-roundcheckfill", //menubar的全选图标
  44. LI_DIV_MENUBAR_UNCHECKALL = "dtree-icon-roundclosefill", //menubar的全不选图标
  45. LI_DIV_MENUBAR_INVERTALL = "dtree-icon-roundcheck", //menubar的反选图标
  46. LI_DIV_MENUBAR_DELETE = "dtree-icon-delete1", //menubar的删除图标
  47. LI_DIV_MENUBAR_SEARCH = "dtree-icon-search_list_light", //menubar的搜索图标
  48. LI_DIV_TOOLBAR_PULLDOWN = "dtree-icon-pulldown", //toolbar的展开图标
  49. LI_DIV_TOOLBAR_PULLUP = "dtree-icon-pullup", //toolbar的收缩图标
  50. LI_DIV_TOOLBAR_ADD = "dtree-icon-roundadd", //toolbar的新增图标
  51. LI_DIV_TOOLBAR_EDIT = "dtree-icon-bianji", //toolbar的编辑图标
  52. LI_DIV_TOOLBAR_DEL = "dtree-icon-roundclose"; //toolbar的删除图标
  53. // 树的非叶子节点图标集合
  54. var nodeIconArray = {
  55. "-1": {"open": "dtree-icon-null-open", "close": "dtree-icon-null-close"}, //未指定
  56. "0" : {"open": "dtree-icon-wenjianjiazhankai", "close": "dtree-icon-weibiaoti5"}, //文件夹(二级图标默认样式)
  57. "1" : {"open": "dtree-icon-jian", "close": "dtree-icon-jia"}, //+-图标(一级图标默认样式)
  58. "2" : {"open": "dtree-icon-xiangxia1", "close": "dtree-icon-xiangyou"} //箭头图标
  59. };
  60. // 树的叶子节点图标集合
  61. var leafIconArray = {
  62. "-1": "dtree-icon-null", //未指定
  63. "0" : "dtree-icon-weibiaoti5", //文件夹
  64. "1" : "dtree-icon-yonghu", //人员
  65. "2" : "dtree-icon-fenzhijigou", //机构
  66. "3" : "dtree-icon-fenguangbaobiao", //报表
  67. "4" : "dtree-icon-xinxipilu", //信息
  68. "5" : "dtree-icon-shuye1", //叶子(二级图标默认样式)
  69. "6" : "dtree-icon-caidan_xunzhang", //勋章
  70. "7" : "dtree-icon-normal-file", //文件
  71. "8" : "dtree-icon-dian", //小圆点(一级图标默认样式)
  72. "9" : "dtree-icon-set-sm", //齿轮
  73. "10" : "dtree-icon-rate" //星星
  74. };
  75. // 树的自定义样式
  76. var DTREE = "dtree-", //自定义样式前缀
  77. ITEMTHIS = "-item-this", //自定义样式当前行选中后缀
  78. ITEM = "-item", //自定义样式当前行后缀
  79. DFONT = "-dtreefont", //自定义样式图标样式后缀
  80. FICON = "-ficon", //自定义样式一级图标样式后缀
  81. ICON = "-icon", //自定义样式二级图标样式后缀
  82. CBOX = "-checkbox", //自定义样式复选框样式后缀
  83. CHS = "-choose"; //自定义样式复选框选中样式后缀
  84. // 树自定义操作事件名称集合 绑定dtree-click的事件
  85. var eventName = {
  86. checkNodeClick: "checkNodeClick", //点击复选框
  87. itemNodeClick: "itemNodeClick" //点击子节点div
  88. };
  89. // 树默认toolbar提供的功能集合 绑定dtree-tool的事件
  90. var defaultTool = {
  91. pulldown: "pulldown", //点击展开当前节点下的全部节点
  92. pullup: "pullup", //点击收缩当前节点下的全部节点
  93. addTool: "addToolbar", //点击toolbar新增
  94. editTool: "editToolbar", //点击toolbar编辑
  95. delTool: "delToolbar" //点击toolbar删除
  96. };
  97. // 树默认menubar提供的功能集合 绑定dtree-menu的事件
  98. var defaultMenu = {
  99. moveDown: "moveDown", //menubar展开全部节点
  100. moveUp: "moveUp", //menubar收缩全部节点
  101. refresh: "refresh", //menubar刷新树
  102. checkAll: "checkAll", //menubar全选
  103. unCheckAll: "unCheckAll", //menubar全不选
  104. invertAll: "invertAll", //menubar反选
  105. remove: "remove", //menubar删除选中节点
  106. searchNode: "searchNode" //menubar查询节点
  107. };
  108. // 树的公共事件
  109. var event = {
  110. getElemId: function(options){ // 根据传入的参数获取ID
  111. var elem = options.elem || "";
  112. var obj = options.obj || $(elem);
  113. if (obj.length == 0) { //页面中未找到绑定id
  114. return "";
  115. } else {
  116. return $(obj)[0].id;
  117. }
  118. },
  119. escape: function(html){
  120. if(typeof html !== 'string') return '';
  121. return html.replace(entityReg.escape, function(match){return entityMap.escape[match];});
  122. },
  123. unescape: function(str){
  124. if(typeof str !== 'string') return '';
  125. return str.replace(entityReg.unescape, function(match){return entityMap.unescape[match];});
  126. },
  127. cloneObj: function (obj, filter) { //深复制对象方法
  128. var newObj = {};
  129. if (obj instanceof Array) {
  130. newObj = [];
  131. }
  132. var str = "";
  133. if(typeof filter !== 'undefined') {str = filter.join(",");}
  134. for (var key in obj) {
  135. if(str.indexOf(key) == -1){
  136. var val = obj[key];
  137. newObj[key] = typeof val === 'object' ? event.cloneObj(val, typeof filter !== undefined ? filter : []): val;
  138. }
  139. }
  140. return newObj;
  141. },
  142. trimToDot: function(str){
  143. return str.replace(/ /g, ".");
  144. }
  145. };
  146. // 特殊符号转义
  147. var keys = Object.keys || function(obj) {
  148. obj = Object(obj);
  149. var arr = [];
  150. for(var a in obj) arr.push(a);
  151. return arr;
  152. };
  153. var invert = function(obj){
  154. obj = Object(obj);
  155. var result = {};
  156. for(var a in obj) result[obj[a]] = a;
  157. return result;
  158. };
  159. var entityMap = {
  160. escape: {
  161. "&" : "&",
  162. "<" : "&lt;",
  163. ">" : "&gt;",
  164. "'" : "&quo;"
  165. }
  166. };
  167. entityMap.unescape = invert(entityMap.escape);
  168. var entityReg = {
  169. escape: RegExp('[' + keys(entityMap.escape).join('') + ']', 'g'),
  170. unescape: RegExp('(' + keys(entityMap.unescape).join('|') + ')', 'g')
  171. };
  172. //异步加载接口
  173. var AjaxHelper = {
  174. request : function(config) {
  175. var data = config.data ? config.data : {};
  176. var async = (typeof (config.async) === "boolean") ? config.async : true;
  177. $.ajax({
  178. type : config.type ? config.type : "POST",
  179. headers : config.headers,
  180. url : config.url,
  181. dataType : config.dataType ? config.dataType : "json",
  182. data : data,
  183. async : async,
  184. contentType : config.contentType,
  185. xhrFields: {withCredentials: config.withCredentials},
  186. success : config.success,
  187. error : function(XMLHttpRequest, textStatus, errorThrown) {
  188. if (typeof (config.error) === "function") {
  189. config.error(XMLHttpRequest, textStatus, errorThrown);
  190. } else {
  191. layer.msg("异步加载失败: " + textStatus,{icon:5, shift:6});
  192. }
  193. },
  194. statusCode : {
  195. 404 : function() {
  196. layer.msg('未找到指定请求,请检查访问路径!',{icon:5, shift:6});
  197. },
  198. 500 : function() {
  199. layer.msg('系统错误!',{icon:5, shift:6});
  200. }
  201. },
  202. complete : function(XMLHttpRequest, textStatus) {
  203. if (typeof (config.complete) === "function") {
  204. config.complete(XMLHttpRequest, textStatus);
  205. }
  206. }
  207. });
  208. },
  209. serialize: function(param){ //json序列化 key=value&key1=value1
  210. var p = "?";
  211. for (var key in param) {
  212. p += key + "=" + param[key] + "&";
  213. }
  214. p = p.substring(0, p.length-1);
  215. return p;
  216. }
  217. };
  218. // 树类
  219. var DTree = function(options){
  220. var _this = this;
  221. /** 默认赋值**/
  222. this.formatter = { // 数据过滤
  223. title: false // 文字,默认不开启
  224. };
  225. this.response = { // 树返回的json格式
  226. statusName: "code", //返回标识
  227. statusCode: 200, //返回码
  228. message: "message", //返回信息
  229. rootName: "data", //根节点名称
  230. treeId: "id", //节点ID
  231. parentId: "parentId", //父节点ID
  232. title: "title", //节点名称
  233. ficonClass: "ficonClass", //自定义一级图标
  234. iconClass: "iconClass", //自定义二级图标
  235. childName: "children", //子节点名称
  236. last: "last", //是否最后一级节点
  237. // level: "level", //层级
  238. spread: "spread", //展开
  239. disabled: "disabled", //禁用
  240. hide: "hide", //隐藏
  241. checkArr: "checkArr", //复选框列表
  242. checked: "checked", //是否选中
  243. type: "type", //复选框标记
  244. basicData: "basicData" //表示用户自定义需要存储在树节点中的数据
  245. };
  246. this.defaultRequest = { // 树的默认发起请求参数格式,最后会将value作为参数名称传递
  247. nodeId: "nodeId", //节点ID
  248. parentId: "parentId", //父节点ID
  249. context: "context", //节点内容
  250. leaf: "leaf", //是否叶子节点
  251. level: "level", //层级
  252. spread: "spread", //节点展开状态
  253. dataType: "dataType", //节点标记
  254. checked: "checked", //节点复选框选中状态
  255. initchecked: "initchecked", //节点复选框初始状态
  256. basicData: "basicData", //用户自定义的记录节点数据
  257. recordData: "recordData", //当前data数据(排除basicData和children字段)
  258. };
  259. this.toolbarFun = {
  260. addTreeNode: function(param, $div) { //添加树节点后调用的函数,用于用户自定义,如未指定则树不会发生变化
  261. return ;
  262. },
  263. editTreeNode: function(param, $div) { //编辑树节点后调用的函数,用于用户自定义,如未指定则树不会发生变化
  264. return ;
  265. },
  266. editTreeLoad: function(param){ // 编辑树的数据回显,用于打开编辑时,回填数据
  267. return ;
  268. },
  269. delTreeNode: function(param, $div){ //删除树后调用的函数,用于用户自定义,如未指定则树不会发生变化
  270. return ;
  271. },
  272. loadToolbarBefore: function(buttons, param, $div){ // 右键菜单加载前的函数
  273. return buttons;
  274. }
  275. };
  276. this.toolbarStyle = {
  277. title: "节点",
  278. area: ["60%","80%"]
  279. };
  280. this.menubarFun = {
  281. remove: function(checkbarNodes){ //删除复选框选中节点,需要用户自定义,如未指定则树只是页面上做了修改
  282. return true;
  283. }
  284. };
  285. this.menubarTips = {
  286. toolbar: [],
  287. group: [defaultMenu.moveDown, defaultMenu.moveUp, defaultMenu.refresh, defaultMenu.checkAll, defaultMenu.unCheckAll, defaultMenu.invertAll, defaultMenu.remove, defaultMenu.searchNode],
  288. freedom: []
  289. };
  290. this.checkbarFun = {
  291. chooseBefore: function($i, node){ // 复选框点击前回调
  292. return true;
  293. },
  294. chooseDone: function(checkbarNodesParam) { //复选框点击事件完毕后,返回该树关于复选框操作的全部信息,用于用户自定义,如未指定则树只是页面上做了修改
  295. return ;
  296. }
  297. };
  298. this.iframeDefaultRequest = { //iframe的默认参数,目的是与加载树的参数不一样
  299. nodeId: "nodeId", //节点ID
  300. parentId: "parentId", //父节点ID
  301. context: "context", //节点内容
  302. leaf: "leaf", //是否叶子节点
  303. level: "level", //层级
  304. spread: "spread", //节点展开状态
  305. dataType: "dataType", //节点标记
  306. checked: "checked", //节点复选框选中状态
  307. initchecked: "initchecked", //节点复选框初始状态
  308. basicData: "basicData", //用户自定义的记录节点数据
  309. recordData: "recordData", //当前data数据(排除basicData和children字段)
  310. };
  311. this.iframeFun = {
  312. iframeDone: function(iframeParam){ //iframe加载完毕后,用于用户自定义事件
  313. return ;
  314. }
  315. };
  316. this.style = { //树最终使用的样式集合
  317. item: "", //每一项div的样式
  318. itemThis: "", //选中div的样式
  319. dfont: "", //一级图标的样式
  320. icon: "", //二级图标的样式
  321. cbox: "", //复选框的样式
  322. chs: "" //复选框选中的样式
  323. };
  324. this.usefontStyle = { //树最终使用的图标集合
  325. fnode:{ //一级节点
  326. node:{ //非叶子节点
  327. open:"", //节点展开
  328. close:"" //节点关闭
  329. },
  330. leaf:"" //叶子节点
  331. },
  332. snode:{ //二级节点
  333. node:{ //非叶子节点
  334. open:"", //节点展开
  335. close:"" //节点关闭
  336. },
  337. leaf:"" //叶子节点
  338. },
  339. checkbox:{ //复选框
  340. on:"", //复选框选中
  341. out:"", //未选中
  342. noall:"" //半选
  343. },
  344. menubar:{ //菜单栏
  345. movedown:"", //全部展开
  346. moveup:"", //全部收缩
  347. refresh:"", //刷新
  348. checkAll:"", //全选
  349. unCheckAll:"", //全不选
  350. invertAll:"", //反选
  351. remove:"", //删除
  352. search:"" //搜索
  353. },
  354. menubarExt:"", //扩展菜单栏
  355. toolbar:{ //工具栏
  356. menubar:{ //依附在菜单栏的工具栏
  357. movedown:"", //全部展开
  358. moveup:"", //全部收缩
  359. refresh:"", //刷新
  360. checkAll:"", //全选
  361. unCheckAll:"", //全不选
  362. invertAll:"", //反选
  363. remove:"", //删除
  364. search:"" //搜索
  365. },
  366. menubarExt:"", //依附在菜单栏的扩展菜单栏
  367. pulldown:"", //展开
  368. pullup:"", //收缩
  369. add:"", //添加
  370. edit:"", //编辑
  371. del:"" //删除
  372. },
  373. toolbarExt:"" //扩展工具栏
  374. }
  375. /** 数据绑定**/
  376. this.node = { // 树节点选中时,包含当前节点的全部信息
  377. nodeId: "", //节点ID
  378. parentId: "", //父节点ID
  379. context: "", //节点内容
  380. leaf: "", //是否叶子节点
  381. level: "", //层级
  382. spread: "", //节点展开状态
  383. dataType: "", //节点标记
  384. checked: "", //节点复选框选中状态
  385. initchecked: "", //节点复选框初始状态
  386. basicData: "", //用户自定义的记录节点数据
  387. recordData: "", //当前data数据(排除basicData和children字段)
  388. };
  389. this.toolbarMenu = {}; // 工具栏右键菜单绑定的所有元素
  390. this.checkbarNode = []; // 复选框标记的全部节点数据
  391. this.errData = []; // 记录在渲染节点时有问题的数据
  392. this.checkArrLen = 0; //添加节点的时判断复选框个数
  393. this.temp = []; // 临时变量
  394. this.bak = ""; // 临时变量
  395. this.setting(options);
  396. };
  397. /******************** 初始参数加载 ********************/
  398. // 设置基本参数值
  399. DTree.prototype.setting = function(options) {
  400. this.options = options || {};
  401. /** 绑定元素参数(必填,2个参数项必填一个)**/
  402. this.elem = this.options.elem || OPTIONS.elem || ""; //树绑定的元素ID:#elem
  403. if(typeof this.options.obj === 'undefined'){
  404. if(this.elem) {
  405. if($(this.elem).length > 0) {
  406. this.obj = $(this.elem);
  407. }
  408. }
  409. } else {
  410. this.obj = this.options.obj || OPTIONS.obj || this.obj; //树绑定的jquery元素,用于当元素是延迟加载出来的话,可以用这个找到
  411. this.elem = "#" + this.obj[0].id;
  412. }
  413. /** 基本参数**/
  414. this.scroll = this.options.scroll || OPTIONS.scroll || this.elem; //树的上级div容器,让树可以显示滚动条的div容器的ID
  415. this.accordion = (typeof (this.options.accordion) === "boolean") ? this.options.accordion : (typeof (OPTIONS.accordion) === "boolean") ? OPTIONS.accordion : false; //手风琴加载, 默认false
  416. if(this.accordion) {
  417. this.initLevel = 1; //默认展开节点 1节
  418. } else {
  419. this.initLevel = this.options.initLevel || OPTIONS.initLevel || 2; //默认展开节点 2节
  420. }
  421. this.type = this.options.type || OPTIONS.type || "load"; //树的加载方式 all,全量树, load,增量树,默认load
  422. this.cache = (typeof (this.options.cache) === "boolean") ? this.options.cache : (typeof (OPTIONS.cache) === "boolean") ? OPTIONS.cache : true; //数据缓存,默认true
  423. this.record = this.options.record || OPTIONS.record || false; //开启数据记录模式,默认false
  424. this.load = (typeof (this.options.load) === "boolean") ? this.options.load : (typeof (OPTIONS.load) === "boolean") ? OPTIONS.load : true; //开启加载动画,默认true
  425. this.none = this.options.none || OPTIONS.nont || "无数据"; //初始加载无记录时显示文字
  426. this.tempHeight = this.options.height || OPTIONS.height; //临时转换高度变量
  427. if(this.tempHeight) { // 设置高度
  428. if(/^full-\d+$/.test(this.tempHeight)) {
  429. this.fullHeightGap = this.tempHeight.split('-')[1];
  430. this.height = $WIN.height() - this.fullHeightGap; //设置高度
  431. } else {
  432. this.fullHeightGap = this.tempHeight;
  433. this.height = this.tempHeight;
  434. }
  435. } else {
  436. this.fullHeightGap = "";
  437. this.height = "";
  438. }
  439. this.width = this.options.width || OPTIONS.width || "260"; //宽度
  440. this.obj.css("width", this.width);
  441. /** 样式相关参数**/
  442. this.iconfont = this.options.iconfont || OPTIONS.iconfont || DTREEFONT; //默认图标字体 dtreefont
  443. this.iconfontStyle = this.options.iconfontStyle || OPTIONS.iconfontStyle || {}; //用于自定义树的每个关键部位使用的图标
  444. this.nodeIconArray = $.extend(nodeIconArray, this.options.nodeIconArray || OPTIONS.nodeIconArray) || nodeIconArray; //用户自定义非叶子节点图标集合,node
  445. this.leafIconArray = $.extend(leafIconArray, this.options.leafIconArray || OPTIONS.leafIconArray) || leafIconArray; //用户自定义叶子节点图标集合,leaf
  446. this.skin = this.options.skin || OPTIONS.skin || "theme"; // 自定义样式
  447. if(this.skin == "layui"){ // layui主题
  448. this.line = (typeof (this.options.line) === "boolean") ? this.options.line : (typeof (OPTIONS.line) === "boolean") ? OPTIONS.line : true; //开启树线,默认开启
  449. this.ficon = this.options.ficon || OPTIONS.ficon || "7"; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'7'
  450. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示一级图标,默认'1'
  451. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; //一级图标中的leaf节点图标
  452. this.icon = this.options.icon || OPTIONS.icon || "-1"; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'-1'
  453. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'-1'
  454. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  455. } else if(this.skin == "laySimple"){ // laySimple主题
  456. this.line = this.options.line || OPTIONS.line || false; //开启树线,默认不开启
  457. this.ficon = this.options.ficon || OPTIONS.ficon || ["2","-1"]; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'-1'
  458. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "2") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示一级图标,默认'2'
  459. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
  460. this.icon = this.options.icon || OPTIONS.icon || "-1"; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'-1'
  461. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'-1'
  462. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  463. } else { // 默认主题 或者自定义主题
  464. this.line = this.options.line || OPTIONS.line || false; //开启树线,默认不开启
  465. this.ficon = this.options.ficon || OPTIONS.ficon || "8"; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'8'
  466. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示一级图标,默认'1'
  467. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
  468. this.icon = this.options.icon || OPTIONS.icon || "5"; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'5'
  469. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "0") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'0'
  470. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  471. }
  472. /** 数据加载参数**/
  473. this.url = this.options.url || OPTIONS.url || ""; //请求地址
  474. this.async = (typeof (this.options.async) === "boolean") ? this.options.async : (typeof (OPTIONS.async) === "boolean") ? OPTIONS.async : true; //异步同步加载,默认异步加载
  475. this.headers = this.options.headers || OPTIONS.headers || {}; //ajax header属性
  476. this.method = this.options.method || OPTIONS.method || "post"; //请求类型
  477. this.dataType = this.options.dataType || OPTIONS.dataType || "json"; //参数类型
  478. this.contentType = this.options.contentType || OPTIONS.contentType || "application/x-www-form-urlencoded"; //发送信息至服务器时内容编码类型
  479. this.defaultRequest = $.extend(this.defaultRequest, this.options.defaultRequest || OPTIONS.defaultRequest) || this.defaultRequest; //默认请求参数
  480. this.filterRequest = this.options.filterRequest || OPTIONS.filterRequest || []; //过滤请求参数
  481. this.request = this.options.request || OPTIONS.request || {}; //用户自定义请求参数
  482. this.response = $.extend(this.response, this.options.response || OPTIONS.response) || this.response; //返回json格式
  483. this.data = this.options.data || OPTIONS.data || null; //初始化指定该参数,则不会访问异步接口
  484. this.dataFormat = this.options.dataFormat || OPTIONS.dataFormat || "levelRelationship"; //用于用户配置的data数据格式,list:列表, levelRelationship:层级关系,默认
  485. this.dataStyle = this.options.dataStyle || OPTIONS.dataStyle || "defaultStyle"; //用于用户配置layui通用的json数据风格,layuiStyle:layui风格,defaultStyle:默认风格
  486. this.errDataShow = this.options.errDataShow || OPTIONS.errDataShow || false; //是否在递归数据出现错误后,显示错误信息,默认false
  487. this.withCredentials = this.options.withCredentials || OPTIONS.withCredentials || false; //是否允许跨域请求,默认false
  488. this.success = this.options.success || OPTIONS.success || function(data, obj){}; //树加载完毕后执行解析树之前的回调
  489. this.done = this.options.done || OPTIONS.done || function(data, obj){}; //树加载完毕后的回调
  490. this.formatter = $.extend(this.formatter, this.options.formatter || OPTIONS.formatter) || this.formatter; //数据过滤
  491. this.error = this.options.error || OPTIONS.error || function(XMLHttpRequest, textStatus, errorThrown){}; // 异步加载异常回调
  492. this.complete = this.options.complete || OPTIONS.complete || function(XMLHttpRequest, textStatus){}; // 异步加载完成回调
  493. /** 复选框参数**/
  494. this.checkbar = this.options.checkbar || OPTIONS.checkbar || false; //是否开启复选框模式
  495. this.checkbarLoad = this.options.checkbarLoad || OPTIONS.checkbarLoad || "node"; //复选框作用范围,node:所有节点, leaf:最后一级;默认所有节点
  496. this.checkbarType = this.options.checkbarType || OPTIONS.checkbarType || "all"; //复选框选中形式 all:子集选中父级也选中, no-all:子集选中父级半选中,子集全选父级选中,p-casc:父级选中子集全选,子集无法改变父级选中状态, self:没有任何级联关系,only:只能选中一个复选框。 默认all
  497. this.checkbarData = this.options.checkbarData || OPTIONS.checkbarData || "choose"; //复选框记录数据类型形式, change表示记录变更数据,choose表示记录选中数据,all记录全部数据,halfChoose记录选中和半选中的数据,默认choose
  498. this.checkbarFun = $.extend(this.checkbarFun, this.options.checkbarFun || OPTIONS.checkbarFun) || this.checkbarFun; //checkbar事件加载
  499. /** 菜单栏参数**/
  500. this.menubar = this.options.menubar || OPTIONS.menubar || false; //是否打开菜单栏
  501. this.menubarTips = $.extend(this.menubarTips, this.options.menubarTips || OPTIONS.menubarTips) || this.menubarTips; //菜单栏吸附, toolbar:依附在工具栏,group:依附在按钮组,freedom,自由
  502. this.menubarFun = $.extend(this.menubarFun, this.options.menubarFun || OPTIONS.menubarFun) || this.menubarFun; //menubar事件加载
  503. /** 工具栏参数**/
  504. this.toolbar = this.options.toolbar || OPTIONS.toolbar || false; //是否开启可编辑模式
  505. this.toolbarWay = this.options.toolbarWay || OPTIONS.toolbarWay || "contextmenu"; //工具栏显示方式,contextmenu:右键,follow:跟随节点,fixed:固定在节点右侧
  506. this.toolbarStyle = $.extend(this.toolbarStyle, this.options.toolbarStyle || OPTIONS.toolbarStyle) || this.toolbarStyle; //toolbar的自定义风格,标题,弹框大小
  507. this.toolbarLoad = this.options.toolbarLoad || OPTIONS.toolbarLoad || "node"; //toolbar作用范围:node:所有节点,noleaf:非最后一级节点,leaf:最后一级
  508. this.toolbarShow = this.options.toolbarShow || OPTIONS.toolbarShow || ["add","edit","delete"]; //toolbar三个按钮自定义加载
  509. this.toolbarBtn = this.options.toolbarBtn || OPTIONS.toolbarBtn || null; //toolbar增删改中内容的自定义加载
  510. this.toolbarExt = this.options.toolbarExt || OPTIONS.toolbarExt || []; //toolbar按钮扩展
  511. this.toolbarFun = $.extend(this.toolbarFun, this.options.toolbarFun || OPTIONS.toolbarFun) || this.toolbarFun; //toolbar事件加载
  512. /** iframe模式参数**/
  513. this.useIframe = this.options.useIframe || OPTIONS.useIframe || false; //是否加载iframe 默认false,
  514. this.iframeElem = this.options.iframeElem || OPTIONS.iframeElem || ""; //iframe的ID
  515. this.iframeUrl = this.options.iframeUrl || OPTIONS.iframeUrl || ""; //树关联的iframe地址
  516. this.iframeLoad = this.options.iframeLoad || OPTIONS.iframeLoad || "leaf"; //点击哪一层加载frame: node:所有节点, leaf:默认,最后一级
  517. this.iframeDefaultRequest = $.extend(this.iframeDefaultRequest, this.options.iframeDefaultRequest || OPTIONS.iframeDefaultRequest) || this.iframeDefaultRequest; //iframe的默认传递参数
  518. this.iframeRequest = $.extend(this.iframeRequest, this.options.iframeRequest) || $.extend(this.iframeRequest, OPTIONS.iframeRequest) || this.iframeRequest; //iframe的自定义参数
  519. this.iframeFun = $.extend(this.iframeFun, this.options.iframeFun) || $.extend(this.iframeFun, OPTIONS.iframeFun) || this.iframeFun; //iframe事件加载
  520. /** 下拉树模式参数**/
  521. this.select = this.options.select || false;
  522. if(this.select) {
  523. // 重置下拉树
  524. this.selectSetting();
  525. }
  526. /** 调用确认最终主题方法*/
  527. this.ensureTheme();
  528. };
  529. // 设置基本参数值
  530. DTree.prototype.reloadSetting = function(options) {
  531. this.options = $.extend(this.options, options) || this.options;
  532. /** 绑定元素参数**/
  533. this.elem = this.options.elem || this.elem; //树绑定的元素ID:#elem
  534. if(typeof this.options.obj === 'undefined'){
  535. if(this.elem) {
  536. if($(this.elem).length > 0) {
  537. this.obj = $(this.elem);
  538. }
  539. }
  540. } else {
  541. this.obj = this.options.obj || this.obj; //树绑定的jquery元素,用于当元素是延迟加载出来的话,可以用这个找到
  542. this.elem = "#" + this.obj[0].id;
  543. }
  544. /** 基本参数**/
  545. this.scroll = this.options.scroll || this.scroll; //树的上级div容器,让树可以显示滚动条的div容器
  546. this.accordion = (typeof (this.options.accordion) === "boolean") ? this.options.accordion : this.accordion; //开启手风琴加载
  547. if(this.accordion) {
  548. this.initLevel = 1; //默认展开节点 1节
  549. } else {
  550. this.initLevel = this.options.initLevel || this.initLevel; //默认展开节点 2节
  551. }
  552. this.type = this.options.type || this.type; //树的加载方式 all,全量树, load,增量树,默认load
  553. this.cache = (typeof (this.options.cache) === "boolean") ? this.options.cache : this.cache; //开启数据缓存
  554. this.record = (typeof (this.options.record) === "boolean") ? this.options.record : this.record; //开启数据记录模式
  555. this.load = (typeof (this.options.load) === "boolean") ? this.options.load : this.load; //开启加载动画
  556. this.none = this.options.none || this.none; //初始节点加载无数据时显示文字
  557. this.tempHeight = this.options.height || this.height; //临时转换高度变量
  558. if(this.tempHeight) { //设置高度
  559. if(/^full-\d+$/.test(this.tempHeight)) {
  560. this.fullHeightGap = this.tempHeight.split('-')[1];
  561. this.height = $WIN.height() - this.fullHeightGap;
  562. } else {
  563. this.fullHeightGap = this.tempHeight;
  564. this.height = this.tempHeight;
  565. }
  566. }
  567. this.width = this.options.width || this.width; //宽度
  568. this.obj.css("width", this.width);
  569. /** 样式相关参数**/
  570. this.line = (typeof (this.options.line) === "boolean") ? this.options.line : this.line; //开启树线,默认不开启
  571. this.iconfont = this.options.iconfont || this.iconfont; //默认图标字体 dtreefont
  572. this.iconfontStyle = this.options.iconfontStyle || this.iconfontStyle; //用于自定义树的每个关键部位使用的图标
  573. this.nodeIconArray = $.extend(nodeIconArray, this.options.nodeIconArray) || this.nodeIconArray; //用户自定义非叶子节点图标集合,node
  574. this.leafIconArray = $.extend(leafIconArray, this.options.leafIconArray) || this.leafIconArray; //用户自定义叶子节点图标集合,leaf
  575. this.skin = this.options.skin || this.skin; //自定义样式
  576. if(this.skin == "layui"){ //layui主题
  577. this.line = (typeof (this.options.line) === "boolean") ? this.options.line : true; //开启树线,默认开启
  578. this.ficon = this.options.ficon || this.ficon; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'7'
  579. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'1'
  580. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; //一级图标中的leaf节点图标
  581. this.icon = this.options.icon || this.icon; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'-1'
  582. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'-1'
  583. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  584. } else if(this.skin == "laySimple"){ //laySimple主题
  585. this.line = (typeof (this.options.line) === "boolean") ? this.options.line : false; //开启树线,默认不开启
  586. this.ficon = this.options.ficon || this.ficon; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'-1'
  587. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "2") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'2'
  588. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1];//一级图标中的leaf节点图标
  589. this.icon = this.options.icon || this.icon; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'-1'
  590. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "-1") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'-1'
  591. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  592. } else { // 默认主题 或者自定义主题
  593. this.line = (typeof (this.options.line) === "boolean") ? this.options.line : false; //开启树线,默认不开启
  594. this.ficon = this.options.ficon || this.ficon; //一级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示一级图标。默认'8'
  595. this.fnodeIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? (this.ficon == "-1" ? "-1" : "1") : this.ficon[0]; //一级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'1'
  596. this.fleafIcon = (typeof this.ficon === 'string' || typeof this.ficon === 'number') ? this.ficon : this.ficon[1]; // 一级图标中的leaf节点图标
  597. this.icon = this.options.icon || this.icon; //二级图标样式,0:文件夹,1:人员,2:机构,3:报表,4:信息,5:叶子,6:勋章,7:文件,8:小圆点,9:齿轮,10:星星, -1:不显示二级图标。默认'5'
  598. this.nodeIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? (this.icon == "-1" ? "-1" : "0") : this.icon[0]; //二级图标中的node节点图标。0:文件夹,1:+、-,2:三角形, -1:不显示二级图标,默认'0'
  599. this.leafIcon = (typeof this.icon === 'string' || typeof this.icon === 'number') ? this.icon : this.icon[1]; //二级图标中的leaf节点图标
  600. }
  601. /** 数据加载参数**/
  602. this.url = this.options.url || this.url; //请求地址
  603. this.async = (typeof (this.options.async) === "boolean") ? this.options.async : this.async; //异步同步加载,默认异步加载
  604. this.headers = this.options.headers || this.headers; //ajax header属性
  605. this.method = this.options.method || this.method; //请求类型
  606. this.dataType = this.options.dataType || this.dataType; //参数类型
  607. this.contentType = this.options.contentType || this.contentType; //发送信息至服务器时内容编码类型
  608. this.defaultRequest = $.extend(this.defaultRequest, this.options.defaultRequest) || this.defaultRequest; //默认请求参数
  609. this.filterRequest = this.options.filterRequest || this.filterRequest; //过滤请求参数
  610. this.request = this.options.request || this.request; //用户自定义请求参数
  611. this.response = $.extend(this.response, this.options.response) || this.response; //返回json格式
  612. this.data = this.options.data || this.data; //初始化指定该参数,则不会访问异步接口
  613. this.dataFormat = this.options.dataFormat || this.dataFormat; //用于用户配置的data数据格式,list:列表, levelRelationship:层级关系,默认
  614. this.dataStyle = this.options.dataStyle || this.dataStyle; //用于用户配置layui通用的json数据风格,layuiStyle:layui风格,defaultStyle:默认风格
  615. this.errDataShow = (typeof (this.options.errDataShow) === "boolean") ? this.options.errDataShow : this.errDataShow; //是否在使用list模式递归数据出现错误时,显示错误信息
  616. this.withCredentials = (typeof (this.options.withCredentials) === "boolean") ? this.options.withCredentials : this.withCredentials; //是否允许跨域请求
  617. this.success = this.options.success || this.success; //树加载完毕后执行解析树之前的回调
  618. this.done = this.options.done || this.done; //树加载完毕后的回调
  619. this.formatter = $.extend(this.formatter, this.options.formatter)|| this.formatter; //数据过滤
  620. this.error = this.options.error || this.error; //异步加载异常回调
  621. this.complete = this.options.complete || this.complete; //异步加载完成回调
  622. /** 复选框参数**/
  623. this.checkbar = this.options.checkbar || this.checkbar; //是否开启复选框模式
  624. this.checkbarLoad = this.options.checkbarLoad || this.checkbarLoad; //复选框作用范围,node:所有节点, leaf:最后一级;默认所有节点
  625. this.checkbarType = this.options.checkbarType || this.checkbarType; //复选框选中形式 all:子集选中父级也选中, no-all:子集选中父级半选中,子集全选父级选中,p-casc:父级选中子集全选,子集无法改变父级选中状态, self:没有任何级联关系,only:只能选中一个复选框。 默认all
  626. this.checkbarData = this.options.checkbarData || this.checkbarData; //复选框记录数据类型形式, change表示记录变更数据,choose表示记录选中数据,all记录全部数据,halfChoose记录选中和半选中的数据,默认choose
  627. this.checkbarFun = $.extend(this.checkbarFun, this.options.checkbarFun)|| this.checkbarFun; //checkbar事件加载
  628. /** 菜单栏参数**/
  629. this.menubar = this.options.menubar || this.menubar; //是否打开菜单栏
  630. this.menubarTips = $.extend(this.menubarTips, this.options.menubarTips) || this.menubarTips; //菜单栏吸附, toolbar:依附在工具栏,group:依附在按钮组,freedom,自由
  631. this.menubarFun = $.extend(this.menubarFun, this.options.menubarFun) || this.menubarFun; //menubar事件加载
  632. /** 工具栏参数**/
  633. this.toolbar = this.options.toolbar || this.toolbar; //是否开启工具栏
  634. this.toolbarWay = this.options.toolbarWay || this.toolbarWay; //工具栏显示方式,contextmenu:右键,follow:跟随节点,fixed:固定在节点右侧
  635. this.toolbarStyle = $.extend(this.toolbarStyle, this.options.toolbarStyle) || this.toolbarStyle; //toolbar的自定义风格,标题,弹框大小
  636. this.toolbarLoad = this.options.toolbarLoad || this.toolbarLoad; //toolbar作用范围:node:所有节点,noleaf:非最后一级节点,leaf:最后一级
  637. this.toolbarShow = this.options.toolbarShow || this.toolbarShow; //toolbar三个按钮
  638. this.toolbarBtn = this.options.toolbarBtn || this.toolbarBtn; //toolbar增删改中内容的自定义加载
  639. this.toolbarExt = this.options.toolbarExt || this.toolbarExt; //toolbar按钮扩展
  640. this.toolbarFun = $.extend(this.toolbarFun, this.options.toolbarFun) || this.toolbarFun; //toolbar事件加载
  641. /** iframe模式参数**/
  642. this.useIframe = this.options.useIframe || this.useIframe;//是否加载iframe 默认false
  643. this.iframeElem = this.options.iframeElem || this.iframeElem; //iframe的ID
  644. this.iframeUrl = this.options.iframeUrl || this.iframeUrl; //树关联的iframe地址
  645. this.iframeLoad = this.options.iframeLoad || this.iframeLoad; //点击哪一层加载frame: node:所有节点, leaf:默认,最后一级
  646. this.iframeDefaultRequest = $.extend(this.iframeDefaultRequest, this.options.iframeDefaultRequest) || this.iframeDefaultRequest; //iframe的默认传递参数
  647. this.iframeRequest = $.extend(this.iframeRequest, this.options.iframeRequest) || this.iframeRequest; //iframe的自定义参数
  648. this.iframeFun = $.extend(this.iframeFun, this.options.iframeFun) || this.iframeFun; //iframe事件加载
  649. /** 下拉树模式参数**/
  650. if(this.select) {
  651. // 重置下拉树
  652. this.reloadSelectSetting();
  653. }
  654. /** 调用确认最终主题方法*/
  655. this.ensureTheme();
  656. };
  657. // 设置下拉树的基本参数值
  658. DTree.prototype.selectSetting = function() {
  659. /** select模式参数*/
  660. this.select = true; //配置成select模式
  661. this.selectInitVal = this.obj.attr("data-value") || this.options.selectInitVal || ""; //输入框的值
  662. this.selectTreeDiv = this.obj[0].id + "_tree_div"; // 上级DIV节点
  663. this.selectCardDiv = this.obj[0].id + "_select_card_div"; // 上级layui卡片节点
  664. this.selectDiv = this.obj[0].id + "_select_div"; // 模拟的select节点
  665. this.selectTipsName = this.obj[0].id + "_select_input"; // select的提示输入框名称
  666. this.selectTips = this.options.selectTips || "请选择"; // 输入框的提示语
  667. this.selectInputName = this.options.selectInputName || {nodeId: this.obj[0].id + "_select_nodeId"}; // select表单中的元素
  668. // 调取下拉树的特殊处理页面元素标识
  669. this.renderSelectDom();
  670. }
  671. // 重新设置下拉树的基本参数值
  672. DTree.prototype.reloadSelectSetting = function() {
  673. this.selectInitVal = this.obj.attr("data-value") || this.options.selectInitVal || this.selectInitVal; //输入框的值
  674. this.selectTips = this.options.selectTips || this.selectTips; // 输入框的提示语
  675. this.selectInputName = $.extend(this.selectInputName, this.options.selectInputName) || this.selectInputName; // select表单中的元素
  676. // 调取下拉树的特殊处理页面元素标识
  677. this.reloadSelectDom();
  678. }
  679. /******************** 下拉树设置区域 ********************/
  680. // 渲染下拉树的Dom结构
  681. DTree.prototype.renderSelectDom = function() {
  682. var _this = this;
  683. var rootId = _this.obj[0].id;
  684. // 设置自定义表单隐藏域
  685. var selectInputName = _this.selectInputName;
  686. var selectInput = [];
  687. for(var key in selectInputName) {
  688. selectInput.push('<input type="hidden" dtree-id="' + rootId + '" dtree-node="' + key + '" name="' + selectInputName[key] + '" value="" readonly>');
  689. }
  690. // 设置html
  691. var prevHtml = ['<div class="layui-unselect layui-form-select" dtree-id="' + rootId + '" dtree-select="' + _this.selectDiv + '">',
  692. '<div class="layui-select-title">', selectInput.join(""),
  693. '<input type="text" dtree-id="' + rootId + '" id="' + _this.selectTipsName +'_id" name="' + _this.selectTipsName + '" placeholder="' + _this.selectTips + '" value="" readonly class="layui-input layui-unselect">',
  694. '<i class="layui-edge"></i>',
  695. '</div></div>'].join('');
  696. _this.obj.before(prevHtml);
  697. _this.obj.wrap('<div class="layui-card dtree-select" dtree-id="' + rootId + '" dtree-card="' + _this.selectCardDiv + '"></div>').wrap('<div class="layui-card-body"></div>').wrap('<div id="' + _this.selectTreeDiv + '"></div>');
  698. }
  699. // 重新渲染下拉树的Dom结构
  700. DTree.prototype.reloadSelectDom = function() {
  701. var _this = this;
  702. var rootId = _this.obj[0].id;
  703. // 设置自定义表单隐藏域
  704. var selectInputName = _this.selectInputName;
  705. var selectInput = [];
  706. for(var key in selectInputName) {
  707. selectInput.push('<input type="hidden" dtree-id="' + rootId + '" dtree-node="' + key + '" name="' + selectInputName[key] + '" value="" readonly>');
  708. }
  709. $("div[dtree-id='"+rootId+"'][dtree-select='"+_this.selectDiv+"']").find("div.layui-select-title").html("");
  710. // 设置html
  711. var prevHtml = [selectInput.join(""),
  712. '<input type="text" dtree-id="' + rootId + '" id="' + _this.selectTipsName +'_id" name="' + _this.selectTipsName + '" placeholder="' + _this.selectTips + '" value="" readonly class="layui-input layui-unselect">',
  713. '<i class="layui-edge"></i>'].join('');
  714. $("div[dtree-id='"+rootId+"'][dtree-select='"+_this.selectDiv+"']").find("div.layui-select-title").html(prevHtml);
  715. }
  716. // 设置输入框的值
  717. DTree.prototype.selectVal = function(param) {
  718. var _this = this;
  719. var rootId = _this.obj[0].id;
  720. var selectInputName = _this.selectInputName;
  721. var selectTipsNameValue = "";
  722. var selectValues = {};
  723. // 如果开启了复选框,则此方法用来取值
  724. if(_this.checkbar) {
  725. $("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "']").each(function(){
  726. var name = $(this).attr("name");
  727. var val = $(this).val();
  728. selectValues[name] = val;
  729. });
  730. } else {
  731. if(typeof param === 'undefined') { // 不传,则为当前树中记录的ID
  732. param = _this.getNowParam();
  733. }
  734. if(typeof param === 'string') { // 传递ID,则查询树节点ID对应的值
  735. param = _this.getParam(param);
  736. }
  737. selectTipsNameValue = param["context"];
  738. for(var key in selectInputName) {
  739. selectValues[selectInputName[key]] = param[key];
  740. $("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+selectInputName[key]+"']").val(param[key] || "");
  741. }
  742. if(param["nodeId"] && !param["context"]) {
  743. selectTipsNameValue = _this.getParam(param["nodeId"]);
  744. }
  745. // 返显提示输入框值
  746. $("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+_this.selectTipsName+"']").val(selectTipsNameValue || "");
  747. }
  748. // 返回隐藏域中的值
  749. return selectValues;
  750. }
  751. // 设置复选框模式中的下拉树的值
  752. DTree.prototype.selectCheckboxVal = function() {
  753. var _this = this;
  754. var rootId = _this.obj[0].id;
  755. var selectInputName = _this.selectInputName;
  756. // 获取全部复选框选中节点
  757. var param = _this.getCheckbarJsonArrParam();
  758. selectTipsNameValue = param["context"];
  759. var selectValues = {};
  760. for(var key in selectInputName) {
  761. var value = param[key].join(",");
  762. selectValues[selectInputName[key]] = value;
  763. $("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+selectInputName[key]+"']").val(value);
  764. }
  765. $("div[dtree-select='" + _this.selectDiv + "']").find("input[dtree-id='" + rootId + "'][name='"+_this.selectTipsName+"']").val(selectTipsNameValue);
  766. // 返回隐藏域中的值
  767. return selectValues;
  768. }
  769. // 重置下拉树的值
  770. DTree.prototype.selectResetVal = function() {
  771. var _this = this;
  772. var rootId = _this.obj[0].id;
  773. // 表单清空
  774. $("input[dtree-id='"+rootId+"']").val("");
  775. // 节点重置
  776. _this.cancelNavThis();
  777. if(_this.checkbar) {
  778. // 复选框重置
  779. _this.cancelCheckedNode();
  780. }
  781. }
  782. /******************** 字体及图标区域 ********************/
  783. // 确认最终主题
  784. DTree.prototype.ensureTheme = function(){
  785. var _this = this;
  786. // 确认style
  787. this.style.item = DTREE + this.skin + ITEM;
  788. this.style.itemThis = DTREE + this.skin + ITEMTHIS;
  789. this.style.dfont = DTREE + this.skin + DFONT;
  790. this.style.ficon = DTREE + this.skin + FICON;
  791. this.style.icon = DTREE + this.skin + ICON;
  792. this.style.cbox = DTREE + this.skin + CBOX;
  793. this.style.chs = DTREE + this.skin + CHS;
  794. // 确认usefontStyle
  795. var iconfont = this.iconfont;
  796. var iconfonts = [];
  797. if(typeof iconfont === 'string') {
  798. iconfonts.push(iconfont);
  799. } else {
  800. iconfonts = iconfont;
  801. }
  802. var iconfontStyle = this.iconfontStyle;
  803. var iconfontStyles = [];
  804. if(iconfontStyle.length == undefined) {
  805. iconfontStyles.push(iconfontStyle);
  806. } else {
  807. iconfontStyles = iconfontStyle;
  808. }
  809. for(var i=0; i<iconfonts.length; i++){
  810. var ifont = iconfonts[i];
  811. var ifontStyle = iconfontStyles[i];
  812. if(typeof ifontStyle !== 'undefined') {
  813. // 判断,赋值
  814. this.useDefaultOrUserDefineFnodeStyle(ifont, ifontStyle.fnode);
  815. this.useDefaultOrUserDefineSnodeStyle(ifont, ifontStyle.snode);
  816. this.useDefaultOrUserDefineCheckboxStyle(ifont, ifontStyle.checkbox);
  817. this.useDefaultOrUserDefineMenubarStyle(ifont, ifontStyle.menubar);
  818. this.useDefaultOrUserDefineMenubarExtStyle(ifont, ifontStyle.menubarExt);
  819. this.useDefaultOrUserDefineToolbarStyle(ifont, ifontStyle.toolbar);
  820. this.useDefaultOrUserDefineToolbarExtStyle(ifont, ifontStyle.toolbarExt);
  821. }
  822. }
  823. };
  824. // 赋值一级图标
  825. DTree.prototype.useDefaultOrUserDefineFnodeStyle = function(ifont, fnode){
  826. var _this = this;
  827. var tempOpen = this.usefontStyle.fnode.node.open;
  828. var tempClose = this.usefontStyle.fnode.node.close;
  829. var tempLeaf = this.usefontStyle.fnode.leaf;
  830. if(typeof fnode === 'undefined'){
  831. this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
  832. this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
  833. this.usefontStyle.fnode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.fleafIcon]) : tempLeaf; // 一级图标中的node节点的leaf图标
  834. } else {
  835. var node = fnode.node;
  836. var leaf = fnode.leaf;
  837. if(typeof node === 'undefined'){
  838. this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
  839. this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
  840. } else {
  841. var open = node.open;
  842. var close = node.close;
  843. if(typeof open === 'undefined'){
  844. this.usefontStyle.fnode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["open"]) : tempOpen; // 一级图标中的node节点open图标
  845. } else {
  846. this.usefontStyle.fnode.node.open = ifont + " " + open;
  847. }
  848. if(typeof close === 'undefined') {
  849. this.usefontStyle.fnode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.fnodeIcon]["close"]) : tempClose; // 一级图标中的node节点close图标
  850. } else {
  851. this.usefontStyle.fnode.node.close = ifont + " " + close;
  852. }
  853. }
  854. if(typeof leaf === 'undefined'){
  855. this.usefontStyle.fnode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.fleafIcon]) : tempLeaf; // 一级图标中的node节点的leaf图标
  856. } else {
  857. this.usefontStyle.fnode.leaf = ifont + " " + leaf;
  858. }
  859. }
  860. };
  861. // 赋值二级图标
  862. DTree.prototype.useDefaultOrUserDefineSnodeStyle = function(ifont, snode){
  863. var _this = this;
  864. var tempOpen = this.usefontStyle.snode.node.open;
  865. var tempClose = this.usefontStyle.snode.node.close;
  866. var tempLeaf = this.usefontStyle.snode.leaf;
  867. if(typeof snode === 'undefined'){
  868. this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
  869. this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
  870. this.usefontStyle.snode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.leafIcon]) : tempLeaf; // 二级图标中的leaf节点图标
  871. } else {
  872. var node = snode.node;
  873. var leaf = snode.leaf;
  874. if(typeof node === 'undefined') {
  875. this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
  876. this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
  877. } else {
  878. var open = node.open;
  879. var close = node.close;
  880. if(typeof open === 'undefined'){
  881. this.usefontStyle.snode.node.open = (tempOpen == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["open"]) : tempOpen; // 二级图标中的node节点open图标
  882. } else {
  883. this.usefontStyle.snode.node.open = ifont + " " + open;
  884. }
  885. if(typeof close === 'undefined') {
  886. this.usefontStyle.snode.node.close = (tempClose == "") ? (ifont + " " + this.nodeIconArray[this.nodeIcon]["close"]) : tempClose; // 二级图标中的node节点close图标
  887. } else {
  888. this.usefontStyle.snode.node.close = ifont + " " + close;
  889. }
  890. }
  891. if(typeof leaf === 'undefined') {
  892. this.usefontStyle.snode.leaf = (tempLeaf == "") ? (ifont + " " + this.leafIconArray[this.leafIcon]) : tempLeaf; // 二级图标中的leaf节点图标
  893. } else {
  894. this.usefontStyle.snode.leaf = ifont + " " + leaf;
  895. }
  896. }
  897. };
  898. // 赋值复选框图标
  899. DTree.prototype.useDefaultOrUserDefineCheckboxStyle = function(ifont, checkbox){
  900. var _this = this;
  901. var tempOn = this.usefontStyle.checkbox.on;
  902. var tempOut = this.usefontStyle.checkbox.out;
  903. var tempNoall = this.usefontStyle.checkbox.noall;
  904. if(typeof checkbox === 'undefined'){
  905. this.usefontStyle.checkbox.on = (tempOn == "") ? (ifont + " " + LI_DIV_CHECKBAR_ON) : tempOn;
  906. this.usefontStyle.checkbox.out = (tempOut == "") ? (ifont + " " + LI_DIV_CHECKBAR_OUT) : tempOut;
  907. this.usefontStyle.checkbox.noall = (tempNoall == "") ? (ifont + " " + LI_DIV_CHECKBAR_NOALL) : tempNoall;
  908. } else {
  909. var on = checkbox.on;
  910. var out = checkbox.out;
  911. var noall = checkbox.noall;
  912. if(typeof on === 'undefined') {
  913. this.usefontStyle.checkbox.on = (tempOn == "") ? (ifont + " " + LI_DIV_CHECKBAR_ON) : tempOn;
  914. } else {
  915. this.usefontStyle.checkbox.on = ifont + " " + on;
  916. }
  917. if(typeof out === 'undefined') {
  918. this.usefontStyle.checkbox.out = (tempOut == "") ? (ifont + " " + LI_DIV_CHECKBAR_OUT) : tempOut;
  919. } else {
  920. this.usefontStyle.checkbox.out = ifont + " " + out;
  921. }
  922. if(typeof noall === 'undefined') {
  923. this.usefontStyle.checkbox.noall = (tempNoall == "") ? (ifont + " " + LI_DIV_CHECKBAR_NOALL) : tempNoall;
  924. } else {
  925. this.usefontStyle.checkbox.noall = ifont + " " + noall;
  926. }
  927. }
  928. };
  929. // 赋值菜单栏图标
  930. DTree.prototype.useDefaultOrUserDefineMenubarStyle = function(ifont, menubar){
  931. var _this = this;
  932. var tempMovedown = this.usefontStyle.menubar.movedown;
  933. var tempMoveup = this.usefontStyle.menubar.moveup;
  934. var tempRefresh = this.usefontStyle.menubar.refresh;
  935. var tempCheckAll = this.usefontStyle.menubar.checkAll;
  936. var tempUncheckAll = this.usefontStyle.menubar.unCheckAll;
  937. var tempInvertAll = this.usefontStyle.menubar.invertAll;
  938. var tempRemove = this.usefontStyle.menubar.remove;
  939. var tempSearch = this.usefontStyle.menubar.search;
  940. if(typeof menubar === 'undefined'){
  941. this.usefontStyle.menubar.movedown = (tempMovedown == "") ? (ifont + " " + LI_DIV_MENUBAR_DOWN) : tempMovedown;
  942. this.usefontStyle.menubar.moveup = (tempMoveup == "") ? (ifont + " " + LI_DIV_MENUBAR_UP) : tempMoveup;
  943. this.usefontStyle.menubar.refresh = (tempRefresh == "") ? (ifont + " " + LI_DIV_MENUBAR_REFRESH) : tempRefresh;
  944. this.usefontStyle.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_CHECKALL) : tempCheckAll;
  945. this.usefontStyle.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_UNCHECKALL) : tempUncheckAll;
  946. this.usefontStyle.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + LI_DIV_MENUBAR_INVERTALL) : tempInvertAll;
  947. this.usefontStyle.menubar.remove = (tempRemove == "") ? (ifont + " " + LI_DIV_MENUBAR_DELETE) : tempRemove;
  948. this.usefontStyle.menubar.search = (tempSearch == "") ? (ifont + " " + LI_DIV_MENUBAR_SEARCH) : tempSearch;
  949. } else {
  950. var movedown = menubar.movedown;
  951. var moveup = menubar.moveup;
  952. var refresh = menubar.refresh;
  953. var checkAll = menubar.checkAll;
  954. var unCheckAll = menubar.unCheckAll;
  955. var invertAll = menubar.invertAll;
  956. var remove = menubar.remove;
  957. var search = menubar.search;
  958. if(typeof movedown === 'undefined') {
  959. this.usefontStyle.menubar.movedown = (tempMovedown == "") ? (ifont + " " + LI_DIV_MENUBAR_DOWN) : tempMovedown;
  960. } else {
  961. this.usefontStyle.menubar.movedown = ifont + " " + movedown;
  962. }
  963. if(typeof moveup === 'undefined') {
  964. this.usefontStyle.menubar.moveup = (tempMoveup == "") ? (ifont + " " + LI_DIV_MENUBAR_UP) : tempMoveup;
  965. } else {
  966. this.usefontStyle.menubar.moveup = ifont + " " + moveup;
  967. }
  968. if(typeof refresh === 'undefined') {
  969. this.usefontStyle.menubar.refresh = (tempRefresh == "") ? (ifont + " " + LI_DIV_MENUBAR_REFRESH) : tempRefresh;
  970. } else {
  971. this.usefontStyle.menubar.refresh = ifont + " " + refresh;
  972. }
  973. if(typeof checkAll === 'undefined') {
  974. this.usefontStyle.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_CHECKALL) : tempCheckAll;
  975. } else {
  976. this.usefontStyle.menubar.checkAll = ifont + " " + checkAll;
  977. }
  978. if(typeof unCheckAll === 'undefined') {
  979. this.usefontStyle.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + LI_DIV_MENUBAR_UNCHECKALL) : tempUncheckAll;
  980. } else {
  981. this.usefontStyle.menubar.unCheckAll = ifont + " " + unCheckAll;
  982. }
  983. if(typeof invertAll === 'undefined') {
  984. this.usefontStyle.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + LI_DIV_MENUBAR_INVERTALL) : tempInvertAll;
  985. } else {
  986. this.usefontStyle.menubar.invertAll = ifont + " " + invertAll;
  987. }
  988. if(typeof remove === 'undefined') {
  989. this.usefontStyle.menubar.remove = (tempRemove == "") ? (ifont + " " + LI_DIV_MENUBAR_DELETE) : tempRemove;
  990. } else {
  991. this.usefontStyle.menubar.remove = ifont + " " + remove;
  992. }
  993. if(typeof search === 'undefined') {
  994. this.usefontStyle.menubar.search = (tempSearch == "") ? (ifont + " " + LI_DIV_MENUBAR_SEARCH) : tempSearch;
  995. } else {
  996. this.usefontStyle.menubar.search = ifont + " " + search;
  997. }
  998. }
  999. };
  1000. // 赋值扩展菜单栏图标
  1001. DTree.prototype.useDefaultOrUserDefineMenubarExtStyle = function(ifont, menubarExt){
  1002. var _this = this;
  1003. var tempExt = this.usefontStyle.menubarExt;
  1004. if(typeof menubarExt === 'undefined'){
  1005. this.usefontStyle.menubarExt = (tempExt == "") ? ifont : tempExt;
  1006. } else {
  1007. this.usefontStyle.menubarExt = menubarExt;
  1008. }
  1009. };
  1010. // 赋值工具栏图标
  1011. DTree.prototype.useDefaultOrUserDefineToolbarStyle = function(ifont, toolbar){
  1012. var _this = this;
  1013. var tempMovedown = this.usefontStyle.toolbar.menubar.movedown;
  1014. var tempMoveup = this.usefontStyle.toolbar.menubar.moveup;
  1015. var tempRefresh = this.usefontStyle.toolbar.menubar.refresh;
  1016. var tempCheckAll = this.usefontStyle.toolbar.menubar.checkAll;
  1017. var tempUnCheckAll = this.usefontStyle.toolbar.menubar.unCheckAll;
  1018. var tempInvertAll = this.usefontStyle.toolbar.menubar.invertAll;
  1019. var tempRemove = this.usefontStyle.toolbar.menubar.remove;
  1020. var tempSearch = this.usefontStyle.toolbar.menubar.search;
  1021. var tempExt = this.usefontStyle.toolbar.menubarExt;
  1022. var tempPulldown = this.usefontStyle.toolbar.pulldown;
  1023. var tempPullup = this.usefontStyle.toolbar.pullup;
  1024. var tempAdd = this.usefontStyle.toolbar.add;
  1025. var tempEdit = this.usefontStyle.toolbar.edit;
  1026. var tempDel = this.usefontStyle.toolbar.del;
  1027. if(typeof toolbar === 'undefined'){
  1028. this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
  1029. this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
  1030. this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
  1031. this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
  1032. this.usefontStyle.toolbar.menubar.unCheckAll = (tempUnCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUnCheckAll;
  1033. this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
  1034. this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
  1035. this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
  1036. this.usefontStyle.toolbar.menubarExt = (tempExt == "") ? this.usefontStyle.menubarExt : tempExt;
  1037. this.usefontStyle.toolbar.pulldown = (tempPulldown == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLDOWN) : tempPulldown;
  1038. this.usefontStyle.toolbar.pullup = (tempPullup == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLUP) : tempPullup;
  1039. this.usefontStyle.toolbar.add = (tempAdd == "") ? (ifont + " " + LI_DIV_TOOLBAR_ADD) : tempAdd;
  1040. this.usefontStyle.toolbar.edit = (tempEdit == "") ? (ifont + " " + LI_DIV_TOOLBAR_EDIT) : tempEdit;
  1041. this.usefontStyle.toolbar.del = (tempDel == "") ? (ifont + " " + LI_DIV_TOOLBAR_DEL) : tempDel;
  1042. } else {
  1043. var menubar = toolbar.menubar;
  1044. var menubarExt = toolbar.menubarExt;
  1045. var pulldown = toolbar.pulldown;
  1046. var pullup = toolbar.pullup;
  1047. var add = toolbar.add;
  1048. var edit = toolbar.edit;
  1049. var del = toolbar.del;
  1050. if(typeof menubar === 'undefined'){
  1051. this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
  1052. this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
  1053. this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
  1054. this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
  1055. this.usefontStyle.toolbar.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUncheckAll;
  1056. this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
  1057. this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
  1058. this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
  1059. } else {
  1060. var movedown = menubar.movedown;
  1061. var moveup = menubar.moveup;
  1062. var refresh = menubar.refresh;
  1063. var checkAll = menubar.checkAll;
  1064. var unCheckAll = menubar.unCheckAll;
  1065. var invertAll = menubar.invertAll;
  1066. var remove = menubar.remove;
  1067. var search = menubar.search;
  1068. if(typeof movedown === 'undefined') {
  1069. this.usefontStyle.toolbar.menubar.movedown = (tempMovedown == "") ? (ifont + " " + this.usefontStyle.menubar.movedown) : tempMovedown;
  1070. } else {
  1071. this.usefontStyle.toolbar.menubar.movedown = ifont + " " + movedown;
  1072. }
  1073. if(typeof moveup === 'undefined') {
  1074. this.usefontStyle.toolbar.menubar.moveup = (tempMoveup == "") ? (ifont + " " + this.usefontStyle.menubar.moveup) : tempMoveup;
  1075. } else {
  1076. this.usefontStyle.toolbar.menubar.moveup = ifont + " " + moveup;
  1077. }
  1078. if(typeof refresh === 'undefined') {
  1079. this.usefontStyle.toolbar.menubar.refresh = (tempRefresh == "") ? (ifont + " " + this.usefontStyle.menubar.refresh) : tempRefresh;
  1080. } else {
  1081. this.usefontStyle.toolbar.menubar.refresh = ifont + " " + refresh;
  1082. }
  1083. if(typeof checkAll === 'undefined') {
  1084. this.usefontStyle.toolbar.menubar.checkAll = (tempCheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.checkAll) : tempCheckAll;
  1085. } else {
  1086. this.usefontStyle.toolbar.menubar.checkAll = ifont + " " + checkAll;
  1087. }
  1088. if(typeof unCheckAll === 'undefined') {
  1089. this.usefontStyle.toolbar.menubar.unCheckAll = (tempUncheckAll == "") ? (ifont + " " + this.usefontStyle.menubar.unCheckAll) : tempUncheckAll;
  1090. } else {
  1091. this.usefontStyle.toolbar.menubar.unCheckAll = ifont + " " + unCheckAll;
  1092. }
  1093. if(typeof invertAll === 'undefined') {
  1094. this.usefontStyle.toolbar.menubar.invertAll = (tempInvertAll == "") ? (ifont + " " + this.usefontStyle.menubar.invertAll) : tempInvertAll;
  1095. } else {
  1096. this.usefontStyle.toolbar.menubar.invertAll = ifont + " " + invertAll;
  1097. }
  1098. if(typeof remove === 'undefined') {
  1099. this.usefontStyle.toolbar.menubar.remove = (tempRemove == "") ? (ifont + " " + this.usefontStyle.menubar.remove) : tempRemove;
  1100. } else {
  1101. this.usefontStyle.toolbar.menubar.remove = ifont + " " + remove;
  1102. }
  1103. if(typeof search === 'undefined') {
  1104. this.usefontStyle.toolbar.menubar.search = (tempSearch == "") ? (ifont + " " + this.usefontStyle.menubar.search) : tempSearch;
  1105. } else {
  1106. this.usefontStyle.toolbar.menubar.search = ifont + " " + search;
  1107. }
  1108. }
  1109. if(typeof menubarExt === 'undefined'){
  1110. this.usefontStyle.toolbar.menubarExt = (tempExt == "") ? this.usefontStyle.menubarExt : tempExt;
  1111. } else {
  1112. this.usefontStyle.toolbar.menubarExt = menubarExt;
  1113. }
  1114. if(typeof pulldown === 'undefined'){
  1115. this.usefontStyle.toolbar.pulldown = (tempPulldown == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLDOWN) : tempPulldown;
  1116. } else {
  1117. this.usefontStyle.toolbar.pulldown = ifont + " " + pulldown;
  1118. }
  1119. if(typeof pullup === 'undefined'){
  1120. this.usefontStyle.toolbar.pullup = (tempPullup == "") ? (ifont + " " + LI_DIV_TOOLBAR_PULLUP) : tempPullup;
  1121. } else {
  1122. this.usefontStyle.toolbar.pullup = ifont + " " + pullup;
  1123. }
  1124. if(typeof add === 'undefined'){
  1125. this.usefontStyle.toolbar.add = (tempAdd == "") ? (ifont + " " + LI_DIV_TOOLBAR_ADD) : tempAdd;
  1126. } else {
  1127. this.usefontStyle.toolbar.add = ifont + " " + add;
  1128. }
  1129. if(typeof edit === 'undefined'){
  1130. this.usefontStyle.toolbar.edit = (tempEdit == "") ? (ifont + " " + LI_DIV_TOOLBAR_EDIT) : tempEdit;
  1131. } else {
  1132. this.usefontStyle.toolbar.edit = ifont + " " + edit;
  1133. }
  1134. if(typeof del === 'undefined'){
  1135. this.usefontStyle.toolbar.del = (tempDel == "") ? (ifont + " " + LI_DIV_TOOLBAR_DEL) : tempDel;
  1136. } else {
  1137. this.usefontStyle.toolbar.del = ifont + " " + del;
  1138. }
  1139. }
  1140. };
  1141. // 赋值扩展工具栏图标
  1142. DTree.prototype.useDefaultOrUserDefineToolbarExtStyle = function(ifont, toolbarExt){
  1143. var _this = this;
  1144. var tempExt = this.usefontStyle.toolbarExt;
  1145. if(typeof toolbarExt === 'undefined'){
  1146. this.usefontStyle.toolbarExt = (tempExt == "") ? ifont : tempExt;
  1147. } else {
  1148. this.usefontStyle.toolbarExt = toolbarExt;
  1149. }
  1150. };
  1151. // 设置图标的展开关闭,以及展开时/关闭时是最后一级图标的处理
  1152. DTree.prototype.operateIcon = function($i_spread, $i_node){
  1153. var _this = this;
  1154. var ficonClass = $i_spread.attr("data-iconClass");
  1155. var iconClass = $i_node.attr("data-iconClass");
  1156. return{
  1157. open: function(){
  1158. $i_spread.attr("data-spread","open");
  1159. $i_node.attr("data-spread","open");
  1160. if(!ficonClass) {
  1161. $i_spread.removeClass(_this.usefontStyle.fnode.node.close);
  1162. $i_spread.addClass(_this.usefontStyle.fnode.node.open);
  1163. }
  1164. if(!iconClass) {
  1165. $i_node.removeClass(_this.usefontStyle.snode.node.close);
  1166. $i_node.addClass(_this.usefontStyle.snode.node.open);
  1167. }
  1168. },
  1169. close: function(){
  1170. $i_spread.attr("data-spread","close");
  1171. $i_node.attr("data-spread","close");
  1172. if(!ficonClass) {
  1173. $i_spread.removeClass(_this.usefontStyle.fnode.node.open);
  1174. $i_spread.addClass(_this.usefontStyle.fnode.node.close);
  1175. }
  1176. if(!iconClass) {
  1177. $i_node.removeClass(_this.usefontStyle.snode.node.open);
  1178. $i_node.addClass(_this.usefontStyle.snode.node.close);
  1179. }
  1180. },
  1181. openWithLeaf: function(){
  1182. $i_spread.attr("data-spread","open");
  1183. $i_node.attr("data-spread","open");
  1184. if(!ficonClass) {
  1185. $i_spread.removeClass(_this.usefontStyle.fnode.leaf);
  1186. $i_spread.addClass(_this.usefontStyle.fnode.node.open);
  1187. }
  1188. if(!iconClass) {
  1189. $i_node.removeClass(_this.usefontStyle.snode.leaf);
  1190. $i_node.addClass(_this.usefontStyle.snode.node.open);
  1191. }
  1192. },
  1193. closeWithLeaf: function(){
  1194. $i_spread.attr("data-spread","last");
  1195. $i_node.attr("data-spread","last");
  1196. if(!ficonClass) {
  1197. $i_spread.removeClass(_this.usefontStyle.fnode.node.open);
  1198. $i_spread.removeClass(_this.usefontStyle.fnode.node.close);
  1199. $i_spread.addClass(_this.usefontStyle.fnode.leaf);
  1200. }
  1201. if(!iconClass) {
  1202. $i_node.removeClass(_this.usefontStyle.snode.node.open);
  1203. $i_node.removeClass(_this.usefontStyle.snode.node.close);
  1204. $i_node.addClass(_this.usefontStyle.snode.leaf);
  1205. }
  1206. }
  1207. }
  1208. };
  1209. // 显示树线
  1210. DTree.prototype.showLine = function($lis){
  1211. var _this = this;
  1212. if(_this.line){
  1213. if($lis && $lis.length > 0) {
  1214. $lis.each(function(){
  1215. _this.showLineLi($(this));
  1216. });
  1217. } else {
  1218. _this.obj.find("li[data-id]").each(function(){
  1219. _this.showLineLi($(this));
  1220. });
  1221. }
  1222. }
  1223. }
  1224. // 真正显示树线的方法
  1225. DTree.prototype.showLineLi = function($li){
  1226. var _this = this;
  1227. var $div = $li.children("div"),
  1228. $nextLi = $li.next("li"),
  1229. $ul = $li.parent("ul");
  1230. if($ul[0].id == _this.obj[0].id) {
  1231. // 根节点下的节点
  1232. $li.removeClass(LI_NAV_LINE);
  1233. $li.removeClass(LI_NAV_LAST_LINE);
  1234. $li.addClass(LI_NAV_FIRST_LINE);
  1235. } else {
  1236. // 非根节点下的节点
  1237. var $pnextLi = $ul.parent("li").next("li");
  1238. if($pnextLi.length == 0) {
  1239. if($nextLi.length == 0){
  1240. $li.removeClass(LI_NAV_LINE);
  1241. $li.removeClass(LI_NAV_FIRST_LINE);
  1242. $li.addClass(LI_NAV_LAST_LINE);
  1243. } else {
  1244. $li.removeClass(LI_NAV_FIRST_LINE);
  1245. $li.removeClass(LI_NAV_LAST_LINE);
  1246. $li.addClass(LI_NAV_LINE);
  1247. }
  1248. }else {
  1249. var $pnextdiv = $pnextLi.children("div");
  1250. if($nextLi.length == 0 && $div.children("cite").attr("data-leaf") == "leaf" && $pnextdiv.children("cite").attr("data-leaf") == "leaf") {
  1251. $li.removeClass(LI_NAV_FIRST_LINE);
  1252. $li.removeClass(LI_NAV_LINE);
  1253. $li.addClass(LI_NAV_LAST_LINE);
  1254. } else {
  1255. $li.removeClass(LI_NAV_FIRST_LINE);
  1256. $li.removeClass(LI_NAV_LAST_LINE);
  1257. $li.addClass(LI_NAV_LINE);
  1258. }
  1259. }
  1260. }
  1261. }
  1262. /******************** 初始化数据区域 ********************/
  1263. // 设置高度
  1264. DTree.prototype.autoHeight = function(){
  1265. var _this = this;
  1266. var height = _this.height;
  1267. if(height != "") {
  1268. if(_this.elem == _this.scroll){
  1269. _this.obj.parent().css("height", height + "px");
  1270. } else {
  1271. var $toolbarDiv = _this.obj.closest(_this.scroll);
  1272. $toolbarDiv.css("height", height + "px");
  1273. }
  1274. }
  1275. };
  1276. // 重载树
  1277. DTree.prototype.reload = function(options){
  1278. var _this = this;
  1279. _this.reloadSetting(options);
  1280. _this.init();
  1281. };
  1282. // 初始化树
  1283. DTree.prototype.init = function(){
  1284. var _this = this;
  1285. if (typeof _this !== "object") {
  1286. //_this.obj.html(_this.getNoneDom().errText("树组件未成功加载,请检查配置"));
  1287. layer.msg("树组件未成功加载,请检查配置", {icon:5});
  1288. return ;
  1289. }
  1290. // 设置组件高度
  1291. _this.autoHeight();
  1292. if(_this.data) {
  1293. if(typeof _this.data.length === 'undefined'){
  1294. //_this.obj.html(_this.getNoneDom().errText("数据解析异常,data数据格式不正确"));
  1295. layer.msg("数据解析异常,data数据格式不正确", {icon:5});
  1296. return ;
  1297. }
  1298. if(_this.data.length == 0) {
  1299. _this.obj.html(_this.getNoneDom().text());
  1300. return ;
  1301. }
  1302. //先将ul中的元素清空
  1303. _this.obj.html("");
  1304. setTimeout(function () {
  1305. // 加载完毕后执行树解析前的回调
  1306. _this.success(_this.data, _this.obj);
  1307. // 第一次解析树
  1308. if (_this.dataFormat == 'list'){
  1309. //1.识别根节点ul中的data-id标签,判断顶级父节点
  1310. var pid = _this.obj.attr("data-id");
  1311. //2.构建一个存放节点的树组
  1312. var rootListData = _this.queryListTreeByPid(pid, _this.data);
  1313. _this.loadListTree(rootListData, _this.data, 1);
  1314. } else {
  1315. _this.loadTree(_this.data, 1);
  1316. }
  1317. // 显示树线
  1318. _this.showLine();
  1319. // 这种情况下需要一开始就将toolbar显示在页面上
  1320. if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
  1321. _this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
  1322. }
  1323. // 判断是否存在错误数据,并是否打印错误数据
  1324. _this.msgErrData();
  1325. // 设置复选框的初始值
  1326. if(_this.select){
  1327. _this.selectVal(_this.selectInitVal);
  1328. }
  1329. // 保存树副本
  1330. _this.bak = _this.obj.html();
  1331. // 加载完毕后的回调
  1332. _this.done(_this.data, _this.obj);
  1333. }, 100);
  1334. } else {
  1335. if (!_this.url) {
  1336. //_this.obj.html(_this.getNoneDom().errText("数据请求异常,url参数未指定"));
  1337. layer.msg("数据请求异常,url参数未指定", {icon:5});
  1338. return ;
  1339. }
  1340. //先将ul中的元素清空
  1341. _this.obj.html("");
  1342. var index = _this.load ? layer.load(1) : "";
  1343. AjaxHelper.request({
  1344. async: _this.async,
  1345. headers: _this.headers,
  1346. type: _this.method,
  1347. url: _this.url,
  1348. dataType: _this.dataType,
  1349. contentType: _this.contentType,
  1350. withCredentials: _this.withCredentials,
  1351. data: _this.getFilterRequestParam(_this.getRequestParam()),
  1352. success: function(result) {
  1353. if (typeof result === 'string') {
  1354. result = $.parseJSON(result);
  1355. }
  1356. // 加载完毕后执行树解析前的回调
  1357. _this.success(result, _this.obj);
  1358. var code = "";
  1359. if (_this.dataStyle == 'layuiStyle'){
  1360. code = result[_this.response.statusName];
  1361. } else {
  1362. code = result.status[_this.response.statusName];
  1363. }
  1364. if (code == _this.response.statusCode) {
  1365. var d = result[_this.response.rootName];
  1366. if(typeof d.length === 'undefined'){
  1367. _this.obj.html(_this.getNoneDom().errText("数据解析异常,url回调后的数据格式不正确"));
  1368. //layer.msg("数据解析异常,url回调后的数据格式不正确", {icon:5});
  1369. return ;
  1370. }
  1371. if(d.length == 0) {
  1372. _this.obj.html(_this.getNoneDom().text());
  1373. return ;
  1374. }
  1375. // 第一次解析树
  1376. if (_this.dataFormat == 'list'){
  1377. //1.识别根节点ul中的data-id标签,判断顶级父节点
  1378. var pid = _this.obj.attr("data-id");
  1379. //2.构建一个存放节点的树组
  1380. var rootListData = _this.queryListTreeByPid(pid, d);
  1381. _this.loadListTree(rootListData, d, 1);
  1382. } else {
  1383. _this.loadTree(d, 1);
  1384. }
  1385. // 显示树线
  1386. _this.showLine();
  1387. // 这种情况下需要一开始就将toolbar显示在页面上
  1388. if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
  1389. _this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
  1390. }
  1391. // 判断是否存在错误数据,并是否打印错误数据
  1392. _this.msgErrData();
  1393. // 设置复选框的初始值
  1394. if(_this.select){
  1395. _this.selectVal(_this.selectInitVal);
  1396. }
  1397. // 保存树副本
  1398. _this.bak = _this.obj.html();
  1399. // 加载完毕后的回调
  1400. _this.done(result, _this.obj);
  1401. } else {
  1402. // 如果打印不出任何信息说明是在这里,用了错误的数据格式, 或返回码不正确
  1403. if (_this.dataStyle == 'layuiStyle'){
  1404. _this.obj.html(_this.getNoneDom().errText(result[_this.response.message]));
  1405. _this.error(null, code, result[_this.response.message]);
  1406. //layer.msg(result[_this.response.message], {icon:2});
  1407. } else {
  1408. _this.obj.html(_this.getNoneDom().errText(result.status[_this.response.message]));
  1409. _this.error(null, code, result.status[_this.response.message]);
  1410. //layer.msg(result.status[_this.response.message], {icon:2});
  1411. }
  1412. }
  1413. },
  1414. error: function(XMLHttpRequest, textStatus, errorThrown){// 异步加载异常回调
  1415. _this.obj.html(_this.getNoneDom().errText(textStatus + ": " + errorThrown));
  1416. _this.error(XMLHttpRequest, textStatus, errorThrown);
  1417. },
  1418. complete: function(XMLHttpRequest, textStatus){// 异步加载完成回调
  1419. if(_this.load){layer.close(index);}
  1420. _this.complete(XMLHttpRequest, textStatus);
  1421. }
  1422. });
  1423. }
  1424. };
  1425. // 加载子节点
  1426. DTree.prototype.getChild = function($div, data) {
  1427. var _this = this, $ul = $div.next("ul");
  1428. _this.setNodeParam($div);
  1429. if(typeof data !== 'undefined') {
  1430. if(typeof data.length === 'undefined'){
  1431. //_this.obj.html(_this.getNoneDom().errText("数据解析异常,data数据格式不正确"));
  1432. layer.msg("数据解析异常,data数据格式不正确", {icon:5});
  1433. return ;
  1434. }
  1435. //先将ul中的元素清空
  1436. $ul.html("");
  1437. // 解析树
  1438. if (_this.dataFormat == 'list'){
  1439. var pid = _this.node.nodeId;
  1440. var level = parseInt(_this.node.level)+1;
  1441. var listData = _this.queryListTreeByPid(pid, data);
  1442. _this.loadListTree(listData, _this.data, level);
  1443. } else {
  1444. _this.loadTree(data, level);
  1445. }
  1446. // 显示树线
  1447. _this.showLine();
  1448. // 这种情况下需要一开始就将toolbar显示在页面上
  1449. if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
  1450. _this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
  1451. }
  1452. // 判断是否存在错误数据,并是否打印错误数据
  1453. _this.msgErrData();
  1454. // 保存树副本
  1455. _this.bak = _this.obj.html();
  1456. } else {
  1457. if (!_this.url) {
  1458. //_this.obj.html(_this.getNoneDom().errText("数据请求异常,url参数未指定"));
  1459. layer.msg("数据请求异常,url参数未指定", {icon:5});
  1460. return ;
  1461. }
  1462. $ul.html("");
  1463. var index = _this.load ? layer.load(1) : "";
  1464. AjaxHelper.request({
  1465. async: _this.async,
  1466. headers: _this.headers,
  1467. type: _this.method,
  1468. url: _this.url,
  1469. dataType: _this.dataType,
  1470. withCredentials: _this.withCredentials,
  1471. data: _this.getFilterRequestParam(_this.getRequestParam()),
  1472. success: function(result) {
  1473. if (typeof result === 'string') {
  1474. result = $.parseJSON(result);
  1475. }
  1476. var code = "";
  1477. if (_this.dataStyle == 'layuiStyle'){
  1478. code = result[_this.response.statusName];
  1479. } else {
  1480. code = result.status[_this.response.statusName];
  1481. }
  1482. if (code == _this.response.statusCode) {
  1483. // 解析树
  1484. var pid = _this.node.nodeId;
  1485. var level = parseInt(_this.node.level)+1;
  1486. if (_this.dataFormat == 'list'){
  1487. var pListData = _this.queryListTreeByPid(pid, result[_this.response.rootName]);
  1488. _this.loadListTree(pListData, result[_this.response.rootName], level, $ul);
  1489. } else {
  1490. _this.loadTree(result[_this.response.rootName], level, $ul);
  1491. }
  1492. // 显示树线
  1493. _this.showLine();
  1494. // 这种情况下需要一开始就将toolbar显示在页面上
  1495. if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
  1496. _this.setToolbarDom().setToolbarPlace(_this.toolbarMenu);
  1497. }
  1498. // 判断是否存在错误数据,并是否打印错误数据
  1499. _this.msgErrData();
  1500. $ul.addClass(NAV_SHOW);
  1501. // 保存树副本
  1502. _this.bak = _this.obj.html();
  1503. } else {
  1504. if (_this.dataStyle == 'layuiStyle'){
  1505. _this.obj.html(_this.getNoneDom().errText(result[_this.response.message]));
  1506. _this.error(null, code, result[_this.response.message]);
  1507. //layer.msg(result[_this.response.message], {icon:2});
  1508. } else {
  1509. _this.obj.html(_this.getNoneDom().errText(result.status[_this.response.message]));
  1510. _this.error(null, code, result.status[_this.response.message]);
  1511. //layer.msg(result.status[_this.response.message], {icon:2});
  1512. }
  1513. }
  1514. },
  1515. error: function(XMLHttpRequest, textStatus, errorThrown){// 异步加载异常回调
  1516. _this.obj.html(_this.getNoneDom().errText(textStatus + ": " + errorThrown));
  1517. _this.error(XMLHttpRequest, textStatus, errorThrown);
  1518. },
  1519. complete: function(XMLHttpRequest, textStatus){// 异步加载完成回调
  1520. if(_this.load){layer.close(index);}
  1521. _this.complete(XMLHttpRequest, textStatus);
  1522. }
  1523. });
  1524. }
  1525. };
  1526. // 初始化树或者拼接树
  1527. DTree.prototype.loadListTree = function(pListData, listData, level, $ul){
  1528. var _this = this;
  1529. $ul = $ul || _this.getNodeDom().nowOrRootUl(); //当前选中的节点或根节点
  1530. if (pListData.length > 0){
  1531. for (var i = 0; i < pListData.length; i++) {
  1532. // 1.获取已知节点的全部数据
  1533. var data = pListData[i];
  1534. if(typeof data !== "object") continue;
  1535. var parseData = _this.parseData(data);
  1536. var childListData = _this.queryListTreeByPid(parseData.treeId(), listData); // 根据已知数据的id判断该条数据是否还有子数据
  1537. // 3. 页面元素加载数据
  1538. $ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(childListData.length), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(level), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), ($ul.hasClass(UL_ROOT) ? "root" : "item")));
  1539. // 4.有子数据的元素加载子节点
  1540. if(childListData.length > 0){
  1541. var cLevel = parseInt(level)+1;
  1542. _this.loadListTree(childListData, listData, cLevel, _this.obj.find("ul[data-id='"+parseData.treeId()+"']"));
  1543. }
  1544. }
  1545. }
  1546. };
  1547. // 根据父ID查找list数据中匹配的元素
  1548. DTree.prototype.queryListTreeByPid = function(pid, listData){
  1549. var _this = this;
  1550. var rootListData = [];
  1551. if (listData) {
  1552. for (var i = 0; i < listData.length; i++) {
  1553. var data = listData[i];
  1554. if(typeof data !== "object") continue;
  1555. if(pid == "null" || pid == null){
  1556. if(data[_this.response.parentId] == null) { rootListData.push(data); }
  1557. } else {
  1558. if (data[_this.response.parentId] == pid){
  1559. if (data[_this.response.treeId] == pid){
  1560. _this.errData.push(data);
  1561. } else {
  1562. rootListData.push(data);
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. return rootListData;
  1569. };
  1570. // 初始化树或者拼接树
  1571. DTree.prototype.loadTree = function(root, level, $ul){
  1572. var _this = this;
  1573. if (root) {
  1574. $ul = $ul || _this.getNodeDom().nowOrRootUl(); //当前选中的节点或根节点
  1575. for (var i = 0; i < root.length; i++) { // 遍历跟节点或追加的跟节点
  1576. var data = root[i];
  1577. if(typeof data !== "object") continue;
  1578. if(data[_this.response.treeId] == data[_this.response.parentId]) { _this.errData.push(data); }
  1579. var parseData = _this.parseData(data);
  1580. var children = parseData.children();
  1581. $ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(children.length), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(level), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), ($ul.hasClass(UL_ROOT) ? "root" : "item")));
  1582. if (children.length != 0) {
  1583. var cLevel = parseInt(level)+1;
  1584. _this.loadTree(children, cLevel, _this.obj.find("ul[data-id='"+parseData.treeId()+"']"));
  1585. }
  1586. }
  1587. }
  1588. };
  1589. // 判断在数据加载时是否存在错误数据,并是否打印错误数据
  1590. DTree.prototype.msgErrData = function() {
  1591. var _this = this;
  1592. if(_this.errData.length > 0 && _this.errDataShow) {
  1593. var title = "";
  1594. for(var i=0; i<_this.errData.length; i++) {
  1595. var edata = _this.errData[i];
  1596. title += "数据:【"+edata[_this.response.title]+"】中节点id和上级id值一致! \n";
  1597. }
  1598. layer.msg(title, {icon:2,time:5000});
  1599. }
  1600. // 显示之后,将错误数据制空
  1601. _this.errData = [];
  1602. };
  1603. // 解析data数据
  1604. DTree.prototype.parseData = function(data) {
  1605. var _this = this;
  1606. return {
  1607. treeId: function(){
  1608. return data[_this.response.treeId];
  1609. },
  1610. parentId: function(){
  1611. return data[_this.response.parentId];
  1612. },
  1613. fmtTitle: function(){
  1614. if(typeof _this.formatter.title === 'function'){
  1615. var ftitle = _this.formatter.title(data);
  1616. var tt = data[_this.response.title];
  1617. tt = (ftitle == "" || ftitle == undefined || ftitle == null) ? tt : ftitle;
  1618. return tt || "";
  1619. }
  1620. return data[_this.response.title];
  1621. },
  1622. title: function(){
  1623. return data[_this.response.title];
  1624. },
  1625. level: function(){
  1626. return data[_this.response.level] || "";
  1627. },
  1628. ficonClass: function(){
  1629. return data[_this.response.ficonClass] || "";
  1630. },
  1631. iconClass: function(){
  1632. return data[_this.response.iconClass] || "";
  1633. },
  1634. last: function(len){
  1635. return ((len == 0) ?
  1636. ((typeof (data[_this.response.last]) === "boolean") ? data[_this.response.last] : true) :
  1637. ((typeof (data[_this.response.last]) === "boolean") ? data[_this.response.last] : false));
  1638. },
  1639. spread: function(level){
  1640. return ((level < _this.initLevel) ?
  1641. ((typeof (data[_this.response.spread]) === "boolean") ? data[_this.response.spread] : true) :
  1642. ((typeof (data[_this.response.spread]) === "boolean") ? data[_this.response.spread] : false));
  1643. },
  1644. disabled: function(){
  1645. return (typeof (data[_this.response.disabled]) === "boolean") ? data[_this.response.disabled] : false;
  1646. },
  1647. hide: function(){
  1648. return (typeof (data[_this.response.hide]) === "boolean") ? data[_this.response.hide] : false;
  1649. },
  1650. checkArr: function(){
  1651. var checkArr = [];
  1652. var checkArrData = data[_this.response.checkArr];
  1653. if(typeof checkArrData === 'string'){
  1654. if(checkArrData.indexOf("{") > -1 && checkArrData.indexOf("}") > -1){
  1655. checkArrData = JSON.parse(checkArrData);
  1656. } else {
  1657. checkArrData = {"type":"0","checked":checkArrData};
  1658. }
  1659. }
  1660. if(typeof checkArrData === 'object'){
  1661. if(typeof checkArrData.length === 'undefined'){
  1662. checkArr.push(checkArrData);
  1663. } else {
  1664. checkArr = checkArrData;
  1665. }
  1666. }
  1667. if(checkArr.length > 0 && checkArr.length > _this.checkArrLen){
  1668. _this.checkArrLen = checkArr.length; // 获取复选框个数
  1669. }
  1670. return checkArr;
  1671. },
  1672. children: function(){
  1673. return data[_this.response.childName] || [];
  1674. },
  1675. basicData: function(){
  1676. return event.escape(JSON.stringify(data[_this.response.basicData])) || JSON.stringify({});
  1677. },
  1678. recordData: function(){
  1679. var recordData = _this.record ? event.cloneObj(data, [_this.response.treeId,
  1680. _this.response.parentId,
  1681. _this.response.title,
  1682. _this.response.iconClass,
  1683. _this.response.childName,
  1684. _this.response.last,
  1685. _this.response.spread,
  1686. _this.response.disabled,
  1687. _this.response.hide,
  1688. _this.response.checkArr,
  1689. _this.response.checked,
  1690. _this.response.type,
  1691. _this.response.basicData]) : {};
  1692. return event.escape(JSON.stringify(recordData));
  1693. },
  1694. data: function(){
  1695. return data;
  1696. }
  1697. }
  1698. };
  1699. //当无节点数据时显示dom
  1700. DTree.prototype.getNoneDom = function(){
  1701. var _this = this,
  1702. rootId = _this.obj[0].id,
  1703. noneTitle = _this.none;
  1704. return {
  1705. text: function(){
  1706. return "<div class='"+NONETITLE+"' dtree-id='"+rootId+"'>"+noneTitle+"</div>";
  1707. },
  1708. errText: function(errInfo){
  1709. return "<div class='"+NONETITLE+"' dtree-id='"+rootId+"'>"+errInfo+"</div>";
  1710. }
  1711. }
  1712. };
  1713. //新增节点的dom值
  1714. DTree.prototype.getDom = function(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide) {
  1715. var _this = this,
  1716. rootId = _this.obj[0].id,
  1717. toolbar = _this.toolbar,
  1718. checkbar = _this.checkbar;
  1719. return {
  1720. fnode: function() { // + - 图标
  1721. // 获取图标的变量
  1722. var fnodeIcon = _this.fnodeIcon,
  1723. fleafIcon = _this.fleafIcon;
  1724. var fleafIconLeaf = _this.usefontStyle.fnode.leaf,
  1725. fnodeIconOpen = _this.usefontStyle.fnode.node.open,
  1726. fnodeIconClose = _this.usefontStyle.fnode.node.close;
  1727. if(ficonClass){
  1728. var iconfont = _this.iconfont;
  1729. if(typeof iconfont === 'string') {
  1730. fleafIconLeaf = iconfont + " " + ficonClass;
  1731. fnodeIconOpen = iconfont + " " + ficonClass;
  1732. fnodeIconClose = iconfont + " " + ficonClass;
  1733. } else {
  1734. fleafIconLeaf = iconfont[0] + " " + ficonClass;
  1735. fnodeIconOpen = iconfont[0] + " " + ficonClass;
  1736. fnodeIconClose = iconfont[0] + " " + ficonClass;
  1737. }
  1738. }
  1739. if(fnodeIcon != "-1" && fleafIcon != "-1"){ // 都加载
  1740. return last ? "<i class='"+fleafIconLeaf+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
  1741. (spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1742. }
  1743. if(fnodeIcon != "-1" && fleafIcon == "-1"){ // 加载node 隐藏leaf
  1744. return last ? "<i class='"+fleafIconLeaf+" "+ICON_HIDE+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
  1745. (spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1746. }
  1747. if(fnodeIcon == "-1" && fleafIcon != "-1"){ // 隐藏node 加载leaf
  1748. return last ? "<i class='"+fleafIconLeaf+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" :
  1749. (spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1750. }
  1751. if(fnodeIcon == "-1" && fleafIcon == "-1"){ // 都隐藏
  1752. return last ? "<i class='"+fleafIconLeaf+" "+ICON_HIDE+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' style='display:none;'></i>" :
  1753. (spread ? "<i class='"+fnodeIconOpen+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"'></i>" : "<i class='"+fnodeIconClose+" "+_this.style.dfont+" "+_this.style.ficon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1754. }
  1755. },
  1756. node: function() { // 二级图标样式
  1757. // 获取图标的变量
  1758. var nodeIcon = _this.nodeIcon,
  1759. leafIcon = _this.leafIcon;
  1760. var sleafIconLeaf = _this.usefontStyle.snode.leaf,
  1761. snodeIconOpen = _this.usefontStyle.snode.node.open,
  1762. snodeIconClose = _this.usefontStyle.snode.node.close;
  1763. if(iconClass){
  1764. var iconfont = _this.iconfont;
  1765. if(typeof iconfont === 'string') {
  1766. sleafIconLeaf = iconfont + " " + iconClass;
  1767. snodeIconOpen = iconfont + " " + iconClass;
  1768. snodeIconClose = iconfont + " " + iconClass;
  1769. } else {
  1770. sleafIconLeaf = iconfont[0] + " " + iconClass;
  1771. snodeIconOpen = iconfont[0] + " " + iconClass;
  1772. snodeIconClose = iconfont[0] + " " + iconClass;
  1773. }
  1774. }
  1775. if(nodeIcon != "-1" && leafIcon != "-1"){ // 都加载
  1776. return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1777. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1778. }
  1779. if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
  1780. return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1781. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1782. }
  1783. if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
  1784. return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1785. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1786. }
  1787. if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
  1788. return last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1789. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1790. }
  1791. },
  1792. checkbox: function() { // 复选框
  1793. var flag = false;
  1794. if(_this.checkbarLoad == "node"){if (checkbar) {flag = true;}} else {if (last) {if (checkbar) {flag = true;}}}
  1795. if(flag){
  1796. var result = "<div class='"+LI_DIV_CHECKBAR+"' data-id='"+treeId+"' dtree-id='"+rootId+"'>";
  1797. if(checkArr && checkArr.length > 0){
  1798. for (var i = 0; i < checkArr.length; i++) {
  1799. var checkData = checkArr[i];
  1800. var checked = checkData.checked;
  1801. var CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
  1802. if (checked == "2") { //半选择
  1803. CHOOSE_CLASS = _this.usefontStyle.checkbox.noall + " " + _this.style.chs;
  1804. } else if (checked == "1") { //选择
  1805. CHOOSE_CLASS = _this.usefontStyle.checkbox.on + " " + _this.style.chs;
  1806. } else { //未选择或者无值
  1807. CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
  1808. }
  1809. var disClass = "";
  1810. if(disabled){disClass = NAV_DIS;}
  1811. result += "<i class='"+CHOOSE_CLASS+" "+_this.style.dfont+" "+_this.style.cbox+" "+disClass+"' data-id='"+treeId+"' dtree-id='"+rootId+"' data-checked='"+checkData.checked+"' data-initchecked='"+checkData.checked+"' data-type='"+checkData.type+"' dtree-click='"+eventName.checkNodeClick+"' data-par='."+LI_CLICK_CHECKBAR+"' dtree-disabled='"+disabled+"'></i>";
  1812. }
  1813. }
  1814. result += "</div>";
  1815. return result;
  1816. }
  1817. return "";
  1818. },
  1819. text: function() { // 文字显示
  1820. var disClass = "";
  1821. if(disabled){disClass = NAV_DIS;}
  1822. return "<cite class='"+LI_DIV_TEXT_CLASS+" "+disClass+"' data-id='"+treeId+"' data-leaf='"+(last ? "leaf" : "node")+"' dtree-disabled='"+disabled+"' data-title='"+title+"' >"+fmtTitle+"</cite>";
  1823. },
  1824. ul: function() { //子节点ul
  1825. return last ? "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" :
  1826. (spread ? "<ul class='"+LI_NAV_CHILD+" "+NAV_SHOW+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" : "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>");
  1827. }
  1828. };
  1829. };
  1830. //替换节点的dom值,或指定值
  1831. DTree.prototype.replaceDom = function($div, treeId, last, spread, disabled, hide) {
  1832. var _this = this,
  1833. rootId = _this.obj[0].id,
  1834. toolbar = _this.toolbar,
  1835. checkbar = _this.checkbar;
  1836. return {
  1837. fnode: function(ficonClass) { // + - 图标
  1838. var fnode = "";
  1839. // 获取图标的变量
  1840. var fnodeIcon = _this.fnodeIcon,
  1841. fleafIcon = _this.fleafIcon;
  1842. var fleafIconLeaf = _this.usefontStyle.fnode.leaf,
  1843. fnodeIconOpen = _this.usefontStyle.fnode.node.open,
  1844. fnodeIconClose = _this.usefontStyle.fnode.node.close;
  1845. if(ficonClass){
  1846. var iconfont = _this.iconfont;
  1847. if(typeof iconfont === 'string') {
  1848. fleafIconLeaf = iconfont + " " + ficonClass;
  1849. fnodeIconOpen = iconfont + " " + ficonClass;
  1850. fnodeIconClose = iconfont + " " + ficonClass;
  1851. } else {
  1852. fleafIconLeaf = iconfont[0] + " " + ficonClass;
  1853. fnodeIconOpen = iconfont[0] + " " + ficonClass;
  1854. fnodeIconClose = iconfont[0] + " " + ficonClass;
  1855. }
  1856. }
  1857. if(fnodeIcon != "-1" && leafIcon != "-1"){ // 都加载
  1858. fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1859. (spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1860. }else if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
  1861. fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1862. (spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1863. }else if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
  1864. fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1865. (spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1866. }else if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
  1867. fnode = last ? "<i class='"+fleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1868. (spread ? "<i class='"+fnodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+fnodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+ficonClass+"'></i>");
  1869. }
  1870. if(fnode != ""){_this.getNodeDom($div).fnode().replaceWith($(fnode));}
  1871. },
  1872. node: function(iconClass) { // 二级图标样式
  1873. var snode = "";
  1874. // 获取图标的变量
  1875. var nodeIcon = _this.nodeIcon,
  1876. leafIcon = _this.leafIcon;
  1877. var sleafIconLeaf = _this.usefontStyle.snode.leaf,
  1878. snodeIconOpen = _this.usefontStyle.snode.node.open,
  1879. snodeIconClose = _this.usefontStyle.snode.node.close;
  1880. if(iconClass){
  1881. var iconfont = _this.iconfont;
  1882. if(typeof iconfont === 'string') {
  1883. sleafIconLeaf = iconfont + " " + iconClass;
  1884. snodeIconOpen = iconfont + " " + iconClass;
  1885. snodeIconClose = iconfont + " " + iconClass;
  1886. } else {
  1887. sleafIconLeaf = iconfont[0] + " " + iconClass;
  1888. snodeIconOpen = iconfont[0] + " " + iconClass;
  1889. snodeIconClose = iconfont[0] + " " + iconClass;
  1890. }
  1891. }
  1892. if(nodeIcon != "-1" && leafIcon != "-1"){ // 都加载
  1893. snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1894. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1895. }else if(nodeIcon != "-1" && leafIcon == "-1"){ // 加载node 隐藏leaf
  1896. snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1897. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1898. }else if(nodeIcon == "-1" && leafIcon != "-1"){ // 隐藏node 加载leaf
  1899. snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1900. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1901. }else if(nodeIcon == "-1" && leafIcon == "-1"){ // 都隐藏
  1902. snode = last ? "<i class='"+sleafIconLeaf+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='last' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" :
  1903. (spread ? "<i class='"+snodeIconOpen+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='open' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>" : "<i class='"+snodeIconClose+" "+DTREEFONTSPECIAL+" "+_this.style.dfont+" "+_this.style.icon+"' data-spread='close' data-id='"+treeId+"' dtree-id='"+rootId+"' data-iconClass='"+iconClass+"'></i>");
  1904. }
  1905. if(snode != ""){_this.getNodeDom($div).snode().replaceWith($(snode));}
  1906. },
  1907. checkbox: function(checkArr) { // 复选框
  1908. var flag = false;
  1909. if(_this.checkbarLoad == "node"){if (checkbar) {flag = true;}} else {if (last) {if (checkbar) {flag = true;}}}
  1910. if(flag){
  1911. var result = "<div class='"+LI_DIV_CHECKBAR+"' data-id='"+treeId+"' dtree-id='"+rootId+"'>";
  1912. if(checkArr && checkArr.length > 0){
  1913. for (var i = 0; i < checkArr.length; i++) {
  1914. var checkData = checkArr[i];
  1915. var checked = checkData.checked;
  1916. var CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
  1917. if (checked == "2") { //半选择
  1918. CHOOSE_CLASS = _this.usefontStyle.checkbox.noall + " " + _this.style.chs;
  1919. } else if (checked == "1") { //选择
  1920. CHOOSE_CLASS = _this.usefontStyle.checkbox.on + " " + _this.style.chs;
  1921. } else { //未选择或者无值
  1922. CHOOSE_CLASS = _this.usefontStyle.checkbox.out;
  1923. }
  1924. var disClass = "";
  1925. if(disabled){disClass = NAV_DIS;}
  1926. result += "<i class='"+CHOOSE_CLASS+" "+_this.style.dfont+" "+_this.style.cbox+" "+disClass+"' data-id='"+treeId+"' dtree-id='"+rootId+"' data-checked='"+checkData.checked+"' data-initchecked='"+checkData.checked+"' data-type='"+checkData.type+"' dtree-click='"+eventName.checkNodeClick+"' data-par='."+LI_CLICK_CHECKBAR+"' dtree-disabled='"+disabled+"'></i>";
  1927. }
  1928. }
  1929. result += "</div>";
  1930. _this.getNodeDom($div).snode().next("div").replaceWith($(result));
  1931. }
  1932. },
  1933. text: function(title) { // 文字显示
  1934. var disClass = "";
  1935. if(disabled){disClass = NAV_DIS;}
  1936. var cite = "<cite class='"+LI_DIV_TEXT_CLASS+" "+disClass+"' data-id='"+treeId+"' data-leaf='"+(last ? "leaf" : "node")+"' dtree-disabled='"+disabled+"' >"+title+"</cite>"
  1937. _this.getNodeDom($div).cite().replaceWith($(cite));
  1938. },
  1939. ul: function() { //子节点ul
  1940. var ul = last ? "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" :
  1941. (spread ? "<ul class='"+LI_NAV_CHILD+" "+NAV_SHOW+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>" : "<ul class='"+LI_NAV_CHILD+"' data-id='"+treeId+"' dtree-id='"+rootId+"'></ul>");
  1942. _this.getNodeDom($div).nextUl().replaceWith($(ul));
  1943. },
  1944. div: function(){
  1945. $div.attr("data-id", treeId);
  1946. },
  1947. basicData: function(basicData){
  1948. basicData = (basicData == "{}") ? "" : basicData;
  1949. $div.attr("data-basic", basicData);
  1950. },
  1951. recordData: function(recordData){
  1952. recordData = (recordData == "{}") ? "" : recordData;
  1953. $div.attr("data-record", recordData);
  1954. },
  1955. p_li: function(pId){
  1956. var $li = $div.parent("li");
  1957. $li.attr("data-id", treeId);
  1958. if(pId) {
  1959. $li.attr("data-pid", pId);
  1960. }
  1961. return $li;
  1962. }
  1963. };
  1964. };
  1965. // 获取拼接好的li
  1966. DTree.prototype.getLiItemDom = function(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide, basicData, recordData, flag) {
  1967. var _this = this,
  1968. rootId = _this.obj[0].id;
  1969. var dom = _this.getDom(treeId, parentId, title, fmtTitle, last, ficonClass, iconClass, checkArr, level, spread, disabled, hide);
  1970. basicData = (basicData == "{}") ? "" : basicData;
  1971. recordData = (recordData == "{}") ? "" : recordData;
  1972. var div = "<div class='"+LI_DIV_ITEM+" "+_this.style.item+"' data-id='"+treeId+"' dtree-id='"+rootId+"' dtree-click='"+eventName.itemNodeClick+"' data-basic='"+basicData+"' data-record='"+recordData+"' dtree-disabled='"+disabled+"' dtree-hide='"+hide+"' ";
  1973. if(_this.toolbar){
  1974. if(_this.toolbarWay == "contextmenu") {
  1975. if(_this.toolbarLoad == "node") { div += " d-contextmenu='true'>"; }
  1976. if(_this.toolbarLoad == "noleaf") { if(!last){ div += " d-contextmenu='true'>"; } else { div += " d-contextmenu='false'>";} }
  1977. if(_this.toolbarLoad == "leaf") { if(last){ div += " d-contextmenu='true'>"; } else { div += " d-contextmenu='false'>";} }
  1978. } else { div += " d-contextmenu='false'>"; }
  1979. } else { div += " d-contextmenu='false'>"; }
  1980. var hideClass = "";
  1981. var lineClass = "";
  1982. if(hide){hideClass = NAV_HIDE;}
  1983. var li = ["<li " + "class='"+LI_CLICK_CHECKBAR+" "+LI_NAV_ITEM+" "+hideClass+" "+lineClass+"'" + "data-id='"+treeId+"'" + "data-pid='"+(flag == "root" ? ((typeof parentId !== undefined && parentId != "") ? parentId : "-1") : parentId)+"'" + "dtree-id='"+rootId+"'" + "data-index='"+level+"'" + "dtree-hide='"+hide+"'" +">" +
  1984. div ,
  1985. dom.fnode(),
  1986. dom.node(),
  1987. dom.checkbox(),
  1988. dom.text(),
  1989. "</div>", dom.ul(), "</li>"].join("");
  1990. return li;
  1991. };
  1992. // 初始化节点,用于数据回显
  1993. DTree.prototype.dataInit = function(chooseId){
  1994. var _this = this;
  1995. var $div = _this.obj.find("div[data-id='"+chooseId+"']");
  1996. _this.getNodeDom($div).parentLi().find("."+NAV_THIS).removeClass(NAV_THIS);
  1997. _this.getNodeDom($div).parentLi().find("."+_this.style.itemThis).removeClass(_this.style.itemThis);
  1998. $div.addClass(NAV_THIS);
  1999. $div.addClass(_this.style.itemThis);
  2000. _this.setNodeParam($div);
  2001. // 将该节点的父节点全部展开
  2002. var $li_parents = $div.parents("."+LI_NAV_ITEM);
  2003. $li_parents.children("ul").addClass(NAV_SHOW);
  2004. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).addClass(_this.usefontStyle.fnode.node.open);
  2005. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).removeClass(_this.usefontStyle.fnode.node.close);
  2006. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).addClass(_this.usefontStyle.snode.node.open);
  2007. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).removeClass(_this.usefontStyle.snode.node.close);
  2008. return _this.getNowParam();
  2009. };
  2010. // 基于备份的Html数据回滚
  2011. DTree.prototype.rollbackHtml = function(chooseId){
  2012. var _this = this;
  2013. if(_this.bak) {
  2014. _this.obj.html(_this.bak);
  2015. // 取消全部选中状态
  2016. _this.cancelNavThis();
  2017. if(_this.checkbar) {
  2018. _this.cancelCheckedNode();
  2019. _this.chooseDataInit(chooseId);
  2020. } else {
  2021. _this.dataInit(chooseId);
  2022. }
  2023. _this.bak = _this.obj.html();
  2024. }
  2025. };
  2026. /******************** 基础事件区域 ********************/
  2027. // 数据格式化
  2028. DTree.prototype.escape = function(html){
  2029. return event.escape(html);
  2030. };
  2031. // 格式化数据转回正常数据
  2032. DTree.prototype.unescape = function(str){
  2033. return event.unescape(str);
  2034. };
  2035. // 取消选中div
  2036. DTree.prototype.cancelNavThis = function(){
  2037. var _this = this;
  2038. _this.obj.find("div[data-id]").parent().find("."+NAV_THIS).removeClass(NAV_THIS);
  2039. _this.obj.find("div[data-id]").parent().find("."+_this.style.itemThis).removeClass(_this.style.itemThis);
  2040. }
  2041. // 选中div
  2042. DTree.prototype.navThis = function(id){
  2043. var _this = this;
  2044. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  2045. if($div != null) {
  2046. _this.cancelNavThis();
  2047. $div.addClass(NAV_THIS);
  2048. $div.addClass(_this.style.itemThis);
  2049. }
  2050. }
  2051. // 手风琴模式操作其他节点
  2052. DTree.prototype.accordionUL = function($ul) {
  2053. var _this = this;
  2054. if(_this.accordion) {
  2055. $ul.closest("li[data-index]").siblings("li[data-index]").children("ul[data-id]").removeClass(NAV_SHOW);
  2056. var $divs = $ul.closest("li[data-index]").siblings("li[data-index]").children("ul[data-id]").prev("div");
  2057. if($divs.length && $divs.length > 0) {
  2058. for (var i=0; i<$divs.length; i++) {
  2059. var $div = $($divs[i]);
  2060. var $i_spread = _this.getNodeDom($div).fnode(),
  2061. $i_node = _this.getNodeDom($div).snode();
  2062. if($i_spread.attr("data-spread") != 'last'){
  2063. _this.operateIcon($i_spread, $i_node).close();
  2064. }
  2065. }
  2066. }
  2067. }
  2068. };
  2069. // 展开或隐藏节点 作用点: div
  2070. DTree.prototype.clickSpread = function($div) {
  2071. var _this = this;
  2072. var $i_spread = _this.getNodeDom($div).fnode(),
  2073. $i_node = _this.getNodeDom($div).snode(),
  2074. $cite = _this.getNodeDom($div).cite(),
  2075. spread = $i_spread.attr("data-spread"),
  2076. $ul = $div.next("ul");
  2077. if ($ul.length > 0) {
  2078. if (spread == "close") {
  2079. if (_this.type=="load") { //增加加载
  2080. if (_this.cache) { //开启缓存
  2081. if ($ul.html()) {
  2082. $ul.addClass(NAV_SHOW);
  2083. _this.accordionUL($ul);
  2084. } else { //加载节点
  2085. _this.getChild($div);
  2086. _this.accordionUL($ul);
  2087. }
  2088. }else { //每次取新的数据
  2089. $ul.html("");
  2090. _this.getChild($div);
  2091. _this.accordionUL($ul);
  2092. }
  2093. } else { // 全量加载
  2094. $ul.addClass(NAV_SHOW);
  2095. _this.accordionUL($ul);
  2096. }
  2097. _this.operateIcon($i_spread, $i_node).open();
  2098. } else if (spread == "open") {
  2099. $ul.removeClass(NAV_SHOW);
  2100. _this.operateIcon($i_spread, $i_node).close();
  2101. }
  2102. }
  2103. };
  2104. // 设置节点为disabled
  2105. DTree.prototype.setDisabledNodes = function(disabledIds){
  2106. var _this = this;
  2107. var disabledId = disabledIds.split(",");
  2108. for (var i=0; i<disabledId.length; i++) {
  2109. var $div = _this.getNodeDom(disabledId[i]).div();
  2110. var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
  2111. var $cite = $div.children("cite[data-leaf]");
  2112. if($div != null && $div.attr("dtree-disabled") != "true") {
  2113. $div.attr("dtree-disabled", "true");
  2114. $i.attr("dtree-disabled", "true");
  2115. $i.addClass(NAV_DIS);
  2116. $cite.attr("dtree-disabled", "true");
  2117. $cite.addClass(NAV_DIS);
  2118. }
  2119. }
  2120. };
  2121. // 设置全部节点为disabled
  2122. DTree.prototype.setDisabledAllNodes = function(){
  2123. var _this = this;
  2124. _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"']").each(function(){
  2125. var $div = $(this);
  2126. var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
  2127. var $cite = $div.children("cite[data-leaf]");
  2128. if($div != null && $div.attr("dtree-disabled") != "true") {
  2129. $div.attr("dtree-disabled", "true");
  2130. $i.attr("dtree-disabled", "true");
  2131. $i.addClass(NAV_DIS);
  2132. $cite.attr("dtree-disabled", "true");
  2133. $cite.addClass(NAV_DIS);
  2134. }
  2135. });
  2136. };
  2137. // 将节点的disabled取消
  2138. DTree.prototype.cancelDisabledNodes = function(disabledIds){
  2139. var _this = this;
  2140. var disabledId = disabledIds.split(",");
  2141. for (var i=0; i<disabledId.length; i++) {
  2142. var $div = _this.getNodeDom(disabledId[i]).div();
  2143. var $i = $div.children("div."+LI_DIV_CHECKBAR).children("i[data-par]");
  2144. var $cite = $div.children("cite[data-leaf]");
  2145. if($div != null && $div.attr("dtree-disabled") == "true") {
  2146. $div.attr("dtree-disabled", "false");
  2147. $i.attr("dtree-disabled", "false");
  2148. $i.removeClass(NAV_DIS);
  2149. $cite.attr("dtree-disabled", "false");
  2150. $cite.removeClass(NAV_DIS);
  2151. }
  2152. }
  2153. };
  2154. // 获取指定disabled节点的值
  2155. DTree.prototype.getDisabledNodesParam = function(disabledIds){
  2156. var _this = this;
  2157. var disabledId = disabledIds.split(",");
  2158. var disabledNodes = [];
  2159. for (var i=0; i<disabledId.length; i++) {
  2160. var $div = _this.getNodeDom(disabledId[i]).div();
  2161. if($div != null && $div.attr("dtree-disabled") == "true") {
  2162. disabledNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
  2163. }
  2164. }
  2165. return disabledNodes;
  2166. };
  2167. // 获取全部disabled节点的值
  2168. DTree.prototype.getAllDisabledNodesParam = function(){
  2169. var _this = this;
  2170. var disabledNodes = [];
  2171. _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][dtree-disabled='true']").each(function(){
  2172. var $div = $(this);
  2173. disabledNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
  2174. });
  2175. return disabledNodes;
  2176. };
  2177. // 设置节点为hide
  2178. DTree.prototype.setHideNodes = function(hideIds){
  2179. var _this = this;
  2180. var hideId = hideIds.split(",");
  2181. for (var i=0; i<hideId.length; i++) {
  2182. var $div = _this.getNodeDom(hideId[i]).div();
  2183. var $li = $div.parent("li[dtree-hide]");
  2184. if($div != null && $div.attr("dtree-hide") != "true") {
  2185. $div.attr("dtree-hide", "true");
  2186. $li.attr("dtree-hide", "true");
  2187. $li.addClass(NAV_HIDE);
  2188. }
  2189. }
  2190. };
  2191. // 将节点的hide取消
  2192. DTree.prototype.cancelHideNodes = function(hideIds){
  2193. var _this = this;
  2194. var hideId = hideIds.split(",");
  2195. for (var i=0; i<hideId.length; i++) {
  2196. var $div = _this.getNodeDom(hideId[i]).div();
  2197. var $li = $div.parent("li[dtree-hide]");
  2198. if($div != null && $div.attr("dtree-hide") == "true") {
  2199. $div.attr("dtree-hide", "false");
  2200. $li.attr("dtree-hide", "false");
  2201. $li.removeClass(NAV_HIDE);
  2202. }
  2203. }
  2204. };
  2205. // 获取指定hide节点的值
  2206. DTree.prototype.getHideNodesParam = function(hideIds){
  2207. var _this = this;
  2208. var hideId = hideIds.split(",");
  2209. var hideNodes = [];
  2210. for (var i=0; i<hideId.length; i++) {
  2211. var $div = _this.getNodeDom(hideId[i]).div();
  2212. if($div != null && $div.attr("dtree-hide") == "true") {
  2213. hideNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
  2214. }
  2215. }
  2216. return hideNodes;
  2217. };
  2218. // 获取全部hide节点的值
  2219. DTree.prototype.getAllHideNodesParam = function(){
  2220. var _this = this;
  2221. var hideNodes = [];
  2222. _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][dtree-hide='true']").each(function(){
  2223. var $div = $(this);
  2224. hideNodes.push(_this.getRequestParam(_this.getTempNodeParam($div)));
  2225. });
  2226. return hideNodes;
  2227. };
  2228. // 刷新树
  2229. DTree.prototype.refreshTree = function(){
  2230. var _this = this;
  2231. _this.obj.html(""); // 清空树结构
  2232. _this.initNodeParam(); // 清空参数
  2233. _this.init(); //执行初始化方法
  2234. }
  2235. // 局部刷新树--新增子节点时
  2236. DTree.prototype.partialRefreshAdd = function($div, data){
  2237. var _this = this;
  2238. $ul = $div.next("ul");
  2239. // 判断当前点击的节点是否是最后一级节点,如果是,则需要修改节点的样式
  2240. var $icon_i = $div.find("i[data-spread]");
  2241. if ($icon_i.eq(0).attr("data-spread") == "last") {
  2242. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).openWithLeaf();
  2243. } else { //如果不是,也要修改节点样式
  2244. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).open();
  2245. }
  2246. $ul.addClass(NAV_SHOW); //展开UL
  2247. _this.accordionUL($ul);
  2248. if(data) {
  2249. if(data.length && data.length > 0) {
  2250. _this.getChild($div, data);
  2251. } else {
  2252. var parseData = _this.parseData(data);
  2253. if(parseData.treeId()){
  2254. var level = parseInt($div.parent("li").attr("data-index"))+1;
  2255. $ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(0), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), "item"));
  2256. // 建造完毕后,选中该DIV
  2257. $thisDiv = $ul.find("div[data-id='"+parseData.treeId()+"']");
  2258. _this.setNodeParam($thisDiv);
  2259. _this.showLine($ul.find("li"));
  2260. } else {
  2261. layer.msg("添加失败,节点ID为undefined!",{icon:5});
  2262. // 重新赋值
  2263. _this.setNodeParam($div);
  2264. }
  2265. }
  2266. } else {
  2267. _this.getChild($div);
  2268. }
  2269. }
  2270. // 局部刷新树--编辑当前节点选中节点时
  2271. DTree.prototype.partialRefreshEdit = function($div, data){
  2272. var _this = this;
  2273. $ul = $div.next("ul"),
  2274. $p_li = $div.parent("li");
  2275. if(data) {
  2276. if(typeof data === 'object') {
  2277. var parseData = _this.parseData(data);
  2278. if(parseData.treeId()){
  2279. var replaceDom = _this.replaceDom($div, parseData.treeId(), parseData.last(0), parseData.spread(), parseData.disabled(), parseData.hide());
  2280. replaceDom.div();
  2281. replaceDom.node(parseData.iconClass());
  2282. replaceDom.checkbox(parseData.checkArr());
  2283. replaceDom.text(parseData.title());
  2284. replaceDom.ul();
  2285. replaceDom.basicData(parseData.basicData());
  2286. replaceDom.recordData(parseData.recordData());
  2287. var parentId = parseData.parentId();
  2288. var oldParentId = $p_li.attr("data-pid");
  2289. if(parentId && parentId != oldParentId) {
  2290. // 变更了父节点
  2291. $p_li = replaceDom.p_li(parentId);
  2292. // 根据parentId找到下挂节点的ul
  2293. var $goto_div = _this.getNodeDom(parentId).div(),
  2294. $goto_ul = _this.getNodeDom(parentId).nextUl();
  2295. // 判断父级ul中是否还存在li,如果不存在,则需要修改节点的样式
  2296. if($goto_ul.children("li").length == 0){
  2297. var $icon_i = $goto_div.find("i[data-spread]");
  2298. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).openWithLeaf();
  2299. $goto_ul.addClass(NAV_SHOW);
  2300. }
  2301. $goto_ul.append($p_li);
  2302. } else {
  2303. replaceDom.p_li();
  2304. }
  2305. _this.setNodeParam($div);
  2306. } else {
  2307. layer.msg("编辑失败,节点ID为undefined!",{icon:5});
  2308. // 重新赋值
  2309. _this.setNodeParam($div);
  2310. }
  2311. } else {
  2312. _this.getNodeDom($div).cite().html(data);
  2313. }
  2314. }
  2315. }
  2316. // 局部刷新树--当前节点选中被删除时
  2317. DTree.prototype.partialRefreshDel = function($div){
  2318. var _this = this;
  2319. $p_li = $div.parent("li");
  2320. $p_ul = _this.getNodeDom($div).parentUl();
  2321. $p_div = _this.getNodeDom($div).parentDiv();
  2322. $p_li.remove();
  2323. _this.showLine($p_ul.find("li"));
  2324. // 判断父级ul中是否还存在li,如果不存在,则需要修改节点的样式
  2325. if($p_ul.children("li").length == 0){
  2326. var $icon_i = $p_div.find("i[data-spread]");
  2327. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).closeWithLeaf();
  2328. }
  2329. _this.initNodeParam();
  2330. }
  2331. /******************** 复选框区域 ********************/
  2332. // 初始化复选框的值
  2333. DTree.prototype.chooseDataInit = function(chooseIds){
  2334. var _this = this;
  2335. var chooseId = chooseIds.split(",");
  2336. for (var i=0; i<chooseId.length; i++) {
  2337. _this.obj.find("i[dtree-click='"+eventName.checkNodeClick+"']").each(function(){
  2338. if ($(this).attr("data-id") == chooseId[i]) {
  2339. _this.checkStatus($(this)).check();
  2340. }
  2341. });
  2342. }
  2343. // 展开选中节点的父节点
  2344. var $li_parents = _this.obj.find("i[dtree-click='"+eventName.checkNodeClick+"'][data-checked='1']").parents("."+LI_NAV_ITEM);
  2345. $li_parents.children("ul").addClass(NAV_SHOW);
  2346. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).addClass(_this.usefontStyle.fnode.node.open);
  2347. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.fnode.node.close)).removeClass(_this.usefontStyle.fnode.node.close);
  2348. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).addClass(_this.usefontStyle.snode.node.open);
  2349. $li_parents.children("."+LI_DIV_ITEM).children("i[data-spread]."+event.trimToDot(_this.usefontStyle.snode.node.close)).removeClass(_this.usefontStyle.snode.node.close);
  2350. return _this.getCheckbarNodesParam();
  2351. };
  2352. //实现复选框点击,子集选中父级也选中
  2353. DTree.prototype.checkAllOrNot = function($i) {
  2354. var _this = this;
  2355. //$i 当前点击的checkbox
  2356. var dataPar = $i.attr("data-par"),
  2357. dataType = $i.attr("data-type"),
  2358. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2359. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2360. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2361. if ($i.attr("data-checked") == "1") {
  2362. // 处理当前节点的选中状态
  2363. _this.checkStatus($i).noCheck();
  2364. // 处理子级节点的选中状态
  2365. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2366. _this.checkStatus($child_li_i).noCheck();
  2367. // 处理父级节点的选中状态
  2368. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2369. var flag = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"'][data-checked='1']").length;
  2370. if (flag == 0) {
  2371. //把父级去掉选中
  2372. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2373. _this.checkStatus($item_i).noCheck();
  2374. }
  2375. }
  2376. } else {
  2377. // 处理当前节点的选中状态
  2378. _this.checkStatus($i).check();
  2379. // 处理子级节点的选中状态
  2380. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2381. _this.checkStatus($child_li_i).check();
  2382. // 处理父级节点的选中状态
  2383. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2384. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2385. //把父级选中
  2386. _this.checkStatus($item_i).check();
  2387. }
  2388. }
  2389. };
  2390. //实现复选框点击, no-all 子集选中父级半选中,子集全选父级选中
  2391. DTree.prototype.checkAllOrNoallOrNot = function($i) {
  2392. var _this = this;
  2393. //$i 当前点击的checkbox
  2394. var $div = $i.closest("."+LI_DIV_ITEM),
  2395. dataPar = $i.attr("data-par"),
  2396. dataType = $i.attr("data-type"),
  2397. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2398. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2399. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2400. if ($i.attr("data-checked") == "1") { //当前复选框为选中状态,点击后变为未选中状态
  2401. // 处理当前节点的选中状态
  2402. _this.checkStatus($i).noCheck();
  2403. // 处理子级节点的选中状态
  2404. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2405. _this.checkStatus($child_li_i).noCheck();
  2406. // 处理父级节点的选中状态
  2407. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2408. var flag = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"'][data-checked='1']").length;
  2409. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2410. if (flag == 0) {
  2411. //把父级去掉选中
  2412. _this.checkStatus($item_i).noCheck();
  2413. } else {
  2414. //把父级半选
  2415. _this.checkStatus($item_i).noallCheck();
  2416. }
  2417. }
  2418. } else { //当前复选框为未选中状态,点击后变为选中状态
  2419. // 处理当前节点的选中状态
  2420. _this.checkStatus($i).check();
  2421. // 处理子级节点的选中状态
  2422. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2423. _this.checkStatus($child_li_i).check();
  2424. // 处理父级节点的选中状态
  2425. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2426. var flag1 = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"'][data-checked='1']").length;
  2427. var flag2 = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']").length;
  2428. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2429. if (flag1 != flag2) {
  2430. // 父级复选框半选
  2431. _this.checkStatus($item_i).noallCheck();
  2432. } else {
  2433. // 父级复选框全选
  2434. _this.checkStatus($item_i).check();
  2435. }
  2436. }
  2437. }
  2438. };
  2439. //实现复选框点击,p-casc:父级选中子集全选,子集无法改变父级选中状态
  2440. DTree.prototype.checkAllOrPcascOrNot = function($i) {
  2441. var _this = this;
  2442. //$i 当前点击的checkbox
  2443. var $div = $i.closest("."+LI_DIV_ITEM),
  2444. dataPar = $i.attr("data-par"),
  2445. dataType = $i.attr("data-type"),
  2446. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2447. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2448. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2449. if ($i.attr("data-checked") == "1") { //当前复选框为选中状态,点击后变为未选中状态
  2450. // 处理当前节点的选中状态
  2451. _this.checkStatus($i).noCheck();
  2452. // 处理子级节点的选中状态
  2453. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2454. _this.checkStatus($child_li_i).noCheck();
  2455. } else { //当前复选框为未选中状态,点击后变为选中状态
  2456. // 处理当前节点的选中状态
  2457. _this.checkStatus($i).check();
  2458. // 处理子级节点的选中状态
  2459. var $child_li_i = $child_li.find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2460. _this.checkStatus($child_li_i).check();
  2461. }
  2462. };
  2463. //实现复选框点击,self:各自选中互不影响
  2464. DTree.prototype.checkOrNot = function($i) {
  2465. var _this = this;
  2466. //$i 当前点击的checkbox
  2467. var $div = $i.closest("."+LI_DIV_ITEM),
  2468. dataPar = $i.attr("data-par"),
  2469. dataType = $i.attr("data-type"),
  2470. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2471. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2472. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2473. if ($i.attr("data-checked") == "1") { //当前复选框为选中状态,点击后变为未选中状态
  2474. // 处理当前节点的选中状态
  2475. _this.checkStatus($i).noCheck();
  2476. } else { //当前复选框为未选中状态,点击后变为选中状态
  2477. // 处理当前节点的选中状态
  2478. _this.checkStatus($i).check();
  2479. }
  2480. };
  2481. //实现复选框点击,only:只能选中1个复选框
  2482. DTree.prototype.checkOnly = function($i) {
  2483. var _this = this;
  2484. //$i 当前点击的checkbox
  2485. var $div = $i.closest("."+LI_DIV_ITEM),
  2486. dataPar = $i.attr("data-par"),
  2487. dataType = $i.attr("data-type"),
  2488. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2489. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2490. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2491. var checked = $i.attr("data-checked");
  2492. // 将全部节点全部设为未选中状态
  2493. var $all_i = _this.obj.find("i[data-checked]");
  2494. _this.checkStatus($all_i).noCheck();
  2495. if (checked != "1") { //当前复选框为未选中状态,点击后变为选中状态
  2496. // 处理当前节点的选中状态
  2497. _this.checkStatus($i).check();
  2498. }
  2499. };
  2500. //实现复选框点击
  2501. DTree.prototype.changeCheck = function($i) {
  2502. var _this = this;
  2503. var temp = _this.temp;
  2504. if(typeof $i === 'undefined') {
  2505. $i = temp[0];
  2506. }
  2507. // 复选框选中事件
  2508. if (_this.checkbarType == "all") {
  2509. _this.checkAllOrNot($i);
  2510. } else if(_this.checkbarType == "no-all") {
  2511. _this.checkAllOrNoallOrNot($i);
  2512. } else if(_this.checkbarType == "p-casc") {
  2513. _this.checkAllOrPcascOrNot($i);
  2514. } else if(_this.checkbarType == "self") {
  2515. _this.checkOrNot($i);
  2516. } else if(_this.checkbarType == "only") {
  2517. _this.checkOnly($i);
  2518. } else {
  2519. _this.checkAllOrNot($i);
  2520. }
  2521. if(_this.select) {
  2522. // 设置复选框模式中的下拉树的值
  2523. _this.selectCheckboxVal();
  2524. }
  2525. // 获取复选框选中节点的内容
  2526. var checkbarNodes = _this.setAndGetCheckbarNodesParam(true);
  2527. // 用户自定义想做的事情
  2528. _this.checkbarFun.chooseDone(checkbarNodes);
  2529. layui.event.call(this, MOD_NAME, "chooseDone("+$(_this.obj)[0].id+")", {"checkbarParams": checkbarNodes});
  2530. _this.temp = [];
  2531. };
  2532. //复选框半选状态初始化设置
  2533. DTree.prototype.initNoAllCheck = function(){
  2534. var _this = this;
  2535. //1.获取所有选中节点
  2536. var $is = _this.obj.find("i[data-checked='1']");
  2537. if($is.length > 0){
  2538. for ( var key = 0; key < $is.length; key++) {
  2539. var $i = $($is[key]),
  2540. dataPar = $i.attr("data-par"),
  2541. dataType = $i.attr("data-type"),
  2542. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2543. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2544. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2545. // 处理父级节点的选中状态
  2546. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2547. var flag1 = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"'][data-checked='1']").length;
  2548. var flag2 = item.eq(i).find(">."+LI_NAV_CHILD+" ."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']").length;
  2549. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2550. if (flag1 != flag2) {
  2551. // 父级复选框半选
  2552. _this.checkStatus($item_i).noallCheck();
  2553. } else {
  2554. // 父级复选框全选
  2555. _this.checkStatus($item_i).check();
  2556. }
  2557. }
  2558. }
  2559. }
  2560. };
  2561. //复选框选中状态初始化设置
  2562. DTree.prototype.initAllCheck = function(){
  2563. var _this = this;
  2564. //1.获取所有选中节点
  2565. var $is = _this.obj.find("i[data-checked='1']");
  2566. if($is.length > 0){
  2567. for ( var key = 0; key < $is.length; key++) {
  2568. var $i = $($is[key]),
  2569. dataPar = $i.attr("data-par"),
  2570. dataType = $i.attr("data-type"),
  2571. $li = $i.closest(dataPar), //当前checkbox的上级li节点
  2572. $parent_li = $i.parents(dataPar), //当前checkbox的所有父级li节点
  2573. $child_li = $li.find(dataPar); //当前checkbox的上级li节点下的所有子级li节点
  2574. // 处理父级节点的选中状态
  2575. for (var i = 1, item = $parent_li; i < item.length; i++) {
  2576. var $item_i = item.eq(i).find(">."+LI_DIV_ITEM+">."+LI_DIV_CHECKBAR+">i[data-type='"+dataType+"']");
  2577. // 父级复选框全选
  2578. _this.checkStatus($item_i).check();
  2579. }
  2580. }
  2581. }
  2582. };
  2583. // 设置复选框选中/未选中/半选 _this.checkStatus($i).check(); _this.checkStatus($i).noCheck(); _this.checkStatus($i).noallCheck();
  2584. DTree.prototype.checkStatus = function($i) {
  2585. var _this = this;
  2586. return {
  2587. check: function(){
  2588. $i.removeClass(_this.usefontStyle.checkbox.out);
  2589. $i.removeClass(_this.usefontStyle.checkbox.noall);
  2590. $i.addClass(_this.usefontStyle.checkbox.on);
  2591. $i.addClass(_this.style.chs);
  2592. $i.attr("data-checked","1");
  2593. },
  2594. noCheck: function(){
  2595. $i.removeClass(_this.usefontStyle.checkbox.noall);
  2596. $i.removeClass(_this.usefontStyle.checkbox.on);
  2597. $i.removeClass(_this.style.chs);
  2598. $i.addClass(_this.usefontStyle.checkbox.out);
  2599. $i.attr("data-checked","0");
  2600. },
  2601. noallCheck: function(){
  2602. $i.removeClass(_this.usefontStyle.checkbox.out);
  2603. $i.removeClass(_this.usefontStyle.checkbox.on);
  2604. $i.addClass(_this.usefontStyle.checkbox.noall);
  2605. $i.addClass(_this.style.chs);
  2606. $i.attr("data-checked","2");
  2607. }
  2608. }
  2609. };
  2610. // 设置树的复选框操作值的全部参数,并获取
  2611. DTree.prototype.setAndGetCheckbarNodesParam = function(requestParamFlag) {
  2612. var _this = this;
  2613. //操作前先清空
  2614. _this.checkbarNode = [];
  2615. // 选择所有复选框节点
  2616. if (_this.checkbarData == "change"){ //记录变更数据
  2617. _this.obj.find("i[data-par][dtree-disabled='false']").each(function(){
  2618. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2619. if ($i.attr("data-checked") != $i.attr("data-initchecked")) {
  2620. if(requestParamFlag) {
  2621. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2622. } else {
  2623. _this.checkbarNode.push(_this.getCheckbarNodeParam($div, $i));
  2624. }
  2625. }
  2626. });
  2627. } else if (_this.checkbarData == "all"){ //记录全部数据
  2628. _this.obj.find("i[data-par][data-checked][dtree-disabled='false']").each(function(){
  2629. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2630. if(requestParamFlag) {
  2631. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2632. } else {
  2633. _this.checkbarNode.push(_this.getCheckbarNodeParam($div, $i));
  2634. }
  2635. });
  2636. } else if (_this.checkbarData == "choose"){ //记录选中数据
  2637. _this.obj.find("i[data-par][data-checked='1'][dtree-disabled='false']").each(function(){
  2638. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2639. if(requestParamFlag) {
  2640. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2641. } else {
  2642. _this.checkbarNode.push(_this.getCheckbarNodeParam($div, $i));
  2643. }
  2644. });
  2645. } else if (_this.checkbarData == "halfChoose"){ //记录选中和半选数据
  2646. _this.obj.find("i[data-par][data-checked='1'][dtree-disabled='false']").each(function(){
  2647. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2648. if(requestParamFlag) {
  2649. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2650. } else {
  2651. _this.checkbarNode.push(_this.getCheckbarNodeParam($div, $i));
  2652. }
  2653. });
  2654. _this.obj.find("i[data-par][data-checked='2'][dtree-disabled='false']").each(function(){
  2655. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2656. if(requestParamFlag) {
  2657. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2658. } else {
  2659. _this.checkbarNode.push(_this.getCheckbarNodeParam($div, $i));
  2660. }
  2661. });
  2662. }
  2663. return _this.checkbarNode;
  2664. };
  2665. // 获取树的复选框操作值的全部参数
  2666. DTree.prototype.getCheckbarNodesParam = function() {
  2667. var _this = this;
  2668. return _this.setAndGetCheckbarNodesParam(true);
  2669. };
  2670. // 获取树的一个复选框的参数
  2671. DTree.prototype.getCheckbarNodeParam = function($div, $i){
  2672. var _this = this;
  2673. var temp_node = {};
  2674. temp_node.nodeId = $div.attr("data-id");
  2675. temp_node.parentId = _this.getNodeDom($div).parentLi().attr("data-pid");
  2676. temp_node.context = (typeof _this.formatter.title === 'function') ? _this.getNodeDom($div).cite().attr("data-title") : _this.getNodeDom($div).cite().text();
  2677. temp_node.leaf = _this.getNodeDom($div).cite().attr("data-leaf") == "leaf" ? true : false;
  2678. temp_node.level = _this.getNodeDom($div).parentLi().attr("data-index");
  2679. temp_node.spread = _this.getNodeDom($div).fnode().attr("data-spread") == "open" ? true : false;
  2680. var basicData = $div.attr("data-basic");
  2681. if(basicData) {
  2682. basicData = JSON.parse(event.unescape(basicData));
  2683. }
  2684. temp_node.basicData = basicData;
  2685. var recordData = $div.attr("data-record");
  2686. if(recordData) {
  2687. recordData = JSON.parse(event.unescape(recordData));
  2688. }
  2689. temp_node.recordData = recordData;
  2690. temp_node.dataType = $i.attr("data-type");
  2691. temp_node.checked = $i.attr("data-checked");
  2692. temp_node.initchecked = $i.attr("data-initchecked");
  2693. return temp_node;
  2694. };
  2695. // 获取基于返回参数的树的复选框参数
  2696. DTree.prototype.getCheckbarJsonArrParam = function(){
  2697. var _this = this;
  2698. var checkbarJsonArr = {
  2699. nodeId: [], //节点ID
  2700. parentId: [], //父节点ID
  2701. context: [], //节点内容
  2702. leaf: [], //是否叶子节点
  2703. level: [], //层级
  2704. spread: [], //节点展开状态
  2705. dataType: [], //节点标记
  2706. checked: [], //节点复选框选中状态
  2707. initchecked: [], //节点复选框初始状态
  2708. basicData: [], //用户自定义的记录节点数据
  2709. recordData: [], //当前data数据(排除basicData和children字段)
  2710. };
  2711. // 获取全部复选框选中节点
  2712. var params = _this.setAndGetCheckbarNodesParam(false);
  2713. if(params && params.length > 0) {
  2714. for(var i=0; i<params.length; i++) {
  2715. var param = params[i];
  2716. console.log(param);
  2717. checkbarJsonArr["nodeId"].push(param["nodeId"]);
  2718. checkbarJsonArr["parentId"].push(param["parentId"]);
  2719. checkbarJsonArr["context"].push(param["context"]);
  2720. checkbarJsonArr["leaf"].push(param["leaf"]);
  2721. checkbarJsonArr["level"].push(param["level"]);
  2722. checkbarJsonArr["spread"].push(param["spread"]);
  2723. checkbarJsonArr["dataType"].push(param["dataType"]);
  2724. checkbarJsonArr["checked"].push(param["checked"]);
  2725. checkbarJsonArr["initchecked"].push(param["initchecked"]);
  2726. checkbarJsonArr["basicData"].push(param["basicData"]);
  2727. checkbarJsonArr["recordData"].push(param["recordData"]);
  2728. }
  2729. }
  2730. checkbarJsonArr = _this.getRequestParam(checkbarJsonArr);
  2731. console.log(checkbarJsonArr);
  2732. return checkbarJsonArr;
  2733. };
  2734. //判断复选框是否发生变更
  2735. DTree.prototype.changeCheckbarNodes = function(){
  2736. var flag = false;
  2737. var _this = this;
  2738. _this.obj.find("i[data-par]").each(function(){
  2739. var $i = $(this);
  2740. $div = $i.closest("."+LI_DIV_ITEM);
  2741. if ($i.attr("data-checked") != $i.attr("data-initchecked")) {
  2742. flag = true;
  2743. return true;
  2744. }
  2745. });
  2746. return flag;
  2747. };
  2748. //点击节点选中/不选 复选框
  2749. DTree.prototype.clickNodeCheckbar = function(nodeId){
  2750. var _this = this;
  2751. var $checkbar = _this.getNodeDom(nodeId).checkbox();
  2752. _this.temp = [$checkbar];
  2753. _this.changeCheck();
  2754. }
  2755. //复选框全选
  2756. DTree.prototype.checkAllNode = function(nodeId){
  2757. var _this = this;
  2758. var $i = _this.obj.find("i[data-par][data-checked!='1']");
  2759. if($i.length > 0) { _this.checkStatus($i).check(); }
  2760. }
  2761. //取消全部复选框选中
  2762. DTree.prototype.cancelCheckedNode = function(nodeId){
  2763. var _this = this;
  2764. var $i = _this.obj.find("i[data-par][data-checked!='0']");
  2765. if($i.length > 0) { _this.checkStatus($i).noCheck(); }
  2766. }
  2767. //反选复选框
  2768. DTree.prototype.invertCheckedNode = function(nodeId){
  2769. var _this = this;
  2770. if(_this.obj.find("i[data-par]").length > 0) {
  2771. var b = false;
  2772. _this.obj.find("i[data-par]").each(function(){
  2773. var $i = $(this);
  2774. if($i.attr("data-checked") == '2'){
  2775. b = true;
  2776. }else if($i.attr("data-checked") == '0') {
  2777. _this.checkStatus($i).check();
  2778. }else if($i.attr("data-checked") == '1') {
  2779. _this.checkStatus($i).noCheck();
  2780. }
  2781. });
  2782. if(b) {
  2783. _this.initNoAllCheck();
  2784. } else {
  2785. _this.initAllCheck();
  2786. }
  2787. }
  2788. }
  2789. //删除选中节点
  2790. DTree.prototype.removeCheckedNode = function(nodeId){
  2791. var _this = this;
  2792. var len = _this.obj.find("i[data-par][data-checked='1']").length;
  2793. if(len == 0){
  2794. layer.msg("请至少选中一个节点",{icon:2});
  2795. }else{
  2796. //操作前先清空
  2797. _this.checkbarNode = [];
  2798. // 选择所有复选框节点
  2799. var i_node = {};
  2800. _this.obj.find("i[data-par][data-checked='1']").each(function(){
  2801. var $i = $(this), $div = $i.closest("."+LI_DIV_ITEM);
  2802. _this.checkbarNode.push(_this.getRequestParam(_this.getCheckbarNodeParam($div, $i)));
  2803. });
  2804. layer.confirm('确定要删除选中节点?', {icon: 3, title:'删除选中节点'}, function(index1){
  2805. var flag = _this.menubarFun.remove(_this.checkbarNode);
  2806. if(flag){
  2807. _this.obj.find("i[data-par][data-checked='1']").closest("."+LI_DIV_ITEM).next("ul").remove();
  2808. _this.obj.find("i[data-par][data-checked='1']").closest("."+LI_DIV_ITEM).remove();
  2809. _this.checkbarNode=[];
  2810. }
  2811. layer.close(index1);
  2812. });
  2813. }
  2814. }
  2815. /******************** 工具栏及菜单栏区域 ********************/
  2816. // 初始化菜单栏和工具栏的div
  2817. DTree.prototype.initTreePlus = function(){
  2818. var _this = this;
  2819. // 初始化菜单栏和工具栏的div
  2820. _this.obj.prevAll('div#dtree_menubar_'+_this.obj[0].id).remove();
  2821. _this.toolbarMenu = {};
  2822. if(_this.menubar && _this.menubarTips.group && _this.menubarTips.group.length > 0) _this.obj.before("<div class='"+LI_DIV_MENUBAR+"' id='dtree_menubar_"+_this.obj[0].id+"'><div class='layui-btn-group'></div></div>");
  2823. if(_this.toolbar){
  2824. if(_this.toolbarWay == "contextmenu") {
  2825. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).remove();
  2826. _this.obj.before("<div class='"+LI_DIV_TOOLBAR+" layui-nav' id='dtree_toolbar_"+_this.obj[0].id+"'><div class='layui-nav-item'><dl class='layui-nav-child layui-anim'></dl></div></div>");
  2827. }
  2828. }
  2829. };
  2830. // 开启工具栏和菜单栏
  2831. DTree.prototype.openTreePlus = function(){
  2832. var _this = this;
  2833. // 先对工具栏做处理,因为菜单栏可能会与工具栏产生关联。
  2834. var ggMenu = [];
  2835. if(_this.toolbar) _this.getToolbarDom();
  2836. if(_this.menubar) {
  2837. var menubarTips = _this.menubarTips,
  2838. mtbar = menubarTips.toolbar,
  2839. group = menubarTips.group,
  2840. freedom = menubarTips.freedom;
  2841. if(mtbar && mtbar.length > 0){
  2842. // 菜单栏吸附工具栏上
  2843. for(var i=0; i<mtbar.length; i++){
  2844. var mt = mtbar[i];
  2845. if(typeof mt === 'string'){
  2846. _this.getMenubarToolDom(mt);
  2847. }
  2848. if(typeof mt === 'object'){
  2849. _this.getExtMenubarToolDom(mt);
  2850. }
  2851. }
  2852. }
  2853. if(group && group.length > 0){
  2854. // 菜单栏吸附在上方的按钮组div中
  2855. for(var i=0; i<group.length; i++){
  2856. var gg = group[i];
  2857. if(typeof gg === 'string'){
  2858. ggMenu.push(_this.getMenubarDom(gg));
  2859. }
  2860. if(typeof gg === 'object'){
  2861. ggMenu.push(_this.getExtMenubarDom(gg));
  2862. }
  2863. }
  2864. _this.obj.prevAll('div#dtree_menubar_'+_this.obj[0].id).children('div.layui-btn-group').append(ggMenu.join(""));
  2865. }
  2866. }
  2867. };
  2868. /******************** 菜单栏区域 ********************/
  2869. // 获取菜单栏
  2870. DTree.prototype.getMenubarDom = function(menu){
  2871. var _this = this;
  2872. var rootId = _this.obj[0].id;
  2873. var gg = "";
  2874. switch (menu) {
  2875. case defaultMenu.moveDown:
  2876. gg = "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.moveDown+"' title='展开全部节点'><i class='"+_this.usefontStyle.menubar.movedown+"'></i></button>";
  2877. break;
  2878. case defaultMenu.moveUp:
  2879. gg = "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.moveUp+"' title='收缩全部节点'><i class='"+_this.usefontStyle.menubar.moveup+"'></i></button>";
  2880. break;
  2881. case defaultMenu.refresh:
  2882. gg = "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.refresh+"' title='刷新'><i class='"+_this.usefontStyle.menubar.refresh+"'></i></button>";
  2883. break;
  2884. case defaultMenu.checkAll:
  2885. gg = (_this.checkbar && _this.checkbarType != 'only') ? "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.checkAll+"' title='全选节点'><i class='"+_this.usefontStyle.menubar.checkAll+"'></i></button>" : "";
  2886. break;
  2887. case defaultMenu.unCheckAll:
  2888. gg = (_this.checkbar && _this.checkbarType != 'only') ? "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.unCheckAll+"' title='全不选节点'><i class='"+_this.usefontStyle.menubar.unCheckAll+"'></i></button>" : "";
  2889. break;
  2890. case defaultMenu.invertAll:
  2891. gg = (_this.checkbar && _this.checkbarType != 'only') ? "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.invertAll+"' title='反选节点'><i class='"+_this.usefontStyle.menubar.invertAll+"'></i></button>" : "";
  2892. break;
  2893. case defaultMenu.remove:
  2894. gg = (_this.checkbar) ? "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.remove+"' title='删除选中节点'><i class='"+_this.usefontStyle.menubar.remove+"'></i></button>" : "";
  2895. break;
  2896. case defaultMenu.searchNode:
  2897. gg = "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+rootId+"' d-menu='"+defaultMenu.searchNode+"' title='查询节点'><i class='"+_this.usefontStyle.menubar.search+"'></i></button>";
  2898. break;
  2899. }
  2900. return gg;
  2901. };
  2902. // 获取扩展菜单栏
  2903. DTree.prototype.getExtMenubarDom = function(menu){
  2904. var _this = this;
  2905. return "<button type='button' class='layui-btn layui-btn-sm layui-btn-primary' dtree-id='"+_this.obj[0].id+"' d-menu='"+menu.menubarId+"' title='"+menu.title+"'><i class='"+_this.usefontStyle.menubarExt+" "+menu.icon+"'></i></button>";
  2906. };
  2907. // 获取依附在工具栏的菜单栏
  2908. DTree.prototype.getMenubarToolDom = function(menu){
  2909. var _this = this;
  2910. var rootId = _this.obj[0].id;
  2911. switch (menu) {
  2912. case defaultMenu.moveDown:
  2913. _this.toolbarMenu[defaultMenu.moveDown] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.moveDown, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.movedown, "展开全部");
  2914. break;
  2915. case defaultMenu.moveUp:
  2916. _this.toolbarMenu[defaultMenu.moveUp] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.moveUp, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.moveup, "收缩全部");
  2917. break;
  2918. case defaultMenu.refresh:
  2919. _this.toolbarMenu[defaultMenu.refresh] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.refresh, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.refresh, "刷新");
  2920. break;
  2921. case defaultMenu.checkAll:
  2922. if(_this.checkbar && _this.checkbarType != 'only')
  2923. _this.toolbarMenu[defaultMenu.checkAll] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.checkAll, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.checkAll, "全选节点");
  2924. break;
  2925. case defaultMenu.unCheckAll:
  2926. if(_this.checkbar && _this.checkbarType != 'only')
  2927. _this.toolbarMenu[defaultMenu.unCheckAll] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.unCheckAll, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.unCheckAll, "全不选节点");
  2928. break;
  2929. case defaultMenu.invertAll:
  2930. if(_this.checkbar && _this.checkbarType != 'only')
  2931. _this.toolbarMenu[defaultMenu.invertAll] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.invertAll, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.invertAll, "反选节点");
  2932. break;
  2933. case defaultMenu.remove:
  2934. if(_this.checkbar)
  2935. _this.toolbarMenu[defaultMenu.remove] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.remove, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.remove, "删除选中");
  2936. break;
  2937. case defaultMenu.searchNode:
  2938. _this.toolbarMenu[defaultMenu.searchNode] = _this.setToolbarDom().setMenuToolbarOption(defaultMenu.searchNode, _this.toolbarStyle.title, _this.usefontStyle.toolbar.menubar.searchNode, "查询");
  2939. break;
  2940. }
  2941. };
  2942. // 获取依附在工具栏的扩展菜单栏
  2943. DTree.prototype.getExtMenubarToolDom = function(menu){
  2944. var _this = this;
  2945. _this.toolbarMenu[menu.menubarId] = _this.setToolbarDom().setMenuToolbarOption(menu.menubarId, menu.title, _this.usefontStyle.toolbar.menubarExt+" "+menu.icon, "");
  2946. };
  2947. // menubar内置方法
  2948. DTree.prototype.menubarMethod = function(){
  2949. var _this = this;
  2950. return {
  2951. openAllNode: function(obj){ // 展开所有节点
  2952. var $ulNode = obj || _this.obj.children("li").children("ul");
  2953. // 遍历所有ul子节点
  2954. for (var i = 0; i < $ulNode.length; i++) {
  2955. // 获取当前节点的信息
  2956. var $ul = $($ulNode[i]),
  2957. $div = $ul.prev("div"),
  2958. $i_spread = _this.getNodeDom($div).fnode(),
  2959. $i_node = _this.getNodeDom($div).snode(),
  2960. $cite = _this.getNodeDom($div).cite(),
  2961. spread = $i_spread.attr("data-spread"),
  2962. leaf = $cite.attr("data-leaf");
  2963. if (leaf == "leaf") { continue; } // 说明是叶子了,则继续循环下一个
  2964. if (spread == "open") {
  2965. // 说明该节点已经展开了,则进行子节点循环
  2966. } else {
  2967. if (_this.type=="load") { //是否全量加载
  2968. if (_this.cache) { //是否开启缓存
  2969. if ($ul.html()) {
  2970. $ul.addClass(NAV_SHOW);
  2971. } else { //加载节点
  2972. _this.getChild($div);
  2973. }
  2974. }else { //每次取新的数据
  2975. $ul.html("");
  2976. _this.getChild($div);
  2977. }
  2978. } else { // 全量加载
  2979. $ul.addClass(NAV_SHOW);
  2980. }
  2981. _this.operateIcon($i_spread, $i_node).open();
  2982. }
  2983. var $childUl = $ul.children("li").children("ul");
  2984. _this.menubarMethod().openAllNode($childUl);
  2985. }
  2986. },
  2987. closeAllNode: function(){ //收缩所有节点
  2988. _this.obj.find("."+LI_NAV_CHILD).each(function(){
  2989. // 获取当前节点的信息
  2990. var $ul = $(this),
  2991. $div = $ul.prev("div"),
  2992. $i_spread = _this.getNodeDom($div).fnode(),
  2993. $i_node = _this.getNodeDom($div).snode(),
  2994. $cite = _this.getNodeDom($div).cite(),
  2995. spread = $i_spread.attr("data-spread"),
  2996. leaf = $cite.attr("data-leaf");
  2997. $ul.removeClass(NAV_SHOW);
  2998. _this.operateIcon($i_spread, $i_node).close();
  2999. });
  3000. },
  3001. refreshTree: function(){// 刷新树
  3002. _this.refreshTree();
  3003. },
  3004. checkAll: function(){ // 全选节点
  3005. _this.checkAllNode();
  3006. },
  3007. unCheckAll: function(){ // 全不选节点
  3008. _this.cancelCheckedNode();
  3009. },
  3010. invertAll: function(){ // 反选节点
  3011. _this.invertCheckedNode();
  3012. },
  3013. remove: function(){// 删除选中节点
  3014. _this.removeCheckedNode();
  3015. },
  3016. searchNode: function(){//模糊查询该值,展开该值节点
  3017. layer.prompt({
  3018. formType: 0,
  3019. value: "",
  3020. title: '查询节点'
  3021. }, function(value, index1, elem){
  3022. if (value) {
  3023. var flag = _this.searchNode(value);
  3024. if (!flag) {
  3025. layer.msg("该名称节点不存在!", {icon:5});
  3026. }
  3027. } else {
  3028. layer.msg("未指定查询节点名称", {icon:5});
  3029. }
  3030. layer.close(index1);
  3031. });
  3032. },
  3033. extMethod: function(menuId, $div, flag){
  3034. if(_this.menubar && _this.menubarTips.group && _this.menubarTips.group.length > 0 && flag == "group"){
  3035. for(var i=0; i<_this.menubarTips.group.length; i++){
  3036. var ext = _this.menubarTips.group[i];
  3037. if (menuId == ext.menubarId){
  3038. ext.handler(_this.getRequestParam(_this.getNodeParam($div), $div));
  3039. break;
  3040. }
  3041. }
  3042. }
  3043. if(_this.menubar && _this.menubarTips.toolbar && _this.menubarTips.toolbar.length > 0 && flag == "toolbar"){
  3044. for(var i=0; i<_this.menubarTips.toolbar.length; i++){
  3045. var ext = _this.menubarTips.toolbar[i];
  3046. if (menuId == ext.menubarId){
  3047. ext.handler(_this.getRequestParam(_this.getNodeParam($div), $div));
  3048. break;
  3049. }
  3050. }
  3051. }
  3052. if(_this.menubar && _this.menubarTips.freedom && _this.menubarTips.freedom.length > 0 && flag == "freedom"){
  3053. for(var i=0; i<_this.menubarTips.freedom.length; i++){
  3054. var ext = _this.menubarTips.freedom[i];
  3055. if (menuId == ext.menubarId){
  3056. ext.handler(_this.getRequestParam(_this.getNodeParam($div), $div));
  3057. break;
  3058. }
  3059. }
  3060. }
  3061. }
  3062. };
  3063. };
  3064. // menubar监听方法
  3065. DTree.prototype.menubarListener = function(menuId, flag){
  3066. var _this = this;
  3067. var $div = _this.getNodeDom().nowDiv();
  3068. switch (menuId) {
  3069. case defaultMenu.moveDown: // 展开全部节点
  3070. _this.menubarMethod().openAllNode();
  3071. break;
  3072. case defaultMenu.moveUp: // 收缩全部节点
  3073. _this.menubarMethod().closeAllNode();
  3074. break;
  3075. case defaultMenu.refresh:
  3076. _this.menubarMethod().refreshTree(); // 刷新树
  3077. break;
  3078. case defaultMenu.checkAll:
  3079. _this.menubarMethod().checkAll();
  3080. break;
  3081. case defaultMenu.unCheckAll:
  3082. _this.menubarMethod().unCheckAll();
  3083. break;
  3084. case defaultMenu.invertAll:
  3085. _this.menubarMethod().invertAll();
  3086. break;
  3087. case defaultMenu.remove:
  3088. _this.menubarMethod().remove();
  3089. break;
  3090. case defaultMenu.searchNode:
  3091. _this.menubarMethod().searchNode();
  3092. break;
  3093. default:
  3094. _this.menubarMethod().extMethod(menuId, $div, flag);
  3095. break;
  3096. }
  3097. };
  3098. //模糊查询该值,展开该值节点
  3099. DTree.prototype.searchNode = function(value){
  3100. var _this = this;
  3101. var b = false;
  3102. var $lis = [];
  3103. _this.obj.find("cite[data-leaf]").each(function(){
  3104. var $nthis = $(this);
  3105. var html = $nthis.html();
  3106. if(html.indexOf(value) > -1){
  3107. if($nthis.attr("data-leaf") == "leaf") {
  3108. // 叶子节点提供包含父节点的所有信息
  3109. var title = "";
  3110. $nthis.parents("li").each(function(){
  3111. title = "-" + $(this).find("cite[data-leaf]").html() + title;
  3112. });
  3113. title = title.substring(1, title.length);
  3114. $nthis.attr("title", title);
  3115. }
  3116. // 保存当前cite所在的li及父li中包含该值,则只保留父的
  3117. var i = 0;
  3118. $nthis.parents("li").each(function(){
  3119. var html2 = $(this).find("cite[data-leaf]").html();
  3120. if(html2.indexOf(value) > -1){
  3121. i++;
  3122. }
  3123. if(i >= 2){
  3124. return true;
  3125. }
  3126. });
  3127. if (i < 2){
  3128. $lis.push($nthis.closest("li").prop("outerHTML"));
  3129. }
  3130. }
  3131. });
  3132. if($lis.length > 0) {
  3133. b = true;
  3134. // 1.将树节点清空
  3135. _this.obj.html("");
  3136. // 2.遍历所有cite节点,展开当前cite节点
  3137. for(var i=0; i<$lis.length; i++){
  3138. _this.obj.append($lis[i]);
  3139. }
  3140. }
  3141. return b;
  3142. };
  3143. /******************** 工具栏区域 ********************/
  3144. // 获取工具栏
  3145. DTree.prototype.getToolbarDom = function(){
  3146. var _this = this;
  3147. var toolbarShow = _this.toolbarShow,
  3148. toolbarExt = _this.toolbarExt,
  3149. toolbarWay = _this.toolbarWay;
  3150. if(toolbarShow.length > 0){
  3151. for(var i=0; i<toolbarShow.length; i++){
  3152. var show = toolbarShow[i];
  3153. if(show == "pulldown"){
  3154. _this.toolbarMenu[defaultTool.pulldown] = _this.setToolbarDom().setToolbarOption(defaultTool.pulldown, _this.toolbarStyle.title, _this.usefontStyle.toolbar.pulldown, "展开");
  3155. }
  3156. if(show == "pullup"){
  3157. _this.toolbarMenu[defaultTool.pullup] = _this.setToolbarDom().setToolbarOption(defaultTool.pullup, _this.toolbarStyle.title, _this.usefontStyle.toolbar.pullup, "收缩");
  3158. }
  3159. if(show == "add"){
  3160. _this.toolbarMenu[defaultTool.addTool] = _this.setToolbarDom().setToolbarOption(defaultTool.addTool, _this.toolbarStyle.title, _this.usefontStyle.toolbar.add, "新增");
  3161. }
  3162. if(show == "edit"){
  3163. _this.toolbarMenu[defaultTool.editTool] = _this.setToolbarDom().setToolbarOption(defaultTool.editTool, _this.toolbarStyle.title, _this.usefontStyle.toolbar.edit, "编辑");
  3164. }
  3165. if(show == "delete"){
  3166. _this.toolbarMenu[defaultTool.delTool] = _this.setToolbarDom().setToolbarOption(defaultTool.delTool, _this.toolbarStyle.title, _this.usefontStyle.toolbar.del, "删除");
  3167. }
  3168. }
  3169. }
  3170. if(toolbarExt.length > 0){
  3171. for(var i=0; i<toolbarExt.length; i++){
  3172. var ext = toolbarExt[i];
  3173. _this.toolbarMenu[ext.toolbarId] = _this.setToolbarDom().setToolbarOption(ext.toolbarId, ext.title, _this.usefontStyle.toolbarExt+" "+ext.icon, "");
  3174. }
  3175. }
  3176. };
  3177. // 设置工具栏按钮
  3178. DTree.prototype.setToolbarDom = function(){
  3179. var _this = this;
  3180. var toolbarWay = _this.toolbarWay;
  3181. return {
  3182. setToolbarOption: function(toolbarId, title, classId, other){
  3183. if(toolbarWay == "contextmenu") {
  3184. return "<dd><a dtree-tool='"+toolbarId+"'><i class='"+classId+"'></i>&nbsp;"+other +title+"</a></dd>";
  3185. } else if(toolbarWay == "fixed" || toolbarWay == "follow") {
  3186. return "<a dtree-tool='"+toolbarId+"' title='"+other + title+"'><i class='"+classId+"'></i></a>";
  3187. }
  3188. },
  3189. setMenuToolbarOption: function(menubarId, title, classId, other){
  3190. var rootId = _this.obj[0].id;
  3191. if(toolbarWay == "contextmenu") {
  3192. return "<dd><a dtree-id='"+rootId+"' d-menu='"+menubarId+"'><i class='"+classId+"'></i>&nbsp;"+other +title+"</a></dd>";
  3193. } else if(toolbarWay == "fixed" || toolbarWay == "follow") {
  3194. return "<a dtree-id='"+rootId+"' d-menu='"+menubarId+"' title='"+other + title+"'><i class='"+classId+"'></i></a>";
  3195. }
  3196. },
  3197. setToolbarPlace: function(toolbarMenu){
  3198. if(toolbarWay == "contextmenu") {
  3199. if(toolbarMenu){
  3200. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).find('div.layui-nav-item>dl.layui-nav-child').html("");
  3201. for(var key in toolbarMenu){
  3202. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).find('div.layui-nav-item>dl.layui-nav-child').append(toolbarMenu[key]);
  3203. }
  3204. }
  3205. } else if(toolbarWay == "fixed" || toolbarWay == "follow") {
  3206. _this.obj.find("cite[data-leaf][dtree-disabled='false']").each(function(){
  3207. var $cite = $(this);
  3208. _this.dynamicToolbarDom($cite);
  3209. });
  3210. }
  3211. }
  3212. }
  3213. };
  3214. // 在节点后动态绑定fixed和follow条件的工具栏
  3215. DTree.prototype.dynamicToolbarDom = function($cite){
  3216. var _this = this;
  3217. var toolbarWay = _this.toolbarWay;
  3218. if($cite.next("em."+TOOLBAR_TOOL_EM).length == 0) {
  3219. var $div = $cite.parent("div");
  3220. var param = _this.getRequestParam(_this.getTempNodeParam($div));
  3221. var toolbarMenus = _this.toolbarFun.loadToolbarBefore(event.cloneObj(_this.toolbarMenu), param, $div);
  3222. var hideCls = (toolbarWay == "follow") ? NAV_HIDE : "";
  3223. var em = ["<em class='"+TOOLBAR_TOOL_EM+" "+hideCls+"'>"];
  3224. if(toolbarMenus){
  3225. for(var key in toolbarMenus){
  3226. em.push(toolbarMenus[key]);
  3227. }
  3228. }
  3229. em.push("</em>");
  3230. $cite.after(em.join(''));
  3231. }
  3232. }
  3233. // 隐藏toolbar
  3234. DTree.prototype.toolbarHide = function() {
  3235. var _this = this;
  3236. if(_this.toolbar && _this.toolbarWay == "contextmenu") {
  3237. var $toolBarDiv = _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id);
  3238. $toolBarDiv.find(".layui-nav-child").removeClass('layui-anim-fadein layui-show');
  3239. }
  3240. }
  3241. // toolbar内置方法
  3242. DTree.prototype.toolbarMethod = function(){
  3243. var _this = this;
  3244. return {
  3245. pulldown: function(obj){ // 展开当前点击节点的下面全部节点
  3246. if(!obj) return;
  3247. var $ulNode = obj;
  3248. // 遍历所有ul子节点
  3249. for (var i = 0; i < $ulNode.length; i++) {
  3250. // 获取当前节点的信息
  3251. var $ul = $($ulNode[i]),
  3252. $div = $ul.prev("div"),
  3253. $i_spread = _this.getNodeDom($div).fnode(),
  3254. $i_node = _this.getNodeDom($div).snode(),
  3255. $cite = _this.getNodeDom($div).cite(),
  3256. spread = $i_spread.attr("data-spread"),
  3257. leaf = $cite.attr("data-leaf");
  3258. if (leaf == "leaf") { continue; } // 说明是叶子了,则继续循环下一个
  3259. if (spread == "open") {
  3260. // 说明该节点已经展开了,则进行子节点循环
  3261. } else {
  3262. if (_this.type=="load") { //是否全量加载
  3263. if (_this.cache) { //是否开启缓存
  3264. if ($ul.html()) {
  3265. $ul.addClass(NAV_SHOW);
  3266. } else { //加载节点
  3267. _this.getChild($div);
  3268. }
  3269. }else { //每次取新的数据
  3270. $ul.html("");
  3271. _this.getChild($div);
  3272. }
  3273. } else { // 全量加载
  3274. $ul.addClass(NAV_SHOW);
  3275. }
  3276. _this.operateIcon($i_spread, $i_node).open();
  3277. }
  3278. var $childUl = $ul.children("li").children("ul");
  3279. _this.toolbarMethod().pulldown($childUl);
  3280. }
  3281. },
  3282. pullup: function($li){ // 收缩当前点击节点的下面全部节点
  3283. $li.find("."+LI_NAV_CHILD).each(function(){
  3284. // 获取当前节点的信息
  3285. var $ul = $(this),
  3286. $div = $ul.prev("div"),
  3287. $i_spread = _this.getNodeDom($div).fnode(),
  3288. $i_node = _this.getNodeDom($div).snode(),
  3289. $cite = _this.getNodeDom($div).cite(),
  3290. spread = $i_spread.attr("data-spread"),
  3291. leaf = $cite.attr("data-leaf");
  3292. $ul.removeClass(NAV_SHOW);
  3293. _this.operateIcon($i_spread, $i_node).close();
  3294. });
  3295. }
  3296. }
  3297. };
  3298. // toolbar监听方法
  3299. DTree.prototype.toolbarListener = function(tool, $div) {
  3300. var _this = this;
  3301. var $cite = $div.children("cite[data-leaf]"),
  3302. $ul = $div.next("ul"),
  3303. $p_li = $div.parent("li[data-index]"), //当前选中节点的顶级li节点
  3304. $p_ul = $p_li.parent("ul"), //当前选中节点的顶级li节点的父级ul
  3305. $p_div = $p_ul.prev("div"), //当前选中节点的顶级li节点的父级ul的前一个div
  3306. title = $cite.html();
  3307. switch (tool) {
  3308. case defaultTool.pulldown:
  3309. _this.toolbarMethod().pulldown($ul);
  3310. break;
  3311. case defaultTool.pullup:
  3312. _this.toolbarMethod().pullup($p_li);
  3313. break;
  3314. case defaultTool.addTool:
  3315. var content = _this.loadToolBar(title, defaultTool.addTool);
  3316. layer.open({
  3317. title: "新增"+_this.toolbarStyle.title,
  3318. type: 1,
  3319. area: _this.toolbarStyle.area,
  3320. content: content,
  3321. success: function(layero, index){
  3322. form.render();
  3323. form.on("submit(dtree_addNode_form)",function(data){
  3324. var data = data.field;
  3325. var parentId = $div.attr("data-id"),
  3326. id = $div.attr("data-id")+"_node_"+$ul[0].childNodes.length,
  3327. leaf = true,
  3328. checked = "0",
  3329. level = parseInt($p_li.attr("data-index"))+1;
  3330. // 创建子节点的DOM,添加子节点
  3331. var checkArr = [];
  3332. if (_this.checkArrLen > 0) {
  3333. for (var i = 0; i < _this.checkArrLen; i++) {
  3334. checkArr.push({"type":i,"checked":"0"});
  3335. }
  3336. }
  3337. $ul.append(_this.getLiItemDom(id, parentId, data.addNodeName, data.addNodeName, true, "", "", checkArr, level, false, false, false, "", "", "item"));
  3338. // 先将li节点隐藏
  3339. $ul.find("li[data-id='"+id+"']").hide();
  3340. // 重新赋值
  3341. var $addDiv = $ul.find("div[data-id='"+id+"']");
  3342. node = _this.getNodeParam($addDiv);
  3343. //获取组装后的requestNode,组合参数
  3344. var requestNode = _this.getRequestParam(node);
  3345. requestNode = $.extend(requestNode, data);
  3346. _this.temp = [id, $ul, $div, level];
  3347. // 用户自定义想做的事情
  3348. _this.toolbarFun.addTreeNode(requestNode, $div);
  3349. layer.close(index);
  3350. return false;
  3351. });
  3352. }
  3353. });
  3354. break;
  3355. case defaultTool.editTool:
  3356. var content = _this.loadToolBar(title, defaultTool.editTool);
  3357. layer.open({
  3358. title: "编辑"+_this.toolbarStyle.title,
  3359. type: 1,
  3360. area: _this.toolbarStyle.area,
  3361. content: content,
  3362. success: function(layero, index){
  3363. _this.toolbarFun.editTreeLoad(_this.getRequestParam(_this.getNodeParam($div)));
  3364. form.render();
  3365. form.on("submit(dtree_editNode_form)",function(data){
  3366. var data = data.field;
  3367. $cite.html(data.editNodeName);
  3368. node = _this.getNodeParam($div);
  3369. var requestNode = _this.getRequestParam(node);
  3370. requestNode = $.extend(requestNode, data);
  3371. _this.temp = [$cite, $div, title, $p_div];
  3372. _this.toolbarFun.editTreeNode(requestNode, $div);
  3373. layer.close(index);
  3374. });
  3375. }
  3376. });
  3377. break;
  3378. case defaultTool.delTool:
  3379. layer.confirm('确定要删除该'+_this.toolbarStyle.title+'?', {icon: 3, title:'删除'+_this.toolbarStyle.title}, function(index){
  3380. var node = _this.getNodeParam($div);
  3381. _this.temp = [$p_li, $p_div];
  3382. _this.toolbarFun.delTreeNode(_this.getRequestParam(_this.getNodeParam($div)), $div);
  3383. layer.close(index);
  3384. });
  3385. break;
  3386. default:
  3387. if(_this.toolbarExt.length > 0){
  3388. for(var i=0; i<_this.toolbarExt.length; i++){
  3389. var ext = _this.toolbarExt[i];
  3390. if (tool == ext.toolbarId){
  3391. ext.handler(_this.getRequestParam(_this.getNodeParam($div)), $div);
  3392. break;
  3393. }
  3394. }
  3395. }
  3396. break;
  3397. }
  3398. }
  3399. // 加载toolBar中的内容
  3400. DTree.prototype.loadToolBar = function(title, name){
  3401. var _this = this;
  3402. var toolbarShow = _this.toolbarShow;
  3403. var nodeBarContents = _this.toolbarBtn;
  3404. var html = "";
  3405. switch (name) {
  3406. case defaultTool.addTool:
  3407. var addNodeBarDef = [{"label": "当前选中", "name": "nodeTitle", "type": "text", "value": title, "defElem": "nowChoose", "readonly": true},
  3408. {"label": "新增"+_this.toolbarStyle.title, "name": "addNodeName", "type": "text", "value": "", "defElem": "nowChange", "verify": "required"},
  3409. {"type": "submit", "value": "确认添加", "defElem": "btn", "filter": "dtree_addNode_form"}];
  3410. //2. 用户自定义的节点内容
  3411. var addNodeBar = ['<div class="'+TOOLBAR_TOOL+'"><form class="layui-form layui-form-pane" lay-filter="dtree_addNode_form">'];
  3412. if(nodeBarContents != null && nodeBarContents.length > 0){
  3413. if(nodeBarContents[0] != null && nodeBarContents[0] != undefined && nodeBarContents[0].length > 0){
  3414. var addNodeBarContents = nodeBarContents[0];
  3415. // 1. 检查是否包含了now、newly、btn这三个默认项,将其他元素依次排列,将特殊元素至于栈顶
  3416. for(var i=0; i<addNodeBarContents.length; i++){
  3417. var defElem = addNodeBarContents[i].defElem;
  3418. if(defElem == "nowChoose") {
  3419. $.extend(addNodeBarDef[0], addNodeBarContents[i]);
  3420. } else if(defElem == "nowChange") {
  3421. $.extend(addNodeBarDef[1], addNodeBarContents[i]);
  3422. } else if(defElem == "btn") {
  3423. $.extend(addNodeBarDef[2], addNodeBarContents[i]);
  3424. } else {
  3425. addNodeBarDef.push(addNodeBarContents[i]);
  3426. }
  3427. }
  3428. }
  3429. }
  3430. // 2. 遍历生成全部表单标签
  3431. for(var j=0; j<addNodeBarDef.length; j++){
  3432. var type = addNodeBarDef[j].type;
  3433. if(!type){type = "text";}
  3434. switch (type) {
  3435. case "text":
  3436. addNodeBar.push(_this.loadToolBarDetail(addNodeBarDef[j]).text());
  3437. break;
  3438. case "textarea":
  3439. addNodeBar.push(_this.loadToolBarDetail(addNodeBarDef[j]).textarea());
  3440. break;
  3441. case "select":
  3442. addNodeBar.push(_this.loadToolBarDetail(addNodeBarDef[j]).select());
  3443. break;
  3444. case "hidden":
  3445. addNodeBar.push(_this.loadToolBarDetail(addNodeBarDef[j]).hidden());
  3446. break;
  3447. }
  3448. }
  3449. var addBtn = ['<div class="layui-form-item">', '<div class="layui-input-block" style="margin-left:0px;text-align:center;">'];
  3450. // 3.遍历生成按钮
  3451. for(var j=0; j<addNodeBarDef.length; j++){
  3452. var type = addNodeBarDef[j].type;
  3453. if(!type){type = "text";}
  3454. switch (type) {
  3455. case "submit":
  3456. addBtn.push(_this.loadToolBarDetail(addNodeBarDef[j]).submit());
  3457. break;
  3458. case "button":
  3459. addBtn.push(_this.loadToolBarDetail(addNodeBarDef[j]).button());
  3460. break;
  3461. case "reset":
  3462. addBtn.push(_this.loadToolBarDetail(addNodeBarDef[j]).reset());
  3463. break;
  3464. }
  3465. }
  3466. addBtn.push('</div></div>');
  3467. addNodeBar.push(addBtn.join(''));
  3468. addNodeBar.push('</form></div>');
  3469. html = addNodeBar.join('');
  3470. break;
  3471. case defaultTool.editTool:
  3472. var editNodeBarDef = [{"label": "当前选中", "name": "nodeTitle", "type": "text", "value": title, "defElem": "nowChoose", "readonly": true},
  3473. {"label": "编辑"+_this.toolbarStyle.title, "name": "editNodeName", "type": "text", "value": "", "defElem": "nowChange", "verify": "required"},
  3474. {"type": "submit", "value": "确认编辑", "defElem": "btn", "filter": "dtree_editNode_form"}];
  3475. var editNodeBar = ['<div class="'+TOOLBAR_TOOL+'"><form class="layui-form layui-form-pane" lay-filter="dtree_editNode_form">'];
  3476. //2. 用户自定义的节点内容
  3477. if(nodeBarContents != null && nodeBarContents.length > 0){
  3478. if(nodeBarContents[1] != null && nodeBarContents[1] != undefined && nodeBarContents[1].length > 0){
  3479. var editNodeBarContents = nodeBarContents[1];
  3480. // 1. 检查是否包含了now、newly、btn这三个默认项,将其他元素依次排列,将特殊元素至于栈顶
  3481. for(var i=0; i<editNodeBarContents.length; i++){
  3482. var defElem = editNodeBarContents[i].defElem;
  3483. if(defElem == "nowChoose") {
  3484. $.extend(editNodeBarDef[0], editNodeBarContents[i]);
  3485. } else if(defElem == "nowChange") {
  3486. $.extend(editNodeBarDef[1], editNodeBarContents[i]);
  3487. } else if(defElem == "btn") {
  3488. $.extend(editNodeBarDef[2], editNodeBarContents[i]);
  3489. } else {
  3490. editNodeBarDef.push(editNodeBarContents[i]);
  3491. }
  3492. }
  3493. }
  3494. }
  3495. // 2. 遍历生成全部表单标签
  3496. for(var j=0; j<editNodeBarDef.length; j++){
  3497. var type = editNodeBarDef[j].type;
  3498. if(!type){type = "text";}
  3499. switch (type) {
  3500. case "text":
  3501. editNodeBar.push(_this.loadToolBarDetail(editNodeBarDef[j]).text());
  3502. break;
  3503. case "textarea":
  3504. editNodeBar.push(_this.loadToolBarDetail(editNodeBarDef[j]).textarea());
  3505. break;
  3506. case "select":
  3507. editNodeBar.push(_this.loadToolBarDetail(editNodeBarDef[j]).select());
  3508. break;
  3509. case "hidden":
  3510. editNodeBar.push(_this.loadToolBarDetail(editNodeBarDef[j]).hidden());
  3511. break;
  3512. }
  3513. }
  3514. var editBtn = ['<div class="layui-form-item">', '<div class="layui-input-block" style="margin-left:0px;text-align:center;">'];
  3515. // 3.遍历生成按钮
  3516. for(var j=0; j<editNodeBarDef.length; j++){
  3517. var type = editNodeBarDef[j].type;
  3518. if(!type){type = "text";}
  3519. switch (type) {
  3520. case "submit":
  3521. editBtn.push(_this.loadToolBarDetail(editNodeBarDef[j]).submit());
  3522. break;
  3523. case "button":
  3524. editBtn.push(_this.loadToolBarDetail(editNodeBarDef[j]).button());
  3525. break;
  3526. case "reset":
  3527. editBtn.push(_this.loadToolBarDetail(editNodeBarDef[j]).reset());
  3528. break;
  3529. }
  3530. }
  3531. editBtn.push('</div></div>');
  3532. editNodeBar.push(editBtn.join(''));
  3533. editNodeBar.push('</form></div>');
  3534. html = editNodeBar.join('');
  3535. break;
  3536. }
  3537. return html;
  3538. };
  3539. // 获取toolbar详细的标签信息
  3540. DTree.prototype.loadToolBarDetail = function(nodeBarContents){
  3541. var _this = this;
  3542. var readonly = (typeof (nodeBarContents.readonly) === "boolean") ? nodeBarContents.readonly : false;
  3543. var disabled = (typeof (nodeBarContents.disabled) === "boolean") ? nodeBarContents.disabled : false;
  3544. var id = nodeBarContents.id ? nodeBarContents.id : "";
  3545. var name = nodeBarContents.name ? nodeBarContents.name : "";
  3546. var val = nodeBarContents.value ? nodeBarContents.value : "";
  3547. var verify = nodeBarContents.verify ? nodeBarContents.verify : "";
  3548. var placeholder = nodeBarContents.placeholder ? nodeBarContents.placeholder : val;
  3549. return{
  3550. text: function(){
  3551. return ['<div class="layui-form-item">',
  3552. '<label class="layui-form-label" title="'+nodeBarContents.label+'">'+nodeBarContents.label+':</label>',
  3553. '<div class="layui-input-block f-input-par">',
  3554. '<input type="text" class="layui-input f-input" value="'+val+'" placeholder="'+placeholder+'" lay-verify="'+verify+'" ',
  3555. (id != "" ? 'id="'+id+'" ' : ''),
  3556. (name != "" ? 'name="'+name+'" ' : ''),
  3557. (readonly ? 'readonly ' : ''),
  3558. (disabled ? 'disabled ' : ''),
  3559. '/>',
  3560. '</div>',
  3561. '</div>'].join('');
  3562. },
  3563. textarea: function(){
  3564. return ['<div class="layui-form-item layui-form-text">',
  3565. '<label class="layui-form-label" title="'+nodeBarContents.label+'">'+nodeBarContents.label+':</label>',
  3566. '<div class="layui-input-block f-input-par">',
  3567. '<textarea class="layui-textarea f-input" value="'+val+'" placeholder="'+placeholder+'" lay-verify="'+verify+'" ',
  3568. (id != "" ? 'id="'+id+'" ' : ''),
  3569. (name != "" ? 'name="'+name+'" ' : ''),
  3570. (readonly ? 'readonly ' : ''),
  3571. (disabled ? 'disabled ' : ''),
  3572. '>'+val+'</textarea>',
  3573. '</div>',
  3574. '</div>'].join('');
  3575. },
  3576. hidden: function(){
  3577. return ['<input type="hidden" class="layui-input f-input" value="'+val+'" lay-verify="'+verify+'" ',
  3578. (id != "" ? 'id="'+id+'" ' : ''),
  3579. (name != "" ? 'name="'+name+'" ' : ''),
  3580. (readonly ? 'readonly ' : ''),
  3581. (disabled ? 'disabled ' : ''),
  3582. '/>'].join('');
  3583. },
  3584. select: function(){
  3585. var optionsData = (typeof nodeBarContents.optionsData === 'object') ? nodeBarContents.optionsData : nodeBarContents.optionsData();
  3586. var options = "";
  3587. for(var key in optionsData){
  3588. if(val == optionsData[key]){
  3589. options += "<option value='"+key+"' selected>"+optionsData[key]+"</option>";
  3590. } else {
  3591. options += "<option value='"+key+"'>"+optionsData[key]+"</option>";
  3592. }
  3593. }
  3594. return ['<div class="layui-form-item">',
  3595. '<label class="layui-form-label" title="'+nodeBarContents.label+'">'+nodeBarContents.label+':</label>',
  3596. '<div class="layui-input-block f-input-par">',
  3597. '<select lay-verify="'+verify+'" ',
  3598. (id != "" ? 'id="'+id+'" ' : ''),
  3599. (name != "" ? 'name="'+name+'" ' : ''),
  3600. (readonly ? 'readonly ' : ''),
  3601. (disabled ? 'disabled ' : ''),
  3602. '>',
  3603. options,
  3604. '</select>', '</div>', '</div>'].join('');
  3605. },
  3606. submit: function(){
  3607. var filter = nodeBarContents.filter;
  3608. return ['<button type="button" class="layui-btn layui-btn-normal btn-w100" lay-submit lay-filter="'+filter+'" ',
  3609. (id != "" ? 'id="'+id+'" ' : ''),
  3610. (name != "" ? 'name="'+name+'" ' : ''),
  3611. '>'+val+'</button>'].join('');
  3612. },
  3613. button: function(){
  3614. return ['<button type="button" class="layui-btn layui-btn-normal btn-w100" ',
  3615. (id != "" ? 'id="'+id+'" ' : ''),
  3616. (name != "" ? 'name="'+name+'" ' : ''),
  3617. ' >'+val+'</button>'].join('');
  3618. },
  3619. reset: function(){
  3620. return ['<button type="reset" class="layui-btn layui-btn-primary btn-w100" ',
  3621. (id != "" ? 'id="'+id+'" ' : ''),
  3622. (name != "" ? 'name="'+name+'" ' : ''),
  3623. '>'+val+'</button>'].join('');
  3624. }
  3625. }
  3626. };
  3627. // 新增节点后改变节点内容
  3628. DTree.prototype.changeTreeNodeAdd = function(returnID){
  3629. var _this = this;
  3630. var temp = _this.temp;
  3631. var id = temp[0], $ul = temp[1], $div = temp[2], level = temp[3];
  3632. var flag = false;
  3633. if(returnID){
  3634. var $thisDiv = _this.obj.find("[data-id='"+id+"']");
  3635. if(typeof returnID === "object"){
  3636. // 如果是JSON格式数据,则将当前DIV删除,重新建造DIV
  3637. $thisDiv.remove();
  3638. var parseData = _this.parseData(returnID);
  3639. if(parseData.treeId()){
  3640. $ul.append(_this.getLiItemDom(parseData.treeId(), parseData.parentId(), parseData.title(), parseData.fmtTitle(), parseData.last(0), parseData.ficonClass(), parseData.iconClass(), parseData.checkArr(), level, parseData.spread(), parseData.disabled(), parseData.hide(), parseData.basicData(), parseData.recordData(), "item"));
  3641. // 建造完毕后,选中该DIV
  3642. $thisDiv = $ul.find("div[data-id='"+parseData.treeId()+"']");
  3643. _this.setNodeParam($thisDiv)
  3644. } else {
  3645. layer.msg("添加失败,节点ID为undefined!",{icon:5});
  3646. // 将li节点删除
  3647. $ul.find("li[data-id='"+id+"']").remove();
  3648. // 重新赋值
  3649. _this.setNodeParam($div);
  3650. // 临时变量制空
  3651. _this.temp = [];
  3652. return ;
  3653. }
  3654. }else if(returnID == 'refresh'){
  3655. // 如果是设置为refresh参数,则向后台发送请求,获取新增节点下的真实参数,局部刷新树。
  3656. flag = true;
  3657. } else if(typeof returnID === "string" || typeof returnID === 'number' || returnID == true){
  3658. $thisDiv.attr("data-id", returnID);
  3659. // 将li节点展示
  3660. $ul.find("li[data-id='"+returnID+"']").show();
  3661. _this.setNodeParam($thisDiv)
  3662. }
  3663. // 判断当前点击的节点是否是最后一级节点,如果是,则需要修改节点的样式
  3664. var $icon_i = $div.find("i[data-spread]");
  3665. if ($icon_i.eq(0).attr("data-spread") == "last") {
  3666. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).openWithLeaf();
  3667. } else { //如果不是,也要修改节点样式
  3668. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).open();
  3669. }
  3670. $ul.addClass(NAV_SHOW); //展开UL
  3671. _this.accordionUL($ul);
  3672. if(flag) {
  3673. _this.getChild($div);
  3674. } else {
  3675. // _this.showLine();
  3676. _this.showLine($ul.find("li"));
  3677. // 这种情况下需要在新增节点后对节点新增工具栏
  3678. if(_this.toolbar && _this.toolbarWay != 'contextmenu') {
  3679. _this.dynamicToolbarDom($thisDiv.find("cite[data-leaf]"));
  3680. }
  3681. }
  3682. } else {
  3683. // 将li节点删除
  3684. $ul.find("li[data-id='"+id+"']").remove();
  3685. // 重新赋值
  3686. _this.setNodeParam($div);
  3687. }
  3688. _this.temp = []; // 临时变量制空
  3689. };
  3690. // 编辑页打开后显示编辑页内容
  3691. DTree.prototype.changeTreeNodeDone = function(param){
  3692. var _this = this;
  3693. form.val('dtree_editNode_form', param);
  3694. form.render();
  3695. };
  3696. // 修改节点后改变节点内容
  3697. DTree.prototype.changeTreeNodeEdit = function(returnID){
  3698. var _this = this;
  3699. var temp = _this.temp;
  3700. var $cite = temp[0], $div = temp[1], title = temp[2], $p_div = temp[3];
  3701. var flag = false;
  3702. if(returnID){
  3703. if(typeof returnID === "object"){
  3704. var parseData = _this.parseData(data);
  3705. if(parseData.treeId()){
  3706. var replaceDom = _this.replaceDom($div, parseData.treeId(), parseData.last(0), parseData.spread(), parseData.disabled(), parseData.hide());
  3707. replaceDom.node(parseData.iconClass());
  3708. replaceDom.checkbox(parseData.checkArr());
  3709. replaceDom.text(parseData.title());
  3710. replaceDom.ul();
  3711. replaceDom.basicData(parseData.basicData());
  3712. replaceDom.recordData(parseData.recordData());
  3713. _this.setNodeParam($div);
  3714. } else {
  3715. layer.msg("编辑失败,节点ID为undefined!",{icon:5});
  3716. // 重新赋值
  3717. _this.setNodeParam($div);
  3718. }
  3719. }
  3720. } else {
  3721. $cite.html(title);
  3722. _this.getNodeParam($div);
  3723. }
  3724. _this.temp = []; // 临时变量制空
  3725. };
  3726. // 删除节点后改变节点内容
  3727. DTree.prototype.changeTreeNodeDel = function(flag){
  3728. var _this = this;
  3729. var temp = _this.temp;
  3730. var $p_li = temp[0],
  3731. $p_ul = $p_li.parent("ul"),
  3732. $p_div = temp[1];
  3733. if(flag){
  3734. $p_li.remove();
  3735. _this.showLine($p_ul.find("li"));
  3736. // 判断父级ul中是否还存在li,如果不存在,则需要修改节点的样式
  3737. if($p_ul.children("li").length == 0){
  3738. var $icon_i = $p_div.find("i[data-spread]");
  3739. _this.operateIcon($icon_i.eq(0), $icon_i.eq(1)).closeWithLeaf();
  3740. }
  3741. _this.initNodeParam();
  3742. }
  3743. _this.temp = []; // 临时变量制空
  3744. };
  3745. /******************** iframe区域 ********************/
  3746. // 加载iframe
  3747. DTree.prototype.loadIframe = function($div, iframeParam) {
  3748. var _this = this;
  3749. var $cite = _this.getNodeDom($div).cite();
  3750. if (!_this.useIframe) { // 启用iframe
  3751. return false;
  3752. }
  3753. var iframeElem = _this.iframeElem,
  3754. iframeUrl = _this.iframeUrl,
  3755. iframeLoad = _this.iframeLoad;
  3756. var flag = iframeLoad == "leaf" ? (($cite.attr("data-leaf") == "leaf") ? true : false) : true;
  3757. if (flag) {
  3758. if ($(iframeElem).length > 0) { //iframe存在
  3759. if (!iframeUrl) {
  3760. layer.msg("数据请求异常,iframeUrl参数未指定", {icon:5});
  3761. return false;
  3762. }
  3763. var param = AjaxHelper.serialize(iframeParam);
  3764. if(iframeUrl.indexOf("?")> -1){
  3765. param = "&"+param.substring(1, param.length);
  3766. }
  3767. var url = iframeUrl + param;
  3768. $(iframeElem).attr("src", url);
  3769. } else {
  3770. layer.msg("iframe绑定异常,请确认页面中是否有iframe页对应的容器", {icon:5});
  3771. return false;
  3772. }
  3773. }
  3774. return flag;
  3775. };
  3776. // 获取传递出去的参数,根据iframe.iframeDefaultRequest、iframe.iframeRequest和node拼出发出请求的参数
  3777. DTree.prototype.getIframeRequestParam = function(nodes){
  3778. var _this = this;
  3779. var request = _this.iframeRequest,
  3780. defaultRequestNames = _this.iframeDefaultRequest,
  3781. node = nodes || _this.node,
  3782. requestParam = {};
  3783. // 先拼用户自定义的,在拼树生成的,这样的话用户可以自定义当树未生成时的节点的初始值
  3784. for ( var key in request) {
  3785. requestParam[key] = request[key];
  3786. }
  3787. for ( var key in defaultRequestNames) {
  3788. var paramName = defaultRequestNames[key];
  3789. var paramValue = node[key];
  3790. if(typeof paramValue === "boolean"){
  3791. requestParam[paramName] = paramValue;
  3792. }else {
  3793. if(paramValue){
  3794. requestParam[paramName] = paramValue;
  3795. }
  3796. }
  3797. }
  3798. // 解决传递中文的乱码问题
  3799. var reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/; //正则匹配中文
  3800. for(var key in requestParam){
  3801. if(reg.test(requestParam[key])) {
  3802. var str = requestParam[key];
  3803. requestParam[key] = encodeURI(encodeURI(str));
  3804. }
  3805. }
  3806. return requestParam;
  3807. };
  3808. /******************** 数据回调区域 ********************/
  3809. // 根据具体的id获取基于当前id的div以及对应的其他dom元素
  3810. DTree.prototype.getNodeDom = function(id){
  3811. var _this = this;
  3812. // 获取当前div,如果id就是一个dom,则就是这个,如果不是则进行选择。如果选不中则为null
  3813. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  3814. return {
  3815. div: function(){ // 获取当前div
  3816. return $div;
  3817. },
  3818. fnode: function(){ // 获取一级图标元素
  3819. return ($div == null) ? null : $div.find("i[data-spread]").eq(0);
  3820. },
  3821. snode: function(){ // 获取二级图标元素
  3822. return ($div == null) ? null : $div.find("i[data-spread]").eq(1);
  3823. },
  3824. checkbox: function(){ // 获取复选框元素
  3825. return ($div == null) ? null : $div.find("i[data-par]");
  3826. },
  3827. cite: function(){ // 获取cite元素
  3828. return ($div == null) ? null : $div.find("cite[data-leaf]");
  3829. },
  3830. nextUl: function(){ // 获取相邻的ul元素
  3831. return ($div == null) ? null : $div.next("ul");
  3832. },
  3833. parentLi: function(){ // 获取父级li元素
  3834. return ($div == null) ? null : $div.parent("li");
  3835. },
  3836. parentUl: function(){ // 获取基于当前$div的上级$ul
  3837. return ($div == null) ? null : $div.parent("li").parent("ul");
  3838. },
  3839. parentDiv: function(){ // 获取基于当前$div的上级$div
  3840. return ($div == null) ? null : $div.parent("li").parent("ul").prev("div");
  3841. },
  3842. nowDiv: function(){ // 获取当前选中节点,没有则返回null
  3843. return (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS).length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS);
  3844. },
  3845. nowOrRootDiv: function(){ // 获取当前选中节点,没有则返回根节点下的第一个div
  3846. return (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS).length == 0) ? _this.obj.children("li").eq(0).children("div").eq(0) : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS);
  3847. },
  3848. nowOrRootUl: function(){ // 获取当前选中节点下一个UL 或根节点。为了将新节点放入ul下
  3849. return (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS).length == 0) ? _this.obj : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id]").parent().find("."+NAV_THIS).next("ul");
  3850. }
  3851. }
  3852. };
  3853. // 获取当前选中节点下一个UL 或根节点。为了将新节点放入ul下
  3854. DTree.prototype.getNowNodeUl = function() {
  3855. var _this = this;
  3856. return _this.getNodeDom().nowOrRootUl();
  3857. };
  3858. // 获取当前选中节点 或第一个根节点。
  3859. DTree.prototype.getNowNode = function() {
  3860. var _this = this;
  3861. return _this.getNodeDom().nowOrRootDiv();
  3862. };
  3863. // 获取当前选中节点 无则返回null。
  3864. DTree.prototype.getNowNodeOrNull = function() {
  3865. var _this = this;
  3866. return _this.getNodeDom().nowDiv();
  3867. };
  3868. // 获取指定节点。
  3869. DTree.prototype.getNode = function(id) {
  3870. var _this = this;
  3871. return _this.getNodeDom(id).div();
  3872. };
  3873. // 设置当前选中节点的全部参数
  3874. DTree.prototype.setNodeParam = function($div) {
  3875. var _this = this;
  3876. _this.node.nodeId = $div.attr("data-id");
  3877. _this.node.parentId = _this.getNodeDom($div).parentLi().attr("data-pid");
  3878. _this.node.context = (typeof _this.formatter.title === 'function') ? _this.getNodeDom($div).cite().attr("data-title") : _this.getNodeDom($div).cite().text();
  3879. _this.node.leaf = _this.getNodeDom($div).cite().attr("data-leaf") == "leaf" ? true : false;
  3880. _this.node.level = _this.getNodeDom($div).parentLi().attr("data-index");
  3881. _this.node.spread = _this.getNodeDom($div).fnode().attr("data-spread") == "open" ? true : false;
  3882. var basicData = $div.attr("data-basic");
  3883. if(basicData) {
  3884. basicData = JSON.parse(event.unescape(basicData));
  3885. }
  3886. _this.node.basicData = basicData;
  3887. var recordData = $div.attr("data-record");
  3888. if(recordData) {
  3889. recordData = JSON.parse(event.unescape(recordData));
  3890. }
  3891. _this.node.recordData = recordData;
  3892. if (_this.getNodeDom($div).checkbox()) {
  3893. var dataTypes = "", checkeds = "", initcheckeds = "";
  3894. _this.getNodeDom($div).checkbox().each(function(){
  3895. dataTypes += $(this).attr("data-type") + ",";
  3896. checkeds += $(this).attr("data-checked") + ",";
  3897. initcheckeds += $(this).attr("data-initchecked") + ",";
  3898. });
  3899. dataTypes = dataTypes.substring(0, dataTypes.length-1);
  3900. checkeds = checkeds.substring(0, checkeds.length-1);
  3901. initcheckeds = initcheckeds.substring(0, initcheckeds.length-1);
  3902. _this.node.dataType = dataTypes;
  3903. _this.node.checked = checkeds;
  3904. _this.node.initchecked = initcheckeds;
  3905. }
  3906. };
  3907. // 获取当前选中节点的全部参数
  3908. DTree.prototype.getNodeParam = function($div) {
  3909. var _this = this;
  3910. if ($div) {
  3911. _this.setNodeParam($div);
  3912. } else {
  3913. if(_this.obj.find("div[data-id]").parent().find("."+NAV_THIS).length == 0){
  3914. _this.initNodeParam();
  3915. }
  3916. }
  3917. return this.node;
  3918. };
  3919. // 获取一个临时的node参数
  3920. DTree.prototype.getTempNodeParam = function($div) {
  3921. var _this = this;
  3922. var temp_node = {};
  3923. temp_node.nodeId = $div.attr("data-id");
  3924. temp_node.parentId = _this.getNodeDom($div).parentLi().attr("data-pid");
  3925. temp_node.context = (typeof _this.formatter.title === 'function') ? _this.getNodeDom($div).cite().attr("data-title") : _this.getNodeDom($div).cite().text();
  3926. temp_node.leaf = _this.getNodeDom($div).cite().attr("data-leaf") == "leaf" ? true : false;
  3927. temp_node.level = _this.getNodeDom($div).parentLi().attr("data-index");
  3928. temp_node.spread = _this.getNodeDom($div).fnode().attr("data-spread") == "open" ? true : false;
  3929. var basicData = $div.attr("data-basic");
  3930. if(basicData) {
  3931. basicData = JSON.parse(event.unescape(basicData));
  3932. }
  3933. temp_node.basicData = basicData;
  3934. var recordData = $div.attr("data-record");
  3935. if(recordData) {
  3936. recordData = JSON.parse(event.unescape(recordData));
  3937. }
  3938. temp_node.recordData = recordData;
  3939. if (_this.getNodeDom($div).checkbox()) {
  3940. var dataTypes = "", checkeds = "", initcheckeds = "";
  3941. _this.getNodeDom($div).checkbox().each(function(){
  3942. dataTypes += $(this).attr("data-type") + ",";
  3943. checkeds += $(this).attr("data-checked") + ",";
  3944. initcheckeds += $(this).attr("data-initchecked") + ",";
  3945. });
  3946. dataTypes = dataTypes.substring(0, dataTypes.length-1);
  3947. checkeds = checkeds.substring(0, checkeds.length-1);
  3948. initcheckeds = initcheckeds.substring(0, initcheckeds.length-1);
  3949. temp_node.dataType = dataTypes;
  3950. temp_node.checked = checkeds;
  3951. temp_node.initchecked = initcheckeds;
  3952. }
  3953. return temp_node;
  3954. };
  3955. // 重置参数
  3956. DTree.prototype.initNodeParam = function(){
  3957. var _this = this;
  3958. _this.node.nodeId = "";
  3959. _this.node.parentId = "";
  3960. _this.node.context = "";
  3961. _this.node.leaf = "";
  3962. _this.node.level = "";
  3963. _this.node.spread = "";
  3964. _this.node.dataType = "";
  3965. _this.node.checked = "";
  3966. _this.node.initchecked = "";
  3967. _this.node.basicData = "";
  3968. _this.node.recordData = "";
  3969. if(_this.select) {
  3970. _this.selectResetVal();
  3971. }
  3972. };
  3973. // 获取传递出去的参数,根据defaultRequest、request和node拼出发出请求的参数
  3974. DTree.prototype.getRequestParam = function(nodes){
  3975. var _this = this;
  3976. var request = _this.request,
  3977. defaultRequestNames = _this.defaultRequest,
  3978. node = nodes || _this.node,
  3979. requestParam = {};
  3980. // 先拼用户自定义的,在拼树生成的,这样的话用户可以自定义当树未生成时的节点的初始值
  3981. for ( var key in request) {
  3982. requestParam[key] = request[key];
  3983. }
  3984. for ( var key in defaultRequestNames) {
  3985. var paramName = defaultRequestNames[key];
  3986. var paramValue = node[key];
  3987. if(typeof paramValue === "boolean"){
  3988. requestParam[paramName] = paramValue;
  3989. }else {
  3990. if(paramValue){
  3991. requestParam[paramName] = paramValue;
  3992. }
  3993. }
  3994. }
  3995. return requestParam;
  3996. };
  3997. // 获取filterParam过滤后的requestParam
  3998. DTree.prototype.getFilterRequestParam = function(requestParam){
  3999. var _this = this;
  4000. var filterRequest = _this.filterRequest;
  4001. return event.cloneObj(requestParam, filterRequest);
  4002. };
  4003. // 获取当前选中值
  4004. DTree.prototype.getNowParam = function(){
  4005. var _this = this;
  4006. return _this.getRequestParam(_this.getNodeParam());
  4007. };
  4008. // 获取指定节点选中值
  4009. DTree.prototype.getParam = function(id){
  4010. var _this = this;
  4011. // 获取当前div,如果id就是一个dom,则就是这个,如果不是则进行选择。如果选不中则为null
  4012. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  4013. if($div != null){ return _this.callbackData().node(_this.getTempNodeParam($div)); } else { return {}; }
  4014. };
  4015. // 获取参数的上级节点
  4016. DTree.prototype.getParentParam = function(id){
  4017. var _this = this;
  4018. // 获取当前div,如果id就是一个dom,则就是这个,如果不是则进行选择。如果选不中则为null
  4019. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  4020. if($div != null){ return _this.callbackData().parentNode($div); } else { return {}; }
  4021. };
  4022. // 获取参数的全部上级节点
  4023. DTree.prototype.getAllParentParam = function(id){
  4024. var _this = this;
  4025. // 获取当前div,如果id就是一个dom,则就是这个,如果不是则进行选择。如果选不中则为null
  4026. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  4027. var arr = [];
  4028. if($div != null){
  4029. var level = _this.getTempNodeParam($div).level;
  4030. for(var i=1; i<level; i++){ // 从1开始遍历,如果level等于1说明是根节点
  4031. arr.unshift(_this.callbackData().parentNode($div));
  4032. $div = _this.getNodeDom($div).parentDiv();
  4033. }
  4034. }
  4035. return arr;
  4036. };
  4037. // 获取参数的下级节点
  4038. DTree.prototype.getChildParam = function(id){
  4039. var _this = this;
  4040. // 获取当前div,如果id就是一个dom,则就是这个,如果不是则进行选择。如果选不中则为null
  4041. var $div = (typeof id === 'object') ? id : (_this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']").length == 0) ? null : _this.obj.find("div[dtree-click='"+eventName.itemNodeClick+"'][data-id='"+id+"']");
  4042. if($div != null){ return _this.callbackData().childNode($div); } else { return []; }
  4043. };
  4044. // 获取回调数据
  4045. DTree.prototype.callbackData = function(){
  4046. var _this = this;
  4047. return {
  4048. dom: function($dom){ // 获取dom
  4049. return $dom;
  4050. },
  4051. node: function(node){ // 获取当前节点值
  4052. return _this.getRequestParam(node);
  4053. },
  4054. childNode: function($div){ // 获取下级节点值
  4055. var $childDivs = $div.next("ul").find("li."+LI_NAV_ITEM+" div."+LI_DIV_ITEM);
  4056. var childNode = [];
  4057. if($childDivs && $childDivs.length > 0){
  4058. $childDivs.each(function(){
  4059. var $cDiv = $(this);
  4060. childNode.push(_this.getRequestParam(_this.getTempNodeParam($cDiv)));
  4061. });
  4062. }
  4063. return childNode;
  4064. },
  4065. parentNode: function($div){ // 获取上级节点值
  4066. var pId = _this.getNodeDom($div).parentLi().attr("data-pid");
  4067. var $pdiv = _this.obj.find("div[data-id='"+pId+"']");
  4068. if($pdiv.length > 0) {return _this.getRequestParam(_this.getTempNodeParam($pdiv));} else {return {};}
  4069. }
  4070. }
  4071. };
  4072. /******************** 事件回调区域 ********************/
  4073. // 绑定浏览器事件
  4074. DTree.prototype.bindBrowserEvent = function(){
  4075. var _this = this;
  4076. var rootId = _this.obj[0].id;
  4077. // 绑定文件夹展开/收缩的图标的点击事件,点击时给当前节点的div添加选中class
  4078. _this.obj.on("click", "i[data-spread]", function(event) {
  4079. event.stopPropagation();
  4080. var $i = $(this),
  4081. $div = $i.parent("div"),
  4082. node = _this.getNodeParam($div);
  4083. _this.toolbarHide();
  4084. _this.navThis($div);
  4085. _this.clickSpread($div); // 展开或隐藏节点
  4086. // 树状态改变后,用户自定义想做的事情
  4087. layui.event.call(this, MOD_NAME, "changeTree("+$(_this.obj)[0].id+")", {
  4088. dom: _this.callbackData().dom($i),
  4089. param: _this.callbackData().node(node),
  4090. show: _this.callbackData().dom($i).attr("data-spread") == "open" ? true : false
  4091. });
  4092. });
  4093. // 绑定所有子节点div的单击事件,点击时触发加载iframe或用户自定义想做的事情
  4094. _this.obj.on("click", "div[dtree-click='"+eventName.itemNodeClick+"'][dtree-disabled='false']", function(event) {
  4095. event.stopPropagation();
  4096. var $div = $(this),
  4097. $cite = $div.find("cite"),
  4098. node = _this.getNodeParam($div);
  4099. _this.toolbarHide();
  4100. _this.navThis($div);
  4101. if(_this.select) {
  4102. _this.selectVal(node.nodeId);
  4103. $("div[dtree-id='" + rootId + "'][dtree-select='"+_this.selectDiv+"']").click();
  4104. }
  4105. if (_this.useIframe) {
  4106. var iframeParam = _this.getFilterRequestParam(_this.getIframeRequestParam(node));
  4107. var flag = _this.loadIframe($div, iframeParam); // 加载iframe
  4108. if (flag) {
  4109. // iframe加载完毕后,用户自定义想做的事情
  4110. _this.iframeFun.iframeDone(iframeParam);
  4111. layui.event.call(this, MOD_NAME, "iframeDone("+$(_this.obj)[0].id+")", {
  4112. "iframeParam": iframeParam,
  4113. dom: _this.callbackData().dom($div)
  4114. });
  4115. }
  4116. } else {
  4117. // 单击事件执行完毕后,用户自定义想做的事情
  4118. layui.event.call(this, MOD_NAME, "node("+$(_this.obj)[0].id+")", {
  4119. param: _this.callbackData().node(node),
  4120. childParams: _this.callbackData().childNode($div),
  4121. parentParam: _this.callbackData().parentNode($div),
  4122. dom: _this.callbackData().dom($div)
  4123. });
  4124. }
  4125. });
  4126. // 绑定所有子节点div的双击事件,暴露on给用户自定义
  4127. _this.obj.on("dblclick", "div[dtree-click='"+eventName.itemNodeClick+"'][dtree-disabled='false']", function(event) {
  4128. event.stopPropagation();
  4129. var $div = $(this),
  4130. $cite = $div.find("cite"),
  4131. node = _this.getNodeParam($div);
  4132. _this.toolbarHide();
  4133. _this.navThis($div);
  4134. if(_this.select) {
  4135. _this.selectVal(node.nodeId);
  4136. $("div[dtree-id='" + rootId + "'][dtree-select='"+_this.selectDiv+"']").click();
  4137. }
  4138. // 双击事件执行完毕后,用户自定义想做的事情
  4139. layui.event.call(this, MOD_NAME, "nodedblclick("+$(_this.obj)[0].id+")", {
  4140. param: _this.callbackData().node(node),
  4141. childParams: _this.callbackData().childNode($div),
  4142. parentParam: _this.callbackData().parentNode($div),
  4143. dom: _this.callbackData().dom($div)
  4144. });
  4145. });
  4146. if(_this.checkbar) {
  4147. // 绑定cheboxbar的节点复选框
  4148. _this.obj.on("click", "i[dtree-click='"+eventName.checkNodeClick+"'][dtree-disabled='false']", function(event) {
  4149. _this.toolbarHide();
  4150. var $i = $(this),
  4151. $div = $i.closest("div[dtree-click='"+eventName.itemNodeClick+"']"),
  4152. node = _this.getNodeParam($div);
  4153. // 复选框选中前的回调
  4154. var flag = _this.checkbarFun.chooseBefore($i, _this.getRequestParam(node));
  4155. _this.temp = [$i];
  4156. if(flag){_this.changeCheck();}
  4157. event.stopPropagation();
  4158. });
  4159. }
  4160. if(_this.menubar) {
  4161. // 绑定menubar的点击事件
  4162. _this.obj.prevAll('div#dtree_menubar_'+_this.obj[0].id).on("click", "button[d-menu]", function(event) {
  4163. event.stopPropagation();
  4164. _this.toolbarHide();
  4165. _this.menubarListener($(this).attr("d-menu"), "group");
  4166. });
  4167. // 绑定menubar的点击事件
  4168. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).on("click", "a[d-menu]", function(event) {
  4169. event.stopPropagation();
  4170. _this.toolbarHide();
  4171. _this.menubarListener($(this).attr("d-menu"), "toolbar");
  4172. });
  4173. // 绑定menubar的点击按钮事件
  4174. _this.obj.closest('body').find("*[dtree-id='"+_this.obj[0].id+"'][dtree-menu]").on("click", function(event) {
  4175. event.stopPropagation();
  4176. _this.toolbarHide();
  4177. _this.menubarListener($(this).attr("dtree-menu"), "freedom");
  4178. });
  4179. }
  4180. if(_this.toolbar) {
  4181. if(_this.toolbarWay == "contextmenu") {
  4182. //绑定所有子节点div的右键点击事件,用于显示toolbar
  4183. _this.obj.on("contextmenu", "div[dtree-click='"+eventName.itemNodeClick+"'][d-contextmenu='true'][dtree-disabled='false']", function(e){
  4184. var $div = $(this),
  4185. node = _this.getNodeParam($div);
  4186. _this.toolbarHide();
  4187. // toolbar加载前执行的方法,执行完毕之后创建按钮
  4188. _this.setToolbarDom().setToolbarPlace(_this.toolbarFun.loadToolbarBefore(event.cloneObj(_this.toolbarMenu), _this.getRequestParam(node), $div));
  4189. var e = e || window.event,
  4190. mx = e.pageX - $div.offset().left +45 ,
  4191. my = $div.offset().top - _this.obj.closest(_this.scroll).offset().top +15;
  4192. _this.navThis($div);
  4193. var $toolBarDiv = _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id);
  4194. $toolBarDiv.find(".layui-nav-child").addClass('layui-anim-fadein layui-show');
  4195. $toolBarDiv.css({'left':mx+'px','top':my+'px'});
  4196. e.stopPropagation();
  4197. return false;
  4198. });
  4199. // 绑定装载树的上层出现滚动条的容器,让toolbar隐藏
  4200. _this.obj.closest(_this.scroll).scroll(function() {
  4201. _this.toolbarHide();
  4202. });
  4203. // 绑定toolbar的点击事件
  4204. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).on("click", "a[dtree-tool]", function(event) {
  4205. event.stopPropagation();
  4206. var $div = _this.getNodeDom().nowOrRootDiv(),
  4207. node = _this.getNodeParam($div);
  4208. _this.toolbarHide();
  4209. var tool = $(this).attr("dtree-tool");
  4210. _this.toolbarListener(tool, $div);
  4211. });
  4212. } else if(_this.toolbarWay == "fixed") {
  4213. // 绑定toolbar的点击事件
  4214. _this.obj.on("click", "a[dtree-tool]", function(event) {
  4215. event.stopPropagation();
  4216. var $a = $(this),
  4217. $cite = $a.parent("em."+TOOLBAR_TOOL_EM).prev("cite"), //当前选中节点的text
  4218. $div = $cite.parent("div"),
  4219. node = _this.getNodeParam($div);
  4220. var tool = $a.attr("dtree-tool");
  4221. _this.toolbarHide();
  4222. _this.navThis($div);
  4223. _this.toolbarListener(tool, $div);
  4224. });
  4225. } else if(_this.toolbarWay == "follow") {
  4226. //绑定所有子节点div的mouseover mouseout事件,用于显示或隐藏toolbar
  4227. _this.obj.on("mouseover mouseout", "div[dtree-click='"+eventName.itemNodeClick+"'][dtree-disabled='false']", function(event){
  4228. var $div = $(this),
  4229. $toolBarEm = $div.children("em."+TOOLBAR_TOOL_EM);
  4230. if(event.type == "mouseover"){
  4231. $toolBarEm.removeClass(NAV_HIDE);
  4232. event.stopPropagation();
  4233. } else if(event.type == "mouseout"){
  4234. $toolBarEm.addClass(NAV_HIDE);
  4235. event.stopPropagation();
  4236. }
  4237. });
  4238. // 绑定toolbar的点击事件
  4239. _this.obj.on("click", "a[dtree-tool]", function(event) {
  4240. event.stopPropagation();
  4241. var $a = $(this),
  4242. $cite = $a.parent("em."+TOOLBAR_TOOL_EM).prev("cite"), //当前选中节点的text
  4243. $div = $cite.parent("div"),
  4244. node = _this.getNodeParam($div);
  4245. var tool = $a.attr("dtree-tool");
  4246. _this.toolbarHide();
  4247. _this.navThis($div);
  4248. _this.toolbarListener(tool, $div);
  4249. });
  4250. }
  4251. }
  4252. if(_this.select) {
  4253. // 绑定select的点击事件
  4254. $("div[dtree-id='" + rootId + "'][dtree-select='"+_this.selectDiv+"']").on("click", function(event){
  4255. event.stopPropagation();
  4256. $(this).toggleClass("layui-form-selected");
  4257. $("div[dtree-id='" + rootId + "'][dtree-card='"+_this.selectCardDiv+"']").toggleClass("dtree-select-show layui-anim layui-anim-upbit");
  4258. // 下拉树面板开闭状态改变后,用户自定义想做的事情
  4259. layui.event.call(this, MOD_NAME, "changeSelect("+$(_this.obj)[0].id+")", {
  4260. show: $(this).hasClass("layui-form-selected"),
  4261. param: _this.selectVal()
  4262. });
  4263. });
  4264. }
  4265. };
  4266. // 绑定body的单击,让本页面所有的toolbar隐藏
  4267. $BODY.on("click", function(event){
  4268. $("div."+LI_DIV_TOOLBAR).find(".layui-show").removeClass('layui-anim-fadein layui-show');
  4269. // $("div[dtree-id][dtree-select]").removeClass("layui-form-selected");
  4270. // $("div[dtree-id][dtree-card]").removeClass("dtree-select-show layui-anim layui-anim-upbit");
  4271. });
  4272. // 解绑浏览器事件
  4273. DTree.prototype.unbindBrowserEvent = function(){
  4274. var _this = this;
  4275. // 本身事件解绑
  4276. _this.obj.unbind();
  4277. // 菜单栏解绑
  4278. if(_this.menubar){
  4279. _this.obj.prevAll('div#dtree_menubar_'+_this.obj[0].id).unbind();
  4280. if(_this.obj.closest('body').find("*[dtree-id='"+_this.obj[0].id+"'][dtree-menu]").length > 0){
  4281. _this.obj.closest('body').find("*[dtree-id='"+_this.obj[0].id+"'][dtree-menu]").unbind();
  4282. }
  4283. }
  4284. // 工具栏解绑
  4285. if(_this.toolbar){
  4286. if(_this.toolbarWay == "contextmenu") {
  4287. _this.obj.prevAll('div#dtree_toolbar_'+_this.obj[0].id).unbind();
  4288. if(_this.obj.closest(_this.scroll).length > 0){
  4289. _this.obj.closest(_this.scroll).unbind();
  4290. }
  4291. }
  4292. }
  4293. // 下拉树解绑
  4294. if(_this.select) {
  4295. // 解绑select的点击事件
  4296. $("div[dtree-id='" + _this.obj[0].id + "'][dtree-select='"+_this.selectDiv+"']").removeClass("layui-form-selected");
  4297. $("div[dtree-id='" + _this.obj[0].id + "'][dtree-card='"+_this.selectCardDiv+"']").removeClass("dtree-select-show layui-anim layui-anim-upbit");
  4298. $("div[dtree-id='" + _this.obj[0].id + "'][dtree-select='"+_this.selectDiv+"']").unbind();
  4299. }
  4300. };
  4301. /** 外部访问 **/
  4302. var dtree = {
  4303. set: function(options){ //设置全局属性
  4304. if(typeof options !== 'undefined') {
  4305. $.extend(OPTIONS, options);
  4306. }
  4307. },
  4308. render: function(options){ // 初始化树
  4309. var dTree = null;
  4310. var id = event.getElemId(options);
  4311. if(id == "") {
  4312. layer.msg("页面中未找到绑定id", {icon:5});
  4313. } else {
  4314. dTree = DTrees[id];
  4315. if(typeof dTree === 'object'){
  4316. dTree.unbindBrowserEvent();
  4317. }
  4318. // 创建树
  4319. dTree = new DTree(options);
  4320. // 添加到树数组中去
  4321. DTrees[id] = dTree;
  4322. dTree.initTreePlus();
  4323. dTree.openTreePlus();
  4324. dTree.init();
  4325. dTree.bindBrowserEvent();
  4326. }
  4327. return dTree;
  4328. },
  4329. renderSelect: function(options){ // 初始化下拉树
  4330. var dTree = null;
  4331. var id = event.getElemId(options);
  4332. if(id == "") {
  4333. layer.msg("页面中未找到绑定id", {icon:5});
  4334. } else {
  4335. dTree = DTrees[id];
  4336. if(typeof dTree === 'object'){
  4337. dTree.unbindBrowserEvent();
  4338. }
  4339. // 创建下拉树
  4340. dTree = new DTree(options);
  4341. dTree.selectSetting();
  4342. // 添加到树数组中去
  4343. DTrees[id] = dTree;
  4344. dTree.initTreePlus();
  4345. dTree.openTreePlus();
  4346. dTree.init();
  4347. dTree.bindBrowserEvent();
  4348. }
  4349. return dTree;
  4350. },
  4351. reload: function(dTree, options){ // 重新加载树
  4352. if(typeof dTree === "string"){
  4353. dTree = DTrees[dTree];
  4354. }
  4355. if(typeof dTree === "undefined"){
  4356. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4357. return ;
  4358. }
  4359. dTree.reloadSetting(options);
  4360. dTree.initTreePlus();
  4361. dTree.openTreePlus();
  4362. dTree.initNodeParam();
  4363. dTree.init();
  4364. dTree.unbindBrowserEvent();
  4365. dTree.bindBrowserEvent();
  4366. },
  4367. on: function(events, callback) { // 绑定事件
  4368. if(events.indexOf("'") > 0){
  4369. events = events.replace(/'/g,"");
  4370. }
  4371. if(events.indexOf('"') > 0) {
  4372. events = events.replace(/"/g,"");
  4373. }
  4374. return layui.onevent.call(this, MOD_NAME, events, callback);
  4375. },
  4376. click: function(dTree, id) { // 模拟单击事件
  4377. if(typeof dTree === "string"){
  4378. dTree = DTrees[dTree];
  4379. }
  4380. if(typeof dTree === "undefined"){
  4381. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4382. return ;
  4383. }
  4384. $("div[dtree-click='"+eventName.itemNodeClick+"'][dtree-id='"+dTree.obj[0].id+"'][data-id='"+id+"']").click();
  4385. },
  4386. getNowParam: function(dTree){ // 获取当前选中值
  4387. if(typeof dTree === "string"){
  4388. dTree = DTrees[dTree];
  4389. }
  4390. if(typeof dTree === "undefined"){
  4391. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4392. return ;
  4393. }
  4394. return dTree.getNowParam(); // 获取当前选中值
  4395. },
  4396. getParam: function(dTree, id){ // 获取指定节点值
  4397. if(typeof dTree === "string"){
  4398. dTree = DTrees[dTree];
  4399. }
  4400. if(typeof dTree === "undefined"){
  4401. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4402. return ;
  4403. }
  4404. return dTree.getParam(id); // 获取指定节点值
  4405. },
  4406. getParentParam: function(dTree, id){ // 获取参数的上级节点
  4407. if(typeof dTree === "string"){
  4408. dTree = DTrees[dTree];
  4409. }
  4410. if(typeof dTree === "undefined"){
  4411. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4412. return ;
  4413. }
  4414. return dTree.getParentParam(id);
  4415. },
  4416. getAllParentParam: function(dTree, id){ // 获取参数的全部上级节点
  4417. if(typeof dTree === "string"){
  4418. dTree = DTrees[dTree];
  4419. }
  4420. if(typeof dTree === "undefined"){
  4421. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4422. return ;
  4423. }
  4424. return dTree.getAllParentParam(id);
  4425. },
  4426. getChildParam: function(dTree, id){ // 获取参数的全部下级节点
  4427. if(typeof dTree === "string"){
  4428. dTree = DTrees[dTree];
  4429. }
  4430. if(typeof dTree === "undefined"){
  4431. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4432. return ;
  4433. }
  4434. return dTree.getChildParam(id);
  4435. },
  4436. getCheckbarNodesParam: function(dTree){ // 获取复选框选中值
  4437. if(typeof dTree === "string"){
  4438. dTree = DTrees[dTree];
  4439. }
  4440. if(typeof dTree === "undefined"){
  4441. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4442. return {};
  4443. }
  4444. return dTree.getCheckbarNodesParam(); // 获取复选框选中值
  4445. },
  4446. dataInit: function(dTree, chooseId){ // 初始化选中树,针对数据反选
  4447. if(typeof dTree === "string"){
  4448. dTree = DTrees[dTree];
  4449. }
  4450. if(typeof dTree === "undefined"){
  4451. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4452. return ;
  4453. }
  4454. if(chooseId){
  4455. return dTree.dataInit(chooseId);
  4456. }
  4457. },
  4458. chooseDataInit: function(dTree, chooseIds){ // 初始化复选框选中,针对数据反选
  4459. if(typeof dTree === "string"){
  4460. dTree = DTrees[dTree];
  4461. }
  4462. if(typeof dTree === "undefined"){
  4463. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4464. return ;
  4465. }
  4466. if(chooseIds){
  4467. return dTree.chooseDataInit(chooseIds);
  4468. }
  4469. },
  4470. changeCheckbarNodes: function(dTree){ //判断复选框是否发生变更
  4471. if(typeof dTree === "string"){
  4472. dTree = DTrees[dTree];
  4473. }
  4474. if(typeof dTree === "undefined"){
  4475. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4476. return ;
  4477. }
  4478. return dTree.changeCheckbarNodes();
  4479. },
  4480. initNoAllCheck: function(dTree) { //复选框半选状态初始化设置
  4481. if(typeof dTree === "string"){
  4482. dTree = DTrees[dTree];
  4483. }
  4484. if(typeof dTree === "undefined"){
  4485. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4486. return ;
  4487. }
  4488. return dTree.initNoAllCheck();
  4489. },
  4490. initAllCheck: function(dTree){ // 复选框选中状态初始化设置
  4491. if(typeof dTree === "string"){
  4492. dTree = DTrees[dTree];
  4493. }
  4494. if(typeof dTree === "undefined"){
  4495. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4496. return ;
  4497. }
  4498. return dTree.initAllCheck();
  4499. },
  4500. selectVal: function(dTree, param){ // select模式设置输入框选中值
  4501. if(typeof dTree === "string"){
  4502. dTree = DTrees[dTree];
  4503. }
  4504. if(typeof dTree === "undefined"){
  4505. layer.msg("方法获取失败,请检查ID或对象传递是否正确",{icon:2});
  4506. return ;
  4507. }
  4508. return dTree.selectVal(param); // select模式设置输入框选中值
  4509. },
  4510. escape: function(html){ // 字符串格式化
  4511. return event.escape(html);
  4512. },
  4513. unescape: function(str){ // 字符串反格式化
  4514. return event.unescape(str);
  4515. },
  4516. version: function(){ //获取版本号
  4517. return VERSION;
  4518. }
  4519. };
  4520. exports('dtree', dtree);
  4521. });