截流自动化的商城平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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