form-create.js 181 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916
  1. /*!
  2. * @form-create/iview v2.5.27
  3. * (c) 2018-2022 xaboy
  4. * Github https://github.com/xaboy/form-create
  5. * Released under the MIT License.
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
  9. typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
  10. (global = global || self, factory(global.formCreate = {}, global.Vue));
  11. }(this, (function (exports, Vue) { 'use strict';
  12. Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue;
  13. function _extends() {
  14. return _extends = Object.assign || function (a) {
  15. for (var b, c = 1; c < arguments.length; c++) {
  16. for (var d in b = arguments[c], b) {
  17. Object.prototype.hasOwnProperty.call(b, d) && (a[d] = b[d]);
  18. }
  19. }
  20. return a;
  21. }, _extends.apply(this, arguments);
  22. }
  23. var normalMerge = ["attrs", "props", "domProps"],
  24. toArrayMerge = ["class", "style", "directives"],
  25. functionalMerge = ["on", "nativeOn"],
  26. mergeJsxProps = function mergeJsxProps(a) {
  27. return a.reduce(function (c, a) {
  28. for (var b in a) {
  29. if (!c[b]) c[b] = a[b];else if (-1 !== normalMerge.indexOf(b)) c[b] = _extends({}, c[b], a[b]);else if (-1 !== toArrayMerge.indexOf(b)) {
  30. var d = c[b] instanceof Array ? c[b] : [c[b]],
  31. e = a[b] instanceof Array ? a[b] : [a[b]];
  32. c[b] = d.concat(e);
  33. } else if (-1 !== functionalMerge.indexOf(b)) {
  34. for (var f in a[b]) {
  35. if (c[b][f]) {
  36. var g = c[b][f] instanceof Array ? c[b][f] : [c[b][f]],
  37. h = a[b][f] instanceof Array ? a[b][f] : [a[b][f]];
  38. c[b][f] = g.concat(h);
  39. } else c[b][f] = a[b][f];
  40. }
  41. } else if ("hook" == b) for (var i in a[b]) {
  42. c[b][i] = c[b][i] ? mergeFn(c[b][i], a[b][i]) : a[b][i];
  43. } else c[b] = a[b];
  44. }
  45. return c;
  46. }, {});
  47. },
  48. mergeFn = function mergeFn(a, b) {
  49. return function () {
  50. a && a.apply(this, arguments), b && b.apply(this, arguments);
  51. };
  52. };
  53. var helper = mergeJsxProps;
  54. function _typeof(obj) {
  55. "@babel/helpers - typeof";
  56. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  57. _typeof = function (obj) {
  58. return typeof obj;
  59. };
  60. } else {
  61. _typeof = function (obj) {
  62. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  63. };
  64. }
  65. return _typeof(obj);
  66. }
  67. function _classCallCheck(instance, Constructor) {
  68. if (!(instance instanceof Constructor)) {
  69. throw new TypeError("Cannot call a class as a function");
  70. }
  71. }
  72. function _defineProperty(obj, key, value) {
  73. if (key in obj) {
  74. Object.defineProperty(obj, key, {
  75. value: value,
  76. enumerable: true,
  77. configurable: true,
  78. writable: true
  79. });
  80. } else {
  81. obj[key] = value;
  82. }
  83. return obj;
  84. }
  85. function ownKeys(object, enumerableOnly) {
  86. var keys = Object.keys(object);
  87. if (Object.getOwnPropertySymbols) {
  88. var symbols = Object.getOwnPropertySymbols(object);
  89. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  90. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  91. });
  92. keys.push.apply(keys, symbols);
  93. }
  94. return keys;
  95. }
  96. function _objectSpread2(target) {
  97. for (var i = 1; i < arguments.length; i++) {
  98. var source = arguments[i] != null ? arguments[i] : {};
  99. if (i % 2) {
  100. ownKeys(Object(source), true).forEach(function (key) {
  101. _defineProperty(target, key, source[key]);
  102. });
  103. } else if (Object.getOwnPropertyDescriptors) {
  104. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  105. } else {
  106. ownKeys(Object(source)).forEach(function (key) {
  107. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  108. });
  109. }
  110. }
  111. return target;
  112. }
  113. function _inherits(subClass, superClass) {
  114. if (typeof superClass !== "function" && superClass !== null) {
  115. throw new TypeError("Super expression must either be null or a function");
  116. }
  117. subClass.prototype = Object.create(superClass && superClass.prototype, {
  118. constructor: {
  119. value: subClass,
  120. writable: true,
  121. configurable: true
  122. }
  123. });
  124. if (superClass) _setPrototypeOf(subClass, superClass);
  125. }
  126. function _getPrototypeOf(o) {
  127. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  128. return o.__proto__ || Object.getPrototypeOf(o);
  129. };
  130. return _getPrototypeOf(o);
  131. }
  132. function _setPrototypeOf(o, p) {
  133. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  134. o.__proto__ = p;
  135. return o;
  136. };
  137. return _setPrototypeOf(o, p);
  138. }
  139. function _isNativeReflectConstruct() {
  140. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  141. if (Reflect.construct.sham) return false;
  142. if (typeof Proxy === "function") return true;
  143. try {
  144. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  145. return true;
  146. } catch (e) {
  147. return false;
  148. }
  149. }
  150. function _assertThisInitialized(self) {
  151. if (self === void 0) {
  152. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  153. }
  154. return self;
  155. }
  156. function _possibleConstructorReturn(self, call) {
  157. if (call && (typeof call === "object" || typeof call === "function")) {
  158. return call;
  159. }
  160. return _assertThisInitialized(self);
  161. }
  162. function _createSuper(Derived) {
  163. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  164. return function _createSuperInternal() {
  165. var Super = _getPrototypeOf(Derived),
  166. result;
  167. if (hasNativeReflectConstruct) {
  168. var NewTarget = _getPrototypeOf(this).constructor;
  169. result = Reflect.construct(Super, arguments, NewTarget);
  170. } else {
  171. result = Super.apply(this, arguments);
  172. }
  173. return _possibleConstructorReturn(this, result);
  174. };
  175. }
  176. function _toConsumableArray(arr) {
  177. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  178. }
  179. function _arrayWithoutHoles(arr) {
  180. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  181. }
  182. function _iterableToArray(iter) {
  183. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  184. }
  185. function _unsupportedIterableToArray(o, minLen) {
  186. if (!o) return;
  187. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  188. var n = Object.prototype.toString.call(o).slice(8, -1);
  189. if (n === "Object" && o.constructor) n = o.constructor.name;
  190. if (n === "Map" || n === "Set") return Array.from(o);
  191. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  192. }
  193. function _arrayLikeToArray(arr, len) {
  194. if (len == null || len > arr.length) len = arr.length;
  195. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  196. return arr2;
  197. }
  198. function _nonIterableSpread() {
  199. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  200. }
  201. function getSlot(slots, exclude) {
  202. return Object.keys(slots).reduce(function (lst, name) {
  203. if (!exclude || exclude.indexOf(name) === -1) {
  204. lst.push(slots[name]);
  205. }
  206. return lst;
  207. }, []);
  208. }
  209. var NAME = 'fcCheckbox';
  210. var Checkbox = {
  211. name: NAME,
  212. props: {
  213. formCreateInject: {
  214. type: Object,
  215. required: true
  216. },
  217. value: {
  218. type: Array,
  219. "default": function _default() {
  220. return [];
  221. }
  222. }
  223. },
  224. watch: {
  225. 'formCreateInject.options': {
  226. handler: function handler() {
  227. this.update();
  228. },
  229. deep: true
  230. },
  231. value: function value() {
  232. this.update();
  233. }
  234. },
  235. data: function data() {
  236. return {
  237. trueValue: []
  238. };
  239. },
  240. methods: {
  241. options: function options() {
  242. var opt = this.formCreateInject.options;
  243. return Array.isArray(opt) ? opt : [];
  244. },
  245. onInput: function onInput(n) {
  246. this.$emit('input', this.options().filter(function (opt) {
  247. return n.indexOf(opt.label) !== -1;
  248. }).map(function (opt) {
  249. return opt.value;
  250. }).filter(function (v) {
  251. return v !== undefined;
  252. }));
  253. },
  254. update: function update() {
  255. var _this = this;
  256. this.trueValue = this.value ? this.options().filter(function (opt) {
  257. return _this.value.indexOf(opt.value) !== -1;
  258. }).map(function (option) {
  259. return option.label;
  260. }) : [];
  261. }
  262. },
  263. created: function created() {
  264. this.update();
  265. },
  266. render: function render() {
  267. var h = arguments[0];
  268. return h("CheckboxGroup", helper([{}, this.formCreateInject.prop, {}, {
  269. "props": {
  270. value: this.trueValue
  271. }
  272. }, {
  273. "on": {
  274. "input": this.onInput
  275. }
  276. }]), [this.options().map(function (opt, index) {
  277. var props = _objectSpread2({}, opt);
  278. delete props.value;
  279. return h("Checkbox", helper([{}, {
  280. "props": props
  281. }, {
  282. "key": '' + index + '-' + opt.value
  283. }]));
  284. }), getSlot(this.$slots)]);
  285. }
  286. };
  287. function toArray(value) {
  288. return Array.isArray(value) ? value : [null, undefined, ''].indexOf(value) > -1 ? [] : [value];
  289. }
  290. function styleInject(css, ref) {
  291. if (ref === void 0) ref = {};
  292. var insertAt = ref.insertAt;
  293. if (!css || typeof document === 'undefined') {
  294. return;
  295. }
  296. var head = document.head || document.getElementsByTagName('head')[0];
  297. var style = document.createElement('style');
  298. style.type = 'text/css';
  299. if (insertAt === 'top') {
  300. if (head.firstChild) {
  301. head.insertBefore(style, head.firstChild);
  302. } else {
  303. head.appendChild(style);
  304. }
  305. } else {
  306. head.appendChild(style);
  307. }
  308. if (style.styleSheet) {
  309. style.styleSheet.cssText = css;
  310. } else {
  311. style.appendChild(document.createTextNode(css));
  312. }
  313. }
  314. var css_248z = "._fc-frame .fc-upload-btn {\n border: 1px dashed #c0ccda;\n cursor: pointer;\n}\n\n._fc-frame .fc-upload-cover {\n opacity: 0;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background: rgba(0, 0, 0, .6);\n transition: opacity .3s;\n}\n\n._fc-frame .fc-upload-cover i {\n color: #fff;\n font-size: 20px;\n cursor: pointer;\n margin: 0 2px;\n}\n\n._fc-frame .fc-files:hover .fc-upload-cover {\n opacity: 1;\n}\n\n._fc-frame .ivu-upload-list {\n margin-top: 0;\n}\n\n._fc-frame .fc-files img {\n width: 100%;\n height: 100%;\n display: inline-block;\n vertical-align: top;\n}\n\n._fc-frame .fc-upload-btn, ._fc-frame .fc-files {\n display: inline-block;\n width: 58px;\n height: 58px;\n text-align: center;\n line-height: 58px;\n border: 1px solid #c0ccda;\n border-radius: 4px;\n overflow: hidden;\n background: #fff;\n position: relative;\n box-shadow: 2px 2px 5px rgba(0, 0, 0, .1);\n margin-right: 4px;\n box-sizing: border-box;\n}\n";
  315. styleInject(css_248z);
  316. var NAME$1 = 'fcFrame';
  317. function createFrame(config) {
  318. return {
  319. name: NAME$1,
  320. props: {
  321. formCreateInject: {
  322. type: Object,
  323. required: true
  324. },
  325. type: {
  326. type: String,
  327. "default": 'input'
  328. },
  329. field: String,
  330. helper: {
  331. type: Boolean,
  332. "default": true
  333. },
  334. disabled: {
  335. type: Boolean,
  336. "default": false
  337. },
  338. src: {
  339. type: String,
  340. required: true
  341. },
  342. icon: {
  343. type: String,
  344. "default": config.fileUpIcon
  345. },
  346. width: {
  347. type: [Number, String],
  348. "default": 500
  349. },
  350. height: {
  351. type: String,
  352. "default": '370px'
  353. },
  354. maxLength: {
  355. type: Number,
  356. "default": 0
  357. },
  358. okBtnText: {
  359. type: String,
  360. "default": '确定'
  361. },
  362. closeBtnText: {
  363. type: String,
  364. "default": '关闭'
  365. },
  366. modalTitle: String,
  367. handleIcon: {
  368. type: [String, Boolean],
  369. "default": undefined
  370. },
  371. title: String,
  372. allowRemove: {
  373. type: Boolean,
  374. "default": true
  375. },
  376. onOpen: {
  377. type: Function,
  378. "default": function _default() {}
  379. },
  380. onOk: {
  381. type: Function,
  382. "default": function _default() {}
  383. },
  384. onCancel: {
  385. type: Function,
  386. "default": function _default() {}
  387. },
  388. onLoad: {
  389. type: Function,
  390. "default": function _default() {}
  391. },
  392. onBeforeRemove: {
  393. type: Function,
  394. "default": function _default() {}
  395. },
  396. onRemove: {
  397. type: Function,
  398. "default": function _default() {}
  399. },
  400. onHandle: {
  401. type: Function,
  402. "default": function _default(src) {
  403. this.previewImage = this.getSrc(src);
  404. this.previewVisible = true;
  405. }
  406. },
  407. modal: {
  408. type: Object,
  409. "default": function _default() {
  410. return {};
  411. }
  412. },
  413. srcKey: {
  414. type: [String, Number]
  415. },
  416. value: [Array, String, Number, Object],
  417. previewMask: undefined,
  418. footer: {
  419. type: Boolean,
  420. "default": true
  421. },
  422. reload: {
  423. type: Boolean,
  424. "default": true
  425. },
  426. closeBtn: {
  427. type: Boolean,
  428. "default": true
  429. },
  430. okBtn: {
  431. type: Boolean,
  432. "default": true
  433. }
  434. },
  435. data: function data() {
  436. return {
  437. fileList: toArray(this.value),
  438. previewVisible: false,
  439. frameVisible: false,
  440. previewImage: ''
  441. };
  442. },
  443. watch: {
  444. value: function value(n) {
  445. this.fileList = toArray(n);
  446. },
  447. fileList: function fileList(n) {
  448. var val = this.maxLength === 1 ? n[0] || '' : n;
  449. this.$emit('input', val);
  450. this.$emit('change', val);
  451. },
  452. src: function src(n) {
  453. this.modalVm && (this.modalVm.src = n);
  454. }
  455. },
  456. methods: {
  457. key: function key(unique) {
  458. return unique;
  459. },
  460. closeModel: function closeModel(close) {
  461. this.$emit(close ? '$close' : '$ok');
  462. if (this.reload) {
  463. this.$off('$ok');
  464. this.$off('$close');
  465. }
  466. this.frameVisible = false;
  467. },
  468. showModel: function showModel() {
  469. if (this.disabled || false === this.onOpen()) return;
  470. this.frameVisible = true;
  471. },
  472. makeInput: function makeInput() {
  473. var _this = this;
  474. var h = this.$createElement;
  475. var props = {
  476. type: 'text',
  477. value: this.fileList.map(function (v) {
  478. return _this.getSrc(v);
  479. }).toString(),
  480. icon: this.icon,
  481. readonly: true,
  482. clearable: false
  483. };
  484. return h("Input", helper([{}, {
  485. "props": props
  486. }, {}, {
  487. "on": {
  488. 'on-click': function onClick() {
  489. return _this.showModel();
  490. }
  491. }
  492. }, {
  493. "key": this.key('input')
  494. }]));
  495. },
  496. makeGroup: function makeGroup(children) {
  497. var h = this.$createElement;
  498. if (!this.maxLength || this.fileList.length < this.maxLength) children.push(this.makeBtn());
  499. return h("div", {
  500. "key": this.key('group')
  501. }, _toConsumableArray(children));
  502. },
  503. makeItem: function makeItem(index, children) {
  504. var h = this.$createElement;
  505. return h("div", {
  506. "class": 'fc-files',
  507. "key": this.key('file' + index)
  508. }, _toConsumableArray(children));
  509. },
  510. valid: function valid(f) {
  511. var field = this.formCreateInject.field || this.field;
  512. if (field && f !== field) throw new Error('[frame]无效的字段值');
  513. },
  514. makeIcons: function makeIcons(val, index) {
  515. var h = this.$createElement;
  516. if (this.handleIcon !== false || this.allowRemove === true) {
  517. var icons = [];
  518. if (this.type !== 'file' && this.handleIcon !== false || this.type === 'file' && this.handleIcon) icons.push(this.makeHandleIcon(val, index));
  519. if (this.allowRemove) icons.push(this.makeRemoveIcon(val, index));
  520. return h("div", {
  521. "class": 'fc-upload-cover',
  522. "key": this.key('uc')
  523. }, [icons]);
  524. }
  525. },
  526. makeHandleIcon: function makeHandleIcon(val, index) {
  527. var _this2 = this;
  528. var h = this.$createElement;
  529. return h("icon", helper([{}, {
  530. "props": {
  531. type: this.handleIcon === true || this.handleIcon === undefined ? 'ios-eye-outline' : this.handleIcon
  532. }
  533. }, {
  534. "on": {
  535. "click": function click() {
  536. return _this2.handleClick(val);
  537. }
  538. },
  539. "key": this.key('hi' + index)
  540. }]));
  541. },
  542. makeRemoveIcon: function makeRemoveIcon(val, index) {
  543. var _this3 = this;
  544. var h = this.$createElement;
  545. return h("icon", helper([{}, {
  546. "props": {
  547. type: 'ios-trash-outline'
  548. }
  549. }, {
  550. "on": {
  551. "click": function click() {
  552. return _this3.handleRemove(val);
  553. }
  554. },
  555. "key": this.key('ri' + index)
  556. }]));
  557. },
  558. makeFiles: function makeFiles() {
  559. var _this4 = this;
  560. var h = this.$createElement;
  561. return this.makeGroup(this.fileList.map(function (src, index) {
  562. return _this4.makeItem(index, [h("icon", helper([{}, {
  563. "props": {
  564. type: config.fileIcon,
  565. size: 40
  566. }
  567. }, {
  568. "on": {
  569. "click": function click() {
  570. return _this4.handleClick(src);
  571. }
  572. }
  573. }])), _this4.makeIcons(src, index)]);
  574. }));
  575. },
  576. makeImages: function makeImages() {
  577. var _this5 = this;
  578. var h = this.$createElement;
  579. return this.makeGroup(this.fileList.map(function (src, index) {
  580. return _this5.makeItem(index, [h("img", {
  581. "attrs": {
  582. "src": _this5.getSrc(src)
  583. }
  584. }), _this5.makeIcons(src, index)]);
  585. }));
  586. },
  587. makeBtn: function makeBtn() {
  588. var _this6 = this;
  589. var h = this.$createElement;
  590. return h("div", {
  591. "class": 'fc-upload-btn',
  592. "on": {
  593. "click": function click() {
  594. return _this6.showModel();
  595. }
  596. },
  597. "key": this.key('btn')
  598. }, [h("icon", helper([{}, {
  599. "props": {
  600. type: this.icon,
  601. size: 20
  602. }
  603. }]))]);
  604. },
  605. handleClick: function handleClick(src) {
  606. return this.onHandle(src);
  607. },
  608. handleRemove: function handleRemove(src) {
  609. if (this.disabled) return;
  610. if (false !== this.onBeforeRemove(src)) {
  611. this.fileList.splice(this.fileList.indexOf(src), 1);
  612. this.onRemove(src);
  613. }
  614. },
  615. getSrc: function getSrc(src) {
  616. return !this.srcKey ? src : src[this.srcKey];
  617. },
  618. frameLoad: function frameLoad(iframe) {
  619. var _this7 = this;
  620. this.onLoad(iframe);
  621. try {
  622. if (this.helper === true) {
  623. iframe['form_create_helper'] = {
  624. api: this.formCreateInject.api,
  625. close: function close(field) {
  626. _this7.valid(field);
  627. _this7.closeModel();
  628. },
  629. set: function set(field, value) {
  630. _this7.valid(field);
  631. if (!_this7.disabled) _this7.$emit('input', value);
  632. },
  633. get: function get(field) {
  634. _this7.valid(field);
  635. return _this7.value;
  636. },
  637. onOk: function onOk(fn) {
  638. return _this7.$on('$ok', fn);
  639. },
  640. onClose: function onClose(fn) {
  641. return _this7.$on('$close', fn);
  642. }
  643. };
  644. }
  645. } catch (e) {
  646. console.log(e);
  647. }
  648. },
  649. makeFooter: function makeFooter() {
  650. var _this8 = this;
  651. var h = this.$createElement;
  652. var _this$$props = this.$props,
  653. okBtnText = _this$$props.okBtnText,
  654. closeBtnText = _this$$props.closeBtnText,
  655. closeBtn = _this$$props.closeBtn,
  656. okBtn = _this$$props.okBtn,
  657. footer = _this$$props.footer;
  658. var node = [];
  659. if (!footer) return node;
  660. if (closeBtn) node.push(h("Button", {
  661. "on": {
  662. "click": function click() {
  663. return _this8.onCancel() !== false && _this8.closeModel(true);
  664. }
  665. }
  666. }, [closeBtnText]));
  667. if (okBtn) node.push(h("Button", {
  668. "attrs": {
  669. "type": "primary"
  670. },
  671. "on": {
  672. "click": function click() {
  673. return _this8.onOk() !== false && _this8.closeModel();
  674. }
  675. }
  676. }, [okBtnText]));
  677. return node;
  678. }
  679. },
  680. render: function render() {
  681. var _this9 = this;
  682. var h = arguments[0];
  683. var type = this.type;
  684. var node;
  685. if (type === 'input') node = this.makeInput();else if (type === 'image') node = this.makeImages();else node = this.makeFiles();
  686. var _this$$props2 = this.$props,
  687. width = _this$$props2.width,
  688. height = _this$$props2.height,
  689. src = _this$$props2.src,
  690. title = _this$$props2.title,
  691. modalTitle = _this$$props2.modalTitle;
  692. this.$nextTick(function () {
  693. if (_this9.$refs.frame) {
  694. _this9.frameLoad(_this9.$refs.frame.contentWindow || {});
  695. }
  696. });
  697. return h("div", {
  698. "class": "_fc-frame"
  699. }, [node, h("Modal", helper([{}, {
  700. "props": {
  701. mask: this.previewMask,
  702. title: modalTitle,
  703. footerHide: true
  704. }
  705. }, {
  706. "model": {
  707. value: _this9.previewVisible,
  708. callback: function callback($$v) {
  709. _this9.previewVisible = $$v;
  710. }
  711. }
  712. }]), [h("img", {
  713. "style": "width: 100%",
  714. "attrs": {
  715. "src": this.previewImage
  716. }
  717. })]), h("Modal", helper([{}, {
  718. "props": _objectSpread2({
  719. width: width,
  720. title: title
  721. }, this.modal)
  722. }, {
  723. "on": {
  724. "on-cancel": function onCancel() {
  725. return _this9.closeModel(true);
  726. }
  727. },
  728. "model": {
  729. value: _this9.frameVisible,
  730. callback: function callback($$v) {
  731. _this9.frameVisible = $$v;
  732. }
  733. }
  734. }]), [this.frameVisible || !this.reload ? h("iframe", {
  735. "ref": "frame",
  736. "attrs": {
  737. "src": src,
  738. "frameBorder": "0"
  739. },
  740. "style": {
  741. 'height': height,
  742. 'border': '0 none',
  743. 'width': '100%'
  744. }
  745. }) : null, h("div", {
  746. "slot": "footer"
  747. }, [this.makeFooter()])])]);
  748. },
  749. mounted: function mounted() {
  750. this.$on('fc.closeModal', this.closeModal);
  751. }
  752. };
  753. }
  754. var frame = createFrame({
  755. fileIcon: 'md-document',
  756. fileUpIcon: 'ios-folder-open'
  757. });
  758. frame.v2 = createFrame({
  759. fileIcon: 'document-text',
  760. fileUpIcon: 'folder'
  761. });
  762. var NAME$2 = 'fcRadio';
  763. var Radio = {
  764. name: NAME$2,
  765. props: {
  766. formCreateInject: {
  767. type: Object,
  768. required: true
  769. },
  770. value: {}
  771. },
  772. watch: {
  773. 'formCreateInject.options': {
  774. handler: function handler() {
  775. this.update();
  776. },
  777. deep: true
  778. },
  779. value: function value() {
  780. this.update();
  781. }
  782. },
  783. data: function data() {
  784. return {
  785. trueValue: []
  786. };
  787. },
  788. methods: {
  789. options: function options() {
  790. var opt = this.formCreateInject.options;
  791. return Array.isArray(opt) ? opt : [];
  792. },
  793. onInput: function onInput(n) {
  794. this.$emit('input', this.options().filter(function (opt) {
  795. return opt.label === n;
  796. }).reduce(function (initial, opt) {
  797. return opt.value;
  798. }, ''));
  799. },
  800. update: function update() {
  801. var _this = this;
  802. this.trueValue = this.options().filter(function (opt) {
  803. return opt.value === _this.value;
  804. }).reduce(function (initial, opt) {
  805. return opt.label;
  806. }, '');
  807. }
  808. },
  809. created: function created() {
  810. this.update();
  811. },
  812. render: function render() {
  813. var h = arguments[0];
  814. return h("RadioGroup", helper([{}, this.formCreateInject.prop, {}, {
  815. "props": {
  816. value: this.trueValue
  817. }
  818. }, {
  819. "on": {
  820. "input": this.onInput
  821. }
  822. }]), [this.options().map(function (opt, index) {
  823. var props = _objectSpread2({}, opt);
  824. delete props.value;
  825. return h("Radio", helper([{}, {
  826. "props": props
  827. }, {
  828. "key": '' + index + '-' + opt.value
  829. }]));
  830. }), getSlot(this.$slots)]);
  831. }
  832. };
  833. var is = {
  834. type: function type(arg, _type) {
  835. return Object.prototype.toString.call(arg) === '[object ' + _type + ']';
  836. },
  837. Undef: function Undef(v) {
  838. return v === undefined || v === null;
  839. },
  840. Element: function Element(arg) {
  841. return _typeof(arg) === 'object' && arg !== null && arg.nodeType === 1 && !is.Object(arg);
  842. },
  843. trueArray: function trueArray(data) {
  844. return Array.isArray(data) && data.length > 0;
  845. },
  846. Function: function Function(v) {
  847. var type = this.getType(v);
  848. return type === 'Function' || type === 'AsyncFunction';
  849. },
  850. getType: function getType(v) {
  851. var str = Object.prototype.toString.call(v);
  852. return /^\[object (.*)\]$/.exec(str)[1];
  853. },
  854. empty: function empty(value) {
  855. if (value === undefined || value === null) {
  856. return true;
  857. }
  858. if (Array.isArray(value) && Array.isArray(value) && !value.length) {
  859. return true;
  860. }
  861. return typeof value === 'string' && !value;
  862. }
  863. };
  864. ['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
  865. is[t] = function (arg) {
  866. return is.type(arg, t);
  867. };
  868. });
  869. function hasProperty(rule, k) {
  870. return {}.hasOwnProperty.call(rule, k);
  871. }
  872. var NAME$3 = 'fcSelect';
  873. var Select = {
  874. name: NAME$3,
  875. functional: true,
  876. props: {
  877. formCreateInject: {
  878. type: Object,
  879. required: true
  880. }
  881. },
  882. render: function render(h, ctx) {
  883. var options = ctx.props.formCreateInject.options;
  884. return h("Select", helper([{}, ctx.data]), [(Array.isArray(options) ? options : []).map(function (props, index) {
  885. var slot = props.slot;
  886. return h("Option", helper([{}, {
  887. "props": props
  888. }, {
  889. "key": '' + index + '-' + props.value
  890. }]), [slot ? h("template", {
  891. "slot": props.slotName || 'default'
  892. }, [is.Function(slot) ? props.slot(h) : slot]) : null]);
  893. }), ctx.children]);
  894. }
  895. };
  896. var NAME$4 = 'fcTree';
  897. var Tree = {
  898. name: NAME$4,
  899. props: {
  900. formCreateInject: {
  901. type: Object,
  902. required: true
  903. },
  904. type: {
  905. type: String,
  906. "default": 'checked'
  907. },
  908. value: {
  909. type: [Array, String, Number],
  910. "default": function _default() {
  911. return [];
  912. }
  913. }
  914. },
  915. data: function data() {
  916. return {
  917. treeData: []
  918. };
  919. },
  920. watch: {
  921. value: function value(n) {
  922. this.setStatus(n);
  923. }
  924. },
  925. created: function created() {
  926. this.setStatus(this.value);
  927. },
  928. methods: {
  929. setStatus: function setStatus(value) {
  930. var n = toArray(value);
  931. var data = this.formCreateInject.prop.props.data;
  932. this.type === 'selected' ? this.checked(data, n, 'selected') : this.checked(data, n, 'checked');
  933. this.$forceUpdate();
  934. },
  935. checked: function checked(_data, value, type) {
  936. var _this = this;
  937. _data.forEach(function (node) {
  938. _this.$set(node, type, value.indexOf(node.id) !== -1);
  939. if (node.children !== undefined && Array.isArray(node.children)) _this.checked(node.children, value, type);
  940. });
  941. },
  942. onInput: function onInput(list) {
  943. this.$emit('input', list.map(function (node) {
  944. return node.id;
  945. }));
  946. }
  947. },
  948. render: function render() {
  949. var h = arguments[0];
  950. var on = {};
  951. if (this.type === 'selected') {
  952. on['on-select-change'] = this.onInput;
  953. } else {
  954. on['on-check-change'] = this.onInput;
  955. }
  956. return h("Tree", helper([{}, this.formCreateInject.prop, {
  957. "ref": "tree"
  958. }, {
  959. "on": on
  960. }]), [getSlot(this.$slots)]);
  961. }
  962. };
  963. var css_248z$1 = "._fc-upload .fc-upload-btn {\n border: 1px dashed #c0ccda;\n cursor: pointer;\n}\n\n._fc-upload .fc-upload-cover {\n opacity: 0;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background: rgba(0, 0, 0, .6);\n transition: opacity .3s;\n}\n\n._fc-upload .fc-upload-cover i {\n color: #fff;\n font-size: 20px;\n cursor: pointer;\n margin: 0 2px;\n}\n\n._fc-upload .fc-files:hover .fc-upload-cover {\n opacity: 1;\n}\n\n._fc-upload .ivu-upload-list {\n margin-top: 0;\n}\n\n._fc-upload .fc-files img {\n width: 100%;\n height: 100%;\n display: inline-block;\n vertical-align: top;\n}\n\n._fc-upload .fc-upload-btn, ._fc-upload .fc-files {\n display: inline-block;\n width: 58px;\n height: 58px;\n text-align: center;\n line-height: 58px;\n border: 1px solid #c0ccda;\n border-radius: 4px;\n overflow: hidden;\n background: #fff;\n position: relative;\n box-shadow: 2px 2px 5px rgba(0, 0, 0, .1);\n margin-right: 4px;\n box-sizing: border-box;\n}\n";
  964. styleInject(css_248z$1);
  965. function parseFile(file) {
  966. return {
  967. url: file,
  968. name: getFileName(file)
  969. };
  970. }
  971. function getFileName(file) {
  972. return ('' + file).split('/').pop();
  973. }
  974. var NAME$5 = 'fcUpload';
  975. function createUpload(config) {
  976. return {
  977. name: NAME$5,
  978. props: {
  979. formCreateInject: {
  980. type: Object,
  981. required: true
  982. },
  983. onHandle: {
  984. type: Function,
  985. "default": function _default(file) {
  986. this.previewImage = file.url;
  987. this.previewVisible = true;
  988. }
  989. },
  990. uploadType: {
  991. type: String,
  992. "default": 'file'
  993. },
  994. maxLength: {
  995. type: Number,
  996. "default": 0
  997. },
  998. allowRemove: {
  999. type: Boolean,
  1000. "default": true
  1001. },
  1002. modalTitle: String,
  1003. handleIcon: {
  1004. type: [String, Boolean],
  1005. "default": function _default() {
  1006. return undefined;
  1007. }
  1008. },
  1009. value: [Array, String]
  1010. },
  1011. data: function data() {
  1012. return {
  1013. uploadList: [],
  1014. previewVisible: false,
  1015. previewImage: '',
  1016. cacheFiles: []
  1017. };
  1018. },
  1019. created: function created() {
  1020. if (this.formCreateInject.prop.props.showUploadList === undefined) this.formCreateInject.prop.props.showUploadList = false;
  1021. this.formCreateInject.prop.props.defaultFileList = toArray(this.value).map(parseFile);
  1022. },
  1023. watch: {
  1024. value: function value(n) {
  1025. if (this.$refs.upload.fileList.every(function (file) {
  1026. return !file.status || file.status === 'finished';
  1027. })) {
  1028. this.$refs.upload.fileList = toArray(n).map(parseFile);
  1029. this.uploadList = this.$refs.upload.fileList;
  1030. }
  1031. },
  1032. maxLength: function maxLength(n, o) {
  1033. if (o === 1 || n === 1) this.update();
  1034. }
  1035. },
  1036. methods: {
  1037. key: function key(unique) {
  1038. return unique;
  1039. },
  1040. isDisabled: function isDisabled() {
  1041. return this.formCreateInject.prop.props.disabled === true;
  1042. },
  1043. onRemove: function onRemove(file) {
  1044. if (this.isDisabled()) return;
  1045. this.$refs.upload.handleRemove(file);
  1046. },
  1047. handleClick: function handleClick(file) {
  1048. this.onHandle(file);
  1049. },
  1050. makeItem: function makeItem(file, index) {
  1051. var h = this.$createElement;
  1052. return this.uploadType === 'image' ? h("img", {
  1053. "attrs": {
  1054. "src": file.url
  1055. },
  1056. "key": this.key('img' + index)
  1057. }) : h("icon", helper([{}, {
  1058. "props": {
  1059. type: config.fileIcon,
  1060. size: 40
  1061. }
  1062. }, {
  1063. "key": this.key('i' + index)
  1064. }]));
  1065. },
  1066. makeRemoveIcon: function makeRemoveIcon(file, index) {
  1067. var _this = this;
  1068. var h = this.$createElement;
  1069. return h("icon", {
  1070. "attrs": {
  1071. "type": 'ios-trash-outline'
  1072. },
  1073. "on": {
  1074. "click": function click() {
  1075. return _this.onRemove(file);
  1076. }
  1077. },
  1078. "key": this.key('ri' + index)
  1079. });
  1080. },
  1081. makeHandleIcon: function makeHandleIcon(file, index) {
  1082. var _this2 = this;
  1083. var h = this.$createElement;
  1084. return h("icon", {
  1085. "attrs": {
  1086. "type": this.handleIcon === true || this.handleIcon === undefined ? 'ios-eye-outline' : this.handleIcon
  1087. },
  1088. "on": {
  1089. "click": function click() {
  1090. return _this2.handleClick(file);
  1091. }
  1092. },
  1093. "key": this.key('hi' + index)
  1094. });
  1095. },
  1096. makeProgress: function makeProgress(file, index) {
  1097. var h = this.$createElement;
  1098. return h("Progress", helper([{}, {
  1099. "props": {
  1100. percent: file.percentage,
  1101. hideInfo: true
  1102. }
  1103. }, {
  1104. "style": "width:90%",
  1105. "key": this.key('pg' + index)
  1106. }]));
  1107. },
  1108. makeIcons: function makeIcons(file, index) {
  1109. var h = this.$createElement;
  1110. var icons = [];
  1111. if (this.allowRemove || this.handleIcon !== false) {
  1112. if (this.uploadType !== 'file' && this.handleIcon !== false || this.uploadType === 'file' && this.handleIcon) icons.push(this.makeHandleIcon(file, index));
  1113. if (this.allowRemove) icons.push(this.makeRemoveIcon(file, index));
  1114. return h("div", {
  1115. "class": "fc-upload-cover"
  1116. }, [icons]);
  1117. }
  1118. },
  1119. makeFiles: function makeFiles() {
  1120. var _this3 = this;
  1121. var h = this.$createElement;
  1122. return this.uploadList.map(function (file, index) {
  1123. return _this3.$scopedSlots.fileList ? _this3.$scopedSlots.fileList({
  1124. file: file,
  1125. index: index,
  1126. vm: _this3
  1127. }) : h("div", {
  1128. "key": _this3.key(index),
  1129. "class": "fc-files"
  1130. }, [file.showProgress ? _this3.makeProgress(file, index) : [_this3.makeItem(file, index), _this3.makeIcons(file, index)]]);
  1131. });
  1132. },
  1133. makeUpload: function makeUpload() {
  1134. var h = this.$createElement;
  1135. var isShow = !this.maxLength || this.maxLength > this.uploadList.length;
  1136. return h("Upload", helper([{}, this.formCreateInject.prop, {
  1137. "ref": "upload",
  1138. "style": {
  1139. display: 'inline-block'
  1140. },
  1141. "key": this.key('upload')
  1142. }]), [isShow ? h("template", {
  1143. "slot": "default"
  1144. }, [this.$slots["default"] || h("div", {
  1145. "class": "fc-upload-btn"
  1146. }, [h("icon", helper([{}, {
  1147. "props": {
  1148. type: this.uploadType === 'file' ? 'ios-cloud-upload-outline' : config.imgUpIcon,
  1149. size: 20
  1150. }
  1151. }]))])]) : null, getSlot(this.$slots, ['default'])]);
  1152. },
  1153. update: function update() {
  1154. var files = this.$refs.upload.fileList.map(function (file) {
  1155. return file.url;
  1156. }).filter(function (url) {
  1157. return url !== undefined;
  1158. });
  1159. if (this.cacheFiles.length !== files.length) {
  1160. this.cacheFiles = _toConsumableArray(files);
  1161. this.$emit('input', this.maxLength === 1 ? files[0] || '' : files);
  1162. }
  1163. },
  1164. handleCancel: function handleCancel() {
  1165. this.previewVisible = false;
  1166. }
  1167. },
  1168. render: function render() {
  1169. var _this4 = this;
  1170. var h = arguments[0];
  1171. if (this.$refs.upload) {
  1172. if (this.formCreateInject.prop.props.showUploadList === undefined) this.formCreateInject.prop.props.showUploadList = this.$refs.upload.showUploadList;
  1173. this.formCreateInject.prop.props.defaultFileList = this.$refs.upload.defaultFileList;
  1174. }
  1175. return h("div", {
  1176. "class": "_fc-upload"
  1177. }, [[this.formCreateInject.prop.props.showUploadList ? [] : this.makeFiles(), this.makeUpload()], h("Modal", helper([{}, {
  1178. "props": {
  1179. title: this.modalTitle,
  1180. footerHide: true
  1181. }
  1182. }, {
  1183. "model": {
  1184. value: _this4.previewVisible,
  1185. callback: function callback($$v) {
  1186. _this4.previewVisible = $$v;
  1187. }
  1188. }
  1189. }]), [h("img", {
  1190. "attrs": {
  1191. "alt": "example",
  1192. "src": this.previewImage
  1193. },
  1194. "style": "width: 100%"
  1195. })])]);
  1196. },
  1197. mounted: function mounted() {
  1198. var _this5 = this;
  1199. this.uploadList = this.$refs.upload.fileList;
  1200. this.$watch(function () {
  1201. return _this5.$refs.upload.fileList;
  1202. }, function () {
  1203. _this5.update();
  1204. }, {
  1205. deep: true
  1206. });
  1207. }
  1208. };
  1209. }
  1210. var upload = createUpload({
  1211. fileIcon: 'md-document',
  1212. imgUpIcon: 'md-images'
  1213. });
  1214. upload.v2 = createUpload({
  1215. fileIcon: 'document-text',
  1216. imgUpIcon: 'image'
  1217. });
  1218. function $set(target, field, value) {
  1219. Vue.set(target, field, value);
  1220. }
  1221. function $del(target, field) {
  1222. Vue["delete"](target, field);
  1223. }
  1224. function deepExtend(origin) {
  1225. var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1226. var mode = arguments.length > 2 ? arguments[2] : undefined;
  1227. var isArr = false;
  1228. for (var key in target) {
  1229. if (Object.prototype.hasOwnProperty.call(target, key)) {
  1230. var clone = target[key];
  1231. if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
  1232. var nst = origin[key] === undefined;
  1233. if (isArr) {
  1234. isArr = false;
  1235. nst && $set(origin, key, []);
  1236. } else if (clone._clone && mode !== undefined) {
  1237. if (mode) {
  1238. clone = clone.getRule();
  1239. nst && $set(origin, key, {});
  1240. } else {
  1241. $set(origin, key, clone._clone());
  1242. continue;
  1243. }
  1244. } else {
  1245. nst && $set(origin, key, {});
  1246. }
  1247. origin[key] = deepExtend(origin[key], clone, mode);
  1248. } else {
  1249. $set(origin, key, clone);
  1250. if (!is.Undef(clone)) {
  1251. if (!is.Undef(clone.__json)) {
  1252. origin[key].__json = clone.__json;
  1253. }
  1254. if (!is.Undef(clone.__origin)) {
  1255. origin[key].__origin = clone.__origin;
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
  1262. return !v || !v.__ctrl;
  1263. }) : origin;
  1264. }
  1265. function deepCopy(value) {
  1266. return deepExtend({}, {
  1267. value: value
  1268. }).value;
  1269. }
  1270. var _extends$1 = Object.assign || function (a) {
  1271. for (var b, c = 1; c < arguments.length; c++) {
  1272. for (var d in b = arguments[c], b) {
  1273. Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
  1274. }
  1275. }
  1276. return a;
  1277. };
  1278. function extend() {
  1279. return _extends$1.apply(this, arguments);
  1280. }
  1281. var NAME$6 = 'fcGroup';
  1282. function createGroup(config) {
  1283. return {
  1284. name: NAME$6,
  1285. props: {
  1286. field: String,
  1287. rule: [Array, Object],
  1288. rules: Array,
  1289. expand: Number,
  1290. options: Object,
  1291. formCreateInject: {
  1292. type: Object,
  1293. required: true
  1294. },
  1295. button: {
  1296. type: Boolean,
  1297. "default": true
  1298. },
  1299. max: {
  1300. type: Number,
  1301. "default": 0
  1302. },
  1303. min: {
  1304. type: Number,
  1305. "default": 0
  1306. },
  1307. value: {
  1308. type: Array,
  1309. "default": function _default() {
  1310. return [];
  1311. }
  1312. },
  1313. defaultValue: Object,
  1314. disabled: {
  1315. type: Boolean,
  1316. "default": false
  1317. },
  1318. syncDisabled: {
  1319. type: Boolean,
  1320. "default": true
  1321. },
  1322. fontSize: {
  1323. type: Number,
  1324. "default": 28
  1325. },
  1326. onBeforeRemove: {
  1327. type: Function,
  1328. "default": function _default() {}
  1329. },
  1330. onBeforeAdd: {
  1331. type: Function,
  1332. "default": function _default() {}
  1333. }
  1334. },
  1335. data: function data() {
  1336. return {
  1337. len: 0,
  1338. cacheRule: {},
  1339. cacheValue: {},
  1340. type: undefined
  1341. };
  1342. },
  1343. computed: {
  1344. formRule: function formRule() {
  1345. if (this.rules) {
  1346. return this.rules;
  1347. }
  1348. if (this.rule) {
  1349. return Array.isArray(this.rule) ? this.rule : [this.rule];
  1350. }
  1351. return [];
  1352. }
  1353. },
  1354. watch: {
  1355. formRule: {
  1356. handler: function handler(n, o) {
  1357. var _this = this;
  1358. Object.keys(this.cacheRule).forEach(function (v) {
  1359. var item = _this.cacheRule[v];
  1360. if (item.$f) {
  1361. var val = item.$f.formData();
  1362. if (n === o) {
  1363. item.$f.deferSyncValue(function () {
  1364. deepExtend(item.rule, n);
  1365. item.$f.setValue(val);
  1366. }, true);
  1367. } else {
  1368. var _val = item.$f.formData();
  1369. item.$f.once('reloading', function () {
  1370. item.$f.setValue(_val);
  1371. });
  1372. item.rule = deepCopy(n);
  1373. }
  1374. }
  1375. });
  1376. },
  1377. deep: true
  1378. },
  1379. disabled: function disabled(n) {
  1380. if (this.syncDisabled) {
  1381. var lst = this.cacheRule;
  1382. Object.keys(lst).forEach(function (k) {
  1383. lst[k].$f.disabled(n);
  1384. });
  1385. }
  1386. },
  1387. expand: function expand(n) {
  1388. var d = n - this.value.length;
  1389. if (d > 0) {
  1390. this.expandRule(d);
  1391. }
  1392. },
  1393. value: function value(n) {
  1394. var _this2 = this;
  1395. n = n || [];
  1396. var keys = Object.keys(this.cacheRule),
  1397. total = keys.length,
  1398. len = total - n.length;
  1399. if (len < 0) {
  1400. for (var i = len; i < 0; i++) {
  1401. this.addRule(n.length + i);
  1402. }
  1403. for (var _i = 0; _i < total; _i++) {
  1404. this.setValue(keys[_i], n[_i]);
  1405. }
  1406. } else {
  1407. if (len > 0) {
  1408. for (var _i2 = 0; _i2 < len; _i2++) {
  1409. this.removeRule(keys[total - _i2 - 1]);
  1410. }
  1411. }
  1412. n.forEach(function (val, i) {
  1413. _this2.setValue(keys[i], n[i]);
  1414. });
  1415. }
  1416. }
  1417. },
  1418. methods: {
  1419. _value: function _value(v) {
  1420. return v && hasProperty(v, this.field) ? v[this.field] : v;
  1421. },
  1422. cache: function cache(k, val) {
  1423. this.cacheValue[k] = JSON.stringify(val);
  1424. },
  1425. input: function input(value) {
  1426. this.$emit('input', value);
  1427. this.$emit('change', value);
  1428. },
  1429. formData: function formData(key, _formData) {
  1430. var _this3 = this;
  1431. var cacheRule = this.cacheRule;
  1432. var keys = Object.keys(cacheRule);
  1433. if (keys.filter(function (k) {
  1434. return cacheRule[k].$f;
  1435. }).length !== keys.length) {
  1436. return;
  1437. }
  1438. var value = keys.map(function (k) {
  1439. var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
  1440. var value = _this3.field ? data[_this3.field] || null : data;
  1441. _this3.cache(k, value);
  1442. return value;
  1443. });
  1444. this.input(value);
  1445. },
  1446. setValue: function setValue(key, value) {
  1447. var field = this.field,
  1448. $f = this.cacheRule[key].$f;
  1449. if (field) {
  1450. value = _defineProperty({}, field, this._value(value));
  1451. }
  1452. if (this.cacheValue[key] === JSON.stringify(field ? value[field] : value)) {
  1453. return;
  1454. }
  1455. this.cache(key, value);
  1456. $f.coverValue(value || {});
  1457. },
  1458. addRule: function addRule(i, emit) {
  1459. var _this4 = this;
  1460. var rule = this.formCreateInject.form.copyRules(this.formRule);
  1461. var options = this.options ? _objectSpread2({}, this.options) : {
  1462. submitBtn: false,
  1463. resetBtn: false
  1464. };
  1465. if (this.defaultValue) {
  1466. if (!options.formData) options.formData = {};
  1467. var defVal = deepCopy(this.defaultValue);
  1468. extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
  1469. }
  1470. this.$set(this.cacheRule, ++this.len, {
  1471. rule: rule,
  1472. options: options
  1473. });
  1474. if (emit) {
  1475. this.$nextTick(function () {
  1476. return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
  1477. });
  1478. }
  1479. },
  1480. add$f: function add$f(i, key, $f) {
  1481. var _this5 = this;
  1482. this.cacheRule[key].$f = $f;
  1483. this.formData(key, $f.formData());
  1484. this.$nextTick(function () {
  1485. if (_this5.syncDisabled) {
  1486. $f.disabled(_this5.disabled);
  1487. }
  1488. _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
  1489. });
  1490. },
  1491. removeRule: function removeRule(key, emit) {
  1492. var _this6 = this;
  1493. var index = Object.keys(this.cacheRule).indexOf(key);
  1494. this.$delete(this.cacheRule, key);
  1495. this.$delete(this.cacheValue, key);
  1496. if (emit) {
  1497. this.$nextTick(function () {
  1498. return _this6.$emit('remove', index);
  1499. });
  1500. }
  1501. },
  1502. add: function add(i) {
  1503. if (this.disabled || false === this.onBeforeAdd(this.value)) {
  1504. return;
  1505. }
  1506. this.addRule(i, true);
  1507. },
  1508. del: function del(index, key) {
  1509. if (this.disabled || false === this.onBeforeRemove(this.value, index)) {
  1510. return;
  1511. }
  1512. this.removeRule(key, true);
  1513. this.value.splice(index, 1);
  1514. this.input(this.value);
  1515. },
  1516. addIcon: function addIcon(key) {
  1517. var h = this.$createElement;
  1518. return h("Icon", {
  1519. "key": "a".concat(key),
  1520. "attrs": {
  1521. "type": config.addIcon
  1522. },
  1523. "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#000'),
  1524. "on": {
  1525. "click": this.add
  1526. }
  1527. });
  1528. },
  1529. delIcon: function delIcon(index, key) {
  1530. var _this7 = this;
  1531. var h = this.$createElement;
  1532. return h("Icon", {
  1533. "key": "d".concat(key),
  1534. "attrs": {
  1535. "type": config.removeIcon
  1536. },
  1537. "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer', ";"),
  1538. "on": {
  1539. "click": function click() {
  1540. return _this7.del(index, key);
  1541. }
  1542. }
  1543. });
  1544. },
  1545. makeIcon: function makeIcon(total, index, key) {
  1546. var _this8 = this;
  1547. if (this.$scopedSlots.button) {
  1548. return this.$scopedSlots.button({
  1549. total: total,
  1550. index: index,
  1551. vm: this,
  1552. key: key,
  1553. del: function del() {
  1554. return _this8.del(index, key);
  1555. },
  1556. add: this.add
  1557. });
  1558. }
  1559. if (index === 0) {
  1560. return [this.max !== 0 && total >= this.max ? null : this.addIcon(key), this.min === 0 || total > this.min ? this.delIcon(index, key) : null];
  1561. }
  1562. if (index >= this.min) {
  1563. return this.delIcon(index, key);
  1564. }
  1565. },
  1566. emitEvent: function emitEvent(name, args, index, key) {
  1567. this.$emit.apply(this, [name].concat(_toConsumableArray(args), [this.cacheRule[key].$f, index]));
  1568. },
  1569. expandRule: function expandRule(n) {
  1570. for (var i = 0; i < n; i++) {
  1571. this.value.push(this.field ? null : {});
  1572. }
  1573. }
  1574. },
  1575. created: function created() {
  1576. this.type = this.formCreateInject.form.$form();
  1577. var d = (this.expand || 0) - this.value.length;
  1578. if (d > 0) {
  1579. this.expandRule(d);
  1580. }
  1581. for (var i = 0; i < this.value.length; i++) {
  1582. this.addRule(i);
  1583. }
  1584. },
  1585. render: function render() {
  1586. var _this9 = this;
  1587. var h = arguments[0];
  1588. var keys = Object.keys(this.cacheRule);
  1589. var button = this.button;
  1590. var Type = this.type;
  1591. return keys.length === 0 ? this.$scopedSlots["default"] ? this.$scopedSlots["default"]({
  1592. vm: this,
  1593. add: this.add
  1594. }) : h("Icon", {
  1595. "key": 'a_def',
  1596. "attrs": {
  1597. "type": config.addIcon
  1598. },
  1599. "style": "font-size:".concat(this.fontSize, "px;vertical-align:middle;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer', ";"),
  1600. "on": {
  1601. "click": this.add
  1602. }
  1603. }) : h("div", {
  1604. "key": 'con'
  1605. }, [keys.map(function (key, index) {
  1606. var _this9$cacheRule$key = _this9.cacheRule[key],
  1607. rule = _this9$cacheRule$key.rule,
  1608. options = _this9$cacheRule$key.options;
  1609. return h("Row", {
  1610. "attrs": {
  1611. "align": "middle",
  1612. "type": "flex"
  1613. },
  1614. "key": key,
  1615. "style": "border-bottom:1px dashed #dcdee2;margin-bottom:10px;"
  1616. }, [h("Col", {
  1617. "attrs": {
  1618. "span": button ? 20 : 24
  1619. }
  1620. }, [h(Type, helper([{
  1621. "key": key
  1622. }, {
  1623. "on": {
  1624. 'update:value': function updateValue(formData) {
  1625. return _this9.formData(key, formData);
  1626. },
  1627. 'emit-event': function emitEvent(name) {
  1628. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1629. args[_key - 1] = arguments[_key];
  1630. }
  1631. return _this9.emitEvent(name, args, index, key);
  1632. },
  1633. input: function input($f) {
  1634. return _this9.add$f(index, key, $f);
  1635. }
  1636. }
  1637. }, {}, {
  1638. "props": {
  1639. value: _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.value[index])) : _this9.value[index],
  1640. rule: rule,
  1641. option: options,
  1642. extendOption: true,
  1643. inFor: true
  1644. }
  1645. }]))]), button ? h("Col", helper([{}, {
  1646. "props": {
  1647. span: 2,
  1648. pull: 1,
  1649. push: 1
  1650. }
  1651. }]), [_this9.makeIcon(keys.length, index, key)]) : null]);
  1652. })]);
  1653. }
  1654. };
  1655. }
  1656. var group = createGroup({
  1657. removeIcon: 'ios-remove-circle-outline',
  1658. addIcon: 'ios-add-circle-outline'
  1659. });
  1660. group.v2 = createGroup({
  1661. addIcon: 'ios-plus-outline',
  1662. removeIcon: 'ios-minus-outline'
  1663. });
  1664. var NAME$7 = 'fcSubForm';
  1665. var Sub = {
  1666. name: NAME$7,
  1667. props: {
  1668. rule: Array,
  1669. options: Object,
  1670. formCreateInject: {
  1671. type: Object,
  1672. required: true
  1673. },
  1674. value: {
  1675. type: Object,
  1676. "default": function _default() {
  1677. return {};
  1678. }
  1679. },
  1680. disabled: {
  1681. type: Boolean,
  1682. "default": false
  1683. },
  1684. syncDisabled: {
  1685. type: Boolean,
  1686. "default": true
  1687. }
  1688. },
  1689. data: function data() {
  1690. return {
  1691. cacheRule: {},
  1692. cacheValue: {},
  1693. type: undefined
  1694. };
  1695. },
  1696. watch: {
  1697. disabled: function disabled(n) {
  1698. this.syncDisabled && this.cacheRule.$f.disabled(n);
  1699. },
  1700. value: function value(n) {
  1701. this.setValue(n);
  1702. }
  1703. },
  1704. methods: {
  1705. formData: function formData(value) {
  1706. this.cacheValue = JSON.stringify(value);
  1707. this.$emit('input', value);
  1708. this.$emit('change', value);
  1709. },
  1710. setValue: function setValue(value) {
  1711. var str = JSON.stringify(value);
  1712. if (this.cacheValue === str) {
  1713. return;
  1714. }
  1715. this.cacheValue = str;
  1716. this.cacheRule.$f.coverValue(value || {});
  1717. },
  1718. addRule: function addRule() {
  1719. var options = this.options ? this.options : {
  1720. submitBtn: false,
  1721. resetBtn: false
  1722. };
  1723. options.formData = _objectSpread2({}, this.value || {});
  1724. this.cacheRule = {
  1725. rule: this.rule,
  1726. options: options
  1727. };
  1728. },
  1729. add$f: function add$f($f) {
  1730. var _this = this;
  1731. this.cacheRule.$f = $f;
  1732. this.$nextTick(function () {
  1733. _this.syncDisabled && $f.disabled(_this.disabled);
  1734. _this.$emit('itemMounted', $f);
  1735. });
  1736. },
  1737. emitEvent: function emitEvent(name) {
  1738. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1739. args[_key - 1] = arguments[_key];
  1740. }
  1741. this.$emit.apply(this, [name].concat(args));
  1742. }
  1743. },
  1744. created: function created() {
  1745. this.addRule();
  1746. this.type = this.formCreateInject.form.$form();
  1747. },
  1748. render: function render() {
  1749. var h = arguments[0];
  1750. var _this$cacheRule = this.cacheRule,
  1751. rule = _this$cacheRule.rule,
  1752. options = _this$cacheRule.options;
  1753. var Type = this.type;
  1754. return h(Type, helper([{}, {
  1755. "on": {
  1756. 'update:value': this.formData,
  1757. 'emit-event': this.emitEvent,
  1758. input: this.add$f
  1759. }
  1760. }, {}, {
  1761. "props": {
  1762. rule: rule,
  1763. option: options,
  1764. extendOption: true
  1765. }
  1766. }]));
  1767. }
  1768. };
  1769. var components = [Checkbox, Radio, Select, Tree, Sub, frame, upload, group];
  1770. var NAME$8 = 'FormCreate';
  1771. var getRuleInject = function getRuleInject(vm, parent) {
  1772. if (!vm || vm === parent) {
  1773. return;
  1774. }
  1775. if (vm.formCreateInject) {
  1776. return vm.formCreateInject;
  1777. }
  1778. if (vm.$parent) {
  1779. return getRuleInject(vm.$parent, parent);
  1780. }
  1781. };
  1782. function $FormCreate(FormCreate) {
  1783. return {
  1784. name: NAME$8,
  1785. componentName: NAME$8,
  1786. model: {
  1787. prop: 'api'
  1788. },
  1789. provide: function provide() {
  1790. return {
  1791. $pfc: this
  1792. };
  1793. },
  1794. inject: {
  1795. $pfc: {
  1796. "default": null
  1797. }
  1798. },
  1799. props: {
  1800. rule: {
  1801. type: Array,
  1802. required: true
  1803. },
  1804. option: {
  1805. type: Object,
  1806. "default": function _default() {
  1807. return {};
  1808. }
  1809. },
  1810. extendOption: Boolean,
  1811. value: Object,
  1812. api: Object,
  1813. name: String,
  1814. subForm: {
  1815. type: Boolean,
  1816. "default": true
  1817. },
  1818. inFor: Boolean
  1819. },
  1820. data: function data() {
  1821. return {
  1822. formData: undefined,
  1823. destroyed: false,
  1824. validate: {},
  1825. $f: undefined,
  1826. isShow: true,
  1827. unique: 1,
  1828. renderRule: _toConsumableArray(this.rule || []),
  1829. ctxInject: {},
  1830. updateValue: JSON.stringify(this.value || {}),
  1831. isMore: !!this.inFor
  1832. };
  1833. },
  1834. render: function render() {
  1835. return this.formCreate.render();
  1836. },
  1837. methods: {
  1838. _refresh: function _refresh() {
  1839. ++this.unique;
  1840. },
  1841. _renderRule: function _renderRule() {
  1842. this.renderRule = _toConsumableArray(this.rule || []);
  1843. },
  1844. _updateValue: function _updateValue(value) {
  1845. if (this.destroyed) return;
  1846. this.updateValue = JSON.stringify(value);
  1847. this.$emit('update:value', value);
  1848. }
  1849. },
  1850. watch: {
  1851. value: {
  1852. handler: function handler(n) {
  1853. if (JSON.stringify(n || {}) === this.updateValue) return;
  1854. this.$f.config.forceCoverValue ? this.$f.coverValue(n || {}) : this.$f.setValue(n || {});
  1855. },
  1856. deep: true
  1857. },
  1858. option: {
  1859. handler: function handler(n) {
  1860. this.formCreate.initOptions(n);
  1861. this.$f.refresh();
  1862. },
  1863. deep: true
  1864. },
  1865. rule: function rule(n) {
  1866. var _this = this;
  1867. if (n.length === this.renderRule.length && n.every(function (v) {
  1868. return _this.renderRule.indexOf(v) > -1;
  1869. })) return;
  1870. this.formCreate.$handle.reloadRule(n);
  1871. this._renderRule();
  1872. }
  1873. },
  1874. beforeCreate: function beforeCreate() {
  1875. var _this2 = this;
  1876. var _this$$options$propsD = this.$options.propsData,
  1877. rule = _this$$options$propsD.rule,
  1878. option = _this$$options$propsD.option;
  1879. this.formCreate = new FormCreate(this, rule, option);
  1880. Object.keys(this.formCreate.prop).forEach(function (k) {
  1881. extend(_this2.$options[k], _this2.formCreate.prop[k]);
  1882. });
  1883. this.$emit('beforeCreate', this.formCreate.api());
  1884. },
  1885. created: function created() {
  1886. var _this3 = this;
  1887. var vm = this,
  1888. fapi = this.formCreate.api();
  1889. var addSubForm = function addSubForm() {
  1890. if (vm.$pfc) {
  1891. var inject = getRuleInject(vm, vm.$pfc);
  1892. if (inject) {
  1893. var sub;
  1894. if (vm.isMore) {
  1895. sub = toArray(inject.getSubForm());
  1896. sub.push(fapi);
  1897. } else {
  1898. sub = fapi;
  1899. }
  1900. inject.subForm(sub);
  1901. }
  1902. }
  1903. };
  1904. var rmSubForm = function rmSubForm() {
  1905. var inject = getRuleInject(vm, vm.$pfc);
  1906. if (inject) {
  1907. if (vm.isMore) {
  1908. var sub = toArray(inject.getSubForm());
  1909. var idx = sub.indexOf(fapi);
  1910. if (idx > -1) {
  1911. sub.splice(idx, 1);
  1912. }
  1913. } else {
  1914. inject.subForm();
  1915. }
  1916. }
  1917. };
  1918. vm.$on('hook:beforeDestroy', function () {
  1919. rmSubForm();
  1920. });
  1921. this.$watch(function () {
  1922. return _this3.subForm;
  1923. }, function (n) {
  1924. n ? addSubForm() : rmSubForm();
  1925. }, {
  1926. immediate: true
  1927. });
  1928. }
  1929. };
  1930. }
  1931. var normalMerge$1 = ['attrs', 'props', 'domProps', 'scopedSlots'];
  1932. var toArrayMerge$1 = ['class', 'style', 'directives'];
  1933. var functionalMerge$1 = ['on', 'nativeOn'];
  1934. var mergeProps = function mergeProps(objects) {
  1935. var initial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1936. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1937. var _normalMerge = [].concat(normalMerge$1, _toConsumableArray(opt['normal'] || []));
  1938. var _toArrayMerge = [].concat(toArrayMerge$1, _toConsumableArray(opt['array'] || []));
  1939. var _functionalMerge = [].concat(functionalMerge$1, _toConsumableArray(opt['functional'] || []));
  1940. var propsMerge = opt['props'] || [];
  1941. return objects.reduce(function (a, b) {
  1942. for (var key in b) {
  1943. if (a[key]) {
  1944. if (propsMerge.indexOf(key) > -1) {
  1945. a[key] = mergeProps([b[key]], a[key]);
  1946. } else if (_normalMerge.indexOf(key) > -1) {
  1947. a[key] = _objectSpread2(_objectSpread2({}, a[key]), b[key]);
  1948. } else if (_toArrayMerge.indexOf(key) > -1) {
  1949. var arrA = a[key] instanceof Array ? a[key] : [a[key]];
  1950. var arrB = b[key] instanceof Array ? b[key] : [b[key]];
  1951. a[key] = [].concat(_toConsumableArray(arrA), _toConsumableArray(arrB));
  1952. } else if (_functionalMerge.indexOf(key) > -1) {
  1953. for (var event in b[key]) {
  1954. if (a[key][event]) {
  1955. var _arrA = a[key][event] instanceof Array ? a[key][event] : [a[key][event]];
  1956. var _arrB = b[key][event] instanceof Array ? b[key][event] : [b[key][event]];
  1957. a[key][event] = [].concat(_toConsumableArray(_arrA), _toConsumableArray(_arrB));
  1958. } else {
  1959. a[key][event] = b[key][event];
  1960. }
  1961. }
  1962. } else if (key === 'hook') {
  1963. for (var hook in b[key]) {
  1964. if (a[key][hook]) {
  1965. a[key][hook] = mergeFn$1(a[key][hook], b[key][hook]);
  1966. } else {
  1967. a[key][hook] = b[key][hook];
  1968. }
  1969. }
  1970. } else {
  1971. a[key] = b[key];
  1972. }
  1973. } else {
  1974. if (_normalMerge.indexOf(key) > -1 || _functionalMerge.indexOf(key) > -1 || propsMerge.indexOf(key) > -1) {
  1975. a[key] = _objectSpread2({}, b[key]);
  1976. } else if (_toArrayMerge.indexOf(key) > -1) {
  1977. a[key] = b[key] instanceof Array ? _toConsumableArray(b[key]) : _typeof(b[key]) === 'object' ? _objectSpread2({}, b[key]) : b[key];
  1978. } else a[key] = b[key];
  1979. }
  1980. }
  1981. return a;
  1982. }, initial);
  1983. };
  1984. var mergeFn$1 = function mergeFn(fn1, fn2) {
  1985. return function () {
  1986. fn1 && fn1.apply(this, arguments);
  1987. fn2 && fn2.apply(this, arguments);
  1988. };
  1989. };
  1990. var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'nativeEmit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'preview', 'component', 'cache'];
  1991. var arrayAttrs = ['validate', 'children', 'control'];
  1992. var normalAttrs = ['effect', 'deep'];
  1993. function attrs() {
  1994. return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
  1995. }
  1996. function format(type, msg, rule) {
  1997. return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
  1998. }
  1999. function tip(msg, rule) {
  2000. console.warn(format('tip', msg, rule));
  2001. }
  2002. function err(msg, rule) {
  2003. console.error(format('err', msg, rule));
  2004. }
  2005. function logError(e) {
  2006. err(e.toString());
  2007. console.error(e);
  2008. }
  2009. var PREFIX = '[[FORM-CREATE-PREFIX-';
  2010. var SUFFIX = '-FORM-CREATE-SUFFIX]]';
  2011. var $T = '$FN:';
  2012. var $TX = '$FNX:';
  2013. var FUNCTION = 'function';
  2014. function toJson(obj, space) {
  2015. return JSON.stringify(deepExtend([], obj, true), function (key, val) {
  2016. if (val && val._isVue === true) return undefined;
  2017. if (_typeof(val) !== FUNCTION) {
  2018. return val;
  2019. }
  2020. if (val.__json) {
  2021. return val.__json;
  2022. }
  2023. if (val.__origin) val = val.__origin;
  2024. if (val.__emit) return undefined;
  2025. return PREFIX + val + SUFFIX;
  2026. }, space);
  2027. }
  2028. function makeFn(fn) {
  2029. return eval('(' + FUNCTION + '(){return ' + fn + ' })()');
  2030. }
  2031. function parseFn(fn, mode) {
  2032. if (fn && is.String(fn) && fn.length > 4) {
  2033. var v = fn.trim();
  2034. var flag = false;
  2035. try {
  2036. if (v.indexOf(SUFFIX) > 0 && v.indexOf(PREFIX) === 0) {
  2037. v = v.replace(SUFFIX, '').replace(PREFIX, '');
  2038. flag = true;
  2039. } else if (v.indexOf($T) === 0) {
  2040. v = v.replace($T, '');
  2041. flag = true;
  2042. } else if (v.indexOf($TX) === 0) {
  2043. v = makeFn('function($inject){' + v.replace($TX, '') + '}');
  2044. v.__json = fn;
  2045. v.__inject = true;
  2046. return v;
  2047. } else if (!mode && v.indexOf(FUNCTION) === 0 && v !== FUNCTION) {
  2048. flag = true;
  2049. }
  2050. if (!flag) return fn;
  2051. var val = makeFn(v.indexOf(FUNCTION) === -1 && v.indexOf('(') !== 0 ? FUNCTION + ' ' + v : v);
  2052. val.__json = fn;
  2053. return val;
  2054. } catch (e) {
  2055. err("\u89E3\u6790\u5931\u8D25:".concat(v, "\n\nerr: ").concat(e));
  2056. return undefined;
  2057. }
  2058. }
  2059. return fn;
  2060. }
  2061. function parseJson(json, mode) {
  2062. return JSON.parse(json, function (k, v) {
  2063. if (is.Undef(v) || !v.indexOf) return v;
  2064. return parseFn(v, mode);
  2065. });
  2066. }
  2067. function enumerable(value, writable) {
  2068. return {
  2069. value: value,
  2070. enumerable: false,
  2071. configurable: false,
  2072. writable: !!writable
  2073. };
  2074. }
  2075. function copyRule(rule) {
  2076. return copyRules([rule])[0];
  2077. }
  2078. function copyRules(rules, mode) {
  2079. return deepExtend([], _toConsumableArray(rules), mode || false);
  2080. }
  2081. function mergeRule(rule, merge) {
  2082. mergeProps(Array.isArray(merge) ? merge : [merge], rule, {
  2083. array: arrayAttrs,
  2084. normal: normalAttrs
  2085. });
  2086. return rule;
  2087. }
  2088. function getRule(rule) {
  2089. var r = is.Function(rule.getRule) ? rule.getRule() : rule;
  2090. if (!r.type) {
  2091. r.type = 'input';
  2092. }
  2093. return r;
  2094. }
  2095. function mergeGlobal(target, merge) {
  2096. if (!target) return merge;
  2097. Object.keys(merge || {}).forEach(function (k) {
  2098. if (merge[k]) {
  2099. target[k] = mergeRule(target[k] || {}, merge[k]);
  2100. }
  2101. });
  2102. return target;
  2103. }
  2104. function funcProxy(that, proxy) {
  2105. Object.defineProperties(that, Object.keys(proxy).reduce(function (initial, k) {
  2106. initial[k] = {
  2107. get: function get() {
  2108. return proxy[k]();
  2109. }
  2110. };
  2111. return initial;
  2112. }, {}));
  2113. }
  2114. function byCtx(rule) {
  2115. return rule.__fc__ || (rule.__origin__ ? rule.__origin__.__fc__ : null);
  2116. }
  2117. function invoke(fn, def) {
  2118. try {
  2119. def = fn();
  2120. } catch (e) {
  2121. logError(e);
  2122. }
  2123. return def;
  2124. }
  2125. function baseRule() {
  2126. return {
  2127. props: {},
  2128. on: {},
  2129. options: [],
  2130. children: [],
  2131. hidden: false,
  2132. display: true,
  2133. value: undefined
  2134. };
  2135. }
  2136. function creatorFactory(name, init) {
  2137. return function (title, field, value) {
  2138. var props = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  2139. var maker = new Creator(name, title, field, value, props);
  2140. if (init) {
  2141. if (is.Function(init)) init(maker);else maker.props(init);
  2142. }
  2143. return maker;
  2144. };
  2145. }
  2146. function Creator(type, title, field, value, props) {
  2147. this._data = extend(baseRule(), {
  2148. type: type,
  2149. title: title,
  2150. field: field,
  2151. value: value,
  2152. props: props || {}
  2153. });
  2154. this.event = this.on;
  2155. }
  2156. extend(Creator.prototype, {
  2157. getRule: function getRule() {
  2158. return this._data;
  2159. },
  2160. setProp: function setProp(key, value) {
  2161. $set(this._data, key, value);
  2162. return this;
  2163. },
  2164. _clone: function _clone() {
  2165. var clone = new this.constructor();
  2166. clone._data = copyRule(this._data);
  2167. return clone;
  2168. }
  2169. });
  2170. function appendProto(attrs) {
  2171. attrs.forEach(function (name) {
  2172. Creator.prototype[name] = function (key) {
  2173. mergeRule(this._data, _defineProperty({}, name, arguments.length < 2 ? key : _defineProperty({}, key, arguments[1])));
  2174. return this;
  2175. };
  2176. });
  2177. }
  2178. appendProto(attrs());
  2179. var commonMaker = creatorFactory('');
  2180. function create(type, field, title) {
  2181. var make = commonMaker('', field);
  2182. make._data.type = type;
  2183. make._data.title = title;
  2184. return make;
  2185. }
  2186. function createTmp(template, vm, field, title) {
  2187. var make = commonMaker('', field);
  2188. make._data.type = 'template';
  2189. make._data.template = template;
  2190. make._data.title = title;
  2191. make._data.vm = vm;
  2192. return make;
  2193. }
  2194. function makerFactory() {
  2195. return {
  2196. create: create,
  2197. createTmp: createTmp,
  2198. template: createTmp,
  2199. factory: creatorFactory
  2200. };
  2201. }
  2202. function copy(value) {
  2203. return deepCopy(value);
  2204. }
  2205. function Api(h) {
  2206. function tidyFields(fields) {
  2207. if (is.Undef(fields)) fields = h.fields();else if (!Array.isArray(fields)) fields = [fields];
  2208. return fields;
  2209. }
  2210. function props(fields, key, val) {
  2211. tidyFields(fields).forEach(function (field) {
  2212. h.getCtxs(field).forEach(function (ctx) {
  2213. $set(ctx.rule, key, val);
  2214. h.$render.clearCache(ctx);
  2215. });
  2216. });
  2217. }
  2218. function allSubForm() {
  2219. var subs = h.subForm;
  2220. return Object.keys(subs).reduce(function (initial, k) {
  2221. var sub = subs[k];
  2222. if (!sub) return initial;
  2223. if (Array.isArray(sub)) initial.push.apply(initial, _toConsumableArray(sub));else initial.push(sub);
  2224. return initial;
  2225. }, []);
  2226. }
  2227. var api = {
  2228. get config() {
  2229. return h.options;
  2230. },
  2231. get options() {
  2232. return h.options;
  2233. },
  2234. get form() {
  2235. return h.form;
  2236. },
  2237. get rule() {
  2238. return h.rules;
  2239. },
  2240. get parent() {
  2241. return h.vm.$pfc && h.vm.$pfc.$f;
  2242. },
  2243. get children() {
  2244. return allSubForm();
  2245. },
  2246. formData: function formData(fields) {
  2247. return tidyFields(fields).reduce(function (initial, id) {
  2248. var ctx = h.getFieldCtx(id);
  2249. if (!ctx) return initial;
  2250. initial[ctx.field] = copy(ctx.rule.value);
  2251. return initial;
  2252. }, h.options.appendValue ? copy(h.appendData) : {});
  2253. },
  2254. getValue: function getValue(field) {
  2255. var ctx = h.getFieldCtx(field);
  2256. if (!ctx) return;
  2257. return copy(ctx.rule.value);
  2258. },
  2259. coverValue: function coverValue(formData) {
  2260. var data = _objectSpread2({}, formData || {});
  2261. h.deferSyncValue(function () {
  2262. api.fields().forEach(function (key) {
  2263. var ctxs = h.fieldCtx[key];
  2264. if (ctxs) {
  2265. var flag = hasProperty(data, key);
  2266. ctxs.forEach(function (ctx) {
  2267. ctx.rule.value = flag ? data[key] : undefined;
  2268. });
  2269. delete data[key];
  2270. }
  2271. });
  2272. extend(h.appendData, data);
  2273. });
  2274. },
  2275. setValue: function setValue(field) {
  2276. var formData = field;
  2277. if (arguments.length >= 2) formData = _defineProperty({}, field, arguments[1]);
  2278. h.deferSyncValue(function () {
  2279. Object.keys(formData).forEach(function (key) {
  2280. var ctxs = h.fieldCtx[key];
  2281. if (!ctxs) return h.appendData[key] = formData[key];
  2282. ctxs.forEach(function (ctx) {
  2283. ctx.rule.value = formData[key];
  2284. });
  2285. });
  2286. });
  2287. },
  2288. removeField: function removeField(field) {
  2289. var ctx = h.getCtx(field);
  2290. h.deferSyncValue(function () {
  2291. h.getCtxs(field).forEach(function (ctx) {
  2292. ctx.rm();
  2293. });
  2294. }, true);
  2295. return ctx ? ctx.origin : undefined;
  2296. },
  2297. removeRule: function removeRule(rule) {
  2298. var ctx = rule && byCtx(rule);
  2299. if (!ctx) return;
  2300. ctx.rm();
  2301. return ctx.origin;
  2302. },
  2303. destroy: function destroy() {
  2304. h.vm.$el.parentNode && h.vm.$el.parentNode.removeChild(h.vm.$el);
  2305. h.vm.$destroy();
  2306. },
  2307. fields: function fields() {
  2308. return h.fields();
  2309. },
  2310. append: function append(rule, after, child) {
  2311. var index = h.sort.length - 1,
  2312. rules;
  2313. var ctx = h.getCtx(after);
  2314. if (ctx) {
  2315. if (child) {
  2316. rules = ctx.rule.children;
  2317. index = ctx.rule.children.length - 1;
  2318. } else {
  2319. index = ctx.root.indexOf(ctx.origin);
  2320. rules = ctx.root;
  2321. }
  2322. } else rules = h.rules;
  2323. rules.splice(index + 1, 0, rule);
  2324. },
  2325. prepend: function prepend(rule, after, child) {
  2326. var index = 0,
  2327. rules;
  2328. var ctx = h.getCtx(after);
  2329. if (ctx) {
  2330. if (child) {
  2331. rules = ctx.rule.children;
  2332. } else {
  2333. index = ctx.root.indexOf(ctx.origin);
  2334. rules = ctx.root;
  2335. }
  2336. } else rules = h.rules;
  2337. rules.splice(index, 0, rule);
  2338. },
  2339. hidden: function hidden(state, fields) {
  2340. props(fields, 'hidden', !!state);
  2341. h.refresh();
  2342. },
  2343. hiddenStatus: function hiddenStatus(id) {
  2344. var ctx = h.getCtx(id);
  2345. if (!ctx) return;
  2346. return !!ctx.rule.hidden;
  2347. },
  2348. display: function display(state, fields) {
  2349. props(fields, 'display', !!state);
  2350. h.refresh();
  2351. },
  2352. displayStatus: function displayStatus(id) {
  2353. var ctx = h.getCtx(id);
  2354. if (!ctx) return;
  2355. return !!ctx.rule.display;
  2356. },
  2357. disabled: function disabled(_disabled, fields) {
  2358. tidyFields(fields).forEach(function (field) {
  2359. h.getCtxs(field).forEach(function (ctx) {
  2360. ctx.rule.props && $set(ctx.rule.props, 'disabled', !!_disabled);
  2361. });
  2362. });
  2363. h.refresh();
  2364. },
  2365. all: function all(origin) {
  2366. return Object.keys(h.ctxs).map(function (k) {
  2367. var ctx = h.ctxs[k];
  2368. return origin ? ctx.origin : ctx.rule;
  2369. });
  2370. },
  2371. model: function model(origin) {
  2372. return h.fields().reduce(function (initial, key) {
  2373. var ctx = h.fieldCtx[key][0];
  2374. initial[key] = origin ? ctx.origin : ctx.rule;
  2375. return initial;
  2376. }, {});
  2377. },
  2378. component: function component(origin) {
  2379. return Object.keys(h.nameCtx).reduce(function (initial, key) {
  2380. var ctx = h.nameCtx[key].map(function (ctx) {
  2381. return origin ? ctx.origin : ctx.rule;
  2382. });
  2383. initial[key] = ctx.length === 1 ? ctx[0] : ctx;
  2384. return initial;
  2385. }, {});
  2386. },
  2387. bind: function bind() {
  2388. return api.form;
  2389. },
  2390. reload: function reload(rules) {
  2391. h.reloadRule(rules);
  2392. },
  2393. updateOptions: function updateOptions(options) {
  2394. h.fc.updateOptions(options);
  2395. api.refresh();
  2396. },
  2397. onSubmit: function onSubmit(fn) {
  2398. api.updateOptions({
  2399. onSubmit: fn
  2400. });
  2401. },
  2402. sync: function sync(field) {
  2403. if (Array.isArray(field)) {
  2404. field.forEach(function (v) {
  2405. return api.sync(v);
  2406. });
  2407. return;
  2408. }
  2409. var ctxs = is.Object(field) ? byCtx(field) : h.getCtxs(field);
  2410. if (!ctxs) {
  2411. return;
  2412. }
  2413. ctxs = Array.isArray(ctxs) ? ctxs : [ctxs];
  2414. ctxs.forEach(function (ctx) {
  2415. if (!ctx.deleted) {
  2416. var subForm = h.subForm[ctx.id];
  2417. if (subForm) {
  2418. if (Array.isArray(subForm)) {
  2419. subForm.forEach(function (form) {
  2420. form.refresh();
  2421. });
  2422. } else if (subForm) {
  2423. subForm.refresh();
  2424. }
  2425. }
  2426. h.$render.clearCache(ctx);
  2427. }
  2428. });
  2429. h.refresh();
  2430. },
  2431. refresh: function refresh() {
  2432. allSubForm().forEach(function (sub) {
  2433. sub.refresh();
  2434. });
  2435. h.$render.clearCacheAll();
  2436. h.refresh();
  2437. },
  2438. refreshOptions: function refreshOptions() {
  2439. h.$manager.updateOptions(h.options);
  2440. api.refresh();
  2441. },
  2442. hideForm: function hideForm(hide) {
  2443. $set(h.vm, 'isShow', !hide);
  2444. },
  2445. changeStatus: function changeStatus() {
  2446. return h.changeStatus;
  2447. },
  2448. clearChangeStatus: function clearChangeStatus() {
  2449. h.changeStatus = false;
  2450. },
  2451. updateRule: function updateRule(id, rule) {
  2452. h.getCtxs(id).forEach(function (ctx) {
  2453. extend(ctx.rule, rule);
  2454. });
  2455. },
  2456. updateRules: function updateRules(rules) {
  2457. Object.keys(rules).forEach(function (id) {
  2458. api.updateRule(id, rules[id]);
  2459. });
  2460. },
  2461. mergeRule: function mergeRule$1(id, rule) {
  2462. h.getCtxs(id).forEach(function (ctx) {
  2463. mergeRule(ctx.rule, rule);
  2464. });
  2465. },
  2466. mergeRules: function mergeRules(rules) {
  2467. Object.keys(rules).forEach(function (id) {
  2468. api.mergeRule(id, rules[id]);
  2469. });
  2470. },
  2471. getRule: function getRule(id, origin) {
  2472. var ctx = h.getCtx(id);
  2473. if (ctx) {
  2474. return origin ? ctx.origin : ctx.rule;
  2475. }
  2476. },
  2477. setEffect: function setEffect(id, attr, value) {
  2478. var ctx = h.getCtx(id);
  2479. if (ctx && attr) {
  2480. if (attr[0] === '$') {
  2481. attr = attr.substr(1);
  2482. }
  2483. if (hasProperty(ctx.rule, '$' + attr)) {
  2484. $set(ctx.rule, '$' + attr, value);
  2485. }
  2486. if (!hasProperty(ctx.rule, 'effect')) {
  2487. ctx.rule.effect = {};
  2488. }
  2489. $set(ctx.rule.effect, attr, value);
  2490. }
  2491. },
  2492. clearEffectData: function clearEffectData(id, attr) {
  2493. var ctx = h.getCtx(id);
  2494. if (ctx) {
  2495. if (attr && attr[0] === '$') {
  2496. attr = attr.substr(1);
  2497. }
  2498. ctx.clearEffectData(attr);
  2499. api.sync(id);
  2500. }
  2501. },
  2502. updateValidate: function updateValidate(id, validate, merge) {
  2503. if (merge) {
  2504. api.mergeRule(id, {
  2505. validate: validate
  2506. });
  2507. } else {
  2508. props(id, 'validate', validate);
  2509. }
  2510. },
  2511. updateValidates: function updateValidates(validates, merge) {
  2512. Object.keys(validates).forEach(function (id) {
  2513. api.updateValidate(id, validates[id], merge);
  2514. });
  2515. },
  2516. refreshValidate: function refreshValidate() {
  2517. h.vm.validate = {};
  2518. api.refresh();
  2519. },
  2520. resetFields: function resetFields(fields) {
  2521. tidyFields(fields).forEach(function (field) {
  2522. h.getCtxs(field).forEach(function (ctx) {
  2523. h.$render.clearCache(ctx);
  2524. ctx.rule.value = copy(ctx.defaultValue);
  2525. });
  2526. });
  2527. },
  2528. method: function method(id, name) {
  2529. var el = api.el(id);
  2530. if (!el || !el[name]) throw new Error(format('err', "".concat(name, "\u65B9\u6CD5\u4E0D\u5B58\u5728")));
  2531. return function () {
  2532. return el[name].apply(el, arguments);
  2533. };
  2534. },
  2535. exec: function exec(id, name) {
  2536. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  2537. args[_key - 2] = arguments[_key];
  2538. }
  2539. return invoke(function () {
  2540. return api.method(id, name).apply(void 0, args);
  2541. });
  2542. },
  2543. toJson: function toJson$1(space) {
  2544. return toJson(api.rule, space);
  2545. },
  2546. trigger: function trigger(id, event) {
  2547. var el = api.el(id);
  2548. for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  2549. args[_key2 - 2] = arguments[_key2];
  2550. }
  2551. el && el.$emit.apply(el, [event].concat(args));
  2552. },
  2553. el: function el(id) {
  2554. var ctx = h.getCtx(id);
  2555. if (ctx) return ctx.el || h.vm.$refs[ctx.ref];
  2556. },
  2557. closeModal: function closeModal(id) {
  2558. var el = api.el(id);
  2559. el && el.$emit && el.$emit('close-modal');
  2560. },
  2561. getSubForm: function getSubForm(field) {
  2562. var ctx = h.getCtx(field);
  2563. return ctx ? h.subForm[ctx.id] : undefined;
  2564. },
  2565. nextTick: function nextTick(fn) {
  2566. h.bus.$once('next-tick', fn);
  2567. h.refresh();
  2568. },
  2569. nextRefresh: function nextRefresh(fn) {
  2570. h.nextRefresh();
  2571. fn && invoke(fn);
  2572. },
  2573. emit: function emit(name) {
  2574. var _h$vm;
  2575. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  2576. args[_key3 - 1] = arguments[_key3];
  2577. }
  2578. (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
  2579. },
  2580. deferSyncValue: function deferSyncValue(fn, sync) {
  2581. h.deferSyncValue(fn, sync);
  2582. },
  2583. helper: {
  2584. tidyFields: tidyFields,
  2585. props: props
  2586. }
  2587. };
  2588. ['on', 'once', 'off', 'set'].forEach(function (n) {
  2589. api[n] = function () {
  2590. var _h$vm2;
  2591. (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
  2592. };
  2593. });
  2594. api.changeValue = api.changeField = api.setValue;
  2595. return api;
  2596. }
  2597. function useCache(Render) {
  2598. extend(Render.prototype, {
  2599. initCache: function initCache() {
  2600. this.clearCacheAll();
  2601. },
  2602. clearCache: function clearCache(ctx) {
  2603. if (!this.cache[ctx.id]) {
  2604. ctx.parent && this.clearCache(ctx.parent);
  2605. return;
  2606. }
  2607. if (this.cache[ctx.id].use === true || this.cache[ctx.id].parent) {
  2608. this.$handle.refresh();
  2609. }
  2610. var parent = this.cache[ctx.id].parent;
  2611. this.cache[ctx.id] = null;
  2612. parent && this.clearCache(parent);
  2613. },
  2614. clearCacheAll: function clearCacheAll() {
  2615. this.cache = {};
  2616. },
  2617. setCache: function setCache(ctx, vnode, parent) {
  2618. this.cache[ctx.id] = {
  2619. vnode: vnode,
  2620. use: false,
  2621. parent: parent,
  2622. slot: ctx.rule.slot
  2623. };
  2624. },
  2625. getCache: function getCache(ctx) {
  2626. var cache = this.cache[ctx.id];
  2627. if (cache) {
  2628. cache.use = true;
  2629. return cache.vnode;
  2630. }
  2631. return undefined;
  2632. }
  2633. });
  2634. }
  2635. function toCase(str) {
  2636. var to = str.replace(/(-[a-z])/g, function (v) {
  2637. return v.replace('-', '').toLocaleUpperCase();
  2638. });
  2639. return lower(to);
  2640. }
  2641. function lower(str) {
  2642. return str.replace(str[0], str[0].toLowerCase());
  2643. }
  2644. function toString$1(val) {
  2645. return val == null ? '' : _typeof(val) === 'object' ? JSON.stringify(val, null, 2) : String(val);
  2646. }
  2647. function toLine(name) {
  2648. var line = name.replace(/([A-Z])/g, '-$1').toLocaleLowerCase();
  2649. if (line.indexOf('-') === 0) line = line.substr(1);
  2650. return line;
  2651. }
  2652. var id = 0;
  2653. function uniqueId() {
  2654. return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
  2655. }
  2656. function deepSet(data, idx, val) {
  2657. var _data = data,
  2658. to;
  2659. (idx || '').split('.').forEach(function (v) {
  2660. if (to) {
  2661. if (!_data[to] || _typeof(_data[to]) != 'object') {
  2662. _data[to] = {};
  2663. }
  2664. _data = _data[to];
  2665. }
  2666. to = v;
  2667. });
  2668. _data[to] = val;
  2669. return _data;
  2670. }
  2671. function useRender(Render) {
  2672. extend(Render.prototype, {
  2673. initRender: function initRender() {
  2674. this.tempList = {};
  2675. this.clearOrgChildren();
  2676. },
  2677. initOrgChildren: function initOrgChildren() {
  2678. var ctxs = this.$handle.ctxs;
  2679. this.orgChildren = Object.keys(ctxs).reduce(function (initial, id) {
  2680. if (ctxs[id].parser.loadChildren !== false) {
  2681. var children = ctxs[id].rule.children;
  2682. initial[id] = is.trueArray(children) ? _toConsumableArray(children) : [];
  2683. }
  2684. return initial;
  2685. }, {});
  2686. },
  2687. clearOrgChildren: function clearOrgChildren() {
  2688. this.orgChildren = {};
  2689. },
  2690. getTypeSlot: function getTypeSlot(type) {
  2691. var name = 'type-' + toLine(type);
  2692. var _fn = function _fn(vm) {
  2693. if (vm) {
  2694. var slot = vm.$scopedSlots[name] || vm.$scopedSlots['type-' + type];
  2695. if (slot) {
  2696. return slot;
  2697. }
  2698. return _fn(vm.$pfc);
  2699. }
  2700. };
  2701. return _fn(this.vm);
  2702. },
  2703. render: function render() {
  2704. var _this = this;
  2705. if (!this.vm.isShow) {
  2706. return;
  2707. }
  2708. this.$h = this.vm.$createElement;
  2709. this.$manager.beforeRender();
  2710. var vn;
  2711. var make = function make() {
  2712. return _this.renderList();
  2713. };
  2714. make.renderSlot = function (slot) {
  2715. return _this.renderList(slot);
  2716. };
  2717. make.renderName = function (name) {
  2718. return _this.renderId(name);
  2719. };
  2720. make.renderField = function (field) {
  2721. return _this.renderId(field, 'field');
  2722. };
  2723. if (this.vm.$scopedSlots.container) {
  2724. vn = [this.vm.$scopedSlots.container(make)];
  2725. } else {
  2726. vn = make();
  2727. }
  2728. return this.$manager.render(vn);
  2729. },
  2730. renderList: function renderList(slot) {
  2731. var _this2 = this;
  2732. return this.sort.map(function (id) {
  2733. return slot ? _this2.renderSlot(_this2.$handle.ctxs[id], slot) : _this2.renderCtx(_this2.$handle.ctxs[id]);
  2734. }).filter(function (val) {
  2735. return val !== undefined;
  2736. });
  2737. },
  2738. makeVm: function makeVm(rule) {
  2739. var _this3 = this;
  2740. var vm = rule.vm;
  2741. if (!vm) return new _vue();else if (is.Function(vm)) return invoke(function () {
  2742. return rule.vm(_this3.$handle.getInjectData(rule));
  2743. });else if (!vm._isVue) return new _vue(vm);
  2744. return vm;
  2745. },
  2746. mergeGlobal: function mergeGlobal(ctx) {
  2747. var g = this.$handle.options.global;
  2748. if (!g) return;
  2749. if (!ctx.cacheConfig) ctx.cacheConfig = g[ctx.originType] || g[ctx.type] || g[ctx.trueType] || {};
  2750. ctx.prop = mergeRule({}, [g['*'], ctx.cacheConfig, ctx.prop]);
  2751. },
  2752. setOptions: function setOptions(ctx) {
  2753. if (ctx.prop.optionsTo && ctx.prop.options) {
  2754. deepSet(ctx.prop, ctx.prop.optionsTo, ctx.prop.options);
  2755. }
  2756. },
  2757. deepSet: function deepSet$1(ctx) {
  2758. var deep = ctx.rule.deep;
  2759. deep && Object.keys(deep).sort(function (a, b) {
  2760. return a.length < b.length ? -1 : 1;
  2761. }).forEach(function (str) {
  2762. deepSet(ctx.prop, str, deep[str]);
  2763. });
  2764. },
  2765. setTempProps: function setTempProps(vm, ctx) {
  2766. if (!vm.$props) return;
  2767. var prop = ctx.prop;
  2768. var keys = Object.keys(vm.$props);
  2769. var inject = this.injectProp(ctx);
  2770. var injectKeys = Object.keys(inject);
  2771. keys.forEach(function (key) {
  2772. if (hasProperty(prop.props, key)) vm.$props[key] = prop.props[key];else if (injectKeys.indexOf(key) > -1) vm.$props[key] = inject[key];
  2773. });
  2774. var key = vm.$options.model && vm.$options.model.prop || 'value';
  2775. if (keys.indexOf(key) > -1) {
  2776. vm.$props[key] = prop.value;
  2777. }
  2778. },
  2779. renderTemp: function renderTemp(ctx) {
  2780. var _this4 = this;
  2781. if (!_vue.compile) {
  2782. tip('当前使用的Vue构建版本不支持compile,无法使用template功能');
  2783. return [];
  2784. }
  2785. var rule = ctx.prop;
  2786. var id = ctx.id,
  2787. key = ctx.key;
  2788. if (!this.tempList[id]) {
  2789. if (!ctx.el) {
  2790. ctx.el = this.makeVm(rule);
  2791. this.vm.$nextTick(function () {
  2792. return ctx.parser.mounted(ctx);
  2793. });
  2794. }
  2795. var _vm = ctx.el;
  2796. if (ctx.input) _vm.$on(_vm.$options.model && _vm.$options.model.event || 'input', function (value) {
  2797. _this4.onInput(ctx, value);
  2798. });
  2799. this.tempList[id] = {
  2800. vm: _vm,
  2801. template: _vue.compile(rule.template)
  2802. };
  2803. }
  2804. var _this$tempList$id = this.tempList[id],
  2805. vm = _this$tempList$id.vm,
  2806. template = _this$tempList$id.template;
  2807. this.setTempProps(vm, ctx);
  2808. var vn = template.render.call(vm);
  2809. if (is.Undef(vn.data)) vn.data = {};
  2810. vn.key = key;
  2811. vn.data.ref = ctx.ref;
  2812. vn.data.key = key;
  2813. return vn;
  2814. },
  2815. parseSide: function parseSide(side) {
  2816. return is.Object(side) ? mergeRule({}, side) : side;
  2817. },
  2818. renderSides: function renderSides(vn, ctx, temp) {
  2819. var prop = ctx[temp ? 'rule' : 'prop'];
  2820. return [this.renderRule(this.parseSide(prop.prefix)), vn, this.renderRule(this.parseSide(prop.suffix))];
  2821. },
  2822. renderSlot: function renderSlot(ctx, slot) {
  2823. return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
  2824. },
  2825. renderId: function renderId(name, type) {
  2826. var _this5 = this;
  2827. var ctxs = this.$handle[type === 'field' ? 'fieldCtx' : 'nameCtx'][name];
  2828. return ctxs ? ctxs.map(function (ctx) {
  2829. return _this5.renderCtx(ctx, ctx.parent);
  2830. }) : undefined;
  2831. },
  2832. renderCtx: function renderCtx(ctx, parent) {
  2833. if (ctx.type === 'hidden') return;
  2834. var rule = ctx.rule;
  2835. if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
  2836. var vn;
  2837. var cacheFlag = rule.cache !== false;
  2838. var _type = ctx.trueType;
  2839. var none = !(is.Undef(rule.display) || !!rule.display);
  2840. if (_type === 'template' && !rule.template) {
  2841. vn = this.renderSides(this.renderChildren(ctx), ctx, true);
  2842. if (none) {
  2843. this.display(vn);
  2844. }
  2845. vn = this.item(ctx, vn);
  2846. } else if (_type === 'fcFragment') {
  2847. vn = this.renderChildren(ctx);
  2848. } else {
  2849. ctx.initProp();
  2850. this.mergeGlobal(ctx);
  2851. this.$manager.tidyRule(ctx);
  2852. this.deepSet(ctx);
  2853. this.setOptions(ctx);
  2854. this.ctxProp(ctx);
  2855. var prop = ctx.prop;
  2856. prop.preview = !!(hasProperty(prop, 'preview') ? prop.preview : this.options.preview || false);
  2857. prop.props.formCreateInject = this.injectProp(ctx);
  2858. var preview = prop.preview;
  2859. if (prop.hidden) {
  2860. this.setCache(ctx, undefined, parent);
  2861. return;
  2862. }
  2863. if (_type === 'template' && prop.template) {
  2864. vn = this.renderTemp(ctx);
  2865. cacheFlag = false;
  2866. } else {
  2867. var children = [];
  2868. if (ctx.parser.renderChildren) {
  2869. children = ctx.parser.renderChildren(ctx);
  2870. } else if (ctx.parser.loadChildren !== false) {
  2871. children = this.renderChildren(ctx);
  2872. }
  2873. var slot = this.getTypeSlot(ctx.type);
  2874. if (slot) {
  2875. vn = slot({
  2876. rule: rule,
  2877. prop: prop,
  2878. preview: preview,
  2879. children: children,
  2880. api: this.$handle.api,
  2881. model: prop.model || {}
  2882. });
  2883. } else {
  2884. vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
  2885. }
  2886. }
  2887. vn = this.renderSides(vn, ctx);
  2888. if (!(!ctx.input && is.Undef(prop["native"])) && prop["native"] !== true) {
  2889. vn = this.$manager.makeWrap(ctx, vn);
  2890. }
  2891. if (none) {
  2892. vn = this.display(vn);
  2893. }
  2894. vn = this.item(ctx, vn);
  2895. }
  2896. if (cacheFlag) {
  2897. this.setCache(ctx, vn, parent);
  2898. }
  2899. return vn;
  2900. }
  2901. return this.getCache(ctx);
  2902. },
  2903. display: function display(vn) {
  2904. var _this6 = this;
  2905. if (Array.isArray(vn)) {
  2906. var data = [];
  2907. vn.forEach(function (v) {
  2908. if (Array.isArray(v)) return _this6.display(v);
  2909. if (_this6.none(v)) data.push(v);
  2910. });
  2911. return data;
  2912. } else {
  2913. return this.none(vn);
  2914. }
  2915. },
  2916. none: function none(vn) {
  2917. if (vn && vn.data) {
  2918. if (Array.isArray(vn.data.style)) {
  2919. vn.data.style.push({
  2920. display: 'none'
  2921. });
  2922. } else if (is.String(vn.data.style)) {
  2923. vn.data.style += ';display:none;';
  2924. } else {
  2925. vn.data.style = [vn.data.style, {
  2926. display: 'none'
  2927. }];
  2928. }
  2929. return vn;
  2930. }
  2931. },
  2932. item: function item(ctx, vn) {
  2933. return this.$h('fcFragment', {
  2934. slot: ctx.rule.slot,
  2935. key: ctx.key
  2936. }, [vn]);
  2937. },
  2938. injectProp: function injectProp(ctx) {
  2939. var _this7 = this;
  2940. if (!this.vm.ctxInject[ctx.id]) {
  2941. $set(this.vm.ctxInject, ctx.id, {
  2942. api: this.$handle.api,
  2943. form: this.fc.create,
  2944. subForm: function subForm(_subForm) {
  2945. _this7.$handle.addSubForm(ctx, _subForm);
  2946. },
  2947. getSubForm: function getSubForm() {
  2948. return _this7.$handle.subForm[ctx.id];
  2949. },
  2950. options: [],
  2951. children: [],
  2952. prop: {},
  2953. preview: false,
  2954. field: ctx.field,
  2955. rule: ctx.rule,
  2956. input: ctx.input
  2957. });
  2958. }
  2959. var inject = this.vm.ctxInject[ctx.id];
  2960. extend(inject, {
  2961. preview: ctx.prop.preview,
  2962. options: ctx.prop.options,
  2963. children: ctx.rule.children,
  2964. prop: function () {
  2965. var temp = _objectSpread2({}, ctx.prop);
  2966. temp.on = temp.on ? _objectSpread2({}, temp.on) : {};
  2967. delete temp.model;
  2968. return temp;
  2969. }()
  2970. });
  2971. return inject;
  2972. },
  2973. ctxProp: function ctxProp(ctx, custom) {
  2974. var _this8 = this;
  2975. var ref = ctx.ref,
  2976. key = ctx.key,
  2977. rule = ctx.rule;
  2978. this.$manager.mergeProp(ctx, custom);
  2979. ctx.parser.mergeProp(ctx, custom);
  2980. var props = [{
  2981. ref: ref,
  2982. key: rule.key || "".concat(key, "fc"),
  2983. slot: undefined,
  2984. on: {
  2985. 'hook:mounted': function hookMounted() {
  2986. _this8.onMounted(ctx);
  2987. },
  2988. 'fc.sub-form': function fcSubForm(subForm) {
  2989. _this8.$handle.addSubForm(ctx, subForm);
  2990. }
  2991. }
  2992. }];
  2993. if (!custom && ctx.input) {
  2994. ctx.prop.model = {
  2995. value: this.$handle.getFormData(ctx),
  2996. callback: function callback(value) {
  2997. _this8.onInput(ctx, value);
  2998. },
  2999. expression: "formData.".concat(ctx.id)
  3000. };
  3001. }
  3002. mergeProps(props, ctx.prop);
  3003. return ctx.prop;
  3004. },
  3005. onMounted: function onMounted(ctx) {
  3006. ctx.el = this.vm.$refs[ctx.ref];
  3007. if (ctx.el) {
  3008. (ctx.el.$el || ctx.el).__rule__ = ctx.rule;
  3009. }
  3010. ctx.parser.mounted(ctx);
  3011. this.$handle.effect(ctx, 'mounted');
  3012. },
  3013. onInput: function onInput(ctx, value) {
  3014. this.$handle.onInput(ctx, value);
  3015. },
  3016. renderChildren: function renderChildren(ctx) {
  3017. var _this9 = this;
  3018. var children = ctx.rule.children,
  3019. orgChildren = this.orgChildren[ctx.id];
  3020. var isRm = function isRm(child) {
  3021. return !is.String(child) && child.__fc__ && !_this9.$handle.ctxs[child.__fc__.id];
  3022. };
  3023. if (!is.trueArray(children) && orgChildren) {
  3024. this.$handle.deferSyncValue(function () {
  3025. orgChildren.forEach(function (child) {
  3026. if (!child) return;
  3027. if (isRm(child)) {
  3028. _this9.$handle.rmCtx(child.__fc__);
  3029. }
  3030. });
  3031. });
  3032. this.orgChildren[ctx.id] = [];
  3033. return [];
  3034. }
  3035. orgChildren && this.$handle.deferSyncValue(function () {
  3036. orgChildren.forEach(function (child) {
  3037. if (!child) return;
  3038. if (children.indexOf(child) === -1 && isRm(child)) {
  3039. _this9.$handle.rmCtx(child.__fc__);
  3040. }
  3041. });
  3042. });
  3043. return children.map(function (child) {
  3044. if (!child) return;
  3045. if (is.String(child)) return child;
  3046. if (child.__fc__) {
  3047. return _this9.renderCtx(child.__fc__, ctx);
  3048. }
  3049. if (child.type) {
  3050. _this9.vm.$nextTick(function () {
  3051. _this9.$handle.loadChildren(children, ctx);
  3052. _this9.$handle.refresh();
  3053. });
  3054. }
  3055. });
  3056. },
  3057. defaultRender: function defaultRender(ctx, children) {
  3058. var prop = ctx.prop;
  3059. if (prop.component) return this.vNode.makeComponent(prop.component, prop, children);
  3060. if (this.vNode[ctx.type]) return this.vNode[ctx.type](prop, children);
  3061. if (this.vNode[ctx.originType]) return this.vNode[ctx.originType](prop, children);
  3062. return this.vNode.make(lower(ctx.originType), prop, children);
  3063. },
  3064. renderRule: function renderRule(rule, children, origin) {
  3065. var _this10 = this;
  3066. if (!rule) return undefined;
  3067. if (is.String(rule)) return rule;
  3068. var type;
  3069. if (origin) {
  3070. type = rule.type;
  3071. } else {
  3072. type = rule.is;
  3073. if (rule.type) {
  3074. type = toCase(rule.type);
  3075. var alias = this.vNode.aliasMap[type];
  3076. if (alias) type = toCase(alias);
  3077. }
  3078. }
  3079. if (!type) return undefined;
  3080. var data = [[children]];
  3081. if (is.trueArray(rule.children)) {
  3082. data.push(rule.children.map(function (v) {
  3083. return _this10.renderRule(v);
  3084. }));
  3085. }
  3086. return this.$h(type, _objectSpread2({}, rule), data);
  3087. }
  3088. });
  3089. }
  3090. function Render(handle) {
  3091. extend(this, {
  3092. $handle: handle,
  3093. fc: handle.fc,
  3094. vm: handle.vm,
  3095. $manager: handle.$manager,
  3096. vNode: new handle.fc.CreateNode(handle.vm)
  3097. });
  3098. funcProxy(this, {
  3099. options: function options() {
  3100. return handle.options;
  3101. },
  3102. sort: function sort() {
  3103. return handle.sort;
  3104. }
  3105. });
  3106. this.initCache();
  3107. this.initRender();
  3108. }
  3109. useCache(Render);
  3110. useRender(Render);
  3111. function useInject(Handler) {
  3112. extend(Handler.prototype, {
  3113. parseInjectEvent: function parseInjectEvent(rule, on) {
  3114. var inject = rule.inject || this.options.injectEvent;
  3115. return this.parseEventLst(rule, on, inject);
  3116. },
  3117. parseEventLst: function parseEventLst(rule, data, inject, deep) {
  3118. var _this = this;
  3119. Object.keys(data).forEach(function (k) {
  3120. var fn = _this.parseEvent(rule, data[k], inject, deep);
  3121. if (fn) {
  3122. data[k] = fn;
  3123. }
  3124. });
  3125. return data;
  3126. },
  3127. parseEvent: function parseEvent(rule, fn, inject, deep) {
  3128. if (is.Function(fn) && (inject !== false && !is.Undef(inject) || fn.__inject)) {
  3129. return this.inject(rule, fn, inject);
  3130. } else if (!deep && Array.isArray(fn) && fn[0] && (is.String(fn[0]) || is.Function(fn[0]))) {
  3131. return this.parseEventLst(rule, fn, inject, true);
  3132. } else if (is.String(fn)) {
  3133. var val = parseFn(fn);
  3134. if (val && fn !== val) {
  3135. return val.__inject ? this.parseEvent(rule, val, inject, true) : val;
  3136. }
  3137. }
  3138. },
  3139. parseEmit: function parseEmit(ctx, on) {
  3140. var _this2 = this;
  3141. var event = {},
  3142. rule = ctx.rule,
  3143. emitPrefix = rule.emitPrefix,
  3144. field = rule.field,
  3145. name = rule.name,
  3146. inject = rule.inject;
  3147. var emit = rule[on ? 'emit' : 'nativeEmit'] || [];
  3148. if (is.trueArray(emit)) {
  3149. var emitKey = emitPrefix || field || name;
  3150. if (emitKey) {
  3151. if (!on) emitKey = "native-".concat(emitKey);
  3152. emit.forEach(function (eventName) {
  3153. if (!eventName) return;
  3154. var eventInject;
  3155. if (is.Object(eventName)) {
  3156. eventInject = eventName.inject;
  3157. eventName = eventName.name;
  3158. }
  3159. var fieldKey = toLine("".concat(emitKey, "-").concat(eventName));
  3160. var fn = function fn() {
  3161. var _this2$vm, _this2$vm2;
  3162. for (var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++) {
  3163. arg[_key] = arguments[_key];
  3164. }
  3165. (_this2$vm = _this2.vm).$emit.apply(_this2$vm, [fieldKey].concat(arg));
  3166. (_this2$vm2 = _this2.vm).$emit.apply(_this2$vm2, ['emit-event', fieldKey].concat(arg));
  3167. };
  3168. fn.__emit = true;
  3169. if (!eventInject && inject === false) {
  3170. event[eventName] = fn;
  3171. } else {
  3172. var _inject = eventInject || inject || _this2.options.injectEvent;
  3173. event[eventName] = is.Undef(_inject) ? fn : _this2.inject(rule, fn, _inject);
  3174. }
  3175. });
  3176. }
  3177. }
  3178. ctx.computed[on ? 'on' : 'nativeOn'] = event;
  3179. return event;
  3180. },
  3181. getInjectData: function getInjectData(self, inject) {
  3182. var _this$vm$$options$pro = this.vm.$options.propsData,
  3183. option = _this$vm$$options$pro.option,
  3184. rule = _this$vm$$options$pro.rule;
  3185. return {
  3186. api: this.api,
  3187. $f: this.api,
  3188. rule: rule,
  3189. self: self.__origin__,
  3190. option: option,
  3191. inject: inject
  3192. };
  3193. },
  3194. inject: function inject(self, _fn, _inject2) {
  3195. if (_fn.__origin) {
  3196. if (this.watching && !this.loading) return _fn;
  3197. _fn = _fn.__origin;
  3198. }
  3199. var h = this;
  3200. var fn = function fn() {
  3201. var data = h.getInjectData(self, _inject2);
  3202. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  3203. args[_key2] = arguments[_key2];
  3204. }
  3205. data.args = [].concat(args);
  3206. args.unshift(data);
  3207. return _fn.apply(this, args);
  3208. };
  3209. fn.__origin = _fn;
  3210. fn.__json = _fn.__json;
  3211. return fn;
  3212. }
  3213. });
  3214. }
  3215. var EVENT = ['hook:updated', 'hook:mounted'];
  3216. function usePage(Handler) {
  3217. extend(Handler.prototype, {
  3218. usePage: function usePage() {
  3219. var _this = this;
  3220. var page = this.options.page;
  3221. if (!page) return;
  3222. var first = 25;
  3223. var limit = getLimit(this.rules);
  3224. if (is.Object(page)) {
  3225. if (page.first) first = parseInt(page.first, 10) || first;
  3226. if (page.limit) limit = parseInt(page.limit, 10) || limit;
  3227. }
  3228. extend(this, {
  3229. first: first,
  3230. limit: limit,
  3231. pageEnd: this.rules.length <= first
  3232. });
  3233. this.bus.$on('page-end', function () {
  3234. return _this.vm.$emit('page-end', _this.api);
  3235. });
  3236. this.pageLoad();
  3237. },
  3238. pageLoad: function pageLoad() {
  3239. var _this2 = this;
  3240. var pageFn = function pageFn() {
  3241. if (_this2.pageEnd) {
  3242. _this2.vm.$off(EVENT, pageFn);
  3243. _this2.bus.$emit('page-end');
  3244. } else {
  3245. _this2.first += _this2.limit;
  3246. _this2.pageEnd = _this2.rules.length <= _this2.first;
  3247. _this2.loadRule();
  3248. _this2.refresh();
  3249. }
  3250. };
  3251. this.vm.$on(EVENT, pageFn);
  3252. }
  3253. });
  3254. }
  3255. function getLimit(rules) {
  3256. return rules.length < 31 ? 31 : Math.ceil(rules.length / 3);
  3257. }
  3258. function useRender$1(Handler) {
  3259. extend(Handler.prototype, {
  3260. clearNextTick: function clearNextTick() {
  3261. this.nextTick && clearTimeout(this.nextTick);
  3262. this.nextTick = null;
  3263. },
  3264. bindNextTick: function bindNextTick(fn) {
  3265. var _this = this;
  3266. this.clearNextTick();
  3267. this.nextTick = setTimeout(function () {
  3268. fn();
  3269. _this.nextTick = null;
  3270. }, 10);
  3271. },
  3272. render: function render() {
  3273. ++this.loadedId;
  3274. if (this.vm.unique > 0) return this.$render.render();else {
  3275. this.vm.unique = 1;
  3276. return [];
  3277. }
  3278. }
  3279. });
  3280. }
  3281. function bind(ctx) {
  3282. Object.defineProperties(ctx.origin, {
  3283. __fc__: enumerable(ctx, true)
  3284. });
  3285. }
  3286. function RuleContext(handle, rule, defaultValue) {
  3287. var id = uniqueId();
  3288. extend(this, {
  3289. id: id,
  3290. ref: id,
  3291. wrapRef: id + 'fi',
  3292. rule: rule,
  3293. origin: rule.__origin__ || rule,
  3294. name: rule.name,
  3295. watch: [],
  3296. linkOn: [],
  3297. root: [],
  3298. ctrlRule: [],
  3299. parent: null,
  3300. cacheConfig: null,
  3301. prop: _objectSpread2({}, rule),
  3302. computed: {},
  3303. payload: {},
  3304. input: !!rule.field,
  3305. el: undefined,
  3306. defaultValue: rule.field ? deepCopy(defaultValue) : undefined,
  3307. field: rule.field || undefined
  3308. });
  3309. this.updateType();
  3310. this.updateKey();
  3311. bind(this);
  3312. this.update(handle, true);
  3313. }
  3314. extend(RuleContext.prototype, {
  3315. effectData: function effectData(name) {
  3316. if (!this.payload[name]) {
  3317. this.payload[name] = {};
  3318. }
  3319. return this.payload[name];
  3320. },
  3321. clearEffectData: function clearEffectData(name) {
  3322. if (name === undefined) {
  3323. this.payload = {};
  3324. } else {
  3325. delete this.payload[name];
  3326. }
  3327. },
  3328. updateKey: function updateKey(flag) {
  3329. this.key = uniqueId();
  3330. flag && this.parent && this.parent.updateKey(flag);
  3331. },
  3332. updateType: function updateType() {
  3333. this.originType = this.rule.type;
  3334. this.type = toCase(this.rule.type);
  3335. },
  3336. setParser: function setParser(parser) {
  3337. this.parser = parser;
  3338. parser.init(this);
  3339. },
  3340. initProp: function initProp() {
  3341. var _this = this;
  3342. var rule = _objectSpread2({}, this.rule);
  3343. delete rule.children;
  3344. this.prop = mergeProps([rule].concat(_toConsumableArray(Object.keys(this.payload).map(function (k) {
  3345. return _this.payload[k];
  3346. })), [this.computed]));
  3347. },
  3348. check: function check(handle) {
  3349. return this.vm === handle.vm;
  3350. },
  3351. unwatch: function unwatch() {
  3352. this.watch.forEach(function (un) {
  3353. return un();
  3354. });
  3355. this.watch = [];
  3356. },
  3357. unlink: function unlink() {
  3358. this.linkOn.forEach(function (un) {
  3359. return un();
  3360. });
  3361. this.linkOn = [];
  3362. },
  3363. link: function link() {
  3364. this.unlink();
  3365. this.$handle.appendLink(this);
  3366. },
  3367. watchTo: function watchTo() {
  3368. this.$handle.watchCtx(this);
  3369. },
  3370. "delete": function _delete() {
  3371. var undef = void 0;
  3372. this.unwatch();
  3373. this.unlink();
  3374. this.rmCtrl();
  3375. extend(this, {
  3376. deleted: true,
  3377. prop: _objectSpread2({}, this.rule),
  3378. computed: {},
  3379. el: undef,
  3380. $handle: undef,
  3381. $render: undef,
  3382. $api: undef,
  3383. vm: undef,
  3384. vNode: undef,
  3385. parent: null,
  3386. cacheConfig: null
  3387. });
  3388. },
  3389. rmCtrl: function rmCtrl() {
  3390. this.ctrlRule.forEach(function (ctrl) {
  3391. return ctrl.__fc__ && ctrl.__fc__.rm();
  3392. });
  3393. this.ctrlRule = [];
  3394. },
  3395. rm: function rm() {
  3396. var _this2 = this;
  3397. var _rm = function _rm() {
  3398. var index = _this2.root.indexOf(_this2.origin);
  3399. if (index > -1) {
  3400. _this2.root.splice(index, 1);
  3401. _this2.$handle && _this2.$handle.refresh();
  3402. }
  3403. };
  3404. if (this.deleted) {
  3405. _rm();
  3406. return;
  3407. }
  3408. this.$handle.noWatch(function () {
  3409. _this2.$handle.deferSyncValue(function () {
  3410. _this2.rmCtrl();
  3411. _rm();
  3412. _this2.$handle.rmCtx(_this2);
  3413. extend(_this2, {
  3414. root: []
  3415. });
  3416. }, _this2.input);
  3417. });
  3418. },
  3419. update: function update(handle, init) {
  3420. extend(this, {
  3421. deleted: false,
  3422. $handle: handle,
  3423. $render: handle.$render,
  3424. $api: handle.api,
  3425. vm: handle.vm,
  3426. trueType: handle.getType(this.originType),
  3427. vNode: handle.$render.vNode,
  3428. updated: false
  3429. });
  3430. !init && this.unwatch();
  3431. this.watchTo();
  3432. this.link();
  3433. }
  3434. });
  3435. function useLoader(Handler) {
  3436. extend(Handler.prototype, {
  3437. nextRefresh: function nextRefresh(fn) {
  3438. var _this = this;
  3439. var id = this.loadedId;
  3440. this.vm.$nextTick(function () {
  3441. id === _this.loadedId && (fn ? fn() : _this.refresh());
  3442. });
  3443. },
  3444. parseRule: function parseRule(_rule) {
  3445. var _this2 = this;
  3446. var rule = getRule(_rule);
  3447. Object.defineProperties(rule, {
  3448. __origin__: enumerable(_rule, true)
  3449. });
  3450. fullRule(rule);
  3451. this.appendValue(rule);
  3452. rule.options = Array.isArray(rule.options) ? rule.options : [];
  3453. [rule, rule['prefix'], rule['suffix']].forEach(function (item) {
  3454. if (!item) {
  3455. return;
  3456. }
  3457. _this2.loadFn(item, rule);
  3458. });
  3459. this.loadCtrl(rule);
  3460. if (rule.update) {
  3461. rule.update = parseFn(rule.update);
  3462. }
  3463. return rule;
  3464. },
  3465. loadFn: function loadFn(item, rule) {
  3466. var _this3 = this;
  3467. ['on', 'props', 'nativeOn', 'deep'].forEach(function (k) {
  3468. item[k] && _this3.parseInjectEvent(rule, item[k]);
  3469. });
  3470. },
  3471. loadCtrl: function loadCtrl(rule) {
  3472. rule.control && rule.control.forEach(function (ctrl) {
  3473. if (ctrl.handle) {
  3474. ctrl.handle = parseFn(ctrl.handle);
  3475. }
  3476. });
  3477. },
  3478. syncProp: function syncProp(ctx) {
  3479. var _this4 = this;
  3480. var rule = ctx.rule;
  3481. is.trueArray(rule.sync) && mergeProps([{
  3482. on: rule.sync.reduce(function (pre, prop) {
  3483. pre["update:".concat(prop)] = function (val) {
  3484. rule.props[prop] = val;
  3485. _this4.vm.$emit('sync', prop, val, rule, _this4.fapi);
  3486. };
  3487. return pre;
  3488. }, {})
  3489. }], ctx.computed);
  3490. },
  3491. loadRule: function loadRule() {
  3492. var _this5 = this;
  3493. this.cycleLoad = false;
  3494. this.loading = true;
  3495. if (this.pageEnd) {
  3496. this.bus.$emit('load-start');
  3497. }
  3498. this.deferSyncValue(function () {
  3499. _this5._loadRule(_this5.rules);
  3500. _this5.loading = false;
  3501. if (_this5.cycleLoad && _this5.pageEnd) {
  3502. return _this5.loadRule();
  3503. }
  3504. if (_this5.pageEnd) {
  3505. _this5.bus.$emit('load-end');
  3506. }
  3507. _this5.vm._renderRule();
  3508. _this5.$render.initOrgChildren();
  3509. _this5.syncForm();
  3510. });
  3511. },
  3512. loadChildren: function loadChildren(children, parent) {
  3513. this.cycleLoad = false;
  3514. this.loading = true;
  3515. this.bus.$emit('load-start');
  3516. this._loadRule(children, parent);
  3517. this.loading = false;
  3518. if (this.cycleLoad) {
  3519. return this.loadRule();
  3520. } else {
  3521. this.bus.$emit('load-end');
  3522. this.syncForm();
  3523. }
  3524. this.$render.clearCache(parent);
  3525. },
  3526. _loadRule: function _loadRule(rules, parent) {
  3527. var _this6 = this;
  3528. var preIndex = function preIndex(i) {
  3529. var pre = rules[i - 1];
  3530. if (!pre || !pre.__fc__) {
  3531. return i > 0 ? preIndex(i - 1) : -1;
  3532. }
  3533. var index = _this6.sort.indexOf(pre.__fc__.id);
  3534. return index > -1 ? index : preIndex(i - 1);
  3535. };
  3536. var loadChildren = function loadChildren(children, parent) {
  3537. if (is.trueArray(children)) {
  3538. _this6._loadRule(children, parent);
  3539. }
  3540. };
  3541. rules.map(function (_rule, index) {
  3542. if (parent && (is.String(_rule) || is.Undef(_rule))) return;
  3543. if (!_this6.pageEnd && !parent && index >= _this6.first) return;
  3544. if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
  3545. loadChildren(_rule.__fc__.rule.children, _rule.__fc__);
  3546. return _rule.__fc__;
  3547. }
  3548. var rule = getRule(_rule);
  3549. var isRepeat = function isRepeat() {
  3550. return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field][0] !== _rule.__fc__);
  3551. };
  3552. _this6.ruleEffect(rule, 'init', {
  3553. repeat: isRepeat()
  3554. });
  3555. if (isRepeat()) {
  3556. _this6.vm.$emit('repeat-field', _rule, _this6.api);
  3557. }
  3558. var ctx;
  3559. var isCopy = false;
  3560. var isInit = !!_rule.__fc__;
  3561. var defaultValue = rule.value;
  3562. if (isInit) {
  3563. ctx = _rule.__fc__;
  3564. defaultValue = ctx.defaultValue;
  3565. var check = !ctx.check(_this6);
  3566. if (ctx.deleted) {
  3567. if (check) {
  3568. if (isCtrl(ctx)) {
  3569. return;
  3570. }
  3571. ctx.update(_this6);
  3572. }
  3573. } else {
  3574. if (check) {
  3575. if (isCtrl(ctx)) {
  3576. return;
  3577. }
  3578. rules[index] = _rule = _rule._clone ? _rule._clone() : copyRule(_rule);
  3579. ctx = null;
  3580. isCopy = true;
  3581. }
  3582. }
  3583. }
  3584. if (!ctx) {
  3585. var _rule2 = _this6.parseRule(_rule);
  3586. ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
  3587. _this6.bindParser(ctx);
  3588. } else {
  3589. if (ctx.originType !== ctx.rule.type) {
  3590. ctx.updateType();
  3591. _this6.bindParser(ctx);
  3592. }
  3593. _this6.appendValue(ctx.rule);
  3594. }
  3595. [false, true].forEach(function (b) {
  3596. return _this6.parseEmit(ctx, b);
  3597. });
  3598. _this6.syncProp(ctx);
  3599. ctx.parent = parent || null;
  3600. ctx.root = rules;
  3601. _this6.setCtx(ctx);
  3602. !isCopy && !isInit && _this6.effect(ctx, 'load');
  3603. ctx.parser.loadChildren === false || loadChildren(ctx.rule.children, ctx);
  3604. if (!parent) {
  3605. var _preIndex = preIndex(index);
  3606. if (_preIndex > -1 || !index) {
  3607. _this6.sort.splice(_preIndex + 1, 0, ctx.id);
  3608. } else {
  3609. _this6.sort.push(ctx.id);
  3610. }
  3611. }
  3612. var r = ctx.rule;
  3613. if (!ctx.updated) {
  3614. ctx.updated = true;
  3615. if (is.Function(r.update)) {
  3616. _this6.bus.$once('load-end', function () {
  3617. _this6.refreshUpdate(ctx, r.value);
  3618. });
  3619. }
  3620. _this6.effect(ctx, 'loaded');
  3621. }
  3622. if (ctx.input) Object.defineProperty(r, 'value', _this6.valueHandle(ctx));
  3623. if (_this6.refreshControl(ctx)) _this6.cycleLoad = true;
  3624. return ctx;
  3625. });
  3626. },
  3627. refreshControl: function refreshControl(ctx) {
  3628. return ctx.input && ctx.rule.control && this.useCtrl(ctx);
  3629. },
  3630. useCtrl: function useCtrl(ctx) {
  3631. var _this7 = this;
  3632. var controls = getCtrl(ctx),
  3633. validate = [],
  3634. api = this.api;
  3635. if (!controls.length) return false;
  3636. var _loop = function _loop(i) {
  3637. var control = controls[i],
  3638. handleFn = control.handle || function (val) {
  3639. return val === control.value;
  3640. };
  3641. if (!is.trueArray(control.rule)) return "continue";
  3642. var data = _objectSpread2(_objectSpread2({}, control), {}, {
  3643. valid: invoke(function () {
  3644. return handleFn(ctx.rule.value, api);
  3645. }),
  3646. ctrl: findCtrl(ctx, control.rule),
  3647. isHidden: is.String(control.rule[0])
  3648. });
  3649. if (data.valid && data.ctrl || !data.valid && !data.ctrl && !data.isHidden) return "continue";
  3650. validate.push(data);
  3651. };
  3652. for (var i = 0; i < controls.length; i++) {
  3653. var _ret = _loop(i);
  3654. if (_ret === "continue") continue;
  3655. }
  3656. if (!validate.length) return false;
  3657. var hideLst = [];
  3658. var flag = false;
  3659. this.deferSyncValue(function () {
  3660. validate.reverse().forEach(function (_ref) {
  3661. var isHidden = _ref.isHidden,
  3662. valid = _ref.valid,
  3663. rule = _ref.rule,
  3664. prepend = _ref.prepend,
  3665. append = _ref.append,
  3666. child = _ref.child,
  3667. ctrl = _ref.ctrl;
  3668. if (isHidden) {
  3669. valid ? ctx.ctrlRule.push({
  3670. __ctrl: true,
  3671. children: rule,
  3672. valid: valid
  3673. }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
  3674. hideLst[valid ? 'push' : 'unshift'](function () {
  3675. _this7.api.hidden(!valid, rule);
  3676. });
  3677. return;
  3678. }
  3679. if (valid) {
  3680. flag = true;
  3681. var ruleCon = {
  3682. type: 'fcFragment',
  3683. "native": true,
  3684. __ctrl: true,
  3685. children: rule
  3686. };
  3687. ctx.ctrlRule.push(ruleCon);
  3688. _this7.bus.$once('load-start', function () {
  3689. if (prepend) {
  3690. api.prepend(ruleCon, prepend, child);
  3691. } else if (append || child) {
  3692. api.append(ruleCon, append || ctx.id, child);
  3693. } else {
  3694. ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
  3695. }
  3696. });
  3697. } else {
  3698. ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
  3699. var ctrlCtx = byCtx(ctrl);
  3700. ctrlCtx && ctrlCtx.rm();
  3701. }
  3702. });
  3703. });
  3704. hideLst.length && this.vm.$nextTick(function () {
  3705. hideLst.forEach(function (v) {
  3706. return v();
  3707. });
  3708. });
  3709. this.vm.$emit('control', ctx.origin, this.api);
  3710. this.effect(ctx, 'control');
  3711. return flag;
  3712. },
  3713. reloadRule: function reloadRule(rules) {
  3714. return this._reloadRule(rules);
  3715. },
  3716. _reloadRule: function _reloadRule(rules) {
  3717. var _this8 = this;
  3718. if (!rules) rules = this.rules;
  3719. var ctxs = _objectSpread2({}, this.ctxs);
  3720. this.clearNextTick();
  3721. this.$render.clearOrgChildren();
  3722. this.initData(rules);
  3723. this.fc.rules = rules;
  3724. this.deferSyncValue(function () {
  3725. _this8.bus.$once('load-end', function () {
  3726. Object.keys(ctxs).filter(function (id) {
  3727. return _this8.ctxs[id] === undefined;
  3728. }).forEach(function (id) {
  3729. return _this8.rmCtx(ctxs[id]);
  3730. });
  3731. _this8.$render.clearCacheAll();
  3732. });
  3733. _this8.reloading = true;
  3734. _this8.loadRule();
  3735. _this8.reloading = false;
  3736. _this8.refresh();
  3737. _this8.vm.$emit('reloading', _this8.api);
  3738. });
  3739. this.bus.$off('next-tick', this.nextReload);
  3740. this.bus.$once('next-tick', this.nextReload);
  3741. this.vm.$emit('update', this.api);
  3742. },
  3743. refresh: function refresh() {
  3744. this.vm._refresh();
  3745. }
  3746. });
  3747. }
  3748. function fullRule(rule) {
  3749. var def = baseRule();
  3750. Object.keys(def).forEach(function (k) {
  3751. if (!hasProperty(rule, k)) $set(rule, k, def[k]);
  3752. });
  3753. return rule;
  3754. }
  3755. function getCtrl(ctx) {
  3756. var control = ctx.rule.control || [];
  3757. if (is.Object(control)) return [control];else return control;
  3758. }
  3759. function findCtrl(ctx, rule) {
  3760. for (var i = 0; i < ctx.ctrlRule.length; i++) {
  3761. var ctrl = ctx.ctrlRule[i];
  3762. if (ctrl.children === rule) return ctrl;
  3763. }
  3764. }
  3765. function isCtrl(ctx) {
  3766. return !!ctx.rule.__ctrl;
  3767. }
  3768. function useInput(Handler) {
  3769. extend(Handler.prototype, {
  3770. getValue: function getValue(ctx) {
  3771. if (is.Undef(ctx.cacheValue)) {
  3772. ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
  3773. }
  3774. return ctx.cacheValue;
  3775. },
  3776. setValue: function setValue(ctx, value, formValue, setFlag) {
  3777. if (ctx.deleted) return;
  3778. ctx.cacheValue = value;
  3779. this.changeStatus = true;
  3780. this.nextRefresh();
  3781. this.$render.clearCache(ctx);
  3782. this.setFormData(ctx, formValue);
  3783. this.syncValue();
  3784. this.valueChange(ctx, value);
  3785. this.vm.$emit('change', ctx.field, value, ctx.origin, this.api, setFlag || false);
  3786. this.effect(ctx, 'value');
  3787. },
  3788. onInput: function onInput(ctx, value) {
  3789. var val;
  3790. if (ctx.input && (this.isQuote(ctx, val = ctx.parser.toValue(value, ctx)) || this.isChange(ctx, val))) {
  3791. this.setValue(ctx, val, value);
  3792. }
  3793. },
  3794. setFormData: function setFormData(ctx, value) {
  3795. $set(this.formData, ctx.id, value === null ? undefined : value);
  3796. },
  3797. getFormData: function getFormData(ctx) {
  3798. return this.formData[ctx.id];
  3799. },
  3800. validate: function validate() {
  3801. var _this = this;
  3802. toEmpty(this.vm.validate);
  3803. this.fields().forEach(function (id) {
  3804. _this.fieldCtx[id].forEach(function (ctx) {
  3805. _this.vm.validate[ctx.id] = toArray(ctx.rule.validate);
  3806. });
  3807. });
  3808. return this.vm.validate;
  3809. },
  3810. syncForm: function syncForm() {
  3811. var _this2 = this;
  3812. toEmpty(this.form);
  3813. Object.defineProperties(this.form, this.fields().reduce(function (initial, field) {
  3814. var ctx = _this2.getFieldCtx(field);
  3815. var handle = _this2.valueHandle(ctx);
  3816. handle.configurable = true;
  3817. initial[field] = handle;
  3818. return initial;
  3819. }, this.options.appendValue ? Object.keys(this.appendData).reduce(function (initial, field) {
  3820. initial[field] = {
  3821. enumerable: true,
  3822. configurable: true,
  3823. get: function get() {
  3824. return _this2.appendData[field];
  3825. },
  3826. set: function set(val) {
  3827. _this2.appendData[field] = val;
  3828. }
  3829. };
  3830. return initial;
  3831. }, {}) : {}));
  3832. this.syncValue();
  3833. },
  3834. valueHandle: function valueHandle(ctx) {
  3835. var _this3 = this;
  3836. return {
  3837. enumerable: true,
  3838. get: function get() {
  3839. return _this3.getValue(ctx);
  3840. },
  3841. set: function set(value) {
  3842. if (_this3.isChange(ctx, value)) {
  3843. _this3.setValue(ctx, value, ctx.parser.toFormValue(value, ctx), true);
  3844. }
  3845. }
  3846. };
  3847. },
  3848. appendValue: function appendValue(rule) {
  3849. if (!rule.field || !hasProperty(this.appendData, rule.field)) return;
  3850. rule.value = this.appendData[rule.field];
  3851. delete this.appendData[rule.field];
  3852. },
  3853. addSubForm: function addSubForm(ctx, subForm) {
  3854. this.subForm[ctx.id] = subForm;
  3855. },
  3856. deferSyncValue: function deferSyncValue(fn, sync) {
  3857. if (!this.deferSyncFn) {
  3858. this.deferSyncFn = fn;
  3859. }
  3860. if (!this.deferSyncFn.sync) {
  3861. this.deferSyncFn.sync = sync;
  3862. }
  3863. invoke(fn);
  3864. if (this.deferSyncFn === fn) {
  3865. this.deferSyncFn = null;
  3866. if (fn.sync) {
  3867. this.syncValue();
  3868. }
  3869. }
  3870. },
  3871. syncValue: function syncValue() {
  3872. if (this.deferSyncFn) {
  3873. return this.deferSyncFn.sync = true;
  3874. }
  3875. this.vm._updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue ? this.appendData : {}), this.form));
  3876. },
  3877. isChange: function isChange(ctx, value) {
  3878. return JSON.stringify(ctx.rule.value, strFn) !== JSON.stringify(value === null ? undefined : value, strFn);
  3879. },
  3880. isQuote: function isQuote(ctx, value) {
  3881. return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
  3882. },
  3883. refreshUpdate: function refreshUpdate(ctx, val) {
  3884. var _this4 = this;
  3885. if (is.Function(ctx.rule.update)) {
  3886. var state = invoke(function () {
  3887. return ctx.rule.update(val, ctx.origin, _this4.api);
  3888. });
  3889. if (state === undefined) return;
  3890. ctx.rule.hidden = state === true;
  3891. }
  3892. },
  3893. valueChange: function valueChange(ctx, val) {
  3894. this.refreshRule(ctx, val);
  3895. this.bus.$emit('change-' + ctx.field, val);
  3896. },
  3897. refreshRule: function refreshRule(ctx, val) {
  3898. if (this.refreshControl(ctx)) {
  3899. this.$render.clearCacheAll();
  3900. this.loadRule();
  3901. this.vm.$emit('update', this.api);
  3902. this.refresh();
  3903. }
  3904. this.refreshUpdate(ctx, val);
  3905. },
  3906. appendLink: function appendLink(ctx) {
  3907. var _this5 = this;
  3908. var link = ctx.rule.link;
  3909. is.trueArray(link) && link.forEach(function (field) {
  3910. var fn = function fn() {
  3911. return _this5.refreshRule(ctx, ctx.rule.value);
  3912. };
  3913. _this5.bus.$on('change-' + field, fn);
  3914. ctx.linkOn.push(function () {
  3915. return _this5.bus.$off('change-' + field, fn);
  3916. });
  3917. });
  3918. },
  3919. fields: function fields() {
  3920. return Object.keys(this.fieldCtx);
  3921. }
  3922. });
  3923. }
  3924. function strFn(key, val) {
  3925. return typeof val === 'function' ? '' + val : val;
  3926. }
  3927. function toEmpty(obj) {
  3928. Object.keys(obj).forEach(function (k) {
  3929. return delete obj[k];
  3930. });
  3931. }
  3932. var BaseParser = {
  3933. init: function init(ctx) {},
  3934. toFormValue: function toFormValue(value, ctx) {
  3935. return value;
  3936. },
  3937. toValue: function toValue(formValue, ctx) {
  3938. return formValue;
  3939. },
  3940. mounted: function mounted(ctx) {},
  3941. render: function render(children, ctx) {
  3942. return ctx.$render.defaultRender(ctx, children);
  3943. },
  3944. preview: function preview(children, ctx) {
  3945. return this.render(children, ctx);
  3946. },
  3947. mergeProp: function mergeProp(ctx) {}
  3948. };
  3949. var noneKey = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'component', 'cache'];
  3950. function useContext(Handler) {
  3951. extend(Handler.prototype, {
  3952. getCtx: function getCtx(id) {
  3953. return this.getFieldCtx(id) || this.getNameCtx(id)[0] || this.ctxs[id];
  3954. },
  3955. getCtxs: function getCtxs(id) {
  3956. return this.fieldCtx[id] || this.nameCtx[id] || (this.ctxs[id] ? [this.ctxs[id]] : []);
  3957. },
  3958. setIdCtx: function setIdCtx(ctx, key, type) {
  3959. var field = "".concat(type, "Ctx");
  3960. if (!this[field][key]) {
  3961. this[field][key] = [ctx];
  3962. } else {
  3963. this[field][key].push(ctx);
  3964. }
  3965. },
  3966. rmIdCtx: function rmIdCtx(ctx, key, type) {
  3967. var field = "".concat(type, "Ctx");
  3968. var lst = this[field][key];
  3969. if (!lst) return false;
  3970. var flag = lst.splice(lst.indexOf(ctx) >>> 0, 1).length > 0;
  3971. if (!lst.length) {
  3972. delete this[field][key];
  3973. }
  3974. return flag;
  3975. },
  3976. getFieldCtx: function getFieldCtx(field) {
  3977. return (this.fieldCtx[field] || [])[0];
  3978. },
  3979. getNameCtx: function getNameCtx(name) {
  3980. return this.nameCtx[name] || [];
  3981. },
  3982. setCtx: function setCtx(ctx) {
  3983. var id = ctx.id,
  3984. field = ctx.field,
  3985. name = ctx.name,
  3986. rule = ctx.rule;
  3987. this.ctxs[id] = ctx;
  3988. name && this.setIdCtx(ctx, name, 'name');
  3989. if (!ctx.input) return;
  3990. this.setIdCtx(ctx, field, 'field');
  3991. this.setFormData(ctx, ctx.parser.toFormValue(rule.value, ctx));
  3992. if (this.isMounted && !this.reloading) {
  3993. this.vm.$emit('change', ctx.field, rule.value, ctx.origin, this.api);
  3994. }
  3995. },
  3996. getParser: function getParser(ctx) {
  3997. var list = this.fc.parsers;
  3998. return list[ctx.originType] || list[toCase(ctx.type)] || list[ctx.trueType] || BaseParser;
  3999. },
  4000. bindParser: function bindParser(ctx) {
  4001. ctx.setParser(this.getParser(ctx));
  4002. },
  4003. getType: function getType(alias) {
  4004. var map = this.fc.CreateNode.aliasMap;
  4005. var type = map[alias] || map[toCase(alias)] || alias;
  4006. return toCase(type);
  4007. },
  4008. noWatch: function noWatch(fn) {
  4009. if (!this.noWatchFn) {
  4010. this.noWatchFn = fn;
  4011. }
  4012. invoke(fn);
  4013. if (this.noWatchFn === fn) {
  4014. this.noWatchFn = null;
  4015. }
  4016. },
  4017. watchCtx: function watchCtx(ctx) {
  4018. var _this = this;
  4019. var vm = this.vm;
  4020. Object.keys(ctx.rule).filter(function (k) {
  4021. return k[0] !== '_' && k[0] !== '$' && noneKey.indexOf(k) === -1;
  4022. }).forEach(function (key) {
  4023. var flag = key === 'children';
  4024. ctx.watch.push(vm.$watch(function () {
  4025. return ctx.rule[key];
  4026. }, function (n, o) {
  4027. if (_this.loading || _this.noWatchFn || _this.reloading) return;
  4028. if (flag && ctx.parser.loadChildren === false) {
  4029. _this.$render.clearCache(ctx);
  4030. _this.nextRefresh();
  4031. return;
  4032. }
  4033. _this.watching = true;
  4034. if (key === 'link') {
  4035. ctx.link();
  4036. return;
  4037. } else if (['props', 'on', 'nativeOn', 'deep'].indexOf(key) > -1) {
  4038. _this.parseInjectEvent(ctx.rule, n || {});
  4039. if (key === 'props' && ctx.input) {
  4040. _this.setFormData(ctx, ctx.parser.toFormValue(ctx.rule.value, ctx));
  4041. }
  4042. } else if (['emit', 'nativeEmit'].indexOf(key) > -1) _this.parseEmit(ctx, key === 'emit');else if (['prefix', 'suffix'].indexOf(key) > -1) n && _this.loadFn(n, ctx.rule);else if (key === 'type') {
  4043. ctx.updateType();
  4044. _this.bindParser(ctx);
  4045. } else if (key === 'children') {
  4046. var _flag = is.trueArray(n);
  4047. _this.deferSyncValue(function () {
  4048. if (n !== o) {
  4049. _this.rmSub(o, ctx);
  4050. _this.$render.initOrgChildren();
  4051. }
  4052. _flag && _this.loadChildren(n, ctx);
  4053. _this.vm.$emit('update', _this.api);
  4054. });
  4055. }
  4056. _this.$render.clearCache(ctx);
  4057. _this.refresh();
  4058. _this.watching = false;
  4059. }, {
  4060. deep: !flag,
  4061. sync: flag
  4062. }));
  4063. });
  4064. this.watchEffect(ctx);
  4065. },
  4066. rmSub: function rmSub(sub, ctx) {
  4067. var _this2 = this;
  4068. is.trueArray(sub) && sub.forEach(function (r) {
  4069. r && r.__fc__ && r.__fc__.parent === ctx && _this2.rmCtx(r.__fc__);
  4070. });
  4071. },
  4072. rmCtx: function rmCtx(ctx) {
  4073. var _this3 = this;
  4074. if (ctx.deleted) return;
  4075. var id = ctx.id,
  4076. field = ctx.field,
  4077. input = ctx.input,
  4078. name = ctx.name;
  4079. if (ctx.input) {
  4080. Object.defineProperty(ctx.rule, 'value', {
  4081. value: ctx.rule.value,
  4082. writable: true
  4083. });
  4084. }
  4085. $del(this.ctxs, id);
  4086. $del(this.$render.tempList, id);
  4087. $del(this.$render.orgChildren, id);
  4088. $del(this.vm.ctxInject, id);
  4089. $del(this.formData, id);
  4090. $del(this.subForm, id);
  4091. $del(ctx, 'cacheValue');
  4092. input && this.rmIdCtx(ctx, field, 'field');
  4093. name && this.rmIdCtx(ctx, name, 'name');
  4094. if (input && !hasProperty(this.fieldCtx, field)) {
  4095. $del(this.form, field);
  4096. }
  4097. this.deferSyncValue(function () {
  4098. if (!_this3.reloading) {
  4099. if (ctx.parser.loadChildren !== false) {
  4100. if (is.trueArray(ctx.rule.children)) {
  4101. ctx.rule.children.forEach(function (h) {
  4102. return h.__fc__ && _this3.rmCtx(h.__fc__);
  4103. });
  4104. }
  4105. }
  4106. if (ctx.root === _this3.rules) {
  4107. _this3.vm._renderRule();
  4108. }
  4109. }
  4110. }, input);
  4111. var index = this.sort.indexOf(id);
  4112. if (index > -1) {
  4113. this.sort.splice(index, 1);
  4114. }
  4115. this.$render.clearCache(ctx);
  4116. ctx["delete"]();
  4117. this.effect(ctx, 'deleted');
  4118. input && !this.fieldCtx[field] && this.vm.$emit('removeField', field, ctx.rule, this.api);
  4119. ctx.rule.__ctrl || this.vm.$emit('removeRule', ctx.rule, this.api);
  4120. return ctx;
  4121. }
  4122. });
  4123. }
  4124. function useLifecycle(Handler) {
  4125. extend(Handler.prototype, {
  4126. mounted: function mounted() {
  4127. var _this = this;
  4128. var _mounted = function _mounted() {
  4129. _this.isMounted = true;
  4130. _this.lifecycle('mounted');
  4131. };
  4132. if (this.pageEnd) {
  4133. _mounted();
  4134. } else {
  4135. this.bus.$once('page-end', _mounted);
  4136. }
  4137. },
  4138. lifecycle: function lifecycle(name) {
  4139. var _this2 = this;
  4140. var fn = this.options[name];
  4141. is.Function(fn) && invoke(function () {
  4142. return fn(_this2.api);
  4143. });
  4144. this.vm.$emit(name, this.api);
  4145. }
  4146. });
  4147. }
  4148. function useEffect(Handler) {
  4149. extend(Handler.prototype, {
  4150. useProvider: function useProvider() {
  4151. var _this = this;
  4152. var ps = this.fc.providers;
  4153. Object.keys(ps).forEach(function (k) {
  4154. var prop = ps[k];
  4155. if (is.Function(prop)) {
  4156. prop = prop(_this.fc);
  4157. }
  4158. prop._c = getComponent(prop);
  4159. _this.onEffect(prop);
  4160. _this.providers[k] = prop;
  4161. });
  4162. },
  4163. onEffect: function onEffect(provider) {
  4164. var _this2 = this;
  4165. var used = [];
  4166. (provider._c || ['*']).forEach(function (name) {
  4167. var type = name === '*' ? '*' : _this2.getType(name);
  4168. if (used.indexOf(type) > -1) return;
  4169. used.push(type);
  4170. _this2.bus.$on("p:".concat(provider.name, ":").concat(type, ":").concat(provider.input ? 1 : 0), function (event, args) {
  4171. provider[event] && provider[event].apply(provider, _toConsumableArray(args));
  4172. });
  4173. });
  4174. provider._used = used;
  4175. },
  4176. watchEffect: function watchEffect(ctx) {
  4177. var _this3 = this;
  4178. var vm = this.vm;
  4179. var effect = {};
  4180. Object.keys(ctx.rule.effect || {}).forEach(function (k) {
  4181. effect[k] = function () {
  4182. return ctx.rule.effect[k];
  4183. };
  4184. });
  4185. Object.keys(ctx.rule).forEach(function (k) {
  4186. if (k[0] === '$') {
  4187. effect[k.substr(1)] = function () {
  4188. return ctx.rule[k];
  4189. };
  4190. }
  4191. });
  4192. Object.keys(effect || {}).forEach(function (k) {
  4193. ctx.watch.push(vm.$watch(effect[k], function (n) {
  4194. _this3.effect(ctx, 'watch', _defineProperty({}, k, n));
  4195. }, {
  4196. deep: true
  4197. }));
  4198. });
  4199. },
  4200. ruleEffect: function ruleEffect(rule, event, append) {
  4201. this.emitEffect({
  4202. rule: rule,
  4203. input: !!rule.field,
  4204. type: this.getType(rule.type)
  4205. }, event, append);
  4206. },
  4207. effect: function effect(ctx, event, custom) {
  4208. this.emitEffect({
  4209. rule: ctx.rule,
  4210. input: ctx.input,
  4211. type: ctx.trueType,
  4212. ctx: ctx,
  4213. custom: custom
  4214. }, event);
  4215. },
  4216. getEffect: function getEffect(rule, name) {
  4217. if (hasProperty(rule, '$' + name)) {
  4218. return rule['$' + name];
  4219. }
  4220. if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];
  4221. return undefined;
  4222. },
  4223. emitEffect: function emitEffect(_ref, event, append) {
  4224. var _this4 = this;
  4225. var ctx = _ref.ctx,
  4226. rule = _ref.rule,
  4227. input = _ref.input,
  4228. type = _ref.type,
  4229. custom = _ref.custom;
  4230. if (!type || type === 'fcFragment') return;
  4231. var effect = custom ? custom : Object.keys(rule).reduce(function (i, k) {
  4232. if (k[0] === '$') {
  4233. i[k.substr(1)] = rule[k];
  4234. }
  4235. return i;
  4236. }, _objectSpread2({}, rule.effect || {}));
  4237. Object.keys(effect).forEach(function (attr) {
  4238. var p = _this4.providers[attr];
  4239. if (!p || p.input && !input) return;
  4240. var _type;
  4241. if (!p._c) {
  4242. _type = '*';
  4243. } else if (p._used.indexOf(type) > -1) {
  4244. _type = type;
  4245. } else {
  4246. return;
  4247. }
  4248. var data = _objectSpread2({
  4249. value: effect[attr],
  4250. getValue: function getValue() {
  4251. return _this4.getEffect(rule, attr);
  4252. }
  4253. }, append || {});
  4254. if (ctx) {
  4255. data.getProp = function () {
  4256. return ctx.effectData(attr);
  4257. };
  4258. data.clearProp = function () {
  4259. return ctx.clearEffectData(attr);
  4260. };
  4261. data.mergeProp = function (prop) {
  4262. return mergeProps([prop], data.getProp());
  4263. };
  4264. }
  4265. _this4.bus.$emit("p:".concat(attr, ":").concat(_type, ":").concat(p.input ? 1 : 0), event, [data, rule, _this4.api]);
  4266. });
  4267. }
  4268. });
  4269. }
  4270. function unique(arr) {
  4271. return arr.filter(function (item, index, arr) {
  4272. return arr.indexOf(item, 0) === index;
  4273. });
  4274. }
  4275. function getComponent(p) {
  4276. var c = p.components;
  4277. if (Array.isArray(c)) return unique(c.filter(function (v) {
  4278. return v !== '*';
  4279. }));else if (is.String(c)) return [c];else return false;
  4280. }
  4281. function Handler(fc) {
  4282. var _this = this;
  4283. extend(this, {
  4284. fc: fc,
  4285. vm: fc.vm,
  4286. watching: false,
  4287. loading: false,
  4288. reloading: false,
  4289. noWatchFn: null,
  4290. deferSyncFn: null,
  4291. isMounted: false,
  4292. formData: {},
  4293. subForm: {},
  4294. form: {},
  4295. appendData: {},
  4296. providers: {},
  4297. cycleLoad: null,
  4298. loadedId: 1,
  4299. nextTick: null,
  4300. changeStatus: false,
  4301. pageEnd: true,
  4302. nextReload: function nextReload() {
  4303. _this.lifecycle('reload');
  4304. }
  4305. });
  4306. funcProxy(this, {
  4307. options: function options() {
  4308. return fc.options;
  4309. },
  4310. bus: function bus() {
  4311. return fc.bus;
  4312. }
  4313. });
  4314. this.initData(fc.rules);
  4315. this.$manager = new fc.manager(this);
  4316. this.$render = new Render(this);
  4317. this.api = fc.extendApi(Api(this), this);
  4318. }
  4319. extend(Handler.prototype, {
  4320. initData: function initData(rules) {
  4321. extend(this, {
  4322. ctxs: {},
  4323. fieldCtx: {},
  4324. nameCtx: {},
  4325. sort: [],
  4326. rules: rules
  4327. });
  4328. },
  4329. init: function init() {
  4330. this.appendData = _objectSpread2(_objectSpread2(_objectSpread2({}, this.fc.options.formData || {}), this.vm.value || {}), this.appendData);
  4331. this.useProvider();
  4332. this.usePage();
  4333. this.loadRule();
  4334. this.$manager.__init();
  4335. this.vm.$set(this.vm, 'formData', this.formData);
  4336. }
  4337. });
  4338. useInject(Handler);
  4339. usePage(Handler);
  4340. useRender$1(Handler);
  4341. useLoader(Handler);
  4342. useInput(Handler);
  4343. useContext(Handler);
  4344. useLifecycle(Handler);
  4345. useEffect(Handler);
  4346. function getError(action, option, xhr) {
  4347. var msg = "fail to ".concat(action, " ").concat(xhr.status, "'");
  4348. var err = new Error(msg);
  4349. err.status = xhr.status;
  4350. err.url = action;
  4351. return err;
  4352. }
  4353. function getBody(xhr) {
  4354. var text = xhr.responseText || xhr.response;
  4355. if (!text) {
  4356. return text;
  4357. }
  4358. try {
  4359. return JSON.parse(text);
  4360. } catch (e) {
  4361. return text;
  4362. }
  4363. }
  4364. function fetch(option) {
  4365. if (typeof XMLHttpRequest === 'undefined') {
  4366. return;
  4367. }
  4368. var xhr = new XMLHttpRequest();
  4369. var action = option.action;
  4370. xhr.onerror = function error(e) {
  4371. option.onError(e);
  4372. };
  4373. xhr.onload = function onload() {
  4374. if (xhr.status < 200 || xhr.status >= 300) {
  4375. return option.onError(getError(action, option, xhr), getBody(xhr));
  4376. }
  4377. option.onSuccess(getBody(xhr));
  4378. };
  4379. xhr.open(option.method || 'get', action, true);
  4380. var formData;
  4381. if (option.data) {
  4382. if ((option.dataType || '').toLowerCase() !== 'json') {
  4383. formData = new FormData();
  4384. Object.keys(option.data).map(function (key) {
  4385. formData.append(key, option.data[key]);
  4386. });
  4387. } else {
  4388. formData = JSON.stringify(option.data);
  4389. xhr.setRequestHeader('content-type', 'application/json');
  4390. }
  4391. }
  4392. if (option.withCredentials && 'withCredentials' in xhr) {
  4393. xhr.withCredentials = true;
  4394. }
  4395. var headers = option.headers || {};
  4396. Object.keys(headers).forEach(function (item) {
  4397. if (headers[item] !== null) {
  4398. xhr.setRequestHeader(item, headers[item]);
  4399. }
  4400. });
  4401. xhr.send(formData);
  4402. }
  4403. var NAME$9 = 'fcFragment';
  4404. var fragment = {
  4405. name: NAME$9,
  4406. functional: true,
  4407. props: ['vnode'],
  4408. render: function render(h, ctx) {
  4409. return ctx.props.vnode ? ctx.props.vnode : ctx.children;
  4410. }
  4411. };
  4412. function parseProp(prop) {
  4413. if (is.String(prop)) return {
  4414. domProps: {
  4415. innerHTML: prop
  4416. }
  4417. };
  4418. return prop;
  4419. }
  4420. function CreateNodeFactory() {
  4421. var aliasMap = {};
  4422. function CreateNode(vm) {
  4423. vm && this.setVm(vm);
  4424. }
  4425. extend(CreateNode.prototype, {
  4426. setVm: function setVm(vm) {
  4427. this.vm = vm;
  4428. this.$h = vm.$createElement;
  4429. },
  4430. make: function make(tag, data, children) {
  4431. if (Vue.config.isReservedTag(tag) && data.nativeOn) delete data.nativeOn;
  4432. return this.makeComponent(tag, data, children);
  4433. },
  4434. makeComponent: function makeComponent(type, data, children) {
  4435. var Node = this.$h(type, parseProp(data), children || []);
  4436. Node.context = this.vm;
  4437. return Node;
  4438. },
  4439. aliasMap: aliasMap
  4440. });
  4441. extend(CreateNode, {
  4442. aliasMap: aliasMap,
  4443. alias: function alias(_alias, name) {
  4444. aliasMap[_alias] = name;
  4445. },
  4446. use: function use(nodes) {
  4447. Object.keys(nodes).forEach(function (k) {
  4448. var line = toLine(k);
  4449. var lower = toString$1(k).toLocaleLowerCase();
  4450. var v = nodes[k];
  4451. [k, line, lower].forEach(function (n) {
  4452. CreateNode.alias(k, v);
  4453. CreateNode.prototype[n] = function (data, children) {
  4454. return this.make(v, data, children);
  4455. };
  4456. });
  4457. });
  4458. }
  4459. });
  4460. return CreateNode;
  4461. }
  4462. function createManager(proto) {
  4463. var CustomManager = function (_Manager) {
  4464. _inherits(CustomManager, _Manager);
  4465. var _super = _createSuper(CustomManager);
  4466. function CustomManager() {
  4467. _classCallCheck(this, CustomManager);
  4468. return _super.apply(this, arguments);
  4469. }
  4470. return CustomManager;
  4471. }(Manager);
  4472. Object.assign(CustomManager.prototype, proto);
  4473. return CustomManager;
  4474. }
  4475. function Manager(handler) {
  4476. extend(this, {
  4477. $handle: handler,
  4478. vm: handler.vm,
  4479. options: {},
  4480. ref: 'fcForm',
  4481. mergeOptionsRule: {
  4482. normal: ['form', 'row', 'info', 'submitBtn', 'resetBtn']
  4483. }
  4484. });
  4485. this.updateKey();
  4486. this.init();
  4487. }
  4488. extend(Manager.prototype, {
  4489. __init: function __init() {
  4490. var _this = this;
  4491. this.$render = this.$handle.$render;
  4492. this.$r = function () {
  4493. var _this$$render;
  4494. return (_this$$render = _this.$render).renderRule.apply(_this$$render, arguments);
  4495. };
  4496. },
  4497. updateKey: function updateKey() {
  4498. this.key = uniqueId();
  4499. },
  4500. init: function init() {},
  4501. update: function update() {},
  4502. beforeRender: function beforeRender() {},
  4503. form: function form() {
  4504. return this.vm.$refs[this.ref];
  4505. },
  4506. mergeOptions: function mergeOptions(args, opt) {
  4507. var _this2 = this;
  4508. return mergeProps(args.map(function (v) {
  4509. return _this2.tidyOptions(v);
  4510. }), opt, this.mergeOptionsRule);
  4511. },
  4512. updateOptions: function updateOptions(options) {
  4513. this.options = this.mergeOptions([options], this.getDefaultOptions());
  4514. this.update();
  4515. },
  4516. tidyOptions: function tidyOptions(options) {
  4517. return options;
  4518. },
  4519. tidyRule: function tidyRule(ctx) {},
  4520. mergeProp: function mergeProp(ctx) {},
  4521. getDefaultOptions: function getDefaultOptions() {
  4522. return {};
  4523. },
  4524. render: function render(children) {}
  4525. });
  4526. var fetch$1 = function fetch(fc) {
  4527. function parseOpt(option) {
  4528. if (is.String(option)) {
  4529. option = {
  4530. action: option,
  4531. to: 'options'
  4532. };
  4533. }
  4534. return option;
  4535. }
  4536. function run(inject, rule, api) {
  4537. var option = inject.value;
  4538. if (is.Function(option)) {
  4539. option = option(rule, api);
  4540. }
  4541. option = parseOpt(option);
  4542. if (!option || !option.action) {
  4543. return false;
  4544. }
  4545. if (!option.to) {
  4546. option.to = 'options';
  4547. }
  4548. var _onError = option.onError;
  4549. var check = function check() {
  4550. if (!inject.getValue()) {
  4551. inject.clearProp();
  4552. api.sync(rule);
  4553. return true;
  4554. }
  4555. };
  4556. var set = function set(val) {
  4557. if (val === undefined) {
  4558. inject.clearProp();
  4559. api.sync(rule);
  4560. } else {
  4561. deepSet(inject.getProp(), option.to, val);
  4562. }
  4563. };
  4564. invoke(function () {
  4565. return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
  4566. onSuccess: function onSuccess(body) {
  4567. if (check()) return;
  4568. var fn = function fn(v) {
  4569. return v.data;
  4570. };
  4571. if (is.Function(option.parse)) {
  4572. fn = option.parse;
  4573. }
  4574. set(fn(body, rule, api));
  4575. api.sync(rule);
  4576. },
  4577. onError: function onError(e) {
  4578. set(undefined);
  4579. if (check()) return;
  4580. (_onError || function (e) {
  4581. return err(e.message || 'fetch fail ' + option.action);
  4582. })(e, rule, api);
  4583. }
  4584. }), {
  4585. inject: inject,
  4586. rule: rule,
  4587. api: api
  4588. });
  4589. });
  4590. return true;
  4591. }
  4592. return {
  4593. name: 'fetch',
  4594. loaded: function loaded() {
  4595. run.apply(void 0, arguments);
  4596. },
  4597. watch: function watch(inject, rule, api) {
  4598. if (!run(inject, rule, api)) {
  4599. inject.clearProp();
  4600. api.sync(rule);
  4601. }
  4602. }
  4603. };
  4604. };
  4605. var $required = {
  4606. name: 'required',
  4607. load: function load(inject, rule, api) {
  4608. var val = parseVal(inject.getValue());
  4609. if (val.required === false) {
  4610. inject.clearProp();
  4611. } else {
  4612. var validate = _objectSpread2({
  4613. required: true,
  4614. validator: function validator(_, v, call) {
  4615. is.empty(v) ? call(validate.message) : call();
  4616. }
  4617. }, val);
  4618. if (!validate.message) {
  4619. var title = rule.title || '';
  4620. validate.message = ((_typeof(title) === 'object' ? title.title : title) || '') + '不能为空';
  4621. }
  4622. inject.getProp().validate = [validate];
  4623. }
  4624. api.sync(rule);
  4625. },
  4626. watch: function watch() {
  4627. $required.load.apply($required, arguments);
  4628. }
  4629. };
  4630. function parseVal(val) {
  4631. if (is.Boolean(val)) {
  4632. return {
  4633. required: val
  4634. };
  4635. } else if (is.String(val)) {
  4636. return {
  4637. message: val
  4638. };
  4639. } else if (is.Function(val)) {
  4640. return {
  4641. validator: val
  4642. };
  4643. } else if (!is.Object(val)) {
  4644. return {};
  4645. } else {
  4646. return val;
  4647. }
  4648. }
  4649. var $provider = {
  4650. fetch: fetch$1,
  4651. required: $required
  4652. };
  4653. var name = 'html';
  4654. var html = {
  4655. name: name,
  4656. loadChildren: false,
  4657. render: function render(children, ctx) {
  4658. if (!ctx.prop.domProps) ctx.prop.domProps = {};
  4659. ctx.prop.domProps.innerHTML = children;
  4660. return ctx.vNode.make(ctx.prop.props.tag || 'div', ctx.prop);
  4661. },
  4662. renderChildren: function renderChildren(ctx) {
  4663. if (Array.isArray(ctx.rule.children)) {
  4664. return ctx.rule.children.filter(function (v) {
  4665. return is.String(v);
  4666. }).join('');
  4667. }
  4668. return '';
  4669. }
  4670. };
  4671. var _vue = typeof window !== 'undefined' && window.Vue ? window.Vue : Vue;
  4672. function _parseProp(name, id) {
  4673. var prop;
  4674. if (arguments.length === 2) {
  4675. prop = arguments[1];
  4676. id = prop[name];
  4677. } else {
  4678. prop = arguments[2];
  4679. }
  4680. return {
  4681. id: id,
  4682. prop: prop
  4683. };
  4684. }
  4685. function nameProp() {
  4686. return _parseProp.apply(void 0, ['name'].concat(Array.prototype.slice.call(arguments)));
  4687. }
  4688. function _getEl(options) {
  4689. if (!options || !options.el) return window.document.body;
  4690. return is.Element(options.el) ? options.el : document.querySelector(options.el);
  4691. }
  4692. function mountForm(rules, option) {
  4693. var $vm = new _vue({
  4694. data: function data() {
  4695. return {
  4696. rule: rules,
  4697. option: option || {}
  4698. };
  4699. },
  4700. render: function render(h) {
  4701. return h('FormCreate', {
  4702. ref: 'fc',
  4703. props: this.$data
  4704. });
  4705. }
  4706. });
  4707. $vm.$mount();
  4708. return $vm;
  4709. }
  4710. function exportAttrs(attrs) {
  4711. var key = attrs.key || [];
  4712. var array = attrs.array || [];
  4713. var normal = attrs.normal || [];
  4714. keyAttrs.push.apply(keyAttrs, _toConsumableArray(key));
  4715. arrayAttrs.push.apply(arrayAttrs, _toConsumableArray(array));
  4716. normalAttrs.push.apply(normalAttrs, _toConsumableArray(normal));
  4717. appendProto([].concat(_toConsumableArray(key), _toConsumableArray(array), _toConsumableArray(normal)));
  4718. }
  4719. var id$1 = 1;
  4720. var instance = {};
  4721. function FormCreateFactory(config) {
  4722. var components = _defineProperty({}, fragment.name, fragment);
  4723. var parsers = {};
  4724. var directives = {};
  4725. var providers = _objectSpread2({}, $provider);
  4726. var maker = makerFactory();
  4727. var globalConfig = {
  4728. global: {}
  4729. };
  4730. var data = {};
  4731. var CreateNode = CreateNodeFactory();
  4732. exportAttrs(config.attrs || {});
  4733. function getApi(name) {
  4734. var val = instance[name];
  4735. if (Array.isArray(val)) return _toConsumableArray(val);
  4736. return val;
  4737. }
  4738. function directive() {
  4739. var data = nameProp.apply(void 0, arguments);
  4740. if (data.id && data.prop) directives[data.id] = data.prop;
  4741. }
  4742. function register() {
  4743. var data = nameProp.apply(void 0, arguments);
  4744. if (data.id && data.prop) providers[data.id] = _objectSpread2(_objectSpread2({}, data.prop), {}, {
  4745. name: data.id
  4746. });
  4747. }
  4748. function componentAlias(alias) {
  4749. CreateNode.use(alias);
  4750. }
  4751. function parser() {
  4752. var data = nameProp.apply(void 0, arguments);
  4753. if (!data.id || !data.prop) return;
  4754. var name = toCase(data.id);
  4755. var parser = data.prop;
  4756. var base = parser.merge === true ? parsers[name] : undefined;
  4757. parsers[name] = _objectSpread2(_objectSpread2({}, base || BaseParser), parser);
  4758. maker[name] = creatorFactory(name);
  4759. parser.maker && extend(maker, parser.maker);
  4760. }
  4761. function component(id, component) {
  4762. var name;
  4763. if (is.String(id)) {
  4764. name = toCase(id);
  4765. if (['form-create', 'formcreate'].indexOf(name) > -1) {
  4766. return $form();
  4767. } else if (component === undefined) {
  4768. return components[name];
  4769. }
  4770. } else {
  4771. name = toCase(id.name);
  4772. component = id;
  4773. }
  4774. if (!name || !component) return;
  4775. components[name] = component;
  4776. if (component.formCreateParser) parser(name, component.formCreateParser);
  4777. }
  4778. function $form() {
  4779. return _vue.extend($FormCreate(FormCreate));
  4780. }
  4781. function $vnode() {
  4782. return _vue.extend(fragment);
  4783. }
  4784. function use(fn, opt) {
  4785. if (is.Function(fn.install)) fn.install(create, opt);else if (is.Function(fn)) fn(create, opt);
  4786. return this;
  4787. }
  4788. function create(rules, _opt, parent) {
  4789. var $vm = mountForm(rules, _opt || {});
  4790. var _this = $vm.$refs.fc.formCreate;
  4791. _this.$parent = parent;
  4792. _getEl(_this.options).appendChild($vm.$el);
  4793. return _this.api();
  4794. }
  4795. function factory(inherit) {
  4796. var _config = _objectSpread2({}, config);
  4797. if (inherit) {
  4798. _config.inherit = {
  4799. components: components,
  4800. parsers: parsers,
  4801. directives: directives,
  4802. providers: providers,
  4803. maker: maker,
  4804. data: data
  4805. };
  4806. } else {
  4807. delete _config.inherit;
  4808. }
  4809. return FormCreateFactory(_config);
  4810. }
  4811. function FormCreate(vm, rules, options) {
  4812. extend(this, {
  4813. id: id$1++,
  4814. vm: vm,
  4815. create: create,
  4816. manager: createManager(config.manager),
  4817. parsers: parsers,
  4818. providers: providers,
  4819. rules: Array.isArray(rules) ? rules : [],
  4820. name: vm.$options.propsData.name,
  4821. inFor: vm.$options.propsData.inFor,
  4822. prop: {
  4823. components: components,
  4824. directives: directives
  4825. },
  4826. CreateNode: CreateNode,
  4827. bus: new _vue(),
  4828. unwatch: null,
  4829. options: options || {},
  4830. extendApi: config.extendApi || function (api) {
  4831. return api;
  4832. }
  4833. });
  4834. this.init();
  4835. this.initOptions(this.options);
  4836. if (this.name) {
  4837. if (this.inFor) {
  4838. if (!instance[this.name]) instance[this.name] = [];
  4839. instance[this.name].push(this.api());
  4840. } else {
  4841. instance[this.name] = this.api();
  4842. }
  4843. }
  4844. }
  4845. extend(FormCreate.prototype, {
  4846. init: function init() {
  4847. var _this2 = this;
  4848. var vm = this.vm;
  4849. var h = new Handler(this);
  4850. this.$handle = h;
  4851. vm.$f = h.api;
  4852. vm.$emit('input', h.api);
  4853. vm.$on('hook:created', function () {
  4854. if (_this2.isSub()) {
  4855. _this2.unwatch = vm.$watch(function () {
  4856. return vm.$pfc.option;
  4857. }, function () {
  4858. _this2.initOptions(_this2.options);
  4859. vm.$f.refresh();
  4860. }, {
  4861. deep: true
  4862. });
  4863. _this2.initOptions(_this2.options);
  4864. }
  4865. _this2.created();
  4866. });
  4867. vm.$on('hook:mounted', function () {
  4868. _this2.mounted();
  4869. });
  4870. vm.$on('hook:beforeDestroy', function () {
  4871. vm.destroyed = true;
  4872. _this2.unwatch && _this2.unwatch();
  4873. h.reloadRule([]);
  4874. if (_this2.name) {
  4875. if (_this2.inFor) {
  4876. var idx = instance[_this2.name].indexOf(_this2.api());
  4877. instance[_this2.name].splice(idx, 1);
  4878. } else {
  4879. delete instance[_this2.name];
  4880. }
  4881. }
  4882. });
  4883. vm.$on('hook:updated', function () {
  4884. h.bindNextTick(function () {
  4885. return _this2.bus.$emit('next-tick', h.api);
  4886. });
  4887. });
  4888. },
  4889. isSub: function isSub() {
  4890. return this.vm.$pfc && this.vm.extendOption;
  4891. },
  4892. initOptions: function initOptions(options) {
  4893. this.options = _objectSpread2({
  4894. formData: {},
  4895. submitBtn: {},
  4896. resetBtn: {}
  4897. }, deepCopy(globalConfig));
  4898. if (this.isSub()) {
  4899. this.mergeOptions(this.options, this.vm.$pfc.$f.config || {}, true);
  4900. }
  4901. this.updateOptions(options);
  4902. },
  4903. mergeOptions: function mergeOptions(target, opt, parent) {
  4904. opt = deepCopy(opt);
  4905. parent && ['page', 'onSubmit', 'mounted', 'reload', 'formData', 'el'].forEach(function (n) {
  4906. delete opt[n];
  4907. });
  4908. if (opt.global) {
  4909. target.global = mergeGlobal(target.global, opt.global);
  4910. delete opt.global;
  4911. }
  4912. this.$handle.$manager.mergeOptions([opt], target);
  4913. return target;
  4914. },
  4915. updateOptions: function updateOptions(options) {
  4916. this.mergeOptions(this.options, options);
  4917. this.$handle.$manager.updateOptions(this.options);
  4918. },
  4919. created: function created() {
  4920. this.$handle.init();
  4921. this.vm.$emit('created', this.api());
  4922. },
  4923. api: function api() {
  4924. return this.$handle.api;
  4925. },
  4926. render: function render() {
  4927. return this.$handle.render();
  4928. },
  4929. mounted: function mounted() {
  4930. this.$handle.mounted();
  4931. }
  4932. });
  4933. function useAttr(formCreate) {
  4934. extend(formCreate, {
  4935. version: config.version,
  4936. ui: config.ui,
  4937. data: data,
  4938. maker: maker,
  4939. component: component,
  4940. directive: directive,
  4941. register: register,
  4942. $vnode: $vnode,
  4943. parser: parser,
  4944. use: use,
  4945. factory: factory,
  4946. componentAlias: componentAlias,
  4947. copyRule: copyRule,
  4948. copyRules: copyRules,
  4949. fetch: fetch,
  4950. $form: $form,
  4951. parseFn: parseFn,
  4952. parseJson: parseJson,
  4953. toJson: toJson,
  4954. getApi: getApi,
  4955. init: function init(rules) {
  4956. var _opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4957. var $vm = mountForm(rules, _opt),
  4958. _this = $vm.$refs.fc.formCreate;
  4959. return {
  4960. mount: function mount($el) {
  4961. if ($el && is.Element($el)) _this.options.el = $el;
  4962. _getEl(_this.options).appendChild($vm.$el);
  4963. return _this.api();
  4964. },
  4965. remove: function remove() {
  4966. $vm.$el.parentNode && $vm.$el.parentNode.removeChild($vm.$el);
  4967. },
  4968. destroy: function destroy() {
  4969. this.remove();
  4970. $vm.$destroy();
  4971. },
  4972. $f: _this.api()
  4973. };
  4974. }
  4975. });
  4976. }
  4977. function useStatic(formCreate) {
  4978. extend(formCreate, {
  4979. create: create,
  4980. install: function install(Vue, options) {
  4981. globalConfig = _objectSpread2(_objectSpread2({}, globalConfig), options || {});
  4982. if (Vue._installedFormCreate === true) return;
  4983. Vue._installedFormCreate = true;
  4984. _vue = Vue;
  4985. var $formCreate = function $formCreate(rules) {
  4986. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4987. return create(rules, opt, this);
  4988. };
  4989. useAttr($formCreate);
  4990. Vue.prototype.$formCreate = $formCreate;
  4991. Vue.component('FormCreate', $form());
  4992. Vue.component('FcFragment', $vnode());
  4993. }
  4994. });
  4995. }
  4996. useAttr(create);
  4997. useStatic(create);
  4998. CreateNode.use({
  4999. fragment: 'fcFragment'
  5000. });
  5001. parser(html);
  5002. if (config.install) create.use(config);
  5003. if (config.inherit) {
  5004. var inherit = config.inherit;
  5005. inherit.components && extend(components, inherit.components);
  5006. inherit.parsers && extend(parsers, inherit.parsers);
  5007. inherit.directives && extend(directives, inherit.directives);
  5008. inherit.providers && extend(providers, inherit.providers);
  5009. inherit.maker && extend(maker, inherit.maker);
  5010. inherit.data && extend(data, inherit.data);
  5011. }
  5012. return create;
  5013. }
  5014. function timeStampToDate(timeStamp) {
  5015. if (is.Date(timeStamp)) return timeStamp;else {
  5016. var date = new Date(timeStamp);
  5017. return date.toString() === 'Invalid Date' ? timeStamp : date;
  5018. }
  5019. }
  5020. var name$1 = 'datePicker';
  5021. var datePicker = {
  5022. name: name$1,
  5023. maker: function () {
  5024. return ['date', 'dateRange', 'datetime', 'datetimeRange', 'year', 'month'].reduce(function (maker, type) {
  5025. maker[type] = creatorFactory(name$1, {
  5026. type: type.toLowerCase()
  5027. });
  5028. return maker;
  5029. }, {});
  5030. }(),
  5031. mergeProp: function mergeProp(ctx) {
  5032. var props = ctx.prop.props;
  5033. if (props.startDate) {
  5034. props.startDate = props.startDate && timeStampToDate(props.startDate);
  5035. }
  5036. },
  5037. isRange: function isRange(el) {
  5038. return el.type.includes('range') || el.multiple;
  5039. },
  5040. _toValue: function _toValue(val, ctx) {
  5041. var value = ctx.el.formatDate(val || ''),
  5042. separator = ctx.el.separator,
  5043. isRange = this.isRange(ctx.el);
  5044. if (!value) return isRange ? ctx.el.multiple ? [] : ['', ''] : value;else if (isRange) return value.split(separator);else return value;
  5045. },
  5046. toValue: function toValue(formValue, ctx) {
  5047. var el = ctx.el;
  5048. if (el) {
  5049. this.el = el;
  5050. return this._toValue(formValue, ctx);
  5051. }
  5052. return formValue;
  5053. },
  5054. toFormValue: function toFormValue(value, ctx) {
  5055. if (ctx.el) {
  5056. var v = ctx.el.parseDate(value);
  5057. return this.isRange(ctx.el) ? v : v[0];
  5058. } else {
  5059. var isArr = Array.isArray(value),
  5060. props = ctx.prop.props,
  5061. parseValue,
  5062. type = props.type || 'date';
  5063. if (['daterange', 'datetimerange'].indexOf(type) !== -1) {
  5064. if (isArr) {
  5065. parseValue = value.map(function (time) {
  5066. return !time ? '' : timeStampToDate(time);
  5067. });
  5068. } else {
  5069. parseValue = ['', ''];
  5070. }
  5071. } else if ('date' === type && props.multiple === true) {
  5072. parseValue = toString(value);
  5073. } else {
  5074. parseValue = isArr ? value[0] || '' : value;
  5075. parseValue = !parseValue ? '' : timeStampToDate(parseValue);
  5076. }
  5077. return parseValue;
  5078. }
  5079. },
  5080. mounted: function mounted(ctx) {
  5081. ctx.rule.value = this.toValue(ctx.$handle.getFormData(ctx), ctx);
  5082. }
  5083. };
  5084. var name$2 = 'hidden';
  5085. var hidden = {
  5086. name: name$2,
  5087. maker: _defineProperty({}, name$2, function (field, value) {
  5088. return creatorFactory(name$2)('', field, value);
  5089. }),
  5090. render: function render() {
  5091. return [];
  5092. }
  5093. };
  5094. var name$3 = 'input';
  5095. var input = {
  5096. name: name$3,
  5097. maker: function () {
  5098. var maker = ['password', 'url', 'email', 'text', 'textarea'].reduce(function (maker, type) {
  5099. maker[type] = creatorFactory(name$3, {
  5100. type: type
  5101. });
  5102. return maker;
  5103. }, {});
  5104. maker.idate = creatorFactory(name$3, {
  5105. type: 'date'
  5106. });
  5107. return maker;
  5108. }(),
  5109. mergeProp: function mergeProp(ctx) {
  5110. var props = ctx.prop.props;
  5111. if (props.autosize && props.autosize.minRows) {
  5112. props.rows = props.autosize.minRows || 2;
  5113. }
  5114. }
  5115. };
  5116. var name$4 = 'slider';
  5117. var slider = {
  5118. name: name$4,
  5119. maker: {
  5120. sliderRange: creatorFactory(name$4, {
  5121. range: true
  5122. })
  5123. },
  5124. toFormValue: function toFormValue(value, ctx) {
  5125. var isArr = Array.isArray(value),
  5126. props = ctx.prop.props,
  5127. min = props.min || 0,
  5128. parseValue;
  5129. if (props.range === true) {
  5130. parseValue = isArr ? value : [min, parseFloat(value) || min];
  5131. } else {
  5132. parseValue = isArr ? parseFloat(value[0]) || min : parseFloat(value);
  5133. }
  5134. return parseValue;
  5135. }
  5136. };
  5137. var iswitch = {
  5138. name: 'switch',
  5139. mergeProp: function mergeProp(ctx) {
  5140. var prop = ctx.prop.props.slot || {};
  5141. var slot = ctx.prop.scopedSlots || {};
  5142. if (prop.open) slot.open = function () {
  5143. return prop.open;
  5144. };
  5145. if (prop.close) slot.close = function () {
  5146. return prop.close;
  5147. };
  5148. ctx.prop.scopedSlots = slot;
  5149. }
  5150. };
  5151. var row = {
  5152. name: 'FcRow',
  5153. render: function render(_, ctx) {
  5154. return ctx.vNode.col({
  5155. props: {
  5156. span: 24
  5157. }
  5158. }, [ctx.vNode.row(ctx.prop, _)]);
  5159. }
  5160. };
  5161. var parsers = [datePicker, hidden, input, slider, iswitch, row];
  5162. var alias = {
  5163. button: 'iButton',
  5164. icon: 'Icon',
  5165. slider: 'Slider',
  5166. rate: 'Rate',
  5167. upload: 'fcUpload',
  5168. cascader: 'Cascader',
  5169. colorPicker: 'ColorPicker',
  5170. timePicker: 'TimePicker',
  5171. datePicker: 'DatePicker',
  5172. 'switch': 'iSwitch',
  5173. select: 'fcSelect',
  5174. checkbox: 'fcCheckbox',
  5175. radio: 'fcRadio',
  5176. inputNumber: 'InputNumber',
  5177. input: 'iInput',
  5178. formItem: 'FormItem',
  5179. form: 'iForm',
  5180. frame: 'fcFrame',
  5181. col: 'iCol',
  5182. row: 'row',
  5183. tree: 'fcTree',
  5184. autoComplete: 'AutoComplete',
  5185. group: 'fcGroup',
  5186. subForm: 'fcSubForm',
  5187. object: 'fcSubForm'
  5188. };
  5189. var iviewConfig = {
  5190. resetBtnType: 'default',
  5191. resetBtnIcon: 'md-refresh',
  5192. infoIcon: 'ios-information-circle-outline'
  5193. };
  5194. function info() {
  5195. return {
  5196. type: 'poptip',
  5197. trigger: 'hover',
  5198. placement: 'top-start',
  5199. wordWrap: true,
  5200. icon: iviewConfig.infoIcon
  5201. };
  5202. }
  5203. function getConfig() {
  5204. return {
  5205. form: {
  5206. inline: false,
  5207. labelPosition: 'right',
  5208. labelWidth: 125,
  5209. showMessage: true,
  5210. autocomplete: 'off',
  5211. size: undefined
  5212. },
  5213. row: {
  5214. gutter: 0
  5215. },
  5216. submitBtn: {
  5217. type: 'primary',
  5218. disabled: false,
  5219. innerText: '提交',
  5220. loading: false,
  5221. show: true,
  5222. click: undefined
  5223. },
  5224. resetBtn: {
  5225. type: iviewConfig.resetBtnType,
  5226. disabled: false,
  5227. icon: iviewConfig.resetBtnIcon,
  5228. innerText: '重置',
  5229. loading: false,
  5230. show: false,
  5231. click: undefined
  5232. }
  5233. };
  5234. }
  5235. function tidy(props, name) {
  5236. if (!hasProperty(props, name)) return;
  5237. if (is.String(props[name])) {
  5238. var _props$name;
  5239. props[name] = (_props$name = {}, _defineProperty(_props$name, name, props[name]), _defineProperty(_props$name, "show", true), _props$name);
  5240. }
  5241. }
  5242. function isFalse(val) {
  5243. return val === false;
  5244. }
  5245. function tidyBool(opt, name) {
  5246. if (hasProperty(opt, name) && !is.Object(opt[name])) {
  5247. opt[name] = {
  5248. show: !!opt[name]
  5249. };
  5250. }
  5251. }
  5252. var manager = {
  5253. validate: function validate(call) {
  5254. this.form().validate(call);
  5255. },
  5256. validateField: function validateField(field, call) {
  5257. this.form().validateField(field, call);
  5258. },
  5259. clearValidateState: function clearValidateState(ctx) {
  5260. var fItem = this.vm.$refs[ctx.wrapRef];
  5261. if (fItem) {
  5262. fItem.validateMessage = '';
  5263. fItem.validateState = '';
  5264. }
  5265. },
  5266. tidyOptions: function tidyOptions(options) {
  5267. ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col'].forEach(function (name) {
  5268. tidyBool(options, name);
  5269. });
  5270. return options;
  5271. },
  5272. tidyRule: function tidyRule(_ref) {
  5273. var prop = _ref.prop;
  5274. tidy(prop, 'title');
  5275. tidy(prop, 'info');
  5276. return prop;
  5277. },
  5278. mergeProp: function mergeProp(ctx) {
  5279. ctx.prop = mergeProps([{
  5280. info: this.options.info || {},
  5281. wrap: this.options.wrap || {},
  5282. col: this.options.col || {}
  5283. }, ctx.prop], {
  5284. info: info(),
  5285. title: {},
  5286. col: {
  5287. span: 24
  5288. },
  5289. wrap: {}
  5290. }, {
  5291. normal: ['title', 'info', 'col', 'wrap']
  5292. });
  5293. this.setSize(ctx.prop.props);
  5294. },
  5295. setSize: function setSize(props) {
  5296. if (!props.size && this.options.form.size) {
  5297. props.size = this.options.form.size;
  5298. }
  5299. },
  5300. getDefaultOptions: function getDefaultOptions() {
  5301. return getConfig();
  5302. },
  5303. update: function update() {
  5304. var form = this.options.form;
  5305. this.rule = {
  5306. props: _objectSpread2({}, form),
  5307. nativeOn: {
  5308. submit: function submit(e) {
  5309. e.preventDefault();
  5310. }
  5311. },
  5312. "class": [form.className, form["class"], 'form-create'],
  5313. style: form.style,
  5314. type: 'form'
  5315. };
  5316. },
  5317. beforeRender: function beforeRender() {
  5318. var key = this.key,
  5319. ref = this.ref,
  5320. $handle = this.$handle;
  5321. extend(this.rule, {
  5322. key: key,
  5323. ref: ref
  5324. });
  5325. extend(this.rule.props, {
  5326. model: $handle.formData,
  5327. rules: $handle.validate()
  5328. });
  5329. },
  5330. render: function render(children) {
  5331. if (children.length) {
  5332. children.push(this.makeFormBtn());
  5333. }
  5334. return this.$r(this.rule, isFalse(this.options.row.show) ? children : [this.makeRow(children)]);
  5335. },
  5336. makeWrap: function makeWrap(ctx, children) {
  5337. var rule = ctx.prop;
  5338. var uni = "".concat(this.key).concat(ctx.key);
  5339. var col = rule.col;
  5340. var isTitle = this.isTitle(rule);
  5341. var labelWidth = !col.labelWidth && !isTitle ? 0 : col.labelWidth;
  5342. var _this$rule$props = this.rule.props,
  5343. inline = _this$rule$props.inline,
  5344. _col = _this$rule$props.col;
  5345. var item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
  5346. props: _objectSpread2(_objectSpread2({
  5347. labelWidth: labelWidth
  5348. }, rule.wrap || {}), {}, {
  5349. prop: ctx.id,
  5350. rules: rule.validate
  5351. }),
  5352. "class": rule.className,
  5353. key: "".concat(uni, "fi"),
  5354. ref: ctx.wrapRef,
  5355. type: 'formItem'
  5356. }]), [children, isTitle ? this.makeInfo(rule, uni) : null]);
  5357. return inline === true || isFalse(_col) || isFalse(col.show) ? item : this.makeCol(rule, uni, [item]);
  5358. },
  5359. isTitle: function isTitle(rule) {
  5360. if (this.options.form.title === false) return false;
  5361. var title = rule.title;
  5362. return !(!title.title && !title["native"] || isFalse(title.show));
  5363. },
  5364. makeInfo: function makeInfo(rule, uni) {
  5365. var titleProp = rule.title;
  5366. var infoProp = rule.info;
  5367. var children = [titleProp.title];
  5368. if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
  5369. var prop = {
  5370. type: infoProp.type || 'poptip',
  5371. props: _objectSpread2({}, infoProp),
  5372. key: "".concat(uni, "pop"),
  5373. slot: 'label'
  5374. };
  5375. var field = 'content';
  5376. if (infoProp.info && !hasProperty(prop.props, field)) {
  5377. prop.props[field] = infoProp.info;
  5378. }
  5379. children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
  5380. type: 'icon',
  5381. props: {
  5382. type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
  5383. size: 16
  5384. },
  5385. style: 'margin-top: -1px',
  5386. key: "".concat(uni, "i")
  5387. })]));
  5388. }
  5389. return this.$r(mergeProps([titleProp, {
  5390. props: titleProp,
  5391. slot: titleProp.slot || 'label',
  5392. key: "".concat(uni, "tit"),
  5393. type: titleProp.type || 'span'
  5394. }]), children);
  5395. },
  5396. makeCol: function makeCol(rule, uni, children) {
  5397. var col = rule.col;
  5398. return this.$r({
  5399. "class": col["class"],
  5400. type: 'col',
  5401. props: col || {
  5402. span: 24
  5403. },
  5404. key: "".concat(uni, "col")
  5405. }, children);
  5406. },
  5407. makeRow: function makeRow(children) {
  5408. var row = this.options.row || {};
  5409. return this.$r({
  5410. type: 'row',
  5411. props: row,
  5412. "class": row["class"],
  5413. key: "".concat(this.key, "row")
  5414. }, children);
  5415. },
  5416. makeFormBtn: function makeFormBtn() {
  5417. var vn = [];
  5418. if (!isFalse(this.options.submitBtn.show)) {
  5419. vn.push(this.makeSubmitBtn());
  5420. }
  5421. if (!isFalse(this.options.resetBtn.show)) {
  5422. vn.push(this.makeResetBtn());
  5423. }
  5424. if (!vn.length) {
  5425. return;
  5426. }
  5427. var item = this.$r({
  5428. type: 'formItem',
  5429. key: "".concat(this.key, "fb")
  5430. }, vn);
  5431. return this.rule.props.inline === true ? item : this.$r({
  5432. type: 'col',
  5433. props: {
  5434. span: 24
  5435. },
  5436. key: "".concat(this.key, "fc")
  5437. }, [item]);
  5438. },
  5439. makeResetBtn: function makeResetBtn() {
  5440. var _this2 = this;
  5441. var resetBtn = this.options.resetBtn;
  5442. this.setSize(resetBtn);
  5443. return this.$r({
  5444. type: 'button',
  5445. props: resetBtn,
  5446. style: {
  5447. width: resetBtn.width,
  5448. marginLeft: '15px'
  5449. },
  5450. on: {
  5451. click: function click() {
  5452. var fApi = _this2.$handle.api;
  5453. resetBtn.click ? resetBtn.click(fApi) : fApi.resetFields();
  5454. }
  5455. },
  5456. key: "".concat(this.key, "b2")
  5457. }, [resetBtn.innerText]);
  5458. },
  5459. makeSubmitBtn: function makeSubmitBtn() {
  5460. var _this3 = this;
  5461. var submitBtn = this.options.submitBtn;
  5462. this.setSize(submitBtn);
  5463. return this.$r({
  5464. type: 'button',
  5465. props: submitBtn,
  5466. style: {
  5467. width: submitBtn.width
  5468. },
  5469. on: {
  5470. click: function click() {
  5471. var fApi = _this3.$handle.api;
  5472. submitBtn.click ? submitBtn.click(fApi) : fApi.submit();
  5473. }
  5474. },
  5475. key: "".concat(this.key, "b1")
  5476. }, [submitBtn.innerText]);
  5477. }
  5478. };
  5479. var maker = {};
  5480. var names = ['upload', 'select', 'tree', 'checkbox', 'autoComplete', 'cascader', 'colorPicker', 'frame', 'inputNumber', 'radio', 'rate', 'timePicker', 'group'];
  5481. function useAlias(maker) {
  5482. names.forEach(function (name) {
  5483. maker[name] = creatorFactory(name);
  5484. });
  5485. maker.auto = maker.autoComplete;
  5486. maker.number = maker.inputNumber;
  5487. maker.color = maker.colorPicker;
  5488. }
  5489. function useUpload(maker) {
  5490. var name = 'upload';
  5491. var types = {
  5492. image: ['image', 0],
  5493. file: ['file', 0],
  5494. uploadFileOne: ['file', 1],
  5495. uploadImageOne: ['image', 1]
  5496. };
  5497. Object.keys(types).reduce(function (maker, key) {
  5498. maker[key] = creatorFactory(name, function (m) {
  5499. return m.props({
  5500. uploadType: types[key][0],
  5501. maxLength: types[key][1]
  5502. });
  5503. });
  5504. return maker;
  5505. }, maker);
  5506. maker.uploadImage = maker.image;
  5507. maker.uploadFile = maker.file;
  5508. }
  5509. function useTree(maker) {
  5510. var name = 'tree';
  5511. var types = {
  5512. 'treeSelected': 'selected',
  5513. 'treeChecked': 'checked'
  5514. };
  5515. Object.keys(types).reduce(function (maker, key) {
  5516. maker[key] = creatorFactory(name, {
  5517. type: types[key]
  5518. });
  5519. return maker;
  5520. }, maker);
  5521. }
  5522. function useTimePicker(maker) {
  5523. var name = 'timePicker';
  5524. maker.time = creatorFactory(name, {
  5525. type: 'time'
  5526. });
  5527. maker.timeRange = creatorFactory(name, {
  5528. type: 'timerange'
  5529. });
  5530. }
  5531. function useSelect(maker) {
  5532. var name = 'select';
  5533. maker.selectMultiple = creatorFactory(name, {
  5534. multiple: true
  5535. });
  5536. maker.selectOne = creatorFactory(name, {
  5537. multiple: false
  5538. });
  5539. }
  5540. function useFrame(maker) {
  5541. var name = 'frame';
  5542. var types = {
  5543. frameInputs: ['input', 0],
  5544. frameFiles: ['file', 0],
  5545. frameImages: ['image', 0],
  5546. frameInputOne: ['input', 1],
  5547. frameFileOne: ['file', 1],
  5548. frameImageOne: ['image', 1]
  5549. };
  5550. Object.keys(types).reduce(function (maker, key) {
  5551. maker[key] = creatorFactory(name, function (m) {
  5552. return m.props({
  5553. type: types[key][0],
  5554. maxLength: types[key][1]
  5555. });
  5556. });
  5557. return maker;
  5558. }, maker);
  5559. maker.frameInput = maker.frameInputs;
  5560. maker.frameFile = maker.frameFiles;
  5561. maker.frameImage = maker.frameImages;
  5562. }
  5563. useAlias(maker);
  5564. useUpload(maker);
  5565. useTree(maker);
  5566. useSelect(maker);
  5567. useFrame(maker);
  5568. useTimePicker(maker);
  5569. var css_248z$2 = ".form-create .form-create .ivu-form-item {\n margin-bottom: 24px;\n}\n\n.form-create .form-create .ivu-form-item .ivu-form-item {\n margin-bottom: 0px;\n}\n";
  5570. styleInject(css_248z$2);
  5571. function tidyBtnProp(btn, def) {
  5572. if (is.Boolean(btn)) btn = {
  5573. show: btn
  5574. };else if (!is.Undef(btn) && !is.Object(btn)) btn = {
  5575. show: def
  5576. };
  5577. return btn;
  5578. }
  5579. function extendApi(api, h) {
  5580. extend(api, {
  5581. validate: function validate(callback) {
  5582. var flag;
  5583. var forms = api.children;
  5584. var len = forms.length;
  5585. var validate = function validate() {
  5586. h.$manager.validate(function () {
  5587. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5588. args[_key] = arguments[_key];
  5589. }
  5590. if (!args[0] || !flag) {
  5591. flag = args;
  5592. }
  5593. callback && callback.apply(void 0, _toConsumableArray(flag));
  5594. });
  5595. };
  5596. var validFn = function validFn(args) {
  5597. setTimeout(function () {
  5598. if (!args[0]) {
  5599. if (!flag) {
  5600. flag = args;
  5601. }
  5602. }
  5603. if (! --len) {
  5604. validate();
  5605. }
  5606. });
  5607. };
  5608. forms.forEach(function (form) {
  5609. form.validate(function () {
  5610. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  5611. args[_key2] = arguments[_key2];
  5612. }
  5613. return validFn(args);
  5614. });
  5615. });
  5616. if (!len) {
  5617. validate();
  5618. }
  5619. },
  5620. validateField: function validateField(field, callback) {
  5621. var ctx = h.getFieldCtx(field);
  5622. if (!ctx) return;
  5623. var sub = h.subForm[ctx.id];
  5624. var len = 0;
  5625. var flag;
  5626. var validate = function validate() {
  5627. h.$manager.validateField(ctx.id, function () {
  5628. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  5629. args[_key3] = arguments[_key3];
  5630. }
  5631. if (args[0]) {
  5632. flag = args;
  5633. } else if (flag) {
  5634. return callback && callback('子表单验证未通过');
  5635. }
  5636. callback && callback.apply(void 0, _toConsumableArray(flag || args));
  5637. });
  5638. };
  5639. var validFn = function validFn(args) {
  5640. setTimeout(function () {
  5641. if (!args[0]) {
  5642. if (!flag) {
  5643. flag = args;
  5644. }
  5645. }
  5646. if (! --len) {
  5647. validate();
  5648. }
  5649. });
  5650. };
  5651. sub && toArray(sub).forEach(function (form) {
  5652. len++;
  5653. form.validate(function () {
  5654. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  5655. args[_key4] = arguments[_key4];
  5656. }
  5657. return validFn(args);
  5658. });
  5659. });
  5660. if (!len) {
  5661. validate();
  5662. }
  5663. },
  5664. clearValidateState: function clearValidateState(fields) {
  5665. var _this = this;
  5666. var clearSub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  5667. api.helper.tidyFields(fields).forEach(function (field) {
  5668. if (clearSub) _this.clearSubValidateState(field);
  5669. h.getCtxs(field).forEach(function (ctx) {
  5670. h.$manager.clearValidateState(ctx);
  5671. });
  5672. });
  5673. },
  5674. clearSubValidateState: function clearSubValidateState(fields) {
  5675. api.helper.tidyFields(fields).forEach(function (field) {
  5676. h.getCtxs(field).forEach(function (ctx) {
  5677. var subForm = h.subForm[ctx.id];
  5678. if (!subForm) return;
  5679. if (Array.isArray(subForm)) {
  5680. subForm.forEach(function (form) {
  5681. form.clearValidateState();
  5682. });
  5683. } else if (subForm) {
  5684. subForm.clearValidateState();
  5685. }
  5686. });
  5687. });
  5688. },
  5689. btn: {
  5690. loading: function loading() {
  5691. var _loading = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5692. api.submitBtnProps({
  5693. loading: !!_loading
  5694. });
  5695. },
  5696. disabled: function disabled() {
  5697. var _disabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5698. api.submitBtnProps({
  5699. disabled: !!_disabled
  5700. });
  5701. },
  5702. show: function show() {
  5703. var isShow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5704. api.submitBtnProps({
  5705. show: !!isShow
  5706. });
  5707. }
  5708. },
  5709. resetBtn: {
  5710. loading: function loading() {
  5711. var _loading2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5712. api.resetBtnProps({
  5713. loading: !!_loading2
  5714. });
  5715. },
  5716. disabled: function disabled() {
  5717. var _disabled2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5718. api.resetBtnProps({
  5719. disabled: !!_disabled2
  5720. });
  5721. },
  5722. show: function show() {
  5723. var isShow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  5724. api.resetBtnProps({
  5725. show: !!isShow
  5726. });
  5727. }
  5728. },
  5729. submitBtnProps: function submitBtnProps() {
  5730. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5731. var btn = tidyBtnProp(h.options.submitBtn, true);
  5732. extend(btn, props);
  5733. h.options.submitBtn = btn;
  5734. api.refreshOptions();
  5735. },
  5736. resetBtnProps: function resetBtnProps() {
  5737. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5738. var btn = tidyBtnProp(h.options.resetBtn, false);
  5739. extend(btn, props);
  5740. h.options.resetBtn = btn;
  5741. api.refreshOptions();
  5742. },
  5743. submit: function submit(successFn, failFn) {
  5744. var _arguments = arguments,
  5745. _this2 = this;
  5746. api.validate(function (valid) {
  5747. if (valid) {
  5748. var formData = api.formData();
  5749. if (is.Function(successFn)) invoke(function () {
  5750. return successFn(formData, _this2);
  5751. });else {
  5752. is.Function(h.options.onSubmit) && invoke(function () {
  5753. return h.options.onSubmit(formData, _this2);
  5754. });
  5755. h.vm.$emit('submit', formData, _this2);
  5756. }
  5757. } else {
  5758. is.Function(failFn) && invoke(function () {
  5759. return failFn.apply(void 0, [_this2].concat(_toConsumableArray(_arguments)));
  5760. });
  5761. }
  5762. });
  5763. }
  5764. });
  5765. return api;
  5766. }
  5767. function install(FormCreate) {
  5768. FormCreate.componentAlias(alias);
  5769. components.forEach(function (component) {
  5770. FormCreate.component(component.name, component);
  5771. });
  5772. parsers.forEach(function (parser) {
  5773. FormCreate.parser(parser);
  5774. });
  5775. Object.keys(maker).forEach(function (name) {
  5776. FormCreate.maker[name] = maker[name];
  5777. });
  5778. }
  5779. function ivuFormCreate() {
  5780. return FormCreateFactory({
  5781. ui: "".concat("iview"),
  5782. version: "".concat("2.5.27"),
  5783. manager: manager,
  5784. install: install,
  5785. extendApi: extendApi,
  5786. attrs: {
  5787. normal: ['col', 'wrap'],
  5788. array: ['className'],
  5789. key: ['title', 'info']
  5790. }
  5791. });
  5792. }
  5793. var FormCreate = ivuFormCreate();
  5794. if (typeof window !== 'undefined') {
  5795. window.formCreate = FormCreate;
  5796. if (window.Vue) {
  5797. FormCreate.install(window.Vue);
  5798. }
  5799. }
  5800. var maker$1 = FormCreate.maker;
  5801. exports.default = FormCreate;
  5802. exports.maker = maker$1;
  5803. Object.defineProperty(exports, '__esModule', { value: true });
  5804. })));