dtree.js 269 KB

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