足力健前端,vue版本

index.v3.js 352KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907
  1. export function createServiceContext(Vue, weex, plus, UniServiceJSBridge,instanceContext){
  2. var setTimeout = instanceContext.setTimeout
  3. var clearTimeout = instanceContext.clearTimeout
  4. var setInterval = instanceContext.setInterval
  5. var clearInterval = instanceContext.clearInterval
  6. var __uniConfig = instanceContext.__uniConfig
  7. var __uniRoutes = instanceContext.__uniRoutes
  8. var serviceContext = (function () {
  9. 'use strict';
  10. const base = [
  11. 'base64ToArrayBuffer',
  12. 'arrayBufferToBase64',
  13. 'addInterceptor',
  14. 'removeInterceptor'
  15. ];
  16. const network = [
  17. 'request',
  18. 'uploadFile',
  19. 'downloadFile',
  20. 'connectSocket',
  21. 'onSocketOpen',
  22. 'onSocketError',
  23. 'sendSocketMessage',
  24. 'onSocketMessage',
  25. 'closeSocket',
  26. 'onSocketClose'
  27. ];
  28. const route = [
  29. 'navigateTo',
  30. 'redirectTo',
  31. 'reLaunch',
  32. 'switchTab',
  33. 'navigateBack'
  34. ];
  35. const storage = [
  36. 'setStorage',
  37. 'setStorageSync',
  38. 'getStorage',
  39. 'getStorageSync',
  40. 'getStorageInfo',
  41. 'getStorageInfoSync',
  42. 'removeStorage',
  43. 'removeStorageSync',
  44. 'clearStorage',
  45. 'clearStorageSync'
  46. ];
  47. const location = [
  48. 'getLocation',
  49. 'chooseLocation',
  50. 'openLocation',
  51. 'createMapContext'
  52. ];
  53. const media = [
  54. 'chooseImage',
  55. 'previewImage',
  56. 'getImageInfo',
  57. 'saveImageToPhotosAlbum',
  58. 'compressImage',
  59. 'getRecorderManager',
  60. 'getBackgroundAudioManager',
  61. 'createInnerAudioContext',
  62. 'chooseVideo',
  63. 'saveVideoToPhotosAlbum',
  64. 'createVideoContext',
  65. 'createCameraContext',
  66. 'createLivePlayerContext',
  67. 'createLivePusherContext'
  68. ];
  69. const device = [
  70. 'getSystemInfo',
  71. 'getSystemInfoSync',
  72. 'canIUse',
  73. 'onMemoryWarning',
  74. 'getNetworkType',
  75. 'onNetworkStatusChange',
  76. 'onAccelerometerChange',
  77. 'startAccelerometer',
  78. 'stopAccelerometer',
  79. 'onCompassChange',
  80. 'startCompass',
  81. 'stopCompass',
  82. 'onGyroscopeChange',
  83. 'startGyroscope',
  84. 'stopGyroscope',
  85. 'makePhoneCall',
  86. 'scanCode',
  87. 'setClipboardData',
  88. 'getClipboardData',
  89. 'setScreenBrightness',
  90. 'getScreenBrightness',
  91. 'setKeepScreenOn',
  92. 'onUserCaptureScreen',
  93. 'vibrateLong',
  94. 'vibrateShort',
  95. 'addPhoneContact',
  96. 'openBluetoothAdapter',
  97. 'startBluetoothDevicesDiscovery',
  98. 'onBluetoothDeviceFound',
  99. 'stopBluetoothDevicesDiscovery',
  100. 'onBluetoothAdapterStateChange',
  101. 'getConnectedBluetoothDevices',
  102. 'getBluetoothDevices',
  103. 'getBluetoothAdapterState',
  104. 'closeBluetoothAdapter',
  105. 'writeBLECharacteristicValue',
  106. 'readBLECharacteristicValue',
  107. 'onBLEConnectionStateChange',
  108. 'onBLECharacteristicValueChange',
  109. 'notifyBLECharacteristicValueChange',
  110. 'getBLEDeviceServices',
  111. 'getBLEDeviceCharacteristics',
  112. 'createBLEConnection',
  113. 'closeBLEConnection',
  114. 'onBeaconServiceChange',
  115. 'onBeaconUpdate',
  116. 'getBeacons',
  117. 'startBeaconDiscovery',
  118. 'stopBeaconDiscovery',
  119. 'checkIsSupportSoterAuthentication',
  120. 'checkIsSoterEnrolledInDevice',
  121. 'startSoterAuthentication',
  122. 'onUIStyleChange'
  123. ];
  124. const keyboard = [
  125. 'hideKeyboard',
  126. 'onKeyboardHeightChange'
  127. ];
  128. const ui = [
  129. 'showToast',
  130. 'hideToast',
  131. 'showLoading',
  132. 'hideLoading',
  133. 'showModal',
  134. 'showActionSheet',
  135. 'setNavigationBarTitle',
  136. 'setNavigationBarColor',
  137. 'showNavigationBarLoading',
  138. 'hideNavigationBarLoading',
  139. 'setTabBarItem',
  140. 'setTabBarStyle',
  141. 'hideTabBar',
  142. 'showTabBar',
  143. 'setTabBarBadge',
  144. 'removeTabBarBadge',
  145. 'showTabBarRedDot',
  146. 'hideTabBarRedDot',
  147. 'onTabBarMidButtonTap',
  148. 'setBackgroundColor',
  149. 'setBackgroundTextStyle',
  150. 'createAnimation',
  151. 'pageScrollTo',
  152. 'onWindowResize',
  153. 'offWindowResize',
  154. 'loadFontFace',
  155. 'startPullDownRefresh',
  156. 'stopPullDownRefresh',
  157. 'createSelectorQuery',
  158. 'createIntersectionObserver',
  159. 'getMenuButtonBoundingClientRect'
  160. ];
  161. const event = [
  162. '$emit',
  163. '$on',
  164. '$once',
  165. '$off'
  166. ];
  167. const file = [
  168. 'saveFile',
  169. 'getSavedFileList',
  170. 'getSavedFileInfo',
  171. 'removeSavedFile',
  172. 'getFileInfo',
  173. 'openDocument',
  174. 'getFileSystemManager'
  175. ];
  176. const canvas = [
  177. 'createOffscreenCanvas',
  178. 'createCanvasContext',
  179. 'canvasToTempFilePath',
  180. 'canvasPutImageData',
  181. 'canvasGetImageData'
  182. ];
  183. const third = [
  184. 'getProvider',
  185. 'login',
  186. 'checkSession',
  187. 'getUserInfo',
  188. 'share',
  189. 'shareWithSystem',
  190. 'showShareMenu',
  191. 'hideShareMenu',
  192. 'requestPayment',
  193. 'subscribePush',
  194. 'unsubscribePush',
  195. 'onPush',
  196. 'offPush',
  197. 'requireNativePlugin',
  198. 'upx2px',
  199. 'restoreGlobal',
  200. 'getSubNVueById',
  201. 'getCurrentSubNVue',
  202. 'setPageMeta',
  203. 'onNativeEventReceive',
  204. 'sendNativeEvent'
  205. ];
  206. const ad = [
  207. 'createRewardedVideoAd'
  208. ];
  209. const apis = [
  210. ...base,
  211. ...network,
  212. ...route,
  213. ...storage,
  214. ...location,
  215. ...media,
  216. ...device,
  217. ...keyboard,
  218. ...ui,
  219. ...event,
  220. ...file,
  221. ...canvas,
  222. ...third,
  223. ...ad
  224. ];
  225. var apis_1 = apis;
  226. let supportsPassive = false;
  227. try {
  228. const opts = {};
  229. Object.defineProperty(opts, 'passive', ({
  230. get () {
  231. /* istanbul ignore next */
  232. supportsPassive = true;
  233. }
  234. })); // https://github.com/facebook/flow/issues/285
  235. window.addEventListener('test-passive', null, opts);
  236. } catch (e) {}
  237. const _toString = Object.prototype.toString;
  238. const hasOwnProperty = Object.prototype.hasOwnProperty;
  239. function isFn (fn) {
  240. return typeof fn === 'function'
  241. }
  242. function isObject (obj) {
  243. return obj !== null && typeof obj === 'object'
  244. }
  245. function isPlainObject (obj) {
  246. return _toString.call(obj) === '[object Object]'
  247. }
  248. function hasOwn (obj, key) {
  249. return hasOwnProperty.call(obj, key)
  250. }
  251. function noop () {}
  252. function toRawType (val) {
  253. return _toString.call(val).slice(8, -1)
  254. }
  255. /**
  256. * Create a cached version of a pure function.
  257. */
  258. function cached (fn) {
  259. const cache = Object.create(null);
  260. return function cachedFn (str) {
  261. const hit = cache[str];
  262. return hit || (cache[str] = fn(str))
  263. }
  264. }
  265. /**
  266. * Camelize a hyphen-delimited string.
  267. */
  268. const camelizeRE = /-(\w)/g;
  269. const camelize = cached((str) => {
  270. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
  271. });
  272. function getLen (str = '') {
  273. /* eslint-disable no-control-regex */
  274. return ('' + str).replace(/[^\x00-\xff]/g, '**').length
  275. }
  276. function debounce (fn, delay) {
  277. let timeout;
  278. const newFn = function () {
  279. clearTimeout(timeout);
  280. const timerFn = () => fn.apply(this, arguments);
  281. timeout = setTimeout(timerFn, delay);
  282. };
  283. newFn.cancel = function () {
  284. clearTimeout(timeout);
  285. };
  286. return newFn
  287. }
  288. /**
  289. * Check if two values are loosely equal - that is,
  290. * if they are plain objects, do they have the same shape?
  291. */
  292. function looseEqual (a, b) {
  293. if (a === b) return true
  294. const isObjectA = isObject(a);
  295. const isObjectB = isObject(b);
  296. if (isObjectA && isObjectB) {
  297. try {
  298. const isArrayA = Array.isArray(a);
  299. const isArrayB = Array.isArray(b);
  300. if (isArrayA && isArrayB) {
  301. return a.length === b.length && a.every((e, i) => {
  302. return looseEqual(e, b[i])
  303. })
  304. } else if (a instanceof Date && b instanceof Date) {
  305. return a.getTime() === b.getTime()
  306. } else if (!isArrayA && !isArrayB) {
  307. const keysA = Object.keys(a);
  308. const keysB = Object.keys(b);
  309. return keysA.length === keysB.length && keysA.every(key => {
  310. return looseEqual(a[key], b[key])
  311. })
  312. } else {
  313. /* istanbul ignore next */
  314. return false
  315. }
  316. } catch (e) {
  317. /* istanbul ignore next */
  318. return false
  319. }
  320. } else if (!isObjectA && !isObjectB) {
  321. return String(a) === String(b)
  322. } else {
  323. return false
  324. }
  325. }
  326. const encodeReserveRE = /[!'()*]/g;
  327. const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16);
  328. const commaRE = /%2C/g;
  329. // fixed encodeURIComponent which is more conformant to RFC3986:
  330. // - escapes [!'()*]
  331. // - preserve commas
  332. const encode = str => encodeURIComponent(str)
  333. .replace(encodeReserveRE, encodeReserveReplacer)
  334. .replace(commaRE, ',');
  335. const decode = decodeURIComponent;
  336. function parseQuery (query) {
  337. const res = {};
  338. query = query.trim().replace(/^(\?|#|&)/, '');
  339. if (!query) {
  340. return res
  341. }
  342. query.split('&').forEach(param => {
  343. const parts = param.replace(/\+/g, ' ').split('=');
  344. const key = decode(parts.shift());
  345. const val = parts.length > 0
  346. ? decode(parts.join('='))
  347. : null;
  348. if (res[key] === undefined) {
  349. res[key] = val;
  350. } else if (Array.isArray(res[key])) {
  351. res[key].push(val);
  352. } else {
  353. res[key] = [res[key], val];
  354. }
  355. });
  356. return res
  357. }
  358. function stringifyQuery (obj, encodeStr = encode) {
  359. const res = obj ? Object.keys(obj).map(key => {
  360. const val = obj[key];
  361. if (val === undefined) {
  362. return ''
  363. }
  364. if (val === null) {
  365. return encodeStr(key)
  366. }
  367. if (Array.isArray(val)) {
  368. const result = [];
  369. val.forEach(val2 => {
  370. if (val2 === undefined) {
  371. return
  372. }
  373. if (val2 === null) {
  374. result.push(encodeStr(key));
  375. } else {
  376. result.push(encodeStr(key) + '=' + encodeStr(val2));
  377. }
  378. });
  379. return result.join('&')
  380. }
  381. return encodeStr(key) + '=' + encodeStr(val)
  382. }).filter(x => x.length > 0).join('&') : null;
  383. return res ? `?${res}` : ''
  384. }
  385. function decodedQuery (query = {}) {
  386. const decodedQuery = {};
  387. Object.keys(query).forEach(name => {
  388. try {
  389. decodedQuery[name] = decode(query[name]);
  390. } catch (e) {
  391. decodedQuery[name] = query[name];
  392. }
  393. });
  394. return decodedQuery
  395. }
  396. let id = 0;
  397. const callbacks = {};
  398. function warp (fn) {
  399. return function (options = {}) {
  400. const callbackId = String(id++);
  401. callbacks[callbackId] = {
  402. success: options.success,
  403. fail: options.fail,
  404. complete: options.complete
  405. };
  406. const data = Object.assign({}, options);
  407. // TODO 下版重构 nvue h5 callback
  408. // delete data.success
  409. // delete data.fail
  410. // delete data.complete
  411. const res = fn.bind(this)(data, callbackId);
  412. if (res) {
  413. invoke(callbackId, res);
  414. }
  415. }
  416. }
  417. function invoke (callbackId, res) {
  418. const callback = callbacks[callbackId] || {};
  419. delete callbacks[callbackId];
  420. const errMsg = res.errMsg || '';
  421. if (new RegExp('\\:\\s*fail').test(errMsg)) {
  422. callback.fail && callback.fail(res);
  423. } else {
  424. callback.success && callback.success(res);
  425. }
  426. callback.complete && callback.complete(res);
  427. }
  428. const callback = {
  429. warp,
  430. invoke
  431. };
  432. /**
  433. * 框架内 try-catch
  434. */
  435. function tryCatchFramework (fn) {
  436. return function () {
  437. try {
  438. return fn.apply(fn, arguments)
  439. } catch (e) {
  440. // TODO
  441. console.error(e);
  442. }
  443. }
  444. }
  445. /**
  446. * 开发者 try-catch
  447. */
  448. function tryCatch (fn) {
  449. return function () {
  450. try {
  451. return fn.apply(fn, arguments)
  452. } catch (e) {
  453. // TODO
  454. console.error(e);
  455. }
  456. }
  457. }
  458. const HOOKS = [
  459. 'invoke',
  460. 'success',
  461. 'fail',
  462. 'complete',
  463. 'returnValue'
  464. ];
  465. const globalInterceptors = {};
  466. const scopedInterceptors = {};
  467. function mergeHook (parentVal, childVal) {
  468. const res = childVal
  469. ? parentVal
  470. ? parentVal.concat(childVal)
  471. : Array.isArray(childVal)
  472. ? childVal : [childVal]
  473. : parentVal;
  474. return res
  475. ? dedupeHooks(res)
  476. : res
  477. }
  478. function dedupeHooks (hooks) {
  479. const res = [];
  480. for (let i = 0; i < hooks.length; i++) {
  481. if (res.indexOf(hooks[i]) === -1) {
  482. res.push(hooks[i]);
  483. }
  484. }
  485. return res
  486. }
  487. function removeHook (hooks, hook) {
  488. const index = hooks.indexOf(hook);
  489. if (index !== -1) {
  490. hooks.splice(index, 1);
  491. }
  492. }
  493. function mergeInterceptorHook (interceptor, option) {
  494. Object.keys(option).forEach(hook => {
  495. if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
  496. interceptor[hook] = mergeHook(interceptor[hook], option[hook]);
  497. }
  498. });
  499. }
  500. function removeInterceptorHook (interceptor, option) {
  501. if (!interceptor || !option) {
  502. return
  503. }
  504. Object.keys(option).forEach(hook => {
  505. if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
  506. removeHook(interceptor[hook], option[hook]);
  507. }
  508. });
  509. }
  510. function addInterceptor (method, option) {
  511. if (typeof method === 'string' && isPlainObject(option)) {
  512. mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), option);
  513. } else if (isPlainObject(method)) {
  514. mergeInterceptorHook(globalInterceptors, method);
  515. }
  516. }
  517. function removeInterceptor (method, option) {
  518. if (typeof method === 'string') {
  519. if (isPlainObject(option)) {
  520. removeInterceptorHook(scopedInterceptors[method], option);
  521. } else {
  522. delete scopedInterceptors[method];
  523. }
  524. } else if (isPlainObject(method)) {
  525. removeInterceptorHook(globalInterceptors, method);
  526. }
  527. }
  528. function wrapperHook (hook) {
  529. return function (data) {
  530. return hook(data) || data
  531. }
  532. }
  533. function isPromise (obj) {
  534. return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
  535. }
  536. function queue (hooks, data) {
  537. let promise = false;
  538. for (let i = 0; i < hooks.length; i++) {
  539. const hook = hooks[i];
  540. if (promise) {
  541. promise = Promise.then(wrapperHook(hook));
  542. } else {
  543. const res = hook(data);
  544. if (isPromise(res)) {
  545. promise = Promise.resolve(res);
  546. }
  547. if (res === false) {
  548. return {
  549. then () {}
  550. }
  551. }
  552. }
  553. }
  554. return promise || {
  555. then (callback) {
  556. return callback(data)
  557. }
  558. }
  559. }
  560. function wrapperOptions (interceptor, options = {}) {
  561. ['success', 'fail', 'complete'].forEach(name => {
  562. if (Array.isArray(interceptor[name])) {
  563. const oldCallback = options[name];
  564. options[name] = function callbackInterceptor (res) {
  565. queue(interceptor[name], res).then((res) => {
  566. /* eslint-disable no-mixed-operators */
  567. return isFn(oldCallback) && oldCallback(res) || res
  568. });
  569. };
  570. }
  571. });
  572. return options
  573. }
  574. function wrapperReturnValue (method, returnValue) {
  575. const returnValueHooks = [];
  576. if (Array.isArray(globalInterceptors.returnValue)) {
  577. returnValueHooks.push(...globalInterceptors.returnValue);
  578. }
  579. const interceptor = scopedInterceptors[method];
  580. if (interceptor && Array.isArray(interceptor.returnValue)) {
  581. returnValueHooks.push(...interceptor.returnValue);
  582. }
  583. returnValueHooks.forEach(hook => {
  584. returnValue = hook(returnValue) || returnValue;
  585. });
  586. return returnValue
  587. }
  588. function getApiInterceptorHooks (method) {
  589. const interceptor = Object.create(null);
  590. Object.keys(globalInterceptors).forEach(hook => {
  591. if (hook !== 'returnValue') {
  592. interceptor[hook] = globalInterceptors[hook].slice();
  593. }
  594. });
  595. const scopedInterceptor = scopedInterceptors[method];
  596. if (scopedInterceptor) {
  597. Object.keys(scopedInterceptor).forEach(hook => {
  598. if (hook !== 'returnValue') {
  599. interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
  600. }
  601. });
  602. }
  603. return interceptor
  604. }
  605. function invokeApi (method, api, options, ...params) {
  606. const interceptor = getApiInterceptorHooks(method);
  607. if (interceptor && Object.keys(interceptor).length) {
  608. if (Array.isArray(interceptor.invoke)) {
  609. const res = queue(interceptor.invoke, options);
  610. return res.then((options) => {
  611. return api(wrapperOptions(interceptor, options), ...params)
  612. })
  613. } else {
  614. return api(wrapperOptions(interceptor, options), ...params)
  615. }
  616. }
  617. return api(options, ...params)
  618. }
  619. const promiseInterceptor = {
  620. returnValue (res) {
  621. if (!isPromise(res)) {
  622. return res
  623. }
  624. return res.then(res => {
  625. return res[1]
  626. }).catch(res => {
  627. return res[0]
  628. })
  629. }
  630. };
  631. const SYNC_API_RE =
  632. /^\$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
  633. const CONTEXT_API_RE = /^create|Manager$/;
  634. // Context例外情况
  635. const CONTEXT_API_RE_EXC = ['createBLEConnection'];
  636. const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket'];
  637. // 同步例外情况
  638. const ASYNC_API = ['createBLEConnection'];
  639. const CALLBACK_API_RE = /^on|^off/;
  640. function isContextApi (name) {
  641. return CONTEXT_API_RE.test(name) && CONTEXT_API_RE_EXC.indexOf(name) === -1
  642. }
  643. function isSyncApi (name) {
  644. return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1
  645. }
  646. function isCallbackApi (name) {
  647. return CALLBACK_API_RE.test(name) && name !== 'onPush'
  648. }
  649. function isTaskApi (name) {
  650. return TASK_APIS.indexOf(name) !== -1
  651. }
  652. function handlePromise (promise) {
  653. return promise.then(data => {
  654. return [null, data]
  655. })
  656. .catch(err => [err])
  657. }
  658. function shouldPromise (name) {
  659. if (
  660. isContextApi(name) ||
  661. isSyncApi(name) ||
  662. isCallbackApi(name)
  663. ) {
  664. return false
  665. }
  666. return true
  667. }
  668. /* eslint-disable no-extend-native */
  669. if (!Promise.prototype.finally) {
  670. Promise.prototype.finally = function (callback) {
  671. const promise = this.constructor;
  672. return this.then(
  673. value => promise.resolve(callback()).then(() => value),
  674. reason => promise.resolve(callback()).then(() => {
  675. throw reason
  676. })
  677. )
  678. };
  679. }
  680. function promisify (name, api) {
  681. if (!shouldPromise(name)) {
  682. return api
  683. }
  684. return function promiseApi (options = {}, ...params) {
  685. if (isFn(options.success) || isFn(options.fail) || isFn(options.complete)) {
  686. return wrapperReturnValue(name, invokeApi(name, api, options, ...params))
  687. }
  688. return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
  689. invokeApi(name, api, Object.assign({}, options, {
  690. success: resolve,
  691. fail: reject
  692. }), ...params);
  693. })))
  694. }
  695. }
  696. const base64ToArrayBuffer = [{
  697. name: 'base64',
  698. type: String,
  699. required: true
  700. }];
  701. const arrayBufferToBase64 = [{
  702. name: 'arrayBuffer',
  703. type: [ArrayBuffer, Uint8Array],
  704. required: true
  705. }];
  706. var require_context_module_0_0 = /*#__PURE__*/Object.freeze({
  707. __proto__: null,
  708. base64ToArrayBuffer: base64ToArrayBuffer,
  709. arrayBufferToBase64: arrayBufferToBase64
  710. });
  711. const canIUse = [{
  712. name: 'schema',
  713. type: String,
  714. required: true
  715. }];
  716. var require_context_module_0_1 = /*#__PURE__*/Object.freeze({
  717. __proto__: null,
  718. canIUse: canIUse
  719. });
  720. const $on = [{
  721. name: 'event',
  722. type: [String, Array],
  723. required: true
  724. }, {
  725. name: 'callback',
  726. type: Function,
  727. required: true
  728. }];
  729. const $once = $on;
  730. const $off = [{
  731. name: 'event',
  732. type: [String, Array]
  733. }, {
  734. name: 'callback',
  735. type: Function
  736. }];
  737. const $emit = [{
  738. name: 'event',
  739. type: String,
  740. required: true
  741. }];
  742. var require_context_module_0_2 = /*#__PURE__*/Object.freeze({
  743. __proto__: null,
  744. $on: $on,
  745. $once: $once,
  746. $off: $off,
  747. $emit: $emit
  748. });
  749. const addInterceptor$1 = [{
  750. name: 'method',
  751. type: [String, Object],
  752. required: true
  753. }];
  754. const removeInterceptor$1 = addInterceptor$1;
  755. var require_context_module_0_3 = /*#__PURE__*/Object.freeze({
  756. __proto__: null,
  757. addInterceptor: addInterceptor$1,
  758. removeInterceptor: removeInterceptor$1
  759. });
  760. const upx2px = [{
  761. name: 'upx',
  762. type: [Number, String],
  763. required: true
  764. }];
  765. var require_context_module_0_4 = /*#__PURE__*/Object.freeze({
  766. __proto__: null,
  767. upx2px: upx2px
  768. });
  769. function getInt (method) {
  770. return function (value, params) {
  771. if (value) {
  772. params[method] = Math.round(value);
  773. }
  774. }
  775. }
  776. const canvasGetImageData = {
  777. canvasId: {
  778. type: String,
  779. required: true
  780. },
  781. x: {
  782. type: Number,
  783. required: true,
  784. validator: getInt('x')
  785. },
  786. y: {
  787. type: Number,
  788. required: true,
  789. validator: getInt('y')
  790. },
  791. width: {
  792. type: Number,
  793. required: true,
  794. validator: getInt('width')
  795. },
  796. height: {
  797. type: Number,
  798. required: true,
  799. validator: getInt('height')
  800. }
  801. };
  802. const canvasPutImageData = {
  803. canvasId: {
  804. type: String,
  805. required: true
  806. },
  807. data: {
  808. type: Uint8ClampedArray,
  809. required: true
  810. },
  811. x: {
  812. type: Number,
  813. required: true,
  814. validator: getInt('x')
  815. },
  816. y: {
  817. type: Number,
  818. required: true,
  819. validator: getInt('y')
  820. },
  821. width: {
  822. type: Number,
  823. required: true,
  824. validator: getInt('width')
  825. },
  826. height: {
  827. type: Number,
  828. validator: getInt('height')
  829. }
  830. };
  831. const fileTypes = {
  832. PNG: 'png',
  833. JPG: 'jpg',
  834. JPEG: 'jpg'
  835. };
  836. const canvasToTempFilePath = {
  837. x: {
  838. type: Number,
  839. default: 0,
  840. validator: getInt('x')
  841. },
  842. y: {
  843. type: Number,
  844. default: 0,
  845. validator: getInt('y')
  846. },
  847. width: {
  848. type: Number,
  849. validator: getInt('width')
  850. },
  851. height: {
  852. type: Number,
  853. validator: getInt('height')
  854. },
  855. destWidth: {
  856. type: Number,
  857. validator: getInt('destWidth')
  858. },
  859. destHeight: {
  860. type: Number,
  861. validator: getInt('destHeight')
  862. },
  863. canvasId: {
  864. type: String,
  865. require: true
  866. },
  867. fileType: {
  868. type: String,
  869. validator (value, params) {
  870. value = (value || '').toUpperCase();
  871. params.fileType = value in fileTypes ? fileTypes[value] : fileTypes.PNG;
  872. }
  873. },
  874. quality: {
  875. type: Number,
  876. validator (value, params) {
  877. value = Math.floor(value);
  878. params.quality = value > 0 && value < 1 ? value : 1;
  879. }
  880. }
  881. };
  882. const drawCanvas = {
  883. canvasId: {
  884. type: String,
  885. require: true
  886. },
  887. actions: {
  888. type: Array,
  889. require: true
  890. },
  891. reserve: {
  892. type: Boolean,
  893. default: false
  894. }
  895. };
  896. var require_context_module_0_5 = /*#__PURE__*/Object.freeze({
  897. __proto__: null,
  898. canvasGetImageData: canvasGetImageData,
  899. canvasPutImageData: canvasPutImageData,
  900. canvasToTempFilePath: canvasToTempFilePath,
  901. drawCanvas: drawCanvas
  902. });
  903. const validator = [{
  904. name: 'id',
  905. type: String,
  906. required: true
  907. }];
  908. const createAudioContext = validator;
  909. const createVideoContext = validator;
  910. const createMapContext = validator;
  911. const createCanvasContext = [{
  912. name: 'canvasId',
  913. type: String,
  914. required: true
  915. }, {
  916. name: 'componentInstance',
  917. type: Object
  918. }];
  919. var require_context_module_0_6 = /*#__PURE__*/Object.freeze({
  920. __proto__: null,
  921. createAudioContext: createAudioContext,
  922. createVideoContext: createVideoContext,
  923. createMapContext: createMapContext,
  924. createCanvasContext: createCanvasContext
  925. });
  926. const makePhoneCall = {
  927. phoneNumber: {
  928. type: String,
  929. required: true,
  930. validator (phoneNumber) {
  931. if (!phoneNumber) {
  932. return 'makePhoneCall:fail parameter error: parameter.phoneNumber should not be empty String;'
  933. }
  934. }
  935. }
  936. };
  937. var require_context_module_0_7 = /*#__PURE__*/Object.freeze({
  938. __proto__: null,
  939. makePhoneCall: makePhoneCall
  940. });
  941. const setClipboardData = {
  942. beforeSuccess () {
  943. uni.showToast({
  944. title: '内容已复制',
  945. icon: 'success',
  946. mask: false
  947. });
  948. }
  949. };
  950. var require_context_module_0_8 = /*#__PURE__*/Object.freeze({
  951. __proto__: null,
  952. setClipboardData: setClipboardData
  953. });
  954. const openDocument = {
  955. filePath: {
  956. type: String,
  957. required: true
  958. },
  959. fileType: {
  960. type: String
  961. }
  962. };
  963. var require_context_module_0_9 = /*#__PURE__*/Object.freeze({
  964. __proto__: null,
  965. openDocument: openDocument
  966. });
  967. const chooseLocation = {
  968. keyword: {
  969. type: String
  970. }
  971. };
  972. var require_context_module_0_10 = /*#__PURE__*/Object.freeze({
  973. __proto__: null,
  974. chooseLocation: chooseLocation
  975. });
  976. const type = {
  977. WGS84: 'WGS84',
  978. GCJ02: 'GCJ02'
  979. };
  980. const getLocation = {
  981. type: {
  982. type: String,
  983. validator (value, params) {
  984. value = (value || '').toUpperCase();
  985. params.type = Object.values(type).indexOf(value) < 0 ? type.WGS84 : value;
  986. },
  987. default: type.WGS84
  988. },
  989. altitude: {
  990. altitude: Boolean,
  991. default: false
  992. }
  993. };
  994. var require_context_module_0_11 = /*#__PURE__*/Object.freeze({
  995. __proto__: null,
  996. getLocation: getLocation
  997. });
  998. const openLocation = {
  999. latitude: {
  1000. type: Number,
  1001. required: true
  1002. },
  1003. longitude: {
  1004. type: Number,
  1005. required: true
  1006. },
  1007. scale: {
  1008. type: Number,
  1009. validator (value, params) {
  1010. value = Math.floor(value);
  1011. params.scale = value >= 5 && value <= 18 ? value : 18;
  1012. },
  1013. default: 18
  1014. },
  1015. name: {
  1016. type: String
  1017. },
  1018. address: {
  1019. type: String
  1020. }
  1021. };
  1022. var require_context_module_0_12 = /*#__PURE__*/Object.freeze({
  1023. __proto__: null,
  1024. openLocation: openLocation
  1025. });
  1026. const SIZE_TYPES = ['original', 'compressed'];
  1027. const SOURCE_TYPES = ['album', 'camera'];
  1028. const chooseImage = {
  1029. count: {
  1030. type: Number,
  1031. required: false,
  1032. default: 9,
  1033. validator (count, params) {
  1034. if (count <= 0) {
  1035. params.count = 9;
  1036. }
  1037. }
  1038. },
  1039. sizeType: {
  1040. type: [Array, String],
  1041. required: false,
  1042. default: SIZE_TYPES,
  1043. validator (sizeType, params) {
  1044. // 非必传的参数,不符合预期时处理为默认值。
  1045. const length = sizeType.length;
  1046. if (!length) {
  1047. params.sizeType = SIZE_TYPES;
  1048. } else if (typeof sizeType === 'string') {
  1049. if (!~SIZE_TYPES.indexOf(sizeType)) {
  1050. params.sizeType = SIZE_TYPES;
  1051. }
  1052. } else {
  1053. for (let i = 0; i < length; i++) {
  1054. if (typeof sizeType[i] !== 'string' || !~SIZE_TYPES.indexOf(sizeType[i])) {
  1055. params.sizeType = SIZE_TYPES;
  1056. break
  1057. }
  1058. }
  1059. }
  1060. }
  1061. },
  1062. sourceType: {
  1063. type: Array,
  1064. required: false,
  1065. default: SOURCE_TYPES,
  1066. validator (sourceType, params) {
  1067. const length = sourceType.length;
  1068. if (!length) {
  1069. params.sourceType = SOURCE_TYPES;
  1070. } else {
  1071. for (let i = 0; i < length; i++) {
  1072. if (typeof sourceType[i] !== 'string' || !~SOURCE_TYPES.indexOf(sourceType[i])) {
  1073. params.sourceType = SOURCE_TYPES;
  1074. break
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. };
  1081. var require_context_module_0_13 = /*#__PURE__*/Object.freeze({
  1082. __proto__: null,
  1083. chooseImage: chooseImage
  1084. });
  1085. const SOURCE_TYPES$1 = ['album', 'camera'];
  1086. const chooseVideo = {
  1087. sourceType: {
  1088. type: Array,
  1089. required: false,
  1090. default: SOURCE_TYPES$1,
  1091. validator (sourceType, params) {
  1092. const length = sourceType.length;
  1093. if (!length) {
  1094. params.sourceType = SOURCE_TYPES$1;
  1095. } else {
  1096. for (let i = 0; i < length; i++) {
  1097. if (typeof sourceType[i] !== 'string' || !~SOURCE_TYPES$1.indexOf(sourceType[i])) {
  1098. params.sourceType = SOURCE_TYPES$1;
  1099. break
  1100. }
  1101. }
  1102. }
  1103. }
  1104. }
  1105. };
  1106. var require_context_module_0_14 = /*#__PURE__*/Object.freeze({
  1107. __proto__: null,
  1108. chooseVideo: chooseVideo
  1109. });
  1110. function getRealRoute (fromRoute, toRoute) {
  1111. if (!toRoute) {
  1112. toRoute = fromRoute;
  1113. if (toRoute.indexOf('/') === 0) {
  1114. return toRoute
  1115. }
  1116. const pages = getCurrentPages();
  1117. if (pages.length) {
  1118. fromRoute = pages[pages.length - 1].$page.route;
  1119. } else {
  1120. fromRoute = '';
  1121. }
  1122. } else {
  1123. if (toRoute.indexOf('/') === 0) {
  1124. return toRoute
  1125. }
  1126. }
  1127. if (toRoute.indexOf('./') === 0) {
  1128. return getRealRoute(fromRoute, toRoute.substr(2))
  1129. }
  1130. const toRouteArray = toRoute.split('/');
  1131. const toRouteLength = toRouteArray.length;
  1132. let i = 0;
  1133. for (; i < toRouteLength && toRouteArray[i] === '..'; i++) {
  1134. // noop
  1135. }
  1136. toRouteArray.splice(0, i);
  1137. toRoute = toRouteArray.join('/');
  1138. const fromRouteArray = fromRoute.length > 0 ? fromRoute.split('/') : [];
  1139. fromRouteArray.splice(fromRouteArray.length - i - 1, i + 1);
  1140. return '/' + fromRouteArray.concat(toRouteArray).join('/')
  1141. }
  1142. const SCHEME_RE = /^([a-z-]+:)?\/\//i;
  1143. const DATA_RE = /^data:.*,.*/;
  1144. // 处理 Android 平台解压与非解压模式下获取的路径不一致的情况
  1145. function handleLocalPath (filePath) {
  1146. return plus.io.convertLocalFileSystemURL(filePath)
  1147. .replace(/^\/?apps\//, '/android_asset/apps/')
  1148. .replace(/\/$/, '')
  1149. }
  1150. let wwwPath;
  1151. function addBase (filePath) {
  1152. if (!wwwPath) { // 需要时,初始化一次,外部直接初始化,需要等 plusready
  1153. wwwPath = 'file://' + handleLocalPath('_www') + '/';
  1154. }
  1155. return wwwPath + filePath
  1156. }
  1157. function getRealPath (filePath) {
  1158. if (filePath.indexOf('/') === 0) {
  1159. if (filePath.indexOf('//') === 0) {
  1160. filePath = 'https:' + filePath;
  1161. } else {
  1162. return addBase(filePath.substr(1))
  1163. }
  1164. }
  1165. // 网络资源或base64
  1166. if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
  1167. return filePath
  1168. }
  1169. // _do=>_doc,_documents,_downloads
  1170. if (filePath.indexOf('_www') === 0 || filePath.indexOf('_do') === 0) {
  1171. return 'file://' + handleLocalPath(filePath)
  1172. }
  1173. const pages = getCurrentPages();
  1174. if (pages.length) {
  1175. return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1))
  1176. }
  1177. return filePath
  1178. }
  1179. const getImageInfo = {
  1180. src: {
  1181. type: String,
  1182. required: true,
  1183. validator (src, params) {
  1184. params.src = getRealPath(src);
  1185. }
  1186. }
  1187. };
  1188. var require_context_module_0_15 = /*#__PURE__*/Object.freeze({
  1189. __proto__: null,
  1190. getImageInfo: getImageInfo
  1191. });
  1192. const previewImage = {
  1193. urls: {
  1194. type: Array,
  1195. required: true,
  1196. validator (value, params) {
  1197. var typeError;
  1198. params.urls = value.map(url => {
  1199. if (typeof url === 'string') {
  1200. return getRealPath(url)
  1201. } else {
  1202. typeError = true;
  1203. }
  1204. });
  1205. if (typeError) {
  1206. return 'url is not string'
  1207. }
  1208. }
  1209. },
  1210. current: {
  1211. type: [String, Number],
  1212. validator (value, params) {
  1213. if (typeof value === 'number') {
  1214. params.current = value > 0 && value < params.urls.length ? value : 0;
  1215. } else if (typeof value === 'string' && value) {
  1216. params.current = getRealPath(value);
  1217. }
  1218. },
  1219. default: 0
  1220. }
  1221. };
  1222. var require_context_module_0_16 = /*#__PURE__*/Object.freeze({
  1223. __proto__: null,
  1224. previewImage: previewImage
  1225. });
  1226. const saveImageToPhotosAlbum = {
  1227. filePath: {
  1228. type: String,
  1229. required: true,
  1230. validator (filePath, params) {
  1231. params.filePath = getRealPath(filePath);
  1232. }
  1233. }
  1234. };
  1235. var require_context_module_0_17 = /*#__PURE__*/Object.freeze({
  1236. __proto__: null,
  1237. saveImageToPhotosAlbum: saveImageToPhotosAlbum
  1238. });
  1239. const downloadFile = {
  1240. url: {
  1241. type: String,
  1242. required: true
  1243. },
  1244. header: {
  1245. type: Object,
  1246. validator (value, params) {
  1247. params.header = value || {};
  1248. }
  1249. }
  1250. };
  1251. var require_context_module_0_18 = /*#__PURE__*/Object.freeze({
  1252. __proto__: null,
  1253. downloadFile: downloadFile
  1254. });
  1255. const method = {
  1256. OPTIONS: 'OPTIONS',
  1257. GET: 'GET',
  1258. HEAD: 'HEAD',
  1259. POST: 'POST',
  1260. PUT: 'PUT',
  1261. DELETE: 'DELETE',
  1262. TRACE: 'TRACE',
  1263. CONNECT: 'CONNECT'
  1264. };
  1265. const dataType = {
  1266. JSON: 'json'
  1267. };
  1268. const responseType = {
  1269. TEXT: 'text',
  1270. ARRAYBUFFER: 'arraybuffer'
  1271. };
  1272. const encode$1 = encodeURIComponent;
  1273. function stringifyQuery$1 (url, data) {
  1274. let str = url.split('#');
  1275. const hash = str[1] || '';
  1276. str = str[0].split('?');
  1277. let query = str[1] || '';
  1278. url = str[0];
  1279. const search = query.split('&').filter(item => item);
  1280. query = {};
  1281. search.forEach(item => {
  1282. item = item.split('=');
  1283. query[item[0]] = item[1];
  1284. });
  1285. for (const key in data) {
  1286. if (hasOwn(data, key)) {
  1287. let v = data[key];
  1288. if (typeof v === 'undefined' || v === null) {
  1289. v = '';
  1290. } else if (isPlainObject(v)) {
  1291. v = JSON.stringify(v);
  1292. }
  1293. query[encode$1(key)] = encode$1(v);
  1294. }
  1295. }
  1296. query = Object.keys(query).map(item => `${item}=${query[item]}`).join('&');
  1297. return url + (query ? '?' + query : '') + (hash ? '#' + hash : '')
  1298. }
  1299. const request = {
  1300. method: {
  1301. type: String,
  1302. validator (value, params) {
  1303. value = (value || '').toUpperCase();
  1304. params.method = Object.values(method).indexOf(value) < 0 ? method.GET : value;
  1305. }
  1306. },
  1307. data: {
  1308. type: [Object, String, Array, ArrayBuffer],
  1309. validator (value, params) {
  1310. params.data = value || '';
  1311. }
  1312. },
  1313. url: {
  1314. type: String,
  1315. required: true,
  1316. validator (value, params) {
  1317. if (
  1318. params.method === method.GET &&
  1319. isPlainObject(params.data) &&
  1320. Object.keys(params.data).length
  1321. ) { // 将 method,data 校验提前,保证 url 校验时,method,data 已被格式化
  1322. params.url = stringifyQuery$1(value, params.data);
  1323. }
  1324. }
  1325. },
  1326. header: {
  1327. type: Object,
  1328. validator (value, params) {
  1329. const header = params.header = value || {};
  1330. if (params.method !== method.GET) {
  1331. if (!Object.keys(header).find(key => key.toLowerCase() === 'content-type')) {
  1332. header['Content-Type'] = 'application/json';
  1333. }
  1334. }
  1335. }
  1336. },
  1337. dataType: {
  1338. type: String,
  1339. validator (value, params) {
  1340. params.dataType = (value || dataType.JSON).toLowerCase();
  1341. }
  1342. },
  1343. responseType: {
  1344. type: String,
  1345. validator (value, params) {
  1346. value = (value || '').toLowerCase();
  1347. params.responseType = Object.values(responseType).indexOf(value) < 0 ? responseType.TEXT : value;
  1348. }
  1349. },
  1350. withCredentials: {
  1351. type: Boolean
  1352. }
  1353. };
  1354. var require_context_module_0_19 = /*#__PURE__*/Object.freeze({
  1355. __proto__: null,
  1356. request: request
  1357. });
  1358. const method$1 = {
  1359. OPTIONS: 'OPTIONS',
  1360. GET: 'GET',
  1361. HEAD: 'HEAD',
  1362. POST: 'POST',
  1363. PUT: 'PUT',
  1364. DELETE: 'DELETE',
  1365. TRACE: 'TRACE',
  1366. CONNECT: 'CONNECT'
  1367. };
  1368. const connectSocket = {
  1369. url: {
  1370. type: String,
  1371. required: true
  1372. },
  1373. header: {
  1374. type: Object,
  1375. validator (value, params) {
  1376. params.header = value || {};
  1377. }
  1378. },
  1379. method: {
  1380. type: String,
  1381. validator (value, params) {
  1382. value = (value || '').toUpperCase();
  1383. params.method = Object.values(method$1).indexOf(value) < 0 ? method$1.GET : value;
  1384. }
  1385. },
  1386. protocols: {
  1387. // 微信文档虽然写的是数组,但是可以正常传递字符串
  1388. type: [Array, String],
  1389. validator (value, params) {
  1390. if (typeof value === 'string') {
  1391. value = [value];
  1392. }
  1393. params.protocols = (value || []).filter(str => typeof str === 'string');
  1394. }
  1395. }
  1396. };
  1397. const sendSocketMessage = {
  1398. data: {
  1399. type: [String, ArrayBuffer]
  1400. }
  1401. };
  1402. const closeSocket = {
  1403. code: {
  1404. type: Number
  1405. },
  1406. reason: {
  1407. type: String
  1408. }
  1409. };
  1410. var require_context_module_0_20 = /*#__PURE__*/Object.freeze({
  1411. __proto__: null,
  1412. connectSocket: connectSocket,
  1413. sendSocketMessage: sendSocketMessage,
  1414. closeSocket: closeSocket
  1415. });
  1416. // App端可以只使用files不传filePath和name
  1417. const uploadFile = {
  1418. url: {
  1419. type: String,
  1420. required: true
  1421. },
  1422. files: {
  1423. type: Array
  1424. },
  1425. filePath: {
  1426. type: String,
  1427. validator (value, params) {
  1428. if (value) {
  1429. params.type = getRealPath(value);
  1430. }
  1431. }
  1432. },
  1433. name: {
  1434. type: String
  1435. },
  1436. header: {
  1437. type: Object,
  1438. validator (value, params) {
  1439. params.header = value || {};
  1440. }
  1441. },
  1442. formData: {
  1443. type: Object,
  1444. validator (value, params) {
  1445. params.formData = value || {};
  1446. }
  1447. }
  1448. };
  1449. var require_context_module_0_21 = /*#__PURE__*/Object.freeze({
  1450. __proto__: null,
  1451. uploadFile: uploadFile
  1452. });
  1453. const service = {
  1454. OAUTH: 'OAUTH',
  1455. SHARE: 'SHARE',
  1456. PAYMENT: 'PAYMENT',
  1457. PUSH: 'PUSH'
  1458. };
  1459. const getProvider = {
  1460. service: {
  1461. type: String,
  1462. required: true,
  1463. validator (value, params) {
  1464. value = (value || '').toUpperCase();
  1465. if (value && Object.values(service).indexOf(value) < 0) {
  1466. return 'service error'
  1467. }
  1468. }
  1469. }
  1470. };
  1471. var require_context_module_0_22 = /*#__PURE__*/Object.freeze({
  1472. __proto__: null,
  1473. getProvider: getProvider
  1474. });
  1475. function encodeQueryString (url) {
  1476. if (typeof url !== 'string') {
  1477. return url
  1478. }
  1479. const index = url.indexOf('?');
  1480. if (index === -1) {
  1481. return url
  1482. }
  1483. const query = url.substr(index + 1).trim().replace(/^(\?|#|&)/, '');
  1484. if (!query) {
  1485. return url
  1486. }
  1487. url = url.substr(0, index);
  1488. const params = [];
  1489. query.split('&').forEach(param => {
  1490. const parts = param.replace(/\+/g, ' ').split('=');
  1491. const key = parts.shift();
  1492. const val = parts.length > 0
  1493. ? parts.join('=')
  1494. : '';
  1495. params.push(key + '=' + encodeURIComponent(val));
  1496. });
  1497. return params.length ? url + '?' + params.join('&') : url
  1498. }
  1499. function createValidator (type) {
  1500. return function validator (url, params) {
  1501. // 格式化为绝对路径路由
  1502. url = getRealRoute(url);
  1503. const pagePath = url.split('?')[0];
  1504. // 匹配路由是否存在
  1505. const routeOptions = __uniRoutes.find(({
  1506. path,
  1507. alias
  1508. }) => path === pagePath || alias === pagePath);
  1509. if (!routeOptions) {
  1510. return 'page `' + url + '` is not found'
  1511. }
  1512. // 检测不同类型跳转
  1513. if (type === 'navigateTo' || type === 'redirectTo') {
  1514. if (routeOptions.meta.isTabBar) {
  1515. return `can not ${type} a tabbar page`
  1516. }
  1517. } else if (type === 'switchTab') {
  1518. if (!routeOptions.meta.isTabBar) {
  1519. return 'can not switch to no-tabBar page'
  1520. }
  1521. }
  1522. // switchTab不允许传递参数,reLaunch到一个tabBar页面是可以的
  1523. if (
  1524. type === 'switchTab' &&
  1525. routeOptions.meta.isTabBar &&
  1526. params.openType !== 'appLaunch'
  1527. ) {
  1528. url = pagePath;
  1529. }
  1530. // 首页自动格式化为`/`
  1531. if (routeOptions.meta.isEntry) {
  1532. url = url.replace(routeOptions.alias, '/');
  1533. }
  1534. // 参数格式化
  1535. params.url = encodeQueryString(url);
  1536. // 主要拦截目标为用户快速点击时触发的多次跳转,该情况,通常前后 url 是一样的
  1537. if (navigatorLock === url) {
  1538. return `${navigatorLock} locked`
  1539. }
  1540. // 至少 onLaunch 之后,再启用lock逻辑(onLaunch之前可能开发者手动调用路由API,来提前跳转)
  1541. // enableNavigatorLock 临时开关(不对外开放),避免该功能上线后,有部分情况异常,可以让开发者临时关闭 lock 功能
  1542. if (__uniConfig.ready && __uniConfig.enableNavigatorLock !== false) {
  1543. navigatorLock = url;
  1544. }
  1545. }
  1546. }
  1547. let navigatorLock;
  1548. function createProtocol (type, extras = {}) {
  1549. return Object.assign({
  1550. url: {
  1551. type: String,
  1552. required: true,
  1553. validator: createValidator(type)
  1554. },
  1555. beforeAll () {
  1556. navigatorLock = '';
  1557. }
  1558. }, extras)
  1559. }
  1560. function createAnimationProtocol (animationTypes) {
  1561. return {
  1562. animationType: {
  1563. type: String,
  1564. validator (type) {
  1565. if (type && animationTypes.indexOf(type) === -1) {
  1566. return '`' + type + '` is not supported for `animationType` (supported values are: `' + animationTypes.join(
  1567. '`|`') + '`)'
  1568. }
  1569. }
  1570. },
  1571. animationDuration: {
  1572. type: Number
  1573. }
  1574. }
  1575. }
  1576. const redirectTo = createProtocol('redirectTo');
  1577. const reLaunch = createProtocol('reLaunch');
  1578. const navigateTo = createProtocol('navigateTo', createAnimationProtocol(
  1579. [
  1580. 'slide-in-right',
  1581. 'slide-in-left',
  1582. 'slide-in-top',
  1583. 'slide-in-bottom',
  1584. 'fade-in',
  1585. 'zoom-out',
  1586. 'zoom-fade-out',
  1587. 'pop-in',
  1588. 'none'
  1589. ]
  1590. ));
  1591. const switchTab = createProtocol('switchTab');
  1592. const navigateBack = Object.assign({
  1593. delta: {
  1594. type: Number,
  1595. validator (delta, params) {
  1596. delta = parseInt(delta) || 1;
  1597. params.delta = Math.min(getCurrentPages().length - 1, delta);
  1598. }
  1599. }
  1600. }, createAnimationProtocol(
  1601. [
  1602. 'slide-out-right',
  1603. 'slide-out-left',
  1604. 'slide-out-top',
  1605. 'slide-out-bottom',
  1606. 'fade-out',
  1607. 'zoom-in',
  1608. 'zoom-fade-in',
  1609. 'pop-out',
  1610. 'none'
  1611. ]
  1612. ));
  1613. var require_context_module_0_23 = /*#__PURE__*/Object.freeze({
  1614. __proto__: null,
  1615. redirectTo: redirectTo,
  1616. reLaunch: reLaunch,
  1617. navigateTo: navigateTo,
  1618. switchTab: switchTab,
  1619. navigateBack: navigateBack
  1620. });
  1621. const getStorage = {
  1622. key: {
  1623. type: String,
  1624. required: true
  1625. }
  1626. };
  1627. const getStorageSync = [{
  1628. name: 'key',
  1629. type: String,
  1630. required: true
  1631. }];
  1632. const setStorage = {
  1633. key: {
  1634. type: String,
  1635. required: true
  1636. },
  1637. data: {
  1638. required: true
  1639. }
  1640. };
  1641. const setStorageSync = [{
  1642. name: 'key',
  1643. type: String,
  1644. required: true
  1645. }, {
  1646. name: 'data',
  1647. required: true
  1648. }];
  1649. const removeStorage = getStorage;
  1650. const removeStorageSync = getStorageSync;
  1651. var require_context_module_0_24 = /*#__PURE__*/Object.freeze({
  1652. __proto__: null,
  1653. getStorage: getStorage,
  1654. getStorageSync: getStorageSync,
  1655. setStorage: setStorage,
  1656. setStorageSync: setStorageSync,
  1657. removeStorage: removeStorage,
  1658. removeStorageSync: removeStorageSync
  1659. });
  1660. const loadFontFace = {
  1661. family: {
  1662. type: String,
  1663. required: true
  1664. },
  1665. source: {
  1666. type: String,
  1667. required: true
  1668. },
  1669. desc: {
  1670. type: Object,
  1671. required: false
  1672. },
  1673. success: {
  1674. type: Function,
  1675. required: false
  1676. },
  1677. fail: {
  1678. type: Function,
  1679. required: false
  1680. },
  1681. complete: {
  1682. type: Function,
  1683. required: false
  1684. }
  1685. };
  1686. var require_context_module_0_25 = /*#__PURE__*/Object.freeze({
  1687. __proto__: null,
  1688. loadFontFace: loadFontFace
  1689. });
  1690. const FRONT_COLORS = ['#ffffff', '#000000'];
  1691. const setNavigationBarColor = {
  1692. frontColor: {
  1693. type: String,
  1694. required: true,
  1695. validator (frontColor, params) {
  1696. if (FRONT_COLORS.indexOf(frontColor) === -1) {
  1697. return `invalid frontColor "${frontColor}"`
  1698. }
  1699. }
  1700. },
  1701. backgroundColor: {
  1702. type: String,
  1703. required: true
  1704. },
  1705. animation: {
  1706. type: Object,
  1707. default () {
  1708. return {
  1709. duration: 0,
  1710. timingFunc: 'linear'
  1711. }
  1712. },
  1713. validator (animation = {}, params) {
  1714. params.animation = {
  1715. duration: animation.duration || 0,
  1716. timingFunc: animation.timingFunc || 'linear'
  1717. };
  1718. }
  1719. }
  1720. };
  1721. const setNavigationBarTitle = {
  1722. title: {
  1723. type: String,
  1724. required: true
  1725. }
  1726. };
  1727. var require_context_module_0_26 = /*#__PURE__*/Object.freeze({
  1728. __proto__: null,
  1729. setNavigationBarColor: setNavigationBarColor,
  1730. setNavigationBarTitle: setNavigationBarTitle
  1731. });
  1732. const pageScrollTo = {
  1733. scrollTop: {
  1734. type: Number,
  1735. required: true
  1736. },
  1737. duration: {
  1738. type: Number,
  1739. default: 300,
  1740. validator (duration, params) {
  1741. params.duration = Math.max(0, duration);
  1742. }
  1743. }
  1744. };
  1745. var require_context_module_0_27 = /*#__PURE__*/Object.freeze({
  1746. __proto__: null,
  1747. pageScrollTo: pageScrollTo
  1748. });
  1749. const showModal = {
  1750. title: {
  1751. type: String,
  1752. default: ''
  1753. },
  1754. content: {
  1755. type: String,
  1756. default: ''
  1757. },
  1758. showCancel: {
  1759. type: Boolean,
  1760. default: true
  1761. },
  1762. cancelText: {
  1763. type: String,
  1764. default: '取消'
  1765. },
  1766. cancelColor: {
  1767. type: String,
  1768. default: '#000000'
  1769. },
  1770. confirmText: {
  1771. type: String,
  1772. default: '确定'
  1773. },
  1774. confirmColor: {
  1775. type: String,
  1776. default: '#007aff'
  1777. },
  1778. visible: {
  1779. type: Boolean,
  1780. default: true
  1781. }
  1782. };
  1783. const showToast = {
  1784. title: {
  1785. type: String,
  1786. default: ''
  1787. },
  1788. icon: {
  1789. default: 'success',
  1790. validator (icon, params) {
  1791. if (['success', 'loading', 'none'].indexOf(icon) === -1) {
  1792. params.icon = 'success';
  1793. }
  1794. }
  1795. },
  1796. image: {
  1797. type: String,
  1798. default: '',
  1799. validator (image, params) {
  1800. if (image) {
  1801. params.image = getRealPath(image);
  1802. }
  1803. }
  1804. },
  1805. duration: {
  1806. type: Number,
  1807. default: 1500
  1808. },
  1809. mask: {
  1810. type: Boolean,
  1811. default: false
  1812. },
  1813. visible: {
  1814. type: Boolean,
  1815. default: true
  1816. }
  1817. };
  1818. const showLoading = {
  1819. title: {
  1820. type: String,
  1821. default: ''
  1822. },
  1823. icon: {
  1824. type: String,
  1825. default: 'loading'
  1826. },
  1827. duration: {
  1828. type: Number,
  1829. default: 100000000 // 简单处理 showLoading,直接设置个大值
  1830. },
  1831. mask: {
  1832. type: Boolean,
  1833. default: false
  1834. },
  1835. visible: {
  1836. type: Boolean,
  1837. default: true
  1838. }
  1839. };
  1840. const showActionSheet = {
  1841. itemList: {
  1842. type: Array,
  1843. required: true,
  1844. validator (itemList, params) {
  1845. if (!itemList.length) {
  1846. return 'parameter.itemList should have at least 1 item'
  1847. }
  1848. }
  1849. },
  1850. itemColor: {
  1851. type: String,
  1852. default: '#000000'
  1853. },
  1854. visible: {
  1855. type: Boolean,
  1856. default: true
  1857. },
  1858. popover: {
  1859. type: Object
  1860. }
  1861. };
  1862. var require_context_module_0_28 = /*#__PURE__*/Object.freeze({
  1863. __proto__: null,
  1864. showModal: showModal,
  1865. showToast: showToast,
  1866. showLoading: showLoading,
  1867. showActionSheet: showActionSheet
  1868. });
  1869. const indexValidator = {
  1870. type: Number,
  1871. required: true
  1872. };
  1873. const setTabBarItem = {
  1874. index: indexValidator,
  1875. text: {
  1876. type: String
  1877. },
  1878. iconPath: {
  1879. type: String
  1880. },
  1881. selectedIconPath: {
  1882. type: String
  1883. }
  1884. };
  1885. const setTabBarStyle = {
  1886. color: {
  1887. type: String
  1888. },
  1889. selectedColor: {
  1890. type: String
  1891. },
  1892. backgroundColor: {
  1893. type: String
  1894. },
  1895. backgroundImage: {
  1896. type: String,
  1897. validator (backgroundImage, params) {
  1898. if (backgroundImage && !(/^(linear|radial)-gradient\(.+?\);?$/.test(backgroundImage))) {
  1899. params.backgroundImage = getRealPath(backgroundImage);
  1900. }
  1901. }
  1902. },
  1903. backgroundRepeat: {
  1904. type: String
  1905. },
  1906. borderStyle: {
  1907. type: String,
  1908. validator (borderStyle, params) {
  1909. if (borderStyle) {
  1910. params.borderStyle = borderStyle === 'black' ? 'black' : 'white';
  1911. }
  1912. }
  1913. }
  1914. };
  1915. const hideTabBar = {
  1916. animation: {
  1917. type: Boolean,
  1918. default: false
  1919. }
  1920. };
  1921. const showTabBar = {
  1922. animation: {
  1923. type: Boolean,
  1924. default: false
  1925. }
  1926. };
  1927. const hideTabBarRedDot = {
  1928. index: indexValidator
  1929. };
  1930. const showTabBarRedDot = {
  1931. index: indexValidator
  1932. };
  1933. const removeTabBarBadge = {
  1934. index: indexValidator
  1935. };
  1936. const setTabBarBadge = {
  1937. index: indexValidator,
  1938. text: {
  1939. type: String,
  1940. required: true,
  1941. validator (text, params) {
  1942. if (getLen(text) >= 4) {
  1943. params.text = '...';
  1944. }
  1945. }
  1946. }
  1947. };
  1948. var require_context_module_0_29 = /*#__PURE__*/Object.freeze({
  1949. __proto__: null,
  1950. setTabBarItem: setTabBarItem,
  1951. setTabBarStyle: setTabBarStyle,
  1952. hideTabBar: hideTabBar,
  1953. showTabBar: showTabBar,
  1954. hideTabBarRedDot: hideTabBarRedDot,
  1955. showTabBarRedDot: showTabBarRedDot,
  1956. removeTabBarBadge: removeTabBarBadge,
  1957. setTabBarBadge: setTabBarBadge
  1958. });
  1959. const protocol = Object.create(null);
  1960. const modules =
  1961. (function() {
  1962. var map = {
  1963. './base/base64.js': require_context_module_0_0,
  1964. './base/can-i-use.js': require_context_module_0_1,
  1965. './base/event-bus.js': require_context_module_0_2,
  1966. './base/interceptor.js': require_context_module_0_3,
  1967. './base/upx2px.js': require_context_module_0_4,
  1968. './context/canvas.js': require_context_module_0_5,
  1969. './context/context.js': require_context_module_0_6,
  1970. './device/make-phone-call.js': require_context_module_0_7,
  1971. './device/set-clipboard-data.js': require_context_module_0_8,
  1972. './file/open-document.js': require_context_module_0_9,
  1973. './location/choose-location.js': require_context_module_0_10,
  1974. './location/get-location.js': require_context_module_0_11,
  1975. './location/open-location.js': require_context_module_0_12,
  1976. './media/choose-image.js': require_context_module_0_13,
  1977. './media/choose-video.js': require_context_module_0_14,
  1978. './media/get-image-info.js': require_context_module_0_15,
  1979. './media/preview-image.js': require_context_module_0_16,
  1980. './media/save-image-to-photos-album.js': require_context_module_0_17,
  1981. './network/download-file.js': require_context_module_0_18,
  1982. './network/request.js': require_context_module_0_19,
  1983. './network/socket.js': require_context_module_0_20,
  1984. './network/upload-file.js': require_context_module_0_21,
  1985. './plugin/get-provider.js': require_context_module_0_22,
  1986. './route/route.js': require_context_module_0_23,
  1987. './storage/storage.js': require_context_module_0_24,
  1988. './ui/load-font-face.js': require_context_module_0_25,
  1989. './ui/navigation-bar.js': require_context_module_0_26,
  1990. './ui/page-scroll-to.js': require_context_module_0_27,
  1991. './ui/popup.js': require_context_module_0_28,
  1992. './ui/tab-bar.js': require_context_module_0_29,
  1993. };
  1994. var req = function req(key) {
  1995. return map[key] || (function() { throw new Error("Cannot find module '" + key + "'.") }());
  1996. };
  1997. req.keys = function() {
  1998. return Object.keys(map);
  1999. };
  2000. return req;
  2001. })();
  2002. modules.keys().forEach(function (key) {
  2003. Object.assign(protocol, modules(key));
  2004. });
  2005. function validateParam (key, paramTypes, paramsData) {
  2006. const paramOptions = paramTypes[key];
  2007. const absent = !hasOwn(paramsData, key);
  2008. let value = paramsData[key];
  2009. const booleanIndex = getTypeIndex(Boolean, paramOptions.type);
  2010. if (booleanIndex > -1) {
  2011. if (absent && !hasOwn(paramOptions, 'default')) {
  2012. value = false;
  2013. }
  2014. }
  2015. if (value === undefined) {
  2016. if (hasOwn(paramOptions, 'default')) {
  2017. const paramDefault = paramOptions.default;
  2018. value = isFn(paramDefault) ? paramDefault() : paramDefault;
  2019. paramsData[key] = value; // 默认值
  2020. }
  2021. }
  2022. return assertParam(paramOptions, key, value, absent, paramsData)
  2023. }
  2024. function assertParam (
  2025. paramOptions,
  2026. name,
  2027. value,
  2028. absent,
  2029. paramsData
  2030. ) {
  2031. if (paramOptions.required && absent) {
  2032. return `Missing required parameter \`${name}\``
  2033. }
  2034. if (value == null && !paramOptions.required) {
  2035. const validator = paramOptions.validator;
  2036. if (validator) {
  2037. return validator(value, paramsData)
  2038. }
  2039. return
  2040. }
  2041. let type = paramOptions.type;
  2042. let valid = !type || type === true;
  2043. const expectedTypes = [];
  2044. if (type) {
  2045. if (!Array.isArray(type)) {
  2046. type = [type];
  2047. }
  2048. for (let i = 0; i < type.length && !valid; i++) {
  2049. const assertedType = assertType(value, type[i]);
  2050. expectedTypes.push(assertedType.expectedType || '');
  2051. valid = assertedType.valid;
  2052. }
  2053. }
  2054. if (!valid) {
  2055. return getInvalidTypeMessage(name, value, expectedTypes)
  2056. }
  2057. const validator = paramOptions.validator;
  2058. if (validator) {
  2059. return validator(value, paramsData)
  2060. }
  2061. }
  2062. const simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/;
  2063. function assertType (value, type) {
  2064. let valid;
  2065. const expectedType = getType(type);
  2066. if (simpleCheckRE.test(expectedType)) {
  2067. const t = typeof value;
  2068. valid = t === expectedType.toLowerCase();
  2069. if (!valid && t === 'object') {
  2070. valid = value instanceof type;
  2071. }
  2072. } else if (value.byteLength >= 0) {
  2073. valid = true;
  2074. } else if (expectedType === 'Object') {
  2075. valid = isPlainObject(value);
  2076. } else if (expectedType === 'Array') {
  2077. valid = Array.isArray(value);
  2078. } else {
  2079. // TODO 页面传入的ArrayBuffer使用instanceof ArrayBuffer返回false,暂做此修改
  2080. valid = value instanceof type || toRawType(value) === getType(type);
  2081. }
  2082. return {
  2083. valid,
  2084. expectedType
  2085. }
  2086. }
  2087. function getType (fn) {
  2088. const match = fn && fn.toString().match(/^\s*function (\w+)/);
  2089. return match ? match[1] : ''
  2090. }
  2091. function isSameType (a, b) {
  2092. return getType(a) === getType(b)
  2093. }
  2094. function getTypeIndex (type, expectedTypes) {
  2095. if (!Array.isArray(expectedTypes)) {
  2096. return isSameType(expectedTypes, type) ? 0 : -1
  2097. }
  2098. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  2099. if (isSameType(expectedTypes[i], type)) {
  2100. return i
  2101. }
  2102. }
  2103. return -1
  2104. }
  2105. function getInvalidTypeMessage (name, value, expectedTypes) {
  2106. let message = `parameter \`${name}\`.` +
  2107. ` Expected ${expectedTypes.join(', ')}`;
  2108. const expectedType = expectedTypes[0];
  2109. const receivedType = toRawType(value);
  2110. const expectedValue = styleValue(value, expectedType);
  2111. const receivedValue = styleValue(value, receivedType);
  2112. if (expectedTypes.length === 1 &&
  2113. isExplicable(expectedType) &&
  2114. !isBoolean(expectedType, receivedType)) {
  2115. message += ` with value ${expectedValue}`;
  2116. }
  2117. message += `, got ${receivedType} `;
  2118. if (isExplicable(receivedType)) {
  2119. message += `with value ${receivedValue}.`;
  2120. }
  2121. return message
  2122. }
  2123. function styleValue (value, type) {
  2124. if (type === 'String') {
  2125. return `"${value}"`
  2126. } else if (type === 'Number') {
  2127. return `${Number(value)}`
  2128. } else {
  2129. return `${value}`
  2130. }
  2131. }
  2132. const explicitTypes = ['string', 'number', 'boolean'];
  2133. function isExplicable (value) {
  2134. return explicitTypes.some(elem => value.toLowerCase() === elem)
  2135. }
  2136. function isBoolean (...args) {
  2137. return args.some(elem => elem.toLowerCase() === 'boolean')
  2138. }
  2139. function invokeCallbackHandlerFail (err, apiName, callbackId) {
  2140. const errMsg = `${apiName}:fail ${err}`;
  2141. if (process.env.NODE_ENV !== 'production') {
  2142. console.error(errMsg);
  2143. }
  2144. if (callbackId === -1) {
  2145. throw new Error(errMsg)
  2146. }
  2147. if (typeof callbackId === 'number') {
  2148. invokeCallbackHandler(callbackId, {
  2149. errMsg
  2150. });
  2151. }
  2152. return false
  2153. }
  2154. const callbackApiParamTypes = [{
  2155. name: 'callback',
  2156. type: Function,
  2157. required: true
  2158. }];
  2159. // 目前已用到的仅这三个
  2160. // 完整的可能包含:
  2161. // beforeValidate,
  2162. // beforeSuccess,
  2163. // afterSuccess,
  2164. // beforeFail,
  2165. // afterFail,
  2166. // beforeCancel,
  2167. // afterCancel,
  2168. // beforeAll,
  2169. // afterAll
  2170. const IGNORE_KEYS = [
  2171. 'beforeValidate',
  2172. 'beforeAll',
  2173. 'beforeSuccess'
  2174. ];
  2175. function validateParams (apiName, paramsData, callbackId) {
  2176. let paramTypes = protocol[apiName];
  2177. if (!paramTypes && isCallbackApi(apiName)) {
  2178. paramTypes = callbackApiParamTypes;
  2179. }
  2180. if (paramTypes) {
  2181. if (Array.isArray(paramTypes) && Array.isArray(paramsData)) {
  2182. const paramTypeObj = Object.create(null);
  2183. const paramsDataObj = Object.create(null);
  2184. const paramsDataLength = paramsData.length;
  2185. paramTypes.forEach((paramType, index) => {
  2186. paramTypeObj[paramType.name] = paramType;
  2187. if (paramsDataLength > index) {
  2188. paramsDataObj[paramType.name] = paramsData[index];
  2189. }
  2190. });
  2191. paramTypes = paramTypeObj;
  2192. paramsData = paramsDataObj;
  2193. }
  2194. if (isFn(paramTypes.beforeValidate)) {
  2195. const err = paramTypes.beforeValidate(paramsData);
  2196. if (err) {
  2197. return invokeCallbackHandlerFail(err, apiName, callbackId)
  2198. }
  2199. }
  2200. const keys = Object.keys(paramTypes);
  2201. for (let i = 0; i < keys.length; i++) {
  2202. if (IGNORE_KEYS.indexOf(keys[i]) !== -1) {
  2203. continue
  2204. }
  2205. const err = validateParam(keys[i], paramTypes, paramsData);
  2206. if (err) {
  2207. return invokeCallbackHandlerFail(err, apiName, callbackId)
  2208. }
  2209. }
  2210. }
  2211. return true
  2212. }
  2213. let invokeCallbackId = 1;
  2214. const invokeCallbacks = {};
  2215. function createKeepAliveApiCallback (apiName, callback) {
  2216. const callbackId = invokeCallbackId++;
  2217. const invokeCallbackName = 'api.' + apiName + '.' + callbackId;
  2218. const invokeCallback = function (res, extras) {
  2219. callback(res, extras);
  2220. };
  2221. invokeCallbacks[callbackId] = {
  2222. name: invokeCallbackName,
  2223. keepAlive: true,
  2224. callback: invokeCallback
  2225. };
  2226. return callbackId
  2227. }
  2228. function createApiCallback (apiName, params = {}, extras = {}) {
  2229. if (!isPlainObject(params)) {
  2230. return {
  2231. params
  2232. }
  2233. }
  2234. params = Object.assign({}, params);
  2235. const apiCallbacks = {};
  2236. for (const name in params) {
  2237. const param = params[name];
  2238. if (isFn(param)) {
  2239. apiCallbacks[name] = tryCatch(param);
  2240. delete params[name];
  2241. }
  2242. }
  2243. const {
  2244. success,
  2245. fail,
  2246. cancel,
  2247. complete
  2248. } = apiCallbacks;
  2249. const hasSuccess = isFn(success);
  2250. const hasFail = isFn(fail);
  2251. const hasCancel = isFn(cancel);
  2252. const hasComplete = isFn(complete);
  2253. if (!hasSuccess && !hasFail && !hasCancel && !hasComplete) { // 无回调
  2254. return {
  2255. params
  2256. }
  2257. }
  2258. const wrapperCallbacks = {};
  2259. for (const name in extras) {
  2260. const extra = extras[name];
  2261. if (isFn(extra)) {
  2262. wrapperCallbacks[name] = tryCatchFramework(extra);
  2263. }
  2264. }
  2265. const {
  2266. beforeSuccess,
  2267. afterSuccess,
  2268. beforeFail,
  2269. afterFail,
  2270. beforeCancel,
  2271. afterCancel,
  2272. beforeAll,
  2273. afterAll
  2274. } = wrapperCallbacks;
  2275. const callbackId = invokeCallbackId++;
  2276. const invokeCallbackName = 'api.' + apiName + '.' + callbackId;
  2277. const invokeCallback = function (res) {
  2278. res.errMsg = res.errMsg || apiName + ':ok';
  2279. // 部分 api 可能返回的 errMsg 的 api 名称部分不一致,格式化为正确的
  2280. if (res.errMsg.indexOf(':ok') !== -1) {
  2281. res.errMsg = apiName + ':ok';
  2282. } else if (res.errMsg.indexOf(':cancel') !== -1) {
  2283. res.errMsg = apiName + ':cancel';
  2284. } else if (res.errMsg.indexOf(':fail') !== -1) {
  2285. let errDetail = '';
  2286. const spaceIndex = res.errMsg.indexOf(' ');
  2287. if (spaceIndex > -1) {
  2288. errDetail = res.errMsg.substr(spaceIndex);
  2289. }
  2290. res.errMsg = apiName + ':fail' + errDetail;
  2291. }
  2292. isFn(beforeAll) && beforeAll(res);
  2293. const errMsg = res.errMsg;
  2294. if (errMsg.indexOf(apiName + ':ok') === 0) {
  2295. isFn(beforeSuccess) && beforeSuccess(res);
  2296. hasSuccess && success(res);
  2297. isFn(afterSuccess) && afterSuccess(res);
  2298. } else if (errMsg.indexOf(apiName + ':cancel') === 0) {
  2299. res.errMsg = res.errMsg.replace(apiName + ':cancel', apiName + ':fail cancel');
  2300. hasFail && fail(res);
  2301. isFn(beforeCancel) && beforeCancel(res);
  2302. hasCancel && cancel(res);
  2303. isFn(afterCancel) && afterCancel(res);
  2304. } else if (errMsg.indexOf(apiName + ':fail') === 0) {
  2305. isFn(beforeFail) && beforeFail(res);
  2306. hasFail && fail(res);
  2307. isFn(afterFail) && afterFail(res);
  2308. }
  2309. hasComplete && complete(res);
  2310. isFn(afterAll) && afterAll(res);
  2311. };
  2312. invokeCallbacks[callbackId] = {
  2313. name: invokeCallbackName,
  2314. callback: invokeCallback
  2315. };
  2316. return {
  2317. params,
  2318. callbackId
  2319. }
  2320. }
  2321. function createInvokeCallback (apiName, params = {}, extras = {}) {
  2322. const {
  2323. params: args,
  2324. callbackId
  2325. } = createApiCallback(apiName, params, extras);
  2326. if (isPlainObject(args) && !validateParams(apiName, args, callbackId)) {
  2327. return {
  2328. params: args,
  2329. callbackId: false
  2330. }
  2331. }
  2332. return {
  2333. params: args,
  2334. callbackId
  2335. }
  2336. }
  2337. // onNativeEventReceive((event,data)=>{}) 需要两个参数,写死最多两个参数,避免改动太大,影响已有逻辑
  2338. function invokeCallbackHandler (invokeCallbackId, res, extras) {
  2339. if (typeof invokeCallbackId === 'number') {
  2340. const invokeCallback = invokeCallbacks[invokeCallbackId];
  2341. if (invokeCallback) {
  2342. if (!invokeCallback.keepAlive) {
  2343. delete invokeCallbacks[invokeCallbackId];
  2344. }
  2345. return invokeCallback.callback(res, extras)
  2346. }
  2347. }
  2348. return res
  2349. }
  2350. function wrapperUnimplemented (name) {
  2351. return function todo (args) {
  2352. console.error('API `' + name + '` is not yet implemented');
  2353. }
  2354. }
  2355. function wrapperExtras (name, extras) {
  2356. const protocolOptions = protocol[name];
  2357. if (protocolOptions) {
  2358. isFn(protocolOptions.beforeAll) && (extras.beforeAll = protocolOptions.beforeAll);
  2359. isFn(protocolOptions.beforeSuccess) && (extras.beforeSuccess = protocolOptions.beforeSuccess);
  2360. }
  2361. }
  2362. function wrapper (name, invokeMethod, extras = {}) {
  2363. if (!isFn(invokeMethod)) {
  2364. return invokeMethod
  2365. }
  2366. wrapperExtras(name, extras);
  2367. return function (...args) {
  2368. if (isSyncApi(name)) {
  2369. if (validateParams(name, args, -1)) {
  2370. return invokeMethod.apply(null, args)
  2371. }
  2372. } else if (isCallbackApi(name)) {
  2373. if (validateParams(name, args, -1)) {
  2374. return invokeMethod(createKeepAliveApiCallback(name, args[0]))
  2375. }
  2376. } else {
  2377. let argsObj = {};
  2378. if (args.length) {
  2379. argsObj = args[0];
  2380. }
  2381. const {
  2382. params,
  2383. callbackId
  2384. } = createInvokeCallback(name, argsObj, extras);
  2385. if (callbackId !== false) {
  2386. let res;
  2387. if (isFn(params)) {
  2388. res = invokeMethod(callbackId);
  2389. } else {
  2390. res = invokeMethod(params, callbackId);
  2391. }
  2392. if (res && !isTaskApi(name)) {
  2393. res = invokeCallbackHandler(callbackId, res);
  2394. if (isPlainObject(res)) {
  2395. res.errMsg = res.errMsg || name + ':ok';
  2396. }
  2397. }
  2398. return res
  2399. }
  2400. }
  2401. }
  2402. }
  2403. function createCommonjsModule(fn, module) {
  2404. return module = { exports: {} }, fn(module, module.exports), module.exports;
  2405. }
  2406. var base64Arraybuffer = createCommonjsModule(function (module, exports) {
  2407. /*
  2408. * base64-arraybuffer
  2409. * https://github.com/niklasvh/base64-arraybuffer
  2410. *
  2411. * Copyright (c) 2012 Niklas von Hertzen
  2412. * Licensed under the MIT license.
  2413. */
  2414. (function(){
  2415. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2416. // Use a lookup table to find the index.
  2417. var lookup = new Uint8Array(256);
  2418. for (var i = 0; i < chars.length; i++) {
  2419. lookup[chars.charCodeAt(i)] = i;
  2420. }
  2421. exports.encode = function(arraybuffer) {
  2422. var bytes = new Uint8Array(arraybuffer),
  2423. i, len = bytes.length, base64 = "";
  2424. for (i = 0; i < len; i+=3) {
  2425. base64 += chars[bytes[i] >> 2];
  2426. base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
  2427. base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
  2428. base64 += chars[bytes[i + 2] & 63];
  2429. }
  2430. if ((len % 3) === 2) {
  2431. base64 = base64.substring(0, base64.length - 1) + "=";
  2432. } else if (len % 3 === 1) {
  2433. base64 = base64.substring(0, base64.length - 2) + "==";
  2434. }
  2435. return base64;
  2436. };
  2437. exports.decode = function(base64) {
  2438. var bufferLength = base64.length * 0.75,
  2439. len = base64.length, i, p = 0,
  2440. encoded1, encoded2, encoded3, encoded4;
  2441. if (base64[base64.length - 1] === "=") {
  2442. bufferLength--;
  2443. if (base64[base64.length - 2] === "=") {
  2444. bufferLength--;
  2445. }
  2446. }
  2447. var arraybuffer = new ArrayBuffer(bufferLength),
  2448. bytes = new Uint8Array(arraybuffer);
  2449. for (i = 0; i < len; i+=4) {
  2450. encoded1 = lookup[base64.charCodeAt(i)];
  2451. encoded2 = lookup[base64.charCodeAt(i+1)];
  2452. encoded3 = lookup[base64.charCodeAt(i+2)];
  2453. encoded4 = lookup[base64.charCodeAt(i+3)];
  2454. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  2455. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  2456. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  2457. }
  2458. return arraybuffer;
  2459. };
  2460. })();
  2461. });
  2462. var base64Arraybuffer_1 = base64Arraybuffer.encode;
  2463. var base64Arraybuffer_2 = base64Arraybuffer.decode;
  2464. function base64ToArrayBuffer$1 (str) {
  2465. return base64Arraybuffer_2(str)
  2466. }
  2467. function arrayBufferToBase64$1 (buffer) {
  2468. return base64Arraybuffer_1(buffer)
  2469. }
  2470. var require_context_module_1_0 = /*#__PURE__*/Object.freeze({
  2471. __proto__: null,
  2472. base64ToArrayBuffer: base64ToArrayBuffer$1,
  2473. arrayBufferToBase64: arrayBufferToBase64$1
  2474. });
  2475. var platformSchema = {};
  2476. // TODO 待处理其他 API 的检测
  2477. function canIUse$1 (schema) {
  2478. if (hasOwn(platformSchema, schema)) {
  2479. return platformSchema[schema]
  2480. }
  2481. return true
  2482. }
  2483. var require_context_module_1_1 = /*#__PURE__*/Object.freeze({
  2484. __proto__: null,
  2485. canIUse: canIUse$1
  2486. });
  2487. const interceptors = {
  2488. promiseInterceptor
  2489. };
  2490. var require_context_module_1_2 = /*#__PURE__*/Object.freeze({
  2491. __proto__: null,
  2492. interceptors: interceptors,
  2493. addInterceptor: addInterceptor,
  2494. removeInterceptor: removeInterceptor
  2495. });
  2496. const EPS = 1e-4;
  2497. const BASE_DEVICE_WIDTH = 750;
  2498. let isIOS = false;
  2499. let deviceWidth = 0;
  2500. let deviceDPR = 0;
  2501. function checkDeviceWidth () {
  2502. const {
  2503. platform,
  2504. pixelRatio,
  2505. windowWidth
  2506. } = uni.getSystemInfoSync();
  2507. deviceWidth = windowWidth;
  2508. deviceDPR = pixelRatio;
  2509. isIOS = platform === 'ios';
  2510. }
  2511. function upx2px$1 (number, newDeviceWidth) {
  2512. if (deviceWidth === 0) {
  2513. checkDeviceWidth();
  2514. }
  2515. number = Number(number);
  2516. if (number === 0) {
  2517. return 0
  2518. }
  2519. let result = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth);
  2520. if (result < 0) {
  2521. result = -result;
  2522. }
  2523. result = Math.floor(result + EPS);
  2524. if (result === 0) {
  2525. if (deviceDPR === 1 || !isIOS) {
  2526. return 1
  2527. } else {
  2528. return 0.5
  2529. }
  2530. }
  2531. return number < 0 ? -result : result
  2532. }
  2533. var require_context_module_1_3 = /*#__PURE__*/Object.freeze({
  2534. __proto__: null,
  2535. upx2px: upx2px$1
  2536. });
  2537. const Emitter = new Vue();
  2538. function apply (ctx, method, args) {
  2539. return ctx[method].apply(ctx, args)
  2540. }
  2541. function $on$1 () {
  2542. return apply(Emitter, '$on', [...arguments])
  2543. }
  2544. function $off$1 () {
  2545. return apply(Emitter, '$off', [...arguments])
  2546. }
  2547. function $once$1 () {
  2548. return apply(Emitter, '$once', [...arguments])
  2549. }
  2550. function $emit$1 () {
  2551. return apply(Emitter, '$emit', [...arguments])
  2552. }
  2553. var eventApis = /*#__PURE__*/Object.freeze({
  2554. __proto__: null,
  2555. $on: $on$1,
  2556. $off: $off$1,
  2557. $once: $once$1,
  2558. $emit: $emit$1
  2559. });
  2560. function unpack (args) {
  2561. return args
  2562. }
  2563. function invoke$1 (...args) {
  2564. return UniServiceJSBridge.invokeCallbackHandler(...args)
  2565. }
  2566. function requireNativePlugin (name) {
  2567. return uni.requireNativePlugin(name)
  2568. }
  2569. /**
  2570. * 触发 service 层,与 onMethod 对应
  2571. */
  2572. function publish (name, ...args) {
  2573. return UniServiceJSBridge.emit('api.' + name, ...args)
  2574. }
  2575. let lastStatusBarStyle;
  2576. const oldSetStatusBarStyle = plus.navigator.setStatusBarStyle;
  2577. function newSetStatusBarStyle (style) {
  2578. lastStatusBarStyle = style;
  2579. oldSetStatusBarStyle(style);
  2580. }
  2581. plus.navigator.setStatusBarStyle = newSetStatusBarStyle;
  2582. function setStatusBarStyle (statusBarStyle) {
  2583. if (!statusBarStyle) {
  2584. const pages = getCurrentPages();
  2585. if (!pages.length) {
  2586. return
  2587. }
  2588. statusBarStyle = pages[pages.length - 1].$page.meta.statusBarStyle;
  2589. if (!statusBarStyle || statusBarStyle === lastStatusBarStyle) {
  2590. return
  2591. }
  2592. }
  2593. if (statusBarStyle === lastStatusBarStyle) {
  2594. return
  2595. }
  2596. if (process.env.NODE_ENV !== 'production') {
  2597. console.log('[uni-app] setStatusBarStyle', statusBarStyle);
  2598. }
  2599. lastStatusBarStyle = statusBarStyle;
  2600. plus.navigator.setStatusBarStyle(statusBarStyle);
  2601. }
  2602. function isTabBarPage (path = '') {
  2603. if (!(__uniConfig.tabBar && Array.isArray(__uniConfig.tabBar.list))) {
  2604. return false
  2605. }
  2606. try {
  2607. if (!path) {
  2608. const pages = getCurrentPages();
  2609. if (!pages.length) {
  2610. return false
  2611. }
  2612. const page = pages[pages.length - 1];
  2613. if (!page) {
  2614. return false
  2615. }
  2616. return page.$page.meta.isTabBar
  2617. }
  2618. if (!/^\//.test(path)) {
  2619. path = '/' + path;
  2620. }
  2621. const route = __uniRoutes.find(route => route.path === path);
  2622. return route && route.meta.isTabBar
  2623. } catch (e) {
  2624. if (process.env.NODE_ENV !== 'production') {
  2625. console.log('getCurrentPages is not ready');
  2626. }
  2627. }
  2628. return false
  2629. }
  2630. function base64ToArrayBuffer$2 (data) {
  2631. return base64Arraybuffer_2(data)
  2632. }
  2633. function arrayBufferToBase64$2 (data) {
  2634. return base64Arraybuffer_1(data)
  2635. }
  2636. function callApiSync (api, args, name, alias) {
  2637. const ret = api(args);
  2638. if (ret && ret.errMsg) {
  2639. ret.errMsg = ret.errMsg.replace(name, alias);
  2640. }
  2641. return ret
  2642. }
  2643. function getLastWebview () {
  2644. try {
  2645. const pages = getCurrentPages();
  2646. if (pages.length) {
  2647. return pages[pages.length - 1].$getAppWebview()
  2648. }
  2649. } catch (e) {
  2650. if (process.env.NODE_ENV !== 'production') {
  2651. console.log('getCurrentPages is not ready');
  2652. }
  2653. }
  2654. }
  2655. const getRealRoute$1 = (e, t) => {
  2656. if (t.indexOf('./') === 0) return getRealRoute$1(e, t.substr(2))
  2657. let n;
  2658. let i;
  2659. const o = t.split('/');
  2660. for (n = 0, i = o.length; n < i && o[n] === '..'; n++);
  2661. o.splice(0, n);
  2662. t = o.join('/');
  2663. const r = e.length > 0 ? e.split('/') : [];
  2664. r.splice(r.length - n - 1, n + 1);
  2665. return r.concat(o).join('/')
  2666. };
  2667. // 处理 Android 平台解压与非解压模式下获取的路径不一致的情况
  2668. const _handleLocalPath = filePath => {
  2669. const localUrl = plus.io.convertLocalFileSystemURL(filePath);
  2670. return localUrl.replace(/^\/?apps\//, '/android_asset/apps/').replace(/\/$/, '')
  2671. };
  2672. function getRealPath$1 (filePath) {
  2673. const SCHEME_RE = /^([a-z-]+:)?\/\//i;
  2674. const DATA_RE = /^data:.*,.*/;
  2675. // 无协议的情况补全 https
  2676. if (filePath.indexOf('//') === 0) {
  2677. filePath = 'https:' + filePath;
  2678. }
  2679. // 网络资源或base64
  2680. if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath)) {
  2681. return filePath
  2682. }
  2683. if (filePath.indexOf('_www') === 0 || filePath.indexOf('_doc') === 0 || filePath.indexOf('_documents') === 0 ||
  2684. filePath.indexOf('_downloads') === 0) {
  2685. return 'file://' + _handleLocalPath(filePath)
  2686. }
  2687. const wwwPath = 'file://' + _handleLocalPath('_www');
  2688. // 绝对路径转换为本地文件系统路径
  2689. if (filePath.indexOf('/') === 0) {
  2690. return wwwPath + filePath
  2691. }
  2692. // 相对资源
  2693. if (filePath.indexOf('../') === 0 || filePath.indexOf('./') === 0) {
  2694. if (typeof __id__ === 'string') {
  2695. return wwwPath + getRealRoute$1('/' + __id__, filePath)
  2696. } else {
  2697. const pages = getCurrentPages();
  2698. if (pages.length) {
  2699. return wwwPath + getRealRoute$1('/' + pages[pages.length - 1].route, filePath)
  2700. }
  2701. }
  2702. }
  2703. return filePath
  2704. }
  2705. function getStatusBarStyle () {
  2706. let style = plus.navigator.getStatusBarStyle();
  2707. if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
  2708. style = 'light';
  2709. } else if (style === 'UIStatusBarStyleDefault') {
  2710. style = 'dark';
  2711. }
  2712. return style
  2713. }
  2714. const PI = 3.1415926535897932384626;
  2715. const a = 6378245.0;
  2716. const ee = 0.00669342162296594323;
  2717. function wgs84togcj02 (lng, lat) {
  2718. lat = +lat;
  2719. lng = +lng;
  2720. if (outOfChina(lng, lat)) {
  2721. return [lng, lat]
  2722. }
  2723. let dlat = _transformlat(lng - 105.0, lat - 35.0);
  2724. let dlng = _transformlng(lng - 105.0, lat - 35.0);
  2725. const radlat = lat / 180.0 * PI;
  2726. let magic = Math.sin(radlat);
  2727. magic = 1 - ee * magic * magic;
  2728. const sqrtmagic = Math.sqrt(magic);
  2729. dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
  2730. dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
  2731. const mglat = lat + dlat;
  2732. const mglng = lng + dlng;
  2733. return [mglng, mglat]
  2734. }
  2735. function gcj02towgs84 (lng, lat) {
  2736. lat = +lat;
  2737. lng = +lng;
  2738. if (outOfChina(lng, lat)) {
  2739. return [lng, lat]
  2740. }
  2741. let dlat = _transformlat(lng - 105.0, lat - 35.0);
  2742. let dlng = _transformlng(lng - 105.0, lat - 35.0);
  2743. const radlat = lat / 180.0 * PI;
  2744. let magic = Math.sin(radlat);
  2745. magic = 1 - ee * magic * magic;
  2746. const sqrtmagic = Math.sqrt(magic);
  2747. dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
  2748. dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
  2749. const mglat = lat + dlat;
  2750. const mglng = lng + dlng;
  2751. return [lng * 2 - mglng, lat * 2 - mglat]
  2752. }
  2753. const _transformlat = function (lng, lat) {
  2754. let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
  2755. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  2756. ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
  2757. ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
  2758. return ret
  2759. };
  2760. const _transformlng = function (lng, lat) {
  2761. let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
  2762. ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
  2763. ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
  2764. ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
  2765. return ret
  2766. };
  2767. const outOfChina = function (lng, lat) {
  2768. return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false)
  2769. };
  2770. function getStatusbarHeight () {
  2771. // 横屏时 iOS 获取的状态栏高度错误,进行纠正
  2772. return plus.navigator.isImmersedStatusbar() ? Math.round(plus.os.name === 'iOS' ? plus.navigator.getSafeAreaInsets().top : plus.navigator.getStatusbarHeight()) : 0
  2773. }
  2774. function getScreenInfo () {
  2775. const { resolutionWidth, resolutionHeight } = plus.screen.getCurrentSize();
  2776. return {
  2777. screenWidth: Math.round(resolutionWidth),
  2778. screenHeight: Math.round(resolutionHeight)
  2779. }
  2780. }
  2781. const audios = {};
  2782. const evts = ['play', 'canplay', 'ended', 'stop', 'waiting', 'seeking', 'seeked', 'pause'];
  2783. const publishAudioStateChange = (state, res = {}) => publish('onAudioStateChange', Object.assign({
  2784. state
  2785. }, res));
  2786. const initStateChage = audioId => {
  2787. const audio = audios[audioId];
  2788. if (!audio) {
  2789. return
  2790. }
  2791. if (!audio.initStateChage) {
  2792. audio.initStateChage = true;
  2793. audio.addEventListener('error', error => {
  2794. publishAudioStateChange('error', {
  2795. audioId,
  2796. errMsg: 'MediaError',
  2797. errCode: error.code
  2798. });
  2799. });
  2800. evts.forEach(event => {
  2801. audio.addEventListener(event, () => {
  2802. // 添加 isStopped 属性是为了解决 安卓设备停止播放后获取播放进度不正确的问题
  2803. if (event === 'play') {
  2804. audio.isStopped = false;
  2805. } else if (event === 'stop') {
  2806. audio.isStopped = true;
  2807. }
  2808. publishAudioStateChange(event, {
  2809. audioId
  2810. });
  2811. });
  2812. });
  2813. }
  2814. };
  2815. function createAudioInstance () {
  2816. const audioId = `${Date.now()}${Math.random()}`;
  2817. const audio = audios[audioId] = plus.audio.createPlayer('');
  2818. audio.src = '';
  2819. audio.volume = 1;
  2820. audio.startTime = 0;
  2821. return {
  2822. errMsg: 'createAudioInstance:ok',
  2823. audioId
  2824. }
  2825. }
  2826. function destroyAudioInstance ({
  2827. audioId
  2828. }) {
  2829. if (audios[audioId]) {
  2830. audios[audioId].close();
  2831. delete audios[audioId];
  2832. }
  2833. return {
  2834. errMsg: 'destroyAudioInstance:ok',
  2835. audioId
  2836. }
  2837. }
  2838. function setAudioState ({
  2839. audioId,
  2840. src,
  2841. startTime,
  2842. autoplay = false,
  2843. loop = false,
  2844. obeyMuteSwitch,
  2845. volume
  2846. }) {
  2847. const audio = audios[audioId];
  2848. if (audio) {
  2849. const style = {
  2850. loop,
  2851. autoplay
  2852. };
  2853. if (src) {
  2854. audio.src = style.src = getRealPath$1(src);
  2855. }
  2856. if (startTime) {
  2857. audio.startTime = style.startTime = startTime;
  2858. }
  2859. if (typeof volume === 'number') {
  2860. audio.volume = style.volume = volume;
  2861. }
  2862. audio.setStyles(style);
  2863. initStateChage(audioId);
  2864. }
  2865. return {
  2866. errMsg: 'setAudioState:ok'
  2867. }
  2868. }
  2869. function getAudioState ({
  2870. audioId
  2871. }) {
  2872. const audio = audios[audioId];
  2873. if (!audio) {
  2874. return {
  2875. errMsg: 'getAudioState:fail'
  2876. }
  2877. }
  2878. const {
  2879. src,
  2880. startTime,
  2881. volume
  2882. } = audio;
  2883. return {
  2884. errMsg: 'getAudioState:ok',
  2885. duration: 1e3 * (audio.getDuration() || 0),
  2886. currentTime: audio.isStopped ? 0 : 1e3 * audio.getPosition(),
  2887. paused: audio.isPaused(),
  2888. src,
  2889. volume,
  2890. startTime: 1e3 * startTime,
  2891. buffered: 1e3 * audio.getBuffered()
  2892. }
  2893. }
  2894. function operateAudio ({
  2895. operationType,
  2896. audioId,
  2897. currentTime
  2898. }) {
  2899. const audio = audios[audioId];
  2900. const operationTypes = ['play', 'pause', 'stop'];
  2901. if (operationTypes.indexOf(operationType) >= 0) {
  2902. audio[operationType === operationTypes[0] && audio.isPaused() ? 'resume' : operationType]();
  2903. } else if (operationType === 'seek') {
  2904. audio.seekTo(currentTime / 1e3);
  2905. }
  2906. return {
  2907. errMsg: 'operateAudio:ok'
  2908. }
  2909. }
  2910. let audio;
  2911. let timeUpdateTimer = null;
  2912. const TIME_UPDATE = 250;
  2913. const publishBackgroundAudioStateChange = (state, res = {}) => publish('onBackgroundAudioStateChange', Object.assign({
  2914. state
  2915. }, res));
  2916. const events = ['play', 'pause', 'ended', 'stop'];
  2917. function initMusic () {
  2918. if (audio) {
  2919. return
  2920. }
  2921. audio = plus.audio.createPlayer({
  2922. autoplay: true,
  2923. backgroundControl: true
  2924. });
  2925. audio.src = audio.title = audio.epname = audio.singer = audio.coverImgUrl = audio.webUrl = '';
  2926. audio.startTime = 0;
  2927. events.forEach(event => {
  2928. audio.addEventListener(event, () => {
  2929. // 添加 isStopped 属性是为了解决 安卓设备停止播放后获取播放进度不正确的问题
  2930. if (event === 'play') {
  2931. audio.isStopped = false;
  2932. startTimeUpdateTimer();
  2933. } else if (event === 'stop') {
  2934. audio.isStopped = true;
  2935. }
  2936. if (event === 'pause' || event === 'ended' || event === 'stop') {
  2937. stopTimeUpdateTimer();
  2938. }
  2939. const eventName = `onMusic${event[0].toUpperCase() + event.substr(1)}`;
  2940. publish(eventName, {
  2941. dataUrl: audio.src,
  2942. errMsg: `${eventName}:ok`
  2943. });
  2944. publishBackgroundAudioStateChange(event, {
  2945. dataUrl: audio.src
  2946. });
  2947. });
  2948. });
  2949. audio.addEventListener('waiting', () => {
  2950. stopTimeUpdateTimer();
  2951. publishBackgroundAudioStateChange('waiting', {
  2952. dataUrl: audio.src
  2953. });
  2954. });
  2955. audio.addEventListener('error', err => {
  2956. stopTimeUpdateTimer();
  2957. publish('onMusicError', {
  2958. dataUrl: audio.src,
  2959. errMsg: 'Error:' + err.message
  2960. });
  2961. publishBackgroundAudioStateChange('error', {
  2962. dataUrl: audio.src,
  2963. errMsg: err.message,
  2964. errCode: err.code
  2965. });
  2966. });
  2967. audio.addEventListener('prev', () => publish('onBackgroundAudioPrev'));
  2968. audio.addEventListener('next', () => publish('onBackgroundAudioNext'));
  2969. }
  2970. function startTimeUpdateTimer () {
  2971. stopTimeUpdateTimer();
  2972. timeUpdateTimer = setInterval(() => {
  2973. publishBackgroundAudioStateChange('timeUpdate', {});
  2974. }, TIME_UPDATE);
  2975. }
  2976. function stopTimeUpdateTimer () {
  2977. if (timeUpdateTimer !== null) {
  2978. clearInterval(timeUpdateTimer);
  2979. }
  2980. }
  2981. function setMusicState (args) {
  2982. initMusic();
  2983. const props = ['src', 'startTime', 'coverImgUrl', 'webUrl', 'singer', 'epname', 'title'];
  2984. const style = {};
  2985. Object.keys(args).forEach(key => {
  2986. if (props.indexOf(key) >= 0) {
  2987. let val = args[key];
  2988. if (key === props[0] && val) {
  2989. val = getRealPath$1(val);
  2990. }
  2991. audio[key] = style[key] = val;
  2992. }
  2993. });
  2994. audio.setStyles(style);
  2995. }
  2996. function getAudio () {
  2997. return audio
  2998. }
  2999. function getMusicPlayerState () {
  3000. const audio = getAudio();
  3001. if (audio) {
  3002. return {
  3003. dataUrl: audio.src,
  3004. duration: audio.getDuration() || 0,
  3005. currentPosition: audio.getPosition(),
  3006. status: audio.isPaused() ? 0 : 1,
  3007. downloadPercent: Math.round(100 * audio.getBuffered() / audio.getDuration()),
  3008. errMsg: 'getMusicPlayerState:ok'
  3009. }
  3010. }
  3011. return {
  3012. status: 2,
  3013. errMsg: 'getMusicPlayerState:ok'
  3014. }
  3015. }
  3016. function operateMusicPlayer ({
  3017. operationType,
  3018. dataUrl,
  3019. position,
  3020. api = 'operateMusicPlayer',
  3021. title,
  3022. coverImgUrl
  3023. }) {
  3024. const audio = getAudio();
  3025. var operationTypes = ['resume', 'pause', 'stop'];
  3026. if (operationTypes.indexOf(operationType) > 0) {
  3027. audio && audio[operationType]();
  3028. } else if (operationType === 'play') {
  3029. setMusicState({
  3030. src: dataUrl,
  3031. startTime: position,
  3032. title,
  3033. coverImgUrl
  3034. });
  3035. audio.play();
  3036. } else if (operationType === 'seek') {
  3037. audio && audio.seekTo(position);
  3038. }
  3039. return {
  3040. errMsg: `${api}:ok`
  3041. }
  3042. }
  3043. function setBackgroundAudioState (args) {
  3044. setMusicState(args);
  3045. return {
  3046. errMsg: 'setBackgroundAudioState:ok'
  3047. }
  3048. }
  3049. function operateBackgroundAudio ({
  3050. operationType,
  3051. src,
  3052. startTime,
  3053. currentTime
  3054. }) {
  3055. return operateMusicPlayer({
  3056. operationType,
  3057. dataUrl: src,
  3058. position: startTime || currentTime || 0,
  3059. api: 'operateBackgroundAudio'
  3060. })
  3061. }
  3062. function getBackgroundAudioState () {
  3063. let data = {
  3064. duration: 0,
  3065. currentTime: 0,
  3066. paused: false,
  3067. src: '',
  3068. buffered: 0,
  3069. title: '',
  3070. epname: '',
  3071. singer: '',
  3072. coverImgUrl: '',
  3073. webUrl: '',
  3074. startTime: 0,
  3075. errMsg: 'getBackgroundAudioState:ok'
  3076. };
  3077. const audio = getAudio();
  3078. if (audio) {
  3079. const newData = {
  3080. duration: audio.getDuration() || 0,
  3081. currentTime: audio.isStopped ? 0 : audio.getPosition(),
  3082. paused: audio.isPaused(),
  3083. src: audio.src,
  3084. buffered: audio.getBuffered(),
  3085. title: audio.title,
  3086. epname: audio.epname,
  3087. singer: audio.singer,
  3088. coverImgUrl: audio.coverImgUrl,
  3089. webUrl: audio.webUrl,
  3090. startTime: audio.startTime
  3091. };
  3092. data = Object.assign(data, newData);
  3093. }
  3094. return data
  3095. }
  3096. const DEVICE_FREQUENCY = 200;
  3097. const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g'];
  3098. const MAP_ID = '__UNIAPP_MAP';
  3099. const TEMP_PATH_BASE = '_doc/uniapp_temp';
  3100. const TEMP_PATH = `${TEMP_PATH_BASE}_${Date.now()}`;
  3101. /**
  3102. * 5+错误对象转换为错误消息
  3103. * @param {*} error 5+错误对象
  3104. */
  3105. function toErrMsg (error) {
  3106. var msg = 'base64ToTempFilePath:fail';
  3107. if (error && error.message) {
  3108. msg += ` ${error.message}`;
  3109. } else if (error) {
  3110. msg += ` ${error}`;
  3111. }
  3112. return msg
  3113. }
  3114. function base64ToTempFilePath ({
  3115. base64Data,
  3116. x,
  3117. y,
  3118. width,
  3119. height,
  3120. destWidth,
  3121. destHeight,
  3122. canvasId,
  3123. fileType,
  3124. quality
  3125. } = {}, callbackId) {
  3126. var id = Date.now();
  3127. var bitmap = new plus.nativeObj.Bitmap(`bitmap${id}`);
  3128. bitmap.loadBase64Data(base64Data, function () {
  3129. var formats = ['jpg', 'png'];
  3130. var format = String(fileType).toLowerCase();
  3131. if (formats.indexOf(format) < 0) {
  3132. format = 'png';
  3133. }
  3134. /**
  3135. * 保存配置
  3136. */
  3137. var saveOption = {
  3138. overwrite: true,
  3139. quality: typeof quality === 'number' ? quality * 100 : 100,
  3140. format
  3141. };
  3142. /**
  3143. * 保存文件路径
  3144. */
  3145. var tempFilePath = `${TEMP_PATH}/canvas/${id}.${format}`;
  3146. bitmap.save(tempFilePath, saveOption, function () {
  3147. clear();
  3148. invoke$1(callbackId, {
  3149. tempFilePath,
  3150. errMsg: 'base64ToTempFilePath:ok'
  3151. });
  3152. }, function (error) {
  3153. clear();
  3154. invoke$1(callbackId, {
  3155. errMsg: toErrMsg(error)
  3156. });
  3157. });
  3158. }, function (error) {
  3159. clear();
  3160. invoke$1(callbackId, {
  3161. errMsg: toErrMsg(error)
  3162. });
  3163. });
  3164. function clear () {
  3165. bitmap.clear();
  3166. }
  3167. }
  3168. function operateMapPlayer (mapId, pageVm, type, data) {
  3169. const pageId = pageVm.$page.id;
  3170. UniServiceJSBridge.publishHandler(pageId + '-map-' + mapId, {
  3171. mapId,
  3172. type,
  3173. data
  3174. }, pageId);
  3175. }
  3176. const SUCCESS = 'success';
  3177. const FAIL = 'fail';
  3178. const COMPLETE = 'complete';
  3179. const CALLBACKS = [SUCCESS, FAIL, COMPLETE];
  3180. /**
  3181. * 调用无参数,或仅一个参数且为 callback 的 API
  3182. * @param {Object} vm
  3183. * @param {Object} method
  3184. * @param {Object} args
  3185. * @param {Object} extras
  3186. */
  3187. function invokeVmMethodWithoutArgs (vm, method, args, extras) {
  3188. if (!vm) {
  3189. return
  3190. }
  3191. if (typeof args === 'undefined') {
  3192. return vm[method]()
  3193. }
  3194. const [, callbacks] = normalizeArgs(args, extras);
  3195. if (!Object.keys(callbacks).length) {
  3196. return vm[method]()
  3197. }
  3198. return vm[method](normalizeCallback(method, callbacks))
  3199. }
  3200. /**
  3201. * 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
  3202. * @param {Object} vm
  3203. * @param {Object} method
  3204. * @param {Object} args
  3205. * @param {Object} extras
  3206. */
  3207. function invokeVmMethod (vm, method, args, extras) {
  3208. if (!vm) {
  3209. return
  3210. }
  3211. const [pureArgs, callbacks] = normalizeArgs(args, extras);
  3212. if (!Object.keys(callbacks).length) {
  3213. return vm[method](pureArgs)
  3214. }
  3215. return vm[method](pureArgs, normalizeCallback(method, callbacks))
  3216. }
  3217. function findElmById (id, vm) {
  3218. const elm = findRefByElm(id, vm.$el);
  3219. if (!elm) {
  3220. return console.error('Can not find `' + id + '`')
  3221. }
  3222. return elm
  3223. }
  3224. function findRefByElm (id, elm) {
  3225. if (!id || !elm) {
  3226. return
  3227. }
  3228. if (elm.attr && elm.attr.id === id) {
  3229. return elm
  3230. }
  3231. const children = elm.children;
  3232. if (!children) {
  3233. return
  3234. }
  3235. for (let i = 0, len = children.length; i < len; i++) {
  3236. const elm = findRefByElm(id, children[i]);
  3237. if (elm) {
  3238. return elm
  3239. }
  3240. }
  3241. }
  3242. function normalizeArgs (args = {}, extras) {
  3243. const callbacks = Object.create(null);
  3244. const iterator = function iterator (name) {
  3245. const callback = args[name];
  3246. if (isFn(callback)) {
  3247. callbacks[name] = callback;
  3248. delete args[name];
  3249. }
  3250. };
  3251. CALLBACKS.forEach(iterator);
  3252. extras && extras.forEach(iterator);
  3253. return [args, callbacks]
  3254. }
  3255. function normalizeCallback (method, callbacks) {
  3256. return function weexCallback (ret) {
  3257. const type = ret.type;
  3258. delete ret.type;
  3259. const callback = callbacks[type];
  3260. if (type === SUCCESS) {
  3261. ret.errMsg = `${method}:ok`;
  3262. } else if (type === FAIL) {
  3263. ret.errMsg = method + ':fail' + (ret.msg ? (' ' + ret.msg) : '');
  3264. }
  3265. delete ret.code;
  3266. delete ret.msg;
  3267. isFn(callback) && callback(ret);
  3268. if (type === SUCCESS || type === FAIL) {
  3269. const complete = callbacks.complete;
  3270. isFn(complete) && complete(ret);
  3271. }
  3272. }
  3273. }
  3274. const METHODS = {
  3275. getCenterLocation (ctx, cbs) {
  3276. return invokeVmMethodWithoutArgs(ctx, 'getCenterLocation', cbs)
  3277. },
  3278. moveToLocation (ctx) {
  3279. return invokeVmMethodWithoutArgs(ctx, 'moveToLocation')
  3280. },
  3281. translateMarker (ctx, args) {
  3282. return invokeVmMethod(ctx, 'translateMarker', args, ['animationEnd'])
  3283. },
  3284. includePoints (ctx, args) {
  3285. return invokeVmMethod(ctx, 'includePoints', args)
  3286. },
  3287. getRegion (ctx, cbs) {
  3288. return invokeVmMethodWithoutArgs(ctx, 'getRegion', cbs)
  3289. },
  3290. getScale (ctx, cbs) {
  3291. return invokeVmMethodWithoutArgs(ctx, 'getScale', cbs)
  3292. }
  3293. };
  3294. function operateMapPlayer$1 (mapId, pageVm, type, data) {
  3295. return METHODS[type](findElmById(mapId, pageVm), data)
  3296. }
  3297. function operateMapPlayer$2 (mapId, pageVm, type, data) {
  3298. pageVm.$page.meta.isNVue
  3299. ? operateMapPlayer$1(mapId, pageVm, type, data)
  3300. : operateMapPlayer(mapId, pageVm, type, data);
  3301. }
  3302. function operateVideoPlayer (videoId, pageVm, type, data) {
  3303. const pageId = pageVm.$page.id;
  3304. UniServiceJSBridge.publishHandler(pageId + '-video-' + videoId, {
  3305. videoId,
  3306. type,
  3307. data
  3308. }, pageId);
  3309. }
  3310. const METHODS$1 = {
  3311. play (ctx) {
  3312. return invokeVmMethodWithoutArgs(ctx, 'play')
  3313. },
  3314. pause (ctx) {
  3315. return invokeVmMethodWithoutArgs(ctx, 'pause')
  3316. },
  3317. seek (ctx, args) {
  3318. return invokeVmMethod(ctx, 'seek', args.position)
  3319. },
  3320. stop (ctx) {
  3321. return invokeVmMethodWithoutArgs(ctx, 'stop')
  3322. },
  3323. sendDanmu (ctx, args) {
  3324. return invokeVmMethod(ctx, 'sendDanmu', args)
  3325. },
  3326. playbackRate (ctx, args) {
  3327. return invokeVmMethod(ctx, 'playbackRate', args.rate)
  3328. },
  3329. requestFullScreen (ctx, args) {
  3330. return invokeVmMethod(ctx, 'requestFullScreen', args)
  3331. },
  3332. exitFullScreen (ctx) {
  3333. return invokeVmMethodWithoutArgs(ctx, 'exitFullScreen')
  3334. },
  3335. showStatusBar (ctx) {
  3336. return invokeVmMethodWithoutArgs(ctx, 'showStatusBar')
  3337. },
  3338. hideStatusBar (ctx) {
  3339. return invokeVmMethodWithoutArgs(ctx, 'hideStatusBar')
  3340. }
  3341. };
  3342. function operateVideoPlayer$1 (videoId, pageVm, type, data) {
  3343. return METHODS$1[type](findElmById(videoId, pageVm), data)
  3344. }
  3345. function operateVideoPlayer$2 (videoId, pageVm, type, data) {
  3346. pageVm.$page.meta.isNVue
  3347. ? operateVideoPlayer$1(videoId, pageVm, type, data)
  3348. : operateVideoPlayer(videoId, pageVm, type, data);
  3349. }
  3350. class LivePusherContext {
  3351. constructor (id, ctx) {
  3352. this.id = id;
  3353. this.ctx = ctx;
  3354. }
  3355. start (cbs) {
  3356. return invokeVmMethodWithoutArgs(this.ctx, 'start', cbs)
  3357. }
  3358. stop (cbs) {
  3359. return invokeVmMethodWithoutArgs(this.ctx, 'stop', cbs)
  3360. }
  3361. pause (cbs) {
  3362. return invokeVmMethodWithoutArgs(this.ctx, 'pause', cbs)
  3363. }
  3364. resume (cbs) {
  3365. return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
  3366. }
  3367. switchCamera (cbs) {
  3368. return invokeVmMethodWithoutArgs(this.ctx, 'switchCamera', cbs)
  3369. }
  3370. snapshot (cbs) {
  3371. return invokeVmMethodWithoutArgs(this.ctx, 'snapshot', cbs)
  3372. }
  3373. toggleTorch (cbs) {
  3374. return invokeVmMethodWithoutArgs(this.ctx, 'toggleTorch', cbs)
  3375. }
  3376. playBGM (args) {
  3377. return invokeVmMethod(this.ctx, 'playBGM', args)
  3378. }
  3379. stopBGM (cbs) {
  3380. return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
  3381. }
  3382. pauseBGM (cbs) {
  3383. return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
  3384. }
  3385. resumeBGM (cbs) {
  3386. return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
  3387. }
  3388. setBGMVolume (cbs) {
  3389. return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
  3390. }
  3391. startPreview (cbs) {
  3392. return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
  3393. }
  3394. stopPreview (args) {
  3395. return invokeVmMethodWithoutArgs(this.ctx, 'stopPreview', args)
  3396. }
  3397. }
  3398. function createLivePusherContext (id, vm) {
  3399. if (!vm) {
  3400. return console.warn('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)')
  3401. }
  3402. const elm = findElmById(id, vm);
  3403. if (!elm) {
  3404. return console.warn('Can not find `' + id + '`')
  3405. }
  3406. return new LivePusherContext(id, elm)
  3407. }
  3408. function createLivePusherContext$1 (id, vm) {
  3409. return createLivePusherContext(id, vm)
  3410. }
  3411. let watchAccelerationId = false;
  3412. let isWatchAcceleration = false;
  3413. const clearWatchAcceleration = () => {
  3414. if (watchAccelerationId) {
  3415. plus.accelerometer.clearWatch(watchAccelerationId);
  3416. watchAccelerationId = false;
  3417. }
  3418. };
  3419. function enableAccelerometer ({
  3420. enable
  3421. }) {
  3422. if (enable) { // 启用监听
  3423. clearWatchAcceleration();
  3424. watchAccelerationId = plus.accelerometer.watchAcceleration((res) => {
  3425. publish('onAccelerometerChange', {
  3426. x: res.xAxis,
  3427. y: res.yAxis,
  3428. z: res.zAxis,
  3429. errMsg: 'enableAccelerometer:ok'
  3430. });
  3431. }, (e) => {
  3432. publish('onAccelerometerChange', {
  3433. errMsg: 'enableAccelerometer:fail'
  3434. });
  3435. }, {
  3436. frequency: DEVICE_FREQUENCY
  3437. });
  3438. if (!isWatchAcceleration) {
  3439. isWatchAcceleration = true;
  3440. const webview = getLastWebview();
  3441. if (webview) {
  3442. webview.addEventListener('close', clearWatchAcceleration);
  3443. }
  3444. }
  3445. } else {
  3446. clearWatchAcceleration();
  3447. }
  3448. return {
  3449. errMsg: 'enableAccelerometer:ok'
  3450. }
  3451. }
  3452. function addPhoneContact ({
  3453. photoFilePath = '',
  3454. nickName,
  3455. lastName,
  3456. middleName,
  3457. firstName,
  3458. remark,
  3459. mobilePhoneNumber,
  3460. weChatNumber,
  3461. addressCountry,
  3462. addressState,
  3463. addressCity,
  3464. addressStreet,
  3465. addressPostalCode,
  3466. organization,
  3467. title,
  3468. workFaxNumber,
  3469. workPhoneNumber,
  3470. hostNumber,
  3471. email,
  3472. url,
  3473. workAddressCountry,
  3474. workAddressState,
  3475. workAddressCity,
  3476. workAddressStreet,
  3477. workAddressPostalCode,
  3478. homeFaxNumber,
  3479. homePhoneNumber,
  3480. homeAddressCountry,
  3481. homeAddressState,
  3482. homeAddressCity,
  3483. homeAddressStreet,
  3484. homeAddressPostalCode
  3485. } = {}, callbackId) {
  3486. plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, (addressbook) => {
  3487. const contact = addressbook.create();
  3488. const name = {};
  3489. if (lastName) {
  3490. name.familyName = lastName;
  3491. }
  3492. if (firstName) {
  3493. name.givenName = firstName;
  3494. }
  3495. if (middleName) {
  3496. name.middleName = middleName;
  3497. }
  3498. contact.name = name;
  3499. if (nickName) {
  3500. contact.nickname = nickName;
  3501. }
  3502. if (photoFilePath) {
  3503. contact.photos = [{
  3504. type: 'url',
  3505. value: photoFilePath
  3506. }];
  3507. }
  3508. if (remark) {
  3509. contact.note = remark;
  3510. }
  3511. const mobilePhone = {
  3512. type: 'mobile'
  3513. };
  3514. const workPhone = {
  3515. type: 'work'
  3516. };
  3517. const companyPhone = {
  3518. type: 'company'
  3519. };
  3520. const homeFax = {
  3521. type: 'home fax'
  3522. };
  3523. const workFax = {
  3524. type: 'work fax'
  3525. };
  3526. if (mobilePhoneNumber) {
  3527. mobilePhone.value = mobilePhoneNumber;
  3528. }
  3529. if (workPhoneNumber) {
  3530. workPhone.value = workPhoneNumber;
  3531. }
  3532. if (hostNumber) {
  3533. companyPhone.value = hostNumber;
  3534. }
  3535. if (homeFaxNumber) {
  3536. homeFax.value = homeFaxNumber;
  3537. }
  3538. if (workFaxNumber) {
  3539. workFax.value = workFaxNumber;
  3540. }
  3541. contact.phoneNumbers = [mobilePhone, workPhone, companyPhone, homeFax, workFax];
  3542. if (email) {
  3543. contact.emails = [{
  3544. type: 'home',
  3545. value: email
  3546. }];
  3547. }
  3548. if (url) {
  3549. contact.urls = [{
  3550. type: 'other',
  3551. value: url
  3552. }];
  3553. }
  3554. if (weChatNumber) {
  3555. contact.ims = [{
  3556. type: 'other',
  3557. value: weChatNumber
  3558. }];
  3559. }
  3560. const defaultAddress = {
  3561. type: 'other',
  3562. preferred: true
  3563. };
  3564. const homeAddress = {
  3565. type: 'home'
  3566. };
  3567. const companyAddress = {
  3568. type: 'company'
  3569. };
  3570. if (addressCountry) {
  3571. defaultAddress.country = addressCountry;
  3572. }
  3573. if (addressState) {
  3574. defaultAddress.region = addressState;
  3575. }
  3576. if (addressCity) {
  3577. defaultAddress.locality = addressCity;
  3578. }
  3579. if (addressStreet) {
  3580. defaultAddress.streetAddress = addressStreet;
  3581. }
  3582. if (addressPostalCode) {
  3583. defaultAddress.postalCode = addressPostalCode;
  3584. }
  3585. if (homeAddressCountry) {
  3586. homeAddress.country = homeAddressCountry;
  3587. }
  3588. if (homeAddressState) {
  3589. homeAddress.region = homeAddressState;
  3590. }
  3591. if (homeAddressCity) {
  3592. homeAddress.locality = homeAddressCity;
  3593. }
  3594. if (homeAddressStreet) {
  3595. homeAddress.streetAddress = homeAddressStreet;
  3596. }
  3597. if (homeAddressPostalCode) {
  3598. homeAddress.postalCode = homeAddressPostalCode;
  3599. }
  3600. if (workAddressCountry) {
  3601. companyAddress.country = workAddressCountry;
  3602. }
  3603. if (workAddressState) {
  3604. companyAddress.region = workAddressState;
  3605. }
  3606. if (workAddressCity) {
  3607. companyAddress.locality = workAddressCity;
  3608. }
  3609. if (workAddressStreet) {
  3610. companyAddress.streetAddress = workAddressStreet;
  3611. }
  3612. if (workAddressPostalCode) {
  3613. companyAddress.postalCode = workAddressPostalCode;
  3614. }
  3615. contact.addresses = [defaultAddress, homeAddress, companyAddress];
  3616. contact.save(() => {
  3617. invoke$1(callbackId, {
  3618. errMsg: 'addPhoneContact:ok'
  3619. });
  3620. }, (e) => {
  3621. invoke$1(callbackId, {
  3622. errMsg: 'addPhoneContact:fail'
  3623. });
  3624. });
  3625. }, (e) => {
  3626. invoke$1(callbackId, {
  3627. errMsg: 'addPhoneContact:fail'
  3628. });
  3629. });
  3630. }
  3631. /**
  3632. * 执行蓝牙相关方法
  3633. */
  3634. function bluetoothExec (method, callbackId, data = {}, beforeSuccess) {
  3635. var deviceId = data.deviceId;
  3636. if (deviceId) {
  3637. data.deviceId = deviceId.toUpperCase();
  3638. }
  3639. var serviceId = data.serviceId;
  3640. if (serviceId) {
  3641. data.serviceId = serviceId.toUpperCase();
  3642. }
  3643. plus.bluetooth[method.replace('Changed', 'Change')](Object.assign(data, {
  3644. success (data) {
  3645. if (typeof beforeSuccess === 'function') {
  3646. beforeSuccess(data);
  3647. }
  3648. invoke$1(callbackId, Object.assign({}, data, {
  3649. errMsg: `${method}:ok`,
  3650. code: undefined,
  3651. message: undefined
  3652. }));
  3653. },
  3654. fail (error = {}) {
  3655. invoke$1(callbackId, {
  3656. errMsg: `${method}:fail ${error.message || ''}`,
  3657. errCode: error.code || 0
  3658. });
  3659. }
  3660. }));
  3661. }
  3662. /**
  3663. * 监听蓝牙相关事件
  3664. */
  3665. function bluetoothOn (method, beforeSuccess) {
  3666. plus.bluetooth[method.replace('Changed', 'Change')](function (data) {
  3667. if (typeof beforeSuccess === 'function') {
  3668. beforeSuccess(data);
  3669. }
  3670. publish(method, Object.assign({}, data, {
  3671. code: undefined,
  3672. message: undefined
  3673. }));
  3674. });
  3675. return true
  3676. }
  3677. var onBluetoothAdapterStateChange;
  3678. var onBluetoothDeviceFound;
  3679. var onBLEConnectionStateChange;
  3680. var onBLECharacteristicValueChange;
  3681. function openBluetoothAdapter (data, callbackId) {
  3682. onBluetoothAdapterStateChange = onBluetoothAdapterStateChange || bluetoothOn('onBluetoothAdapterStateChange');
  3683. bluetoothExec('openBluetoothAdapter', callbackId);
  3684. }
  3685. function closeBluetoothAdapter (data, callbackId) {
  3686. bluetoothExec('closeBluetoothAdapter', callbackId);
  3687. }
  3688. function getBluetoothAdapterState (data, callbackId) {
  3689. bluetoothExec('getBluetoothAdapterState', callbackId);
  3690. }
  3691. function startBluetoothDevicesDiscovery (data, callbackId) {
  3692. onBluetoothDeviceFound = onBluetoothDeviceFound || bluetoothOn('onBluetoothDeviceFound');
  3693. bluetoothExec('startBluetoothDevicesDiscovery', callbackId, data);
  3694. }
  3695. function stopBluetoothDevicesDiscovery (data, callbackId) {
  3696. bluetoothExec('stopBluetoothDevicesDiscovery', callbackId);
  3697. }
  3698. function getBluetoothDevices (data, callbackId) {
  3699. bluetoothExec('getBluetoothDevices', callbackId, {});
  3700. }
  3701. function getConnectedBluetoothDevices (data, callbackId) {
  3702. bluetoothExec('getConnectedBluetoothDevices', callbackId, data);
  3703. }
  3704. function createBLEConnection (data, callbackId) {
  3705. onBLEConnectionStateChange = onBLEConnectionStateChange || bluetoothOn('onBLEConnectionStateChange');
  3706. bluetoothExec('createBLEConnection', callbackId, data);
  3707. }
  3708. function closeBLEConnection (data, callbackId) {
  3709. bluetoothExec('closeBLEConnection', callbackId, data);
  3710. }
  3711. function getBLEDeviceServices (data, callbackId) {
  3712. bluetoothExec('getBLEDeviceServices', callbackId, data);
  3713. }
  3714. function getBLEDeviceCharacteristics (data, callbackId) {
  3715. bluetoothExec('getBLEDeviceCharacteristics', callbackId, data);
  3716. }
  3717. function notifyBLECharacteristicValueChange (data, callbackId) {
  3718. onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange');
  3719. bluetoothExec('notifyBLECharacteristicValueChange', callbackId, data);
  3720. }
  3721. function notifyBLECharacteristicValueChanged (data, callbackId) {
  3722. onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange');
  3723. bluetoothExec('notifyBLECharacteristicValueChanged', callbackId, data);
  3724. }
  3725. function readBLECharacteristicValue (data, callbackId) {
  3726. onBLECharacteristicValueChange = onBLECharacteristicValueChange || bluetoothOn('onBLECharacteristicValueChange');
  3727. bluetoothExec('readBLECharacteristicValue', callbackId, data);
  3728. }
  3729. function writeBLECharacteristicValue (data, callbackId) {
  3730. bluetoothExec('writeBLECharacteristicValue', callbackId, data);
  3731. }
  3732. function getScreenBrightness () {
  3733. return {
  3734. errMsg: 'getScreenBrightness:ok',
  3735. value: plus.screen.getBrightness()
  3736. }
  3737. }
  3738. function setScreenBrightness ({
  3739. value
  3740. } = {}) {
  3741. plus.screen.setBrightness(value);
  3742. return {
  3743. errMsg: 'setScreenBrightness:ok'
  3744. }
  3745. }
  3746. function setKeepScreenOn ({
  3747. keepScreenOn
  3748. } = {}) {
  3749. plus.device.setWakelock(!!keepScreenOn);
  3750. return {
  3751. errMsg: 'setKeepScreenOn:ok'
  3752. }
  3753. }
  3754. function getClipboardData (options, callbackId) {
  3755. const clipboard = requireNativePlugin('clipboard');
  3756. clipboard.getString(ret => {
  3757. if (ret.result === 'success') {
  3758. invoke$1(callbackId, {
  3759. data: ret.data,
  3760. errMsg: 'getClipboardData:ok'
  3761. });
  3762. } else {
  3763. invoke$1(callbackId, {
  3764. data: ret.result,
  3765. errMsg: 'getClipboardData:fail'
  3766. });
  3767. }
  3768. });
  3769. }
  3770. function setClipboardData$1 ({
  3771. data
  3772. }) {
  3773. const clipboard = requireNativePlugin('clipboard');
  3774. clipboard.setString(data);
  3775. return {
  3776. errMsg: 'setClipboardData:ok'
  3777. }
  3778. }
  3779. let watchOrientationId = false;
  3780. let isWatchOrientation = false;
  3781. const clearWatchOrientation = () => {
  3782. if (watchOrientationId) {
  3783. plus.orientation.clearWatch(watchOrientationId);
  3784. watchOrientationId = false;
  3785. }
  3786. };
  3787. function enableCompass ({
  3788. enable
  3789. }) {
  3790. if (enable) {
  3791. clearWatchOrientation();
  3792. watchOrientationId = plus.orientation.watchOrientation((o) => {
  3793. publish('onCompassChange', {
  3794. direction: o.magneticHeading,
  3795. errMsg: 'enableCompass:ok'
  3796. });
  3797. }, (e) => {
  3798. publish('onCompassChange', {
  3799. errMsg: 'enableCompass:fail'
  3800. });
  3801. }, {
  3802. frequency: DEVICE_FREQUENCY
  3803. });
  3804. if (!isWatchOrientation) {
  3805. isWatchOrientation = true;
  3806. const webview = getLastWebview();
  3807. if (webview) {
  3808. webview.addEventListener('close', () => {
  3809. plus.orientation.clearWatch(watchOrientationId);
  3810. });
  3811. }
  3812. }
  3813. } else {
  3814. clearWatchOrientation();
  3815. }
  3816. return {
  3817. errMsg: 'enableCompass:ok'
  3818. }
  3819. }
  3820. function getNetworkType () {
  3821. return {
  3822. errMsg: 'getNetworkType:ok',
  3823. networkType: NETWORK_TYPES[plus.networkinfo.getCurrentType()]
  3824. }
  3825. }
  3826. let beaconUpdateState = false;
  3827. function onBeaconUpdate () {
  3828. if (!beaconUpdateState) {
  3829. plus.ibeacon.onBeaconUpdate(function (data) {
  3830. publish('onBeaconUpdated', data);
  3831. });
  3832. beaconUpdateState = true;
  3833. }
  3834. }
  3835. let beaconServiceChangeState = false;
  3836. function onBeaconServiceChange () {
  3837. if (!beaconServiceChangeState) {
  3838. plus.ibeacon.onBeaconServiceChange(function (data) {
  3839. publish('onBeaconServiceChange', data);
  3840. publish('onBeaconServiceChanged', data);
  3841. });
  3842. beaconServiceChangeState = true;
  3843. }
  3844. }
  3845. function getBeacons (params, callbackId) {
  3846. plus.ibeacon.getBeacons({
  3847. success: (result) => {
  3848. invoke$1(callbackId, {
  3849. errMsg: 'getBeacons:ok',
  3850. beacons: result.beacons
  3851. });
  3852. },
  3853. fail: (error) => {
  3854. invoke$1(callbackId, {
  3855. errMsg: 'getBeacons:fail:' + error.message
  3856. });
  3857. }
  3858. });
  3859. }
  3860. function startBeaconDiscovery ({
  3861. uuids,
  3862. ignoreBluetoothAvailable = false
  3863. }, callbackId) {
  3864. plus.ibeacon.startBeaconDiscovery({
  3865. uuids,
  3866. ignoreBluetoothAvailable,
  3867. success: (result) => {
  3868. invoke$1(callbackId, {
  3869. errMsg: 'startBeaconDiscovery:ok',
  3870. beacons: result.beacons
  3871. });
  3872. },
  3873. fail: (error) => {
  3874. invoke$1(callbackId, {
  3875. errMsg: 'startBeaconDiscovery:fail:' + error.message
  3876. });
  3877. }
  3878. });
  3879. }
  3880. function stopBeaconDiscovery (params, callbackId) {
  3881. plus.ibeacon.stopBeaconDiscovery({
  3882. success: (result) => {
  3883. invoke$1(callbackId, Object.assign(result, {
  3884. errMsg: 'stopBeaconDiscovery:ok'
  3885. }));
  3886. },
  3887. fail: (error) => {
  3888. invoke$1(callbackId, {
  3889. errMsg: 'stopBeaconDiscovery:fail:' + error.message
  3890. });
  3891. }
  3892. });
  3893. }
  3894. function makePhoneCall$1 ({
  3895. phoneNumber
  3896. } = {}) {
  3897. plus.device.dial(phoneNumber);
  3898. return {
  3899. errMsg: 'makePhoneCall:ok'
  3900. }
  3901. }
  3902. const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version) < 6;
  3903. const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in';
  3904. const ANI_DURATION = 300;
  3905. const ANI_CLOSE = downgrade ? 'slide-out-right' : 'pop-out';
  3906. const TITLEBAR_HEIGHT = 44;
  3907. const ON_REACH_BOTTOM_DISTANCE = 50;
  3908. const VIEW_WEBVIEW_PATH = '_www/__uniappview.html';
  3909. const V_FOR = 'f';
  3910. const V_IF = 'i';
  3911. const V_ELSE_IF = 'e';
  3912. const V_SHOW = 'v-show';
  3913. const B_CLASS = 'c';
  3914. const B_STYLE = 's';
  3915. const S_CLASS = 'sc';
  3916. const callbacks$1 = {};
  3917. const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE';
  3918. // 简单处理 view 层与 service 层的通知系统
  3919. /**
  3920. * 消费 view 层通知
  3921. */
  3922. function consumePlusMessage (type, args) {
  3923. // 处理 web-view 组件发送的通知
  3924. if (type === WEB_INVOKE_APPSERVICE) {
  3925. publish(WEB_INVOKE_APPSERVICE, args.data, args.webviewIds);
  3926. return true
  3927. }
  3928. const callback = callbacks$1[type];
  3929. if (callback) {
  3930. callback(args);
  3931. if (!callback.keepAlive) {
  3932. delete callbacks$1[type];
  3933. }
  3934. return true
  3935. }
  3936. return false
  3937. }
  3938. /**
  3939. * 注册 view 层通知 service 层事件处理
  3940. */
  3941. function registerPlusMessage (type, callback, keepAlive = true) {
  3942. if (callbacks$1[type]) {
  3943. return console.warn(`${type} 已注册:` + (callbacks$1[type].toString()))
  3944. }
  3945. callback.keepAlive = !!keepAlive;
  3946. callbacks$1[type] = callback;
  3947. }
  3948. const SCAN_ID = '__UNIAPP_SCAN';
  3949. const SCAN_PATH = '_www/__uniappscan.html';
  3950. const MESSAGE_TYPE = 'scanCode';
  3951. function scanCode ({
  3952. onlyFromCamera = false,
  3953. scanType
  3954. }, callbackId) {
  3955. const barcode = plus.barcode;
  3956. const SCAN_TYPES = {
  3957. qrCode: [
  3958. barcode.QR,
  3959. barcode.AZTEC,
  3960. barcode.MAXICODE
  3961. ],
  3962. barCode: [
  3963. barcode.EAN13,
  3964. barcode.EAN8,
  3965. barcode.UPCA,
  3966. barcode.UPCE,
  3967. barcode.CODABAR,
  3968. barcode.CODE128,
  3969. barcode.CODE39,
  3970. barcode.CODE93,
  3971. barcode.ITF,
  3972. barcode.RSS14,
  3973. barcode.RSSEXPANDED
  3974. ],
  3975. datamatrix: [barcode.DATAMATRIX],
  3976. pdf417: [barcode.PDF417]
  3977. };
  3978. const SCAN_MAPS = {
  3979. [barcode.QR]: 'QR_CODE',
  3980. [barcode.EAN13]: 'EAN_13',
  3981. [barcode.EAN8]: 'EAN_8',
  3982. [barcode.DATAMATRIX]: 'DATA_MATRIX',
  3983. [barcode.UPCA]: 'UPC_A',
  3984. [barcode.UPCE]: 'UPC_E',
  3985. [barcode.CODABAR]: 'CODABAR',
  3986. [barcode.CODE39]: 'CODE_39',
  3987. [barcode.CODE93]: 'CODE_93',
  3988. [barcode.CODE128]: 'CODE_128',
  3989. [barcode.ITF]: 'CODE_25',
  3990. [barcode.PDF417]: 'PDF_417',
  3991. [barcode.AZTEC]: 'AZTEC',
  3992. [barcode.RSS14]: 'RSS_14',
  3993. [barcode.RSSEXPANDED]: 'RSSEXPANDED'
  3994. };
  3995. const statusBarStyle = getStatusBarStyle();
  3996. const isDark = statusBarStyle !== 'light';
  3997. let result;
  3998. let filters = [];
  3999. if (Array.isArray(scanType) && scanType.length) {
  4000. scanType.forEach(type => { // 暂不考虑去重
  4001. const types = SCAN_TYPES[type];
  4002. if (types) {
  4003. filters = filters.concat(types);
  4004. }
  4005. });
  4006. }
  4007. if (!filters.length) {
  4008. filters = filters.concat(SCAN_TYPES.qrCode).concat(SCAN_TYPES.barCode).concat(SCAN_TYPES.datamatrix).concat(
  4009. SCAN_TYPES.pdf417);
  4010. }
  4011. const buttons = [];
  4012. if (!onlyFromCamera) {
  4013. buttons.push({
  4014. float: 'right',
  4015. text: '相册',
  4016. fontSize: '17px',
  4017. width: '60px',
  4018. onclick: function () {
  4019. plus.gallery.pick(file => {
  4020. barcode.scan(file, (type, code) => {
  4021. if (isDark) {
  4022. plus.navigator.setStatusBarStyle('isDark');
  4023. }
  4024. result = {
  4025. type,
  4026. code
  4027. };
  4028. webview.close('auto');
  4029. }, () => {
  4030. plus.nativeUI.toast('识别失败');
  4031. }, filters);
  4032. }, err => {
  4033. if (err.code !== 12) {
  4034. plus.nativeUI.toast('选择失败');
  4035. }
  4036. }, {
  4037. multiple: false,
  4038. system: false
  4039. });
  4040. }
  4041. });
  4042. }
  4043. const webview = plus.webview.create(SCAN_PATH, SCAN_ID, {
  4044. titleNView: {
  4045. autoBackButton: true,
  4046. type: 'float',
  4047. backgroundColor: 'rgba(0,0,0,0)',
  4048. titleColor: '#ffffff',
  4049. titleText: '扫码',
  4050. titleSize: '17px',
  4051. buttons
  4052. },
  4053. popGesture: 'close',
  4054. backButtonAutoControl: 'close'
  4055. }, {
  4056. __uniapp_type: 'scan',
  4057. __uniapp_dark: isDark,
  4058. __uniapp_scan_type: filters,
  4059. 'uni-app': 'none'
  4060. });
  4061. const waiting = plus.nativeUI.showWaiting();
  4062. webview.addEventListener('titleUpdate', () => {
  4063. webview.show(ANI_SHOW, ANI_DURATION, () => {
  4064. waiting.close();
  4065. });
  4066. });
  4067. webview.addEventListener('close', () => {
  4068. if (result) {
  4069. invoke$1(callbackId, {
  4070. result: result.code,
  4071. scanType: SCAN_MAPS[result.type] || '',
  4072. charSet: 'utf8',
  4073. path: '',
  4074. errMsg: 'scanCode:ok'
  4075. });
  4076. } else {
  4077. invoke$1(callbackId, {
  4078. errMsg: 'scanCode:fail cancel'
  4079. });
  4080. }
  4081. consumePlusMessage(MESSAGE_TYPE);
  4082. });
  4083. if (isDark) { // 状态栏前景色
  4084. plus.navigator.setStatusBarStyle('light');
  4085. webview.addEventListener('popGesture', ({
  4086. type,
  4087. result
  4088. }) => {
  4089. if (type === 'start') {
  4090. plus.navigator.setStatusBarStyle('dark');
  4091. } else if (type === 'end' && !result) {
  4092. plus.navigator.setStatusBarStyle('light');
  4093. }
  4094. });
  4095. }
  4096. registerPlusMessage(MESSAGE_TYPE, function (res) {
  4097. if (res && 'code' in res) {
  4098. result = res;
  4099. }
  4100. }, false);
  4101. }
  4102. var webview = /*#__PURE__*/Object.freeze({
  4103. __proto__: null,
  4104. SCAN_ID: SCAN_ID,
  4105. SCAN_PATH: SCAN_PATH,
  4106. scanCode: scanCode
  4107. });
  4108. let plus_;
  4109. let weex_;
  4110. let BroadcastChannel_;
  4111. function getRuntime () {
  4112. return typeof window === 'object' && typeof navigator === 'object' && typeof document === 'object' ? 'webview' : 'v8'
  4113. }
  4114. function getPageId () {
  4115. return plus_.webview.currentWebview().id
  4116. }
  4117. let channel;
  4118. let globalEvent;
  4119. const callbacks$2 = {};
  4120. function onPlusMessage (res) {
  4121. const message = res.data && res.data.__message;
  4122. if (!message || !message.__page) {
  4123. return
  4124. }
  4125. const pageId = message.__page;
  4126. const callback = callbacks$2[pageId];
  4127. callback && callback(message);
  4128. if (!message.keep) {
  4129. delete callbacks$2[pageId];
  4130. }
  4131. }
  4132. function addEventListener (pageId, callback) {
  4133. if (getRuntime() === 'v8') {
  4134. if (BroadcastChannel_) {
  4135. channel && channel.close();
  4136. channel = new BroadcastChannel_(getPageId());
  4137. channel.onmessage = onPlusMessage;
  4138. } else if (!globalEvent) {
  4139. globalEvent = weex_.requireModule('globalEvent');
  4140. globalEvent.addEventListener('plusMessage', onPlusMessage);
  4141. }
  4142. } else {
  4143. window.__plusMessage = onPlusMessage;
  4144. }
  4145. callbacks$2[pageId] = callback;
  4146. }
  4147. class Page {
  4148. constructor (webview) {
  4149. this.webview = webview;
  4150. }
  4151. sendMessage (data) {
  4152. const message = {
  4153. __message: {
  4154. data
  4155. }
  4156. };
  4157. const id = this.webview.id;
  4158. if (BroadcastChannel_) {
  4159. const channel = new BroadcastChannel_(id);
  4160. channel.postMessage(message);
  4161. } else {
  4162. plus_.webview.postMessageToUniNView(message, id);
  4163. }
  4164. }
  4165. close () {
  4166. this.webview.close();
  4167. }
  4168. }
  4169. function showPage ({
  4170. context = {},
  4171. url,
  4172. data = {},
  4173. style = {},
  4174. onMessage,
  4175. onClose
  4176. }) {
  4177. // eslint-disable-next-line
  4178. plus_ = context.plus || plus;
  4179. // eslint-disable-next-line
  4180. weex_ = context.weex || (typeof weex === 'object' ? weex : null);
  4181. // eslint-disable-next-line
  4182. BroadcastChannel_ = context.BroadcastChannel || (typeof BroadcastChannel === 'object' ? BroadcastChannel : null);
  4183. const titleNView = {
  4184. autoBackButton: true,
  4185. titleSize: '17px'
  4186. };
  4187. const pageId = `page${Date.now()}`;
  4188. style = Object.assign({}, style);
  4189. if (style.titleNView !== false && style.titleNView !== 'none') {
  4190. style.titleNView = Object.assign(titleNView, style.titleNView);
  4191. }
  4192. const defaultStyle = {
  4193. top: 0,
  4194. bottom: 0,
  4195. usingComponents: {},
  4196. popGesture: 'close',
  4197. scrollIndicator: 'none',
  4198. animationType: 'pop-in',
  4199. animationDuration: 200,
  4200. uniNView: {
  4201. path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`,
  4202. defaultFontSize: plus_.screen.resolutionWidth / 20,
  4203. viewport: plus_.screen.resolutionWidth
  4204. }
  4205. };
  4206. style = Object.assign(defaultStyle, style);
  4207. const page = plus_.webview.create('', pageId, style, {
  4208. extras: {
  4209. from: getPageId(),
  4210. runtime: getRuntime(),
  4211. data,
  4212. useGlobalEvent: !BroadcastChannel_
  4213. }
  4214. });
  4215. page.addEventListener('close', onClose);
  4216. addEventListener(pageId, message => {
  4217. if (typeof onMessage === 'function') {
  4218. onMessage(message.data);
  4219. }
  4220. if (!message.keep) {
  4221. page.close('auto');
  4222. }
  4223. });
  4224. page.show(style.animationType, style.animationDuration);
  4225. return new Page(page)
  4226. }
  4227. function getStatusBarStyle$1 () {
  4228. let style = plus.navigator.getStatusBarStyle();
  4229. if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
  4230. style = 'light';
  4231. } else if (style === 'UIStatusBarStyleDefault') {
  4232. style = 'dark';
  4233. }
  4234. return style
  4235. }
  4236. function scanCode$1 (options, callbackId) {
  4237. const statusBarStyle = getStatusBarStyle$1();
  4238. const isDark = statusBarStyle !== 'light';
  4239. let result;
  4240. const page = showPage({
  4241. url: '__uniappscan',
  4242. data: {
  4243. scanType: options.scanType
  4244. },
  4245. style: {
  4246. animationType: options.animationType || 'pop-in',
  4247. titleNView: {
  4248. autoBackButton: true,
  4249. type: 'float',
  4250. titleText: options.titleText || '扫码',
  4251. titleColor: '#ffffff',
  4252. backgroundColor: 'rgba(0,0,0,0)',
  4253. buttons: !options.onlyFromCamera ? [{
  4254. text: options.albumText || '相册',
  4255. fontSize: '17px',
  4256. width: '60px',
  4257. onclick: () => {
  4258. page.sendMessage({
  4259. type: 'gallery'
  4260. });
  4261. }
  4262. }] : []
  4263. },
  4264. popGesture: 'close',
  4265. backButtonAutoControl: 'close'
  4266. },
  4267. onMessage ({
  4268. event,
  4269. detail
  4270. }) {
  4271. result = detail;
  4272. if (event === 'marked') {
  4273. result.errMsg = 'scanCode:ok';
  4274. } else {
  4275. result.errMsg = 'scanCode:fail ' + detail.message;
  4276. }
  4277. },
  4278. onClose () {
  4279. if (isDark) {
  4280. plus.navigator.setStatusBarStyle('dark');
  4281. }
  4282. invoke$1(callbackId, result || {
  4283. errMsg: 'scanCode:fail cancel'
  4284. });
  4285. }
  4286. });
  4287. if (isDark) {
  4288. plus.navigator.setStatusBarStyle('light');
  4289. page.webview.addEventListener('popGesture', ({
  4290. type,
  4291. result
  4292. }) => {
  4293. if (type === 'start') {
  4294. plus.navigator.setStatusBarStyle('dark');
  4295. } else if (type === 'end' && !result) {
  4296. plus.navigator.setStatusBarStyle('light');
  4297. }
  4298. });
  4299. }
  4300. }
  4301. var weex$1 = /*#__PURE__*/Object.freeze({
  4302. __proto__: null,
  4303. scanCode: scanCode$1
  4304. });
  4305. function scanCode$2 (...array) {
  4306. const api = __uniConfig.nvueCompiler !== 'weex' ? weex$1 : webview;
  4307. return api.scanCode(...array)
  4308. }
  4309. function checkIsSupportFaceID () {
  4310. const platform = plus.os.name.toLowerCase();
  4311. if (platform !== 'ios') {
  4312. return false
  4313. }
  4314. const faceID = requireNativePlugin('faceID');
  4315. return !!(faceID && faceID.isSupport())
  4316. }
  4317. function checkIsSupportFingerPrint () {
  4318. return !!(plus.fingerprint && plus.fingerprint.isSupport())
  4319. }
  4320. function checkIsSupportSoterAuthentication () {
  4321. const supportMode = [];
  4322. if (checkIsSupportFingerPrint()) {
  4323. supportMode.push('fingerPrint');
  4324. }
  4325. if (checkIsSupportFaceID()) {
  4326. supportMode.push('facial');
  4327. }
  4328. return {
  4329. supportMode,
  4330. errMsg: 'checkIsSupportSoterAuthentication:ok'
  4331. }
  4332. }
  4333. function checkIsSoterEnrolledInDevice ({
  4334. checkAuthMode
  4335. } = {}) {
  4336. if (checkAuthMode === 'fingerPrint') {
  4337. if (checkIsSupportFingerPrint()) {
  4338. const isEnrolled = plus.fingerprint.isKeyguardSecure() && plus.fingerprint.isEnrolledFingerprints();
  4339. return {
  4340. isEnrolled,
  4341. errMsg: 'checkIsSoterEnrolledInDevice:ok'
  4342. }
  4343. }
  4344. return {
  4345. isEnrolled: false,
  4346. errMsg: 'checkIsSoterEnrolledInDevice:fail not support'
  4347. }
  4348. } else if (checkAuthMode === 'facial') {
  4349. if (checkIsSupportFaceID()) {
  4350. const faceID = requireNativePlugin('faceID');
  4351. const isEnrolled = faceID && faceID.isKeyguardSecure() && faceID.isEnrolledFaceID();
  4352. return {
  4353. isEnrolled,
  4354. errMsg: 'checkIsSoterEnrolledInDevice:ok'
  4355. }
  4356. }
  4357. return {
  4358. isEnrolled: false,
  4359. errMsg: 'checkIsSoterEnrolledInDevice:fail not support'
  4360. }
  4361. }
  4362. return {
  4363. isEnrolled: false,
  4364. errMsg: 'checkIsSoterEnrolledInDevice:fail not support'
  4365. }
  4366. }
  4367. function startSoterAuthentication ({
  4368. requestAuthModes,
  4369. challenge = false,
  4370. authContent
  4371. } = {}, callbackId) {
  4372. /*
  4373. 以手机不支持facial未录入fingerPrint为例
  4374. requestAuthModes:['facial','fingerPrint']时,微信小程序返回值里的authMode为"fingerPrint"
  4375. requestAuthModes:['fingerPrint','facial']时,微信小程序返回值里的authMode为"fingerPrint"
  4376. 即先过滤不支持的方式之后再判断是否录入
  4377. 微信小程序errCode(从企业号开发者中心查到如下文档):
  4378. 0:识别成功 'startSoterAuthentication:ok'
  4379. 90001:本设备不支持SOTER 'startSoterAuthentication:fail not support soter'
  4380. 90002:用户未授权微信使用该生物认证接口 注:APP端暂不支持
  4381. 90003:请求使用的生物认证方式不支持 'startSoterAuthentication:fail no corresponding mode'
  4382. 90004:未传入challenge或challenge长度过长(最长512字符)注:APP端暂不支持
  4383. 90005:auth_content长度超过限制(最长42个字符)注:微信小程序auth_content指纹识别时无效果,faceID暂未测试
  4384. 90007:内部错误 'startSoterAuthentication:fail auth key update error'
  4385. 90008:用户取消授权 'startSoterAuthentication:fail cancel'
  4386. 90009:识别失败 'startSoterAuthentication:fail'
  4387. 90010:重试次数过多被冻结 'startSoterAuthentication:fail authenticate freeze. please try again later'
  4388. 90011:用户未录入所选识别方式 'startSoterAuthentication:fail no fingerprint enrolled'
  4389. */
  4390. const supportMode = checkIsSupportSoterAuthentication().supportMode;
  4391. if (supportMode.length === 0) {
  4392. return {
  4393. authMode: supportMode[0] || 'fingerPrint',
  4394. errCode: 90001,
  4395. errMsg: 'startSoterAuthentication:fail'
  4396. }
  4397. }
  4398. const supportRequestAuthMode = [];
  4399. requestAuthModes.map((item, index) => {
  4400. if (supportMode.indexOf(item) > -1) {
  4401. supportRequestAuthMode.push(item);
  4402. }
  4403. });
  4404. if (supportRequestAuthMode.length === 0) {
  4405. return {
  4406. authMode: supportRequestAuthMode[0] || 'fingerPrint',
  4407. errCode: 90003,
  4408. errMsg: 'startSoterAuthentication:fail no corresponding mode'
  4409. }
  4410. }
  4411. const enrolledRequestAuthMode = [];
  4412. supportRequestAuthMode.map((item, index) => {
  4413. const checked = checkIsSoterEnrolledInDevice({
  4414. checkAuthMode: item
  4415. }).isEnrolled;
  4416. if (checked) {
  4417. enrolledRequestAuthMode.push(item);
  4418. }
  4419. });
  4420. if (enrolledRequestAuthMode.length === 0) {
  4421. return {
  4422. authMode: supportRequestAuthMode[0],
  4423. errCode: 90011,
  4424. errMsg: `startSoterAuthentication:fail no ${supportRequestAuthMode[0]} enrolled`
  4425. }
  4426. }
  4427. const realAuthMode = enrolledRequestAuthMode[0];
  4428. if (realAuthMode === 'fingerPrint') {
  4429. if (plus.os.name.toLowerCase() === 'android') {
  4430. plus.nativeUI.showWaiting(authContent || '指纹识别中...').onclose = function () {
  4431. plus.fingerprint.cancel();
  4432. };
  4433. }
  4434. plus.fingerprint.authenticate(() => {
  4435. plus.nativeUI.closeWaiting();
  4436. invoke$1(callbackId, {
  4437. authMode: realAuthMode,
  4438. errCode: 0,
  4439. errMsg: 'startSoterAuthentication:ok'
  4440. });
  4441. }, (e) => {
  4442. switch (e.code) {
  4443. case e.AUTHENTICATE_MISMATCH:
  4444. // 微信小程序没有这个回调,如果要实现此处回调需要多次触发需要用事件publish实现
  4445. // invoke(callbackId, {
  4446. // authMode: realAuthMode,
  4447. // errCode: 90009,
  4448. // errMsg: 'startSoterAuthentication:fail'
  4449. // })
  4450. break
  4451. case e.AUTHENTICATE_OVERLIMIT:
  4452. // 微信小程序在第一次重试次数超限时安卓IOS返回不一致,安卓端会返回次数超过限制(errCode: 90010),IOS端会返回认证失败(errCode: 90009)。APP-IOS实际运行时不会次数超限,超过指定次数之后会弹出输入密码的界面
  4453. plus.nativeUI.closeWaiting();
  4454. invoke$1(callbackId, {
  4455. authMode: realAuthMode,
  4456. errCode: 90010,
  4457. errMsg: 'startSoterAuthentication:fail authenticate freeze. please try again later'
  4458. });
  4459. break
  4460. case e.CANCEL:
  4461. plus.nativeUI.closeWaiting();
  4462. invoke$1(callbackId, {
  4463. authMode: realAuthMode,
  4464. errCode: 90008,
  4465. errMsg: 'startSoterAuthentication:fail cancel'
  4466. });
  4467. break
  4468. default:
  4469. plus.nativeUI.closeWaiting();
  4470. invoke$1(callbackId, {
  4471. authMode: realAuthMode,
  4472. errCode: 90007,
  4473. errMsg: 'startSoterAuthentication:fail'
  4474. });
  4475. break
  4476. }
  4477. }, {
  4478. message: authContent
  4479. });
  4480. } else if (realAuthMode === 'facial') {
  4481. const faceID = requireNativePlugin('faceID');
  4482. faceID.authenticate({
  4483. message: authContent
  4484. }, (e) => {
  4485. if (e.type === 'success' && e.code === 0) {
  4486. invoke$1(callbackId, {
  4487. authMode: realAuthMode,
  4488. errCode: 0,
  4489. errMsg: 'startSoterAuthentication:ok'
  4490. });
  4491. } else {
  4492. switch (e.code) {
  4493. case 4:
  4494. invoke$1(callbackId, {
  4495. authMode: realAuthMode,
  4496. errCode: 90009,
  4497. errMsg: 'startSoterAuthentication:fail'
  4498. });
  4499. break
  4500. case 5:
  4501. invoke$1(callbackId, {
  4502. authMode: realAuthMode,
  4503. errCode: 90010,
  4504. errMsg: 'startSoterAuthentication:fail authenticate freeze. please try again later'
  4505. });
  4506. break
  4507. case 6:
  4508. invoke$1(callbackId, {
  4509. authMode: realAuthMode,
  4510. errCode: 90008,
  4511. errMsg: 'startSoterAuthentication:fail cancel'
  4512. });
  4513. break
  4514. default:
  4515. invoke$1(callbackId, {
  4516. authMode: realAuthMode,
  4517. errCode: 90007,
  4518. errMsg: 'startSoterAuthentication:fail'
  4519. });
  4520. break
  4521. }
  4522. }
  4523. });
  4524. }
  4525. }
  4526. const TABBAR_HEIGHT = 50;
  4527. const isIOS$1 = plus.os.name === 'iOS';
  4528. let config;
  4529. /**
  4530. * tabbar显示状态
  4531. */
  4532. let visible = true;
  4533. let tabBar;
  4534. /**
  4535. * 设置角标
  4536. * @param {string} type
  4537. * @param {number} index
  4538. * @param {string} text
  4539. */
  4540. function setTabBarBadge$1 (type, index, text) {
  4541. if (!tabBar) {
  4542. return
  4543. }
  4544. if (type === 'none') {
  4545. tabBar.hideTabBarRedDot({
  4546. index
  4547. });
  4548. tabBar.removeTabBarBadge({
  4549. index
  4550. });
  4551. } else if (type === 'text') {
  4552. tabBar.setTabBarBadge({
  4553. index,
  4554. text
  4555. });
  4556. } else if (type === 'redDot') {
  4557. tabBar.showTabBarRedDot({
  4558. index
  4559. });
  4560. }
  4561. }
  4562. /**
  4563. * 动态设置 tabBar 某一项的内容
  4564. */
  4565. function setTabBarItem$1 (index, text, iconPath, selectedIconPath) {
  4566. const item = {
  4567. index
  4568. };
  4569. if (text !== undefined) {
  4570. item.text = text;
  4571. }
  4572. if (iconPath) {
  4573. item.iconPath = getRealPath$1(iconPath);
  4574. }
  4575. if (selectedIconPath) {
  4576. item.selectedIconPath = getRealPath$1(selectedIconPath);
  4577. }
  4578. tabBar && tabBar.setTabBarItem(item);
  4579. }
  4580. /**
  4581. * 动态设置 tabBar 的整体样式
  4582. * @param {Object} style 样式
  4583. */
  4584. function setTabBarStyle$1 (style) {
  4585. tabBar && tabBar.setTabBarStyle(style);
  4586. }
  4587. /**
  4588. * 隐藏 tabBar
  4589. * @param {boolean} animation 是否需要动画效果
  4590. */
  4591. function hideTabBar$1 (animation) {
  4592. visible = false;
  4593. tabBar && tabBar.hideTabBar({
  4594. animation
  4595. });
  4596. }
  4597. /**
  4598. * 显示 tabBar
  4599. * @param {boolean} animation 是否需要动画效果
  4600. */
  4601. function showTabBar$1 (animation) {
  4602. visible = true;
  4603. tabBar && tabBar.showTabBar({
  4604. animation
  4605. });
  4606. }
  4607. const maskClickCallback = [];
  4608. var tabBar$1 = {
  4609. id: '0',
  4610. init (options, clickCallback) {
  4611. if (options && options.list.length) {
  4612. config = options;
  4613. }
  4614. try {
  4615. tabBar = requireNativePlugin('uni-tabview');
  4616. } catch (error) {
  4617. console.log(`uni.requireNativePlugin("uni-tabview") error ${error}`);
  4618. }
  4619. tabBar.onMaskClick(() => {
  4620. maskClickCallback.forEach((callback) => {
  4621. callback();
  4622. });
  4623. });
  4624. tabBar && tabBar.onClick(({ index }) => {
  4625. clickCallback(config.list[index], index);
  4626. });
  4627. tabBar && tabBar.onMidButtonClick(() => {
  4628. publish('onTabBarMidButtonTap', {});
  4629. });
  4630. },
  4631. indexOf (page) {
  4632. const itemLength = config && config.list && config.list.length;
  4633. if (itemLength) {
  4634. for (let i = 0; i < itemLength; i++) {
  4635. if (
  4636. config.list[i].pagePath === page ||
  4637. config.list[i].pagePath === `${page}.html`
  4638. ) {
  4639. return i
  4640. }
  4641. }
  4642. }
  4643. return -1
  4644. },
  4645. switchTab (page) {
  4646. const index = this.indexOf(page);
  4647. if (index >= 0) {
  4648. tabBar && tabBar.switchSelect({
  4649. index
  4650. });
  4651. return true
  4652. }
  4653. return false
  4654. },
  4655. setTabBarBadge: setTabBarBadge$1,
  4656. setTabBarItem: setTabBarItem$1,
  4657. setTabBarStyle: setTabBarStyle$1,
  4658. hideTabBar: hideTabBar$1,
  4659. showTabBar: showTabBar$1,
  4660. append (webview) {
  4661. tabBar && tabBar.append({
  4662. id: webview.id
  4663. }, ({ code }) => {
  4664. if (code !== 0) {
  4665. // console.log('tab append error')
  4666. setTimeout(() => {
  4667. this.append(webview);
  4668. }, 20);
  4669. }
  4670. });
  4671. },
  4672. get visible () {
  4673. return visible
  4674. },
  4675. get height () {
  4676. return (config && config.height ? parseFloat(config.height) : TABBAR_HEIGHT) + plus.navigator.getSafeAreaInsets().deviceBottom
  4677. },
  4678. // tabBar是否遮挡内容区域
  4679. get cover () {
  4680. const array = ['extralight', 'light', 'dark'];
  4681. return isIOS$1 && array.indexOf(config.blurEffect) >= 0
  4682. },
  4683. setStyle ({ mask }) {
  4684. tabBar.setMask({
  4685. color: mask
  4686. });
  4687. },
  4688. addEventListener (name, callback) {
  4689. maskClickCallback.push(callback);
  4690. },
  4691. removeEventListener (name, callback) {
  4692. const callbackIndex = maskClickCallback.indexOf(callback);
  4693. maskClickCallback.splice(callbackIndex, 1);
  4694. }
  4695. };
  4696. function getSystemInfoSync () {
  4697. return callApiSync(getSystemInfo, Object.create(null), 'getSystemInfo', 'getSystemInfoSync')
  4698. }
  4699. function getSystemInfo () {
  4700. const platform = plus.os.name.toLowerCase();
  4701. const ios = platform === 'ios';
  4702. const {
  4703. screenWidth,
  4704. screenHeight
  4705. } = getScreenInfo();
  4706. const statusBarHeight = getStatusbarHeight();
  4707. let safeAreaInsets;
  4708. const titleNView = {
  4709. height: 0,
  4710. cover: false
  4711. };
  4712. const webview = getLastWebview();
  4713. if (webview) {
  4714. let style = webview.getStyle();
  4715. style = style && style.titleNView;
  4716. if (style && style.type && style.type !== 'none') {
  4717. titleNView.height = style.type === 'transparent' ? 0 : (statusBarHeight + TITLEBAR_HEIGHT);
  4718. titleNView.cover = style.type === 'transparent' || style.type === 'float';
  4719. }
  4720. safeAreaInsets = webview.getSafeAreaInsets();
  4721. } else {
  4722. safeAreaInsets = plus.navigator.getSafeAreaInsets();
  4723. }
  4724. const tabBarView = {
  4725. height: 0,
  4726. cover: false
  4727. };
  4728. if (isTabBarPage()) {
  4729. tabBarView.height = tabBar$1.visible ? tabBar$1.height : 0;
  4730. tabBarView.cover = tabBar$1.cover;
  4731. }
  4732. const windowTop = titleNView.cover ? titleNView.height : 0;
  4733. const windowBottom = tabBarView.cover ? tabBarView.height : 0;
  4734. let windowHeight = screenHeight - titleNView.height - tabBarView.height;
  4735. let windowHeightReal = screenHeight - (titleNView.cover ? 0 : titleNView.height) - (tabBarView.cover ? 0 : tabBarView.height);
  4736. const windowWidth = screenWidth;
  4737. if ((!tabBarView.height || tabBarView.cover) && !safeAreaInsets.bottom && safeAreaInsets.deviceBottom) {
  4738. windowHeight -= safeAreaInsets.deviceBottom;
  4739. windowHeightReal -= safeAreaInsets.deviceBottom;
  4740. }
  4741. safeAreaInsets = ios ? safeAreaInsets : {
  4742. left: 0,
  4743. right: 0,
  4744. top: titleNView.height && !titleNView.cover ? 0 : statusBarHeight,
  4745. bottom: 0
  4746. };
  4747. const safeArea = {
  4748. left: safeAreaInsets.left,
  4749. right: windowWidth - safeAreaInsets.right,
  4750. top: safeAreaInsets.top,
  4751. bottom: windowHeightReal - safeAreaInsets.bottom,
  4752. width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
  4753. height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
  4754. };
  4755. return {
  4756. errMsg: 'getSystemInfo:ok',
  4757. brand: plus.device.vendor,
  4758. model: plus.device.model,
  4759. pixelRatio: plus.screen.scale,
  4760. screenWidth,
  4761. screenHeight,
  4762. windowWidth,
  4763. windowHeight,
  4764. statusBarHeight,
  4765. language: plus.os.language,
  4766. system: plus.os.version,
  4767. version: plus.runtime.innerVersion,
  4768. fontSizeSetting: '',
  4769. platform,
  4770. SDKVersion: '',
  4771. windowTop,
  4772. windowBottom,
  4773. safeArea,
  4774. safeAreaInsets: {
  4775. top: safeAreaInsets.top,
  4776. right: safeAreaInsets.right,
  4777. bottom: safeAreaInsets.bottom,
  4778. left: safeAreaInsets.left
  4779. }
  4780. }
  4781. }
  4782. function vibrateLong () {
  4783. plus.device.vibrate(400);
  4784. return {
  4785. errMsg: 'vibrateLong:ok'
  4786. }
  4787. }
  4788. function vibrateShort () {
  4789. plus.device.vibrate(15);
  4790. return {
  4791. errMsg: 'vibrateShort:ok'
  4792. }
  4793. }
  4794. const SAVED_DIR = 'uniapp_save';
  4795. const SAVE_PATH = `_doc/${SAVED_DIR}`;
  4796. const REGEX_FILENAME = /^.*[/]/;
  4797. function getSavedFileDir (success, fail) {
  4798. fail = fail || function () {};
  4799. plus.io.requestFileSystem(plus.io.PRIVATE_DOC, fs => { // 请求_doc fs
  4800. fs.root.getDirectory(SAVED_DIR, { // 获取文件保存目录对象
  4801. create: true
  4802. }, dir => {
  4803. success(dir);
  4804. }, err => {
  4805. fail('目录[' + SAVED_DIR + ']创建失败' + err.message);
  4806. });
  4807. }, err => {
  4808. fail('目录[_doc]读取失败' + err.message);
  4809. });
  4810. }
  4811. function saveFile ({
  4812. tempFilePath
  4813. } = {}, callbackId) {
  4814. let fileName = tempFilePath.replace(REGEX_FILENAME, '');
  4815. if (fileName) {
  4816. let extName = '';
  4817. if (~fileName.indexOf('.')) {
  4818. extName = '.' + fileName.split('.').pop();
  4819. }
  4820. fileName = (+new Date()) + '' + extName;
  4821. plus.io.resolveLocalFileSystemURL(getRealPath$1(tempFilePath), entry => { // 读取临时文件 FileEntry
  4822. getSavedFileDir(dir => {
  4823. entry.copyTo(dir, fileName, () => { // 复制临时文件 FileEntry,为了避免把相册里的文件删除,使用 copy,微信中是要删除临时文件的
  4824. const savedFilePath = SAVE_PATH + '/' + fileName;
  4825. invoke$1(callbackId, {
  4826. errMsg: 'saveFile:ok',
  4827. savedFilePath
  4828. });
  4829. }, err => {
  4830. invoke$1(callbackId, {
  4831. errMsg: 'saveFile:fail 保存文件[' + tempFilePath +
  4832. '] copyTo 失败:' + err.message
  4833. });
  4834. });
  4835. }, message => {
  4836. invoke$1(callbackId, {
  4837. errMsg: 'saveFile:fail ' + message
  4838. });
  4839. });
  4840. }, err => {
  4841. invoke$1(callbackId, {
  4842. errMsg: 'saveFile:fail 文件[' + tempFilePath + ']读取失败' + err.message
  4843. });
  4844. });
  4845. } else {
  4846. return {
  4847. errMsg: 'saveFile:fail 文件名[' + tempFilePath + ']不存在'
  4848. }
  4849. }
  4850. }
  4851. function getSavedFileList (options, callbackId) {
  4852. getSavedFileDir(entry => {
  4853. var reader = entry.createReader();
  4854. var fileList = [];
  4855. reader.readEntries(entries => {
  4856. if (entries && entries.length) {
  4857. entries.forEach(entry => {
  4858. entry.getMetadata(meta => {
  4859. fileList.push({
  4860. filePath: plus.io.convertAbsoluteFileSystem(entry.fullPath),
  4861. createTime: meta.modificationTime.getTime(),
  4862. size: meta.size
  4863. });
  4864. if (fileList.length === entries.length) {
  4865. invoke$1(callbackId, {
  4866. errMsg: 'getSavedFileList:ok',
  4867. fileList
  4868. });
  4869. }
  4870. }, error => {
  4871. invoke$1(callbackId, {
  4872. errMsg: 'getSavedFileList:fail ' + error.message
  4873. });
  4874. }, false);
  4875. });
  4876. } else {
  4877. invoke$1(callbackId, {
  4878. errMsg: 'getSavedFileList:ok',
  4879. fileList
  4880. });
  4881. }
  4882. }, error => {
  4883. invoke$1(callbackId, {
  4884. errMsg: 'getSavedFileList:fail ' + error.message
  4885. });
  4886. });
  4887. }, message => {
  4888. invoke$1(callbackId, {
  4889. errMsg: 'getSavedFileList:fail ' + message
  4890. });
  4891. });
  4892. }
  4893. function getFileInfo ({
  4894. filePath,
  4895. digestAlgorithm = 'md5'
  4896. } = {}, callbackId) {
  4897. // TODO 计算文件摘要
  4898. plus.io.resolveLocalFileSystemURL(getRealPath$1(filePath), entry => {
  4899. entry.getMetadata(meta => {
  4900. invoke$1(callbackId, {
  4901. errMsg: 'getFileInfo:ok',
  4902. size: meta.size,
  4903. digestAlgorithm: ''
  4904. });
  4905. }, err => {
  4906. invoke$1(callbackId, {
  4907. errMsg: 'getFileInfo:fail 文件[' +
  4908. filePath +
  4909. '] getMetadata 失败:' + err.message
  4910. });
  4911. });
  4912. }, err => {
  4913. invoke$1(callbackId, {
  4914. errMsg: 'getFileInfo:fail 文件[' + filePath + ']读取失败:' + err.message
  4915. });
  4916. });
  4917. }
  4918. function getSavedFileInfo ({
  4919. filePath
  4920. } = {}, callbackId) {
  4921. plus.io.resolveLocalFileSystemURL(getRealPath$1(filePath), entry => {
  4922. entry.getMetadata(meta => {
  4923. invoke$1(callbackId, {
  4924. createTime: meta.modificationTime.getTime(),
  4925. size: meta.size,
  4926. errMsg: 'getSavedFileInfo:ok'
  4927. });
  4928. }, error => {
  4929. invoke$1(callbackId, {
  4930. errMsg: 'getSavedFileInfo:fail ' + error.message
  4931. });
  4932. }, false);
  4933. }, () => {
  4934. invoke$1(callbackId, {
  4935. errMsg: 'getSavedFileInfo:fail file not find'
  4936. });
  4937. });
  4938. }
  4939. function removeSavedFile ({
  4940. filePath
  4941. } = {}, callbackId) {
  4942. plus.io.resolveLocalFileSystemURL(getRealPath$1(filePath), entry => {
  4943. entry.remove(() => {
  4944. invoke$1(callbackId, {
  4945. errMsg: 'removeSavedFile:ok'
  4946. });
  4947. }, err => {
  4948. invoke$1(callbackId, {
  4949. errMsg: 'removeSavedFile:fail 文件[' + filePath + ']删除失败:' + err.message
  4950. });
  4951. });
  4952. }, () => {
  4953. invoke$1(callbackId, {
  4954. errMsg: 'removeSavedFile:fail file not find'
  4955. });
  4956. });
  4957. }
  4958. function openDocument$1 ({
  4959. filePath,
  4960. fileType
  4961. } = {}, callbackId) {
  4962. plus.io.resolveLocalFileSystemURL(getRealPath$1(filePath), entry => {
  4963. plus.runtime.openFile(getRealPath$1(filePath));
  4964. invoke$1(callbackId, {
  4965. errMsg: 'openDocument:ok'
  4966. });
  4967. }, err => {
  4968. invoke$1(callbackId, {
  4969. errMsg: 'openDocument:fail 文件[' + filePath + ']读取失败:' + err.message
  4970. });
  4971. });
  4972. }
  4973. const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html';
  4974. const MESSAGE_TYPE$1 = 'chooseLocation';
  4975. function chooseLocation$1 (params, callbackId) {
  4976. const statusBarStyle = plus.navigator.getStatusBarStyle();
  4977. const webview = plus.webview.create(
  4978. CHOOSE_LOCATION_PATH,
  4979. MAP_ID, {
  4980. titleNView: {
  4981. autoBackButton: true,
  4982. backgroundColor: '#000000',
  4983. titleColor: '#ffffff',
  4984. titleText: '选择位置',
  4985. titleSize: '17px',
  4986. buttons: [{
  4987. float: 'right',
  4988. text: '完成',
  4989. fontSize: '17px',
  4990. width: '60px',
  4991. onclick: function () {
  4992. webview.evalJS('__chooseLocationConfirm__()');
  4993. }
  4994. }]
  4995. },
  4996. popGesture: 'close',
  4997. scrollIndicator: 'none'
  4998. }, {
  4999. __uniapp_type: 'map',
  5000. __uniapp_statusbar_style: statusBarStyle,
  5001. 'uni-app': 'none'
  5002. }
  5003. );
  5004. if (statusBarStyle === 'dark') {
  5005. plus.navigator.setStatusBarStyle('light');
  5006. webview.addEventListener('popGesture', ({
  5007. type,
  5008. result
  5009. }) => {
  5010. if (type === 'start') {
  5011. plus.navigator.setStatusBarStyle('dark');
  5012. } else if (type === 'end' && !result) {
  5013. plus.navigator.setStatusBarStyle('light');
  5014. }
  5015. });
  5016. }
  5017. let index = 0;
  5018. const onShow = function () {
  5019. index++;
  5020. if (index === 2) {
  5021. webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`);
  5022. }
  5023. };
  5024. webview.addEventListener('loaded', onShow);
  5025. webview.show('slide-in-bottom', ANI_DURATION, onShow);
  5026. let result;
  5027. webview.addEventListener('close', () => {
  5028. if (result) {
  5029. invoke$1(callbackId, {
  5030. name: result.poiname,
  5031. address: result.poiaddress,
  5032. latitude: result.latlng.lat,
  5033. longitude: result.latlng.lng,
  5034. errMsg: 'chooseLocation:ok'
  5035. });
  5036. } else {
  5037. consumePlusMessage(MESSAGE_TYPE$1);
  5038. invoke$1(callbackId, {
  5039. errMsg: 'chooseLocation:fail cancel'
  5040. });
  5041. }
  5042. });
  5043. registerPlusMessage(MESSAGE_TYPE$1, function (res) {
  5044. if (res && 'latlng' in res) {
  5045. result = res;
  5046. }
  5047. }, false);
  5048. }
  5049. var webview$1 = /*#__PURE__*/Object.freeze({
  5050. __proto__: null,
  5051. chooseLocation: chooseLocation$1
  5052. });
  5053. function getStatusBarStyle$2 () {
  5054. let style = plus.navigator.getStatusBarStyle();
  5055. if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
  5056. style = 'light';
  5057. } else if (style === 'UIStatusBarStyleDefault') {
  5058. style = 'dark';
  5059. }
  5060. return style
  5061. }
  5062. function chooseLocation$2 (options, callbackId) {
  5063. const statusBarStyle = getStatusBarStyle$2();
  5064. const isDark = statusBarStyle !== 'light';
  5065. let result;
  5066. const page = showPage({
  5067. url: '__uniappchooselocation',
  5068. data: options,
  5069. style: {
  5070. animationType: options.animationType || 'slide-in-bottom',
  5071. titleNView: false,
  5072. popGesture: 'close',
  5073. scrollIndicator: 'none'
  5074. },
  5075. onMessage ({
  5076. event,
  5077. detail
  5078. }) {
  5079. if (event === 'selected') {
  5080. result = detail;
  5081. result.errMsg = 'chooseLocation:ok';
  5082. }
  5083. },
  5084. onClose () {
  5085. if (isDark) {
  5086. plus.navigator.setStatusBarStyle('dark');
  5087. }
  5088. invoke$1(callbackId, result || {
  5089. errMsg: 'chooseLocation:fail cancel'
  5090. });
  5091. }
  5092. });
  5093. if (isDark) {
  5094. plus.navigator.setStatusBarStyle('light');
  5095. page.webview.addEventListener('popGesture', ({
  5096. type,
  5097. result
  5098. }) => {
  5099. if (type === 'start') {
  5100. plus.navigator.setStatusBarStyle('dark');
  5101. } else if (type === 'end' && !result) {
  5102. plus.navigator.setStatusBarStyle('light');
  5103. }
  5104. });
  5105. }
  5106. }
  5107. var weex$2 = /*#__PURE__*/Object.freeze({
  5108. __proto__: null,
  5109. chooseLocation: chooseLocation$2
  5110. });
  5111. function chooseLocation$3 (...array) {
  5112. const api = __uniConfig.nvueCompiler !== 'weex' ? weex$2 : webview$1;
  5113. return api.chooseLocation(...array)
  5114. }
  5115. function getLocationSuccess (type, position, callbackId) {
  5116. const coords = position.coords;
  5117. if (type !== position.coordsType) {
  5118. if (process.env.NODE_ENV !== 'production') {
  5119. console.log(
  5120. `UNIAPP[location]:before[${position.coordsType}][lng:${
  5121. coords.longitude
  5122. },lat:${coords.latitude}]`
  5123. );
  5124. }
  5125. let coordArray;
  5126. if (type === 'wgs84') {
  5127. coordArray = gcj02towgs84(coords.longitude, coords.latitude);
  5128. } else if (type === 'gcj02') {
  5129. coordArray = wgs84togcj02(coords.longitude, coords.latitude);
  5130. }
  5131. if (coordArray) {
  5132. coords.longitude = coordArray[0];
  5133. coords.latitude = coordArray[1];
  5134. if (process.env.NODE_ENV !== 'production') {
  5135. console.log(
  5136. `UNIAPP[location]:after[${type}][lng:${coords.longitude},lat:${
  5137. coords.latitude
  5138. }]`
  5139. );
  5140. }
  5141. }
  5142. }
  5143. invoke$1(callbackId, {
  5144. type,
  5145. altitude: coords.altitude || 0,
  5146. latitude: coords.latitude,
  5147. longitude: coords.longitude,
  5148. speed: coords.speed,
  5149. accuracy: coords.accuracy,
  5150. address: position.address,
  5151. errMsg: 'getLocation:ok'
  5152. });
  5153. }
  5154. function getLocation$1 ({
  5155. type = 'wgs84',
  5156. geocode = false,
  5157. altitude = false
  5158. } = {}, callbackId) {
  5159. plus.geolocation.getCurrentPosition(
  5160. position => {
  5161. getLocationSuccess(type, position, callbackId);
  5162. },
  5163. e => {
  5164. // 坐标地址解析失败
  5165. if (e.code === 1501) {
  5166. getLocationSuccess(type, e, callbackId);
  5167. return
  5168. }
  5169. invoke$1(callbackId, {
  5170. errMsg: 'getLocation:fail ' + e.message
  5171. });
  5172. }, {
  5173. geocode: geocode,
  5174. enableHighAccuracy: altitude
  5175. }
  5176. );
  5177. }
  5178. const OPEN_LOCATION_PATH = '_www/__uniappopenlocation.html';
  5179. function openLocation$1 (params) {
  5180. const statusBarStyle = plus.navigator.getStatusBarStyle();
  5181. const webview = plus.webview.create(
  5182. OPEN_LOCATION_PATH,
  5183. MAP_ID, {
  5184. titleNView: {
  5185. autoBackButton: true,
  5186. titleColor: '#ffffff',
  5187. titleText: '',
  5188. titleSize: '17px',
  5189. type: 'transparent'
  5190. },
  5191. popGesture: 'close',
  5192. scrollIndicator: 'none'
  5193. }, {
  5194. __uniapp_type: 'map',
  5195. __uniapp_statusbar_style: statusBarStyle,
  5196. 'uni-app': 'none'
  5197. }
  5198. );
  5199. if (statusBarStyle === 'light') {
  5200. plus.navigator.setStatusBarStyle('dark');
  5201. webview.addEventListener('popGesture', ({
  5202. type,
  5203. result
  5204. }) => {
  5205. if (type === 'start') {
  5206. plus.navigator.setStatusBarStyle('light');
  5207. } else if (type === 'end' && !result) {
  5208. plus.navigator.setStatusBarStyle('dark');
  5209. }
  5210. });
  5211. }
  5212. webview.show(ANI_SHOW, ANI_DURATION, () => {
  5213. webview.evalJS(`__openLocation__(${JSON.stringify(params)})`);
  5214. });
  5215. return {
  5216. errMsg: 'openLocation:ok'
  5217. }
  5218. }
  5219. var webview$2 = /*#__PURE__*/Object.freeze({
  5220. __proto__: null,
  5221. openLocation: openLocation$1
  5222. });
  5223. function openLocation$2 (data, callbackId) {
  5224. showPage({
  5225. url: '__uniappopenlocation',
  5226. data,
  5227. style: {
  5228. titleNView: {
  5229. type: 'transparent'
  5230. },
  5231. popGesture: 'close',
  5232. backButtonAutoControl: 'close'
  5233. },
  5234. onClose () {
  5235. invoke$1(callbackId, {
  5236. errMsg: 'openLocation:fail cancel'
  5237. });
  5238. }
  5239. });
  5240. return {
  5241. errMsg: 'openLocation:ok'
  5242. }
  5243. }
  5244. var weex$3 = /*#__PURE__*/Object.freeze({
  5245. __proto__: null,
  5246. openLocation: openLocation$2
  5247. });
  5248. function openLocation$3 (...array) {
  5249. const api = __uniConfig.nvueCompiler !== 'weex' ? weex$3 : webview$2;
  5250. return api.openLocation(...array)
  5251. }
  5252. const RECORD_TIME = 60 * 60 * 1000;
  5253. let recorder;
  5254. let recordTimeout;
  5255. function startRecord (args, callbackId) {
  5256. recorder && recorder.stop();
  5257. recorder = plus.audio.getRecorder();
  5258. recorder.record({
  5259. filename: '_doc/audio/',
  5260. format: 'aac'
  5261. }, (res) => {
  5262. invoke$1(callbackId, {
  5263. errMsg: 'startRecord:ok',
  5264. tempFilePath: res
  5265. });
  5266. }, (res) => {
  5267. invoke$1(callbackId, {
  5268. errMsg: 'startRecord:fail'
  5269. });
  5270. });
  5271. recordTimeout = setTimeout(() => {
  5272. recorder.stop();
  5273. recorder = false;
  5274. }, RECORD_TIME);
  5275. }
  5276. function stopRecord () {
  5277. if (recorder) {
  5278. recordTimeout && clearTimeout(recordTimeout);
  5279. recorder.stop();
  5280. return {
  5281. errMsg: 'stopRecord:ok'
  5282. }
  5283. }
  5284. return {
  5285. errMsg: 'stopRecord:fail'
  5286. }
  5287. }
  5288. let player;
  5289. let playerFilePath;
  5290. let playerStatus;
  5291. function playVoice ({
  5292. filePath
  5293. } = {}, callbackId) {
  5294. if (player && playerFilePath === filePath && playerStatus === 'pause') { // 如果是当前音频被暂停,则继续播放
  5295. playerStatus = 'play';
  5296. player.play((res) => {
  5297. player = false;
  5298. playerFilePath = false;
  5299. playerStatus = false;
  5300. invoke$1(callbackId, {
  5301. errMsg: 'playVoice:ok'
  5302. });
  5303. });
  5304. return {
  5305. errMsg: 'playVoice:ok'
  5306. }
  5307. }
  5308. if (player) { // 如果存在音频播放,则停止
  5309. player.stop();
  5310. }
  5311. playerFilePath = filePath;
  5312. playerStatus = 'play';
  5313. player = plus.audio.createPlayer(getRealPath$1(filePath));
  5314. // 播放操作成功回调
  5315. player.play((res) => {
  5316. player = false;
  5317. playerFilePath = false;
  5318. playerStatus = false;
  5319. invoke$1(callbackId, {
  5320. errMsg: 'playVoice:ok'
  5321. });
  5322. });
  5323. }
  5324. function pauseVoice () {
  5325. if (player && playerStatus === 'play') {
  5326. player.pause();
  5327. playerStatus = 'pause';
  5328. }
  5329. return {
  5330. errMsg: 'pauseVoice:ok'
  5331. }
  5332. }
  5333. function stopVoice () {
  5334. if (player) {
  5335. player.stop();
  5336. player = false;
  5337. playerFilePath = false;
  5338. playerStatus = false;
  5339. }
  5340. return {
  5341. errMsg: 'stopVoice:ok'
  5342. }
  5343. }
  5344. /**
  5345. * 获取文件信息
  5346. * @param {string} filePath 文件路径
  5347. * @returns {Promise} 文件信息Promise
  5348. */
  5349. function getFileInfo$1 (filePath) {
  5350. return new Promise((resolve, reject) => {
  5351. plus.io.resolveLocalFileSystemURL(filePath, function (entry) {
  5352. entry.getMetadata(function (meta) {
  5353. resolve({
  5354. size: meta.size
  5355. });
  5356. }, reject, false);
  5357. }, reject);
  5358. })
  5359. }
  5360. const invokeChooseImage = function (callbackId, type, sizeType, tempFilePaths = []) {
  5361. if (!tempFilePaths.length) {
  5362. invoke$1(callbackId, {
  5363. code: sizeType,
  5364. errMsg: `chooseImage:${type}`
  5365. });
  5366. return
  5367. }
  5368. var tempFiles = [];
  5369. // plus.zip.compressImage 压缩文件并发调用在iOS端容易出现问题(图像错误、闪退),改为队列执行
  5370. tempFilePaths.reduce((promise, tempFilePath, index, array) => {
  5371. return promise
  5372. .then(() => {
  5373. return getFileInfo$1(tempFilePath)
  5374. })
  5375. .then(fileInfo => {
  5376. var size = fileInfo.size;
  5377. // 压缩阈值 0.5 兆
  5378. var threshold = 1024 * 1024 * 0.5;
  5379. // 判断是否需要压缩
  5380. if ((sizeType.indexOf('compressed') >= 0 && sizeType.indexOf('original') < 0) || (((
  5381. sizeType.indexOf(
  5382. 'compressed') < 0 && sizeType.indexOf('original') < 0) || (sizeType
  5383. .indexOf('compressed') >= 0 && sizeType.indexOf(
  5384. 'original') >= 0)) && size > threshold)) {
  5385. return new Promise((resolve, reject) => {
  5386. var dstPath = TEMP_PATH + '/compressed/' + Date.now() + (
  5387. tempFilePath.match(/\.\S+$/) || [''])[0];
  5388. plus.nativeUI.showWaiting();
  5389. plus.zip.compressImage({
  5390. src: tempFilePath,
  5391. dst: dstPath,
  5392. overwrite: true
  5393. }, () => {
  5394. resolve(dstPath);
  5395. }, (error) => {
  5396. reject(error);
  5397. });
  5398. })
  5399. .then(dstPath => {
  5400. array[index] = tempFilePath = dstPath;
  5401. return getFileInfo$1(tempFilePath)
  5402. })
  5403. .then(fileInfo => {
  5404. return tempFiles.push({
  5405. path: tempFilePath,
  5406. size: fileInfo.size
  5407. })
  5408. })
  5409. }
  5410. return tempFiles.push({
  5411. path: tempFilePath,
  5412. size: size
  5413. })
  5414. })
  5415. }, Promise.resolve())
  5416. .then(() => {
  5417. plus.nativeUI.closeWaiting();
  5418. invoke$1(callbackId, {
  5419. errMsg: `chooseImage:${type}`,
  5420. tempFilePaths,
  5421. tempFiles
  5422. });
  5423. }).catch(() => {
  5424. plus.nativeUI.closeWaiting();
  5425. invoke$1(callbackId, {
  5426. errMsg: `chooseImage:${type}`
  5427. });
  5428. });
  5429. };
  5430. const openCamera = function (callbackId, sizeType) {
  5431. const camera = plus.camera.getCamera();
  5432. camera.captureImage(e => invokeChooseImage(callbackId, 'ok', sizeType, [e]),
  5433. e => invokeChooseImage(callbackId, 'fail', 1), {
  5434. filename: TEMP_PATH + '/camera/',
  5435. resolution: 'high'
  5436. });
  5437. };
  5438. const openAlbum = function (callbackId, sizeType, count) {
  5439. // TODO Android 需要拷贝到 temp 目录
  5440. plus.gallery.pick(e => invokeChooseImage(callbackId, 'ok', sizeType, e.files.map(file => {
  5441. return file
  5442. })), e => {
  5443. invokeChooseImage(callbackId, 'fail', 2);
  5444. }, {
  5445. maximum: count,
  5446. multiple: true,
  5447. system: false,
  5448. filename: TEMP_PATH + '/gallery/'
  5449. });
  5450. };
  5451. function chooseImage$1 ({
  5452. count = 9,
  5453. sizeType = ['original', 'compressed'],
  5454. sourceType = ['album', 'camera']
  5455. } = {}, callbackId) {
  5456. let fallback = true;
  5457. if (sourceType.length === 1) {
  5458. if (sourceType[0] === 'album') {
  5459. fallback = false;
  5460. openAlbum(callbackId, sizeType, count);
  5461. } else if (sourceType[0] === 'camera') {
  5462. fallback = false;
  5463. openCamera(callbackId, sizeType);
  5464. }
  5465. }
  5466. if (fallback) {
  5467. plus.nativeUI.actionSheet({
  5468. cancel: '取消',
  5469. buttons: [{
  5470. title: '拍摄'
  5471. }, {
  5472. title: '从手机相册选择'
  5473. }]
  5474. }, (e) => {
  5475. switch (e.index) {
  5476. case 0:
  5477. invokeChooseImage(callbackId, 'fail', 0);
  5478. break
  5479. case 1:
  5480. openCamera(callbackId, sizeType);
  5481. break
  5482. case 2:
  5483. openAlbum(callbackId, sizeType, count);
  5484. break
  5485. }
  5486. });
  5487. }
  5488. }
  5489. const invokeChooseVideo = function (callbackId, type, tempFilePath = '') {
  5490. const callbackResult = {
  5491. errMsg: `chooseVideo:${type}`,
  5492. tempFilePath: tempFilePath,
  5493. duration: 0,
  5494. size: 0,
  5495. height: 0,
  5496. width: 0
  5497. };
  5498. if (type !== 'ok') {
  5499. invoke$1(callbackId, callbackResult);
  5500. return
  5501. }
  5502. plus.io.getVideoInfo({
  5503. filePath: tempFilePath,
  5504. success (videoInfo) {
  5505. callbackResult.size = videoInfo.size;
  5506. callbackResult.duration = videoInfo.duration;
  5507. callbackResult.width = videoInfo.width;
  5508. callbackResult.height = videoInfo.height;
  5509. invoke$1(callbackId, callbackResult);
  5510. },
  5511. fail () {
  5512. invoke$1(callbackId, callbackResult);
  5513. },
  5514. complete () {
  5515. invoke$1(callbackId, callbackResult);
  5516. }
  5517. });
  5518. };
  5519. const openCamera$1 = function (callbackId, maxDuration, cameraIndex) {
  5520. const camera = plus.camera.getCamera();
  5521. camera.startVideoCapture(e => invokeChooseVideo(callbackId, 'ok', e), e => invokeChooseVideo(
  5522. callbackId, 'fail'), {
  5523. index: cameraIndex,
  5524. videoMaximumDuration: maxDuration,
  5525. filename: TEMP_PATH + '/camera/'
  5526. });
  5527. };
  5528. const openAlbum$1 = function (callbackId) {
  5529. plus.gallery.pick(e => {
  5530. invokeChooseVideo(callbackId, 'ok', e);
  5531. }, e => invokeChooseVideo(callbackId, 'fail'), {
  5532. filter: 'video',
  5533. system: false,
  5534. filename: TEMP_PATH + '/gallery/'
  5535. });
  5536. };
  5537. function chooseVideo$1 ({
  5538. sourceType = ['album', 'camera'],
  5539. maxDuration = 60,
  5540. camera = 'back'
  5541. } = {}, callbackId) {
  5542. let fallback = true;
  5543. const cameraIndex = (camera === 'front') ? 2 : 1;
  5544. if (sourceType.length === 1) {
  5545. if (sourceType[0] === 'album') {
  5546. fallback = false;
  5547. openAlbum$1(callbackId);
  5548. } else if (sourceType[0] === 'camera') {
  5549. fallback = false;
  5550. openCamera$1(callbackId, maxDuration, cameraIndex);
  5551. }
  5552. }
  5553. if (fallback) {
  5554. plus.nativeUI.actionSheet({
  5555. cancel: '取消',
  5556. buttons: [{
  5557. title: '拍摄'
  5558. }, {
  5559. title: '从手机相册选择'
  5560. }]
  5561. }, e => {
  5562. switch (e.index) {
  5563. case 0:
  5564. invokeChooseVideo(callbackId, 'fail');
  5565. break
  5566. case 1:
  5567. openCamera$1(callbackId, maxDuration, cameraIndex);
  5568. break
  5569. case 2:
  5570. openAlbum$1(callbackId);
  5571. break
  5572. }
  5573. });
  5574. }
  5575. }
  5576. function compressImage ({
  5577. src,
  5578. quality
  5579. }, callbackId) {
  5580. var dst = TEMP_PATH + '/compressed/' + Date.now() + (src.match(/\.\S+$/) || [''])[0];
  5581. plus.zip.compressImage({
  5582. src,
  5583. dst,
  5584. quality
  5585. }, () => {
  5586. invoke$1(callbackId, {
  5587. errMsg: 'compressImage:ok',
  5588. tempFilePath: dst
  5589. });
  5590. }, () => {
  5591. invoke$1(callbackId, {
  5592. errMsg: 'compressImage:fail'
  5593. });
  5594. });
  5595. }
  5596. function getImageInfo$1 ({
  5597. src
  5598. } = {}, callbackId) {
  5599. // fixed by hxy
  5600. plus.io.getImageInfo({
  5601. src,
  5602. success (imageInfo) {
  5603. invoke$1(callbackId, {
  5604. errMsg: 'getImageInfo:ok',
  5605. ...imageInfo
  5606. });
  5607. },
  5608. fail () {
  5609. invoke$1(callbackId, {
  5610. errMsg: 'getImageInfo:fail'
  5611. });
  5612. }
  5613. });
  5614. }
  5615. function previewImagePlus ({
  5616. current = 0,
  5617. background = '#000000',
  5618. indicator = 'number',
  5619. loop = false,
  5620. urls,
  5621. longPressActions
  5622. } = {}) {
  5623. urls = urls.map(url => getRealPath$1(url));
  5624. const index = Number(current);
  5625. if (isNaN(index)) {
  5626. current = urls.indexOf(getRealPath$1(current));
  5627. current = current < 0 ? 0 : current;
  5628. } else {
  5629. current = index;
  5630. }
  5631. plus.nativeUI.previewImage(urls, {
  5632. current,
  5633. background,
  5634. indicator,
  5635. loop,
  5636. onLongPress: function (res) {
  5637. let itemList = [];
  5638. let itemColor = '';
  5639. let title = '';
  5640. const hasLongPressActions = longPressActions && longPressActions.callbackId;
  5641. if (!hasLongPressActions) {
  5642. itemList = ['保存相册'];
  5643. itemColor = '#000000';
  5644. title = '';
  5645. } else {
  5646. itemList = longPressActions.itemList ? longPressActions.itemList : [];
  5647. itemColor = longPressActions.itemColor ? longPressActions.itemColor : '#000000';
  5648. title = longPressActions.title ? longPressActions.title : '';
  5649. }
  5650. const options = {
  5651. buttons: itemList.map(item => ({
  5652. title: item,
  5653. color: itemColor
  5654. })),
  5655. cancel: '取消'
  5656. };
  5657. if (title) {
  5658. options.title = title;
  5659. }
  5660. // if (plus.os.name === 'iOS') {
  5661. // options.cancel = '取消'
  5662. // }
  5663. plus.nativeUI.actionSheet(options, (e) => {
  5664. if (e.index > 0) {
  5665. if (hasLongPressActions) {
  5666. publish(longPressActions.callbackId, {
  5667. errMsg: 'showActionSheet:ok',
  5668. tapIndex: e.index - 1,
  5669. index: res.index
  5670. });
  5671. return
  5672. }
  5673. plus.gallery.save(res.url, function (GallerySaveEvent) {
  5674. plus.nativeUI.toast('保存图片到相册成功');
  5675. });
  5676. } else if (hasLongPressActions) {
  5677. publish(longPressActions.callbackId, {
  5678. errMsg: 'showActionSheet:fail cancel'
  5679. });
  5680. }
  5681. });
  5682. }
  5683. });
  5684. return {
  5685. errMsg: 'previewImage:ok'
  5686. }
  5687. }
  5688. let recorder$1;
  5689. let recordTimeout$1;
  5690. const publishRecorderStateChange = (state, res = {}) => {
  5691. publish('onRecorderStateChange', Object.assign({
  5692. state
  5693. }, res));
  5694. };
  5695. const Recorder = {
  5696. start ({
  5697. duration = 60000,
  5698. sampleRate,
  5699. numberOfChannels,
  5700. encodeBitRate,
  5701. format = 'mp3',
  5702. frameSize,
  5703. audioSource = 'auto'
  5704. }, callbackId) {
  5705. if (recorder$1) {
  5706. return publishRecorderStateChange('start')
  5707. }
  5708. recorder$1 = plus.audio.getRecorder();
  5709. recorder$1.record({
  5710. format,
  5711. samplerate: sampleRate,
  5712. filename: TEMP_PATH + '/recorder/'
  5713. }, res => publishRecorderStateChange('stop', {
  5714. tempFilePath: res
  5715. }), err => publishRecorderStateChange('error', {
  5716. errMsg: err.message
  5717. }));
  5718. recordTimeout$1 = setTimeout(() => {
  5719. Recorder.stop();
  5720. }, duration);
  5721. publishRecorderStateChange('start');
  5722. },
  5723. stop () {
  5724. if (recorder$1) {
  5725. recorder$1.stop();
  5726. recorder$1 = false;
  5727. recordTimeout$1 && clearTimeout(recordTimeout$1);
  5728. }
  5729. },
  5730. pause () {
  5731. if (recorder$1) {
  5732. publishRecorderStateChange('error', {
  5733. errMsg: '暂不支持录音pause操作'
  5734. });
  5735. }
  5736. },
  5737. resume () {
  5738. if (recorder$1) {
  5739. publishRecorderStateChange('error', {
  5740. errMsg: '暂不支持录音resume操作'
  5741. });
  5742. }
  5743. }
  5744. };
  5745. function operateRecorder ({
  5746. operationType,
  5747. ...args
  5748. }, callbackId) {
  5749. Recorder[operationType](args);
  5750. return {
  5751. errMsg: 'operateRecorder:ok'
  5752. }
  5753. }
  5754. function saveImageToPhotosAlbum$1 ({
  5755. filePath
  5756. } = {}, callbackId) {
  5757. plus.gallery.save(getRealPath$1(filePath), e => {
  5758. invoke$1(callbackId, {
  5759. errMsg: 'saveImageToPhotosAlbum:ok'
  5760. });
  5761. }, e => {
  5762. invoke$1(callbackId, {
  5763. errMsg: 'saveImageToPhotosAlbum:fail'
  5764. });
  5765. });
  5766. }
  5767. function saveVideoToPhotosAlbum ({
  5768. filePath
  5769. } = {}, callbackId) {
  5770. plus.gallery.save(getRealPath$1(filePath), e => {
  5771. invoke$1(callbackId, {
  5772. errMsg: 'saveVideoToPhotosAlbum:ok'
  5773. });
  5774. }, e => {
  5775. invoke$1(callbackId, {
  5776. errMsg: 'saveVideoToPhotosAlbum:fail'
  5777. });
  5778. });
  5779. }
  5780. let downloadTaskId = 0;
  5781. const downloadTasks = {};
  5782. const publishStateChange = (res) => {
  5783. publish('onDownloadTaskStateChange', res);
  5784. };
  5785. const createDownloadTaskById = function (downloadTaskId, {
  5786. url,
  5787. header
  5788. } = {}) {
  5789. const downloader = plus.downloader.createDownload(url, {
  5790. time: __uniConfig.networkTimeout.downloadFile ? __uniConfig.networkTimeout.downloadFile / 1000 : 120,
  5791. filename: TEMP_PATH + '/download/',
  5792. // 需要与其它平台上的表现保持一致,不走重试的逻辑。
  5793. retry: 0,
  5794. retryInterval: 0
  5795. }, (download, statusCode) => {
  5796. if (statusCode) {
  5797. publishStateChange({
  5798. downloadTaskId,
  5799. state: 'success',
  5800. tempFilePath: download.filename,
  5801. statusCode
  5802. });
  5803. } else {
  5804. publishStateChange({
  5805. downloadTaskId,
  5806. state: 'fail',
  5807. statusCode
  5808. });
  5809. }
  5810. });
  5811. for (const name in header) {
  5812. if (hasOwn(header, name)) {
  5813. downloader.setRequestHeader(name, header[name]);
  5814. }
  5815. }
  5816. downloader.addEventListener('statechanged', (download, status) => {
  5817. if (download.downloadedSize && download.totalSize) {
  5818. publishStateChange({
  5819. downloadTaskId,
  5820. state: 'progressUpdate',
  5821. progress: parseInt(download.downloadedSize / download.totalSize * 100),
  5822. totalBytesWritten: download.downloadedSize,
  5823. totalBytesExpectedToWrite: download.totalSize
  5824. });
  5825. }
  5826. });
  5827. downloadTasks[downloadTaskId] = downloader;
  5828. downloader.start();
  5829. return {
  5830. downloadTaskId,
  5831. errMsg: 'createDownloadTask:ok'
  5832. }
  5833. };
  5834. function operateDownloadTask ({
  5835. downloadTaskId,
  5836. operationType
  5837. } = {}) {
  5838. const downloadTask = downloadTasks[downloadTaskId];
  5839. if (downloadTask && operationType === 'abort') {
  5840. delete downloadTasks[downloadTaskId];
  5841. downloadTask.abort();
  5842. publishStateChange({
  5843. downloadTaskId,
  5844. state: 'fail',
  5845. errMsg: 'abort'
  5846. });
  5847. return {
  5848. errMsg: 'operateDownloadTask:ok'
  5849. }
  5850. }
  5851. return {
  5852. errMsg: 'operateDownloadTask:fail'
  5853. }
  5854. }
  5855. function createDownloadTask (args) {
  5856. return createDownloadTaskById(++downloadTaskId, args)
  5857. }
  5858. let requestTaskId = 0;
  5859. const requestTasks = {};
  5860. const publishStateChange$1 = res => {
  5861. publish('onRequestTaskStateChange', res);
  5862. delete requestTasks[requestTaskId];
  5863. };
  5864. function createRequestTaskById (requestTaskId, {
  5865. url,
  5866. data,
  5867. header,
  5868. method = 'GET',
  5869. responseType,
  5870. sslVerify = true
  5871. } = {}) {
  5872. const stream = requireNativePlugin('stream');
  5873. const headers = {};
  5874. let abortTimeout;
  5875. let aborted;
  5876. let hasContentType = false;
  5877. for (const name in header) {
  5878. if (!hasContentType && name.toLowerCase() === 'content-type') {
  5879. hasContentType = true;
  5880. headers['Content-Type'] = header[name];
  5881. // TODO 需要重构
  5882. if (method !== 'GET' && header[name].indexOf('application/x-www-form-urlencoded') === 0 && typeof data !==
  5883. 'string' && !(data instanceof ArrayBuffer)) {
  5884. const bodyArray = [];
  5885. for (const key in data) {
  5886. if (hasOwn(data, key)) {
  5887. bodyArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
  5888. }
  5889. }
  5890. data = bodyArray.join('&');
  5891. }
  5892. } else {
  5893. headers[name] = header[name];
  5894. }
  5895. }
  5896. if (!hasContentType && method === 'POST') {
  5897. headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
  5898. }
  5899. const timeout = __uniConfig.networkTimeout.request;
  5900. if (timeout) {
  5901. abortTimeout = setTimeout(() => {
  5902. aborted = true;
  5903. publishStateChange$1({
  5904. requestTaskId,
  5905. state: 'fail',
  5906. statusCode: 0,
  5907. errMsg: 'timeout'
  5908. });
  5909. }, (timeout + 200)); // TODO +200 发消息到原生层有时间开销,以后考虑由原生层回调超时
  5910. }
  5911. const options = {
  5912. method,
  5913. url: url.trim(),
  5914. // weex 官方文档有误,headers 类型实际 object,用 string 类型会无响应
  5915. headers,
  5916. type: responseType === 'arraybuffer' ? 'base64' : 'text',
  5917. // weex 官方文档未说明实际支持 timeout,单位:ms
  5918. timeout: timeout || 6e5,
  5919. // 配置和weex模块内相反
  5920. sslVerify: !sslVerify
  5921. };
  5922. if (method !== 'GET') {
  5923. options.body = data;
  5924. }
  5925. try {
  5926. stream.fetch(options, ({
  5927. ok,
  5928. status,
  5929. data,
  5930. headers
  5931. }) => {
  5932. if (aborted) {
  5933. return
  5934. }
  5935. if (abortTimeout) {
  5936. clearTimeout(abortTimeout);
  5937. }
  5938. const statusCode = status;
  5939. if (statusCode > 0) {
  5940. publishStateChange$1({
  5941. requestTaskId,
  5942. state: 'success',
  5943. data: ok && responseType === 'arraybuffer' ? base64ToArrayBuffer$2(data) : data,
  5944. statusCode,
  5945. header: headers
  5946. });
  5947. } else {
  5948. publishStateChange$1({
  5949. requestTaskId,
  5950. state: 'fail',
  5951. statusCode,
  5952. errMsg: 'abort statusCode:' + statusCode
  5953. });
  5954. }
  5955. });
  5956. requestTasks[requestTaskId] = {
  5957. abort () {
  5958. aborted = true;
  5959. if (abortTimeout) {
  5960. clearTimeout(abortTimeout);
  5961. }
  5962. publishStateChange$1({
  5963. requestTaskId,
  5964. state: 'fail',
  5965. statusCode: 0,
  5966. errMsg: 'abort'
  5967. });
  5968. }
  5969. };
  5970. } catch (e) {
  5971. return {
  5972. requestTaskId,
  5973. errMsg: 'createRequestTask:fail'
  5974. }
  5975. }
  5976. return {
  5977. requestTaskId,
  5978. errMsg: 'createRequestTask:ok'
  5979. }
  5980. }
  5981. function createRequestTask (args) {
  5982. return createRequestTaskById(++requestTaskId, args)
  5983. }
  5984. function operateRequestTask ({
  5985. requestTaskId,
  5986. operationType
  5987. } = {}) {
  5988. const requestTask = requestTasks[requestTaskId];
  5989. if (requestTask && operationType === 'abort') {
  5990. requestTask.abort();
  5991. return {
  5992. errMsg: 'operateRequestTask:ok'
  5993. }
  5994. }
  5995. return {
  5996. errMsg: 'operateRequestTask:fail'
  5997. }
  5998. }
  5999. const socketTasks = {};
  6000. const publishStateChange$2 = (res) => {
  6001. publish('onSocketTaskStateChange', res);
  6002. };
  6003. let socket;
  6004. function getSocket () {
  6005. if (socket) {
  6006. return socket
  6007. }
  6008. socket = requireNativePlugin('uni-webSocket');
  6009. socket.onopen(function (e) {
  6010. publishStateChange$2({
  6011. socketTaskId: e.id,
  6012. state: 'open'
  6013. });
  6014. });
  6015. socket.onmessage(function (e) {
  6016. const data = e.data;
  6017. publishStateChange$2({
  6018. socketTaskId: e.id,
  6019. state: 'message',
  6020. data: typeof data === 'object' ? base64ToArrayBuffer$2(data.base64) : data
  6021. });
  6022. });
  6023. socket.onerror(function (e) {
  6024. publishStateChange$2({
  6025. socketTaskId: e.id,
  6026. state: 'error',
  6027. errMsg: e.data
  6028. });
  6029. });
  6030. socket.onclose(function (e) {
  6031. const socketTaskId = e.id;
  6032. delete socketTasks[socketTaskId];
  6033. publishStateChange$2({
  6034. socketTaskId,
  6035. state: 'close'
  6036. });
  6037. });
  6038. return socket
  6039. }
  6040. const createSocketTaskById = function (socketTaskId, {
  6041. url,
  6042. data,
  6043. header,
  6044. method,
  6045. protocols
  6046. } = {}) {
  6047. const socket = getSocket();
  6048. socket.WebSocket({
  6049. id: socketTaskId,
  6050. url,
  6051. protocol: Array.isArray(protocols) ? protocols.join(',') : protocols
  6052. });
  6053. socketTasks[socketTaskId] = socket;
  6054. return {
  6055. socketTaskId,
  6056. errMsg: 'createSocketTask:ok'
  6057. }
  6058. };
  6059. function createSocketTask (args) {
  6060. return createSocketTaskById(String(Date.now()), args)
  6061. }
  6062. function operateSocketTask (args) {
  6063. const {
  6064. operationType,
  6065. code,
  6066. reason,
  6067. data,
  6068. socketTaskId
  6069. } = unpack(args);
  6070. const socket = socketTasks[socketTaskId];
  6071. if (!socket) {
  6072. return {
  6073. errMsg: 'operateSocketTask:fail'
  6074. }
  6075. }
  6076. switch (operationType) {
  6077. case 'send':
  6078. if (data) {
  6079. socket.send({
  6080. id: socketTaskId,
  6081. data: typeof data === 'object' ? {
  6082. '@type': 'binary',
  6083. base64: arrayBufferToBase64$2(data)
  6084. } : data
  6085. });
  6086. }
  6087. return {
  6088. errMsg: 'operateSocketTask:ok'
  6089. }
  6090. case 'close':
  6091. socket.close({
  6092. id: socketTaskId,
  6093. code,
  6094. reason
  6095. });
  6096. delete socketTasks[socketTaskId];
  6097. return {
  6098. errMsg: 'operateSocketTask:ok'
  6099. }
  6100. }
  6101. return {
  6102. errMsg: 'operateSocketTask:fail'
  6103. }
  6104. }
  6105. let uploadTaskId = 0;
  6106. const uploadTasks = {};
  6107. const publishStateChange$3 = (res) => {
  6108. publish('onUploadTaskStateChange', res);
  6109. };
  6110. const createUploadTaskById = function (uploadTaskId, {
  6111. url,
  6112. filePath,
  6113. name,
  6114. files,
  6115. header,
  6116. formData
  6117. } = {}) {
  6118. const uploader = plus.uploader.createUpload(url, {
  6119. timeout: __uniConfig.networkTimeout.uploadFile ? __uniConfig.networkTimeout.uploadFile / 1000 : 120,
  6120. // 需要与其它平台上的表现保持一致,不走重试的逻辑。
  6121. retry: 0,
  6122. retryInterval: 0
  6123. }, (upload, statusCode) => {
  6124. if (statusCode) {
  6125. publishStateChange$3({
  6126. uploadTaskId,
  6127. state: 'success',
  6128. data: upload.responseText,
  6129. statusCode
  6130. });
  6131. } else {
  6132. publishStateChange$3({
  6133. uploadTaskId,
  6134. state: 'fail',
  6135. data: '',
  6136. statusCode
  6137. });
  6138. }
  6139. delete uploadTasks[uploadTaskId];
  6140. });
  6141. for (const name in header) {
  6142. if (hasOwn(header, name)) {
  6143. uploader.setRequestHeader(name, header[name]);
  6144. }
  6145. }
  6146. for (const name in formData) {
  6147. if (hasOwn(formData, name)) {
  6148. uploader.addData(name, String(formData[name]));
  6149. }
  6150. }
  6151. if (files && files.length) {
  6152. files.forEach(file => {
  6153. uploader.addFile(getRealPath$1(file.uri), {
  6154. key: file.name || 'file'
  6155. });
  6156. });
  6157. } else {
  6158. uploader.addFile(getRealPath$1(filePath), {
  6159. key: name
  6160. });
  6161. }
  6162. uploader.addEventListener('statechanged', (upload, status) => {
  6163. if (upload.uploadedSize && upload.totalSize) {
  6164. publishStateChange$3({
  6165. uploadTaskId,
  6166. state: 'progressUpdate',
  6167. progress: parseInt(upload.uploadedSize / upload.totalSize * 100),
  6168. totalBytesSent: upload.uploadedSize,
  6169. totalBytesExpectedToSend: upload.totalSize
  6170. });
  6171. }
  6172. });
  6173. uploadTasks[uploadTaskId] = uploader;
  6174. uploader.start();
  6175. return {
  6176. uploadTaskId,
  6177. errMsg: 'createUploadTask:ok'
  6178. }
  6179. };
  6180. function operateUploadTask ({
  6181. uploadTaskId,
  6182. operationType
  6183. } = {}) {
  6184. const uploadTask = uploadTasks[uploadTaskId];
  6185. if (uploadTask && operationType === 'abort') {
  6186. delete uploadTasks[uploadTaskId];
  6187. uploadTask.abort();
  6188. publishStateChange$3({
  6189. uploadTaskId,
  6190. state: 'fail',
  6191. errMsg: 'abort'
  6192. });
  6193. return {
  6194. errMsg: 'operateUploadTask:ok'
  6195. }
  6196. }
  6197. return {
  6198. errMsg: 'operateUploadTask:fail'
  6199. }
  6200. }
  6201. function createUploadTask (args) {
  6202. return createUploadTaskById(++uploadTaskId, args)
  6203. }
  6204. const providers = {
  6205. oauth (callback) {
  6206. plus.oauth.getServices(services => {
  6207. const provider = [];
  6208. services.forEach(({
  6209. id
  6210. }) => {
  6211. provider.push(id);
  6212. });
  6213. callback(null, provider);
  6214. }, err => {
  6215. callback(err);
  6216. });
  6217. },
  6218. share (callback) {
  6219. plus.share.getServices(services => {
  6220. const provider = [];
  6221. services.forEach(({
  6222. id
  6223. }) => {
  6224. provider.push(id);
  6225. });
  6226. callback(null, provider);
  6227. }, err => {
  6228. callback(err);
  6229. });
  6230. },
  6231. payment (callback) {
  6232. plus.payment.getChannels(services => {
  6233. const provider = [];
  6234. services.forEach(({
  6235. id
  6236. }) => {
  6237. provider.push(id);
  6238. });
  6239. callback(null, provider);
  6240. }, err => {
  6241. callback(err);
  6242. });
  6243. },
  6244. push (callback) {
  6245. if (typeof weex !== 'undefined' || typeof plus !== 'undefined') {
  6246. callback(null, [plus.push.getClientInfo().id]);
  6247. } else {
  6248. callback(null, []);
  6249. }
  6250. }
  6251. };
  6252. function getProvider$1 ({
  6253. service
  6254. }, callbackId) {
  6255. if (providers[service]) {
  6256. providers[service]((err, provider) => {
  6257. if (err) {
  6258. invoke$1(callbackId, {
  6259. errMsg: 'getProvider:fail:' + err.message
  6260. });
  6261. } else {
  6262. invoke$1(callbackId, {
  6263. errMsg: 'getProvider:ok',
  6264. service,
  6265. provider
  6266. });
  6267. }
  6268. });
  6269. } else {
  6270. invoke$1(callbackId, {
  6271. errMsg: 'getProvider:fail:服务[' + service + ']不支持'
  6272. });
  6273. }
  6274. }
  6275. const loginServices = {};
  6276. const loginByService = (provider, callbackId) => {
  6277. function login () {
  6278. loginServices[provider].login(res => {
  6279. const authResult = res.target.authResult;
  6280. invoke$1(callbackId, {
  6281. code: authResult.code,
  6282. authResult: authResult,
  6283. errMsg: 'login:ok'
  6284. });
  6285. }, err => {
  6286. invoke$1(callbackId, {
  6287. code: err.code,
  6288. errMsg: 'login:fail:' + err.message
  6289. });
  6290. }, provider === 'apple' ? { scope: 'email' } : {});
  6291. }
  6292. // 先注销再登录
  6293. // apple登录logout之后无法重新触发获取email,fullname
  6294. if (provider === 'apple') {
  6295. login();
  6296. } else {
  6297. loginServices[provider].logout(login, login);
  6298. }
  6299. };
  6300. /**
  6301. * 微信登录
  6302. */
  6303. function login (params, callbackId) {
  6304. const provider = params.provider || 'weixin';
  6305. if (loginServices[provider]) {
  6306. loginByService(provider, callbackId);
  6307. } else {
  6308. plus.oauth.getServices(services => {
  6309. loginServices[provider] = services.find(({
  6310. id
  6311. }) => id === provider);
  6312. if (!loginServices[provider]) {
  6313. invoke$1(callbackId, {
  6314. code: '',
  6315. errMsg: 'login:fail:登录服务[' + provider + ']不存在'
  6316. });
  6317. } else {
  6318. loginByService(provider, callbackId);
  6319. }
  6320. }, err => {
  6321. invoke$1(callbackId, {
  6322. code: err.code,
  6323. errMsg: 'login:fail:' + err.message
  6324. });
  6325. });
  6326. }
  6327. }
  6328. function getUserInfo (params, callbackId) {
  6329. const provider = params.provider || 'weixin';
  6330. const loginService = loginServices[provider];
  6331. if (!loginService || !loginService.authResult) {
  6332. return invoke$1(callbackId, {
  6333. errMsg: 'operateWXData:fail:请先调用 uni.login'
  6334. })
  6335. }
  6336. loginService.getUserInfo(res => {
  6337. let userInfo;
  6338. if (provider === 'weixin') {
  6339. const wechatUserInfo = loginService.userInfo;
  6340. userInfo = {
  6341. openId: wechatUserInfo.openid,
  6342. nickName: wechatUserInfo.nickname,
  6343. gender: wechatUserInfo.sex,
  6344. city: wechatUserInfo.city,
  6345. province: wechatUserInfo.province,
  6346. country: wechatUserInfo.country,
  6347. avatarUrl: wechatUserInfo.headimgurl,
  6348. unionId: wechatUserInfo.unionid
  6349. };
  6350. } else if (provider === 'apple') {
  6351. const appleInfo = loginService.appleInfo;
  6352. userInfo = {
  6353. openId: appleInfo.user,
  6354. fullName: appleInfo.fullName,
  6355. email: appleInfo.email,
  6356. authorizationCode: appleInfo.authorizationCode,
  6357. identityToken: appleInfo.identityToken,
  6358. realUserStatus: appleInfo.realUserStatus
  6359. };
  6360. } else {
  6361. loginService.userInfo.openId = loginService.userInfo.openId || loginService.userInfo.openid ||
  6362. loginService.authResult.openid;
  6363. loginService.userInfo.nickName = loginService.userInfo.nickName || loginService.userInfo.nickname;
  6364. loginService.userInfo.avatarUrl = loginService.userInfo.avatarUrl || loginService.userInfo.avatarUrl ||
  6365. loginService.userInfo.headimgurl;
  6366. userInfo = loginService.userInfo;
  6367. }
  6368. const result = {
  6369. errMsg: 'operateWXData:ok'
  6370. };
  6371. if (params.data && params.data.api_name === 'webapi_getuserinfo') {
  6372. result.data = {
  6373. data: JSON.stringify(userInfo),
  6374. rawData: '',
  6375. signature: '',
  6376. encryptedData: '',
  6377. iv: ''
  6378. };
  6379. } else {
  6380. result.userInfo = userInfo;
  6381. }
  6382. invoke$1(callbackId, result);
  6383. }, err => {
  6384. invoke$1(callbackId, {
  6385. errMsg: 'operateWXData:fail:' + err.message
  6386. });
  6387. });
  6388. }
  6389. /**
  6390. * 获取用户信息
  6391. */
  6392. function operateWXData (params, callbackId) {
  6393. switch (params.data.api_name) {
  6394. case 'webapi_getuserinfo':
  6395. getUserInfo(params, callbackId);
  6396. break
  6397. default:
  6398. return {
  6399. errMsg: 'operateWXData:fail'
  6400. }
  6401. }
  6402. }
  6403. function requestPayment (params, callbackId) {
  6404. const provider = params.provider;
  6405. plus.payment.getChannels(services => {
  6406. const service = services.find(({
  6407. id
  6408. }) => id === provider);
  6409. if (!service) {
  6410. invoke$1(callbackId, {
  6411. errMsg: 'requestPayment:fail:支付服务[' + provider + ']不存在'
  6412. });
  6413. } else {
  6414. plus.payment.request(service, params.orderInfo, res => {
  6415. res.errMsg = 'requestPayment:ok';
  6416. invoke$1(callbackId, res);
  6417. }, err => {
  6418. invoke$1(callbackId, {
  6419. errMsg: 'requestPayment:fail:' + err.message
  6420. });
  6421. });
  6422. }
  6423. }, err => {
  6424. invoke$1(callbackId, {
  6425. errMsg: 'requestPayment:fail:' + err.message
  6426. });
  6427. });
  6428. }
  6429. let onPushing;
  6430. let isListening = false;
  6431. let unsubscribe = false;
  6432. function subscribePush (params, callbackId) {
  6433. const clientInfo = plus.push.getClientInfo();
  6434. if (clientInfo) {
  6435. if (!isListening) {
  6436. isListening = true;
  6437. plus.push.addEventListener('receive', msg => {
  6438. if (onPushing && !unsubscribe) {
  6439. publish('onPushMessage', {
  6440. messageId: msg.__UUID__,
  6441. data: msg.payload,
  6442. errMsg: 'onPush:ok'
  6443. });
  6444. }
  6445. });
  6446. }
  6447. unsubscribe = false;
  6448. clientInfo.errMsg = 'subscribePush:ok';
  6449. return clientInfo
  6450. } else {
  6451. return {
  6452. errMsg: 'subscribePush:fail:请确保当前运行环境已包含 push 模块'
  6453. }
  6454. }
  6455. }
  6456. function unsubscribePush (params) {
  6457. unsubscribe = true;
  6458. return {
  6459. errMsg: 'unsubscribePush:ok'
  6460. }
  6461. }
  6462. function onPush () {
  6463. if (!isListening) {
  6464. return {
  6465. errMsg: 'onPush:fail:请先调用 uni.subscribePush'
  6466. }
  6467. }
  6468. if (plus.push.getClientInfo()) {
  6469. onPushing = true;
  6470. return {
  6471. errMsg: 'onPush:ok'
  6472. }
  6473. }
  6474. return {
  6475. errMsg: 'onPush:fail:请确保当前运行环境已包含 push 模块'
  6476. }
  6477. }
  6478. function offPush (params) {
  6479. onPushing = false;
  6480. return {
  6481. errMsg: 'offPush:ok'
  6482. }
  6483. }
  6484. function requireNativePlugin$1 (name) {
  6485. return weex.requireModule(name)
  6486. }
  6487. // 0:图文,1:纯文字,2:纯图片,3:音乐,4:视频,5:小程序
  6488. const TYPES = {
  6489. 0: {
  6490. name: 'web',
  6491. title: '图文'
  6492. },
  6493. 1: {
  6494. name: 'text',
  6495. title: '纯文字'
  6496. },
  6497. 2: {
  6498. name: 'image',
  6499. title: '纯图片'
  6500. },
  6501. 3: {
  6502. name: 'music',
  6503. title: '音乐'
  6504. },
  6505. 4: {
  6506. name: 'video',
  6507. title: '视频'
  6508. },
  6509. 5: {
  6510. name: 'miniProgram',
  6511. title: '小程序'
  6512. }
  6513. };
  6514. const parseParams = (args, callbackId, method) => {
  6515. args.type = args.type || 0;
  6516. let {
  6517. provider,
  6518. type,
  6519. title,
  6520. summary: content,
  6521. href,
  6522. imageUrl,
  6523. mediaUrl: media,
  6524. scene,
  6525. miniProgram
  6526. } = args;
  6527. if (typeof imageUrl === 'string' && imageUrl) {
  6528. imageUrl = getRealPath$1(imageUrl);
  6529. }
  6530. const shareType = TYPES[type + ''];
  6531. if (shareType) {
  6532. const sendMsg = {
  6533. provider,
  6534. type: shareType.name,
  6535. title,
  6536. content,
  6537. href,
  6538. pictures: [imageUrl],
  6539. thumbs: [imageUrl],
  6540. media,
  6541. miniProgram,
  6542. extra: {
  6543. scene
  6544. }
  6545. };
  6546. if (provider === 'weixin' && (type === 1 || type === 2)) {
  6547. delete sendMsg.thumbs;
  6548. }
  6549. return sendMsg
  6550. }
  6551. return '分享参数 type 不正确'
  6552. };
  6553. const sendShareMsg = function (service, params, callbackId, method = 'share') {
  6554. service.send(
  6555. params,
  6556. () => {
  6557. invoke$1(callbackId, {
  6558. errMsg: method + ':ok'
  6559. });
  6560. },
  6561. err => {
  6562. invoke$1(callbackId, {
  6563. errMsg: method + ':fail:' + err.message
  6564. });
  6565. }
  6566. );
  6567. };
  6568. function shareAppMessageDirectly ({
  6569. title,
  6570. path,
  6571. imageUrl,
  6572. useDefaultSnapshot
  6573. }, callbackId) {
  6574. title = title || __uniConfig.appname;
  6575. const goShare = () => {
  6576. share({
  6577. provider: 'weixin',
  6578. type: 0,
  6579. title,
  6580. imageUrl,
  6581. href: path,
  6582. scene: 'WXSceneSession'
  6583. },
  6584. callbackId,
  6585. 'shareAppMessageDirectly'
  6586. );
  6587. };
  6588. if (useDefaultSnapshot) {
  6589. const pages = getCurrentPages();
  6590. const webview = plus.webview.getWebviewById(pages[pages.length - 1].__wxWebviewId__ + '');
  6591. if (webview) {
  6592. const bitmap = new plus.nativeObj.Bitmap();
  6593. webview.draw(
  6594. bitmap,
  6595. () => {
  6596. const fileName = TEMP_PATH + '/share/snapshot.jpg';
  6597. bitmap.save(
  6598. fileName, {
  6599. overwrite: true,
  6600. format: 'jpg'
  6601. },
  6602. () => {
  6603. imageUrl = fileName;
  6604. goShare();
  6605. },
  6606. err => {
  6607. invoke$1(callbackId, {
  6608. errMsg: 'shareAppMessageDirectly:fail:' + err.message
  6609. });
  6610. }
  6611. );
  6612. },
  6613. err => {
  6614. invoke$1(callbackId, {
  6615. errMsg: 'shareAppMessageDirectly:fail:' + err.message
  6616. });
  6617. }
  6618. );
  6619. } else {
  6620. goShare();
  6621. }
  6622. } else {
  6623. goShare();
  6624. }
  6625. }
  6626. function share (params, callbackId, method = 'share') {
  6627. params = parseParams(params);
  6628. if (typeof params === 'string') {
  6629. return invoke$1(callbackId, {
  6630. errMsg: method + ':fail:' + params
  6631. })
  6632. }
  6633. const provider = params.provider;
  6634. plus.share.getServices(
  6635. services => {
  6636. const service = services.find(({
  6637. id
  6638. }) => id === provider);
  6639. if (!service) {
  6640. invoke$1(callbackId, {
  6641. errMsg: method + ':fail:分享服务[' + provider + ']不存在'
  6642. });
  6643. } else {
  6644. if (service.authenticated) {
  6645. sendShareMsg(service, params, callbackId);
  6646. } else {
  6647. service.authorize(
  6648. () => sendShareMsg(service, params, callbackId),
  6649. err => {
  6650. invoke$1(callbackId, {
  6651. errMsg: method + ':fail:' + err.message
  6652. });
  6653. }
  6654. );
  6655. }
  6656. }
  6657. },
  6658. err => {
  6659. invoke$1(callbackId, {
  6660. errMsg: method + ':fail:' + err.message
  6661. });
  6662. }
  6663. );
  6664. }
  6665. function shareWithSystem (params, callbackId, method = 'shareWithSystem') {
  6666. let {
  6667. type,
  6668. imageUrl,
  6669. summary: content,
  6670. href
  6671. } = params;
  6672. type = type || 'text';
  6673. const allowedTypes = ['text', 'image'];
  6674. if (allowedTypes.indexOf(type) < 0) {
  6675. invoke$1(callbackId, {
  6676. errMsg: method + ':fail:分享参数 type 不正确'
  6677. });
  6678. }
  6679. if (typeof imageUrl === 'string' && imageUrl) {
  6680. imageUrl = getRealPath$1(imageUrl);
  6681. }
  6682. plus.share.sendWithSystem({
  6683. type,
  6684. pictures: imageUrl && [imageUrl],
  6685. content,
  6686. href
  6687. }, function (res) {
  6688. invoke$1(callbackId, {
  6689. errMsg: method + ':ok'
  6690. });
  6691. }, function (err) {
  6692. invoke$1(callbackId, {
  6693. errMsg: method + ':fail:' + err.message
  6694. });
  6695. });
  6696. }
  6697. function restoreGlobal (
  6698. newWeex,
  6699. newPlus,
  6700. newSetTimeout,
  6701. newClearTimeout,
  6702. newSetInterval,
  6703. newClearInterval
  6704. ) {
  6705. // 确保部分全局变量 是 app-service 中的
  6706. // 若首页 nvue 初始化比 app-service 快,导致框架处于该 nvue 环境下
  6707. // plus 如果不用 app-service,资源路径会出问题
  6708. // 若首页 nvue 被销毁,如 redirectTo 或 reLaunch,则这些全局功能会损坏
  6709. if (plus !== newPlus) {
  6710. if (process.env.NODE_ENV !== 'production') {
  6711. console.log(`[restoreGlobal][${Date.now()}]`);
  6712. }
  6713. weex = newWeex;
  6714. plus = newPlus;
  6715. plus.navigator.setStatusBarStyle = newSetStatusBarStyle;
  6716. /* eslint-disable no-global-assign */
  6717. setTimeout = newSetTimeout;
  6718. clearTimeout = newClearTimeout;
  6719. setInterval = newSetInterval;
  6720. clearInterval = newClearInterval;
  6721. }
  6722. }
  6723. function wrapper$1 (webview) {
  6724. webview.$processed = true;
  6725. webview.postMessage = function (data) {
  6726. plus.webview.postMessageToUniNView({
  6727. type: 'UniAppSubNVue',
  6728. data
  6729. }, webview.id);
  6730. };
  6731. let callbacks = [];
  6732. webview.onMessage = function (callback) {
  6733. callbacks.push(callback);
  6734. };
  6735. webview.$consumeMessage = function (e) {
  6736. callbacks.forEach(callback => callback(e));
  6737. };
  6738. if (!webview.__uniapp_mask_id) {
  6739. return
  6740. }
  6741. const maskColor = webview.__uniapp_mask;
  6742. const maskWebview = webview.__uniapp_mask_id === '0' ? {
  6743. setStyle ({
  6744. mask
  6745. }) {
  6746. requireNativePlugin$1('uni-tabview').setMask({
  6747. color: mask
  6748. });
  6749. }
  6750. } : plus.webview.getWebviewById(webview.__uniapp_mask_id);
  6751. const oldShow = webview.show;
  6752. const oldHide = webview.hide;
  6753. const oldClose = webview.close;
  6754. const showMask = function () {
  6755. maskWebview.setStyle({
  6756. mask: maskColor
  6757. });
  6758. };
  6759. const closeMask = function () {
  6760. maskWebview.setStyle({
  6761. mask: 'none'
  6762. });
  6763. };
  6764. webview.show = function (...args) {
  6765. showMask();
  6766. return oldShow.apply(webview, args)
  6767. };
  6768. webview.hide = function (...args) {
  6769. closeMask();
  6770. return oldHide.apply(webview, args)
  6771. };
  6772. webview.close = function (...args) {
  6773. closeMask();
  6774. callbacks = [];
  6775. return oldClose.apply(webview, args)
  6776. };
  6777. }
  6778. function getSubNVueById (id) {
  6779. const webview = plus.webview.getWebviewById(id);
  6780. if (webview && !webview.$processed) {
  6781. wrapper$1(webview);
  6782. }
  6783. const oldSetStyle = webview.setStyle;
  6784. var parentWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id);
  6785. webview.setStyle = function (style) {
  6786. if (style && style.mask) {
  6787. parentWebview.setStyle({
  6788. mask: style.mask
  6789. });
  6790. delete style.mask;
  6791. }
  6792. oldSetStyle.call(this, style);
  6793. };
  6794. return webview
  6795. }
  6796. function getCurrentSubNVue () {
  6797. return getSubNVueById(plus.webview.currentWebview().id)
  6798. }
  6799. const callbacks$3 = [];
  6800. // 不使用uni-core/service/platform中的onMethod,避免循环引用
  6801. UniServiceJSBridge.on('api.uniMPNativeEvent', function (res) {
  6802. callbacks$3.forEach(callbackId => {
  6803. invoke$1(callbackId, res.event, res.data);
  6804. });
  6805. });
  6806. function onNativeEventReceive (callbackId) {
  6807. callbacks$3.push(callbackId);
  6808. }
  6809. function sendNativeEvent (event, data, callback) {
  6810. // 实时获取weex module(weex可能会变化,比如首页nvue加速显示时)
  6811. return weex.requireModule('plus').sendNativeEvent(event, data, callback)
  6812. }
  6813. let firstBackTime = 0;
  6814. function quit () {
  6815. if (!firstBackTime) {
  6816. firstBackTime = Date.now();
  6817. plus.nativeUI.toast('再按一次退出应用');
  6818. setTimeout(() => {
  6819. firstBackTime = null;
  6820. }, 2000);
  6821. } else if (Date.now() - firstBackTime < 2000) {
  6822. plus.runtime.quit();
  6823. }
  6824. }
  6825. function backWebview (webview, callback) {
  6826. const children = webview.children();
  6827. if (!children || !children.length) { // 有子 webview
  6828. return callback()
  6829. }
  6830. const childWebview = children[0];
  6831. childWebview.canBack(({
  6832. canBack
  6833. }) => {
  6834. if (canBack) {
  6835. childWebview.back(); // webview 返回
  6836. } else {
  6837. callback();
  6838. }
  6839. });
  6840. }
  6841. function back (delta, animationType, animationDuration) {
  6842. const pages = getCurrentPages();
  6843. const len = pages.length;
  6844. const currentPage = pages[len - 1];
  6845. if (delta > 1) {
  6846. // 中间页隐藏
  6847. pages.slice(len - delta, len - 1).reverse().forEach(deltaPage => {
  6848. deltaPage.$getAppWebview().close('none');
  6849. });
  6850. }
  6851. const backPage = function (webview) {
  6852. if (animationType) {
  6853. webview.close(animationType, animationDuration || ANI_DURATION);
  6854. } else {
  6855. if (currentPage.$page.openType === 'redirect') { // 如果是 redirectTo 跳转的,需要制定 back 动画
  6856. webview.close(ANI_CLOSE, ANI_DURATION);
  6857. }
  6858. webview.close('auto');
  6859. }
  6860. pages.slice(len - delta, len).forEach(page => page.$remove());
  6861. setStatusBarStyle();
  6862. UniServiceJSBridge.emit('onAppRoute', {
  6863. type: 'navigateBack'
  6864. });
  6865. };
  6866. const webview = currentPage.$getAppWebview();
  6867. if (!currentPage.__uniapp_webview) {
  6868. return backPage(webview)
  6869. }
  6870. backWebview(webview, () => {
  6871. backPage(webview);
  6872. });
  6873. }
  6874. function navigateBack$1 ({
  6875. from = 'navigateBack',
  6876. delta,
  6877. animationType,
  6878. animationDuration
  6879. }) {
  6880. const pages = getCurrentPages();
  6881. const currentPage = pages[pages.length - 1];
  6882. if (
  6883. currentPage.$vm &&
  6884. currentPage.$vm.$options.onBackPress &&
  6885. currentPage.$vm.__call_hook &&
  6886. currentPage.$vm.__call_hook('onBackPress', {
  6887. from
  6888. })
  6889. ) {
  6890. return
  6891. }
  6892. uni.hideToast(); // 后退时,关闭 toast,loading
  6893. if (currentPage.$page.meta.isQuit) {
  6894. quit();
  6895. } else if (currentPage.$page.id === 1 && __uniConfig.realEntryPagePath) {
  6896. // condition
  6897. __uniConfig.entryPagePath = __uniConfig.realEntryPagePath;
  6898. delete __uniConfig.realEntryPagePath;
  6899. uni.reLaunch({
  6900. url: '/' + __uniConfig.entryPagePath
  6901. });
  6902. } else {
  6903. back(delta, animationType, animationDuration);
  6904. }
  6905. return {
  6906. errMsg: 'navigateBack:ok'
  6907. }
  6908. }
  6909. function createButtonOnClick (index) {
  6910. return function onClick (btn) {
  6911. const pages = getCurrentPages();
  6912. if (!pages.length) {
  6913. return
  6914. }
  6915. btn.index = index;
  6916. const page = pages[pages.length - 1];
  6917. page.$vm &&
  6918. page.$vm.__call_hook &&
  6919. page.$vm.__call_hook('onNavigationBarButtonTap', btn);
  6920. }
  6921. }
  6922. function parseTitleNViewButtons (titleNView) {
  6923. const buttons = titleNView.buttons;
  6924. if (!Array.isArray(buttons)) {
  6925. return titleNView
  6926. }
  6927. buttons.forEach((btn, index) => {
  6928. btn.onclick = createButtonOnClick(index);
  6929. });
  6930. return titleNView
  6931. }
  6932. function parseTitleNView (routeOptions) {
  6933. const windowOptions = routeOptions.window;
  6934. const titleNView = windowOptions.titleNView;
  6935. routeOptions.meta.statusBarStyle = windowOptions.navigationBarTextStyle === 'black' ? 'dark' : 'light';
  6936. if ( // 无头
  6937. titleNView === false ||
  6938. titleNView === 'false' ||
  6939. (
  6940. windowOptions.navigationStyle === 'custom' &&
  6941. !isPlainObject(titleNView)
  6942. ) || (
  6943. windowOptions.transparentTitle === 'always' &&
  6944. !isPlainObject(titleNView)
  6945. )
  6946. ) {
  6947. return false
  6948. }
  6949. const titleImage = windowOptions.titleImage || '';
  6950. const transparentTitle = windowOptions.transparentTitle || 'none';
  6951. const titleNViewTypeList = {
  6952. none: 'default',
  6953. auto: 'transparent',
  6954. always: 'float'
  6955. };
  6956. const ret = {
  6957. autoBackButton: !routeOptions.meta.isQuit,
  6958. titleText: titleImage === '' ? windowOptions.navigationBarTitleText || '' : '',
  6959. titleColor: windowOptions.navigationBarTextStyle === 'black' ? '#000000' : '#ffffff',
  6960. type: titleNViewTypeList[transparentTitle],
  6961. backgroundColor: windowOptions.navigationBarBackgroundColor || '#f8f8f8',
  6962. tags: titleImage === '' ? [] : [{
  6963. tag: 'img',
  6964. src: titleImage,
  6965. position: {
  6966. left: 'auto',
  6967. top: 'auto',
  6968. width: 'auto',
  6969. height: '26px'
  6970. }
  6971. }]
  6972. };
  6973. if (isPlainObject(titleNView)) {
  6974. return Object.assign(ret, parseTitleNViewButtons(titleNView))
  6975. }
  6976. return ret
  6977. }
  6978. function parsePullToRefresh (routeOptions) {
  6979. const windowOptions = routeOptions.window;
  6980. if (windowOptions.enablePullDownRefresh || (windowOptions.pullToRefresh && windowOptions.pullToRefresh.support)) {
  6981. const pullToRefreshStyles = Object.create(null);
  6982. // 初始化默认值
  6983. if (plus.os.name === 'Android') {
  6984. Object.assign(pullToRefreshStyles, {
  6985. support: true,
  6986. style: 'circle'
  6987. });
  6988. } else {
  6989. Object.assign(pullToRefreshStyles, {
  6990. support: true,
  6991. style: 'default',
  6992. height: '50px',
  6993. range: '200px',
  6994. contentdown: {
  6995. caption: ''
  6996. },
  6997. contentover: {
  6998. caption: ''
  6999. },
  7000. contentrefresh: {
  7001. caption: ''
  7002. }
  7003. });
  7004. }
  7005. if (windowOptions.backgroundTextStyle) {
  7006. pullToRefreshStyles.color = windowOptions.backgroundTextStyle;
  7007. pullToRefreshStyles.snowColor = windowOptions.backgroundTextStyle;
  7008. }
  7009. Object.assign(pullToRefreshStyles, windowOptions.pullToRefresh || {});
  7010. return pullToRefreshStyles
  7011. }
  7012. }
  7013. const REGEX_UPX = /(\d+(\.\d+)?)[r|u]px/g;
  7014. function transformCSS (css) {
  7015. return css.replace(REGEX_UPX, (a, b) => {
  7016. return uni.upx2px(parseInt(b) || 0) + 'px'
  7017. })
  7018. }
  7019. function parseStyleUnit (styles) {
  7020. let newStyles = {};
  7021. const stylesStr = JSON.stringify(styles);
  7022. if (~stylesStr.indexOf('upx') || ~stylesStr.indexOf('rpx')) {
  7023. try {
  7024. newStyles = JSON.parse(transformCSS(stylesStr));
  7025. } catch (e) {
  7026. newStyles = styles;
  7027. console.error(e);
  7028. }
  7029. } else {
  7030. newStyles = JSON.parse(stylesStr);
  7031. }
  7032. return newStyles
  7033. }
  7034. const WEBVIEW_STYLE_BLACKLIST = [
  7035. 'navigationBarBackgroundColor',
  7036. 'navigationBarTextStyle',
  7037. 'navigationBarTitleText',
  7038. 'navigationBarShadow',
  7039. 'navigationStyle',
  7040. 'disableScroll',
  7041. 'backgroundColor',
  7042. 'backgroundTextStyle',
  7043. 'enablePullDownRefresh',
  7044. 'onReachBottomDistance',
  7045. 'usingComponents',
  7046. // 需要解析的
  7047. 'titleNView',
  7048. 'pullToRefresh'
  7049. ];
  7050. function parseWebviewStyle (id, path, routeOptions = {}) {
  7051. const webviewStyle = {
  7052. bounce: 'vertical'
  7053. };
  7054. // 合并
  7055. routeOptions.window = parseStyleUnit(Object.assign(
  7056. JSON.parse(JSON.stringify(__uniConfig.window || {})),
  7057. routeOptions.window || {}
  7058. ));
  7059. Object.keys(routeOptions.window).forEach(name => {
  7060. if (WEBVIEW_STYLE_BLACKLIST.indexOf(name) === -1) {
  7061. webviewStyle[name] = routeOptions.window[name];
  7062. }
  7063. });
  7064. const backgroundColor = routeOptions.window.backgroundColor;
  7065. if (backgroundColor) {
  7066. if (!webviewStyle.background) {
  7067. webviewStyle.background = backgroundColor;
  7068. }
  7069. if (!webviewStyle.backgroundColorTop) {
  7070. webviewStyle.backgroundColorTop = backgroundColor;
  7071. }
  7072. }
  7073. const titleNView = parseTitleNView(routeOptions);
  7074. if (titleNView) {
  7075. if (
  7076. id === 1 &&
  7077. __uniConfig.realEntryPagePath &&
  7078. !routeOptions.meta.isQuit // 可能是tabBar
  7079. ) {
  7080. titleNView.autoBackButton = true;
  7081. }
  7082. webviewStyle.titleNView = titleNView;
  7083. }
  7084. const pullToRefresh = parsePullToRefresh(routeOptions);
  7085. if (pullToRefresh) {
  7086. if (pullToRefresh.style === 'circle') {
  7087. webviewStyle.bounce = 'none';
  7088. }
  7089. webviewStyle.pullToRefresh = pullToRefresh;
  7090. }
  7091. // 不支持 hide
  7092. if (webviewStyle.popGesture === 'hide') {
  7093. delete webviewStyle.popGesture;
  7094. }
  7095. if (routeOptions.meta.isQuit) { // 退出
  7096. webviewStyle.popGesture = plus.os.name === 'iOS' ? 'appback' : 'none';
  7097. }
  7098. // TODO 下拉刷新
  7099. if (path && routeOptions.meta.isNVue) {
  7100. webviewStyle.uniNView = {
  7101. path,
  7102. defaultFontSize: __uniConfig.defaultFontSize,
  7103. viewport: __uniConfig.viewport
  7104. };
  7105. }
  7106. return webviewStyle
  7107. }
  7108. function backbuttonListener () {
  7109. uni.navigateBack({
  7110. from: 'backbutton'
  7111. });
  7112. }
  7113. function initPopupSubNVue (subNVueWebview, style, maskWebview) {
  7114. if (!maskWebview.popupSubNVueWebviews) {
  7115. maskWebview.popupSubNVueWebviews = {};
  7116. }
  7117. maskWebview.popupSubNVueWebviews[subNVueWebview.id] = subNVueWebview;
  7118. if (process.env.NODE_ENV !== 'production') {
  7119. console.log(
  7120. `UNIAPP[webview][${maskWebview.id}]:add.popupSubNVueWebview[${subNVueWebview.id}]`
  7121. );
  7122. }
  7123. const hideSubNVue = function () {
  7124. maskWebview.setStyle({
  7125. mask: 'none'
  7126. });
  7127. subNVueWebview.hide('auto');
  7128. };
  7129. maskWebview.addEventListener('maskClick', hideSubNVue);
  7130. let isRemoved = false; // 增加个 remove 标记,防止出错
  7131. subNVueWebview.addEventListener('show', () => {
  7132. if (!isRemoved) {
  7133. plus.key.removeEventListener('backbutton', backbuttonListener);
  7134. plus.key.addEventListener('backbutton', hideSubNVue);
  7135. isRemoved = true;
  7136. }
  7137. });
  7138. subNVueWebview.addEventListener('hide', () => {
  7139. if (isRemoved) {
  7140. plus.key.removeEventListener('backbutton', hideSubNVue);
  7141. plus.key.addEventListener('backbutton', backbuttonListener);
  7142. isRemoved = false;
  7143. }
  7144. });
  7145. subNVueWebview.addEventListener('close', () => {
  7146. delete maskWebview.popupSubNVueWebviews[subNVueWebview.id];
  7147. if (isRemoved) {
  7148. plus.key.removeEventListener('backbutton', hideSubNVue);
  7149. plus.key.addEventListener('backbutton', backbuttonListener);
  7150. isRemoved = false;
  7151. }
  7152. });
  7153. }
  7154. function initNormalSubNVue (subNVueWebview, style, webview) {
  7155. webview.append(subNVueWebview);
  7156. }
  7157. function initSubNVue (subNVue, routeOptions, webview) {
  7158. if (!subNVue.path) {
  7159. return
  7160. }
  7161. const style = subNVue.style || {};
  7162. const isNavigationBar = subNVue.type === 'navigationBar';
  7163. const isPopup = subNVue.type === 'popup';
  7164. delete style.type;
  7165. if (isPopup && !subNVue.id) {
  7166. console.warn('subNVue[' + subNVue.path + '] 尚未配置 id');
  7167. }
  7168. // TODO lazyload
  7169. style.uniNView = {
  7170. path: subNVue.path.replace('.nvue', '.js'),
  7171. defaultFontSize: __uniConfig.defaultFontSize,
  7172. viewport: __uniConfig.viewport
  7173. };
  7174. const extras = {
  7175. __uniapp_host: routeOptions.path,
  7176. __uniapp_origin: style.uniNView.path.split('?')[0].replace('.js', ''),
  7177. __uniapp_origin_id: webview.id,
  7178. __uniapp_origin_type: webview.__uniapp_type
  7179. };
  7180. let maskWebview;
  7181. if (isNavigationBar) {
  7182. style.position = 'dock';
  7183. style.dock = 'top';
  7184. style.top = 0;
  7185. style.width = '100%';
  7186. style.height = TITLEBAR_HEIGHT + getStatusbarHeight();
  7187. delete style.left;
  7188. delete style.right;
  7189. delete style.bottom;
  7190. delete style.margin;
  7191. } else if (isPopup) {
  7192. style.position = 'absolute';
  7193. if (isTabBarPage(routeOptions.path)) {
  7194. maskWebview = tabBar$1;
  7195. } else {
  7196. maskWebview = webview;
  7197. }
  7198. extras.__uniapp_mask = style.mask || 'rgba(0,0,0,0.5)';
  7199. extras.__uniapp_mask_id = maskWebview.id;
  7200. }
  7201. if (process.env.NODE_ENV !== 'production') {
  7202. console.log(
  7203. `UNIAPP[webview][${webview.id}]:create[${subNVue.id}]:${JSON.stringify(style)}`
  7204. );
  7205. }
  7206. delete style.mask;
  7207. const subNVueWebview = plus.webview.create('', subNVue.id, style, extras);
  7208. if (isPopup) {
  7209. initPopupSubNVue(subNVueWebview, style, maskWebview);
  7210. } else {
  7211. initNormalSubNVue(subNVueWebview, style, webview);
  7212. }
  7213. }
  7214. function initSubNVues (routeOptions, webview) {
  7215. const subNVues = routeOptions.window.subNVues;
  7216. if (!subNVues || !subNVues.length) {
  7217. return
  7218. }
  7219. subNVues.forEach(subNVue => {
  7220. initSubNVue(subNVue, routeOptions, webview);
  7221. });
  7222. }
  7223. function onWebviewClose (webview) {
  7224. webview.popupSubNVueWebviews && webview.addEventListener('close', () => {
  7225. Object.keys(webview.popupSubNVueWebviews).forEach(id => {
  7226. if (process.env.NODE_ENV !== 'production') {
  7227. console.log(
  7228. `UNIAPP[webview][${webview.id}]:popupSubNVueWebview[${id}].close`
  7229. );
  7230. }
  7231. webview.popupSubNVueWebviews[id].close('none');
  7232. });
  7233. });
  7234. }
  7235. function onWebviewResize (webview) {
  7236. const onResize = function ({
  7237. width,
  7238. height
  7239. }) {
  7240. const landscape = Math.abs(plus.navigator.getOrientation()) === 90;
  7241. const res = {
  7242. deviceOrientation: landscape ? 'landscape' : 'portrait',
  7243. size: {
  7244. windowWidth: Math.ceil(width),
  7245. windowHeight: Math.ceil(height)
  7246. }
  7247. };
  7248. publish('onViewDidResize', res); // API
  7249. UniServiceJSBridge.emit('onResize', res, parseInt(webview.id)); // Page lifecycle
  7250. };
  7251. webview.addEventListener('resize', debounce(onResize, 50));
  7252. }
  7253. const PAGE_CREATE = 2;
  7254. const MOUNTED_DATA = 4;
  7255. const UPDATED_DATA = 6;
  7256. const PAGE_CREATED = 10;
  7257. const UI_EVENT = 20;
  7258. const VD_SYNC = 'vdSync';
  7259. const WEBVIEW_READY = 'webviewReady';
  7260. const VD_SYNC_CALLBACK = 'vdSyncCallback';
  7261. const INVOKE_API = 'invokeApi';
  7262. const WEB_INVOKE_APPSERVICE$1 = 'WEB_INVOKE_APPSERVICE';
  7263. const WEBVIEW_INSERTED = 'webviewInserted';
  7264. const WEBVIEW_REMOVED = 'webviewRemoved';
  7265. function onWebviewRecovery (webview, routeOptions) {
  7266. const {
  7267. subscribe,
  7268. unsubscribe
  7269. } = UniServiceJSBridge;
  7270. const id = webview.id;
  7271. const onWebviewRecoveryReady = function (data, pageId) {
  7272. if (id !== pageId) {
  7273. return
  7274. }
  7275. unsubscribe(WEBVIEW_READY, onWebviewRecoveryReady);
  7276. if (process.env.NODE_ENV !== 'production') {
  7277. console.log(`UNIAPP[webview][${id}]:onWebviewRecoveryReady ready`);
  7278. }
  7279. // 恢复目标页面
  7280. pageId = parseInt(pageId);
  7281. const page = getCurrentPages(true).find(page => page.$page.id === pageId);
  7282. if (!page) {
  7283. return console.error(`Page[${pageId}] not found`)
  7284. }
  7285. page.$vm._$vd.restore();
  7286. };
  7287. webview.addEventListener('recovery', e => {
  7288. if (process.env.NODE_ENV !== 'production') {
  7289. console.log(`UNIAPP[webview][${this.id}].recovery.reload:` + JSON.stringify({
  7290. path: routeOptions.path,
  7291. webviewId: id
  7292. }));
  7293. }
  7294. subscribe(WEBVIEW_READY, onWebviewRecoveryReady);
  7295. });
  7296. }
  7297. function onWebviewPopGesture (webview) {
  7298. let popStartStatusBarStyle;
  7299. webview.addEventListener('popGesture', e => {
  7300. if (e.type === 'start') {
  7301. // 设置下一个页面的 statusBarStyle
  7302. const pages = getCurrentPages();
  7303. const page = pages[pages.length - 2];
  7304. popStartStatusBarStyle = lastStatusBarStyle;
  7305. const statusBarStyle = page && page.$page.meta.statusBarStyle;
  7306. statusBarStyle && setStatusBarStyle(statusBarStyle);
  7307. } else if (e.type === 'end' && !e.result) {
  7308. // 拖拽未完成,设置为当前状态栏前景色
  7309. setStatusBarStyle(popStartStatusBarStyle);
  7310. } else if (e.type === 'end' && e.result) {
  7311. const pages = getCurrentPages();
  7312. const page = pages[pages.length - 1];
  7313. page && page.$remove();
  7314. setStatusBarStyle();
  7315. UniServiceJSBridge.emit('onAppRoute', {
  7316. type: 'navigateBack'
  7317. });
  7318. }
  7319. });
  7320. }
  7321. let preloadWebview;
  7322. let id$1 = 2;
  7323. const WEBVIEW_LISTENERS = {
  7324. pullToRefresh: 'onPullDownRefresh',
  7325. titleNViewSearchInputChanged: 'onNavigationBarSearchInputChanged',
  7326. titleNViewSearchInputConfirmed: 'onNavigationBarSearchInputConfirmed',
  7327. titleNViewSearchInputClicked: 'onNavigationBarSearchInputClicked',
  7328. titleNViewSearchInputFocusChanged: 'onNavigationBarSearchInputFocusChanged'
  7329. };
  7330. function setPreloadWebview (webview) {
  7331. preloadWebview = webview;
  7332. }
  7333. function noop$1 (str) {
  7334. return str
  7335. }
  7336. function getUniPageUrl (path, query) {
  7337. const queryString = query ? stringifyQuery(query, noop$1) : '';
  7338. return {
  7339. path: path.substr(1),
  7340. query: queryString ? queryString.substr(1) : queryString
  7341. }
  7342. }
  7343. function getDebugRefresh (path, query, routeOptions) {
  7344. const queryString = query ? stringifyQuery(query, noop$1) : '';
  7345. return {
  7346. isTab: routeOptions.meta.isTabBar,
  7347. arguments: JSON.stringify({
  7348. path: path.substr(1),
  7349. query: queryString ? queryString.substr(1) : queryString
  7350. })
  7351. }
  7352. }
  7353. function createWebview (path, routeOptions, query) {
  7354. if (routeOptions.meta.isNVue) {
  7355. const webviewId = id$1++;
  7356. const webviewStyle = parseWebviewStyle(
  7357. webviewId,
  7358. path,
  7359. routeOptions
  7360. );
  7361. webviewStyle.uniPageUrl = getUniPageUrl(path, query);
  7362. if (process.env.NODE_ENV !== 'production') {
  7363. console.log('[uni-app] createWebview', webviewId, path, webviewStyle);
  7364. }
  7365. return plus.webview.create('', String(webviewId), webviewStyle, {
  7366. nvue: true
  7367. })
  7368. }
  7369. if (id$1 === 2) { // 如果首页非 nvue,则直接返回 Launch Webview
  7370. return plus.webview.getLaunchWebview()
  7371. }
  7372. const webview = preloadWebview;
  7373. return webview
  7374. }
  7375. function initWebview (webview, routeOptions, path, query) {
  7376. // 首页或非 nvue 页面
  7377. if (webview.id === '1' || !routeOptions.meta.isNVue) {
  7378. const webviewStyle = parseWebviewStyle(
  7379. parseInt(webview.id),
  7380. '',
  7381. routeOptions
  7382. );
  7383. webviewStyle.uniPageUrl = getUniPageUrl(path, query);
  7384. if (!routeOptions.meta.isNVue) {
  7385. webviewStyle.debugRefresh = getDebugRefresh(path, query, routeOptions);
  7386. }
  7387. if (process.env.NODE_ENV !== 'production') {
  7388. console.log('[uni-app] updateWebview', webviewStyle);
  7389. }
  7390. webview.setStyle(webviewStyle);
  7391. }
  7392. const {
  7393. on,
  7394. emit
  7395. } = UniServiceJSBridge;
  7396. initSubNVues(routeOptions, webview);
  7397. Object.keys(WEBVIEW_LISTENERS).forEach(name => {
  7398. webview.addEventListener(name, (e) => {
  7399. emit(WEBVIEW_LISTENERS[name], e, parseInt(webview.id));
  7400. });
  7401. });
  7402. onWebviewClose(webview);
  7403. onWebviewResize(webview);
  7404. if (plus.os.name === 'iOS') {
  7405. !webview.nvue && onWebviewRecovery(webview, routeOptions);
  7406. onWebviewPopGesture(webview);
  7407. }
  7408. on(webview.id + '.startPullDownRefresh', () => {
  7409. webview.beginPullToRefresh();
  7410. });
  7411. on(webview.id + '.stopPullDownRefresh', () => {
  7412. webview.endPullToRefresh();
  7413. });
  7414. return webview
  7415. }
  7416. function createPreloadWebview () {
  7417. if (!preloadWebview || preloadWebview.__uniapp_route) { // 不存在,或已被使用
  7418. preloadWebview = plus.webview.create(VIEW_WEBVIEW_PATH, String(id$1++));
  7419. if (process.env.NODE_ENV !== 'production') {
  7420. console.log(`[uni-app] preloadWebview[${preloadWebview.id}]`);
  7421. }
  7422. }
  7423. return preloadWebview
  7424. }
  7425. const webviewReadyCallbacks = {};
  7426. function registerWebviewReady (pageId, callback) {
  7427. (webviewReadyCallbacks[pageId] || (webviewReadyCallbacks[pageId] = [])).push(callback);
  7428. }
  7429. function consumeWebviewReady (pageId) {
  7430. const callbacks = webviewReadyCallbacks[pageId];
  7431. Array.isArray(callbacks) && callbacks.forEach(callback => callback());
  7432. delete webviewReadyCallbacks[pageId];
  7433. }
  7434. let todoNavigator = false;
  7435. function setTodoNavigator (path, callback, msg) {
  7436. todoNavigator = {
  7437. path: path,
  7438. nvue: __uniRoutes.find(route => route.path === path).meta.isNVue,
  7439. navigate: callback
  7440. };
  7441. if (process.env.NODE_ENV !== 'production') {
  7442. console.log(`todoNavigator:${todoNavigator.path} ${msg}`);
  7443. }
  7444. }
  7445. function navigate (path, callback, isAppLaunch) {
  7446. {
  7447. if (isAppLaunch && __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose && (!__uniConfig.splashscreen.alwaysShowBeforeRender)) {
  7448. plus.navigator.closeSplashscreen();
  7449. }
  7450. if (!isAppLaunch && todoNavigator) {
  7451. return console.error(`已存在待跳转页面${todoNavigator.path},请不要连续多次跳转页面${path}`)
  7452. }
  7453. if (__uniConfig.renderer === 'native') { // 纯原生无需wait逻辑
  7454. // 如果是首页还未初始化,需要等一等,其他无需等待
  7455. if (getCurrentPages().length === 0) {
  7456. return setTodoNavigator(path, callback, 'waitForReady')
  7457. }
  7458. return callback()
  7459. }
  7460. // 未创建 preloadWebview 或 preloadWebview 已被使用
  7461. const waitPreloadWebview = !preloadWebview || (preloadWebview && preloadWebview.__uniapp_route);
  7462. // 已创建未 loaded
  7463. const waitPreloadWebviewReady = preloadWebview && !preloadWebview.loaded;
  7464. if (waitPreloadWebview || waitPreloadWebviewReady) {
  7465. setTodoNavigator(path, callback, waitPreloadWebview ? 'waitForCreate' : 'waitForReady');
  7466. } else {
  7467. callback();
  7468. }
  7469. if (waitPreloadWebviewReady) {
  7470. registerWebviewReady(preloadWebview.id, todoNavigate);
  7471. }
  7472. }
  7473. }
  7474. function todoNavigate () {
  7475. if (!todoNavigator) {
  7476. return
  7477. }
  7478. const {
  7479. navigate
  7480. } = todoNavigator;
  7481. if (process.env.NODE_ENV !== 'production') {
  7482. console.log(`todoNavigate:${todoNavigator.path}`);
  7483. }
  7484. todoNavigator = false;
  7485. return navigate()
  7486. }
  7487. function navigateFinish () {
  7488. {
  7489. if (__uniConfig.renderer === 'native') {
  7490. if (!todoNavigator) {
  7491. return
  7492. }
  7493. if (todoNavigator.nvue) {
  7494. return todoNavigate()
  7495. }
  7496. return
  7497. }
  7498. // 创建预加载
  7499. const preloadWebview = createPreloadWebview();
  7500. if (process.env.NODE_ENV !== 'production') {
  7501. console.log(`navigateFinish.preloadWebview:${preloadWebview.id}`);
  7502. }
  7503. if (!todoNavigator) {
  7504. return
  7505. }
  7506. if (todoNavigator.nvue) {
  7507. return todoNavigate()
  7508. }
  7509. preloadWebview.loaded
  7510. ? todoNavigator.navigate()
  7511. : registerWebviewReady(preloadWebview.id, todoNavigate);
  7512. }
  7513. }
  7514. function showWebview (webview, animationType, animationDuration, showCallback, delay) {
  7515. if (typeof delay === 'undefined') {
  7516. delay = webview.nvue ? 0 : 100;
  7517. }
  7518. if (typeof animationDuration === 'undefined') {
  7519. animationDuration = ANI_DURATION;
  7520. } else {
  7521. animationDuration = parseInt(animationDuration);
  7522. }
  7523. if (process.env.NODE_ENV !== 'production') {
  7524. console.log(`[show][${Date.now()}]`, delay);
  7525. }
  7526. const duration = animationDuration || ANI_DURATION;
  7527. setTimeout(() => {
  7528. const execShowCallback = function () {
  7529. if (execShowCallback._called) {
  7530. if (process.env.NODE_ENV !== 'production') {
  7531. console.log('execShowCallback.prevent');
  7532. }
  7533. return
  7534. }
  7535. execShowCallback._called = true;
  7536. showCallback && showCallback();
  7537. navigateFinish();
  7538. };
  7539. const timer = setTimeout(() => {
  7540. if (process.env.NODE_ENV !== 'production') {
  7541. console.log(`[show.callback.timer][${Date.now()}]`);
  7542. }
  7543. execShowCallback();
  7544. }, duration + 150);
  7545. webview.show(
  7546. animationType || ANI_SHOW,
  7547. duration,
  7548. () => {
  7549. if (process.env.NODE_ENV !== 'production') {
  7550. console.log(`[show.callback][${Date.now()}]`);
  7551. }
  7552. if (!execShowCallback._called) {
  7553. clearTimeout(timer);
  7554. }
  7555. execShowCallback();
  7556. }
  7557. );
  7558. }, delay);
  7559. }
  7560. const pageFactory = Object.create(null);
  7561. function definePage (name, createPageVueComponent) {
  7562. pageFactory[name] = createPageVueComponent;
  7563. }
  7564. const getPageVueComponent = cached(function (pagePath) {
  7565. return pageFactory[pagePath]()
  7566. });
  7567. function createPage (pagePath, pageId, pageQuery, pageInstance) {
  7568. if (!pageFactory[pagePath]) {
  7569. console.error(`${pagePath} not found`);
  7570. }
  7571. const startTime = Date.now();
  7572. const pageVm = new (getPageVueComponent(pagePath))({
  7573. mpType: 'page',
  7574. pageId,
  7575. pagePath,
  7576. pageQuery,
  7577. pageInstance
  7578. });
  7579. if (process.env.NODE_ENV !== 'production') {
  7580. console.log(`new ${pagePath}[${pageId}]:time(${Date.now() - startTime})`);
  7581. }
  7582. return pageVm
  7583. }
  7584. const pages = [];
  7585. function getCurrentPages$1 (returnAll) {
  7586. return returnAll ? pages.slice(0) : pages.filter(page => {
  7587. return !page.$page.meta.isTabBar || page.$page.meta.visible
  7588. })
  7589. }
  7590. /**
  7591. * 首页需要主动registerPage,二级页面路由跳转时registerPage
  7592. */
  7593. function registerPage ({
  7594. url,
  7595. path,
  7596. query,
  7597. openType,
  7598. webview
  7599. }) {
  7600. const routeOptions = JSON.parse(JSON.stringify(__uniRoutes.find(route => route.path === path)));
  7601. if (
  7602. openType === 'reLaunch' ||
  7603. (
  7604. !__uniConfig.realEntryPagePath &&
  7605. pages.length === 0
  7606. )
  7607. ) {
  7608. routeOptions.meta.isQuit = true;
  7609. } else if (!routeOptions.meta.isTabBar) {
  7610. routeOptions.meta.isQuit = false;
  7611. }
  7612. if (!webview) {
  7613. webview = createWebview(path, routeOptions, query);
  7614. } else {
  7615. webview = plus.webview.getWebviewById(webview.id);
  7616. webview.nvue = routeOptions.meta.isNVue;
  7617. }
  7618. if (routeOptions.meta.isTabBar) {
  7619. routeOptions.meta.visible = true;
  7620. }
  7621. if (routeOptions.meta.isTabBar && webview.id !== '1') {
  7622. tabBar$1.append(webview);
  7623. }
  7624. if (process.env.NODE_ENV !== 'production') {
  7625. console.log(`[uni-app] registerPage(${path},${webview.id})`);
  7626. }
  7627. initWebview(webview, routeOptions, path, query);
  7628. const route = path.slice(1);
  7629. webview.__uniapp_route = route;
  7630. const pageInstance = {
  7631. route,
  7632. options: Object.assign({}, query || {}),
  7633. $getAppWebview () {
  7634. // 重要,不能直接返回 webview 对象,因为 plus 可能会被二次替换,返回的 webview 对象内部的 plus 不正确
  7635. // 导致 webview.getStyle 等逻辑出错(旧的 webview 内部 plus 被释放)
  7636. return plus.webview.getWebviewById(webview.id)
  7637. },
  7638. $page: {
  7639. id: parseInt(webview.id),
  7640. meta: routeOptions.meta,
  7641. path,
  7642. route,
  7643. openType
  7644. },
  7645. $remove () {
  7646. const index = pages.findIndex(page => page === this);
  7647. if (index !== -1) {
  7648. if (!webview.nvue) {
  7649. this.$vm.$destroy();
  7650. }
  7651. pages.splice(index, 1);
  7652. if (process.env.NODE_ENV !== 'production') {
  7653. console.log('[uni-app] removePage(' + path + ')[' + webview.id + ']');
  7654. }
  7655. }
  7656. },
  7657. // 兼容小程序框架
  7658. selectComponent (selector) {
  7659. return this.$vm.selectComponent(selector)
  7660. },
  7661. selectAllComponents (selector) {
  7662. return this.$vm.selectAllComponents(selector)
  7663. }
  7664. };
  7665. pages.push(pageInstance);
  7666. // 首页是 nvue 时,在 registerPage 时,执行路由堆栈
  7667. if (webview.id === '1' && webview.nvue) {
  7668. if (
  7669. __uniConfig.splashscreen &&
  7670. __uniConfig.splashscreen.autoclose &&
  7671. !__uniConfig.splashscreen.alwaysShowBeforeRender
  7672. ) {
  7673. plus.navigator.closeSplashscreen();
  7674. }
  7675. __uniConfig.onReady(function () {
  7676. navigateFinish();
  7677. });
  7678. }
  7679. {
  7680. if (!webview.nvue) {
  7681. const pageId = webview.id;
  7682. try {
  7683. createPage(route, pageId, query, pageInstance).$mount();
  7684. } catch (e) {
  7685. console.error(e);
  7686. }
  7687. }
  7688. }
  7689. return webview
  7690. }
  7691. function _navigateTo ({
  7692. url,
  7693. path,
  7694. query,
  7695. animationType,
  7696. animationDuration
  7697. }, callbackId) {
  7698. UniServiceJSBridge.emit('onAppRoute', {
  7699. type: 'navigateTo',
  7700. path
  7701. });
  7702. showWebview(
  7703. registerPage({
  7704. url,
  7705. path,
  7706. query,
  7707. openType: 'navigate'
  7708. }),
  7709. animationType,
  7710. animationDuration,
  7711. () => {
  7712. invoke$1(callbackId, {
  7713. errMsg: 'navigateTo:ok'
  7714. });
  7715. }
  7716. );
  7717. setStatusBarStyle();
  7718. }
  7719. function navigateTo$1 ({
  7720. url,
  7721. openType,
  7722. animationType,
  7723. animationDuration
  7724. }, callbackId) {
  7725. const urls = url.split('?');
  7726. const path = urls[0];
  7727. const routeStyles = __uniRoutes.find(route => route.path === path).window;
  7728. const globalStyle = __uniConfig.window || {};
  7729. if (!animationType) {
  7730. animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW;
  7731. }
  7732. if (!animationDuration) {
  7733. animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION;
  7734. }
  7735. const query = parseQuery(urls[1] || '');
  7736. navigate(path, function () {
  7737. _navigateTo({
  7738. url,
  7739. path,
  7740. query,
  7741. animationType,
  7742. animationDuration
  7743. }, callbackId);
  7744. }, openType === 'appLaunch');
  7745. }
  7746. function _reLaunch ({
  7747. url,
  7748. path,
  7749. query
  7750. }, callbackId) {
  7751. const pages = getCurrentPages(true).slice(0);
  7752. const routeOptions = __uniRoutes.find(route => route.path === path);
  7753. if (routeOptions.meta.isTabBar) {
  7754. tabBar$1.switchTab(path.slice(1));
  7755. }
  7756. showWebview(
  7757. registerPage({
  7758. url,
  7759. path,
  7760. query,
  7761. openType: 'reLaunch'
  7762. }),
  7763. 'none',
  7764. 0,
  7765. () => {
  7766. pages.forEach(page => {
  7767. page.$remove();
  7768. page.$getAppWebview().close('none');
  7769. });
  7770. invoke$1(callbackId, {
  7771. errMsg: 'reLaunch:ok'
  7772. });
  7773. }
  7774. );
  7775. setStatusBarStyle();
  7776. }
  7777. function reLaunch$1 ({
  7778. url
  7779. }, callbackId) {
  7780. const urls = url.split('?');
  7781. const path = urls[0];
  7782. const query = parseQuery(urls[1] || '');
  7783. navigate(path, function () {
  7784. _reLaunch({
  7785. url,
  7786. path,
  7787. query
  7788. }, callbackId);
  7789. });
  7790. }
  7791. function _redirectTo ({
  7792. url,
  7793. path,
  7794. query
  7795. }, callbackId) {
  7796. const pages = getCurrentPages();
  7797. const lastPage = pages[pages.length - 1];
  7798. lastPage && lastPage.$remove();
  7799. showWebview(
  7800. registerPage({
  7801. url,
  7802. path,
  7803. query,
  7804. openType: 'redirect'
  7805. }),
  7806. 'none',
  7807. 0,
  7808. () => {
  7809. lastPage && lastPage.$getAppWebview().close('none');
  7810. invoke$1(callbackId, {
  7811. errMsg: 'redirectTo:ok'
  7812. });
  7813. }
  7814. );
  7815. setStatusBarStyle();
  7816. }
  7817. function redirectTo$1 ({
  7818. url
  7819. }, callbackId) {
  7820. const urls = url.split('?');
  7821. const path = urls[0];
  7822. const query = parseQuery(urls[1] || '');
  7823. navigate(path, function () {
  7824. _redirectTo({
  7825. url,
  7826. path,
  7827. query
  7828. }, callbackId);
  7829. });
  7830. }
  7831. function _switchTab ({
  7832. url,
  7833. path,
  7834. query,
  7835. from
  7836. }, callbackId) {
  7837. tabBar$1.switchTab(path.slice(1));
  7838. const pages = getCurrentPages();
  7839. const len = pages.length;
  7840. let callOnHide = false;
  7841. let callOnShow = false;
  7842. let currentPage;
  7843. if (len >= 1) { // 前一个页面是非 tabBar 页面
  7844. currentPage = pages[len - 1];
  7845. if (!currentPage.$page.meta.isTabBar) {
  7846. // 前一个页面为非 tabBar 页面时,目标tabBar需要强制触发onShow
  7847. // 该情况下目标页tabBarPage的visible是不对的
  7848. // 除非每次路由跳转都处理一遍tabBarPage的visible,目前仅switchTab会处理
  7849. // 简单起见,暂时直接判断该情况,执行onShow
  7850. callOnShow = true;
  7851. pages.reverse().forEach(page => {
  7852. if (!page.$page.meta.isTabBar && page !== currentPage) {
  7853. page.$remove();
  7854. page.$getAppWebview().close('none');
  7855. }
  7856. });
  7857. currentPage.$remove();
  7858. // 延迟执行避免iOS应用退出
  7859. setTimeout(() => {
  7860. if (currentPage.$page.openType === 'redirect') {
  7861. currentPage.$getAppWebview().close(ANI_CLOSE, ANI_DURATION);
  7862. } else {
  7863. currentPage.$getAppWebview().close('auto');
  7864. }
  7865. }, 100);
  7866. } else {
  7867. callOnHide = true;
  7868. }
  7869. }
  7870. let tabBarPage;
  7871. // 查找当前 tabBarPage,且设置 visible
  7872. getCurrentPages(true).forEach(page => {
  7873. if (('/' + page.route) === path) {
  7874. if (!page.$page.meta.visible) { // 之前未显示
  7875. callOnShow = true;
  7876. }
  7877. page.$page.meta.visible = true;
  7878. tabBarPage = page;
  7879. } else {
  7880. if (page.$page.meta.isTabBar) {
  7881. page.$page.meta.visible = false;
  7882. }
  7883. }
  7884. });
  7885. // 相同tabBar页面
  7886. if (currentPage === tabBarPage) {
  7887. callOnHide = false;
  7888. }
  7889. if (currentPage && callOnHide) {
  7890. currentPage.$vm.__call_hook('onHide');
  7891. }
  7892. if (tabBarPage) {
  7893. tabBarPage.$getAppWebview().show('none');
  7894. // 等visible状态都切换完之后,再触发onShow,否则开发者在onShow里边 getCurrentPages 会不准确
  7895. callOnShow && tabBarPage.$vm.__call_hook('onShow');
  7896. } else {
  7897. return showWebview(registerPage({
  7898. url,
  7899. path,
  7900. query,
  7901. openType: 'switchTab'
  7902. }), 'none', 0, () => {
  7903. setStatusBarStyle();
  7904. invoke$1(callbackId, {
  7905. errMsg: 'switchTab:ok'
  7906. });
  7907. }, 70)
  7908. }
  7909. setStatusBarStyle();
  7910. invoke$1(callbackId, {
  7911. errMsg: 'switchTab:ok'
  7912. });
  7913. }
  7914. function switchTab$1 ({
  7915. url,
  7916. from,
  7917. openType
  7918. }, callbackId) {
  7919. // 直达时,允许 tabBar 带参数
  7920. const urls = url.split('?');
  7921. const path = urls[0];
  7922. const query = parseQuery(urls[1] || '');
  7923. navigate(path, function () {
  7924. _switchTab({
  7925. url,
  7926. path,
  7927. query,
  7928. from
  7929. }, callbackId);
  7930. }, openType === 'appLaunch');
  7931. }
  7932. const STORAGE_DATA_TYPE = '__TYPE';
  7933. const STORAGE_KEYS = 'uni-storage-keys';
  7934. function parseValue (value) {
  7935. const types = ['object', 'string', 'number', 'boolean', 'undefined'];
  7936. try {
  7937. const object = typeof value === 'string' ? JSON.parse(value) : value;
  7938. const type = object.type;
  7939. if (types.indexOf(type) >= 0) {
  7940. const keys = Object.keys(object);
  7941. if (keys.length === 2 && 'data' in object) {
  7942. // eslint-disable-next-line valid-typeof
  7943. if (typeof object.data === type) {
  7944. return object.data
  7945. }
  7946. // eslint-disable-next-line no-useless-escape
  7947. if (type === 'object' && /^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}Z$/.test(object.data)) {
  7948. // ISO 8601 格式返回 Date
  7949. return new Date(object.data)
  7950. }
  7951. } else if (keys.length === 1) {
  7952. return ''
  7953. }
  7954. }
  7955. } catch (error) {}
  7956. }
  7957. function setStorage$1 ({
  7958. key,
  7959. data,
  7960. isSync
  7961. } = {}, callbackId) {
  7962. const type = typeof data;
  7963. const value = type === 'string' ? data : JSON.stringify({
  7964. type,
  7965. data: data
  7966. });
  7967. try {
  7968. if (type === 'string' && parseValue(value) !== undefined) {
  7969. plus.storage.setItemAsync(key + STORAGE_DATA_TYPE, type);
  7970. } else {
  7971. plus.storage.removeItemAsync(key + STORAGE_DATA_TYPE);
  7972. }
  7973. plus.storage.setItemAsync(key, value, function () {
  7974. invoke$1(callbackId, {
  7975. errMsg: 'setStorage:ok'
  7976. });
  7977. }, function (err) {
  7978. invoke$1(callbackId, {
  7979. errMsg: `setStorage:fail ${err.message}`
  7980. });
  7981. });
  7982. } catch (error) {
  7983. invoke$1(callbackId, {
  7984. errMsg: `setStorage:fail ${error}`
  7985. });
  7986. }
  7987. }
  7988. function setStorageSync$1 (key, data) {
  7989. const type = typeof data;
  7990. const value = type === 'string' ? data : JSON.stringify({
  7991. type,
  7992. data: data
  7993. });
  7994. try {
  7995. if (type === 'string' && parseValue(value) !== undefined) {
  7996. plus.storage.setItem(key + STORAGE_DATA_TYPE, type);
  7997. } else {
  7998. plus.storage.removeItem(key + STORAGE_DATA_TYPE);
  7999. }
  8000. plus.storage.setItem(key, value);
  8001. } catch (error) {
  8002. }
  8003. }
  8004. function parseGetStorage (type, value) {
  8005. let data = value;
  8006. if (type !== 'string' || (type === 'string' && value === '{"type":"undefined"}')) {
  8007. try {
  8008. // 兼容H5和V3初期历史格式
  8009. let object = JSON.parse(value);
  8010. const result = parseValue(object);
  8011. if (result !== undefined) {
  8012. data = result;
  8013. } else if (type) {
  8014. // 兼容App端历史格式
  8015. data = object;
  8016. if (typeof object === 'string') {
  8017. object = JSON.parse(object);
  8018. const objectType = typeof object;
  8019. if (objectType === 'number' && type === 'date') {
  8020. data = new Date(object);
  8021. } else if (objectType === (['null', 'array'].indexOf(type) < 0 ? type : 'object')) {
  8022. data = object;
  8023. }
  8024. }
  8025. }
  8026. } catch (error) {}
  8027. }
  8028. return data
  8029. }
  8030. function getStorage$1 ({
  8031. key
  8032. } = {}, callbackId) {
  8033. plus.storage.getItemAsync(key, function (res) {
  8034. plus.storage.getItemAsync(key + STORAGE_DATA_TYPE, function (typeRes) {
  8035. const typeOrigin = typeRes.data || '';
  8036. const type = typeOrigin.toLowerCase();
  8037. invoke$1(callbackId, {
  8038. data: parseGetStorage(type, res.data),
  8039. errMsg: 'getStorage:ok'
  8040. });
  8041. }, function () {
  8042. const type = '';
  8043. invoke$1(callbackId, {
  8044. data: parseGetStorage(type, res.data),
  8045. errMsg: 'getStorage:ok'
  8046. });
  8047. });
  8048. }, function (err) {
  8049. invoke$1(callbackId, {
  8050. data: '',
  8051. errMsg: `getStorage:fail ${err.message}`
  8052. });
  8053. });
  8054. }
  8055. function getStorageSync$1 (key) {
  8056. const value = plus.storage.getItem(key);
  8057. const typeOrigin = plus.storage.getItem(key + STORAGE_DATA_TYPE) || '';
  8058. const type = typeOrigin.toLowerCase();
  8059. if (typeof value !== 'string') {
  8060. return ''
  8061. }
  8062. return parseGetStorage(type, value)
  8063. }
  8064. function removeStorage$1 ({
  8065. key
  8066. } = {}, callbackId) {
  8067. // 兼容App端历史格式
  8068. plus.storage.removeItemAsync(key + STORAGE_DATA_TYPE);
  8069. plus.storage.removeItemAsync(key, function (res) {
  8070. invoke$1(callbackId, {
  8071. errMsg: 'removeStorage:ok'
  8072. });
  8073. }, function (err) {
  8074. invoke$1(callbackId, {
  8075. errMsg: `removeStorage:fail ${err.message}`
  8076. });
  8077. });
  8078. }
  8079. function removeStorageSync$1 (key) {
  8080. plus.storage.removeItem(key + STORAGE_DATA_TYPE);
  8081. plus.storage.removeItem(key);
  8082. }
  8083. function clearStorage (args, callbackId) {
  8084. plus.storage.clearAsync(function (res) {
  8085. invoke$1(callbackId, {
  8086. errMsg: 'clearStorage:ok'
  8087. });
  8088. }, function (err) {
  8089. invoke$1(callbackId, {
  8090. errMsg: `clearStorage:fail ${err.message}`
  8091. });
  8092. });
  8093. }
  8094. function clearStorageSync () {
  8095. plus.storage.clear();
  8096. }
  8097. function getStorageInfo () {
  8098. const length = (plus.storage.length || plus.storage.getLength()) || 0;
  8099. const keys = [];
  8100. let currentSize = 0;
  8101. for (let index = 0; index < length; index++) {
  8102. const key = plus.storage.key(index);
  8103. if (key !== STORAGE_KEYS && key.indexOf(STORAGE_DATA_TYPE) + STORAGE_DATA_TYPE.length !== key.length) {
  8104. const value = plus.storage.getItem(key);
  8105. currentSize += key.length + value.length;
  8106. keys.push(key);
  8107. }
  8108. }
  8109. return {
  8110. keys,
  8111. currentSize: Math.ceil(currentSize * 2 / 1024),
  8112. limitSize: Number.MAX_VALUE,
  8113. errMsg: 'getStorageInfo:ok'
  8114. }
  8115. }
  8116. function getStorageInfoSync () {
  8117. const res = getStorageInfo();
  8118. delete res.errMsg;
  8119. return res
  8120. }
  8121. function showKeyboard () {
  8122. plus.key.showSoftKeybord();
  8123. return {
  8124. errMsg: 'showKeyboard:ok'
  8125. }
  8126. }
  8127. function hideKeyboard () {
  8128. plus.key.hideSoftKeybord();
  8129. return {
  8130. errMsg: 'hideKeyboard:ok'
  8131. }
  8132. }
  8133. function setNavigationBarTitle$1 ({
  8134. title = ''
  8135. } = {}) {
  8136. const webview = getLastWebview();
  8137. if (webview) {
  8138. const style = webview.getStyle();
  8139. if (style && style.titleNView) {
  8140. webview.setStyle({
  8141. titleNView: {
  8142. titleText: title
  8143. }
  8144. });
  8145. }
  8146. return {
  8147. errMsg: 'setNavigationBarTitle:ok'
  8148. }
  8149. }
  8150. return {
  8151. errMsg: 'setNavigationBarTitle:fail'
  8152. }
  8153. }
  8154. function showNavigationBarLoading () {
  8155. plus.nativeUI.showWaiting('', {
  8156. modal: false
  8157. });
  8158. return {
  8159. errMsg: 'showNavigationBarLoading:ok'
  8160. }
  8161. }
  8162. function hideNavigationBarLoading () {
  8163. plus.nativeUI.closeWaiting();
  8164. return {
  8165. errMsg: 'hideNavigationBarLoading:ok'
  8166. }
  8167. }
  8168. function setNavigationBarColor$1 ({
  8169. frontColor,
  8170. backgroundColor
  8171. } = {}) {
  8172. const webview = getLastWebview();
  8173. if (webview) {
  8174. const styles = {};
  8175. if (frontColor) {
  8176. styles.titleColor = frontColor;
  8177. }
  8178. if (backgroundColor) {
  8179. styles.backgroundColor = backgroundColor;
  8180. }
  8181. plus.navigator.setStatusBarStyle(frontColor === '#000000' ? 'dark' : 'light');
  8182. const style = webview.getStyle();
  8183. if (style && style.titleNView) {
  8184. if (style.titleNView.autoBackButton) {
  8185. styles.backButton = styles.backButton || {};
  8186. styles.backButton.color = frontColor;
  8187. }
  8188. webview.setStyle({
  8189. titleNView: styles
  8190. });
  8191. }
  8192. return {
  8193. errMsg: 'setNavigationBarColor:ok'
  8194. }
  8195. }
  8196. return {
  8197. errMsg: 'setNavigationBarColor:fail'
  8198. }
  8199. }
  8200. let waiting;
  8201. let waitingTimeout;
  8202. let toast = false;
  8203. let toastTimeout;
  8204. function showLoading$1 (args) {
  8205. return callApiSync(showToast$1, args, 'showToast', 'showLoading')
  8206. }
  8207. function hideLoading () {
  8208. return callApiSync(hideToast, Object.create(null), 'hideToast', 'hideLoading')
  8209. }
  8210. function showToast$1 ({
  8211. title = '',
  8212. icon = 'success',
  8213. image = '',
  8214. duration = 1500,
  8215. mask = false,
  8216. position = ''
  8217. } = {}) {
  8218. if (position) {
  8219. if (toast) {
  8220. toastTimeout && clearTimeout(toastTimeout);
  8221. plus.nativeUI.closeToast();
  8222. }
  8223. if (waiting) {
  8224. waitingTimeout && clearTimeout(waitingTimeout);
  8225. waiting.close();
  8226. }
  8227. if (~['top', 'center', 'bottom'].indexOf(position)) {
  8228. const richText = `<span>${title}</span>`;
  8229. plus.nativeUI.toast(richText, {
  8230. verticalAlign: position,
  8231. type: 'richtext'
  8232. });
  8233. toast = true;
  8234. toastTimeout = setTimeout(() => {
  8235. hideToast();
  8236. }, 2000);
  8237. return {
  8238. errMsg: 'showToast:ok'
  8239. }
  8240. }
  8241. console.warn('uni.showToast 传入的 "position" 值 "' + position + '" 无效');
  8242. }
  8243. if (duration) {
  8244. if (waiting) {
  8245. waitingTimeout && clearTimeout(waitingTimeout);
  8246. waiting.close();
  8247. }
  8248. if (toast) {
  8249. toastTimeout && clearTimeout(toastTimeout);
  8250. plus.nativeUI.closeToast();
  8251. }
  8252. if (icon && !~['success', 'loading', 'none'].indexOf(icon)) {
  8253. icon = 'success';
  8254. }
  8255. const waitingOptions = {
  8256. modal: mask,
  8257. back: 'transmit',
  8258. padding: '10px',
  8259. size: '16px' // 固定字体大小
  8260. };
  8261. if (!image && (!icon || icon === 'none')) { // 无图
  8262. // waitingOptions.width = '120px'
  8263. // waitingOptions.height = '40px'
  8264. waitingOptions.loading = {
  8265. display: 'none'
  8266. };
  8267. } else { // 有图
  8268. waitingOptions.width = '140px';
  8269. waitingOptions.height = '112px';
  8270. }
  8271. if (image) {
  8272. waitingOptions.loading = {
  8273. display: 'block',
  8274. height: '55px',
  8275. icon: image,
  8276. interval: duration
  8277. };
  8278. } else {
  8279. if (icon === 'success') {
  8280. waitingOptions.loading = {
  8281. display: 'block',
  8282. height: '55px',
  8283. icon: '__uniappsuccess.png',
  8284. interval: duration
  8285. };
  8286. }
  8287. }
  8288. waiting = plus.nativeUI.showWaiting(title, waitingOptions);
  8289. waitingTimeout = setTimeout(() => {
  8290. hideToast();
  8291. }, duration);
  8292. }
  8293. return {
  8294. errMsg: 'showToast:ok'
  8295. }
  8296. }
  8297. function hideToast () {
  8298. if (toast) {
  8299. toastTimeout && clearTimeout(toastTimeout);
  8300. plus.nativeUI.closeToast();
  8301. toast = false;
  8302. }
  8303. if (waiting) {
  8304. waitingTimeout && clearTimeout(waitingTimeout);
  8305. waiting.close();
  8306. waiting = null;
  8307. waitingTimeout = null;
  8308. }
  8309. return {
  8310. errMsg: 'hideToast:ok'
  8311. }
  8312. }
  8313. function showModal$1 ({
  8314. title = '',
  8315. content = '',
  8316. showCancel = true,
  8317. cancelText = '取消',
  8318. cancelColor = '#000000',
  8319. confirmText = '确定',
  8320. confirmColor = '#3CC51F'
  8321. } = {}, callbackId) {
  8322. content = content || ' ';
  8323. plus.nativeUI.confirm(content, (e) => {
  8324. if (showCancel) {
  8325. invoke$1(callbackId, {
  8326. errMsg: 'showModal:ok',
  8327. confirm: e.index === 1,
  8328. cancel: e.index === 0 || e.index === -1
  8329. });
  8330. } else {
  8331. invoke$1(callbackId, {
  8332. errMsg: 'showModal:ok',
  8333. confirm: e.index === 0,
  8334. cancel: false
  8335. });
  8336. }
  8337. }, title, showCancel ? [cancelText, confirmText] : [confirmText]);
  8338. }
  8339. function showActionSheet$1 ({
  8340. itemList = [],
  8341. itemColor = '#000000',
  8342. title = '',
  8343. popover
  8344. }, callbackId) {
  8345. const options = {
  8346. buttons: itemList.map(item => ({
  8347. title: item,
  8348. color: itemColor
  8349. }))
  8350. };
  8351. if (title) {
  8352. options.title = title;
  8353. }
  8354. if (plus.os.name === 'iOS') {
  8355. options.cancel = '';
  8356. }
  8357. plus.nativeUI.actionSheet(Object.assign(options, { popover }), (e) => {
  8358. if (e.index > 0) {
  8359. invoke$1(callbackId, {
  8360. errMsg: 'showActionSheet:ok',
  8361. tapIndex: e.index - 1
  8362. });
  8363. } else {
  8364. invoke$1(callbackId, {
  8365. errMsg: 'showActionSheet:fail cancel'
  8366. });
  8367. }
  8368. });
  8369. }
  8370. let webview$3;
  8371. function setPullDownRefreshPageId (pullDownRefreshWebview) {
  8372. if (typeof pullDownRefreshWebview === 'number') {
  8373. webview$3 = plus.webview.getWebviewById(String(pullDownRefreshWebview));
  8374. } else {
  8375. webview$3 = pullDownRefreshWebview;
  8376. }
  8377. }
  8378. function startPullDownRefresh () {
  8379. if (webview$3) {
  8380. webview$3.endPullToRefresh();
  8381. }
  8382. webview$3 = getLastWebview();
  8383. if (webview$3) {
  8384. webview$3.beginPullToRefresh();
  8385. return {
  8386. errMsg: 'startPullDownRefresh:ok'
  8387. }
  8388. }
  8389. return {
  8390. errMsg: 'startPullDownRefresh:fail'
  8391. }
  8392. }
  8393. function stopPullDownRefresh () {
  8394. if (!webview$3) {
  8395. webview$3 = getLastWebview();
  8396. }
  8397. if (webview$3) {
  8398. webview$3.endPullToRefresh();
  8399. webview$3 = null;
  8400. return {
  8401. errMsg: 'stopPullDownRefresh:ok'
  8402. }
  8403. }
  8404. return {
  8405. errMsg: 'stopPullDownRefresh:fail'
  8406. }
  8407. }
  8408. function setTabBarBadge$2 ({
  8409. index,
  8410. text,
  8411. type = 'text'
  8412. }) {
  8413. tabBar$1.setTabBarBadge(type, index, text);
  8414. return {
  8415. errMsg: 'setTabBarBadge:ok'
  8416. }
  8417. }
  8418. function setTabBarItem$2 ({
  8419. index,
  8420. text,
  8421. iconPath,
  8422. selectedIconPath
  8423. }) {
  8424. if (!isTabBarPage()) {
  8425. return {
  8426. errMsg: 'setTabBarItem:fail not TabBar page'
  8427. }
  8428. }
  8429. tabBar$1.setTabBarItem(index, text, iconPath, selectedIconPath);
  8430. return {
  8431. errMsg: 'setTabBarItem:ok'
  8432. }
  8433. }
  8434. function setTabBarStyle$2 (style = {}) {
  8435. if (!isTabBarPage()) {
  8436. return {
  8437. errMsg: 'setTabBarStyle:fail not TabBar page'
  8438. }
  8439. }
  8440. const borderStyles = {
  8441. black: 'rgba(0,0,0,0.4)',
  8442. white: 'rgba(255,255,255,0.4)'
  8443. };
  8444. const borderStyle = style.borderStyle;
  8445. if (borderStyle in borderStyles) {
  8446. style.borderStyle = borderStyles[borderStyle];
  8447. }
  8448. tabBar$1.setTabBarStyle(style);
  8449. return {
  8450. errMsg: 'setTabBarStyle:ok'
  8451. }
  8452. }
  8453. function hideTabBar$2 ({
  8454. animation
  8455. }) {
  8456. if (!isTabBarPage()) {
  8457. return {
  8458. errMsg: 'hideTabBar:fail not TabBar page'
  8459. }
  8460. }
  8461. tabBar$1.hideTabBar(animation);
  8462. return {
  8463. errMsg: 'hideTabBar:ok'
  8464. }
  8465. }
  8466. function showTabBar$2 ({
  8467. animation
  8468. }) {
  8469. if (!isTabBarPage()) {
  8470. return {
  8471. errMsg: 'showTabBar:fail not TabBar page'
  8472. }
  8473. }
  8474. tabBar$1.showTabBar(animation);
  8475. return {
  8476. errMsg: 'showTabBar:ok'
  8477. }
  8478. }
  8479. const callbacks$4 = {};
  8480. function createCallbacks (namespace) {
  8481. let scopedCallbacks = callbacks$4[namespace];
  8482. if (!scopedCallbacks) {
  8483. scopedCallbacks = {
  8484. id: 1,
  8485. callbacks: Object.create(null)
  8486. };
  8487. callbacks$4[namespace] = scopedCallbacks;
  8488. }
  8489. return {
  8490. get (id) {
  8491. return scopedCallbacks.callbacks[id]
  8492. },
  8493. pop (id) {
  8494. const callback = scopedCallbacks.callbacks[id];
  8495. if (callback) {
  8496. delete scopedCallbacks.callbacks[id];
  8497. }
  8498. return callback
  8499. },
  8500. push (callback) {
  8501. const id = scopedCallbacks.id++;
  8502. scopedCallbacks.callbacks[id] = callback;
  8503. return id
  8504. }
  8505. }
  8506. }
  8507. const requestComponentInfoCallbacks = createCallbacks('requestComponentInfo');
  8508. function requestComponentInfo (pageVm, queue, callback) {
  8509. UniServiceJSBridge.publishHandler('requestComponentInfo', {
  8510. reqId: requestComponentInfoCallbacks.push(callback),
  8511. reqs: queue
  8512. }, pageVm.$page.id);
  8513. }
  8514. function parseDataset (attr) {
  8515. const dataset = {};
  8516. Object.keys(attr || {}).forEach(key => {
  8517. if (key.indexOf('data') === 0) {
  8518. let str = key.replace('data', '');
  8519. str = str.charAt(0).toLowerCase() + str.slice(1);
  8520. dataset[str] = attr[key];
  8521. }
  8522. });
  8523. return dataset
  8524. }
  8525. function findAttrs (ids, elm, result) {
  8526. const nodes = elm.children;
  8527. if (!Array.isArray(nodes)) {
  8528. return false
  8529. }
  8530. for (let i = 0; i < nodes.length; i++) {
  8531. const node = nodes[i];
  8532. if (node.attr) {
  8533. const index = ids.indexOf(node.attr.id);
  8534. if (index >= 0) {
  8535. result[index] = {
  8536. id: ids[index],
  8537. ref: node.ref,
  8538. dataset: parseDataset(node.attr)
  8539. };
  8540. if (ids.length === 1) {
  8541. break
  8542. }
  8543. }
  8544. }
  8545. if (node.children) {
  8546. findAttrs(ids, node, result);
  8547. }
  8548. }
  8549. }
  8550. function getSelectors (queue) {
  8551. const ids = [];
  8552. for (let i = 0; i < queue.length; i++) {
  8553. const selector = queue[i].selector;
  8554. if (selector.indexOf('#') === 0) {
  8555. ids.push(selector.substring(1));
  8556. }
  8557. }
  8558. return ids
  8559. }
  8560. function getComponentRectAll (dom, attrs, index, result, callback) {
  8561. const attr = attrs[index];
  8562. dom.getComponentRect(attr.ref, option => {
  8563. option.size.id = attr.id;
  8564. option.size.dataset = attr.dataset;
  8565. result.push(option.size);
  8566. index += 1;
  8567. if (index < attrs.length) {
  8568. getComponentRectAll(dom, attrs, index, result, callback);
  8569. } else {
  8570. callback(result);
  8571. }
  8572. });
  8573. }
  8574. function requestComponentInfo$1 (pageVm, queue, callback) {
  8575. // TODO 重构,逻辑不对,queue 里的每一项可能有单独的作用域查找(即 component)
  8576. const dom = pageVm._$weex.requireModule('dom');
  8577. const selectors = getSelectors(queue);
  8578. const outAttrs = new Array(selectors.length);
  8579. findAttrs(selectors, pageVm.$el, outAttrs);
  8580. getComponentRectAll(dom, outAttrs, 0, [], (result) => {
  8581. callback(result);
  8582. });
  8583. }
  8584. function requestComponentInfo$2 (pageVm, queue, callback) {
  8585. pageVm.$page.meta.isNVue
  8586. ? requestComponentInfo$1(pageVm, queue, callback)
  8587. : requestComponentInfo(pageVm, queue, callback);
  8588. }
  8589. const eventNames = [
  8590. 'load',
  8591. 'close',
  8592. 'verify',
  8593. 'error'
  8594. ];
  8595. const ERROR_CODE_LIST = [-5001, -5002, -5003, -5004, -5005, -5006];
  8596. class RewardedVideoAd {
  8597. constructor (options = {}) {
  8598. const _callbacks = this._callbacks = {};
  8599. eventNames.forEach(item => {
  8600. _callbacks[item] = [];
  8601. const name = item[0].toUpperCase() + item.substr(1);
  8602. this[`on${name}`] = function (callback) {
  8603. _callbacks[item].push(callback);
  8604. };
  8605. });
  8606. this._isLoad = false;
  8607. this._adError = '';
  8608. this._loadPromiseResolve = null;
  8609. this._loadPromiseReject = null;
  8610. const rewardAd = this._rewardAd = plus.ad.createRewardedVideoAd(options);
  8611. rewardAd.onLoad((e) => {
  8612. this._isLoad = true;
  8613. this._dispatchEvent('load', {});
  8614. if (this._loadPromiseResolve != null) {
  8615. this._loadPromiseResolve();
  8616. this._loadPromiseResolve = null;
  8617. }
  8618. });
  8619. rewardAd.onClose((e) => {
  8620. this._loadAd();
  8621. this._dispatchEvent('close', { isEnded: e.isEnded });
  8622. });
  8623. rewardAd.onVerify && rewardAd.onVerify((e) => {
  8624. this._dispatchEvent('verify', { isValid: e.isValid });
  8625. });
  8626. rewardAd.onError((e) => {
  8627. const { code, message } = e;
  8628. const data = { code: code, errMsg: message };
  8629. this._adError = message;
  8630. this._dispatchEvent('error', data);
  8631. if ((code === -5005 || ERROR_CODE_LIST.index(code) === -1) && this._loadPromiseReject != null) {
  8632. this._loadPromiseReject(data);
  8633. this._loadPromiseReject = null;
  8634. }
  8635. });
  8636. this._loadAd();
  8637. }
  8638. load () {
  8639. return new Promise((resolve, reject) => {
  8640. if (this._isLoad) {
  8641. resolve();
  8642. return
  8643. }
  8644. this._loadPromiseResolve = resolve;
  8645. this._loadPromiseReject = reject;
  8646. this._loadAd();
  8647. })
  8648. }
  8649. show () {
  8650. return new Promise((resolve, reject) => {
  8651. if (this._isLoad) {
  8652. this._rewardAd.show();
  8653. resolve();
  8654. } else {
  8655. reject(new Error(this._adError));
  8656. }
  8657. })
  8658. }
  8659. getProvider () {
  8660. return this._rewardAd.getProvider()
  8661. }
  8662. destroy () {
  8663. this._rewardAd.destroy();
  8664. }
  8665. _loadAd () {
  8666. this._isLoad = false;
  8667. this._rewardAd.load();
  8668. }
  8669. _dispatchEvent (name, data) {
  8670. this._callbacks[name].forEach(callback => {
  8671. if (typeof callback === 'function') {
  8672. callback(data || {});
  8673. }
  8674. });
  8675. }
  8676. }
  8677. function createRewardedVideoAd (options) {
  8678. return new RewardedVideoAd(options)
  8679. }
  8680. var api = /*#__PURE__*/Object.freeze({
  8681. __proto__: null,
  8682. startPullDownRefresh: startPullDownRefresh,
  8683. stopPullDownRefresh: stopPullDownRefresh,
  8684. $on: $on$1,
  8685. $off: $off$1,
  8686. $once: $once$1,
  8687. $emit: $emit$1,
  8688. createAudioInstance: createAudioInstance,
  8689. destroyAudioInstance: destroyAudioInstance,
  8690. setAudioState: setAudioState,
  8691. getAudioState: getAudioState,
  8692. operateAudio: operateAudio,
  8693. getMusicPlayerState: getMusicPlayerState,
  8694. operateMusicPlayer: operateMusicPlayer,
  8695. setBackgroundAudioState: setBackgroundAudioState,
  8696. operateBackgroundAudio: operateBackgroundAudio,
  8697. getBackgroundAudioState: getBackgroundAudioState,
  8698. base64ToTempFilePath: base64ToTempFilePath,
  8699. operateMapPlayer: operateMapPlayer$2,
  8700. operateVideoPlayer: operateVideoPlayer$2,
  8701. createLivePusherContext: createLivePusherContext$1,
  8702. enableAccelerometer: enableAccelerometer,
  8703. addPhoneContact: addPhoneContact,
  8704. openBluetoothAdapter: openBluetoothAdapter,
  8705. closeBluetoothAdapter: closeBluetoothAdapter,
  8706. getBluetoothAdapterState: getBluetoothAdapterState,
  8707. startBluetoothDevicesDiscovery: startBluetoothDevicesDiscovery,
  8708. stopBluetoothDevicesDiscovery: stopBluetoothDevicesDiscovery,
  8709. getBluetoothDevices: getBluetoothDevices,
  8710. getConnectedBluetoothDevices: getConnectedBluetoothDevices,
  8711. createBLEConnection: createBLEConnection,
  8712. closeBLEConnection: closeBLEConnection,
  8713. getBLEDeviceServices: getBLEDeviceServices,
  8714. getBLEDeviceCharacteristics: getBLEDeviceCharacteristics,
  8715. notifyBLECharacteristicValueChange: notifyBLECharacteristicValueChange,
  8716. notifyBLECharacteristicValueChanged: notifyBLECharacteristicValueChanged,
  8717. readBLECharacteristicValue: readBLECharacteristicValue,
  8718. writeBLECharacteristicValue: writeBLECharacteristicValue,
  8719. getScreenBrightness: getScreenBrightness,
  8720. setScreenBrightness: setScreenBrightness,
  8721. setKeepScreenOn: setKeepScreenOn,
  8722. getClipboardData: getClipboardData,
  8723. setClipboardData: setClipboardData$1,
  8724. enableCompass: enableCompass,
  8725. getNetworkType: getNetworkType,
  8726. onBeaconUpdate: onBeaconUpdate,
  8727. onBeaconServiceChange: onBeaconServiceChange,
  8728. getBeacons: getBeacons,
  8729. startBeaconDiscovery: startBeaconDiscovery,
  8730. stopBeaconDiscovery: stopBeaconDiscovery,
  8731. makePhoneCall: makePhoneCall$1,
  8732. scanCode: scanCode$2,
  8733. checkIsSupportSoterAuthentication: checkIsSupportSoterAuthentication,
  8734. checkIsSoterEnrolledInDevice: checkIsSoterEnrolledInDevice,
  8735. startSoterAuthentication: startSoterAuthentication,
  8736. getSystemInfoSync: getSystemInfoSync,
  8737. getSystemInfo: getSystemInfo,
  8738. vibrateLong: vibrateLong,
  8739. vibrateShort: vibrateShort,
  8740. saveFile: saveFile,
  8741. getSavedFileList: getSavedFileList,
  8742. getFileInfo: getFileInfo,
  8743. getSavedFileInfo: getSavedFileInfo,
  8744. removeSavedFile: removeSavedFile,
  8745. openDocument: openDocument$1,
  8746. chooseLocation: chooseLocation$3,
  8747. getLocation: getLocation$1,
  8748. openLocation: openLocation$3,
  8749. startRecord: startRecord,
  8750. stopRecord: stopRecord,
  8751. playVoice: playVoice,
  8752. pauseVoice: pauseVoice,
  8753. stopVoice: stopVoice,
  8754. chooseImage: chooseImage$1,
  8755. chooseVideo: chooseVideo$1,
  8756. compressImage: compressImage,
  8757. getImageInfo: getImageInfo$1,
  8758. previewImagePlus: previewImagePlus,
  8759. operateRecorder: operateRecorder,
  8760. saveImageToPhotosAlbum: saveImageToPhotosAlbum$1,
  8761. saveVideoToPhotosAlbum: saveVideoToPhotosAlbum,
  8762. operateDownloadTask: operateDownloadTask,
  8763. createDownloadTask: createDownloadTask,
  8764. createRequestTaskById: createRequestTaskById,
  8765. createRequestTask: createRequestTask,
  8766. operateRequestTask: operateRequestTask,
  8767. createSocketTask: createSocketTask,
  8768. operateSocketTask: operateSocketTask,
  8769. operateUploadTask: operateUploadTask,
  8770. createUploadTask: createUploadTask,
  8771. getProvider: getProvider$1,
  8772. login: login,
  8773. getUserInfo: getUserInfo,
  8774. operateWXData: operateWXData,
  8775. requestPayment: requestPayment,
  8776. subscribePush: subscribePush,
  8777. unsubscribePush: unsubscribePush,
  8778. onPush: onPush,
  8779. offPush: offPush,
  8780. requireNativePlugin: requireNativePlugin$1,
  8781. shareAppMessageDirectly: shareAppMessageDirectly,
  8782. share: share,
  8783. shareWithSystem: shareWithSystem,
  8784. restoreGlobal: restoreGlobal,
  8785. getSubNVueById: getSubNVueById,
  8786. getCurrentSubNVue: getCurrentSubNVue,
  8787. onNativeEventReceive: onNativeEventReceive,
  8788. sendNativeEvent: sendNativeEvent,
  8789. navigateBack: navigateBack$1,
  8790. navigateTo: navigateTo$1,
  8791. reLaunch: reLaunch$1,
  8792. redirectTo: redirectTo$1,
  8793. switchTab: switchTab$1,
  8794. setStorage: setStorage$1,
  8795. setStorageSync: setStorageSync$1,
  8796. getStorage: getStorage$1,
  8797. getStorageSync: getStorageSync$1,
  8798. removeStorage: removeStorage$1,
  8799. removeStorageSync: removeStorageSync$1,
  8800. clearStorage: clearStorage,
  8801. clearStorageSync: clearStorageSync,
  8802. getStorageInfo: getStorageInfo,
  8803. getStorageInfoSync: getStorageInfoSync,
  8804. showKeyboard: showKeyboard,
  8805. hideKeyboard: hideKeyboard,
  8806. setNavigationBarTitle: setNavigationBarTitle$1,
  8807. showNavigationBarLoading: showNavigationBarLoading,
  8808. hideNavigationBarLoading: hideNavigationBarLoading,
  8809. setNavigationBarColor: setNavigationBarColor$1,
  8810. showLoading: showLoading$1,
  8811. hideLoading: hideLoading,
  8812. showToast: showToast$1,
  8813. hideToast: hideToast,
  8814. showModal: showModal$1,
  8815. showActionSheet: showActionSheet$1,
  8816. setTabBarBadge: setTabBarBadge$2,
  8817. setTabBarItem: setTabBarItem$2,
  8818. setTabBarStyle: setTabBarStyle$2,
  8819. hideTabBar: hideTabBar$2,
  8820. showTabBar: showTabBar$2,
  8821. requestComponentInfo: requestComponentInfo$2,
  8822. createRewardedVideoAd: createRewardedVideoAd
  8823. });
  8824. var platformApi = Object.assign(Object.create(null), api, eventApis);
  8825. /**
  8826. * 执行内部平台方法
  8827. */
  8828. function invokeMethod (name, ...args) {
  8829. return platformApi[name].apply(null, args)
  8830. }
  8831. /**
  8832. * 监听 service 层内部平台方法回调,与 publish 对应
  8833. * @param {Object} name
  8834. * @param {Object} callback
  8835. */
  8836. function onMethod (name, callback) {
  8837. return UniServiceJSBridge.on('api.' + name, callback)
  8838. }
  8839. function getCurrentPageVm (method) {
  8840. const pages = getCurrentPages();
  8841. const len = pages.length;
  8842. if (!len) {
  8843. UniServiceJSBridge.emit('onError', `${method}:fail`);
  8844. }
  8845. const page = pages[len - 1];
  8846. return page.$vm
  8847. }
  8848. function getCurrentPageId () {
  8849. const pages = getCurrentPages();
  8850. const page = pages[pages.length - 1];
  8851. return page && page.$page.id
  8852. }
  8853. const eventNames$1 = [
  8854. 'canplay',
  8855. 'play',
  8856. 'pause',
  8857. 'stop',
  8858. 'ended',
  8859. 'timeUpdate',
  8860. 'error',
  8861. 'waiting',
  8862. 'seeking',
  8863. 'seeked'
  8864. ];
  8865. const props = [
  8866. {
  8867. name: 'src',
  8868. cache: true
  8869. },
  8870. {
  8871. name: 'startTime',
  8872. default: 0,
  8873. cache: true
  8874. },
  8875. {
  8876. name: 'autoplay',
  8877. default: false,
  8878. cache: true
  8879. },
  8880. {
  8881. name: 'loop',
  8882. default: false,
  8883. cache: true
  8884. },
  8885. {
  8886. name: 'obeyMuteSwitch',
  8887. default: true,
  8888. readonly: true,
  8889. cache: true
  8890. },
  8891. {
  8892. name: 'duration',
  8893. readonly: true
  8894. },
  8895. {
  8896. name: 'currentTime',
  8897. readonly: true
  8898. },
  8899. {
  8900. name: 'paused',
  8901. readonly: true
  8902. },
  8903. {
  8904. name: 'buffered',
  8905. readonly: true
  8906. },
  8907. {
  8908. name: 'volume'
  8909. }
  8910. ];
  8911. class InnerAudioContext {
  8912. constructor (id) {
  8913. this.id = id;
  8914. this._callbacks = {};
  8915. this._options = {};
  8916. eventNames$1.forEach(name => {
  8917. this._callbacks[name.toLowerCase()] = [];
  8918. });
  8919. props.forEach(item => {
  8920. const name = item.name;
  8921. const data = {
  8922. get () {
  8923. const result = item.cache ? this._options : invokeMethod('getAudioState', {
  8924. audioId: this.id
  8925. });
  8926. const value = name in result ? result[name] : item.default;
  8927. return typeof value === 'number' && name !== 'volume' ? value / 1e3 : value
  8928. }
  8929. };
  8930. if (!item.readonly) {
  8931. data.set = function (value) {
  8932. this._options[name] = value;
  8933. invokeMethod('setAudioState', Object.assign({}, this._options, {
  8934. audioId: this.id
  8935. }));
  8936. };
  8937. }
  8938. Object.defineProperty(this, name, data);
  8939. });
  8940. }
  8941. play () {
  8942. this._operate('play');
  8943. }
  8944. pause () {
  8945. this._operate('pause');
  8946. }
  8947. stop () {
  8948. this._operate('stop');
  8949. }
  8950. seek (position) {
  8951. this._operate('seek', {
  8952. currentTime: position * 1e3
  8953. });
  8954. }
  8955. destroy () {
  8956. clearInterval(this.__timing);
  8957. invokeMethod('destroyAudioInstance', {
  8958. audioId: this.id
  8959. });
  8960. delete innerAudioContexts[this.id];
  8961. }
  8962. _operate (type, options) {
  8963. invokeMethod('operateAudio', Object.assign({}, options, {
  8964. audioId: this.id,
  8965. operationType: type
  8966. }));
  8967. }
  8968. }
  8969. eventNames$1.forEach(item => {
  8970. const name = item[0].toUpperCase() + item.substr(1);
  8971. item = item.toLowerCase();
  8972. InnerAudioContext.prototype[`on${name}`] = function (callback) {
  8973. this._callbacks[item].push(callback);
  8974. };
  8975. InnerAudioContext.prototype[`off${name}`] = function (callback) {
  8976. const callbacks = this._callbacks[item];
  8977. const index = callbacks.indexOf(callback);
  8978. if (index >= 0) {
  8979. callbacks.splice(index, 1);
  8980. }
  8981. };
  8982. });
  8983. function emit (audio, state, errMsg, errCode) {
  8984. audio._callbacks[state].forEach(callback => {
  8985. if (typeof callback === 'function') {
  8986. callback(state === 'error' ? {
  8987. errMsg,
  8988. errCode
  8989. } : {});
  8990. }
  8991. });
  8992. }
  8993. onMethod('onAudioStateChange', ({
  8994. state,
  8995. audioId,
  8996. errMsg,
  8997. errCode
  8998. }) => {
  8999. const audio = innerAudioContexts[audioId];
  9000. if (audio) {
  9001. emit(audio, state, errMsg, errCode);
  9002. if (state === 'play') {
  9003. const oldCurrentTime = audio.currentTime;
  9004. audio.__timing = setInterval(() => {
  9005. const currentTime = audio.currentTime;
  9006. if (currentTime !== oldCurrentTime) {
  9007. emit(audio, 'timeupdate');
  9008. }
  9009. }, 200);
  9010. } else if (state === 'pause' || state === 'stop' || state === 'error') {
  9011. clearInterval(audio.__timing);
  9012. }
  9013. }
  9014. });
  9015. const innerAudioContexts = Object.create(null);
  9016. function createInnerAudioContext () {
  9017. const {
  9018. audioId
  9019. } = invokeMethod('createAudioInstance');
  9020. const innerAudioContext = new InnerAudioContext(audioId);
  9021. innerAudioContexts[audioId] = innerAudioContext;
  9022. return innerAudioContext
  9023. }
  9024. var require_context_module_1_4 = /*#__PURE__*/Object.freeze({
  9025. __proto__: null,
  9026. createInnerAudioContext: createInnerAudioContext
  9027. });
  9028. const eventNames$2 = [
  9029. 'canplay',
  9030. 'play',
  9031. 'pause',
  9032. 'stop',
  9033. 'ended',
  9034. 'timeUpdate',
  9035. 'prev',
  9036. 'next',
  9037. 'error',
  9038. 'waiting'
  9039. ];
  9040. const callbacks$5 = {};
  9041. eventNames$2.forEach(name => {
  9042. callbacks$5[name] = [];
  9043. });
  9044. const props$1 = [
  9045. {
  9046. name: 'duration',
  9047. readonly: true
  9048. },
  9049. {
  9050. name: 'currentTime',
  9051. readonly: true
  9052. },
  9053. {
  9054. name: 'paused',
  9055. readonly: true
  9056. },
  9057. {
  9058. name: 'src',
  9059. cache: true
  9060. },
  9061. {
  9062. name: 'startTime',
  9063. default: 0,
  9064. cache: true
  9065. },
  9066. {
  9067. name: 'buffered',
  9068. readonly: true
  9069. },
  9070. {
  9071. name: 'title',
  9072. cache: true
  9073. },
  9074. {
  9075. name: 'epname',
  9076. cache: true
  9077. },
  9078. {
  9079. name: 'singer',
  9080. cache: true
  9081. },
  9082. {
  9083. name: 'coverImgUrl',
  9084. cache: true
  9085. },
  9086. {
  9087. name: 'webUrl',
  9088. cache: true
  9089. },
  9090. {
  9091. name: 'protocol',
  9092. readonly: true,
  9093. default: 'http'
  9094. }
  9095. ];
  9096. class BackgroundAudioManager {
  9097. constructor () {
  9098. this._options = {};
  9099. onMethod('onBackgroundAudioStateChange', ({
  9100. state,
  9101. errMsg,
  9102. errCode
  9103. }) => {
  9104. callbacks$5[state].forEach(callback => {
  9105. if (typeof callback === 'function') {
  9106. callback(state === 'error' ? {
  9107. errMsg,
  9108. errCode
  9109. } : {});
  9110. }
  9111. });
  9112. });
  9113. props$1.forEach(item => {
  9114. const name = item.name;
  9115. const data = {
  9116. get () {
  9117. const result = item.cache ? this._options : invokeMethod('getBackgroundAudioState');
  9118. return name in result ? result[name] : item.default
  9119. }
  9120. };
  9121. if (!item.readonly) {
  9122. data.set = function (value) {
  9123. this._options[name] = value;
  9124. invokeMethod('setBackgroundAudioState', Object.assign({}, this._options, {
  9125. audioId: this.id
  9126. }));
  9127. };
  9128. }
  9129. Object.defineProperty(this, name, data);
  9130. });
  9131. }
  9132. play () {
  9133. this._operate('play');
  9134. }
  9135. pause () {
  9136. this._operate('pause');
  9137. }
  9138. stop () {
  9139. this._operate('stop');
  9140. }
  9141. seek (position) {
  9142. this._operate('seek', {
  9143. currentTime: position
  9144. });
  9145. }
  9146. _operate (type, options) {
  9147. invokeMethod('operateBackgroundAudio', Object.assign({}, options, {
  9148. operationType: type
  9149. }));
  9150. }
  9151. }
  9152. eventNames$2.forEach(item => {
  9153. const name = item[0].toUpperCase() + item.substr(1);
  9154. BackgroundAudioManager.prototype[`on${name}`] = function (callback) {
  9155. callbacks$5[item].push(callback);
  9156. };
  9157. });
  9158. let backgroundAudioManager;
  9159. function getBackgroundAudioManager () {
  9160. return backgroundAudioManager || (backgroundAudioManager = new BackgroundAudioManager())
  9161. }
  9162. var require_context_module_1_5 = /*#__PURE__*/Object.freeze({
  9163. __proto__: null,
  9164. getBackgroundAudioManager: getBackgroundAudioManager
  9165. });
  9166. const canvasEventCallbacks = createCallbacks('canvasEvent');
  9167. UniServiceJSBridge.subscribe('onDrawCanvas', ({
  9168. callbackId,
  9169. data
  9170. }) => {
  9171. const callback = canvasEventCallbacks.pop(callbackId);
  9172. if (callback) {
  9173. callback(data);
  9174. }
  9175. });
  9176. UniServiceJSBridge.subscribe('onCanvasMethodCallback', ({
  9177. callbackId,
  9178. data
  9179. }) => {
  9180. const callback = canvasEventCallbacks.pop(callbackId);
  9181. if (callback) {
  9182. callback(data);
  9183. }
  9184. });
  9185. function operateCanvas (canvasId, pageId, type, data) {
  9186. UniServiceJSBridge.publishHandler(pageId + '-canvas-' + canvasId, {
  9187. canvasId,
  9188. type,
  9189. data
  9190. }, pageId);
  9191. }
  9192. const predefinedColor = {
  9193. aliceblue: '#f0f8ff',
  9194. antiquewhite: '#faebd7',
  9195. aqua: '#00ffff',
  9196. aquamarine: '#7fffd4',
  9197. azure: '#f0ffff',
  9198. beige: '#f5f5dc',
  9199. bisque: '#ffe4c4',
  9200. black: '#000000',
  9201. blanchedalmond: '#ffebcd',
  9202. blue: '#0000ff',
  9203. blueviolet: '#8a2be2',
  9204. brown: '#a52a2a',
  9205. burlywood: '#deb887',
  9206. cadetblue: '#5f9ea0',
  9207. chartreuse: '#7fff00',
  9208. chocolate: '#d2691e',
  9209. coral: '#ff7f50',
  9210. cornflowerblue: '#6495ed',
  9211. cornsilk: '#fff8dc',
  9212. crimson: '#dc143c',
  9213. cyan: '#00ffff',
  9214. darkblue: '#00008b',
  9215. darkcyan: '#008b8b',
  9216. darkgoldenrod: '#b8860b',
  9217. darkgray: '#a9a9a9',
  9218. darkgrey: '#a9a9a9',
  9219. darkgreen: '#006400',
  9220. darkkhaki: '#bdb76b',
  9221. darkmagenta: '#8b008b',
  9222. darkolivegreen: '#556b2f',
  9223. darkorange: '#ff8c00',
  9224. darkorchid: '#9932cc',
  9225. darkred: '#8b0000',
  9226. darksalmon: '#e9967a',
  9227. darkseagreen: '#8fbc8f',
  9228. darkslateblue: '#483d8b',
  9229. darkslategray: '#2f4f4f',
  9230. darkslategrey: '#2f4f4f',
  9231. darkturquoise: '#00ced1',
  9232. darkviolet: '#9400d3',
  9233. deeppink: '#ff1493',
  9234. deepskyblue: '#00bfff',
  9235. dimgray: '#696969',
  9236. dimgrey: '#696969',
  9237. dodgerblue: '#1e90ff',
  9238. firebrick: '#b22222',
  9239. floralwhite: '#fffaf0',
  9240. forestgreen: '#228b22',
  9241. fuchsia: '#ff00ff',
  9242. gainsboro: '#dcdcdc',
  9243. ghostwhite: '#f8f8ff',
  9244. gold: '#ffd700',
  9245. goldenrod: '#daa520',
  9246. gray: '#808080',
  9247. grey: '#808080',
  9248. green: '#008000',
  9249. greenyellow: '#adff2f',
  9250. honeydew: '#f0fff0',
  9251. hotpink: '#ff69b4',
  9252. indianred: '#cd5c5c',
  9253. indigo: '#4b0082',
  9254. ivory: '#fffff0',
  9255. khaki: '#f0e68c',
  9256. lavender: '#e6e6fa',
  9257. lavenderblush: '#fff0f5',
  9258. lawngreen: '#7cfc00',
  9259. lemonchiffon: '#fffacd',
  9260. lightblue: '#add8e6',
  9261. lightcoral: '#f08080',
  9262. lightcyan: '#e0ffff',
  9263. lightgoldenrodyellow: '#fafad2',
  9264. lightgray: '#d3d3d3',
  9265. lightgrey: '#d3d3d3',
  9266. lightgreen: '#90ee90',
  9267. lightpink: '#ffb6c1',
  9268. lightsalmon: '#ffa07a',
  9269. lightseagreen: '#20b2aa',
  9270. lightskyblue: '#87cefa',
  9271. lightslategray: '#778899',
  9272. lightslategrey: '#778899',
  9273. lightsteelblue: '#b0c4de',
  9274. lightyellow: '#ffffe0',
  9275. lime: '#00ff00',
  9276. limegreen: '#32cd32',
  9277. linen: '#faf0e6',
  9278. magenta: '#ff00ff',
  9279. maroon: '#800000',
  9280. mediumaquamarine: '#66cdaa',
  9281. mediumblue: '#0000cd',
  9282. mediumorchid: '#ba55d3',
  9283. mediumpurple: '#9370db',
  9284. mediumseagreen: '#3cb371',
  9285. mediumslateblue: '#7b68ee',
  9286. mediumspringgreen: '#00fa9a',
  9287. mediumturquoise: '#48d1cc',
  9288. mediumvioletred: '#c71585',
  9289. midnightblue: '#191970',
  9290. mintcream: '#f5fffa',
  9291. mistyrose: '#ffe4e1',
  9292. moccasin: '#ffe4b5',
  9293. navajowhite: '#ffdead',
  9294. navy: '#000080',
  9295. oldlace: '#fdf5e6',
  9296. olive: '#808000',
  9297. olivedrab: '#6b8e23',
  9298. orange: '#ffa500',
  9299. orangered: '#ff4500',
  9300. orchid: '#da70d6',
  9301. palegoldenrod: '#eee8aa',
  9302. palegreen: '#98fb98',
  9303. paleturquoise: '#afeeee',
  9304. palevioletred: '#db7093',
  9305. papayawhip: '#ffefd5',
  9306. peachpuff: '#ffdab9',
  9307. peru: '#cd853f',
  9308. pink: '#ffc0cb',
  9309. plum: '#dda0dd',
  9310. powderblue: '#b0e0e6',
  9311. purple: '#800080',
  9312. rebeccapurple: '#663399',
  9313. red: '#ff0000',
  9314. rosybrown: '#bc8f8f',
  9315. royalblue: '#4169e1',
  9316. saddlebrown: '#8b4513',
  9317. salmon: '#fa8072',
  9318. sandybrown: '#f4a460',
  9319. seagreen: '#2e8b57',
  9320. seashell: '#fff5ee',
  9321. sienna: '#a0522d',
  9322. silver: '#c0c0c0',
  9323. skyblue: '#87ceeb',
  9324. slateblue: '#6a5acd',
  9325. slategray: '#708090',
  9326. slategrey: '#708090',
  9327. snow: '#fffafa',
  9328. springgreen: '#00ff7f',
  9329. steelblue: '#4682b4',
  9330. tan: '#d2b48c',
  9331. teal: '#008080',
  9332. thistle: '#d8bfd8',
  9333. tomato: '#ff6347',
  9334. turquoise: '#40e0d0',
  9335. violet: '#ee82ee',
  9336. wheat: '#f5deb3',
  9337. white: '#ffffff',
  9338. whitesmoke: '#f5f5f5',
  9339. yellow: '#ffff00',
  9340. yellowgreen: '#9acd32',
  9341. transparent: '#00000000'
  9342. };
  9343. function checkColor (e) {
  9344. // 其他开发者适配的echarts会传入一个undefined到这里
  9345. e = e || '#000000';
  9346. var t = null;
  9347. if ((t = /^#([0-9|A-F|a-f]{6})$/.exec(e)) != null) {
  9348. const n = parseInt(t[1].slice(0, 2), 16);
  9349. const o = parseInt(t[1].slice(2, 4), 16);
  9350. const r = parseInt(t[1].slice(4), 16);
  9351. return [n, o, r, 255]
  9352. }
  9353. if ((t = /^#([0-9|A-F|a-f]{3})$/.exec(e)) != null) {
  9354. let n = t[1].slice(0, 1);
  9355. let o = t[1].slice(1, 2);
  9356. let r = t[1].slice(2, 3);
  9357. n = parseInt(n + n, 16);
  9358. o = parseInt(o + o, 16);
  9359. r = parseInt(r + r, 16);
  9360. return [n, o, r, 255]
  9361. }
  9362. if ((t = /^rgb\((.+)\)$/.exec(e)) != null) {
  9363. return t[1].split(',').map(function (e) {
  9364. return Math.min(255, parseInt(e.trim()))
  9365. }).concat(255)
  9366. }
  9367. if ((t = /^rgba\((.+)\)$/.exec(e)) != null) {
  9368. return t[1].split(',').map(function (e, t) {
  9369. return t === 3 ? Math.floor(255 * parseFloat(e.trim())) : Math.min(255, parseInt(e.trim()))
  9370. })
  9371. }
  9372. var i = e.toLowerCase();
  9373. if (hasOwn(predefinedColor, i)) {
  9374. t = /^#([0-9|A-F|a-f]{6,8})$/.exec(predefinedColor[i]);
  9375. const n = parseInt(t[1].slice(0, 2), 16);
  9376. const o = parseInt(t[1].slice(2, 4), 16);
  9377. const r = parseInt(t[1].slice(4, 6), 16);
  9378. let a = parseInt(t[1].slice(6, 8), 16);
  9379. a = a >= 0 ? a : 255;
  9380. return [n, o, r, a]
  9381. }
  9382. console.group('非法颜色: ' + e);
  9383. console.error('不支持颜色:' + e);
  9384. console.groupEnd();
  9385. return [0, 0, 0, 255]
  9386. }
  9387. function Pattern (image, repetition) {
  9388. this.image = image;
  9389. this.repetition = repetition;
  9390. }
  9391. class CanvasGradient {
  9392. constructor (type, data) {
  9393. this.type = type;
  9394. this.data = data;
  9395. this.colorStop = [];
  9396. }
  9397. addColorStop (position, color) {
  9398. this.colorStop.push([position, checkColor(color)]);
  9399. }
  9400. }
  9401. var methods1 = ['scale', 'rotate', 'translate', 'setTransform', 'transform'];
  9402. var methods2 = ['drawImage', 'fillText', 'fill', 'stroke', 'fillRect', 'strokeRect', 'clearRect',
  9403. 'strokeText'
  9404. ];
  9405. var methods3 = ['setFillStyle', 'setTextAlign', 'setStrokeStyle', 'setGlobalAlpha', 'setShadow',
  9406. 'setFontSize', 'setLineCap', 'setLineJoin', 'setLineWidth', 'setMiterLimit',
  9407. 'setTextBaseline', 'setLineDash'
  9408. ];
  9409. var tempCanvas;
  9410. function getTempCanvas (width = 0, height = 0) {
  9411. if (!tempCanvas) {
  9412. tempCanvas = document.createElement('canvas');
  9413. }
  9414. tempCanvas.width = width;
  9415. tempCanvas.height = height;
  9416. return tempCanvas
  9417. }
  9418. function TextMetrics (width) {
  9419. this.width = width;
  9420. }
  9421. class CanvasContext {
  9422. constructor (id, pageId) {
  9423. this.id = id;
  9424. this.pageId = pageId;
  9425. this.actions = [];
  9426. this.path = [];
  9427. this.subpath = [];
  9428. this.currentTransform = [];
  9429. this.currentStepAnimates = [];
  9430. this.drawingState = [];
  9431. this.state = {
  9432. lineDash: [0, 0],
  9433. shadowOffsetX: 0,
  9434. shadowOffsetY: 0,
  9435. shadowBlur: 0,
  9436. shadowColor: [0, 0, 0, 0],
  9437. font: '10px sans-serif',
  9438. fontSize: 10,
  9439. fontWeight: 'normal',
  9440. fontStyle: 'normal',
  9441. fontFamily: 'sans-serif'
  9442. };
  9443. }
  9444. draw (reserve = false, callback) {
  9445. var actions = [...this.actions];
  9446. this.actions = [];
  9447. this.path = [];
  9448. var callbackId;
  9449. if (typeof callback === 'function') {
  9450. callbackId = canvasEventCallbacks.push(callback);
  9451. }
  9452. operateCanvas(this.id, this.pageId, 'actionsChanged', {
  9453. actions,
  9454. reserve,
  9455. callbackId
  9456. });
  9457. }
  9458. createLinearGradient (x0, y0, x1, y1) {
  9459. return new CanvasGradient('linear', [x0, y0, x1, y1])
  9460. }
  9461. createCircularGradient (x, y, r) {
  9462. return new CanvasGradient('radial', [x, y, r])
  9463. }
  9464. createPattern (image, repetition) {
  9465. if (undefined === repetition) {
  9466. console.error("Failed to execute 'createPattern' on 'CanvasContext': 2 arguments required, but only 1 present.");
  9467. } else if (['repeat', 'repeat-x', 'repeat-y', 'no-repeat'].indexOf(repetition) < 0) {
  9468. console.error("Failed to execute 'createPattern' on 'CanvasContext': The provided type ('" + repetition +
  9469. "') is not one of 'repeat', 'no-repeat', 'repeat-x', or 'repeat-y'.");
  9470. } else {
  9471. return new Pattern(image, repetition)
  9472. }
  9473. }
  9474. // TODO
  9475. measureText (text) {
  9476. if (typeof document === 'object') {
  9477. var c2d = getTempCanvas().getContext('2d');
  9478. c2d.font = this.state.font;
  9479. return new TextMetrics(c2d.measureText(text).width || 0)
  9480. } else {
  9481. return new TextMetrics(0)
  9482. }
  9483. }
  9484. save () {
  9485. this.actions.push({
  9486. method: 'save',
  9487. data: []
  9488. });
  9489. this.drawingState.push(this.state);
  9490. }
  9491. restore () {
  9492. this.actions.push({
  9493. method: 'restore',
  9494. data: []
  9495. });
  9496. this.state = this.drawingState.pop() || {
  9497. lineDash: [0, 0],
  9498. shadowOffsetX: 0,
  9499. shadowOffsetY: 0,
  9500. shadowBlur: 0,
  9501. shadowColor: [0, 0, 0, 0],
  9502. font: '10px sans-serif',
  9503. fontSize: 10,
  9504. fontWeight: 'normal',
  9505. fontStyle: 'normal',
  9506. fontFamily: 'sans-serif'
  9507. };
  9508. }
  9509. beginPath () {
  9510. this.path = [];
  9511. this.subpath = [];
  9512. }
  9513. moveTo (x, y) {
  9514. this.path.push({
  9515. method: 'moveTo',
  9516. data: [x, y]
  9517. });
  9518. this.subpath = [
  9519. [x, y]
  9520. ];
  9521. }
  9522. lineTo (x, y) {
  9523. if (this.path.length === 0 && this.subpath.length === 0) {
  9524. this.path.push({
  9525. method: 'moveTo',
  9526. data: [x, y]
  9527. });
  9528. } else {
  9529. this.path.push({
  9530. method: 'lineTo',
  9531. data: [x, y]
  9532. });
  9533. }
  9534. this.subpath.push([x, y]);
  9535. }
  9536. quadraticCurveTo (cpx, cpy, x, y) {
  9537. this.path.push({
  9538. method: 'quadraticCurveTo',
  9539. data: [cpx, cpy, x, y]
  9540. });
  9541. this.subpath.push([x, y]);
  9542. }
  9543. bezierCurveTo (cp1x, cp1y, cp2x, cp2y, x, y) {
  9544. this.path.push({
  9545. method: 'bezierCurveTo',
  9546. data: [cp1x, cp1y, cp2x, cp2y, x, y]
  9547. });
  9548. this.subpath.push([x, y]);
  9549. }
  9550. arc (x, y, r, sAngle, eAngle, counterclockwise = false) {
  9551. this.path.push({
  9552. method: 'arc',
  9553. data: [x, y, r, sAngle, eAngle, counterclockwise]
  9554. });
  9555. this.subpath.push([x, y]);
  9556. }
  9557. rect (x, y, width, height) {
  9558. this.path.push({
  9559. method: 'rect',
  9560. data: [x, y, width, height]
  9561. });
  9562. this.subpath = [
  9563. [x, y]
  9564. ];
  9565. }
  9566. arcTo (x1, y1, x2, y2, radius) {
  9567. this.path.push({
  9568. method: 'arcTo',
  9569. data: [x1, y1, x2, y2, radius]
  9570. });
  9571. this.subpath.push([x2, y2]);
  9572. }
  9573. clip () {
  9574. this.actions.push({
  9575. method: 'clip',
  9576. data: [...this.path]
  9577. });
  9578. }
  9579. closePath () {
  9580. this.path.push({
  9581. method: 'closePath',
  9582. data: []
  9583. });
  9584. if (this.subpath.length) {
  9585. this.subpath = [this.subpath.shift()];
  9586. }
  9587. }
  9588. clearActions () {
  9589. this.actions = [];
  9590. this.path = [];
  9591. this.subpath = [];
  9592. }
  9593. getActions () {
  9594. var actions = [...this.actions];
  9595. this.clearActions();
  9596. return actions
  9597. }
  9598. set lineDashOffset (value) {
  9599. this.actions.push({
  9600. method: 'setLineDashOffset',
  9601. data: [value]
  9602. });
  9603. }
  9604. set globalCompositeOperation (type) {
  9605. this.actions.push({
  9606. method: 'setGlobalCompositeOperation',
  9607. data: [type]
  9608. });
  9609. }
  9610. set shadowBlur (level) {
  9611. this.actions.push({
  9612. method: 'setShadowBlur',
  9613. data: [level]
  9614. });
  9615. }
  9616. set shadowColor (color) {
  9617. this.actions.push({
  9618. method: 'setShadowColor',
  9619. data: [color]
  9620. });
  9621. }
  9622. set shadowOffsetX (x) {
  9623. this.actions.push({
  9624. method: 'setShadowOffsetX',
  9625. data: [x]
  9626. });
  9627. }
  9628. set shadowOffsetY (y) {
  9629. this.actions.push({
  9630. method: 'setShadowOffsetY',
  9631. data: [y]
  9632. });
  9633. }
  9634. set font (value) {
  9635. var self = this;
  9636. this.state.font = value;
  9637. // eslint-disable-next-line
  9638. var fontFormat = value.match(/^(([\w\-]+\s)*)(\d+r?px)(\/(\d+\.?\d*(r?px)?))?\s+(.*)/);
  9639. if (fontFormat) {
  9640. var style = fontFormat[1].trim().split(/\s/);
  9641. var fontSize = parseFloat(fontFormat[3]);
  9642. var fontFamily = fontFormat[7];
  9643. var actions = [];
  9644. style.forEach(function (value, index) {
  9645. if (['italic', 'oblique', 'normal'].indexOf(value) > -1) {
  9646. actions.push({
  9647. method: 'setFontStyle',
  9648. data: [value]
  9649. });
  9650. self.state.fontStyle = value;
  9651. } else if (['bold', 'normal'].indexOf(value) > -1) {
  9652. actions.push({
  9653. method: 'setFontWeight',
  9654. data: [value]
  9655. });
  9656. self.state.fontWeight = value;
  9657. } else if (index === 0) {
  9658. actions.push({
  9659. method: 'setFontStyle',
  9660. data: ['normal']
  9661. });
  9662. self.state.fontStyle = 'normal';
  9663. } else if (index === 1) {
  9664. pushAction();
  9665. }
  9666. });
  9667. if (style.length === 1) {
  9668. pushAction();
  9669. }
  9670. style = actions.map(function (action) {
  9671. return action.data[0]
  9672. }).join(' ');
  9673. this.state.fontSize = fontSize;
  9674. this.state.fontFamily = fontFamily;
  9675. this.actions.push({
  9676. method: 'setFont',
  9677. data: [`${style} ${fontSize}px ${fontFamily}`]
  9678. });
  9679. } else {
  9680. console.warn("Failed to set 'font' on 'CanvasContext': invalid format.");
  9681. }
  9682. function pushAction () {
  9683. actions.push({
  9684. method: 'setFontWeight',
  9685. data: ['normal']
  9686. });
  9687. self.state.fontWeight = 'normal';
  9688. }
  9689. }
  9690. get font () {
  9691. return this.state.font
  9692. }
  9693. set fillStyle (color) {
  9694. this.setFillStyle(color);
  9695. }
  9696. set strokeStyle (color) {
  9697. this.setStrokeStyle(color);
  9698. }
  9699. set globalAlpha (value) {
  9700. value = Math.floor(255 * parseFloat(value));
  9701. this.actions.push({
  9702. method: 'setGlobalAlpha',
  9703. data: [value]
  9704. });
  9705. }
  9706. set textAlign (align) {
  9707. this.actions.push({
  9708. method: 'setTextAlign',
  9709. data: [align]
  9710. });
  9711. }
  9712. set lineCap (type) {
  9713. this.actions.push({
  9714. method: 'setLineCap',
  9715. data: [type]
  9716. });
  9717. }
  9718. set lineJoin (type) {
  9719. this.actions.push({
  9720. method: 'setLineJoin',
  9721. data: [type]
  9722. });
  9723. }
  9724. set lineWidth (value) {
  9725. this.actions.push({
  9726. method: 'setLineWidth',
  9727. data: [value]
  9728. });
  9729. }
  9730. set miterLimit (value) {
  9731. this.actions.push({
  9732. method: 'setMiterLimit',
  9733. data: [value]
  9734. });
  9735. }
  9736. set textBaseline (type) {
  9737. this.actions.push({
  9738. method: 'setTextBaseline',
  9739. data: [type]
  9740. });
  9741. }
  9742. }
  9743. [...methods1, ...methods2].forEach(function (method) {
  9744. function get (method) {
  9745. switch (method) {
  9746. case 'fill':
  9747. case 'stroke':
  9748. return function () {
  9749. this.actions.push({
  9750. method: method + 'Path',
  9751. data: [...this.path]
  9752. });
  9753. }
  9754. case 'fillRect':
  9755. return function (x, y, width, height) {
  9756. this.actions.push({
  9757. method: 'fillPath',
  9758. data: [{
  9759. method: 'rect',
  9760. data: [x, y, width, height]
  9761. }]
  9762. });
  9763. }
  9764. case 'strokeRect':
  9765. return function (x, y, width, height) {
  9766. this.actions.push({
  9767. method: 'strokePath',
  9768. data: [{
  9769. method: 'rect',
  9770. data: [x, y, width, height]
  9771. }]
  9772. });
  9773. }
  9774. case 'fillText':
  9775. case 'strokeText':
  9776. return function (text, x, y, maxWidth) {
  9777. var data = [text.toString(), x, y];
  9778. if (typeof maxWidth === 'number') {
  9779. data.push(maxWidth);
  9780. }
  9781. this.actions.push({
  9782. method,
  9783. data
  9784. });
  9785. }
  9786. case 'drawImage':
  9787. return function (imageResource, dx, dy, dWidth, dHeight, sx, sy, sWidth, sHeight) {
  9788. if (sHeight === undefined) {
  9789. sx = dx;
  9790. sy = dy;
  9791. sWidth = dWidth;
  9792. sHeight = dHeight;
  9793. dx = undefined;
  9794. dy = undefined;
  9795. dWidth = undefined;
  9796. dHeight = undefined;
  9797. }
  9798. var data;
  9799. function isNumber (e) {
  9800. return typeof e === 'number'
  9801. }
  9802. data = isNumber(dx) && isNumber(dy) && isNumber(dWidth) && isNumber(dHeight) ? [imageResource, sx, sy,
  9803. sWidth, sHeight, dx, dy, dWidth, dHeight
  9804. ] : isNumber(sWidth) && isNumber(
  9805. sHeight) ? [imageResource, sx, sy, sWidth, sHeight] : [imageResource, sx, sy];
  9806. this.actions.push({
  9807. method,
  9808. data
  9809. });
  9810. }
  9811. default:
  9812. return function (...data) {
  9813. this.actions.push({
  9814. method,
  9815. data
  9816. });
  9817. }
  9818. }
  9819. }
  9820. CanvasContext.prototype[method] = get(method);
  9821. });
  9822. methods3.forEach(function (method) {
  9823. function get (method) {
  9824. switch (method) {
  9825. case 'setFillStyle':
  9826. case 'setStrokeStyle':
  9827. return function (color) {
  9828. if (typeof color !== 'object') {
  9829. this.actions.push({
  9830. method,
  9831. data: ['normal', checkColor(color)]
  9832. });
  9833. } else {
  9834. this.actions.push({
  9835. method,
  9836. data: [color.type, color.data, color.colorStop]
  9837. });
  9838. }
  9839. }
  9840. case 'setGlobalAlpha':
  9841. return function (alpha) {
  9842. alpha = Math.floor(255 * parseFloat(alpha));
  9843. this.actions.push({
  9844. method,
  9845. data: [alpha]
  9846. });
  9847. }
  9848. case 'setShadow':
  9849. return function (offsetX, offsetY, blur, color) {
  9850. color = checkColor(color);
  9851. this.actions.push({
  9852. method,
  9853. data: [offsetX, offsetY, blur, color]
  9854. });
  9855. this.state.shadowBlur = blur;
  9856. this.state.shadowColor = color;
  9857. this.state.shadowOffsetX = offsetX;
  9858. this.state.shadowOffsetY = offsetY;
  9859. }
  9860. case 'setLineDash':
  9861. return function (pattern, offset) {
  9862. pattern = pattern || [0, 0];
  9863. offset = offset || 0;
  9864. this.actions.push({
  9865. method,
  9866. data: [pattern, offset]
  9867. });
  9868. this.state.lineDash = pattern;
  9869. }
  9870. case 'setFontSize':
  9871. return function (fontSize) {
  9872. this.state.font = this.state.font.replace(/\d+\.?\d*px/, fontSize + 'px');
  9873. this.state.fontSize = fontSize;
  9874. this.actions.push({
  9875. method,
  9876. data: [fontSize]
  9877. });
  9878. }
  9879. default:
  9880. return function (...data) {
  9881. this.actions.push({
  9882. method,
  9883. data
  9884. });
  9885. }
  9886. }
  9887. }
  9888. CanvasContext.prototype[method] = get(method);
  9889. });
  9890. function createCanvasContext$1 (id, context) {
  9891. if (context) {
  9892. return new CanvasContext(id, context.$page.id)
  9893. }
  9894. const pageId = getCurrentPageId();
  9895. if (pageId) {
  9896. return new CanvasContext(id, pageId)
  9897. } else {
  9898. UniServiceJSBridge.emit('onError', 'createCanvasContext:fail');
  9899. }
  9900. }
  9901. function canvasGetImageData$1 ({
  9902. canvasId,
  9903. x,
  9904. y,
  9905. width,
  9906. height
  9907. }, callbackId) {
  9908. var pageId = getCurrentPageId();
  9909. if (!pageId) {
  9910. invoke$1(callbackId, {
  9911. errMsg: 'canvasGetImageData:fail'
  9912. });
  9913. return
  9914. }
  9915. var cId = canvasEventCallbacks.push(function (data) {
  9916. var imgData = data.data;
  9917. if (imgData && imgData.length) {
  9918. data.data = new Uint8ClampedArray(imgData);
  9919. }
  9920. invoke$1(callbackId, data);
  9921. });
  9922. operateCanvas(canvasId, pageId, 'getImageData', {
  9923. x,
  9924. y,
  9925. width,
  9926. height,
  9927. callbackId: cId
  9928. });
  9929. }
  9930. function canvasPutImageData$1 ({
  9931. canvasId,
  9932. data,
  9933. x,
  9934. y,
  9935. width,
  9936. height
  9937. }, callbackId) {
  9938. var pageId = getCurrentPageId();
  9939. if (!pageId) {
  9940. invoke$1(callbackId, {
  9941. errMsg: 'canvasPutImageData:fail'
  9942. });
  9943. return
  9944. }
  9945. var cId = canvasEventCallbacks.push(function (data) {
  9946. invoke$1(callbackId, data);
  9947. });
  9948. // fix ...
  9949. operateCanvas(canvasId, pageId, 'putImageData', {
  9950. data: Array.prototype.slice.call(data),
  9951. x,
  9952. y,
  9953. width,
  9954. height,
  9955. callbackId: cId
  9956. });
  9957. }
  9958. function canvasToTempFilePath$1 ({
  9959. x = 0,
  9960. y = 0,
  9961. width,
  9962. height,
  9963. destWidth,
  9964. destHeight,
  9965. canvasId,
  9966. fileType,
  9967. qualit
  9968. }, callbackId) {
  9969. var pageId = getCurrentPageId();
  9970. if (!pageId) {
  9971. invoke$1(callbackId, {
  9972. errMsg: 'canvasToTempFilePath:fail'
  9973. });
  9974. return
  9975. }
  9976. const cId = canvasEventCallbacks.push(function ({
  9977. base64
  9978. }) {
  9979. if (!base64 || !base64.length) {
  9980. invoke$1(callbackId, {
  9981. errMsg: 'canvasToTempFilePath:fail'
  9982. });
  9983. }
  9984. invokeMethod('base64ToTempFilePath', {
  9985. base64Data: base64,
  9986. x,
  9987. y,
  9988. width,
  9989. height,
  9990. destWidth,
  9991. destHeight,
  9992. canvasId,
  9993. fileType,
  9994. qualit
  9995. }, callbackId);
  9996. });
  9997. operateCanvas(canvasId, pageId, 'getDataUrl', {
  9998. x,
  9999. y,
  10000. width,
  10001. height,
  10002. destWidth,
  10003. destHeight,
  10004. hidpi: false,
  10005. fileType,
  10006. qualit,
  10007. callbackId: cId
  10008. });
  10009. }
  10010. var require_context_module_1_6 = /*#__PURE__*/Object.freeze({
  10011. __proto__: null,
  10012. CanvasContext: CanvasContext,
  10013. createCanvasContext: createCanvasContext$1,
  10014. canvasGetImageData: canvasGetImageData$1,
  10015. canvasPutImageData: canvasPutImageData$1,
  10016. canvasToTempFilePath: canvasToTempFilePath$1
  10017. });
  10018. function operateMapPlayer$3 (mapId, pageVm, type, data) {
  10019. invokeMethod('operateMapPlayer', mapId, pageVm, type, data);
  10020. }
  10021. UniServiceJSBridge.subscribe('onMapMethodCallback', ({
  10022. callbackId,
  10023. data
  10024. }) => {
  10025. callback.invoke(callbackId, data);
  10026. });
  10027. const methods = ['getCenterLocation', 'moveToLocation', 'getScale', 'getRegion', 'includePoints', 'translateMarker'];
  10028. class MapContext {
  10029. constructor (id, pageVm) {
  10030. this.id = id;
  10031. this.pageVm = pageVm;
  10032. }
  10033. }
  10034. MapContext.prototype.$getAppMap = function () {
  10035. return plus.maps.getMapById(this.pageVm.$page.id + '-map-' + this.id)
  10036. };
  10037. methods.forEach(function (method) {
  10038. MapContext.prototype[method] = callback.warp(function (options, callbackId) {
  10039. options.callbackId = callbackId;
  10040. operateMapPlayer$3(this.id, this.pageVm, method, options);
  10041. });
  10042. });
  10043. function createMapContext$1 (id, context) {
  10044. if (context) {
  10045. return new MapContext(id, context)
  10046. }
  10047. return new MapContext(id, getCurrentPageVm('createMapContext'))
  10048. }
  10049. var require_context_module_1_7 = /*#__PURE__*/Object.freeze({
  10050. __proto__: null,
  10051. MapContext: MapContext,
  10052. createMapContext: createMapContext$1
  10053. });
  10054. const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0];
  10055. function operateVideoPlayer$3 (videoId, pageVm, type, data) {
  10056. invokeMethod('operateVideoPlayer', videoId, pageVm, type, data);
  10057. }
  10058. class VideoContext {
  10059. constructor (id, pageVm) {
  10060. this.id = id;
  10061. this.pageVm = pageVm;
  10062. }
  10063. play () {
  10064. operateVideoPlayer$3(this.id, this.pageVm, 'play');
  10065. }
  10066. pause () {
  10067. operateVideoPlayer$3(this.id, this.pageVm, 'pause');
  10068. }
  10069. stop () {
  10070. operateVideoPlayer$3(this.id, this.pageVm, 'stop');
  10071. }
  10072. seek (position) {
  10073. operateVideoPlayer$3(this.id, this.pageVm, 'seek', {
  10074. position
  10075. });
  10076. }
  10077. sendDanmu (args) {
  10078. operateVideoPlayer$3(this.id, this.pageVm, 'sendDanmu', args);
  10079. }
  10080. playbackRate (rate) {
  10081. if (!~RATES.indexOf(rate)) {
  10082. rate = 1.0;
  10083. }
  10084. operateVideoPlayer$3(this.id, this.pageVm, 'playbackRate', {
  10085. rate
  10086. });
  10087. }
  10088. requestFullScreen (args = {}) {
  10089. operateVideoPlayer$3(this.id, this.pageVm, 'requestFullScreen', args);
  10090. }
  10091. exitFullScreen () {
  10092. operateVideoPlayer$3(this.id, this.pageVm, 'exitFullScreen');
  10093. }
  10094. showStatusBar () {
  10095. operateVideoPlayer$3(this.id, this.pageVm, 'showStatusBar');
  10096. }
  10097. hideStatusBar () {
  10098. operateVideoPlayer$3(this.id, this.pageVm, 'hideStatusBar');
  10099. }
  10100. }
  10101. function createVideoContext$1 (id, context) {
  10102. if (context) {
  10103. return new VideoContext(id, context)
  10104. }
  10105. return new VideoContext(id, getCurrentPageVm('createVideoContext'))
  10106. }
  10107. var require_context_module_1_8 = /*#__PURE__*/Object.freeze({
  10108. __proto__: null,
  10109. VideoContext: VideoContext,
  10110. createVideoContext: createVideoContext$1
  10111. });
  10112. function operateEditor (componentId, pageId, type, data) {
  10113. UniServiceJSBridge.publishHandler(pageId + '-editor-' + componentId, {
  10114. componentId,
  10115. type,
  10116. data
  10117. }, pageId);
  10118. }
  10119. UniServiceJSBridge.subscribe('onEditorMethodCallback', ({
  10120. callbackId,
  10121. data
  10122. }) => {
  10123. callback.invoke(callbackId, data);
  10124. });
  10125. const methods$1 = ['insertDivider', 'insertImage', 'insertText', 'setContents', 'getContents', 'clear', 'removeFormat', 'undo', 'redo'];
  10126. class EditorContext {
  10127. constructor (id, pageId) {
  10128. this.id = id;
  10129. this.pageId = pageId;
  10130. }
  10131. format (name, value) {
  10132. operateEditor(this.id, this.pageId, 'format', {
  10133. options: {
  10134. name,
  10135. value
  10136. }
  10137. });
  10138. }
  10139. }
  10140. methods$1.forEach(function (method) {
  10141. EditorContext.prototype[method] = callback.warp(function (options, callbackId) {
  10142. operateEditor(this.id, this.pageId, method, {
  10143. options,
  10144. callbackId
  10145. });
  10146. });
  10147. });
  10148. var require_context_module_1_9 = /*#__PURE__*/Object.freeze({
  10149. __proto__: null,
  10150. EditorContext: EditorContext
  10151. });
  10152. const callbacks$6 = [];
  10153. onMethod('onAccelerometerChange', function (res) {
  10154. callbacks$6.forEach(callbackId => {
  10155. invoke$1(callbackId, res);
  10156. });
  10157. });
  10158. let isEnable = false;
  10159. /**
  10160. * 监听加速度
  10161. * @param {*} callbackId
  10162. */
  10163. function onAccelerometerChange (callbackId) {
  10164. // TODO 当没有 start 时,添加 on 需要主动 start?
  10165. callbacks$6.push(callbackId);
  10166. if (!isEnable) {
  10167. startAccelerometer();
  10168. }
  10169. }
  10170. function startAccelerometer ({
  10171. interval // TODO
  10172. } = {}) {
  10173. if (isEnable) {
  10174. return
  10175. }
  10176. isEnable = true;
  10177. return invokeMethod('enableAccelerometer', {
  10178. enable: true
  10179. })
  10180. }
  10181. function stopAccelerometer () {
  10182. isEnable = false;
  10183. return invokeMethod('enableAccelerometer', {
  10184. enable: false
  10185. })
  10186. }
  10187. var require_context_module_1_10 = /*#__PURE__*/Object.freeze({
  10188. __proto__: null,
  10189. onAccelerometerChange: onAccelerometerChange,
  10190. startAccelerometer: startAccelerometer,
  10191. stopAccelerometer: stopAccelerometer
  10192. });
  10193. function on (method) {
  10194. const callbacks = [];
  10195. onMethod(method, data => {
  10196. callbacks.forEach(callbackId => {
  10197. invoke$1(callbackId, data);
  10198. });
  10199. });
  10200. return function (callbackId) {
  10201. callbacks.push(callbackId);
  10202. }
  10203. }
  10204. const onBluetoothDeviceFound$1 = on('onBluetoothDeviceFound');
  10205. const onBluetoothAdapterStateChange$1 = on('onBluetoothAdapterStateChange');
  10206. const onBLEConnectionStateChange$1 = on('onBLEConnectionStateChange');
  10207. const onBLECharacteristicValueChange$1 = on('onBLECharacteristicValueChange');
  10208. var require_context_module_1_11 = /*#__PURE__*/Object.freeze({
  10209. __proto__: null,
  10210. onBluetoothDeviceFound: onBluetoothDeviceFound$1,
  10211. onBluetoothAdapterStateChange: onBluetoothAdapterStateChange$1,
  10212. onBLEConnectionStateChange: onBLEConnectionStateChange$1,
  10213. onBLECharacteristicValueChange: onBLECharacteristicValueChange$1
  10214. });
  10215. const callbacks$7 = [];
  10216. onMethod('onCompassChange', function (res) {
  10217. callbacks$7.forEach(callbackId => {
  10218. invoke$1(callbackId, res);
  10219. });
  10220. });
  10221. let isEnable$1 = false;
  10222. /**
  10223. * 监听加速度
  10224. * @param {*} callbackId
  10225. */
  10226. function onCompassChange (callbackId) {
  10227. // TODO 当没有 start 时,添加 on 需要主动 start?
  10228. callbacks$7.push(callbackId);
  10229. if (!isEnable$1) {
  10230. startCompass();
  10231. }
  10232. }
  10233. function startCompass ({
  10234. interval // TODO
  10235. } = {}) {
  10236. if (isEnable$1) {
  10237. return
  10238. }
  10239. isEnable$1 = true;
  10240. return invokeMethod('enableCompass', {
  10241. enable: true
  10242. })
  10243. }
  10244. function stopCompass () {
  10245. isEnable$1 = false;
  10246. return invokeMethod('enableCompass', {
  10247. enable: false
  10248. })
  10249. }
  10250. var require_context_module_1_12 = /*#__PURE__*/Object.freeze({
  10251. __proto__: null,
  10252. onCompassChange: onCompassChange,
  10253. startCompass: startCompass,
  10254. stopCompass: stopCompass
  10255. });
  10256. const callbacks$8 = [];
  10257. onMethod('onNetworkStatusChange', res => {
  10258. callbacks$8.forEach(callbackId => {
  10259. invoke$1(callbackId, res);
  10260. });
  10261. });
  10262. function onNetworkStatusChange (callbackId) {
  10263. callbacks$8.push(callbackId);
  10264. }
  10265. var require_context_module_1_13 = /*#__PURE__*/Object.freeze({
  10266. __proto__: null,
  10267. onNetworkStatusChange: onNetworkStatusChange
  10268. });
  10269. const callbacks$9 = [];
  10270. onMethod('onUIStyleChange', function (res) {
  10271. callbacks$9.forEach(callbackId => {
  10272. invoke$1(callbackId, res);
  10273. });
  10274. });
  10275. function onUIStyleChange (callbackId) {
  10276. callbacks$9.push(callbackId);
  10277. }
  10278. var require_context_module_1_14 = /*#__PURE__*/Object.freeze({
  10279. __proto__: null,
  10280. onUIStyleChange: onUIStyleChange
  10281. });
  10282. const longPressActionsCallbackId = 'longPressActionsCallback';
  10283. let longPressActions = {};
  10284. onMethod(longPressActionsCallbackId, function (res) {
  10285. const errMsg = res.errMsg || '';
  10286. if (new RegExp('\\:\\s*fail').test(errMsg)) {
  10287. longPressActions.fail && longPressActions.fail(res);
  10288. } else {
  10289. longPressActions.success && longPressActions.success(res);
  10290. }
  10291. longPressActions.complete && longPressActions.complete(res);
  10292. });
  10293. function previewImage$1 (args = {}) {
  10294. longPressActions = args.longPressActions || {};
  10295. if (longPressActions.success || longPressActions.fail || longPressActions.complete) {
  10296. longPressActions.callbackId = longPressActionsCallbackId;
  10297. }
  10298. return invokeMethod('previewImagePlus', args)
  10299. }
  10300. var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
  10301. __proto__: null,
  10302. previewImage: previewImage$1
  10303. });
  10304. const callbacks$a = {
  10305. pause: null,
  10306. resume: null,
  10307. start: null,
  10308. stop: null,
  10309. error: null
  10310. };
  10311. class RecorderManager {
  10312. constructor () {
  10313. onMethod('onRecorderStateChange', res => {
  10314. const state = res.state;
  10315. delete res.state;
  10316. delete res.errMsg;
  10317. if (typeof callbacks$a[state] === 'function') {
  10318. callbacks$a[state](res);
  10319. }
  10320. });
  10321. }
  10322. onError (callback) {
  10323. callbacks$a.error = callback;
  10324. }
  10325. onFrameRecorded (callback) {
  10326. }
  10327. onInterruptionBegin (callback) {
  10328. }
  10329. onInterruptionEnd (callback) {
  10330. }
  10331. onPause (callback) {
  10332. callbacks$a.pause = callback;
  10333. }
  10334. onResume (callback) {
  10335. callbacks$a.resume = callback;
  10336. }
  10337. onStart (callback) {
  10338. callbacks$a.start = callback;
  10339. }
  10340. onStop (callback) {
  10341. callbacks$a.stop = callback;
  10342. }
  10343. pause () {
  10344. invokeMethod('operateRecorder', {
  10345. operationType: 'pause'
  10346. });
  10347. }
  10348. resume () {
  10349. invokeMethod('operateRecorder', {
  10350. operationType: 'resume'
  10351. });
  10352. }
  10353. start (options) {
  10354. invokeMethod('operateRecorder', Object.assign({}, options, {
  10355. operationType: 'start'
  10356. }));
  10357. }
  10358. stop () {
  10359. invokeMethod('operateRecorder', {
  10360. operationType: 'stop'
  10361. });
  10362. }
  10363. }
  10364. let recorderManager;
  10365. function getRecorderManager () {
  10366. return recorderManager || (recorderManager = new RecorderManager())
  10367. }
  10368. var require_context_module_1_16 = /*#__PURE__*/Object.freeze({
  10369. __proto__: null,
  10370. getRecorderManager: getRecorderManager
  10371. });
  10372. class DownloadTask {
  10373. constructor (downloadTaskId, callbackId) {
  10374. this.id = downloadTaskId;
  10375. this._callbackId = callbackId;
  10376. this._callbacks = [];
  10377. }
  10378. abort () {
  10379. invokeMethod('operateDownloadTask', {
  10380. downloadTaskId: this.id,
  10381. operationType: 'abort'
  10382. });
  10383. }
  10384. onProgressUpdate (callback) {
  10385. if (typeof callback !== 'function') {
  10386. return
  10387. }
  10388. this._callbacks.push(callback);
  10389. }
  10390. onHeadersReceived () {
  10391. }
  10392. offProgressUpdate (callback) {
  10393. const index = this._callbacks.indexOf(callback);
  10394. if (index >= 0) {
  10395. this._callbacks.splice(index, 1);
  10396. }
  10397. }
  10398. offHeadersReceived () {
  10399. }
  10400. }
  10401. const downloadTasks$1 = Object.create(null);
  10402. onMethod('onDownloadTaskStateChange', ({
  10403. downloadTaskId,
  10404. state,
  10405. tempFilePath,
  10406. statusCode,
  10407. progress,
  10408. totalBytesWritten,
  10409. totalBytesExpectedToWrite,
  10410. errMsg
  10411. }) => {
  10412. const downloadTask = downloadTasks$1[downloadTaskId];
  10413. const callbackId = downloadTask._callbackId;
  10414. switch (state) {
  10415. case 'progressUpdate':
  10416. downloadTask._callbacks.forEach(callback => {
  10417. callback({
  10418. progress,
  10419. totalBytesWritten,
  10420. totalBytesExpectedToWrite
  10421. });
  10422. });
  10423. break
  10424. case 'success':
  10425. invoke$1(callbackId, {
  10426. tempFilePath,
  10427. statusCode,
  10428. errMsg: 'request:ok'
  10429. });
  10430. // eslint-disable-next-line no-fallthrough
  10431. case 'fail':
  10432. invoke$1(callbackId, {
  10433. errMsg: 'request:fail ' + errMsg
  10434. });
  10435. // eslint-disable-next-line no-fallthrough
  10436. default:
  10437. // progressUpdate 可能晚于 success
  10438. setTimeout(() => {
  10439. delete downloadTasks$1[downloadTaskId];
  10440. }, 100);
  10441. break
  10442. }
  10443. });
  10444. function downloadFile$1 (args, callbackId) {
  10445. const {
  10446. downloadTaskId
  10447. } = invokeMethod('createDownloadTask', args);
  10448. const task = new DownloadTask(downloadTaskId, callbackId);
  10449. downloadTasks$1[downloadTaskId] = task;
  10450. return task
  10451. }
  10452. var require_context_module_1_17 = /*#__PURE__*/Object.freeze({
  10453. __proto__: null,
  10454. downloadFile: downloadFile$1
  10455. });
  10456. const requestTasks$1 = Object.create(null);
  10457. function formatResponse (res, args) {
  10458. if (
  10459. typeof res.data === 'string' &&
  10460. res.data.charCodeAt(0) === 65279
  10461. ) {
  10462. res.data = res.data.substr(1);
  10463. }
  10464. res.statusCode = parseInt(res.statusCode, 10);
  10465. if (isPlainObject(res.header)) {
  10466. res.header = Object.keys(res.header).reduce(function (ret, key) {
  10467. const value = res.header[key];
  10468. if (Array.isArray(value)) {
  10469. ret[key] = value.join(',');
  10470. } else if (typeof value === 'string') {
  10471. ret[key] = value;
  10472. }
  10473. return ret
  10474. }, {});
  10475. }
  10476. if (args.dataType && args.dataType.toLowerCase() === 'json') {
  10477. try {
  10478. res.data = JSON.parse(res.data);
  10479. } catch (e) {}
  10480. }
  10481. return res
  10482. }
  10483. onMethod('onRequestTaskStateChange', function ({
  10484. requestTaskId,
  10485. state,
  10486. data,
  10487. statusCode,
  10488. header,
  10489. errMsg
  10490. }) {
  10491. const {
  10492. args,
  10493. callbackId
  10494. } = requestTasks$1[requestTaskId] || {};
  10495. if (!callbackId) {
  10496. return
  10497. }
  10498. delete requestTasks$1[requestTaskId];
  10499. switch (state) {
  10500. case 'success':
  10501. invoke$1(callbackId, formatResponse({
  10502. data,
  10503. statusCode,
  10504. header,
  10505. errMsg: 'request:ok'
  10506. }, args));
  10507. break
  10508. case 'fail':
  10509. invoke$1(callbackId, {
  10510. errMsg: 'request:fail ' + errMsg
  10511. });
  10512. break
  10513. }
  10514. });
  10515. class RequestTask {
  10516. constructor (id) {
  10517. this.id = id;
  10518. }
  10519. abort () {
  10520. invokeMethod('operateRequestTask', {
  10521. requestTaskId: this.id,
  10522. operationType: 'abort'
  10523. });
  10524. }
  10525. offHeadersReceived () {
  10526. }
  10527. onHeadersReceived () {
  10528. }
  10529. }
  10530. function request$1 (args, callbackId) {
  10531. let contentType;
  10532. for (const name in args.header) {
  10533. if (name.toLowerCase() === 'content-type') {
  10534. contentType = args.header[name];
  10535. break
  10536. }
  10537. }
  10538. if (args.method !== 'GET' && contentType.indexOf('application/json') === 0 && isPlainObject(args.data)) {
  10539. args.data = JSON.stringify(args.data);
  10540. }
  10541. const {
  10542. requestTaskId
  10543. } = invokeMethod('createRequestTask', args);
  10544. requestTasks$1[requestTaskId] = {
  10545. args,
  10546. callbackId
  10547. };
  10548. return new RequestTask(requestTaskId)
  10549. }
  10550. var require_context_module_1_18 = /*#__PURE__*/Object.freeze({
  10551. __proto__: null,
  10552. request: request$1
  10553. });
  10554. class SocketTask {
  10555. constructor (socketTaskId) {
  10556. this.id = socketTaskId;
  10557. this._callbacks = {
  10558. open: [],
  10559. close: [],
  10560. error: [],
  10561. message: []
  10562. };
  10563. this.CLOSED = 3;
  10564. this.CLOSING = 2;
  10565. this.CONNECTING = 0;
  10566. this.OPEN = 1;
  10567. this.readyState = this.CLOSED;
  10568. }
  10569. send (args) {
  10570. if (this.readyState !== this.OPEN) {
  10571. this._callback(args, 'sendSocketMessage:fail WebSocket is not connected');
  10572. }
  10573. const {
  10574. errMsg
  10575. } = invokeMethod('operateSocketTask', Object.assign({}, args, {
  10576. operationType: 'send',
  10577. socketTaskId: this.id
  10578. }));
  10579. this._callback(args, errMsg.replace('operateSocketTask', 'sendSocketMessage'));
  10580. }
  10581. close (args) {
  10582. this.readyState = this.CLOSING;
  10583. const {
  10584. errMsg
  10585. } = invokeMethod('operateSocketTask', Object.assign({}, args, {
  10586. operationType: 'close',
  10587. socketTaskId: this.id
  10588. }));
  10589. this._callback(args, errMsg.replace('operateSocketTask', 'closeSocket'));
  10590. }
  10591. onOpen (callback) {
  10592. this._callbacks.open.push(callback);
  10593. }
  10594. onClose (callback) {
  10595. this._callbacks.close.push(callback);
  10596. }
  10597. onError (callback) {
  10598. this._callbacks.error.push(callback);
  10599. }
  10600. onMessage (callback) {
  10601. this._callbacks.message.push(callback);
  10602. }
  10603. _callback ({
  10604. success,
  10605. fail,
  10606. complete
  10607. } = {}, errMsg) {
  10608. var data = {
  10609. errMsg
  10610. };
  10611. if (/:ok$/.test(errMsg)) {
  10612. if (typeof success === 'function') {
  10613. success(data);
  10614. }
  10615. } else {
  10616. if (typeof fail === 'function') {
  10617. fail(data);
  10618. }
  10619. }
  10620. if (typeof complete === 'function') {
  10621. complete(data);
  10622. }
  10623. }
  10624. }
  10625. const socketTasks$1 = Object.create(null);
  10626. const socketTasksArray = [];
  10627. const callbacks$b = Object.create(null);
  10628. onMethod('onSocketTaskStateChange', ({
  10629. socketTaskId,
  10630. state,
  10631. data,
  10632. errMsg
  10633. }) => {
  10634. const socketTask = socketTasks$1[socketTaskId];
  10635. if (!socketTask) {
  10636. return
  10637. }
  10638. if (state === 'open') {
  10639. socketTask.readyState = socketTask.OPEN;
  10640. }
  10641. if (socketTask === socketTasksArray[0] && callbacks$b[state]) {
  10642. invoke$1(callbacks$b[state], state === 'message' ? {
  10643. data
  10644. } : {});
  10645. }
  10646. if (state === 'error' || state === 'close') {
  10647. socketTask.readyState = socketTask.CLOSED;
  10648. delete socketTasks$1[socketTaskId];
  10649. const index = socketTasksArray.indexOf(socketTask);
  10650. if (index >= 0) {
  10651. socketTasksArray.splice(index, 1);
  10652. }
  10653. }
  10654. socketTask._callbacks[state].forEach(callback => {
  10655. if (typeof callback === 'function') {
  10656. callback(state === 'message' ? {
  10657. data
  10658. } : {});
  10659. }
  10660. });
  10661. });
  10662. function connectSocket$1 (args, callbackId) {
  10663. const {
  10664. socketTaskId
  10665. } = invokeMethod('createSocketTask', args);
  10666. const task = new SocketTask(socketTaskId);
  10667. socketTasks$1[socketTaskId] = task;
  10668. socketTasksArray.push(task);
  10669. setTimeout(() => {
  10670. invoke$1(callbackId, {
  10671. errMsg: 'connectSocket:ok'
  10672. });
  10673. }, 0);
  10674. return task
  10675. }
  10676. function sendSocketMessage$1 (args, callbackId) {
  10677. const socketTask = socketTasksArray[0];
  10678. if (!socketTask || socketTask.readyState !== socketTask.OPEN) {
  10679. invoke$1(callbackId, {
  10680. errMsg: 'sendSocketMessage:fail WebSocket is not connected'
  10681. });
  10682. return
  10683. }
  10684. return invokeMethod('operateSocketTask', Object.assign({}, args, {
  10685. operationType: 'send',
  10686. socketTaskId: socketTask.id
  10687. }))
  10688. }
  10689. function closeSocket$1 (args, callbackId) {
  10690. const socketTask = socketTasksArray[0];
  10691. if (!socketTask) {
  10692. invoke$1(callbackId, {
  10693. errMsg: 'closeSocket:fail WebSocket is not connected'
  10694. });
  10695. return
  10696. }
  10697. socketTask.readyState = socketTask.CLOSING;
  10698. return invokeMethod('operateSocketTask', Object.assign({}, args, {
  10699. operationType: 'close',
  10700. socketTaskId: socketTask.id
  10701. }))
  10702. }
  10703. function onSocketOpen (callbackId) {
  10704. callbacks$b.open = callbackId;
  10705. }
  10706. function onSocketError (callbackId) {
  10707. callbacks$b.error = callbackId;
  10708. }
  10709. function onSocketMessage (callbackId) {
  10710. callbacks$b.message = callbackId;
  10711. }
  10712. function onSocketClose (callbackId) {
  10713. callbacks$b.close = callbackId;
  10714. }
  10715. var require_context_module_1_19 = /*#__PURE__*/Object.freeze({
  10716. __proto__: null,
  10717. connectSocket: connectSocket$1,
  10718. sendSocketMessage: sendSocketMessage$1,
  10719. closeSocket: closeSocket$1,
  10720. onSocketOpen: onSocketOpen,
  10721. onSocketError: onSocketError,
  10722. onSocketMessage: onSocketMessage,
  10723. onSocketClose: onSocketClose
  10724. });
  10725. class UploadTask {
  10726. constructor (uploadTaskId, callbackId) {
  10727. this.id = uploadTaskId;
  10728. this._callbackId = callbackId;
  10729. this._callbacks = [];
  10730. }
  10731. abort () {
  10732. invokeMethod('operateRequestTask', {
  10733. uploadTaskId: this.id,
  10734. operationType: 'abort'
  10735. });
  10736. }
  10737. onProgressUpdate (callback) {
  10738. if (typeof callback !== 'function') {
  10739. return
  10740. }
  10741. this._callbacks.push(callback);
  10742. }
  10743. onHeadersReceived () {
  10744. }
  10745. offProgressUpdate (callback) {
  10746. const index = this._callbacks.indexOf(callback);
  10747. if (index >= 0) {
  10748. this._callbacks.splice(index, 1);
  10749. }
  10750. }
  10751. offHeadersReceived () {
  10752. }
  10753. }
  10754. const uploadTasks$1 = Object.create(null);
  10755. onMethod('onUploadTaskStateChange', ({
  10756. uploadTaskId,
  10757. state,
  10758. data,
  10759. statusCode,
  10760. progress,
  10761. totalBytesSent,
  10762. totalBytesExpectedToSend,
  10763. errMsg
  10764. }) => {
  10765. const uploadTask = uploadTasks$1[uploadTaskId];
  10766. const callbackId = uploadTask._callbackId;
  10767. switch (state) {
  10768. case 'progressUpdate':
  10769. uploadTask._callbacks.forEach(callback => {
  10770. callback({
  10771. progress,
  10772. totalBytesSent,
  10773. totalBytesExpectedToSend
  10774. });
  10775. });
  10776. break
  10777. case 'success':
  10778. invoke$1(callbackId, {
  10779. data,
  10780. statusCode,
  10781. errMsg: 'request:ok'
  10782. });
  10783. // eslint-disable-next-line no-fallthrough
  10784. case 'fail':
  10785. invoke$1(callbackId, {
  10786. errMsg: 'request:fail ' + errMsg
  10787. });
  10788. // eslint-disable-next-line no-fallthrough
  10789. default:
  10790. // progressUpdate 可能晚于 success
  10791. setTimeout(() => {
  10792. delete uploadTasks$1[uploadTaskId];
  10793. }, 100);
  10794. break
  10795. }
  10796. });
  10797. function uploadFile$1 (args, callbackId) {
  10798. const {
  10799. uploadTaskId
  10800. } = invokeMethod('createUploadTask', args);
  10801. const task = new UploadTask(uploadTaskId, callbackId);
  10802. uploadTasks$1[uploadTaskId] = task;
  10803. return task
  10804. }
  10805. var require_context_module_1_20 = /*#__PURE__*/Object.freeze({
  10806. __proto__: null,
  10807. uploadFile: uploadFile$1
  10808. });
  10809. const defaultOption = {
  10810. duration: 400,
  10811. timingFunction: 'linear',
  10812. delay: 0,
  10813. transformOrigin: '50% 50% 0'
  10814. };
  10815. class MPAnimation {
  10816. constructor (option) {
  10817. this.actions = [];
  10818. this.currentTransform = {};
  10819. this.currentStepAnimates = [];
  10820. this.option = Object.assign({}, defaultOption, option);
  10821. }
  10822. _getOption (option) {
  10823. const _option = {
  10824. transition: Object.assign({}, this.option, option)
  10825. };
  10826. _option.transformOrigin = _option.transition.transformOrigin;
  10827. delete _option.transition.transformOrigin;
  10828. return _option
  10829. }
  10830. _pushAnimates (type, args) {
  10831. this.currentStepAnimates.push({
  10832. type: type,
  10833. args: args
  10834. });
  10835. }
  10836. _converType (type) {
  10837. return type.replace(/[A-Z]/g, text => {
  10838. return `-${text.toLowerCase()}`
  10839. })
  10840. }
  10841. _getValue (value) {
  10842. return typeof value === 'number' ? `${value}px` : value
  10843. }
  10844. export () {
  10845. const actions = this.actions;
  10846. this.actions = [];
  10847. return {
  10848. actions
  10849. }
  10850. }
  10851. step (option) {
  10852. this.currentStepAnimates.forEach(animate => {
  10853. if (animate.type !== 'style') {
  10854. this.currentTransform[animate.type] = animate;
  10855. } else {
  10856. this.currentTransform[`${animate.type}.${animate.args[0]}`] = animate;
  10857. }
  10858. });
  10859. this.actions.push({
  10860. animates: Object.values(this.currentTransform),
  10861. option: this._getOption(option)
  10862. });
  10863. this.currentStepAnimates = [];
  10864. return this
  10865. }
  10866. }
  10867. const animateTypes1 = ['matrix', 'matrix3d', 'rotate', 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scale3d', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'translate', 'translate3d', 'translateX', 'translateY', 'translateZ'];
  10868. const animateTypes2 = ['opacity', 'backgroundColor'];
  10869. const animateTypes3 = ['width', 'height', 'left', 'right', 'top', 'bottom'];
  10870. animateTypes1.concat(animateTypes2, animateTypes3).forEach(type => {
  10871. MPAnimation.prototype[type] = function (...args) {
  10872. if (animateTypes2.concat(animateTypes3).includes(type)) {
  10873. this._pushAnimates('style', [this._converType(type), animateTypes3.includes(type) ? this._getValue(args[0]) : args[0]]);
  10874. } else {
  10875. this._pushAnimates(type, args);
  10876. }
  10877. return this
  10878. };
  10879. });
  10880. function createAnimation (option) {
  10881. return new MPAnimation(option)
  10882. }
  10883. var require_context_module_1_21 = /*#__PURE__*/Object.freeze({
  10884. __proto__: null,
  10885. createAnimation: createAnimation
  10886. });
  10887. const createIntersectionObserverCallbacks = createCallbacks('requestComponentObserver');
  10888. const defaultOptions = {
  10889. thresholds: [0],
  10890. initialRatio: 0,
  10891. observeAll: false
  10892. };
  10893. class ServiceIntersectionObserver {
  10894. constructor (component, options) {
  10895. this.pageId = component.$page.id;
  10896. this.component = component._$id || component; // app-plus 平台传输_$id
  10897. this.options = Object.assign({}, defaultOptions, options);
  10898. }
  10899. _makeRootMargin (margins = {}) {
  10900. this.options.rootMargin = ['top', 'right', 'bottom', 'left'].map(name => `${Number(margins[name]) || 0}px`).join(
  10901. ' ');
  10902. }
  10903. relativeTo (selector, margins) {
  10904. this.options.relativeToSelector = selector;
  10905. this._makeRootMargin(margins);
  10906. return this
  10907. }
  10908. relativeToViewport (margins) {
  10909. this.options.relativeToSelector = null;
  10910. this._makeRootMargin(margins);
  10911. return this
  10912. }
  10913. observe (selector, callback) {
  10914. if (typeof callback !== 'function') {
  10915. return
  10916. }
  10917. this.options.selector = selector;
  10918. this.reqId = createIntersectionObserverCallbacks.push(callback);
  10919. UniServiceJSBridge.publishHandler('requestComponentObserver', {
  10920. reqId: this.reqId,
  10921. component: this.component,
  10922. options: this.options
  10923. }, this.pageId);
  10924. }
  10925. disconnect () {
  10926. UniServiceJSBridge.publishHandler('destroyComponentObserver', {
  10927. reqId: this.reqId
  10928. }, this.pageId);
  10929. }
  10930. }
  10931. function createIntersectionObserver (context, options) {
  10932. if (!context._isVue) {
  10933. options = context;
  10934. context = null;
  10935. }
  10936. if (context) {
  10937. return new ServiceIntersectionObserver(context, options)
  10938. }
  10939. return new ServiceIntersectionObserver(getCurrentPageVm('createIntersectionObserver'), options)
  10940. }
  10941. var require_context_module_1_22 = /*#__PURE__*/Object.freeze({
  10942. __proto__: null,
  10943. createIntersectionObserver: createIntersectionObserver
  10944. });
  10945. const ContextClasss = {
  10946. canvas: CanvasContext,
  10947. map: MapContext,
  10948. video: VideoContext,
  10949. editor: EditorContext
  10950. };
  10951. function convertContext (result) {
  10952. if (result && result.context) {
  10953. const { id, name, page } = result.context;
  10954. const ContextClass = ContextClasss[name];
  10955. result.context = ContextClass && new ContextClass(id, page);
  10956. }
  10957. }
  10958. class NodesRef {
  10959. constructor (selectorQuery, component, selector, single) {
  10960. this._selectorQuery = selectorQuery;
  10961. this._component = component;
  10962. this._selector = selector;
  10963. this._single = single;
  10964. }
  10965. boundingClientRect (callback) {
  10966. this._selectorQuery._push(
  10967. this._selector,
  10968. this._component,
  10969. this._single, {
  10970. id: true,
  10971. dataset: true,
  10972. rect: true,
  10973. size: true
  10974. },
  10975. callback);
  10976. return this._selectorQuery
  10977. }
  10978. fields (fields, callback) {
  10979. this._selectorQuery._push(
  10980. this._selector,
  10981. this._component,
  10982. this._single,
  10983. fields,
  10984. callback
  10985. );
  10986. return this._selectorQuery
  10987. }
  10988. scrollOffset (callback) {
  10989. this._selectorQuery._push(
  10990. this._selector,
  10991. this._component,
  10992. this._single, {
  10993. id: true,
  10994. dataset: true,
  10995. scrollOffset: true
  10996. },
  10997. callback
  10998. );
  10999. return this._selectorQuery
  11000. }
  11001. context (callback) {
  11002. this._selectorQuery._push(
  11003. this._selector,
  11004. this._component,
  11005. this._single, {
  11006. context: true
  11007. },
  11008. callback
  11009. );
  11010. return this._selectorQuery
  11011. }
  11012. }
  11013. class SelectorQuery {
  11014. constructor (page) {
  11015. this._page = page;
  11016. this._queue = [];
  11017. this._queueCb = [];
  11018. }
  11019. exec (callback) {
  11020. invokeMethod('requestComponentInfo', this._page, this._queue, res => {
  11021. const queueCbs = this._queueCb;
  11022. res.forEach((result, index) => {
  11023. if (Array.isArray(result)) {
  11024. result.forEach(convertContext);
  11025. } else {
  11026. convertContext(result);
  11027. }
  11028. const queueCb = queueCbs[index];
  11029. if (isFn(queueCb)) {
  11030. queueCb.call(this, result);
  11031. }
  11032. });
  11033. isFn(callback) && callback.call(this, res);
  11034. });
  11035. }
  11036. ['in'] (component) {
  11037. // app-plus 平台传递 id
  11038. this._component = component._$id || component;
  11039. return this
  11040. }
  11041. select (selector) {
  11042. return new NodesRef(this, this._component, selector, true)
  11043. }
  11044. selectAll (selector) {
  11045. return new NodesRef(this, this._component, selector, false)
  11046. }
  11047. selectViewport () {
  11048. return new NodesRef(this, 0, '', true)
  11049. }
  11050. _push (selector, component, single, fields, callback) {
  11051. this._queue.push({
  11052. component,
  11053. selector,
  11054. single,
  11055. fields
  11056. });
  11057. this._queueCb.push(callback);
  11058. }
  11059. }
  11060. function createSelectorQuery (context) {
  11061. if (context) {
  11062. return new SelectorQuery(context)
  11063. }
  11064. return new SelectorQuery(getCurrentPageVm('createSelectorQuery'))
  11065. }
  11066. var require_context_module_1_23 = /*#__PURE__*/Object.freeze({
  11067. __proto__: null,
  11068. createSelectorQuery: createSelectorQuery
  11069. });
  11070. let callback$1;
  11071. onMethod('onKeyboardHeightChange', res => {
  11072. if (callback$1) {
  11073. invoke$1(callback$1, res);
  11074. }
  11075. });
  11076. function onKeyboardHeightChange (callbackId) {
  11077. callback$1 = callbackId;
  11078. }
  11079. var require_context_module_1_24 = /*#__PURE__*/Object.freeze({
  11080. __proto__: null,
  11081. onKeyboardHeightChange: onKeyboardHeightChange
  11082. });
  11083. UniServiceJSBridge.subscribe('onLoadFontFaceCallback', ({
  11084. callbackId,
  11085. data
  11086. }) => {
  11087. invoke$1(callbackId, data);
  11088. });
  11089. function loadFontFace$1 (options, callbackId) {
  11090. const pageId = getCurrentPageId();
  11091. if (!pageId) {
  11092. return {
  11093. errMsg: 'loadFontFace:fail not font page'
  11094. }
  11095. }
  11096. UniServiceJSBridge.publishHandler('loadFontFace', {
  11097. options,
  11098. callbackId
  11099. }, pageId);
  11100. }
  11101. var require_context_module_1_25 = /*#__PURE__*/Object.freeze({
  11102. __proto__: null,
  11103. loadFontFace: loadFontFace$1
  11104. });
  11105. function pageScrollTo$1 (args) {
  11106. const pages = getCurrentPages();
  11107. if (pages.length) {
  11108. UniServiceJSBridge.publishHandler('pageScrollTo', args, pages[pages.length - 1].$page.id);
  11109. }
  11110. return {}
  11111. }
  11112. var require_context_module_1_26 = /*#__PURE__*/Object.freeze({
  11113. __proto__: null,
  11114. pageScrollTo: pageScrollTo$1
  11115. });
  11116. function setPageMeta (args) {
  11117. const pages = getCurrentPages();
  11118. if (pages.length) {
  11119. UniServiceJSBridge.publishHandler('setPageMeta', args, pages[pages.length - 1].$page.id);
  11120. }
  11121. return {}
  11122. }
  11123. var require_context_module_1_27 = /*#__PURE__*/Object.freeze({
  11124. __proto__: null,
  11125. setPageMeta: setPageMeta
  11126. });
  11127. function removeTabBarBadge$1 ({
  11128. index
  11129. }) {
  11130. return invokeMethod('setTabBarBadge', {
  11131. index,
  11132. type: 'none'
  11133. })
  11134. }
  11135. function showTabBarRedDot$1 ({
  11136. index
  11137. }) {
  11138. return invokeMethod('setTabBarBadge', {
  11139. index,
  11140. type: 'redDot'
  11141. })
  11142. }
  11143. const hideTabBarRedDot$1 = removeTabBarBadge$1;
  11144. const callbacks$c = [];
  11145. onMethod('onTabBarMidButtonTap', res => {
  11146. callbacks$c.forEach(callbackId => {
  11147. invoke$1(callbackId, res);
  11148. });
  11149. });
  11150. function onTabBarMidButtonTap (callbackId) {
  11151. callbacks$c.push(callbackId);
  11152. }
  11153. var require_context_module_1_28 = /*#__PURE__*/Object.freeze({
  11154. __proto__: null,
  11155. removeTabBarBadge: removeTabBarBadge$1,
  11156. showTabBarRedDot: showTabBarRedDot$1,
  11157. hideTabBarRedDot: hideTabBarRedDot$1,
  11158. onTabBarMidButtonTap: onTabBarMidButtonTap
  11159. });
  11160. const callbacks$d = [];
  11161. onMethod('onViewDidResize', res => {
  11162. callbacks$d.forEach(callbackId => {
  11163. invoke$1(callbackId, res);
  11164. });
  11165. });
  11166. function onWindowResize (callbackId) {
  11167. callbacks$d.push(callbackId);
  11168. }
  11169. function offWindowResize (callbackId) {
  11170. // TODO 目前 on 和 off 即使传入同一个 function,获取到的 callbackId 也不会一致,导致不能 off 掉指定
  11171. // 后续修复
  11172. // 此处和微信平台一致查询不到去掉最后一个
  11173. callbacks$d.splice(callbacks$d.indexOf(callbackId), 1);
  11174. }
  11175. var require_context_module_1_29 = /*#__PURE__*/Object.freeze({
  11176. __proto__: null,
  11177. onWindowResize: onWindowResize,
  11178. offWindowResize: offWindowResize
  11179. });
  11180. const api$1 = Object.create(null);
  11181. const modules$1 =
  11182. (function() {
  11183. var map = {
  11184. './base/base64.js': require_context_module_1_0,
  11185. './base/can-i-use.js': require_context_module_1_1,
  11186. './base/interceptor.js': require_context_module_1_2,
  11187. './base/upx2px.js': require_context_module_1_3,
  11188. './context/audio.js': require_context_module_1_4,
  11189. './context/background-audio.js': require_context_module_1_5,
  11190. './context/canvas.js': require_context_module_1_6,
  11191. './context/create-map-context.js': require_context_module_1_7,
  11192. './context/create-video-context.js': require_context_module_1_8,
  11193. './context/editor.js': require_context_module_1_9,
  11194. './device/accelerometer.js': require_context_module_1_10,
  11195. './device/bluetooth.js': require_context_module_1_11,
  11196. './device/compass.js': require_context_module_1_12,
  11197. './device/network.js': require_context_module_1_13,
  11198. './device/theme.js': require_context_module_1_14,
  11199. './media/preview-image.js': require_context_module_1_15,
  11200. './media/recorder.js': require_context_module_1_16,
  11201. './network/download-file.js': require_context_module_1_17,
  11202. './network/request.js': require_context_module_1_18,
  11203. './network/socket.js': require_context_module_1_19,
  11204. './network/upload-file.js': require_context_module_1_20,
  11205. './ui/create-animation.js': require_context_module_1_21,
  11206. './ui/create-intersection-observer.js': require_context_module_1_22,
  11207. './ui/create-selector-query.js': require_context_module_1_23,
  11208. './ui/keyboard.js': require_context_module_1_24,
  11209. './ui/load-font-face.js': require_context_module_1_25,
  11210. './ui/page-scroll-to.js': require_context_module_1_26,
  11211. './ui/set-page-meta.js': require_context_module_1_27,
  11212. './ui/tab-bar.js': require_context_module_1_28,
  11213. './ui/window.js': require_context_module_1_29,
  11214. };
  11215. var req = function req(key) {
  11216. return map[key] || (function() { throw new Error("Cannot find module '" + key + "'.") }());
  11217. };
  11218. req.keys = function() {
  11219. return Object.keys(map);
  11220. };
  11221. return req;
  11222. })();
  11223. modules$1.keys().forEach(function (key) {
  11224. Object.assign(api$1, modules$1(key));
  11225. });
  11226. var api$2 = Object.assign(Object.create(null), api$1, platformApi);
  11227. const uni$1 = Object.create(null);
  11228. apis_1.forEach(name => {
  11229. if (api$2[name]) {
  11230. uni$1[name] = promisify(name, wrapper(name, api$2[name]));
  11231. } else {
  11232. uni$1[name] = wrapperUnimplemented(name);
  11233. }
  11234. });
  11235. function publishHandler (eventType, args, pageIds) {
  11236. args = JSON.stringify(args);
  11237. if (process.env.NODE_ENV !== 'production') {
  11238. console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds);
  11239. }
  11240. if (!Array.isArray(pageIds)) {
  11241. pageIds = [pageIds];
  11242. }
  11243. const evalJSCode =
  11244. `typeof UniViewJSBridge !== 'undefined' && UniViewJSBridge.subscribeHandler("${eventType}",${args},__PAGE_ID__)`;
  11245. pageIds.forEach(id => {
  11246. const webview = plus.webview.getWebviewById(String(id));
  11247. webview && webview.evalJS(evalJSCode.replace('__PAGE_ID__', id));
  11248. });
  11249. }
  11250. const wx = Object.create(null);
  11251. apis_1.forEach(name => {
  11252. if (api$2[name]) {
  11253. wx[name] = wrapper(name, api$2[name]);
  11254. } else {
  11255. wx[name] = wrapperUnimplemented(name);
  11256. }
  11257. });
  11258. function callHook (vm, hook, params) {
  11259. vm = vm.$vm || vm;
  11260. return vm.__call_hook && vm.__call_hook(hook, params)
  11261. }
  11262. function callAppHook (vm, hook, params) {
  11263. if (hook !== 'onError') {
  11264. console.debug(`App:${hook} have been invoked` + (params ? ` ${JSON.stringify(params)}` : ''));
  11265. }
  11266. vm = vm.$vm || vm;
  11267. return vm.__call_hook && vm.__call_hook(hook, params)
  11268. }
  11269. function callPageHook (vm, hook, params) {
  11270. if (hook !== 'onPageScroll') {
  11271. console.debug(`${vm.$page.route}[${vm.$page.id}]:${hook} have been invoked`);
  11272. }
  11273. return callHook(vm, hook, params)
  11274. }
  11275. function onMessage (pageId, arg) {
  11276. pageId = parseInt(pageId);
  11277. const page = getCurrentPages(true).find(page => page.$page.id === pageId);
  11278. if (!page) {
  11279. return
  11280. }
  11281. if (!page.$page.meta.isNVue) {
  11282. const target = page.$vm._$vd.elements.find(target => target.type === 'web-view' && target.events.message);
  11283. if (!target) {
  11284. return
  11285. }
  11286. target.dispatchEvent('message', {
  11287. type: 'message',
  11288. target: Object.create(null),
  11289. currentTarget: Object.create(null),
  11290. timeStamp: Date.now(),
  11291. detail: {
  11292. data: [arg]
  11293. }
  11294. });
  11295. }
  11296. }
  11297. function onWebInvokeAppService ({
  11298. name,
  11299. arg
  11300. }, pageIds) {
  11301. if (name === 'postMessage') {
  11302. onMessage(pageIds[0], arg);
  11303. } else {
  11304. uni[name](arg);
  11305. }
  11306. }
  11307. function initOn (on, {
  11308. getApp,
  11309. getCurrentPages
  11310. }) {
  11311. function onError (err) {
  11312. callAppHook(getApp(), 'onError', err);
  11313. }
  11314. function onPageNotFound (page) {
  11315. callAppHook(getApp(), 'onPageNotFound', page);
  11316. }
  11317. function onResize (args, pageId) {
  11318. const page = getCurrentPages().find(page => page.$page.id === pageId);
  11319. page && callPageHook(page, 'onResize', args);
  11320. }
  11321. function onPullDownRefresh (args, pageId) {
  11322. const page = getCurrentPages().find(page => page.$page.id === pageId);
  11323. if (page) {
  11324. setPullDownRefreshPageId(pageId);
  11325. callPageHook(page, 'onPullDownRefresh');
  11326. }
  11327. }
  11328. function callCurrentPageHook (hook, args) {
  11329. const pages = getCurrentPages();
  11330. if (pages.length) {
  11331. callPageHook(pages[pages.length - 1], hook, args);
  11332. }
  11333. }
  11334. function createCallCurrentPageHook (hook) {
  11335. return function (args) {
  11336. callCurrentPageHook(hook, args);
  11337. }
  11338. }
  11339. function onAppEnterBackground () {
  11340. callAppHook(getApp(), 'onHide');
  11341. callCurrentPageHook('onHide');
  11342. }
  11343. function onAppEnterForeground () {
  11344. callAppHook(getApp(), 'onShow');
  11345. callCurrentPageHook('onShow');
  11346. }
  11347. const routeHooks = {
  11348. navigateTo () {
  11349. callCurrentPageHook('onHide');
  11350. },
  11351. navigateBack () {
  11352. callCurrentPageHook('onShow');
  11353. }
  11354. };
  11355. function onAppRoute ({
  11356. type
  11357. }) {
  11358. const routeHook = routeHooks[type];
  11359. routeHook && routeHook();
  11360. }
  11361. on('onError', onError);
  11362. on('onPageNotFound', onPageNotFound);
  11363. { // 后续有时间,h5 平台也要迁移到 onAppRoute
  11364. on('onAppRoute', onAppRoute);
  11365. }
  11366. on('onAppEnterBackground', onAppEnterBackground);
  11367. on('onAppEnterForeground', onAppEnterForeground);
  11368. on('onResize', onResize);
  11369. on('onPullDownRefresh', onPullDownRefresh);
  11370. on('onTabItemTap', createCallCurrentPageHook('onTabItemTap'));
  11371. on('onNavigationBarButtonTap', createCallCurrentPageHook('onNavigationBarButtonTap'));
  11372. on('onNavigationBarSearchInputChanged', createCallCurrentPageHook('onNavigationBarSearchInputChanged'));
  11373. on('onNavigationBarSearchInputConfirmed', createCallCurrentPageHook('onNavigationBarSearchInputConfirmed'));
  11374. on('onNavigationBarSearchInputClicked', createCallCurrentPageHook('onNavigationBarSearchInputClicked'));
  11375. on('onNavigationBarSearchInputFocusChanged', createCallCurrentPageHook('onNavigationBarSearchInputFocusChanged'));
  11376. on('onWebInvokeAppService', onWebInvokeAppService);
  11377. }
  11378. function initSubscribe (subscribe, {
  11379. getApp,
  11380. getCurrentPages
  11381. }) {
  11382. function createPageEvent (eventType) {
  11383. return function (args, pageId) {
  11384. pageId = parseInt(pageId);
  11385. const pages = getCurrentPages();
  11386. const page = pages.find(page => page.$page.id === pageId);
  11387. if (page) {
  11388. callPageHook(page, eventType, args);
  11389. } else if (process.env.NODE_ENV !== 'production') {
  11390. console.error(`Not Found:Page[${pageId}]`);
  11391. }
  11392. }
  11393. }
  11394. const requestComponentInfoCallbacks = createCallbacks('requestComponentInfo');
  11395. function onRequestComponentInfo ({
  11396. reqId,
  11397. res
  11398. }) {
  11399. const callback = requestComponentInfoCallbacks.pop(reqId);
  11400. if (callback) {
  11401. callback(res);
  11402. }
  11403. }
  11404. const requestComponentObserverCallbacks = createCallbacks('requestComponentObserver');
  11405. function onRequestComponentObserver ({
  11406. reqId,
  11407. reqEnd,
  11408. res
  11409. }) {
  11410. const callback = requestComponentObserverCallbacks.get(reqId);
  11411. if (callback) {
  11412. if (reqEnd) {
  11413. requestComponentObserverCallbacks.pop(reqId);
  11414. return
  11415. }
  11416. callback(res);
  11417. }
  11418. }
  11419. subscribe('onPageScroll', createPageEvent('onPageScroll'));
  11420. subscribe('onReachBottom', createPageEvent('onReachBottom'));
  11421. subscribe('onRequestComponentInfo', onRequestComponentInfo);
  11422. subscribe('onRequestComponentObserver', onRequestComponentObserver);
  11423. }
  11424. function perf (type, startTime) {
  11425. /* eslint-disable no-undef */
  11426. startTime = startTime || __UniServiceStartTime__;
  11427. const endTime = Date.now();
  11428. console.log(`[PERF][${endTime}] ${type} 耗时[${Date.now() - startTime}]`);
  11429. }
  11430. let isLaunchWebviewReady = false; // 目前首页双向确定 ready,可能会导致触发两次 onWebviewReady(主要是 Android)
  11431. function onWebviewReady (data, pageId) {
  11432. const isLaunchWebview = pageId === '1';
  11433. if (isLaunchWebview && isLaunchWebviewReady) {
  11434. if (process.env.NODE_ENV !== 'production') {
  11435. console.log('[uni-app] onLaunchWebviewReady.prevent');
  11436. }
  11437. return
  11438. }
  11439. if (isLaunchWebview) { // 首页
  11440. isLaunchWebviewReady = true;
  11441. setPreloadWebview(plus.webview.getLaunchWebview());
  11442. } else if (!preloadWebview) { // preloadWebview 不存在,重新加载一下
  11443. setPreloadWebview(plus.webview.getWebviewById(pageId));
  11444. }
  11445. if (preloadWebview.id !== pageId) {
  11446. return console.error(`webviewReady[${preloadWebview.id}][${pageId}] not match`)
  11447. }
  11448. preloadWebview.loaded = true; // 标记已 ready
  11449. consumeWebviewReady(pageId);
  11450. if (isLaunchWebview) {
  11451. const entryPagePath = '/' + __uniConfig.entryPagePath;
  11452. const routeOptions = __uniRoutes.find(route => route.path === entryPagePath);
  11453. if (!routeOptions.meta.isNVue) { // 非 nvue 首页,需要主动跳转
  11454. const navigateType = routeOptions.meta.isTabBar ? 'switchTab' : 'navigateTo';
  11455. process.env.NODE_ENV !== 'production' && perf(`${entryPagePath} navigateTo`);
  11456. return uni[navigateType]({
  11457. url: entryPagePath + (__uniConfig.entryPageQuery || ''),
  11458. openType: 'appLaunch'
  11459. })
  11460. }
  11461. }
  11462. }
  11463. const vdSyncHandlers = Object.create(null);
  11464. function registerVdSync (pageId, callback) {
  11465. (vdSyncHandlers[pageId] || (vdSyncHandlers[pageId] = [])).push(callback);
  11466. }
  11467. function removeVdSync (pageId) {
  11468. delete vdSyncHandlers[pageId];
  11469. }
  11470. function onVdSync ({
  11471. data,
  11472. options
  11473. }, pageId) {
  11474. const handlers = vdSyncHandlers[pageId];
  11475. if (Array.isArray(handlers)) {
  11476. handlers.forEach(handler => {
  11477. handler(data);
  11478. });
  11479. }
  11480. }
  11481. const vdSyncCallbacks = []; // 数据同步 callback
  11482. function onVdSyncCallback () {
  11483. const copies = vdSyncCallbacks.slice(0);
  11484. vdSyncCallbacks.length = 0;
  11485. for (let i = 0; i < copies.length; i++) {
  11486. copies[i]();
  11487. }
  11488. }
  11489. function onInvokeApi ({
  11490. data: {
  11491. method,
  11492. args
  11493. }
  11494. }) {
  11495. uni[method] && uni[method](args);
  11496. }
  11497. function onWxsInvokeCallMethod ({
  11498. cid,
  11499. method,
  11500. args
  11501. }, pageId) {
  11502. pageId = parseInt(pageId);
  11503. const page = getCurrentPages(true).find(page => page.$page.id === pageId);
  11504. if (!page) {
  11505. return console.error(`Page[${pageId}] not found`)
  11506. }
  11507. const vm = page.$vm._$vd.getVm(cid);
  11508. if (!vm) {
  11509. return console.error(`vm[${cid}] not found`)
  11510. }
  11511. vm[method] && vm[method](args);
  11512. }
  11513. function findPage (pageId) {
  11514. pageId = parseInt(pageId);
  11515. const page = getCurrentPages(true).find(page => page.$page.id === pageId);
  11516. if (!page) {
  11517. return console.error(`Page[${pageId}] not found`)
  11518. }
  11519. return page
  11520. }
  11521. function onWebviewInserted (data, pageId) {
  11522. const page = findPage(pageId);
  11523. page && (page.__uniapp_webview = true);
  11524. }
  11525. function onWebviewRemoved (data, pageId) {
  11526. const page = findPage(pageId);
  11527. page && (delete page.__uniapp_webview);
  11528. }
  11529. function initSubscribeHandlers () {
  11530. const {
  11531. on,
  11532. emit,
  11533. subscribe,
  11534. publishHandler,
  11535. subscribeHandler
  11536. } = UniServiceJSBridge;
  11537. initSubscribe(subscribe, {
  11538. getApp,
  11539. getCurrentPages
  11540. });
  11541. registerPlusMessage('subscribeHandler', (data) => {
  11542. subscribeHandler(data.type, data.data, data.pageId);
  11543. });
  11544. if (__uniConfig.renderer !== 'native') {
  11545. subscribe(WEBVIEW_READY, onWebviewReady);
  11546. subscribe(VD_SYNC, onVdSync);
  11547. subscribe(VD_SYNC_CALLBACK, onVdSyncCallback);
  11548. const entryPagePath = '/' + __uniConfig.entryPagePath;
  11549. const routeOptions = __uniRoutes.find(route => route.path === entryPagePath);
  11550. if (!routeOptions.meta.isNVue) { // 首页是 vue
  11551. // 防止首页 webview 初始化过早, service 还未开始监听
  11552. publishHandler(WEBVIEW_READY, Object.create(null), [1]);
  11553. }
  11554. }
  11555. // 应该使用subscribe,兼容老版本先用 on api 吧
  11556. on('api.' + WEB_INVOKE_APPSERVICE$1, function (data, webviewIds) {
  11557. emit('onWebInvokeAppService', data, webviewIds);
  11558. });
  11559. subscribe('onWxsInvokeCallMethod', onWxsInvokeCallMethod);
  11560. subscribe(INVOKE_API, onInvokeApi);
  11561. subscribe(WEBVIEW_INSERTED, onWebviewInserted);
  11562. subscribe(WEBVIEW_REMOVED, onWebviewRemoved);
  11563. }
  11564. let appCtx;
  11565. const defaultApp = {
  11566. globalData: {}
  11567. };
  11568. function getApp$1 ({
  11569. allowDefault = false
  11570. } = {}) {
  11571. if (appCtx) { // 真实的 App 已初始化
  11572. return appCtx
  11573. }
  11574. if (allowDefault) { // 返回默认实现
  11575. return defaultApp
  11576. }
  11577. console.error(
  11578. '[warn]: getApp() 操作失败,v3模式加速了首页 nvue 的启动速度,当在首页 nvue 中使用 getApp() 不一定可以获取真正的 App 对象。详情请参考:https://uniapp.dcloud.io/collocation/frame/window?id=getapp'
  11579. );
  11580. }
  11581. function initGlobalListeners () {
  11582. const globalEvent = requireNativePlugin('globalEvent');
  11583. const emit = UniServiceJSBridge.emit;
  11584. // splashclosed 时开始监听 backbutton
  11585. plus.globalEvent.addEventListener('splashclosed', () => {
  11586. plus.key.addEventListener('backbutton', backbuttonListener);
  11587. });
  11588. plus.globalEvent.addEventListener('pause', () => {
  11589. emit('onAppEnterBackground');
  11590. });
  11591. plus.globalEvent.addEventListener('resume', () => {
  11592. emit('onAppEnterForeground');
  11593. });
  11594. plus.globalEvent.addEventListener('netchange', () => {
  11595. const networkType = NETWORK_TYPES[plus.networkinfo.getCurrentType()];
  11596. publish('onNetworkStatusChange', {
  11597. isConnected: networkType !== 'none',
  11598. networkType
  11599. });
  11600. });
  11601. plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) {
  11602. publish('onKeyboardHeightChange', {
  11603. height: event.height
  11604. });
  11605. });
  11606. globalEvent.addEventListener('uistylechange', function (event) {
  11607. publish('onUIStyleChange', {
  11608. style: event.uistyle
  11609. });
  11610. });
  11611. globalEvent.addEventListener('uniMPNativeEvent', function (event) {
  11612. publish('uniMPNativeEvent', event);
  11613. });
  11614. plus.globalEvent.addEventListener('plusMessage', onPlusMessage$1);
  11615. // nvue webview post message
  11616. plus.globalEvent.addEventListener('WebviewPostMessage', onPlusMessage$1);
  11617. }
  11618. function onPlusMessage$1 (e) {
  11619. if (process.env.NODE_ENV !== 'production') {
  11620. console.log('[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data));
  11621. }
  11622. if (e.data && e.data.type) {
  11623. const type = e.data.type;
  11624. consumePlusMessage(type, e.data.args || {});
  11625. }
  11626. }
  11627. function initAppLaunch (appVm) {
  11628. const args = {
  11629. path: __uniConfig.entryPagePath,
  11630. query: {},
  11631. scene: 1001
  11632. };
  11633. callAppHook(appVm, 'onLaunch', args);
  11634. callAppHook(appVm, 'onShow', args);
  11635. }
  11636. function initTabBar () {
  11637. if (!__uniConfig.tabBar || !__uniConfig.tabBar.list.length) {
  11638. return
  11639. }
  11640. __uniConfig.tabBar.selected = 0;
  11641. const selected = __uniConfig.tabBar.list.findIndex(page => page.pagePath === __uniConfig.entryPagePath);
  11642. tabBar$1.init(__uniConfig.tabBar, (item, index) => {
  11643. uni.switchTab({
  11644. url: '/' + item.pagePath,
  11645. openType: 'switchTab',
  11646. from: 'tabBar',
  11647. success () {
  11648. UniServiceJSBridge.emit('onTabItemTap', {
  11649. index,
  11650. text: item.text,
  11651. pagePath: item.pagePath
  11652. });
  11653. }
  11654. });
  11655. });
  11656. if (selected !== -1) {
  11657. // 取当前 tab 索引值
  11658. __uniConfig.tabBar.selected = selected;
  11659. selected !== 0 && tabBar$1.switchTab(__uniConfig.entryPagePath);
  11660. }
  11661. }
  11662. function initEntryPage () {
  11663. let entryPagePath;
  11664. let entryPageQuery;
  11665. const weexPlus = weex.requireModule('plus');
  11666. if (weexPlus.getRedirectInfo) {
  11667. const info = weexPlus.getRedirectInfo() || {};
  11668. entryPagePath = info.path;
  11669. entryPageQuery = info.query ? ('?' + info.query) : '';
  11670. } else {
  11671. const argsJsonStr = plus.runtime.arguments;
  11672. if (!argsJsonStr) {
  11673. return
  11674. }
  11675. try {
  11676. const args = JSON.parse(argsJsonStr);
  11677. entryPagePath = args.path || args.pathName;
  11678. entryPageQuery = args.query ? ('?' + args.query) : '';
  11679. } catch (e) {}
  11680. }
  11681. if (!entryPagePath || entryPagePath === __uniConfig.entryPagePath) {
  11682. return
  11683. }
  11684. const entryRoute = '/' + entryPagePath;
  11685. const routeOptions = __uniRoutes.find(route => route.path === entryRoute);
  11686. if (!routeOptions) {
  11687. return
  11688. }
  11689. if (!routeOptions.meta.isTabBar) {
  11690. __uniConfig.realEntryPagePath = __uniConfig.realEntryPagePath || __uniConfig.entryPagePath;
  11691. }
  11692. __uniConfig.entryPagePath = entryPagePath;
  11693. __uniConfig.entryPageQuery = entryPageQuery;
  11694. if (process.env.NODE_ENV !== 'production') {
  11695. console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`);
  11696. }
  11697. }
  11698. function registerApp (appVm) {
  11699. if (process.env.NODE_ENV !== 'production') {
  11700. console.log('[uni-app] registerApp');
  11701. }
  11702. appCtx = appVm;
  11703. appCtx.$vm = appVm;
  11704. Object.assign(appCtx, defaultApp); // 拷贝默认实现
  11705. const globalData = appVm.$options.globalData || {};
  11706. // merge globalData
  11707. appCtx.globalData = Object.assign(globalData, appCtx.globalData);
  11708. initOn(UniServiceJSBridge.on, {
  11709. getApp: getApp$1,
  11710. getCurrentPages: getCurrentPages$1
  11711. });
  11712. initEntryPage();
  11713. initTabBar();
  11714. initGlobalListeners();
  11715. initSubscribeHandlers();
  11716. initAppLaunch(appVm);
  11717. __uniConfig.ready = true;
  11718. process.env.NODE_ENV !== 'production' && perf('registerApp');
  11719. }
  11720. var tags = [
  11721. 'uni-app',
  11722. 'uni-tabbar',
  11723. 'uni-page',
  11724. 'uni-page-head',
  11725. 'uni-page-wrapper',
  11726. 'uni-page-body',
  11727. 'uni-page-refresh',
  11728. 'uni-actionsheet',
  11729. 'uni-modal',
  11730. 'uni-toast',
  11731. 'uni-resize-sensor',
  11732. 'uni-shadow-root',
  11733. 'uni-ad',
  11734. 'uni-audio',
  11735. 'uni-button',
  11736. 'uni-camera',
  11737. 'uni-canvas',
  11738. 'uni-checkbox',
  11739. 'uni-checkbox-group',
  11740. 'uni-cover-image',
  11741. 'uni-cover-view',
  11742. 'uni-editor',
  11743. 'uni-form',
  11744. 'uni-functional-page-navigator',
  11745. 'uni-icon',
  11746. 'uni-image',
  11747. 'uni-input',
  11748. 'uni-label',
  11749. 'uni-live-player',
  11750. 'uni-live-pusher',
  11751. 'uni-map',
  11752. 'uni-movable-area',
  11753. 'uni-movable-view',
  11754. 'uni-navigator',
  11755. 'uni-official-account',
  11756. 'uni-open-data',
  11757. 'uni-picker',
  11758. 'uni-picker-view',
  11759. 'uni-picker-view-column',
  11760. 'uni-progress',
  11761. 'uni-radio',
  11762. 'uni-radio-group',
  11763. 'uni-rich-text',
  11764. 'uni-scroll-view',
  11765. 'uni-slider',
  11766. 'uni-swiper',
  11767. 'uni-swiper-item',
  11768. 'uni-switch',
  11769. 'uni-text',
  11770. 'uni-textarea',
  11771. 'uni-video',
  11772. 'uni-view',
  11773. 'uni-web-view'
  11774. ];
  11775. function hasLifecycleHook (vueOptions = {}, hook) {
  11776. return Array.isArray(vueOptions[hook]) && vueOptions[hook].length
  11777. }
  11778. // 使用白名单过滤(前期有一批自定义组件使用了 uni-)
  11779. function initVue (Vue) {
  11780. Vue.config.errorHandler = function (err) {
  11781. const app = typeof getApp === 'function' && getApp();
  11782. if (app && hasLifecycleHook(app.$options, 'onError')) {
  11783. app.__call_hook('onError', err);
  11784. } else {
  11785. console.error(err);
  11786. }
  11787. };
  11788. const oldIsReservedTag = Vue.config.isReservedTag;
  11789. Vue.config.isReservedTag = function (tag) {
  11790. return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
  11791. };
  11792. Vue.config.ignoredElements = tags;
  11793. const oldGetTagNamespace = Vue.config.getTagNamespace;
  11794. const conflictTags = ['switch', 'image', 'text', 'view'];
  11795. Vue.config.getTagNamespace = function (tag) {
  11796. if (~conflictTags.indexOf(tag)) { // svg 部分标签名称与 uni 标签冲突
  11797. return false
  11798. }
  11799. return oldGetTagNamespace(tag) || false
  11800. };
  11801. }
  11802. /**
  11803. * 补充一些环境兼容内容,如小程序 需要使用的 selectComponent...
  11804. * 之所以在框架内补充,而不是在 mp-runtime 中处理,是因为小程序自定义组件可能需要获取 page 对象并使用 selectComponent
  11805. * 故, 暂时添加到所有 vm 上
  11806. * @param {Object} Vue
  11807. */
  11808. /**
  11809. * 先简单支持 id 和 class
  11810. * @param {Object} selector
  11811. */
  11812. function parseSelector (selector) {
  11813. if (selector.indexOf('#') === 0) {
  11814. const id = selector.substr(1);
  11815. return function match (vnode) {
  11816. // props
  11817. if (vnode.componentInstance && vnode.componentInstance.id === id) {
  11818. return true
  11819. }
  11820. // attrs
  11821. if (vnode.data && vnode.data.attrs && vnode.data.attrs.id === id) {
  11822. return true
  11823. }
  11824. return false
  11825. }
  11826. } else if (selector.indexOf('.') === 0) {
  11827. const clazz = selector.substr(1);
  11828. return function match (vnode) {
  11829. return vnode.data && matchClass(clazz, vnode.data.staticClass, vnode.data.class)
  11830. }
  11831. }
  11832. }
  11833. const CLASS_RE = /\s+/;
  11834. function matchClass (clazz, staticClass = '', dynamicClass = '') {
  11835. if (staticClass) {
  11836. return staticClass.split(CLASS_RE).indexOf(clazz) !== -1
  11837. }
  11838. if (dynamicClass && typeof dynamicClass === 'string') {
  11839. return dynamicClass.split(CLASS_RE).indexOf(clazz) !== -1
  11840. }
  11841. }
  11842. function querySelector (vm, matchSelector) {
  11843. if (matchSelector(vm.$vnode || vm._vnode)) {
  11844. return vm
  11845. }
  11846. const $children = vm.$children;
  11847. for (let i = 0; i < $children.length; i++) {
  11848. const childVm = querySelector($children[i], matchSelector);
  11849. if (childVm) {
  11850. return childVm
  11851. }
  11852. }
  11853. }
  11854. function querySelectorAll (vm, matchSelector, ret) {
  11855. if (matchSelector(vm.$vnode || vm._vnode)) {
  11856. ret.push(vm);
  11857. }
  11858. const $children = vm.$children;
  11859. for (let i = 0; i < $children.length; i++) {
  11860. querySelectorAll($children[i], matchSelector, ret);
  11861. }
  11862. return ret
  11863. }
  11864. function initPolyfill (Vue) {
  11865. Vue.prototype.createIntersectionObserver = function createIntersectionObserver (options) {
  11866. return uni.createIntersectionObserver(this, options)
  11867. };
  11868. Vue.prototype.selectComponent = function selectComponent (selector) {
  11869. return querySelector(this, parseSelector(selector))
  11870. };
  11871. Vue.prototype.selectAllComponents = function selectAllComponents (selector) {
  11872. return querySelectorAll(this, parseSelector(selector), [])
  11873. };
  11874. }
  11875. /**
  11876. * mpvue event
  11877. */
  11878. function wrapperMPEvent (event) {
  11879. event.mp = Object.assign({
  11880. '@warning': 'mp is deprecated'
  11881. }, event);
  11882. event._processed = true;
  11883. return event
  11884. }
  11885. const isAndroid = plus.os.name.toLowerCase() === 'android';
  11886. const FOCUS_TIMEOUT = isAndroid ? 300 : 700;
  11887. const HIDE_TIMEOUT = isAndroid ? 800 : 300;
  11888. let keyboardHeight = 0;
  11889. let onKeyboardShow;
  11890. let focusTimer;
  11891. let hideKeyboardTimeout;
  11892. function hookKeyboardEvent (event, callback) {
  11893. onKeyboardShow = null;
  11894. focusTimer && clearTimeout(focusTimer);
  11895. if (event.type === 'focus') {
  11896. if (keyboardHeight > 0) {
  11897. event.detail.height = keyboardHeight;
  11898. } else {
  11899. focusTimer = setTimeout(function () {
  11900. event.detail.height = keyboardHeight;
  11901. callback(event);
  11902. }, FOCUS_TIMEOUT);
  11903. onKeyboardShow = function () {
  11904. clearTimeout(focusTimer);
  11905. event.detail.height = keyboardHeight;
  11906. callback(event);
  11907. };
  11908. return
  11909. }
  11910. }
  11911. callback(event);
  11912. }
  11913. onMethod('onKeyboardHeightChange', res => {
  11914. keyboardHeight = res.height;
  11915. if (keyboardHeight > 0) {
  11916. onKeyboardShow && onKeyboardShow();
  11917. if (hideKeyboardTimeout) {
  11918. clearTimeout(hideKeyboardTimeout);
  11919. hideKeyboardTimeout = null;
  11920. }
  11921. } else {
  11922. // 安卓/iOS13收起键盘时通知view层失去焦点
  11923. if (isAndroid || parseInt(plus.os.version) >= 13) {
  11924. hideKeyboardTimeout = setTimeout(function () {
  11925. hideKeyboardTimeout = null;
  11926. var pageId = getCurrentPageId();
  11927. UniServiceJSBridge.publishHandler('hideKeyboard', {}, pageId);
  11928. }, HIDE_TIMEOUT);
  11929. }
  11930. }
  11931. });
  11932. function parseComponentCreateOptions (vm) {
  11933. // 目前方案调整为 service 层直接处理,暂不需要同步配置到 view 层
  11934. // if (vm.$options.mpOptions && vm.$options.mpOptions.externalClasses) {
  11935. // return {
  11936. // mpOptions: {
  11937. // externalClasses: vm.$options.mpOptions.externalClasses
  11938. // }
  11939. // }
  11940. // }
  11941. }
  11942. // TODO 临时通过序列化,反序列化传递dataset,后续可以全部保留在service,不做传递
  11943. function parseDataset$1 (dataset) {
  11944. const ret = Object.create(null);
  11945. Object.keys(dataset).forEach(name => {
  11946. try {
  11947. ret[name] = JSON.parse(dataset[name]);
  11948. } catch (e) { // dataset 存在两种,一种是被JSON.stringify的,一种是原始的
  11949. ret[name] = dataset[name];
  11950. }
  11951. });
  11952. return ret
  11953. }
  11954. function parseTargets (event) {
  11955. const targetDataset = event.target && event.target.dataset;
  11956. if (targetDataset) {
  11957. event.target.dataset = parseDataset$1(targetDataset);
  11958. }
  11959. const currentTargetDataset = event.currentTarget && event.currentTarget.dataset;
  11960. if (currentTargetDataset) {
  11961. event.currentTarget.dataset = parseDataset$1(currentTargetDataset);
  11962. }
  11963. }
  11964. function wrapperEvent (event) {
  11965. parseTargets(event);
  11966. event.preventDefault = noop;
  11967. event.stopPropagation = noop;
  11968. return wrapperMPEvent(event)
  11969. }
  11970. const handleVdData = {
  11971. [UI_EVENT]: function onUIEvent (vdBatchEvent, vd) {
  11972. vdBatchEvent.forEach(([cid, nid, event]) => {
  11973. nid = String(nid);
  11974. const target = vd.elements.find(target => target.cid === cid && target.nid === nid);
  11975. if (!target) {
  11976. return console.error(`event handler[${cid}][${nid}] not found`)
  11977. }
  11978. const type = event.type;
  11979. const mpEvent = wrapperEvent(event);
  11980. if (type === 'focus' || type === 'blur') {
  11981. hookKeyboardEvent(mpEvent, event => {
  11982. target.dispatchEvent(type, event);
  11983. });
  11984. } else {
  11985. target.dispatchEvent(type, mpEvent);
  11986. }
  11987. });
  11988. }
  11989. };
  11990. function onVdSync$1 (vdBatchData, vd) {
  11991. vdBatchData.forEach(([type, vdData]) => {
  11992. handleVdData[type](vdData, vd);
  11993. });
  11994. }
  11995. class VDomSync {
  11996. constructor (pageId, pagePath, pageVm) {
  11997. this.pageId = pageId;
  11998. this.pagePath = pagePath;
  11999. this.pageVm = pageVm;
  12000. this.batchData = [];
  12001. this.vms = Object.create(null);
  12002. this.initialized = false;
  12003. this.pageCreateData = false;
  12004. this.elements = []; // 目前仅存储事件 element
  12005. this._init();
  12006. }
  12007. _init () {
  12008. registerVdSync(this.pageId, (vdBatchData) => {
  12009. onVdSync$1(vdBatchData, this);
  12010. });
  12011. }
  12012. addMountedVm (vm) {
  12013. vm._$mounted(); // 触发vd数据同步
  12014. this.addVdSyncCallback(function mounted () {
  12015. vm.__call_hook('mounted');
  12016. });
  12017. }
  12018. addUpdatedVm (vm) {
  12019. vm._$updated(); // 触发vd数据同步
  12020. this.addVdSyncCallback(function mounted () {
  12021. vm.__call_hook('updated');
  12022. });
  12023. }
  12024. addVdSyncCallback (callback) {
  12025. isFn(callback) && vdSyncCallbacks.push(callback);
  12026. }
  12027. getVm (id) {
  12028. return this.vms[id]
  12029. }
  12030. addVm (vm) {
  12031. this.vms[vm._$id] = vm;
  12032. }
  12033. removeVm (vm) {
  12034. const cid = vm._$id;
  12035. if (vm === this.vms[cid]) { // 仅相同vm的才移除,否则保留
  12036. // 目前同一位置的vm,cid均一样
  12037. // 移除尚未同步的data
  12038. this.batchData = this.batchData.filter(data => data[1][0] !== cid);
  12039. delete this.vms[cid];
  12040. }
  12041. }
  12042. addElement (elm) {
  12043. this.elements.indexOf(elm) === -1 && this.elements.push(elm);
  12044. }
  12045. removeElement (elm) {
  12046. const elmIndex = this.elements.indexOf(elm);
  12047. if (elmIndex === -1) {
  12048. if (process.env.NODE_ENV !== 'production') {
  12049. console.error(`removeElement[${elm.cid}][${elm.nid}] not found`);
  12050. }
  12051. return
  12052. }
  12053. this.elements.splice(elmIndex, 1);
  12054. }
  12055. push (type, cid, data, options) {
  12056. const typeData = [cid, data];
  12057. if (options) {
  12058. typeData.push(options);
  12059. }
  12060. this.batchData.push([type, typeData]);
  12061. }
  12062. find (type, cid) {
  12063. return this.batchData.find(data => data[0] === type && data[1][0] === cid)
  12064. }
  12065. sendPageCreate (data) {
  12066. this.pageCreateData = data;
  12067. UniServiceJSBridge.publishHandler(VD_SYNC, {
  12068. data: [
  12069. [PAGE_CREATE, data]
  12070. ],
  12071. options: {
  12072. timestamp: Date.now()
  12073. }
  12074. }, [this.pageId]);
  12075. }
  12076. flush () {
  12077. if (!this.initialized) {
  12078. this.initialized = true;
  12079. this.batchData.push([PAGE_CREATED, [this.pageId, this.pagePath]]);
  12080. }
  12081. const batchData = this.batchData.filter(data => {
  12082. if (data[0] === UPDATED_DATA && !Object.keys(data[1][1]).length) {
  12083. return false
  12084. }
  12085. return true
  12086. });
  12087. this.batchData.length = 0;
  12088. if (batchData.length) {
  12089. UniServiceJSBridge.publishHandler(VD_SYNC, {
  12090. data: batchData,
  12091. options: {
  12092. timestamp: Date.now()
  12093. }
  12094. }, [this.pageId]);
  12095. }
  12096. }
  12097. restorePageCreate () {
  12098. this.batchData.push([PAGE_CREATE, this.pageCreateData]);
  12099. }
  12100. restoreMountedData () {
  12101. const addMountedData = (vm) => {
  12102. if (vm._$id) {
  12103. this.push(MOUNTED_DATA, vm._$id, vm._$data, parseComponentCreateOptions());
  12104. }
  12105. // TODO vue 中 $children 顺序不可靠,可能存在恢复误差
  12106. vm.$children.forEach(childVm => addMountedData(childVm));
  12107. };
  12108. addMountedData(this.pageVm);
  12109. }
  12110. restorePageCreated () {
  12111. this.batchData.push([PAGE_CREATED, [this.pageId, this.pagePath]]);
  12112. }
  12113. restore () {
  12114. this.initialized = true;
  12115. this.batchData.length = 0;
  12116. this.restorePageCreate();
  12117. this.restoreMountedData();
  12118. this.restorePageCreated();
  12119. this.flush();
  12120. }
  12121. destroy () {
  12122. this.batchData.length = 0;
  12123. this.vms = Object.create(null);
  12124. this.initialized = false;
  12125. this.elements.length = 0;
  12126. removeVdSync(this.pageId);
  12127. }
  12128. }
  12129. function generateId (vm, parent) {
  12130. if (!vm.$parent) {
  12131. return '-1'
  12132. }
  12133. const vnode = vm.$vnode;
  12134. const context = vnode.context;
  12135. // slot 内的组件,需要补充 context 的 id,否则可能与内部组件索引值一致,导致 id 冲突
  12136. if (context && context !== parent && context._$id) {
  12137. if (process.env.NODE_ENV !== 'production') {
  12138. console.log('generateId:' + context._$id + ';' + parent._$id + ',' + vnode.data.attrs._i);
  12139. }
  12140. return context._$id + ';' + parent._$id + ',' + vnode.data.attrs._i
  12141. }
  12142. return parent._$id + ',' + vnode.data.attrs._i
  12143. }
  12144. function setResult (data, k, v) {
  12145. data[k] = v;
  12146. }
  12147. function diffElmData (newObj, oldObj) {
  12148. let result, key, cur, old;
  12149. for (key in newObj) {
  12150. cur = newObj[key];
  12151. old = oldObj[key];
  12152. if (!looseEqual(old, cur)) {
  12153. setResult(result || (result = Object.create(null)), key, cur);
  12154. }
  12155. }
  12156. return result
  12157. }
  12158. function diff (newData, oldData, result) {
  12159. let id, cur, old;
  12160. for (id in newData) {
  12161. cur = newData[id];
  12162. old = oldData[id];
  12163. if (!old) {
  12164. setResult(result, id, cur);
  12165. continue
  12166. }
  12167. const idObj = diffElmData(cur, old);
  12168. idObj && setResult(result, id, idObj);
  12169. }
  12170. return result
  12171. }
  12172. function initData (Vue) {
  12173. Vue.prototype._$s = setData;
  12174. Vue.prototype._$setData = function setData (type, data) {
  12175. this._$vd.push(
  12176. type,
  12177. this._$id,
  12178. data,
  12179. type === MOUNTED_DATA && parseComponentCreateOptions()
  12180. );
  12181. };
  12182. Vue.prototype._$mounted = function mounted () {
  12183. if (!this._$vd) {
  12184. return
  12185. }
  12186. diff(this._$newData, this._$data, this._$vdMountedData);
  12187. this._$data = JSON.parse(JSON.stringify(this._$newData));
  12188. if (this.mpType === 'page') {
  12189. // 页面 mounted 之后,第一次同步数据
  12190. this._$vd.flush();
  12191. }
  12192. };
  12193. Vue.prototype._$updated = function updated () {
  12194. if (!this._$vd) {
  12195. return
  12196. }
  12197. diff(this._$newData, this._$data, this._$vdUpdatedData);
  12198. this._$data = JSON.parse(JSON.stringify(this._$newData));
  12199. // setTimeout 一下再 nextTick( 直接 nextTick 的话,会紧接着该 updated 做 flush,导致父组件 updated 数据被丢弃)
  12200. this._$vd.initialized && setTimeout(() => {
  12201. this.$nextTick(this._$vd.flush.bind(this._$vd));
  12202. }, 0);
  12203. };
  12204. Object.defineProperty(Vue.prototype, '_$vd', {
  12205. get () {
  12206. return this.$root._$vdomSync
  12207. }
  12208. });
  12209. Vue.mixin({
  12210. beforeCreate () {
  12211. if (this.$options.mpType) {
  12212. this.mpType = this.$options.mpType;
  12213. }
  12214. if (this.mpType === 'app') {
  12215. return
  12216. }
  12217. if (this.mpType === 'page') {
  12218. this._$vdomSync = new VDomSync(this.$options.pageId, this.$options.pagePath, this);
  12219. }
  12220. if (this._$vd) {
  12221. this._$id = generateId(this, this.$parent);
  12222. this._$vd.addVm(this);
  12223. this._$vdMountedData = Object.create(null);
  12224. this._$setData(MOUNTED_DATA, this._$vdMountedData);
  12225. this._$data = Object.create(null);
  12226. this._$newData = Object.create(null);
  12227. }
  12228. },
  12229. beforeUpdate () {
  12230. if (!this._$vd) {
  12231. return
  12232. }
  12233. // 当已存在 _$vdMountedData 时,使用重置后的 _$vdMountedData
  12234. const mountedData = this._$vd.find(MOUNTED_DATA, this._$id);
  12235. if (mountedData) {
  12236. this._$data = Object.create(null); // 清空已有数据
  12237. this._$vdUpdatedData = mountedData[1][1] = Object.create(null);
  12238. if (process.env.NODE_ENV !== 'production') {
  12239. console.log('updated=>mounted:' + this._$id);
  12240. }
  12241. } else {
  12242. this._$vdUpdatedData = Object.create(null);
  12243. this._$setData(UPDATED_DATA, this._$vdUpdatedData);
  12244. }
  12245. this._$newData = Object.create(null);
  12246. },
  12247. beforeDestroy () {
  12248. if (!this._$vd) {
  12249. return
  12250. }
  12251. this._$vd.removeVm(this);
  12252. this._$vdomSync && this._$vdomSync.destroy();
  12253. }
  12254. });
  12255. }
  12256. function parseExternalClasses (clazz, vm) {
  12257. const mpOptions = vm.$options.mpOptions;
  12258. if (mpOptions && Array.isArray(mpOptions.externalClasses)) {
  12259. mpOptions.externalClasses.forEach(externalClass => {
  12260. // 简单替换 externalClass
  12261. const externalClassValue = vm[camelize(externalClass)];
  12262. externalClassValue && (clazz = clazz.replace(externalClass, externalClassValue));
  12263. });
  12264. }
  12265. return clazz
  12266. }
  12267. function setData (id, name, value) {
  12268. switch (name) {
  12269. case B_CLASS:
  12270. value = parseExternalClasses(this._$stringifyClass(value), this);
  12271. break
  12272. case S_CLASS:
  12273. value = parseExternalClasses(value, this);
  12274. break
  12275. case B_STYLE:
  12276. value = this._$normalizeStyleBinding(value);
  12277. break
  12278. case V_IF:
  12279. case V_SHOW:
  12280. case V_ELSE_IF:
  12281. value = value ? 1 : 0;
  12282. break
  12283. case V_FOR:
  12284. return setForData.call(this, id, value)
  12285. }
  12286. // TODO 暂时先传递 dataset 至 view 层(理论上不需要)
  12287. if (name.indexOf('a-data-') === 0) {
  12288. try {
  12289. value = JSON.stringify(value);
  12290. } catch (e) {}
  12291. }
  12292. return ((this._$newData[id] || (this._$newData[id] = {}))[name] = value)
  12293. }
  12294. function fillVForData (forItems, vForData) {
  12295. let i, l;
  12296. if (Array.isArray(forItems) || typeof forItems === 'string') {
  12297. for (i = 0, l = forItems.length; i < l; i++) {
  12298. vForData[i] = i;
  12299. }
  12300. } else if (typeof forItems === 'number') {
  12301. for (i = 0; i < forItems; i++) {
  12302. vForData[i] = i;
  12303. }
  12304. } else if (isObject(forItems)) {
  12305. for (i = 0, l = Object.keys(forItems).length; i < l; i++) {
  12306. vForData[i] = i;
  12307. }
  12308. }
  12309. }
  12310. function setForData (id, value) {
  12311. const diffData = this._$newData[id] || (this._$newData[id] = {});
  12312. const vForData = diffData[V_FOR] || (diffData[V_FOR] = []);
  12313. if (value.forItems) {
  12314. value.fill && fillVForData(value.forItems, vForData);
  12315. return value.forItems
  12316. }
  12317. const {
  12318. forIndex,
  12319. key
  12320. } = value;
  12321. if (!hasOwn(value, 'keyIndex')) {
  12322. vForData[forIndex] = key;
  12323. } else {
  12324. (vForData[forIndex] || (vForData[forIndex] = {}))['k' + value.keyIndex] = key;
  12325. }
  12326. return key
  12327. }
  12328. /* @flow */
  12329. const LIFECYCLE_HOOKS = [
  12330. // App
  12331. 'onLaunch',
  12332. 'onShow',
  12333. 'onHide',
  12334. 'onUniNViewMessage',
  12335. 'onError',
  12336. // Page
  12337. 'onLoad',
  12338. // 'onShow',
  12339. 'onReady',
  12340. // 'onHide',
  12341. 'onUnload',
  12342. 'onPullDownRefresh',
  12343. 'onReachBottom',
  12344. 'onTabItemTap',
  12345. 'onShareAppMessage',
  12346. 'onResize',
  12347. 'onPageScroll',
  12348. 'onNavigationBarButtonTap',
  12349. 'onBackPress',
  12350. 'onNavigationBarSearchInputChanged',
  12351. 'onNavigationBarSearchInputConfirmed',
  12352. 'onNavigationBarSearchInputClicked',
  12353. 'onNavigationBarSearchInputFocusChanged',
  12354. // Component
  12355. // 'onReady', // 兼容旧版本,应该移除该事件
  12356. 'onPageShow',
  12357. 'onPageHide',
  12358. 'onPageResize',
  12359. // 小程序的 created,attached 生命周期(需要在 service 层的 Vue 内核 mounted 时触发,因小程序 created 可以使用 selectComponent)
  12360. 'onServiceCreated',
  12361. 'onServiceAttached'
  12362. ];
  12363. const KEYS = ['data', 'properties', 'options', 'relations'];
  12364. function mergeObject (ret, fromVal, key) {
  12365. if (fromVal[key]) {
  12366. Object.assign((ret[key] || (ret[key] = {})), fromVal[key]);
  12367. }
  12368. }
  12369. function mergeArray (toArray, fromArray) {
  12370. toArray.push(...fromArray);
  12371. }
  12372. function mergeOptions (ret, toVal) {
  12373. KEYS.forEach(key => {
  12374. mergeObject(ret, toVal, key);
  12375. });
  12376. if (toVal.externalClasses) {
  12377. mergeArray((ret.externalClasses || (ret.externalClasses = [])), toVal.externalClasses);
  12378. }
  12379. if (toVal.path) {
  12380. ret.path = toVal.path;
  12381. }
  12382. }
  12383. function lifecycleMixin (Vue) {
  12384. // fixed vue-class-component
  12385. const oldExtend = Vue.extend;
  12386. Vue.extend = function (extendOptions) {
  12387. extendOptions = extendOptions || {};
  12388. const methods = extendOptions.methods;
  12389. if (methods) {
  12390. Object.keys(methods).forEach(methodName => {
  12391. if (LIFECYCLE_HOOKS.indexOf(methodName) !== -1) {
  12392. extendOptions[methodName] = methods[methodName];
  12393. delete methods[methodName];
  12394. }
  12395. });
  12396. }
  12397. return oldExtend.call(this, extendOptions)
  12398. };
  12399. const strategies = Vue.config.optionMergeStrategies;
  12400. const mergeHook = strategies.created;
  12401. LIFECYCLE_HOOKS.forEach(hook => {
  12402. strategies[hook] = mergeHook;
  12403. });
  12404. // mp runtime
  12405. strategies.mpOptions = function (toVal, fromVal) {
  12406. // data,properties,options,externalClasses,relations,path
  12407. if (!toVal) {
  12408. return fromVal
  12409. }
  12410. const ret = Object.create(null);
  12411. mergeOptions(ret, toVal);
  12412. if (fromVal) {
  12413. mergeOptions(ret, fromVal);
  12414. }
  12415. return ret
  12416. };
  12417. }
  12418. function parsePageCreateOptions (vm, route) {
  12419. const pagePath = '/' + route;
  12420. const routeOptions = __uniRoutes.find(route => route.path === pagePath);
  12421. const windowOptions = Object.assign({}, __uniConfig.window, routeOptions.window);
  12422. const disableScroll = windowOptions.disableScroll === true ? 1 : 0;
  12423. const onReachBottomDistance = hasOwn(windowOptions, 'onReachBottomDistance')
  12424. ? parseInt(windowOptions.onReachBottomDistance)
  12425. : ON_REACH_BOTTOM_DISTANCE;
  12426. const onPageScroll = hasLifecycleHook(vm.$options, 'onPageScroll') ? 1 : 0;
  12427. const onPageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom') ? 1 : 0;
  12428. const statusbarHeight = getStatusbarHeight();
  12429. return {
  12430. disableScroll,
  12431. onPageScroll,
  12432. onPageReachBottom,
  12433. onReachBottomDistance,
  12434. statusbarHeight,
  12435. windowTop: windowOptions.titleNView && windowOptions.titleNView.type === 'float' ? (statusbarHeight +
  12436. TITLEBAR_HEIGHT) : 0,
  12437. windowBottom: (tabBar$1.indexOf(route) >= 0 && tabBar$1.cover) ? tabBar$1.height : 0
  12438. }
  12439. }
  12440. function initLifecycle (Vue) {
  12441. lifecycleMixin(Vue);
  12442. Vue.mixin({
  12443. beforeCreate () {
  12444. // TODO 临时解决方案,service 层也注入 wxs (适用于工具类)
  12445. const options = this.$options;
  12446. // 自动挂载 $store
  12447. if (options.store && !Vue.prototype.$store) {
  12448. Vue.prototype.$store = options.store;
  12449. }
  12450. const wxs = options.wxs;
  12451. if (wxs) {
  12452. Object.keys(wxs).forEach(module => {
  12453. this[module] = wxs[module];
  12454. });
  12455. }
  12456. if (this.mpType === 'page') {
  12457. this.$scope = this.$options.pageInstance;
  12458. this.$scope.$vm = this;
  12459. delete this.$options.pageInstance;
  12460. const route = this.$scope.route;
  12461. const pageId = this.$scope.$page.id;
  12462. // 通知页面已开始创建
  12463. this._$vd.sendPageCreate([pageId, route, parsePageCreateOptions(this, route)]);
  12464. }
  12465. },
  12466. created () {
  12467. if (this.mpType === 'page') {
  12468. // 理论上应该从最开始的 parseQuery 的地方直接 decode 两次,为了减少影响范围,先仅处理 onLoad 参数
  12469. callPageHook(this.$scope, 'onLoad', decodedQuery(this.$options.pageQuery));
  12470. callPageHook(this.$scope, 'onShow');
  12471. }
  12472. },
  12473. beforeDestroy () {
  12474. if (this.mpType === 'page') {
  12475. callPageHook(this.$scope, 'onUnload');
  12476. }
  12477. },
  12478. mounted () {
  12479. if (this.mpType === 'page') {
  12480. callPageHook(this.$scope, 'onReady');
  12481. }
  12482. }
  12483. });
  12484. }
  12485. var vuePlugin = {
  12486. install (Vue, options) {
  12487. initVue(Vue);
  12488. initData(Vue);
  12489. initLifecycle(Vue);
  12490. initPolyfill(Vue);
  12491. Object.defineProperty(Vue.prototype, '$page', {
  12492. get () {
  12493. return this.$root.$scope.$page
  12494. }
  12495. });
  12496. // 兼容旧版本
  12497. Object.defineProperty(Vue.prototype, '$mp', {
  12498. get () {
  12499. return {
  12500. page: this.$root.$scope
  12501. }
  12502. }
  12503. });
  12504. const oldMount = Vue.prototype.$mount;
  12505. Vue.prototype.$mount = function mount (el, hydrating) {
  12506. if (this.mpType === 'app') {
  12507. this.$options.render = function () {};
  12508. registerApp(this);
  12509. }
  12510. return oldMount.call(this, el, hydrating)
  12511. };
  12512. Vue.prototype.$nextTick = function nextTick (cb) {
  12513. const renderWatcher = this._watcher;
  12514. const callback = typeof cb === 'function';
  12515. const result = new Promise((resolve) => {
  12516. if (
  12517. renderWatcher &&
  12518. this._$queue.find(watcher => renderWatcher === watcher)
  12519. ) {
  12520. vdSyncCallbacks.push(callback ? cb.bind(this) : resolve);
  12521. } else {
  12522. // $nextTick bind vm context
  12523. Vue.nextTick(callback ? () => cb.call(this) : resolve);
  12524. }
  12525. callback && resolve();
  12526. });
  12527. return callback ? undefined : result
  12528. };
  12529. }
  12530. };
  12531. // 挂靠在uni上,暂不做全局导出
  12532. uni$1.__$wx__ = wx;
  12533. UniServiceJSBridge.publishHandler = publishHandler;
  12534. UniServiceJSBridge.invokeCallbackHandler = invokeCallbackHandler;
  12535. var index = {
  12536. __vuePlugin: vuePlugin,
  12537. __definePage: definePage,
  12538. __registerApp: registerApp,
  12539. __registerPage: registerPage,
  12540. uni: uni$1,
  12541. getApp: getApp$1,
  12542. getCurrentPages: getCurrentPages$1
  12543. };
  12544. return index;
  12545. }());
  12546. var uni = serviceContext.uni
  12547. var getApp = serviceContext.getApp
  12548. var getCurrentPages = serviceContext.getCurrentPages
  12549. var __definePage = serviceContext.__definePage
  12550. var __registerPage = serviceContext.__registerPage
  12551. return serviceContext
  12552. }