living.vue 238 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096
  1. <template>
  2. <view class="swiper-wrapper" :class="liveItem.showType == 1 ? 'horizontal' : ''">
  3. <view class="container">
  4. <!-- 预告直播状态 -->
  5. <view :class="liveItem.previewUrl?'trailer-box':'trailer-box2'" v-if="liveItem.status == 1">
  6. <view class="video-container2"
  7. :style="{ paddingBottom:liveItem.previewUrl?videoRatio + '%':'' ,height:auto,width:'100%'}">
  8. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="trailer-video"
  9. :src="liveItem.previewUrl" :autoplay="true" :loop="false"
  10. :object-fit="isHeight?'contain':'fill'" :custom-cache="false" :enable-progress-gesture="false"
  11. vslide-gesture-in-fullscreen="false" :show-center-play-btn="false" :http-cache="false"
  12. @error="videoError" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  13. @play="onVideoPlay" :disable-progress="true" :enable-play-gesture="true"
  14. @waiting="onVideoWaiting" preload="auto" type="application/x-mpegURL" :controls="false"></video>
  15. </view>
  16. <image v-if="liveItem.status == 1 && !liveItem.previewUrl" class="trailer-placeholder"
  17. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/readyStart.png">
  18. </image>
  19. <view class="countdown-container" v-if="liveItem.status == 1 && liveCountdown">
  20. <view class="live-name" v-if="liveItem.previewUrl">{{ liveItem.liveName }}</view>
  21. <view class="countdown-display">
  22. <text class="countdown-label">距离开播还有</text>
  23. <view class="countdown-unit">
  24. {{ liveCountdown.hours || '00' }}
  25. </view>
  26. <view class="countdown-separator">:</view>
  27. <view class="countdown-unit">
  28. {{ liveCountdown.minutes || '00' }}
  29. </view>
  30. <view class="countdown-separator">:</view>
  31. <view class="countdown-unit">
  32. {{ liveCountdown.seconds || '00' }}
  33. </view>
  34. </view>
  35. </view>
  36. <view class="trailer-actions">
  37. <button open-type="share" class="button-reset share-button">
  38. <view class="action-button mr24" @click="handleAgreement">
  39. <text>分享给好友</text>
  40. </view>
  41. </button>
  42. <view class="action-button reserve-button" @click="handleAgreement">
  43. <text>{{ hasSubscribed ? '已预约' : '预约直播'}}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 无直播状态 -->
  48. <view class="trailer-box" v-if="!liveItem">
  49. <image class="trailer-placeholder"
  50. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no_live.png">
  51. </image>
  52. <view class="no-live-title">暂无直播</view>
  53. </view>
  54. <!-- 主要内容区域 -->
  55. <view class="content"
  56. :class="{ 'horizontal-content': isFocus==1, 'trailer-content': liveItem.status==1, 'fullscreen-mode': isFullscreen }">
  57. <!-- 顶部信息栏 -->
  58. <view class="top-info-bar" v-if="!isFullscreen"
  59. :class="{'horizontal-top': liveItem.showType == 1,'hidden-on-fullscreen': isFullscreen}"
  60. :style="{marginTop: menuButtonInfo.top}">
  61. <view class="user-info-section">
  62. <image v-if="!scene&&liveItem.showType==2" @click="goBack" class="back-icon mr4"
  63. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/return3.png" />
  64. <image v-if="!scene&&liveItem.showType==1" @click="goBack" class="w42 h42 mr4"
  65. src="/static/images/return_black.png" />
  66. <view class="user-avatar-container">
  67. <u-avatar
  68. :src="liveItem.liveImgUrl || 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar.png'"
  69. :size="32"></u-avatar>
  70. <view class="user-name ml10 mr6">
  71. <view>{{ liveItem.liveName ? truncateString(liveItem.liveName, 8) : '未命名' }}</view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 观众头像列表 -->
  76. <!-- @click="toggleViewerList" -->
  77. <view v-if="Array.isArray(filteredViewers)" class="viewers-section">
  78. <view style="display: flex;align-items: center;">
  79. <view v-for="(item, index) in (filteredViewers ||[])" :key="index">
  80. <image v-if="item" class="viewer-avatar mr4" :src="item" />
  81. </view>
  82. <view class="viewer-count ">{{formattedWatchCount || 0 }}</view>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- 视频区域 -->
  87. <view class="videolist" v-if="liveItem.status == 2" :class="isFullscreen ? 'screen' : ''">
  88. <view class="video-container"
  89. :style="{ paddingBottom: liveItem.showType==2||isFullscreen?'':videoRatio + '%',height:liveItem.showType==2?'100vh':isFullscreen?'auto':'400rpx',width:isFullscreen?'0':'100%'}"
  90. :class="{'horizontal-layout': liveItem.showType == 1,'fullscreen-mode': isFullscreen}">
  91. <video v-if="liveItem.videoUrl && liveItem.liveType == 2 && !generating"
  92. :id="`myVideo_${liveId}`" :autoplay="true" class="video-player" :src="liveItem.videoUrl"
  93. :style="{transform:liveItem.showType!==2?`scale(${scale})`:'', transformOrigin: 'center center', bottom:isFullscreen?'0':''}"
  94. :object-fit="liveItem.showType==2||isFullscreen?'contain':'fill'" :custom-cache="false"
  95. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  96. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  97. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  98. @play="onVideoPlay" @waiting="onVideoWaiting" :enable-play-gesture="false"
  99. :play-strategy="1" @dblclick="preventDoubleClick" preload="auto"
  100. :enable-stash-buffer="false" :stash-initial-size="0" :stash-max-size="0" :stash-time="0"
  101. type="application/x-mpegURL" :controls="false" :show-fullscreen-btn="false" show-play-btn
  102. show-mute-btn enable-play-gesture="true" @fullscreenchange="onFullscreenChange"
  103. x5-video-player-fullscreen="false" x5-video-player-type="h5"
  104. x5-video-orientation="landscape" :webkit-playsinline="true" playsinline="true"
  105. :x5-playsinline="true">
  106. </video>
  107. <view v-else class="txt">回放生成中...</view>
  108. <view v-if="showCustomControls && liveItem.showType==1 && !isFullscreen" class="custom-controls"
  109. @click.stop="toggleFullscreen">
  110. <image src="/static/images/full_screen.png" class="control-icon" />
  111. </view>
  112. <!-- 全屏返回按钮 - 只在全屏状态下显示 -->
  113. <view v-if="isFullscreen" class="fullscreen-exit-btn" @click="exitFullscreen">
  114. <image src="/static/images/half_screen.png" class="exit-fullscreen-icon" />
  115. <text class="exit-text">退出全屏</text>
  116. </view>
  117. <!-- 投诉按钮 -->
  118. <view v-if="liveItem.showType==2||isFullscreen" class="complaint-box"
  119. :class="isFullscreen ? 'complaint-full' : ''"
  120. :style="{top:isFullscreen?'':'15%',bottom:isFullscreen?'86vw':''}"
  121. @click="navgetTo('/pages_shopping/live/complaintList') ">
  122. <image class="image w32 h32 mr10" src="/static/images/complaint.png" mode="widthFix" />
  123. <view class="fs26">投诉</view>
  124. </view>
  125. <!-- 回放标签 -->
  126. <view v-if="isPlayback" class="replay-label"
  127. :style="{top:liveItem.showType === 2?'22%':isFullscreen?'':'10%',bottom:isFullscreen?'75vw':''}"
  128. :class="isFullscreen? 'replay-full' : ''">回放
  129. </view>
  130. <!-- 观看时间 -->
  131. <view class="look-time" v-if="isPlayback&&liveItem.showType==1"
  132. :class="isFullscreen ? 'look-full' : '' ">{{playbackTime}}</view>
  133. </view>
  134. </view>
  135. <!-- 直播结束状态 -->
  136. <!-- v-if="liveItem.status == 3" -->
  137. <view class="videolist" v-if="liveItem.status == 3">
  138. <view class="video-container" style="height: 500rpx;"
  139. :class="{'horizontal-layout': liveItem.showType == 1, 'fullscreen-mode': isFullscreen}">
  140. <view class="live-end-message" :style="{marginTop:liveItem.showType === 2?'50%':''}">直播已结束
  141. </view>
  142. </view>
  143. </view>
  144. <!-- 直播回放 -->
  145. <view class="videolist" v-if="liveItem.status == 4">
  146. <view class="video-container" :class="liveItem.showType == 1 ? 'horizontal-layout' : ''">
  147. <video v-if="liveItem.videoUrl && liveItem.liveType == 3" :id="`myVideo_${liveId}`"
  148. class="video-player" :src="liveItem.videoUrl" :autoplay="true" :controls="true"
  149. :object-fit="isFullscreen?'contain':'contain'" :custom-cache="false"
  150. :enable-progress-gesture="liveItem.isSpeedAllowed" vslide-gesture-in-fullscreen="true"
  151. :show-center-play-btn="true" :http-cache="false" loop @error="videoError"
  152. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  153. @play="onVideoPlay" :enable-play-gesture="true" preload="auto" @waiting="onVideoWaiting"
  154. type="application/x-mpegURL"></video>
  155. <view v-if="liveItem.videoUrl && liveItem.liveType == 3" class="replay-label">直播回放</view>
  156. </view>
  157. </view>
  158. <!-- v-if="!hasReachedTarget" -->
  159. <!-- &&liveItem.completionPointsEnabled -->
  160. <view class="progress-countdown end" :class="liveItem.showType==2?' progress-vertical':''"
  161. :style="{ 'display':isFocus?'none':''}"
  162. v-if="countdownPercentage!=100&&liveItem.completionPointsEnabled&&!receiveStatus&&liveItem.status==2&&!hasReceived&&!isPreview">
  163. <image class="title" src="/static/images/points_title.png"></image>
  164. <view class="progress-bar-bg">
  165. <view class="progress-bar-fill" :style="{ width: countdownPercentage + '%' }"></view>
  166. </view>
  167. <view class="progress-text">
  168. 倒计时{{ formattedCountdown.hours||'00' }}:{{ formattedCountdown.minutes||'00' }}:{{ formattedCountdown.seconds||"00" }}
  169. </view>
  170. </view>
  171. <view class="slide-group" v-if="!isFocus && !isFullscreen">
  172. <view class="action-button-group end">
  173. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','ml20']">
  174. <button open-type="share" class="action-icon button-reset">
  175. <!-- <image class="action-icon"
  176. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/fs/20251231/de30446abc5644fdac8438e6aa7058b6.png"
  177. mode="widthFix" /> -->
  178. <image class="action-icon"
  179. src="@/static/images/weixin1.png"
  180. mode="widthFix" />
  181. </button>
  182. </view>
  183. </view>
  184. <view class="action-button-group end">
  185. <view
  186. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','ml20','like-container']"
  187. @click="onLike">
  188. <LikeButton :initialCount="100" :heartsPerClick="5" @like="onLike" />
  189. <view class="like-count">{{formattedLikeCount||0 }}</view>
  190. </view>
  191. </view>
  192. </view>
  193. <!-- 底部聊天区域 -->
  194. <view class="chat-area-container" :class="{
  195. 'chat-area-container2': liveItem.showType == 1,
  196. 'chat-area-container3': liveItem.status == 1 && !liveItem.previewUrl && liveItem.showType == 1,
  197. 'chat-area-container4': liveItem.status == 1 && liveItem.previewUrl && liveItem.showType == 1,
  198. 'chat-area-focused': isFocus
  199. }" :style="{ '--keyboard-height': keyboardHeight + 'rpx' ,'display':isFullscreen?'none':''}">
  200. <view class="tabs_bg" v-if="liveItem.showType == 1">
  201. <u-tabs :list="listTabs" @click="clickTabs" lineColor="#02B176"
  202. :activeStyle="{color: '#02B176',fontWeight: 'bold',transform: 'scale(1.05)'}">
  203. </u-tabs>
  204. <!-- 投诉 -->
  205. <view v-if="liveItem.showType==1" class="complaint-box"
  206. @click="navgetTo('/pages_shopping/live/complaintList') ">
  207. <image class="image w32 h32 mr10" src="/static/images/complaint2.png" mode="widthFix" />
  208. <view class="fs26">投诉</view>
  209. </view>
  210. </view>
  211. <view class="chat-content-wrapper"
  212. :style="{ 'height':liveItem.status == 1 && !liveItem.previewUrl && liveItem.showType == 2?'48vh':''}"
  213. :class="{ 'chat-content-focused': isFocus }">
  214. <view class="notice-message" v-if="isShowNotice"
  215. :style="{ 'display':isFocus&&liveItem.showType == 2?'none':''}"
  216. :class="liveItem.showType == 1 ? 'horizontal-notice' : 'horizontal-notice2'">
  217. 公告消息: {{notice.msg}}
  218. </view>
  219. <scroll-view id="msgScroll" v-if="Array.isArray(talklist)" enable-flex scroll-y="true"
  220. :style="{ height: liveItem.showType === 1 || liveItem.showType == 2 && !isFocus?`calc(100% - ${commonViewHeight}px)`:'',
  221. marginTop:liveItem.showType === 1?commonViewHeight+'px':liveItem.showType == 2 && !isFocus?`calc(${commonViewHeight}px + 20rpx)`:'' }" :enhanced="true" :bounces="false"
  222. :show-scrollbar="false" :fast-deceleration="false" :enable-back-to-top="false"
  223. class="message-scroll-view" :scroll-top="scrollTop" :scroll-into-view="scrollIntoView"
  224. @scroll="onScroll" ref="scrollView">
  225. <view class="message-list" v-for="(item, talkIndex) in (talklist || [])"
  226. :key="item.uniqueId" :id="`list_${item.uniqueId}`" v-show="item.cmd != 'red' ">
  227. <view class="message-item">
  228. <view class="message-content">
  229. <text class="user-nickname">{{ item.nickName || '未命名' }}
  230. <text v-if="item.cmd != 'entry'">:</text>
  231. </text>
  232. <text class="message-text ml8">{{ item.msg }}</text>
  233. </view>
  234. </view>
  235. </view>
  236. </scroll-view>
  237. </view>
  238. <!-- 底部输入和操作区域 -->
  239. <view class="input-actions-container" :class="{ 'input-actions-focused': isFocus }">
  240. <view v-if="liveItem.status!=3&&!isPlayback&&!generating" class="input-container" :class="{
  241. 'input-container-focused': isFocus,
  242. 'input-container-normal': !isFocus
  243. }">
  244. <input v-if="isIOS" type="text" :placeholder="placeholderText" v-model="value"
  245. :placeholder-style="liveItem.showType == 1 ? 'color:#999999;' : 'color:#e7e7e7;'"
  246. placeholder-class="placeholder-style" class="chat-input"
  247. :class="{ 'input-focused': isFocus }" @focus="inputFocus" @blur="inputBlur"
  248. cursor-spacing="100" :adjust-position="false" :disabled="isEnd" @confirm="sendMsg"
  249. :confirm-type="value?'send':'done'" />
  250. <input v-else :placeholder="placeholderText" v-model="value" type="text"
  251. :placeholder-style="liveItem.showType == 1 ? 'color:#999999;' : 'color:#e7e7e7;'"
  252. placeholder-class="placeholder-style" class="chat-input"
  253. :class="{ 'input-focused': isFocus }" @focus="inputFocus" @blur="inputBlur"
  254. cursor-spacing="100" :adjust-position="false" :disabled="isEnd" @confirm="sendMsg"
  255. :confirm-type="value?'send':'done'" />
  256. <view class="send-button" v-if="!isIOS" :class="liveItem.showType == 1 ? 'send2' : ''"
  257. @click="sendMsg()">
  258. 发送</view>
  259. </view>
  260. <!-- :class="{ 'action-buttons-hidden': isFocus }" -->
  261. <view class="action-buttons" v-if="!isFocus">
  262. <view class="action-button-group" v-if="!isFocus">
  263. <view
  264. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','mr40']"
  265. @click="isMore=true,shopping=false">
  266. <!-- <image src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/more-icon.png"
  267. class="action-icon" /> -->
  268. <image :src="liveItem.showType == 1
  269. ? '/static/images/more2.png'
  270. :'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/more-icon.png'"
  271. class="action-icon" />
  272. </view>
  273. </view>
  274. <view class="icon-button mr20" @tap="openCart()">
  275. <image
  276. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/fs/20251231/8376c769d7154f04b13cbec4a76bacf0.png"
  277. class="cart-icon" />
  278. </view>
  279. </view>
  280. </view>
  281. </view>
  282. </view>
  283. <!-- 商品卡片 -->
  284. <view class="goods-card" v-if="isShowGoods&&!isFullscreen"
  285. @click.stop="goShop(goodsCard.productId, goodsCard.goodsId)">
  286. <view class="goods-card-header">
  287. <view class="goods-status">
  288. <image class="status-icon mr8"
  289. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/signal.png" />
  290. 主播讲解中
  291. </view>
  292. <image @click.stop="isShowGoods = false" class="close-icon" src="/static/images/close_w.png" />
  293. </view>
  294. <image class="goods-image" :src="goodsCard.imgUrl" />
  295. <view class="goods-info">
  296. <view class="goods-title oneline-hide">{{ goodsCard.productName }}</view>
  297. <view class="goods-action">
  298. <view class="goods-price">
  299. <text class="price-symbol">¥<text class="price-integer">{{ goodsCard.price }}</text> <text
  300. class="price-decimal"></text></text>
  301. </view>
  302. <image class="shop-icon" src="/static/images/shop.png"></image>
  303. </view>
  304. </view>
  305. </view>
  306. <!-- :show="userlogo" -->
  307. <u-popup :show="userlogo" mode="bottom" round='12'>
  308. <view class="userlogo column">
  309. <view class="bold fs36 mt42">授权你的昵称信息</view>
  310. <view class=" justify-between align-center mt42">
  311. <view class="button-container">
  312. <input type="nickname" class="hidden-input"
  313. placeholder-style="color:#ffffff; font-size:32rpx;" @blur="onNickNameInput"
  314. placeholder="请点击授权微信昵称" @input="onNickNameInput" />
  315. </view>
  316. </view>
  317. <view class="submitname" @click="confimrname">确定</view>
  318. </view>
  319. </u-popup>
  320. <!-- 抽奖弹窗 -->
  321. <u-popup :show="isShowLotteryPop && countdown" round="40rpx">
  322. <view class="lottery-popup">
  323. <image class="lottery-header-image"
  324. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  325. mode="widthFix" />
  326. <image class="lottery-background-image"
  327. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_bg.png" />
  328. <view class="lottery-content">
  329. <view class="lottery-close-section">
  330. <view class="close-button-wrapper">
  331. <view class="close-button" @click="isShowLotteryPop = false">
  332. <u-icon class="close-icon" name="close" color="#fff" size="20"></u-icon>
  333. </view>
  334. </view>
  335. </view>
  336. <view class="lottery-main-content">
  337. <image class="lottery-title-image"
  338. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_title.png" />
  339. <view class="lottery-countdown-section">
  340. <view class="countdown-label">开奖倒计时</view>
  341. <view class="countdown-timer">
  342. <view class="countdown-number">
  343. {{ countdown.hours || '00' }}
  344. </view>
  345. <view class="countdown-number">
  346. {{ countdown.minutes || '00' }}
  347. </view>
  348. <view class="countdown-number">
  349. {{ countdown.seconds || '00' }}
  350. </view>
  351. </view>
  352. </view>
  353. <view class="lottery-products-section">
  354. <ThreeItemSwiper :products="lotteryProducts"></ThreeItemSwiper>
  355. </view>
  356. <view class="lottery-indicators">
  357. <view class="indicator-point" v-for="(item, index) in (lotteryProducts || [])"
  358. :key="index"></view>
  359. </view>
  360. <view class="lottery-tip">观看直播参与抽奖</view>
  361. <view class="lottery-action-button" @click="onClaim">参与抽奖</view>
  362. </view>
  363. </view>
  364. </view>
  365. </u-popup>
  366. <!-- 积分弹窗(完课) -->
  367. <!-- showPoints -->
  368. <!-- :show="!!integral.status" -->
  369. <!-- :show="showPoints" -->
  370. <!-- :show="shouldShowIntegralPopup" -->
  371. <u-popup :show="shouldShowIntegralPopup" round="20rpx" mode="center" bgColor="#ffffff" zIndex="10076">
  372. <view class="integral-popup color9">
  373. <view class="integral-header">
  374. <view class="integral-title">观看视频领积分</view>
  375. <image class="integral-background-image"
  376. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/integral_bg.png"
  377. mode="widthFix" />
  378. </view>
  379. <view class="integral-content">
  380. <view class="integral-message">积分发放成功</view>
  381. <!-- <view class="integral-confirm-button" @click="showPoints = false">确认</view> -->
  382. </view>
  383. <!-- <view class="integral-content">
  384. <view class="integral-item" v-for="(item,index ) in receiveList" :key="index">
  385. <view class="integral-message">连续签到{{item.continuousDays}}天</view>
  386. <view class="integral-message">获取{{item.pointsAwarded}}积分</view>
  387. <view class="integral-confirm-button" @click="completionReceive(item)">领取</view>
  388. </view>
  389. </view> -->
  390. </view>
  391. </u-popup>
  392. <!-- 积分弹窗(时长) -->
  393. <u-popup :show="!!integral.status" round="20rpx" mode="center" bgColor="#ffffff" zIndex="10076">
  394. <view class="integral-popup color9">
  395. <view class="integral-header">
  396. <view class="integral-title">观看视频领积分</view>
  397. <image class="integral-background-image"
  398. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/integral_bg.png"
  399. mode="widthFix" />
  400. </view>
  401. <view class="integral-content">
  402. <view class="integral-message">{{ integral.msg }}</view>
  403. <view class="integral-confirm-button" @click="integral.status = false">确认</view>
  404. </view>
  405. </view>
  406. </u-popup>
  407. <!-- 红包弹窗 -->
  408. <u-popup :show="isShowRed" round="20rpx" mode="center" zIndex="10076" bgColor="transparent">
  409. <view class="red-envelope-popup" @click="onRed()">
  410. <image class="red-envelope-close-button"
  411. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png"
  412. @click.stop="isShowRed=false"></image>
  413. <image class="red-envelope-background"
  414. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop1.png">
  415. </image>
  416. <view class="red-envelope-content">
  417. <view class="red-envelope-header">
  418. <image class="header-decoration-left"
  419. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_left.png"
  420. mode="widthFix" />
  421. <view class="header-title">恭喜您可以</view>
  422. <image class="header-decoration-right"
  423. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_right.png"
  424. mode="widthFix" />
  425. </view>
  426. <view class="red-envelope-text">领红包</view>
  427. <view class="red-envelope-open-text">开</view>
  428. </view>
  429. </view>
  430. </u-popup>
  431. <!-- 抽奖弹窗2 -->
  432. <u-popup :show="isShowLottery&&countdown" round="20rpx" mode="center" zIndex="10076" bgColor="transparent">
  433. <view class="lottery-popup-v2">
  434. <image class="lottery-close-button-v2"
  435. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png"
  436. @click.stop="isShowLottery=false">
  437. </image>
  438. <image class="lottery-top-image"
  439. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop_top.png"
  440. mode="widthFix"></image>
  441. <image class="lottery-background-v2"
  442. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop2.png">
  443. </image>
  444. <view class="lottery-content-v2">
  445. <view class="lottery-header-v2">
  446. <image class="lottery-header-decoration-left"
  447. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_left.png"
  448. mode="widthFix" />
  449. <view class="lottery-header-title">恭喜您可以</view>
  450. <image class="lottery-header-decoration-right"
  451. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_right.png"
  452. mode="widthFix" />
  453. </view>
  454. <view class="lottery-text-v2">参与抽奖</view>
  455. <view class="lottery-text-v2">赢好礼</view>
  456. <view class="lottery-action-button-v2" @click="onLottery()">确认</view>
  457. </view>
  458. </view>
  459. </u-popup>
  460. <!-- 红包卡片弹窗 -->
  461. <u-popup :show="isShowRedCard" round="20rpx" mode="center" bgColor="transparent" zIndex="10076">
  462. <view class="red-card-popup">
  463. <image class="red-card-image"
  464. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_card.png" />
  465. <view class="red-card-content">
  466. <view class="red-card-message">{{ redCard.msg }}</view>
  467. <view class="red-card-tip">直播惊喜积分</view>
  468. <view class="red-card-confirm-button" @click="isShowRedCard = false">确认</view>
  469. </view>
  470. </view>
  471. </u-popup>
  472. <!-- 消息弹窗 -->
  473. <u-popup :show="isShowPopMsg" round="20rpx" mode="center" zIndex="10076">
  474. <view class="message-popup">
  475. <image class="message-close-icon" src="/static/images/message_icon.png" />
  476. <view class="message-title">消息通知</view>
  477. <view class="message-content">{{popMsg}}</view>
  478. <view class="message-confirm-button" @click="isShowPopMsg = false">确认</view>
  479. <image src="/static/images/close_white_icon.png" class="close" @click="isShowPopMsg = false">
  480. </image>
  481. </view>
  482. </u-popup>
  483. <!-- 中奖和未中奖 -->
  484. <u-popup :show="isShowPrize && havePrize" round="20rpx" mode="center" bgColor="#fff" zIndex="10076">
  485. <view class="prize-popup" v-if="isCurrentUserWon">
  486. <image class="prize-header-image"
  487. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  488. mode="widthFix" />
  489. <view class="prize-title">恭喜您 中奖啦!</view>
  490. <view class="prize-info-section" v-for="(item, index) in (prizeInfo || [])" :key="index">
  491. <view class="prize-info-item">{{ item.userName }}</view>
  492. <view class="prize-info-item">{{ item.userId }}</view>
  493. <view class="prize-level item">{{ item.prizeLevel }}等奖</view>
  494. </view>
  495. <view class="prize-tip">请填写收货地址,主播将会将奖品发给您</view>
  496. <view class="prize-action-button"
  497. @click="navgetTo('/pages_shopping/live/confirmCreateOrder?type=win&productId='+getCurrentUserPrizeProductId+'&liveId='+liveId+'&recordId='+getCurrentUserPrizeRecordId),confirm()">
  498. 填写地址</view>
  499. </view>
  500. <view class="no-prize-popup" v-else>
  501. <image class="no-prize-image"
  502. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no-prize.png"
  503. mode="widthFix" />
  504. <view class="no-prize-tip">很遗憾 您未中奖</view>
  505. <view class="no-prize-confirm-button" @click="confirm">确认</view>
  506. </view>
  507. </u-popup>
  508. <!-- 中奖记录弹窗 -->
  509. <u-popup :show="winning" @close="closeWin" round="20rpx" bgColor="#f3f5f9" zIndex="10076">
  510. <view class="winning-record-popup">
  511. <image class="winning-record-header-bg"
  512. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  513. mode="widthFix"></image>
  514. <image class="winning-record-background"
  515. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_bg.png">
  516. </image>
  517. <view class="winning-record-content">
  518. <view class="winning-record-title">我的中奖记录</view>
  519. <view class="winning-record-header">
  520. <view class="header-column time-column">时间</view>
  521. <view class="header-column status-column">状态</view>
  522. <view class="header-column prize-column">奖品</view>
  523. </view>
  524. <scroll-view v-if="prizeAll" enable-flex scroll-y class="winning-record-list">
  525. <view class="winning-record-item" v-for="(item, index) in (prizeAll||[])" :key="index">
  526. <view class="record-time">{{ item.createTime }}</view>
  527. <view class="record-status-button" v-if="item.orderStatus=='-9'||!item.orderStatus"
  528. @click="navgetTo('/pages_shopping/live/confirmCreateOrder?type=win&productId='+item.productId+'&liveId='+liveId+'&recordId='+item.id),winning=false">
  529. <text>填地址</text>
  530. </view>
  531. <view class="record-status" v-else>
  532. <text v-if="item.orderStatus=='1'">待支付</text>
  533. <text v-if="item.orderStatus=='2'">待发货</text>
  534. <text v-if="item.orderStatus=='3'">待收货</text>
  535. <text v-if="item.orderStatus=='4'">已完成</text>
  536. <text v-if="item.orderStatus=='-3'">已取消</text>
  537. </view>
  538. <view class="record-prize">
  539. {{ item.productName ? truncateString(item.productName, 6) : '' }}
  540. </view>
  541. </view>
  542. </scroll-view>
  543. <view v-else class="no-winning-records">暂无中奖信息</view>
  544. </view>
  545. </view>
  546. </u-popup>
  547. <!-- 更多操作弹窗 -->
  548. <u-popup :show="isMore" @close="closeMore" round="20rpx" bgColor="#f3f5f9" zIndex="10076">
  549. <view class="more-actions-popup">
  550. <view class="more-action-item"
  551. @click="navgetTo('/pages_shopping/live/integral?liveId'+liveId), (isMore = false)">
  552. <image class="action-icon"
  553. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/order.png" />
  554. <view class="action-label">积分</view>
  555. </view>
  556. <!-- <view class="more-action-item"
  557. @click="navgetTo('/pages_shopping/live/storeOrderRefundList?liveId=' + liveId), (isMore = false)">
  558. <image class="action-icon"
  559. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/after_sales.png" />
  560. <view class="action-label">售后订单</view>
  561. </view> -->
  562. <view class="more-action-item" @click="goMiniProgram(), (isMore = false)">
  563. <image class="action-icon"
  564. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/points.png" />
  565. <view class="action-label">兑换好礼</view>
  566. </view>
  567. <view class="more-action-item" @click="getMyLottery(), (isMore = false), (winning = true)">
  568. <image class="action-icon"
  569. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/health_sel.png" />
  570. <view class="action-label">中奖记录</view>
  571. </view>
  572. </view>
  573. </u-popup>
  574. <!-- 商品弹窗 -->
  575. <u-popup :show="shopping" @close="closeShop" round="20rpx" bgColor="#f3f5f9" zIndex="10075">
  576. <view class="shopping-popup">
  577. <view class="shopping-header">
  578. <view class="search-input-container">
  579. <image class="search-icon"
  580. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/search.png"
  581. mode="widthFix" />
  582. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  583. </view>
  584. <view class="x-f">
  585. <view class="shopping-action-button mr30"
  586. @click="navgetTo('/pages_user/user/storeOrder?status=')">
  587. <image class="action-button-icon"
  588. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/carts.png" />
  589. <view class="action-button-label">订单</view>
  590. </view>
  591. <view class="shopping-action-button" @click="(isMore = true), (shopping = false)">
  592. <image class="action-button-icon"
  593. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/search2.png" />
  594. <view class="action-button-label">更多</view>
  595. </view>
  596. </view>
  597. </view>
  598. <scroll-view enable-flex scroll-y class="products-list">
  599. <view v-for="(item, index) in products" :key="index" class="product-item">
  600. <view class="product-image-container">
  601. <image class="product-image" :src="item.imgUrl" mode="widthFix" />
  602. <view class="product-index-label">{{ index + 1 }}</view>
  603. </view>
  604. <view class="product-info">
  605. <view class="product-name">{{ item.productName }}</view>
  606. <!-- <view class="product-sales">{{ item.sales }} 人已购</view> -->
  607. <view class="product-action-section">
  608. <text class="product-price">
  609. <text class="price-symbol">¥</text>
  610. <text class="price-integer">{{ Math.trunc(item.price) }}</text>
  611. .{{ getPureDecimal(item.price) ? getPureDecimal(item.price) : '00' }}
  612. </text>
  613. <view class="product-action-buttons">
  614. <view class="collect-button">
  615. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  616. class="collect-icon"
  617. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/collect_select.png" />
  618. <image v-else @click="onGoodsCollect(item)" class="collect-icon"
  619. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/collect.png" />
  620. </view>
  621. <view v-if="item.status == 1" class="buy-button"
  622. @click="goShop(item.productId, item.goodsId)">去购买</view>
  623. <view v-else-if="item.status == 0" class="buy-button disabled">已下架</view>
  624. </view>
  625. </view>
  626. </view>
  627. </view>
  628. </scroll-view>
  629. </view>
  630. </u-popup>
  631. <!-- 优惠券弹窗 -->
  632. <view class="coupon-popup" v-if="isShowCoupon">
  633. <view class="coupon-container">
  634. <image class="coupon-background"
  635. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/coupon_bg.png" />
  636. <image class="coupon-header"
  637. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/coupon_top.png" />
  638. <image @click="isShowCoupon = false" class="coupon-close-button"
  639. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png" />
  640. <view class="coupon-content">
  641. <view class="coupon-name">{{ couponInfo.couponName }}</view>
  642. <view class="coupon-price">
  643. <text class="coupon-price-integer">{{ couponInfo.couponPrice }}</text>
  644. </view>
  645. <view class="coupon-condition">满{{ couponInfo.useMinPrice }}元可用</view>
  646. <view class="coupon-description">指定商品可用</view>
  647. <view class="coupon-validity">自领取起{{ couponInfo.couponTime }}天内有效</view>
  648. <view class="coupon-get-button" @click="onCoupon()">立即领券</view>
  649. </view>
  650. </view>
  651. </view>
  652. <view v-if="liveItem.status == 1" class="ash_bg"></view>
  653. <view class="custom-toast" v-if="showToast">
  654. <view class="toast-content">
  655. 完课积分已到账
  656. </view>
  657. </view>
  658. </view>
  659. <CustomToast ref="customToast">
  660. </CustomToast>
  661. </view>
  662. </template>
  663. <script>
  664. import {
  665. CustomToast
  666. } from '@/components/custom-toast.vue';
  667. import LikeButton from '@/pages_course/components/like.vue';
  668. import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue';
  669. import CryptoJS from 'crypto-js';
  670. import {
  671. myLiveMsg,
  672. myLottery, // 我的中奖明细
  673. coupon, //领取优惠券
  674. liveLottery, // 抽奖查询
  675. claim, //抽奖
  676. liveRed, // 点击领红包
  677. liveDataLike, // 点赞
  678. collectStore, // 店铺收藏/取消收藏
  679. collectGoods, // 商品收藏/取消收藏
  680. watchUserList, //获取直播间用户(展示在线用户)
  681. liveMsg, //获取最近聊天记录
  682. // 小黄车
  683. liveStore, //店铺展示,
  684. liveOrderUser, //正在购买
  685. getLiveInfo, //获取直播间信息接口
  686. getLiveViewData, //直播间点赞、关注、在线人数数据
  687. currentActivities, //红包 卡片 抽奖
  688. getlive,
  689. subNotifyLive,
  690. internetTraffic, // 流量(缓冲百分比),
  691. liveInternetTraffic, // 直播流量(缓冲百分比),
  692. loginByMp,
  693. getUserInfo,
  694. getIsAddKf,
  695. liveWatchUser
  696. } from '@/api/living.js';
  697. import {
  698. editUser
  699. } from '@/api/user'
  700. import {
  701. checkPurchaseLimit
  702. } from '@/api/product'
  703. import {
  704. nextTick
  705. } from 'vue';
  706. import {
  707. mapGetters
  708. } from 'vuex';
  709. import {
  710. TOKEN_KEYAuto,
  711. generateRandomString
  712. } from '@/utils/courseTool.js'
  713. import {
  714. completionRecords,
  715. completionReceive,
  716. completionUnreceived,
  717. remainingTime,
  718. updateWatchDuration,
  719. receivePoints,
  720. integrallogs
  721. } from '@/api/integral.js'
  722. import dayjs from 'dayjs';
  723. var isSocketOpen = false;
  724. var socket = null;
  725. export default {
  726. components: {
  727. ThreeItemSwiper,
  728. LikeButton,
  729. CustomToast
  730. },
  731. data() {
  732. return {
  733. showToast: false, //完课弹窗
  734. videoDuration: 0, //要看的时长
  735. pointsRemainingTime: 0,
  736. hasReceived: false,
  737. receiveStatus: false,
  738. completionRate: 0,
  739. playbackTime: '00:00:00', //用户观看回放时间
  740. // 观看时长统计变量
  741. watchStartTime: 0, // 开始观看时间戳
  742. accumulatedWatchDuration: 0, // 累计观看时长(秒)
  743. isPageVisible: true, // 页面是否可见
  744. lastPauseTime: 0,
  745. qwCode: false,
  746. hasReachedTarget: false,
  747. receiveList: [],
  748. recordId: null, //完课积分记录ID
  749. showPoints: false,
  750. remainingTime: 0, // 剩余时间(秒)
  751. watchProgressKey: '', // 存储键
  752. isCountdownActive: false, // 倒计时是否激活
  753. countdownTimer: null, // 倒计时定时器
  754. lastUpdateTime: 0, // 上次更新时间
  755. totalWatchTime: 0, // 累计观看时间(秒)
  756. watchTimeStorageKey: '', // 存储键
  757. lastSaveTime: 0, // 上次保存时间
  758. watchTimeTimer: null, // 观看时间定时器
  759. hasSubscribed: false, // 已成功订阅(永久禁用)
  760. urlOption: {},
  761. menuButtonInfo: {}, // 胶囊按钮布局信息
  762. isHeight: false,
  763. isFullscreen: false,
  764. isVideoRotated: false,
  765. showNonVideoElementsFlag: true,
  766. videoRatio: 56.25, // 默认16:9比例
  767. scale: 1,
  768. isMuted: false,
  769. showCustomControls: true,
  770. videoContext: null,
  771. isNow: false,
  772. fakeAvatar: Array.from({
  773. length: 11
  774. }, (_, i) =>
  775. `https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar${i + 1}.jpg`),
  776. virtualHuman: null,
  777. userlogo: false,
  778. listTabs: [{
  779. name: '讨论',
  780. }],
  781. generating: false,
  782. hasPlayback: false,
  783. isPlayback: false, //是否是回放
  784. isIOS: false,
  785. myselfFlag: false, // yhq
  786. isEnd: false,
  787. popMsg: null,
  788. // barrageList: ['支持你!', '谢谢你!', '平台真好!', '666', '欢迎回家!'], //一键弹幕列表
  789. uuId: '',
  790. totalTraffic: 0, // 总流量(字节)
  791. bitrate: 800, // 录播默认码率 0.16Mbps
  792. bitrateLive: 1600, // 直播默认码率 0.16Mbps
  793. videoLoaded: false, // 视频是否加载成功
  794. isManualPause: false, // 是否手动暂停
  795. waitingTimer: null, // 视频等待定时器
  796. waitingStartTime: 0, // 视频等待开始时间
  797. lastVideoUpdateTime: 0, // 视频最后更新时间
  798. trafficStartTime: 0, // 流量计算开始时间
  799. liveBeginWatchTime: 0, //开始观看的时间点 不包含预告
  800. //定时器
  801. trafficTimer: null,
  802. pingTimeoutTimer: null, // 心跳超时定时器
  803. heartBeatTimer: null, // 心跳定时器
  804. liveViewDataTimer: null,
  805. reconnectTimer: null, // 重连定时器
  806. scrollTimer: null, // 滚动防抖定时器
  807. lastScrollTime: 0, // 上次滚动时间
  808. scrollDebounceDelay: 200, // 滚动防抖延迟(毫秒)
  809. searchTimer: null, //搜索
  810. purchasePromptTimer: null, //购买提示
  811. welcomeTimer: null, //进入离开直播间定时器
  812. redTimer: null,
  813. liveStartTimer: null,
  814. lotteryTimer: null,
  815. memoryMonitorTimer: null, // 内存监控定时器
  816. networkStatusTimer: null, // 网络状态检测定时器
  817. networkRetryTimer: null, // 网络重试定时器
  818. lastHeartBeatTime: 0, // 上次心跳时间
  819. // 性能监控
  820. connectionStartTime: 0, // 连接开始时间
  821. connectionLatency: 0, // 连接延迟
  822. messageCount: 0, // 消息计数
  823. errorCount: 0, // 错误计数
  824. lastPerformanceCheck: 0, // 上次性能检查时间
  825. stayTime: 0,
  826. startTime: 0,
  827. goShoppingMap: {}, // 记录正在处理的商品跳转,防止重复点击(key: productId_goodsId)
  828. scrollTop: 0,
  829. currentScrollTop: 0, // 当前实际滚动位置
  830. scrollIntoView: '', // scroll-into-view属性
  831. messageIdCounter: 0, // 消息ID计数器,确保每个消息有唯一ID
  832. scrollPending: false, // 滚动操作是否正在等待执行
  833. isOnload: false,
  834. isConnecting: false, // 是否正在连接中
  835. hasInitialized: false,
  836. // 请求状态标记,防止重复请求
  837. isLoadingLiveInfo: false, // 是否正在加载直播间信息
  838. isLoadingVideo: false, // 是否正在加载视频资源
  839. hasCheckedLogin: false, // 是否已检查登录状态
  840. hasLoadedLocation: false, // 是否已加载位置信息
  841. liveViewersData: [],
  842. liveUserCalled: false, //调用过watchUserList没
  843. userRandomColors: Object.create(null), // 缓存用户ID -> 随机色的映射
  844. heartBeatRetryCount: 0, // 心跳发送重试次数(避免一次失败就重连)
  845. maxHeartBeatRetries: 3, // 心跳最大重试次数(增加到3次)
  846. pingTimeout: 25000, // 心跳超时时间(25秒,适应移动网络)
  847. shownEntryUsers: new Set(), // 存储已显示过「进入提示」的用户ID
  848. socket: null, // WebSocket 实例
  849. isSocketOpen: false, // 连接是否已打开
  850. heartBeatInterval: 15000, // 心跳发送间隔(15秒)
  851. adaptiveHeartBeatInterval: 15000, // 自适应心跳间隔
  852. reconnectCount: 0, // 当前重连次数f
  853. maxReconnectAttempts: 5, // 最大重连次数(增加到5次)
  854. isManualClose: false, // 是否手动关闭(用于区分主动关闭和异常断开)
  855. networkType: 'unknown', // 当前网络类型
  856. isNetworkAvailable: true, // 网络是否可用
  857. templateId: 'JO9ZKlZES7vqxza82uSVyepLk8jbgYO75EGGEzXzje4', //云联精选
  858. //templateId: 'ELHbRqBdzSV7ttXTWw7RgnddnIqkj2-ld8dMU-gJmyU', //乐享优品
  859. isAgreement: false,
  860. wsNewUrl: 'wss://api.fhhx.runtzh.com/ws/app/webSocket',
  861. // wsNewUrl: 'ws://192.168.10.166:7114/ws/app/webSocket',
  862. qrFrom: null,
  863. scene: '',
  864. liveCountdown: {}, //直播倒计时
  865. countdown: {}, //抽奖倒计时
  866. liveViewData: {},
  867. keyboardHeight: 0,
  868. videoCurrentTime: 0, // 当前视频播放时间
  869. videoProgressKey: '', // 存储进度的key
  870. inAndOut: {},
  871. winning: false,
  872. isShowPrize: false,
  873. isShowCoupon: false,
  874. prizeInfo: [],
  875. havePrize: uni.getStorageSync('havePrize') || false, //是否参与抽奖
  876. countDownKey: 0,
  877. lotteryProducts: [],
  878. lotteryList: [],
  879. talklist: [],
  880. isShowLotteryPop: false,
  881. liveItem: {},
  882. isSending: false,
  883. isMore: false,
  884. value: '',
  885. placeholderText: '说点什么...',
  886. prizeAll: [],
  887. isShowLottery: false,
  888. isShowRedCard: false,
  889. isShowPopMsg: false,
  890. isShowNotice: false,
  891. notice: [],
  892. redCard: null, //点击红包出现弹窗
  893. integral: {},
  894. lotteryInfo: {},
  895. goodsCard: {},
  896. couponInfo: {},
  897. redInfo: {},
  898. storeId: null,
  899. isFocus: false,
  900. shopping: false,
  901. systemInfo: null, // 缓存系统信息,避免重复调用同步API
  902. generatingTimer: null, //回访生成中
  903. getlivingTimer: null, // getliving 防抖定时器
  904. inputInfo: '',
  905. showWelcomeMessage: false,
  906. isShowGoods: false,
  907. isShowRed: false,
  908. lastClickTime: 0,
  909. videoRetryCounts: Object.create(null), // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  910. clickDelay: 300, // 300ms内只响应一次点击
  911. liveUserTotal: 0,
  912. viewPageSize: 10, // 每页数量
  913. viewPageNum: 1, // 当前页码
  914. viewLoading: false, // 是否正在加载
  915. scrollHeight: 0,
  916. showPurchasePrompt: false,
  917. prevOrderCount: 0, // 用于记录上一次的购买人数
  918. videoUrl: null,
  919. showType: 1, //横屏1 竖屏2
  920. boxHeight: 300, //小黄车高度
  921. liveViewers: [], //观众
  922. livingUrl: '',
  923. products: [],
  924. loadingProducts: false, // 商品加载状态
  925. orderUser: {}, //正在购买
  926. userType: 0,
  927. timestamp: '',
  928. showadd: false,
  929. liveId: null,
  930. userInfo: {}, //用户信息
  931. userData: {},
  932. diffTotalTime: '',
  933. address: '',
  934. commonViewHeight: '',
  935. user: {},
  936. watchDuration: 0,
  937. liveFlag: -1, //0 回放 1 直播
  938. isPreview: true, //是否预告
  939. hasReplayGeneration: false, //是否经历回放生成
  940. diffLiveStartTime: 0, //距离直播开始时间差值
  941. diffLiveEndTime: 0, //距离直播结束时间差值
  942. diffReplayGenerationSeconds: 0, //经历回放生成的秒速
  943. completionTime: 0, //领取积分所需时间
  944. hasLiveEnd: false, //是否经历过首播结束
  945. isPageLoadFirst: true, //是否首次加载直播间
  946. pointsRetryTimer: null, // 积分领取重试定时器
  947. completionPointsEnabled: false //是否开启积分
  948. };
  949. },
  950. async onLoad(options) {
  951. this.getMenuButtonInfo(); // 初始化获取胶囊信息
  952. this.initTime();
  953. // 解析参数
  954. if (options.liveId) {
  955. this.liveId = options.liveId;
  956. }
  957. if (options.qwUserId) {
  958. this.urlOption.companyId = options.companyId
  959. this.urlOption.companyUserId = options.companyUserId
  960. this.urlOption.corpId = options.corpId
  961. this.urlOption.liveId = options.liveId
  962. this.urlOption.qwUserId = options.qwUserId
  963. this.urlOption.qwExternalId = options.externalId
  964. this.urlOption.chatId = options.chatId
  965. }
  966. // 扫码传来的参数
  967. if (options.scene) {
  968. this.scene = options.scene;
  969. const decodedScene = decodeURIComponent(this.scene);
  970. const params = {};
  971. decodedScene.split('&').forEach((item) => {
  972. const [key, value] = item.split('=');
  973. params[key] = value;
  974. this.liveId = params.a;
  975. });
  976. if (params.b && params.c) {
  977. console.log("扫码参数", params)
  978. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  979. }
  980. }
  981. if (options.companyId && options.companyUserId) {
  982. this.qrFrom = `&companyId=${options.companyId}&companyUserId=${options.companyUserId}`;
  983. }
  984. this.userinfo = uni.getStorageSync('userinfo');
  985. this.hasSubscribed = uni.getStorageSync('subscribe_status_' + this.liveId) || false;
  986. console.log('全部参数', options);
  987. // 优先判断登录状态,然后加载数据
  988. // this.userData = uni.getStorageSync('userData');
  989. try {
  990. const isLogin = await this.utils.checkLiveToken();
  991. this.hasCheckedLogin = true;
  992. if (isLogin) {
  993. // 登录后:优先加载直播间信息,然后加载视频资源
  994. await this.haveLogin();
  995. } else {
  996. // 未登录:先登录,登录成功后再加载数据
  997. this.goLogin();
  998. }
  999. } catch (error) {
  1000. console.error('初始化失败:', error);
  1001. this.hasCheckedLogin = true;
  1002. }
  1003. // 异步加载位置信息(不阻塞主流程)
  1004. if (!this.hasLoadedLocation) {
  1005. this.getLocationByIP();
  1006. }
  1007. //获取键盘高度 - 针对iPhone优化(使用缓存的系统信息)
  1008. uni.onKeyboardHeightChange((res) => {
  1009. console.log('键盘高度变化:', res.height, '平台:', this.systemInfo.platform);
  1010. if (this.systemInfo.platform === 'ios') {
  1011. // iPhone特殊处理
  1012. if (res.height > 0) {
  1013. // 键盘弹出
  1014. this.isKeyboardShow = true;
  1015. // iPhone键盘高度计算优化
  1016. let calculatedHeight = res.height * 2;
  1017. // 根据iPhone型号进行微调
  1018. if (this.systemInfo.model) {
  1019. if (this.systemInfo.model.includes('iPhone X') ||
  1020. this.systemInfo.model.includes('iPhone 11') ||
  1021. this.systemInfo.model.includes('iPhone 12') ||
  1022. this.systemInfo.model.includes('iPhone 13') ||
  1023. this.systemInfo.model.includes('iPhone 14') ||
  1024. this.systemInfo.model.includes('iPhone 15') ||
  1025. this.systemInfo.model.includes('iPhone 16') ||
  1026. this.systemInfo.model.includes('iPhone 17')) {
  1027. // 刘海屏设备需要额外调整
  1028. calculatedHeight = calculatedHeight + 20; // 增加20rpx补偿
  1029. }
  1030. }
  1031. // 减去底部安全区域,避免过高
  1032. const safeAreaBottom = this.systemInfo.safeAreaInsets ? this.systemInfo.safeAreaInsets
  1033. .bottom : 0;
  1034. if (safeAreaBottom > 0) {
  1035. calculatedHeight = calculatedHeight - (safeAreaBottom * 2.0); // 微调10rpx
  1036. }
  1037. this.keyboardHeight = Math.max(400, calculatedHeight);
  1038. } else {
  1039. // 键盘隐藏
  1040. this.isKeyboardShow = false;
  1041. this.keyboardHeight = 0;
  1042. }
  1043. } else {
  1044. console.log("手机型号是>>>>", this.systemInfo.model)
  1045. // Android处理保持原有逻辑
  1046. if (res.height > 0) {
  1047. this.isKeyboardShow = true;
  1048. const safeAreaBottom = this.systemInfo.safeAreaInsets ? this.systemInfo.safeAreaInsets
  1049. .bottom : 0;
  1050. // this.keyboardHeight = (res.height * 2)-50;
  1051. // this.keyboardHeight = res.height * 2;
  1052. if (this.systemInfo.brand == 'vivo') {
  1053. this.keyboardHeight = res.height * 2;
  1054. } else {
  1055. // this.keyboardHeight = (res.height * 1.78) + 20;''
  1056. this.keyboardHeight = (res.height * 1.88) + 20;
  1057. }
  1058. console.log("高度是", this.keyboardHeight)
  1059. } else {
  1060. this.isKeyboardShow = false;
  1061. this.keyboardHeight = 0;
  1062. }
  1063. }
  1064. });
  1065. // 初始化网络状态监听
  1066. this.initNetworkStatusListener();
  1067. },
  1068. async onPullDownRefresh() {
  1069. // 下拉刷新时,重新加载数据
  1070. if (this.liveId) {
  1071. // 重置加载状态,允许重新加载
  1072. this.isLoadingLiveInfo = false;
  1073. //await this.getliving(this.liveId);
  1074. await this.getLiveMsg(this.liveItem);
  1075. }
  1076. setTimeout(() => {
  1077. uni.stopPullDownRefresh();
  1078. }, 1000);
  1079. this.getliving(this.liveId);
  1080. },
  1081. mounted() {
  1082. // 获取 video 上下文
  1083. // 监听视频全屏事件
  1084. setTimeout(() => {
  1085. this.videoContext = uni.createVideoContext(`myVideo_${this.liveId}`, this);
  1086. // 添加全屏状态变化监听(更可靠的方式)
  1087. if (this.videoContext) {
  1088. // 使用 uni.onUserCaptureScreen 作为备选方案
  1089. uni.onUserCaptureScreen(() => {
  1090. console.log('用户截屏,可能是全屏状态');
  1091. });
  1092. }
  1093. }, 1000);
  1094. },
  1095. async onShow() {
  1096. // 清除商品跳转标志位,允许用户从商品详情页返回后再次点击
  1097. this.goShoppingMap = {};
  1098. setTimeout(() => {
  1099. this.startCountdown();
  1100. }, 500);
  1101. const systemInfo = uni.getSystemInfoSync();
  1102. this.isIOS = systemInfo.platform === 'ios';
  1103. console.log(systemInfo, '当前系统型号')
  1104. if (!this.hasCheckedLogin) {
  1105. try {
  1106. const isLogin = await this.utils.checkLiveToken();
  1107. this.hasCheckedLogin = true;
  1108. if (isLogin) {
  1109. await this.haveLogin();
  1110. if (this.urlOption.qwUserId) {
  1111. this.getIsAddKf()
  1112. }
  1113. } else {
  1114. this.goLogin();
  1115. }
  1116. } catch (error) {
  1117. console.error('初始化失败:', error);
  1118. this.hasCheckedLogin = true;
  1119. }
  1120. }
  1121. // 位置信息只加载一次
  1122. if (!this.hasLoadedLocation) {
  1123. this.getLocationByIP();
  1124. }
  1125. this.uuId = generateRandomString(16);
  1126. const isLiveLogin = uni.getStorageSync('isLiveLogin');
  1127. this.share = uni.getStorageSync('share');
  1128. this.scene = uni.getStorageSync('scene');
  1129. if (this.share && this.share.length > 0) {
  1130. this.liveId = this.share.liveId;
  1131. this.qrFrom = `&companyId=${this.share.companyId}&companyUserId=${this.share.companyUserId}`;
  1132. uni.removeStorageSync('share');
  1133. }
  1134. if (this.scene) {
  1135. const decodedScene = decodeURIComponent(this.scene);
  1136. const params = {};
  1137. decodedScene.split('&').forEach((item) => {
  1138. const [key, value] = item.split('=');
  1139. params[key] = value;
  1140. this.liveId = params.a;
  1141. });
  1142. if (params.b && params.c) {
  1143. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  1144. }
  1145. uni.removeStorageSync('scene');
  1146. }
  1147. // 恢复播放和连接
  1148. await this.resumePageActivity();
  1149. // 恢复观看时长统计(如果之前已经开始统计)
  1150. if (this.watchStartTime > 0 || this.accumulatedWatchDuration > 0) {
  1151. this.resumeWatchDurationTracking();
  1152. }
  1153. // this.userinfo = JSON.parse(uni.getStorageSync('userInfo'));
  1154. this.userinfo = uni.getStorageSync('userinfo');
  1155. this.isAgreement = uni.getStorageSync('isAgreement');
  1156. this.$nextTick(() => {
  1157. this.setVideoProgress();
  1158. });
  1159. if (this.lookTimer) {
  1160. clearInterval(this.lookTimer);
  1161. this.lookTimer = null;
  1162. this.stayTime = 0;
  1163. this.startTime = 0;
  1164. }
  1165. // 启动内存监控,定期清理
  1166. this.startMemoryMonitor();
  1167. if (this.trafficTimer) {
  1168. clearInterval(this.trafficTimer);
  1169. this.trafficTimer = null;
  1170. this.startTime = 0;
  1171. this.totalTraffic = 0;
  1172. }
  1173. // 重置视频加载状态和流量计算开始时间
  1174. this.videoLoaded = false;
  1175. this.trafficStartTime = 0;
  1176. // 清除等待定时器
  1177. if (this.waitingTimer) {
  1178. clearTimeout(this.waitingTimer);
  1179. this.waitingTimer = null;
  1180. }
  1181. this.waitingStartTime = 0;
  1182. this.lastVideoUpdateTime = 0;
  1183. this.startTimer();
  1184. this.$nextTick(() => {
  1185. console.log(444, this.userInfo);
  1186. if (!this.userInfo || !this.userInfo.nickname) {
  1187. console.log('用户信息不完整,显示授权弹窗');
  1188. this.userlogo = true;
  1189. return;
  1190. }
  1191. // // 重新计算 isNow
  1192. // const isNowCalculated = dayjs(this.userInfo.updateTime).isSame(dayjs(), 'day');
  1193. // console.log('重新计算 isNow:', isNowCalculated);
  1194. // if (!isNowCalculated) {
  1195. // console.log('不是今天更新过,显示授权弹窗');
  1196. // this.userlogo = true;
  1197. // }
  1198. setTimeout(() => {
  1199. this.videoContext = uni.createVideoContext(`myVideo_${this.liveId}`,
  1200. this);
  1201. console.log('videoContext 初始化完成:', this.videoContext);
  1202. }, 1000);
  1203. });
  1204. },
  1205. //分享给好友
  1206. onShareAppMessage() {
  1207. return {
  1208. title: '邀请你来观看直播:' + this.liveItem.liveName,
  1209. path: '/pages_course/living?companyId=-2&companyUserId=' + this.userInfo.userId +
  1210. '&liveId=' + this.liveId,
  1211. imageUrl: '/static/logo.png',
  1212. success(res) {
  1213. console.log('分享成功', res);
  1214. },
  1215. fail(err) {
  1216. console.error('分享失败', err);
  1217. }
  1218. };
  1219. },
  1220. // 分享到朋友圈
  1221. onShareTimeline() {
  1222. return {
  1223. title: '邀请你来观看直播:' + this.liveItem.liveName,
  1224. query: 'companyId=-2&companyUserId=' + this.userInfo.userId + '&liveId=' + this.liveId
  1225. };
  1226. },
  1227. computed: {
  1228. shouldShowIntegralPopup() {
  1229. //只有当 showPoints 为 true 且 receiveList 有数据时才显示
  1230. return this.showPoints;
  1231. },
  1232. // 格式化后的倒计时
  1233. formattedCountdown() {
  1234. return this.formatCountdown(this.pointsRemainingTime);
  1235. },
  1236. // 倒计时百分比
  1237. countdownPercentage() {
  1238. return this.getCountdownPercentage();
  1239. },
  1240. // 环形进度条样式
  1241. circularStyle() {
  1242. const percentage = this.getCountdownPercentage();
  1243. const strokeDashoffset = 314 - (314 * percentage) / 100; // 2 * π * 50 = 314
  1244. return {
  1245. '--percentage': percentage + '%',
  1246. '--stroke-dashoffset': strokeDashoffset
  1247. };
  1248. },
  1249. // 是否显示倒计时
  1250. // showCountdown() {
  1251. // return !this.hasReachedTarget &&
  1252. // this.liveItem?.liveType === 2 && // 只对录播显示
  1253. // this.pointsRemainingTime > 0 && // 还有剩余时间
  1254. // this.pointsRemainingTime < this.liveItem.duration * this.completionRate; // 已经开始计时
  1255. // },
  1256. // 控制是否显示非视频元素
  1257. shouldShowNonVideoElements() {
  1258. return !this.isFullscreen && this.showNonVideoElementsFlag;
  1259. },
  1260. // 控制是否显示全屏按钮
  1261. shouldShowFullscreenButton() {
  1262. return this.liveItem.showType == 1 && !this.isFullscreen;
  1263. },
  1264. ...mapGetters(['coureLogin']),
  1265. appid() {
  1266. return this.$store.state.appid
  1267. },
  1268. // 观看人数
  1269. formattedWatchCount() {
  1270. return this.formatNumber(this.virtualHuman || 0);
  1271. },
  1272. //点赞人数
  1273. formattedLikeCount() {
  1274. return this.formatNumber(this.liveViewData.like || 0);
  1275. },
  1276. filteredViewers() {
  1277. // 获取3个随机假头像,而不是显示真实观众
  1278. const avatarCount = 3; // 需要显示的假头像数量
  1279. // 如果fakeAvatar数组为空或不存在,返回空数组
  1280. if (!this.fakeAvatar || !Array.isArray(this.fakeAvatar) || this.fakeAvatar.length === 0) {
  1281. return [];
  1282. }
  1283. // 从fakeAvatar中随机选择3个不同的头像
  1284. const randomAvatars = [];
  1285. const availableAvatars = [...this.fakeAvatar]; // 创建副本避免修改原数组
  1286. // 确保有足够的头像可选
  1287. if (availableAvatars.length < avatarCount) {
  1288. // 如果头像数量不足,可以重复使用
  1289. for (let i = 0; i < avatarCount; i++) {
  1290. const randomIndex = Math.floor(Math.random() * availableAvatars.length);
  1291. randomAvatars.push(availableAvatars[randomIndex]);
  1292. }
  1293. } else {
  1294. // 随机选择不重复的头像
  1295. for (let i = 0; i < avatarCount; i++) {
  1296. const randomIndex = Math.floor(Math.random() * availableAvatars.length);
  1297. randomAvatars.push(availableAvatars[randomIndex]);
  1298. availableAvatars.splice(randomIndex, 1); // 移除已选的头像,避免重复
  1299. }
  1300. }
  1301. console.log("随机选择的头像:", randomAvatars);
  1302. return randomAvatars;
  1303. },
  1304. isCurrentUserWon() {
  1305. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1306. return false;
  1307. }
  1308. return this.prizeInfo.some((item) => {
  1309. return String(item.userId) === String(this.userInfo.userId);
  1310. });
  1311. },
  1312. getCurrentUserPrizeProductId() {
  1313. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1314. return null;
  1315. }
  1316. // 在 prizeInfo 中查找当前用户的中奖记录
  1317. const userPrize = this.prizeInfo.find(item => {
  1318. return String(item.userId) == String(this.userInfo.userId);
  1319. });
  1320. // 返回商品ID,如果没有找到则返回null
  1321. return userPrize ? userPrize.productId : null;
  1322. },
  1323. getCurrentUserPrizeRecordId() {
  1324. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1325. console.log('条件不满足,返回null');
  1326. return null;
  1327. }
  1328. const userPrize = this.prizeInfo.find(item => {
  1329. const match = String(item.userId) == String(this.userInfo.userId);
  1330. return match;
  1331. });
  1332. return userPrize ? userPrize.recordId : null;
  1333. },
  1334. nameuser() {
  1335. return this.userInfo.nickname
  1336. },
  1337. },
  1338. onHide() {
  1339. this.updateWatchDuration(); //更新用户的看课时长
  1340. this.stopCountdown();
  1341. if (this.watchTimeTimer) {
  1342. clearInterval(this.watchTimeTimer);
  1343. this.watchTimeTimer = null;
  1344. }
  1345. this.saveWatchTime();
  1346. // 清除所有定时器
  1347. // this.clearAllTimersEnhanced();
  1348. // this.stopHeartBeat();
  1349. // 页面隐藏时,提交当前流量数据
  1350. if (this.videoLoaded && this.trafficStartTime && this.trafficTimer) {
  1351. const watchDuration = Math.floor((this.getServerTimeNow() - this.trafficStartTime) / 1000);
  1352. this.submitTraffic(watchDuration);
  1353. }
  1354. if (this.trafficTimer) {
  1355. clearInterval(this.trafficTimer);
  1356. this.trafficTimer = null;
  1357. }
  1358. // 清除直播间数据定时器(防止页面隐藏后继续请求)
  1359. if (this.liveViewDataTimer) {
  1360. clearInterval(this.liveViewDataTimer);
  1361. this.liveViewDataTimer = null;
  1362. }
  1363. // 暂停观看时长统计
  1364. this.pauseWatchDurationTracking();
  1365. // 页面隐藏时清理部分数据,减少内存占用
  1366. if (this.talklist && this.talklist.length > 20) {
  1367. // 只保留最新的20条消息
  1368. this.talklist = this.talklist.slice(-20);
  1369. }
  1370. // 触发垃圾回收
  1371. // this.triggerGarbageCollection();
  1372. },
  1373. onVideoStateChange(e) { //废弃
  1374. // 这里可以根据视频状态控制倒计时
  1375. if (e.detail.code === 2004) { // 视频开始播放
  1376. //this.startCountdown();
  1377. } else if (e.detail.code === 2006) { // 视频播放结束
  1378. this.stopCountdown();
  1379. }
  1380. },
  1381. onUnload() {
  1382. this.stopCountdown();
  1383. if (this.watchTimeTimer) {
  1384. clearInterval(this.watchTimeTimer);
  1385. this.watchTimeTimer = null;
  1386. }
  1387. this.saveWatchTime();
  1388. // 保存视频进度
  1389. this.saveVideoProgress();
  1390. // 停止观看时长统计
  1391. this.stopWatchDurationTracking();
  1392. // 用户退出时,再次请求一次10s流量接口
  1393. if (this.videoLoaded && this.trafficStartTime) {
  1394. const watchDuration = Math.floor((this.getServerTimeNow() - this.trafficStartTime) / 1000);
  1395. // 提交最后一次流量数据(至少10秒)
  1396. const finalDuration = Math.max(watchDuration, 10);
  1397. this.submitTraffic(finalDuration);
  1398. }
  1399. // 清理直播相关定时器
  1400. if (this.liveItem) {
  1401. this.pauseVideo();
  1402. // 清除直播间的时间定时器
  1403. if (this.liveItem.timeTimer) {
  1404. clearInterval(this.liveItem.timeTimer);
  1405. this.liveItem.timeTimer = null;
  1406. }
  1407. }
  1408. // 关闭WebSocket连接(会自动清理相关资源)
  1409. this.closeWebSocket(true);
  1410. // 清除 getliving 防抖定时器
  1411. if (this.getlivingTimer) {
  1412. clearTimeout(this.getlivingTimer);
  1413. this.getlivingTimer = null;
  1414. }
  1415. // 显式清除直播间数据定时器(防止页面卸载后继续请求)
  1416. if (this.liveViewDataTimer) {
  1417. clearInterval(this.liveViewDataTimer);
  1418. this.liveViewDataTimer = null;
  1419. }
  1420. // 清除所有定时器(使用增强清理)
  1421. this.clearAllTimersEnhanced();
  1422. // 暂停视频
  1423. const videoId = `myVideo_${this.liveId}`;
  1424. const videoContext = uni.createVideoContext(videoId, this);
  1425. if (videoContext) {
  1426. videoContext.pause();
  1427. }
  1428. // 移除网络状态监听
  1429. try {
  1430. uni.offNetworkStatusChange();
  1431. } catch (err) {
  1432. console.warn('移除网络状态监听失败:', err);
  1433. }
  1434. // 清理大数据和状态
  1435. this.clearBigData();
  1436. this.resetAllStates();
  1437. // 解锁屏幕方向
  1438. this.unlockOrientation();
  1439. // 强制退出全屏
  1440. this.isFullscreen = false;
  1441. this.showCustomControls = true;
  1442. },
  1443. mounted() {
  1444. // 初始化系统信息缓存,避免在键盘监听器中重复调用同步API
  1445. this.systemInfo = uni.getSystemInfoSync();
  1446. console.log('系统信息:', this.systemInfo.platform, this.systemInfo.model);
  1447. this.getCurrentActivities();
  1448. this.getliveOrder();
  1449. },
  1450. watch: {
  1451. coureLogin: {
  1452. immediate: true, // 页面一进入就检查一次
  1453. handler(val) {
  1454. if (val == 2 && this.isLogin) {
  1455. this.isLogin = false
  1456. this.goLogin();
  1457. }
  1458. }
  1459. },
  1460. // 监听liveItem.status的变化
  1461. 'liveItem.status': {
  1462. handler(newStatus, oldStatus) {
  1463. if (newStatus === undefined || oldStatus === undefined) return;
  1464. if (newStatus === oldStatus) return;
  1465. if (!this.liveId) {
  1466. console.warn('liveId不存在,无法触发getliving请求');
  1467. return;
  1468. }
  1469. // 状态变化时,调用getliving更新直播间数据
  1470. // 添加防抖,避免频繁请求
  1471. if (this.getlivingTimer) {
  1472. clearTimeout(this.getlivingTimer);
  1473. }
  1474. this.getlivingTimer = setTimeout(() => {
  1475. this.getliving(this.liveId);
  1476. }, 500); // 500ms 防抖
  1477. },
  1478. deep: true
  1479. },
  1480. // 监听orderUser.count的变化
  1481. 'orderUser.count': {
  1482. handler(newVal, oldVal) {
  1483. if (newVal !== this.prevOrderCount) {
  1484. this.prevOrderCount = newVal;
  1485. this.showPurchaseMessage();
  1486. }
  1487. },
  1488. immediate: true
  1489. },
  1490. 'isShowNotice': {
  1491. handler(newVal, oldVal) {
  1492. setTimeout(() => {
  1493. this.noticeHeightFun()
  1494. }, 800)
  1495. },
  1496. immediate: true
  1497. },
  1498. 'notice.msg': {
  1499. handler(newVal, oldVal) {
  1500. // 添加空值检查
  1501. const newLength = newVal ? newVal.length : 0;
  1502. const oldLength = oldVal ? oldVal.length : 0;
  1503. if (newLength !== oldLength) {
  1504. setTimeout(() => {
  1505. this.noticeHeightFun()
  1506. }, 800)
  1507. }
  1508. },
  1509. deep: true
  1510. },
  1511. },
  1512. methods: {
  1513. // 查询当前用户当前直播间领取积分的剩余时长
  1514. getRemainingTime() {
  1515. if (!this.liveId) return;
  1516. const data = {
  1517. liveId: this.liveId
  1518. }
  1519. remainingTime(data).then((res) => {
  1520. if (res.code == 200) {
  1521. //this.pointsRemainingTime = res.data.remainingTime;
  1522. this.hasReceived = res.data.hasReceived;
  1523. this.videoDuration = res.data.videoDuration;
  1524. this.watchDuration = res.data.watchDuration; //停留时长
  1525. //this.completionRate= res.data.completionRate*0.01;//完课比例
  1526. console.log("查询当前用户当前直播间领取积分的剩余时长", res)
  1527. }
  1528. }).catch((error) => {
  1529. });
  1530. },
  1531. // 更新用户的看课时长 (传入直播间id和看课时长)
  1532. updateWatchDuration() {
  1533. if (!this.liveId) return;
  1534. if (this.isPreview) return;
  1535. //const watchDuration = Math.floor((Date.now() - this.liveBeginWatchTime) / 1000)
  1536. const watchDuration = this.totalWatchTime - this.watchDuration;
  1537. updateWatchDuration(this.liveId, watchDuration).then((res) => {
  1538. if (res.code == 200) {
  1539. console.log("更新用户的看课时长", res);
  1540. this.receivePoints();
  1541. }
  1542. }).catch((error) => {
  1543. });
  1544. },
  1545. // 用户领取看课积分 (传入直播间id)
  1546. receivePoints(retryCount = 0) {
  1547. if (!this.liveId) return;
  1548. const data = {
  1549. liveId: this.liveId
  1550. }
  1551. receivePoints(data).then((res) => {
  1552. if (res.code == 200) {
  1553. console.log("用户领取看课积分", res);
  1554. //清除重试定时器
  1555. if (this.pointsRetryTimer) {
  1556. clearTimeout(this.pointsRetryTimer);
  1557. this.pointsRetryTimer = null;
  1558. }
  1559. }
  1560. }).catch((error) => {
  1561. console.log("用户领取积分失败error", error);
  1562. // 增加重试机制:最多重试3次
  1563. if (retryCount < 3) {
  1564. const delay = (retryCount + 1) * 2000; // 递增延迟: 2s, 4s, 6s
  1565. console.log(`领取积分失败,${delay}ms后进行第${retryCount + 1}次重试`);
  1566. if (this.pointsRetryTimer) {
  1567. clearTimeout(this.pointsRetryTimer);
  1568. }
  1569. this.pointsRetryTimer = setTimeout(() => {
  1570. this.receivePoints(retryCount + 1);
  1571. }, delay);
  1572. }
  1573. });
  1574. },
  1575. // ======================== 观看时长统计相关方法 ========================
  1576. /**
  1577. * 开始观看时长统计
  1578. * WebSocket连接成功后调用
  1579. */
  1580. startWatchDurationTracking() {
  1581. // 防止重复启动
  1582. if (this.watchStartTime > 0) {
  1583. console.log('观看时长统计已启动,跳过');
  1584. return;
  1585. }
  1586. this.watchStartTime = Date.now();
  1587. this.isPageVisible = true;
  1588. console.log('开始观看时长统计', new Date(this.watchStartTime).toLocaleString());
  1589. // 启动页面可见性监听
  1590. this.initPageVisibilityListener();
  1591. },
  1592. /**
  1593. * 获取当前累计观看时长(秒)
  1594. * @returns {number} 观看时长(秒)
  1595. */
  1596. getCurrentWatchDuration() {
  1597. if (this.watchStartTime === 0) {
  1598. return this.accumulatedWatchDuration;
  1599. }
  1600. // 如果页面可见,计算当前时段的时长
  1601. if (this.isPageVisible) {
  1602. const currentDuration = Math.floor((Date.now() - this.watchStartTime) / 1000);
  1603. return this.accumulatedWatchDuration + currentDuration;
  1604. }
  1605. // 页面不可见,返回累计时长
  1606. return this.accumulatedWatchDuration;
  1607. },
  1608. /**
  1609. * 暂停观看时长统计(页面隐藏/后台时)
  1610. */
  1611. pauseWatchDurationTracking() {
  1612. if (!this.isPageVisible || this.watchStartTime === 0) {
  1613. return;
  1614. }
  1615. // 累加本次观看的时长
  1616. const currentSessionDuration = Math.floor((Date.now() - this.watchStartTime) / 1000);
  1617. this.accumulatedWatchDuration += currentSessionDuration;
  1618. this.lastPauseTime = Date.now();
  1619. this.isPageVisible = false;
  1620. console.log(`暂停观看统计: 本次=${currentSessionDuration}秒, 累计=${this.accumulatedWatchDuration}秒`);
  1621. },
  1622. /**
  1623. * 恢复观看时长统计(页面显示/前台时)
  1624. */
  1625. resumeWatchDurationTracking() {
  1626. if (this.isPageVisible) {
  1627. return;
  1628. }
  1629. // 重新记录开始时间
  1630. this.watchStartTime = Date.now();
  1631. this.isPageVisible = true;
  1632. const pauseDuration = this.lastPauseTime > 0 ? Math.floor((Date.now() - this.lastPauseTime) /
  1633. 1000) : 0;
  1634. console.log(`恢夏观看统计: 暂停了${pauseDuration}秒, 当前累计=${this.accumulatedWatchDuration}秒`);
  1635. },
  1636. /**
  1637. * 停止观看时长统计
  1638. */
  1639. stopWatchDurationTracking() {
  1640. if (this.isPageVisible && this.watchStartTime > 0) {
  1641. const currentSessionDuration = Math.floor((Date.now() - this.watchStartTime) / 1000);
  1642. this.accumulatedWatchDuration += currentSessionDuration;
  1643. }
  1644. console.log(`停止观看统计: 总时长=${this.accumulatedWatchDuration}秒`);
  1645. // 重置状态
  1646. this.watchStartTime = 0;
  1647. this.isPageVisible = true;
  1648. this.lastPauseTime = 0;
  1649. // 移除监听
  1650. this.removePageVisibilityListener();
  1651. },
  1652. /**
  1653. * 初始化页面可见性监听
  1654. */
  1655. initPageVisibilityListener() {
  1656. // uni-app 的页面生命周期已经在 onShow/onHide 中处理
  1657. // 这里主要监听小程序的前后台切换
  1658. uni.onAppShow(() => {
  1659. console.log('小程序回到前台');
  1660. this.resumeWatchDurationTracking();
  1661. });
  1662. uni.onAppHide(() => {
  1663. console.log('小程序切换到后台');
  1664. this.pauseWatchDurationTracking();
  1665. });
  1666. },
  1667. /**
  1668. * 移除页面可见性监听
  1669. */
  1670. removePageVisibilityListener() {
  1671. // uni-app 不需要手动移除监听,生命周期自动管理
  1672. console.log('页面可见性监听已移除');
  1673. },
  1674. /**
  1675. * 获取当前服务器时间戳(毫秒)
  1676. * 如果存在 serviceTime,则基于服务器时间计算;否则使用本地时间
  1677. * serviceTime 格式:1768816544512(13位毫秒级时间戳)
  1678. */
  1679. getServerTimeNow() {
  1680. if (!this.liveItem || !this.liveItem.serviceTime) {
  1681. return Date.now();
  1682. }
  1683. //return this.liveItem.serviceTime;
  1684. const localTimeWhenReceived = this.liveItem._localTimeWhenReceived;
  1685. if (!localTimeWhenReceived) {
  1686. // 如果没有记录接收时间,使用本地时间
  1687. return Date.now();
  1688. }
  1689. let serverTimeWhenReceived;
  1690. const serviceTime = this.liveItem.serviceTime;
  1691. //如果 serviceTime 是数字类型(毫秒级时间戳,如:1768816544512)
  1692. if (typeof serviceTime === 'number') {
  1693. serverTimeWhenReceived = serviceTime;
  1694. }
  1695. //如果 serviceTime 是字符串格式的数字时间戳
  1696. else if (typeof serviceTime === 'string' && /^\d+$/.test(serviceTime)) {
  1697. // 纯数字字符串,转换为数字
  1698. const numTime = Number(serviceTime);
  1699. // 判断是秒级还是毫秒级时间戳(13位及以上为毫秒级)
  1700. serverTimeWhenReceived = numTime < 1000000000000 ? numTime * 1000 : numTime;
  1701. }
  1702. //如果 serviceTime 是时间字符串(如:2025-01-01 12:00:00)
  1703. else {
  1704. const safeTimeStr = String(serviceTime).replace(/-/g, '/');
  1705. serverTimeWhenReceived = Date.parse(safeTimeStr);
  1706. if (isNaN(serverTimeWhenReceived)) {
  1707. return Date.now();
  1708. }
  1709. }
  1710. //计算服务器时间与本地时间的差值(毫秒)
  1711. const timeDiff = serverTimeWhenReceived - localTimeWhenReceived;
  1712. // 当前服务器时间 = 当前本地时间 + 时间差
  1713. return Date.now() + timeDiff;
  1714. },
  1715. /**
  1716. * 获取直播开始时间,优先使用 serviceStartTime,如果不存在则使用 startTime
  1717. */
  1718. getLiveStartTime() {
  1719. if (!this.liveItem) {
  1720. return null;
  1721. }
  1722. // 优先使用 serviceStartTime(服务器返回的直播开始时间)
  1723. if (this.liveItem.serviceStartTime) {
  1724. return this.liveItem.serviceStartTime;
  1725. }
  1726. // 如果不存在,回退到 startTime
  1727. return this.liveItem.startTime || null;
  1728. },
  1729. /**
  1730. * 计算当前时间与目标时间的差值(秒)
  1731. */
  1732. calculateLiveTimeDiff(timeStr, useServerTime = false) {
  1733. // 0. 安全校验:防止 undefined/null 导致 crash
  1734. if (!timeStr) {
  1735. return 0;
  1736. }
  1737. // 1. 获取当前时间戳(毫秒)- 倒计时场景使用服务器时间
  1738. const now = this.getServerTimeNow();
  1739. // 3. 【关键】解决 iOS 兼容性问题
  1740. // iOS 系统不支持 "2025-12-25" 这种带横杠的格式,需要替换为斜杠 "2025/12/25"
  1741. // const safeTimeStr = new Date(timeStr.replace(/-/g, '/'));
  1742. // // 4. 解析目标时间戳(毫秒)
  1743. // const liveStartTime = Date.parse(safeTimeStr);
  1744. // 5. 计算差值(毫秒 -> 秒)
  1745. // 结果为:当前时间 - 直播开始时间
  1746. const diffInSeconds = Math.floor((now - timeStr) / 1000);
  1747. //console.log("结果为:当前时间 - 直播开始时间,",diffInSeconds,now,timeStr)
  1748. return diffInSeconds;
  1749. },
  1750. // 根据开始时间和时长计算结束时间
  1751. calculateLiveEndTime(startDate, duration) {
  1752. if (!startDate) return '';
  1753. // 计算结束时间戳
  1754. const endTimeMs = startDate + (Number(duration) * 1000);
  1755. const endDate = new Date(endTimeMs);
  1756. // 格式化
  1757. const year = endDate.getFullYear();
  1758. const month = this.padZero(endDate.getMonth() + 1);
  1759. const day = this.padZero(endDate.getDate());
  1760. const hours = this.padZero(endDate.getHours());
  1761. const minutes = this.padZero(endDate.getMinutes());
  1762. const seconds = this.padZero(endDate.getSeconds());
  1763. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  1764. },
  1765. // 开始倒计时
  1766. startCountdown() {
  1767. ///console.log("this.completionPointsEnabled",this.liveItem)
  1768. if (!this.liveItem.completionPointsEnabled) {
  1769. return;
  1770. }
  1771. // 如果倒计时已经在运行,先清除旧的定时器
  1772. if (this.countdownTimer) {
  1773. clearInterval(this.countdownTimer);
  1774. this.countdownTimer = null;
  1775. }
  1776. // 使用服务器时间重新计算初始状态,确保设备时间不一致时也能正确判断
  1777. const liveStartTime = this.getLiveStartTime();
  1778. if (liveStartTime) {
  1779. this.diffLiveStartTime = this.calculateLiveTimeDiff(liveStartTime, true);
  1780. // 如果直播已开始,确保 isPreview 为 false
  1781. if (this.diffLiveStartTime >= 0 ) {
  1782. this.isPreview = false;
  1783. }
  1784. }
  1785. this.isCountdownActive = true;
  1786. // 立即执行一次更新,确保倒计时显示正确
  1787. this.updateCountdown();
  1788. this.countdownTimer = setInterval(() => {
  1789. this.updateCountdown();
  1790. }, 1000); // 每秒更新一次
  1791. //console.log("this.completionPointsEnabled+++++++",this.liveItem.completionPointsEnabled,this.countdownPercentage,this.receiveStatus,this.hasReceived,this.isPreview)
  1792. },
  1793. // 更新倒计时
  1794. updateCountdown() {
  1795. if (!this.liveItem) {
  1796. return;
  1797. }
  1798. //console.log("this.completionPointsEnabled",this.completionTime)
  1799. this.completionTime = this.liveItem.duration * this.completionRate;
  1800. //console.log("qxj watchDuration:"+this.watchDuration+" completionTime:"+this.completionTime+" pointsRemainingTime:"+this.pointsRemainingTime);
  1801. //console.log(`qxj countdownPercentage=${this.countdownPercentage} completionPointsEnabled=${this.liveItem.completionPointsEnabled} receiveStatus=${this.receiveStatus} liveItemStatus=${this.liveItem.status} hasReceived=${this.hasReceived} isPreview=${this.isPreview}`);
  1802. if (this.watchDuration > this.completionTime) { //已达成观看时间
  1803. if (this.countdownTimer) {
  1804. clearInterval(this.countdownTimer);
  1805. this.countdownTimer = null;
  1806. this.isPreview = true;
  1807. return;
  1808. }
  1809. }
  1810. if (this.pointsRemainingTime < 0) {
  1811. this.stopCountdown();
  1812. return;
  1813. }
  1814. this.showPoints = false;
  1815. // 使用服务器时间计算差值
  1816. const serverTimeNow = this.getServerTimeNow();
  1817. const liveStartTime = this.getLiveStartTime();
  1818. this.diffLiveStartTime = this.calculateLiveTimeDiff(liveStartTime, true);
  1819. this.diffLiveEndTime = this.calculateLiveTimeDiff(liveStartTime, true) - this.liveItem.duration;
  1820. if (!this.liveItem.finishTime) {
  1821. this.liveItem.finishTime = this.calculateLiveEndTime(liveStartTime, this.liveItem.duration); //得出首播结束时间
  1822. }
  1823. if (this.diffLiveStartTime < 0) { //预告状态
  1824. this.isPreview = true;
  1825. //console.log('updateCountdown - 服务器时间显示直播还未开始,设置为预告状态');
  1826. return;
  1827. } else {
  1828. // 直播已开始(基于服务器时间),确保 isPreview 为 false
  1829. this.isPreview = false;
  1830. //console.log('updateCountdown - 直播已开始,设置 isPreview = false');
  1831. }
  1832. if (this.diffLiveStartTime >= 0) {
  1833. if (this.diffLiveEndTime >= 0) { //回放文件生成中
  1834. if (this.diffLiveEndTime <= 180) {
  1835. this.isPreview = false;
  1836. this.pointsRemainingTime = Math.max(0, this.completionTime - this.totalWatchTime);
  1837. this.diffReplayGenerationSeconds++; //经历回放生成的秒数
  1838. this.hasReplayGeneration = true;
  1839. return;
  1840. } else {
  1841. if (this.hasReplayGeneration) { //经历过回放生成 回放生成后扣减掉经历回放生成的时间
  1842. this.totalWatchTime = this.watchDuration + Math.floor((serverTimeNow - this
  1843. .liveBeginWatchTime) / 1000) - this.diffReplayGenerationSeconds; //累计观看的总时长
  1844. } else { //进入直播间时已过回放生成中
  1845. this.totalWatchTime = this.watchDuration + Math.floor((serverTimeNow - this
  1846. .liveBeginWatchTime) / 1000); //累计观看的总时长
  1847. }
  1848. }
  1849. } else {
  1850. this.totalWatchTime = this.watchDuration + Math.floor((serverTimeNow - this.liveBeginWatchTime) /
  1851. 1000); //累计观看的总时长
  1852. }
  1853. }
  1854. //console.log("qxj直播中 completionTime:"+this.completionTime+" totalWatchTime:"+this.totalWatchTime+" pointsRemainingTime:"+this.pointsRemainingTime+" watchDuration:"+this.watchDuration+", liveBeginWatchTime:"+this.liveBeginWatchTime);
  1855. if (this.totalWatchTime >= this.completionTime) { //积分领取满足条件
  1856. if (this.countdownTimer) {
  1857. clearInterval(this.countdownTimer);
  1858. this.countdownTimer = null;
  1859. this.onCountdownComplete();
  1860. return;
  1861. }
  1862. }
  1863. if (this.diffLiveStartTime >= 0) {
  1864. this.isPreview = false;
  1865. if (this.diffLiveEndTime < 0) { //直播中状态
  1866. this.pointsRemainingTime = Math.max(0, this.completionTime - this.totalWatchTime);
  1867. }
  1868. if (this.diffLiveEndTime > 180) { //直播回放中
  1869. this.pointsRemainingTime = Math.max(0, this.completionTime - this.totalWatchTime);
  1870. }
  1871. }
  1872. // 更新显示
  1873. this.updateCountdownDisplay();
  1874. },
  1875. // 停止倒计时
  1876. stopCountdown() {
  1877. if (this.countdownTimer) {
  1878. clearInterval(this.countdownTimer);
  1879. this.countdownTimer = null;
  1880. }
  1881. this.isCountdownActive = false;
  1882. this.updateWatchDuration();
  1883. //this.saveWatchProgress(); // 立即保存
  1884. },
  1885. // 倒计时完成
  1886. onCountdownComplete() {
  1887. console.log('倒计时完成!');
  1888. this.stopCountdown();
  1889. this.pointsRemainingTime = -1;
  1890. //this.updateCountdownDisplay();
  1891. this.triggerWatchComplete();
  1892. setTimeout(() => {
  1893. // 5秒后自动隐藏
  1894. this.showToast = true;
  1895. setTimeout(() => {
  1896. this.showToast = false;
  1897. }, 5000); // 5000ms = 5秒
  1898. }, 1000);
  1899. // setTimeout(()=>{
  1900. // uni.showToast({title:"完课积分已到账",duration:150000,icon:"none"});
  1901. // },1000);
  1902. // setTimeout(()=>{
  1903. // this.showPoints=true;
  1904. // },5000)
  1905. },
  1906. // 触发观看完成事件
  1907. async triggerWatchComplete() {
  1908. if (!this.userInfo?.userId || !this.liveId) return;
  1909. try {
  1910. // 这里可以调用API通知服务器用户已完成观看
  1911. console.log('用户已完成观看');
  1912. // 清空进度,防止重复计算
  1913. uni.removeStorageSync(this.watchProgressKey);
  1914. } catch (error) {
  1915. console.error('触发观看完成事件失败:', error);
  1916. }
  1917. },
  1918. // 补零函数
  1919. padZero(num) {
  1920. return num < 10 ? `0${num}` : num.toString();
  1921. },
  1922. // 倒计时格式化函数
  1923. formatCountdown(seconds) {
  1924. // 1. 先校验输入:确保是有效正整数,避免负数/非数字导致计算错误
  1925. const totalSeconds = Math.max(0, Math.floor(Number(seconds) || 0));
  1926. // 2. 重新梳理计算逻辑(核心修复)
  1927. const hours = Math.floor(totalSeconds / 3600);
  1928. const remainingAfterHours = totalSeconds % 3600; // 小时取余后剩余的秒数
  1929. const minutes = Math.floor(remainingAfterHours / 60);
  1930. const secs = remainingAfterHours % 60;
  1931. // 3. 返回格式化结果(补零+原始值)
  1932. return {
  1933. hours: this.padZero(hours),
  1934. minutes: this.padZero(minutes),
  1935. seconds: this.padZero(secs),
  1936. total: totalSeconds // 确保total是处理后的有效数值
  1937. };
  1938. },
  1939. getCountdownPercentage() {
  1940. // 1. 使用倒计时的 remainingTime 计算进度
  1941. if (!this.getRemainingTime) {
  1942. console.log('进度条计算:liveItem.duration无效', this.liveItem?.duration);
  1943. return 0;
  1944. }
  1945. // 2. 如果还在预告状态或直播未开始,返回0%
  1946. const liveStartTime = this.getLiveStartTime();
  1947. if (this.isPreview || !this.liveItem || !liveStartTime) {
  1948. return 0;
  1949. }
  1950. // 3. 使用服务器时间判断直播是否已开始(以服务器时间为准)
  1951. const diffLiveStartTime = this.calculateLiveTimeDiff(liveStartTime, true);
  1952. if (diffLiveStartTime < 0) {
  1953. // 服务器时间显示直播还未开始,无论status是什么,都返回0%
  1954. // 这样可以避免设备时间小于服务器时间时,pointsRemainingTime为0导致返回100%的问题
  1955. return 0;
  1956. }
  1957. // 4. 如果 videoDuration 未初始化,返回0%
  1958. if (!this.videoDuration || this.videoDuration <= 0) {
  1959. return 0;
  1960. }
  1961. // 5. 如果已经达到目标(pointsRemainingTime <= 0),直接返回100%
  1962. if (this.pointsRemainingTime <= 0) {
  1963. return 100;
  1964. }
  1965. //console.log('进度条计算:this.pointsRemainingTime', this.pointsRemainingTime, 'videoDuration:', this.videoDuration);
  1966. // 6. remainingTime = 剩余需要观看的时间
  1967. // 已观看时间 = 总目标时间 - 剩余时间
  1968. const watchedTime = this.videoDuration - this.pointsRemainingTime;
  1969. // 7. 确保数值有效
  1970. if (watchedTime <= 0) {
  1971. return 0;
  1972. }
  1973. // 8. 计算百分比(已观看时间 / 目标时间)
  1974. const percentage = (watchedTime / this.videoDuration) * 100;
  1975. // 9. 限制在 0-100 范围内
  1976. return Math.min(100, Math.max(0, percentage));
  1977. },
  1978. // 更新倒计时显示(如果需要强制更新视图)
  1979. updateCountdownDisplay() {
  1980. // 如果需要,可以在这里触发视图更新
  1981. this.$forceUpdate();
  1982. },
  1983. // 初始化观看时间
  1984. initWatchTime() {
  1985. // 创建基于用户ID和直播ID的存储键
  1986. const userId = this.userInfo?.userId || 'anonymous';
  1987. this.watchTimeStorageKey = `watchTime_${userId}_${this.liveId}`;
  1988. // 从本地存储加载累计观看时间
  1989. try {
  1990. const storedTime = uni.getStorageSync(this.watchTimeStorageKey);
  1991. this.totalWatchTime = storedTime ? parseInt(storedTime) : 0;
  1992. console.log(`加载累计观看时间: ${this.totalWatchTime}秒`);
  1993. } catch (error) {
  1994. console.error('加载观看时间失败:', error);
  1995. this.totalWatchTime = 0;
  1996. }
  1997. },
  1998. //保存观看时间到本地存储
  1999. saveWatchTime() {
  2000. if (!this.watchTimeStorageKey) return;
  2001. try {
  2002. uni.setStorageSync(this.watchTimeStorageKey, this.totalWatchTime);
  2003. console.log(`保存观看时间: ${this.totalWatchTime}秒`);
  2004. } catch (error) {
  2005. console.error('保存观看时间失败:', error);
  2006. }
  2007. },
  2008. // 格式化显示时间
  2009. formatWatchTime(seconds) {
  2010. const hours = Math.floor(seconds / 3600);
  2011. const minutes = Math.floor((seconds % 3600) / 60);
  2012. const secs = seconds % 60;
  2013. return {
  2014. hours: this.padZero(hours),
  2015. minutes: this.padZero(minutes),
  2016. seconds: this.padZero(secs),
  2017. total: seconds
  2018. };
  2019. },
  2020. // // 获取用户未领取的积分列表
  2021. // completionUnreceived() {
  2022. // if (!this.liveId) return;
  2023. // const data = {
  2024. // liveId: this.liveId
  2025. // }
  2026. // completionUnreceived(data).then((res) => {
  2027. // if (res.code == 200) {
  2028. // console.log("获取用户未领取的积分列表", res)
  2029. // if (res.data) {
  2030. // this.receiveList = res.data
  2031. // this.showPoints = true
  2032. // }
  2033. // }
  2034. // }).catch((error) => {});
  2035. // },
  2036. // 领取完课积分
  2037. // completionReceive(item) {
  2038. // if (!item.id) return;
  2039. // completionReceive(item.id).then((res) => {
  2040. // if (res.code == 200) {
  2041. // this.showPoints = false
  2042. // console.log("领取完课积分", res)
  2043. // uni.showToast({
  2044. // title: '领取积分成功',
  2045. // icon: 'none'
  2046. // });
  2047. // }
  2048. // }).catch((error) => {});
  2049. // },
  2050. noticeHeightFun() {
  2051. const query = uni.createSelectorQuery().in(this);
  2052. query.select('.notice-message').boundingClientRect(rect => {
  2053. if (rect) {
  2054. this.commonViewHeight = rect.height;
  2055. this.forceScrollToBottomOnSend();
  2056. } else {
  2057. this.commonViewHeight = ''
  2058. }
  2059. }).exec();
  2060. },
  2061. // 获取胶囊按钮布局参数
  2062. getMenuButtonInfo() {
  2063. // 微信小程序API(Uniapp可直接用uni.getMenuButtonBoundingClientRect)
  2064. const menuBtn = uni.getMenuButtonBoundingClientRect();
  2065. if (menuBtn) {
  2066. this.menuButtonInfo = {
  2067. top: menuBtn.top + 'px', // 胶囊顶部距离
  2068. height: menuBtn.height + 'px', // 胶囊高度
  2069. centerY: (menuBtn.top + menuBtn.height / 2) + 'px', // 胶囊垂直居中Y坐标
  2070. right: menuBtn.right + 'px' // 胶囊右侧距离
  2071. };
  2072. }
  2073. },
  2074. // 退出全屏
  2075. exitFullscreen() {
  2076. console.log('执行退出全屏');
  2077. this.isFullscreen = false;
  2078. // 恢复竖屏样式
  2079. this.restoreVideoList();
  2080. // 显示非videolist元素
  2081. this.showNonVideoElements();
  2082. // 强制页面重排
  2083. this.$forceUpdate();
  2084. },
  2085. // 添加屏幕方向变化监听
  2086. addOrientationChangeListener() {
  2087. if (window.addEventListener) {
  2088. window.addEventListener('orientationchange', this.handleOrientationChange);
  2089. }
  2090. },
  2091. // 移除屏幕方向变化监听
  2092. removeOrientationChangeListener() {
  2093. if (window.removeEventListener) {
  2094. window.removeEventListener('orientationchange', this.handleOrientationChange);
  2095. }
  2096. }, // 处理屏幕方向变化
  2097. handleOrientationChange() {
  2098. uni.onWindowResize((res) => {
  2099. const windowWidth = res.size.windowWidth;
  2100. const windowHeight = res.size.windowHeight;
  2101. const isLandscape = windowWidth > windowHeight;
  2102. if (this.isFullscreen && !isLandscape) {
  2103. console.log('全屏状态下屏幕方向不正确,尝试退出全屏');
  2104. if (this.videoContext) {
  2105. this.videoContext.exitFullScreen();
  2106. }
  2107. }
  2108. });
  2109. }, // 恢复videolist盒子
  2110. restoreVideoList() {
  2111. this.isVideoRotated = false;
  2112. this.isFullscreen = false;
  2113. console.log('恢复视频容器竖屏状态');
  2114. },
  2115. // 强制横屏全屏(备用方案)
  2116. forceLandscapeFullscreen() {
  2117. // 尝试多种全屏方式
  2118. try {
  2119. // 方案1: 使用video的requestFullScreen
  2120. if (this.videoContext) {
  2121. this.videoContext.requestFullScreen({
  2122. direction: 90
  2123. });
  2124. return true;
  2125. }
  2126. } catch (e) {
  2127. console.log('方案1失败:', e);
  2128. }
  2129. try {
  2130. // 方案2: 尝试DOM全屏API
  2131. const videoElement = document.getElementById(`myVideo_${this.liveId}`);
  2132. if (videoElement && videoElement.requestFullscreen) {
  2133. videoElement.requestFullscreen();
  2134. return true;
  2135. }
  2136. } catch (e) {
  2137. console.log('方案2失败:', e);
  2138. }
  2139. try {
  2140. // 方案3: 使用Web API全屏
  2141. if (document.documentElement.requestFullscreen) {
  2142. document.documentElement.requestFullscreen();
  2143. return true;
  2144. }
  2145. } catch (e) {
  2146. console.log('方案3失败:', e);
  2147. }
  2148. console.log('所有全屏方案都失败了');
  2149. uni.showToast({
  2150. title: '无法全屏播放,请尝试手动横屏',
  2151. icon: 'none'
  2152. });
  2153. return false;
  2154. },
  2155. // 切换全屏
  2156. toggleFullscreen() {
  2157. console.log('自定义全屏按钮被点击');
  2158. if (this.isFullscreen) {
  2159. // 退出全屏
  2160. this.exitFullscreen();
  2161. } else {
  2162. // 进入全屏
  2163. this.enterFullscreen();
  2164. }
  2165. }, // 进入全屏
  2166. enterFullscreen() {
  2167. console.log('执行进入全屏');
  2168. this.isFullscreen = true;
  2169. // 设置横屏样式
  2170. this.rotateVideoList();
  2171. // 隐藏非videolist元素
  2172. this.hideNonVideoElements();
  2173. // 强制页面重排
  2174. this.$forceUpdate();
  2175. },
  2176. // 强制全屏的备用方案
  2177. forceFullscreen() {
  2178. console.log('使用备用方案进入全屏');
  2179. const videoId = `myVideo_${this.liveId}`;
  2180. // 在小程序中,只能使用 videoContext
  2181. if (this.videoContext) {
  2182. try {
  2183. this.videoContext.requestFullScreen({
  2184. direction: 90 // 横屏方向
  2185. });
  2186. } catch (error) {
  2187. console.error('请求全屏失败:', error);
  2188. uni.showToast({
  2189. title: '无法全屏播放,请尝试手动横屏',
  2190. icon: 'none'
  2191. });
  2192. }
  2193. }
  2194. }, // 隐藏非videolist元素
  2195. hideNonVideoElements() {
  2196. this.showNonVideoElementsFlag = false;
  2197. console.log('隐藏非视频元素');
  2198. },
  2199. // 显示非videolist元素
  2200. showNonVideoElements() {
  2201. this.showNonVideoElementsFlag = true;
  2202. console.log('显示非视频元素');
  2203. },
  2204. // 旋转videolist盒子
  2205. rotateVideoList() {
  2206. // 在小程序中,通过设置CSS类名来控制样式,而不是直接操作DOM
  2207. this.isVideoRotated = true;
  2208. this.isFullscreen = true;
  2209. console.log('视频容器旋转到横屏状态');
  2210. },
  2211. // 全屏状态变化监听
  2212. onFullscreenChange(e) {
  2213. console.log('全屏状态变化事件详情:', e);
  2214. // 方法1:通过事件参数获取(小程序主要方式)
  2215. let fullScreen = false;
  2216. // 视频组件的全屏事件参数
  2217. if (e.detail && typeof e.detail.fullScreen !== 'undefined') {
  2218. fullScreen = e.detail.fullScreen;
  2219. console.log('通过e.detail.fullScreen获取全屏状态:', fullScreen);
  2220. }
  2221. // 其他可能的参数名
  2222. else if (e.detail && typeof e.detail.fullscreen !== 'undefined') {
  2223. fullScreen = e.detail.fullscreen;
  2224. console.log('通过e.detail.fullscreen获取全屏状态:', fullScreen);
  2225. } else {
  2226. // 在小程序环境中,可以通过屏幕方向判断
  2227. try {
  2228. const systemInfo = uni.getSystemInfoSync();
  2229. fullScreen = systemInfo.windowWidth > systemInfo.windowHeight;
  2230. console.log('通过屏幕方向判断全屏状态:', fullScreen);
  2231. } catch (err) {
  2232. console.error('获取系统信息失败:', err);
  2233. // 默认使用事件参数
  2234. fullScreen = e.detail || false;
  2235. }
  2236. }
  2237. this.isFullscreen = fullScreen;
  2238. console.log('最终设置isFullscreen为:', this.isFullscreen);
  2239. // 根据全屏状态显示/隐藏自定义控件
  2240. this.showCustomControls = !this.isFullscreen;
  2241. // 强制UI更新
  2242. this.$forceUpdate();
  2243. // 全屏时锁定横屏
  2244. if (this.isFullscreen) {
  2245. this.lockOrientation();
  2246. } else {
  2247. this.unlockOrientation();
  2248. }
  2249. },
  2250. // 锁定屏幕方向为横屏
  2251. lockOrientation() {
  2252. // 设置屏幕方向为横屏
  2253. try {
  2254. // 尝试锁定横屏
  2255. plus.screen.lockOrientation('landscape-primary');
  2256. } catch (e) {
  2257. console.log('锁定屏幕方向失败:', e);
  2258. // 备用方案
  2259. try {
  2260. // 使用 Web API(如果支持)
  2261. if (screen.orientation && screen.orientation.lock) {
  2262. screen.orientation.lock('landscape');
  2263. }
  2264. } catch (err) {
  2265. console.log('备用方案也失败了:', err);
  2266. }
  2267. }
  2268. }, // 解锁屏幕方向
  2269. unlockOrientation() {
  2270. try {
  2271. if (screen.orientation && screen.orientation.unlock) {
  2272. screen.orientation.unlock();
  2273. }
  2274. } catch (err) {
  2275. console.log('备用解锁方案也失败了:', err);
  2276. }
  2277. },
  2278. shouquan() {
  2279. if (this.user.nickname == '') {
  2280. uni.showToast({
  2281. icon: 'none',
  2282. title: "请先授权微信昵称",
  2283. });
  2284. }
  2285. },
  2286. confimrname() {
  2287. if (this.user.nickname == '') {
  2288. uni.showToast({
  2289. icon: 'none',
  2290. title: "请授权微信昵称",
  2291. });
  2292. return
  2293. }
  2294. this.editUser();
  2295. uni.setStorageSync('userInfo', this.userInfo);
  2296. if (this.user.nickname) {
  2297. this.userlogo = false;
  2298. }
  2299. },
  2300. editUser() {
  2301. this.user.nickName = this.user.nickname;
  2302. editUser(this.user).then(
  2303. res => {
  2304. if (res.code == 200) {
  2305. uni.showToast({
  2306. icon: 'success',
  2307. title: "修改成功",
  2308. });
  2309. this.getUserInfo()
  2310. } else {
  2311. uni.showToast({
  2312. icon: 'none',
  2313. title: res.msg,
  2314. });
  2315. }
  2316. },
  2317. rej => {}
  2318. );
  2319. },
  2320. onNickNameInput(e) {
  2321. console.log(e)
  2322. this.user.nickname = e.detail.value
  2323. },
  2324. async haveLogin() {
  2325. // 防止重复执行
  2326. if (this.isOnload) {
  2327. return;
  2328. }
  2329. this.userInfo = uni.getStorageSync('userInfo');
  2330. if (this.userInfo) {
  2331. await this.getUserInfo();
  2332. }
  2333. if (this.liveId) {
  2334. // 优先加载直播间信息(包含视频资源URL)
  2335. this.isOnload = true;
  2336. await this.getliving(this.liveId);
  2337. // await this.getLiveMsg(this.liveItem);
  2338. // await this.getliveViewData();
  2339. // 然后加载其他数据(并行执行,不阻塞视频加载)
  2340. Promise.all([
  2341. this.getLiveMsg(this.liveItem),
  2342. //this.getliveViewData()
  2343. ]).catch(err => {
  2344. console.error('加载数据失败:', err);
  2345. });
  2346. // 其他非关键数据异步加载
  2347. this.getCurrentActivities();
  2348. this.getliveOrder();
  2349. this.initSocket();
  2350. }
  2351. },
  2352. // 静默登录
  2353. goLogin(data) {
  2354. let provider = 'weixin'
  2355. uni.login({
  2356. provider: provider,
  2357. success: async loginRes => {
  2358. uni.getUserInfo({
  2359. provider: provider,
  2360. success: (infoRes) => {
  2361. uni.showToast({
  2362. title: '登录中...',
  2363. icon: 'loading'
  2364. });
  2365. loginByMp({
  2366. code: loginRes.code,
  2367. encryptedData: infoRes.encryptedData,
  2368. iv: infoRes.iv,
  2369. appId: this.appid
  2370. }).then(res => {
  2371. uni.hideLoading();
  2372. if (res.code == 200) {
  2373. uni.setStorageSync('AppToken', res
  2374. .token);
  2375. uni.setStorageSync('userInfo', JSON
  2376. .stringify(res
  2377. .user));
  2378. this.userInfo = uni.getStorageSync(
  2379. 'userInfo');
  2380. // uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  2381. // this.user = res.user
  2382. this.$store.commit('setCoureLogin', 1);
  2383. this.isLogin = true
  2384. this.haveLogin()
  2385. this.userlogo = true
  2386. // console.log("TOKEN_KEYAuto",TOKEN_KEYAuto)
  2387. if (this.urlOption.qwUserId) {
  2388. this.getIsAddKf() //this.getIsAddKf()
  2389. }
  2390. } else {
  2391. uni.showToast({
  2392. title: res.msg,
  2393. icon: 'none'
  2394. });
  2395. }
  2396. }).catch(err => {
  2397. uni.hideLoading();
  2398. uni.showToast({
  2399. icon: 'none',
  2400. title: "登录失败,请重新登录",
  2401. });
  2402. });
  2403. }
  2404. });
  2405. }
  2406. })
  2407. },
  2408. // liveWatchUser(){
  2409. // var data={
  2410. // qwUserId:this.urlOption.qwUserId,
  2411. // liveId:this.urlOption.liveId,
  2412. // userId:this.userInfo.userId,
  2413. // corpId:this.urlOption.corpId,
  2414. // companyUserId:this.urlOption.companyUserId,
  2415. // qwExternalId:this.urlOption.qwExternalId,
  2416. // companyId:this.urlOption.companyId,
  2417. // chatId:this.urlOption.chatId,
  2418. // }
  2419. // liveWatchUser(data).then(
  2420. // res => {
  2421. // if (res.code == 200) {
  2422. // } else {
  2423. // uni.showToast({
  2424. // icon: 'none',
  2425. // title: res.msg,
  2426. // });
  2427. // }
  2428. // },
  2429. // rej => {}
  2430. // );
  2431. // },
  2432. // 客服
  2433. getIsAddKf() {
  2434. // {videoId: this.videoId,qwUserId: this.qwUserId,corpId: this.corpId}
  2435. getIsAddKf(this.urlOption).then(res => {
  2436. if (res.code == 200) {
  2437. this.isAddKf = 1
  2438. this.qwCode = true
  2439. //this.getH5CourseVideoDetails()
  2440. } else if (res.code == 401) {
  2441. this.isAddKf = 0
  2442. this.goLogin();
  2443. } else {
  2444. this.qwCode = false
  2445. uni.showToast({
  2446. title: res.msg,
  2447. icon: 'none'
  2448. });
  2449. }
  2450. },
  2451. err => {}
  2452. );
  2453. },
  2454. clickTabs(item) {},
  2455. getLocationByIP() {
  2456. // 防止重复请求
  2457. if (this.hasLoadedLocation) {
  2458. return;
  2459. }
  2460. this.hasLoadedLocation = true;
  2461. // 高德IP定位API,需要替换成你的key
  2462. const key = '4e13632be0cc278f56825919603c07cf';
  2463. uni.request({
  2464. url: `https://restapi.amap.com/v3/ip?key=${key}`,
  2465. method: 'GET',
  2466. success: (res) => {
  2467. if (res.data && res.data.status === '1') {
  2468. // 返回数据格式:{ province: '广东省', city: '深圳市', ... }
  2469. // ${res.data.city}
  2470. this.location = `${res.data.province} `;
  2471. this.address = this.location
  2472. console.log('用户所在地:', this.location);
  2473. } else {
  2474. console.error('获取位置失败:', res.data);
  2475. this.hasLoadedLocation = false; // 失败后允许重试
  2476. }
  2477. },
  2478. fail: (err) => {
  2479. console.error('请求失败:', err);
  2480. this.hasLoadedLocation = false; // 失败后允许重试
  2481. }
  2482. });
  2483. },
  2484. formatNumber(num) {
  2485. if (typeof num !== 'number') {
  2486. num = Number(num) || 0;
  2487. }
  2488. if (num < 10000) {
  2489. return num.toString();
  2490. }
  2491. // 处理万以上的数字
  2492. const wan = num / 10000;
  2493. if (wan < 10) {
  2494. // 1万-10万之间,保留2位小数
  2495. const rounded = Math.round(wan * 100) / 100;
  2496. return rounded.toFixed(2).replace(/\.?0+$/, '') + 'w';
  2497. } else if (wan < 10000) {
  2498. // 10万-1亿之间,保留1位小数
  2499. const rounded = Math.round(wan * 10) / 10;
  2500. return rounded.toFixed(1).replace(/\.0$/, '') + 'w';
  2501. } else {
  2502. // 1亿以上,转换为亿单位
  2503. const yi = wan / 10000;
  2504. const rounded = Math.round(yi * 100) / 100;
  2505. return rounded.toFixed(2).replace(/\.?0+$/, '') + '亿';
  2506. }
  2507. },
  2508. // 重置所有状态
  2509. resetAllStates() {
  2510. this.liveUserCalled = false;
  2511. this.talklist = [];
  2512. this.liveViewersData = [];
  2513. this.liveViewers = [];
  2514. this.products = [];
  2515. this.liveItem = [];
  2516. // 重置WebSocket相关状态
  2517. this.isSocketOpen = false;
  2518. this.isConnecting = false;
  2519. this.isManualClose = true;
  2520. this.reconnectCount = 0;
  2521. this.heartBeatRetryCount = 0;
  2522. this.lastHeartBeatTime = 0;
  2523. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  2524. this.isNetworkAvailable = true;
  2525. this.networkType = 'unknown';
  2526. // 重置性能监控数据
  2527. this.connectionStartTime = 0;
  2528. this.connectionLatency = 0;
  2529. this.messageCount = 0;
  2530. this.errorCount = 0;
  2531. this.lastPerformanceCheck = 0;
  2532. },
  2533. // 获取WebSocket性能统计
  2534. getWebSocketPerformanceStats() {
  2535. const now = Date.now();
  2536. const uptime = this.connectionStartTime > 0 ? now - this.connectionStartTime : 0;
  2537. return {
  2538. connectionLatency: this.connectionLatency,
  2539. uptime: uptime,
  2540. messageCount: this.messageCount,
  2541. errorCount: this.errorCount,
  2542. errorRate: this.messageCount > 0 ? (this.errorCount / this.messageCount * 100).toFixed(2) : 0,
  2543. messagesPerSecond: uptime > 0 ? (this.messageCount / (uptime / 1000)).toFixed(2) : 0,
  2544. networkType: this.networkType,
  2545. isConnected: this.isSocketAvailable(),
  2546. reconnectCount: this.reconnectCount
  2547. };
  2548. },
  2549. // 定期检查性能并输出统计信息
  2550. performanceCheck() {
  2551. const now = Date.now();
  2552. // 每5分钟输出一次性能统计
  2553. if (now - this.lastPerformanceCheck > 300000) { // 5分钟
  2554. const stats = this.getWebSocketPerformanceStats();
  2555. console.log('WebSocket性能统计:', stats);
  2556. this.lastPerformanceCheck = now;
  2557. // 如果错误率过高,记录警告
  2558. if (stats.errorRate > 10) {
  2559. console.warn(`WebSocket错误率过高: ${stats.errorRate}%`);
  2560. }
  2561. // 如果连接延迟过高,记录警告
  2562. if (stats.connectionLatency > 5000) {
  2563. console.warn(`WebSocket连接延迟过高: ${stats.connectionLatency}ms`);
  2564. }
  2565. }
  2566. },
  2567. // 定期清理视频缓存
  2568. startVideoCacheCleanup() {
  2569. if (this.videoCleanupTimer) {
  2570. clearInterval(this.videoCleanupTimer);
  2571. }
  2572. // 每30秒清理一次视频缓存
  2573. this.videoCleanupTimer = setInterval(() => {
  2574. this.cleanupVideoCache();
  2575. }, 30000);
  2576. },
  2577. // 清理视频缓存
  2578. cleanupVideoCache() {
  2579. if (!this.liveItem || !this.liveId) return;
  2580. // 只对录播视频进行清理
  2581. if (this.liveItem.liveType === 2 && this.liveItem.videoUrl) {
  2582. this.reloadVideoPlayer();
  2583. }
  2584. },
  2585. // 重新加载视频播放器
  2586. reloadVideoPlayer() {
  2587. const videoId = `myVideo_${this.liveId}`;
  2588. const videoContext = uni.createVideoContext(videoId, this);
  2589. if (videoContext) {
  2590. const currentTime = this.videoCurrentTime;
  2591. // 暂停视频
  2592. videoContext.pause();
  2593. // 延迟重新加载
  2594. setTimeout(() => {
  2595. // 重新设置视频源,强制清理缓存
  2596. this.$set(this.liveItem, 'videoUrl', this.liveItem.videoUrl + '&t=' + Date.now());
  2597. // 恢复播放位置
  2598. setTimeout(() => {
  2599. if (videoContext.seek) {
  2600. videoContext.seek(currentTime);
  2601. }
  2602. videoContext.play();
  2603. }, 500);
  2604. }, 100);
  2605. }
  2606. },
  2607. // 启动内存监控
  2608. startMemoryMonitoring() {
  2609. if (this.memoryMonitorTimer) {
  2610. clearInterval(this.memoryMonitorTimer);
  2611. }
  2612. this.memoryMonitorTimer = setInterval(() => {
  2613. this.checkMemoryUsage();
  2614. }, 15000); // 每15秒检查一次
  2615. },
  2616. // 检查内存使用情况
  2617. checkMemoryUsage() {
  2618. try {
  2619. // 检查定时器数量
  2620. const timerCount = this.getActiveTimerCount();
  2621. if (timerCount > 10) {
  2622. console.warn(`检测到过多定时器: ${timerCount}个,可能存在内存泄漏`);
  2623. this.cleanupUnusedTimers();
  2624. }
  2625. // 检查消息队列长度
  2626. if (this.messageQueue && this.messageQueue.length > 100) {
  2627. console.warn(`消息队列过长: ${this.messageQueue.length}条,清理旧消息`);
  2628. this.messageQueue = this.messageQueue.slice(-50); // 只保留最新50条
  2629. }
  2630. // 检查用户颜色缓存
  2631. if (this.userRandomColors && Object.keys(this.userRandomColors).length > 500) {
  2632. console.warn('用户颜色缓存过大,清理部分缓存');
  2633. const keys = Object.keys(this.userRandomColors);
  2634. const keysToRemove = keys.slice(0, keys.length - 200); // 只保留最新200个
  2635. keysToRemove.forEach(key => delete this.userRandomColors[key]);
  2636. }
  2637. // 定期触发垃圾回收
  2638. if (Date.now() - this.lastPerformanceCheck > 60000) { // 每分钟一次
  2639. this.triggerGarbageCollection();
  2640. this.lastPerformanceCheck = Date.now();
  2641. }
  2642. } catch (error) {
  2643. console.error('内存检查失败:', error);
  2644. }
  2645. },
  2646. // 强制内存清理
  2647. forceMemoryCleanup() {
  2648. console.log('执行强制内存清理');
  2649. // 1. 清理视频播放器
  2650. this.cleanupVideoPlayer();
  2651. // 2. 清理大数据
  2652. this.clearBigData();
  2653. // 3. 强制垃圾回收(在支持的环境下)
  2654. this.triggerGarbageCollection();
  2655. },
  2656. // 清理视频播放器
  2657. cleanupVideoPlayer() {
  2658. const videoId = `myVideo_${this.liveId}`;
  2659. const videoContext = uni.createVideoContext(videoId, this);
  2660. if (videoContext) {
  2661. // 停止播放
  2662. videoContext.stop();
  2663. // 重置视频源
  2664. setTimeout(() => {
  2665. this.$set(this.liveItem, 'videoUrl', '');
  2666. setTimeout(() => {
  2667. this.$set(this.liveItem, 'videoUrl', this.getFreshVideoUrl());
  2668. this.playVideo();
  2669. }, 500);
  2670. }, 100);
  2671. }
  2672. },
  2673. // 获取带时间戳的新视频URL
  2674. getFreshVideoUrl() {
  2675. if (!this.liveItem.originalVideoUrl) {
  2676. this.liveItem.originalVideoUrl = this.liveItem.videoUrl;
  2677. }
  2678. // 添加时间戳参数,避免缓存
  2679. const separator = this.liveItem.originalVideoUrl.includes('?') ? '&' : '?';
  2680. return this.liveItem.originalVideoUrl + separator + 't=' + Date.now();
  2681. },
  2682. // 清理大数据
  2683. clearBigData() {
  2684. // 清理聊天记录,只保留最近50条
  2685. if (this.talklist.length > 50) {
  2686. this.talklist = this.talklist.slice(-50);
  2687. }
  2688. // 清理虚拟数据
  2689. if (this.liveViewers.length > 100) {
  2690. this.liveViewers = this.liveViewers.slice(-100);
  2691. }
  2692. // 清理商品数据
  2693. if (this.products.length > 50) {
  2694. this.products = this.products.slice(0, 50);
  2695. }
  2696. // 强制垃圾回收(如果支持)
  2697. if (typeof gc === 'function') {
  2698. gc();
  2699. }
  2700. },
  2701. // 触发垃圾回收(在支持的环境下)
  2702. triggerGarbageCollection() {
  2703. if (wx && wx.triggerGC) {
  2704. wx.triggerGC();
  2705. }
  2706. },
  2707. // 强制滚动到底部(备用方案)
  2708. forceScrollToBottom() {
  2709. // console.log('执行强制滚动到底部');
  2710. // iOS 特殊处理:主要使用 scrollTop
  2711. if (this.isIOS) {
  2712. // iOS 方案:使用 scrollTop 滚动到底部
  2713. this.scrollIntoView = '';
  2714. this.scrollTop = 999999;
  2715. this.$nextTick(() => {
  2716. setTimeout(() => {
  2717. this.scrollTop = 9999999;
  2718. this.nativeScrollToBottom();
  2719. }, 100);
  2720. });
  2721. } else {
  2722. // 非 iOS 平台:使用原有逻辑
  2723. // 方案1:直接设置一个很大的scrollTop值
  2724. this.scrollTop = 999999;
  2725. // 方案2:使用scroll-into-view滚动到最后一个元素
  2726. this.$nextTick(() => {
  2727. if (this.talklist && this.talklist.length > 0) {
  2728. const lastMessage = this.talklist[this.talklist.length - 1];
  2729. const targetId = `list_${lastMessage.uniqueId || (this.talklist.length - 1)}`;
  2730. console.log(
  2731. `尝试滚动到元素: ${targetId}, 当前消息数量: ${this.talklist.length}, 最后消息ID: ${lastMessage.uniqueId}`
  2732. );
  2733. this.scrollIntoView = targetId;
  2734. // 清除scroll-into-view,避免影响后续滚动
  2735. setTimeout(() => {
  2736. this.scrollIntoView = '';
  2737. }, 200);
  2738. }
  2739. // 方案3:使用更大的延迟再次设置scrollTop
  2740. setTimeout(() => {
  2741. this.scrollTop = 999999;
  2742. console.log('延迟设置scrollTop为999999');
  2743. }, 100);
  2744. // 方案4:300ms后使用原生API作为最终备用方案
  2745. setTimeout(() => {
  2746. this.nativeScrollToBottom();
  2747. }, 300);
  2748. });
  2749. }
  2750. },
  2751. // 强制滚动到底部(用于发送消息,绕过防抖限制)
  2752. forceScrollToBottomOnSend() {
  2753. //console.log('执行强制滚动到底部(发送消息专用)');
  2754. // 清理之前的定时器
  2755. if (this.scrollTimer) {
  2756. clearTimeout(this.scrollTimer);
  2757. this.scrollTimer = null;
  2758. }
  2759. // 强制更新滚动时间,确保不被防抖阻止
  2760. this.lastScrollTime = Date.now();
  2761. // 清除scroll-into-view,避免冲突
  2762. this.scrollIntoView = '';
  2763. // iOS 特殊处理:主要使用 scrollTop,因为 scroll-into-view 在 iOS 上可能不稳定
  2764. if (this.isIOS) {
  2765. // iOS 方案:使用 scrollTop 滚动到底部
  2766. // 先清除 scroll-into-view,避免冲突
  2767. this.scrollIntoView = '';
  2768. // 使用一个很大的 scrollTop 值
  2769. this.scrollTop = 999999;
  2770. this.$nextTick(() => {
  2771. // 延迟再次设置,确保滚动生效
  2772. setTimeout(() => {
  2773. this.scrollTop = 9999999;
  2774. // 使用原生 API 作为备用
  2775. this.nativeScrollToBottom();
  2776. }, 100);
  2777. });
  2778. } else {
  2779. // 非 iOS 平台:使用原有逻辑
  2780. // 方案1:立即使用scroll-into-view滚动到最后一条消息
  2781. if (this.talklist.length > 0) {
  2782. const lastMessage = this.talklist[this.talklist.length - 1];
  2783. if (lastMessage && lastMessage.uniqueId) {
  2784. this.scrollIntoView = `list_${lastMessage.uniqueId}`;
  2785. //console.log(`强制滚动方案1: 设置scrollIntoView为list_${lastMessage.uniqueId}`);
  2786. }
  2787. }
  2788. // 方案2:同时设置scrollTop为一个非常大的值
  2789. const targetScrollTop = Date.now(); // 使用时间戳确保每次都不同
  2790. this.scrollTop = targetScrollTop;
  2791. //console.log('强制滚动方案2: 设置scrollTop为', targetScrollTop);
  2792. // 方案3:立即尝试原生滚动
  2793. this.nativeScrollToBottom();
  2794. // 方案4:使用nextTick确保DOM更新后再次滚动
  2795. this.$nextTick(() => {
  2796. // 清除scroll-into-view后重新设置scrollTop
  2797. this.scrollIntoView = '';
  2798. this.scrollTop = targetScrollTop + 1;
  2799. //console.log('强制滚动方案3: nextTick后重新设置scrollTop');
  2800. // 再次尝试原生滚动
  2801. setTimeout(() => {
  2802. this.nativeScrollToBottom();
  2803. }, 50);
  2804. });
  2805. // 方案5:延迟检查和强制滚动(最终保障)
  2806. this.scrollTimer = setTimeout(() => {
  2807. this.checkAndForceScroll(targetScrollTop);
  2808. this.scrollTimer = null;
  2809. }, 200);
  2810. }
  2811. },
  2812. // 检查并强制滚动
  2813. checkAndForceScroll(targetScrollTop) {
  2814. //console.log(`检查滚动状态: 当前位置=${this.currentScrollTop}, 目标位置=${targetScrollTop}`);
  2815. // 无论当前位置如何,都尝试强制滚动到底部
  2816. // iOS 特殊处理:主要使用 scrollTop
  2817. if (this.isIOS) {
  2818. // iOS 方案:使用 scrollTop 滚动到底部
  2819. this.scrollIntoView = '';
  2820. this.scrollTop = 999999;
  2821. this.$nextTick(() => {
  2822. setTimeout(() => {
  2823. this.scrollTop = 9999999;
  2824. this.nativeScrollToBottom();
  2825. }, 100);
  2826. });
  2827. } else {
  2828. // 非 iOS 平台:使用原有逻辑
  2829. // 使用scroll-into-view滚动到最后一条消息
  2830. if (this.talklist.length > 0) {
  2831. const lastMessage = this.talklist[this.talklist.length - 1];
  2832. if (lastMessage && lastMessage.uniqueId) {
  2833. this.scrollIntoView = `list_${lastMessage.uniqueId}`;
  2834. //console.log(`最终检查: 设置scrollIntoView为list_${lastMessage.uniqueId}`);
  2835. }
  2836. }
  2837. // 设置一个新的scrollTop值
  2838. this.scrollTop = Date.now() + Math.random() * 1000;
  2839. //console.log('最终检查: 设置新的scrollTop值');
  2840. // 多次尝试原生滚动
  2841. this.nativeScrollToBottom();
  2842. setTimeout(() => {
  2843. this.nativeScrollToBottom();
  2844. }, 100);
  2845. }
  2846. },
  2847. // 使用原生API强制滚动(最终备用方案)
  2848. nativeScrollToBottom() {
  2849. try {
  2850. const query = uni.createSelectorQuery().in(this);
  2851. // iOS 特殊处理:主要使用 scrollTop,因为 scroll-into-view 在 iOS 上可能不稳定
  2852. if (this.isIOS) {
  2853. // iOS 方案:使用 fields 获取滚动信息并设置 scrollTop
  2854. query.select('#msgScroll').fields({
  2855. scrollOffset: true,
  2856. size: true
  2857. }, (res) => {
  2858. if (res && res.scrollHeight && res.height) {
  2859. const maxScrollTop = res.scrollHeight - res.height;
  2860. if (maxScrollTop > 0) {
  2861. // 直接设置一个足够大的 scrollTop 值,确保滚动到底部
  2862. this.scrollTop = maxScrollTop + 1000;
  2863. setTimeout(() => {
  2864. this.scrollTop = maxScrollTop + 2000;
  2865. }, 100);
  2866. } else {
  2867. // 如果计算失败,使用一个很大的值
  2868. this.scrollTop = 999999;
  2869. setTimeout(() => {
  2870. this.scrollTop = 9999999;
  2871. }, 100);
  2872. }
  2873. } else {
  2874. // 如果获取失败,使用一个很大的值
  2875. this.scrollTop = 999999;
  2876. setTimeout(() => {
  2877. this.scrollTop = 9999999;
  2878. }, 100);
  2879. }
  2880. }).exec();
  2881. } else {
  2882. // 非 iOS 平台:使用原有逻辑
  2883. query.select('#msgScroll').node((res) => {
  2884. if (res && res.node) {
  2885. const scrollHeight = res.node.scrollHeight;
  2886. res.node.scrollTop = scrollHeight;
  2887. setTimeout(() => {
  2888. res.node.scrollTop = scrollHeight + 100;
  2889. }, 50);
  2890. }
  2891. }).exec();
  2892. }
  2893. } catch (error) {
  2894. console.error('原生滚动失败:', error);
  2895. }
  2896. },
  2897. // 监听滚动事件
  2898. onScroll(e) {
  2899. this.currentScrollTop = e.detail.scrollTop;
  2900. //console.log('当前滚动位置:', this.currentScrollTop);
  2901. },
  2902. // 停止内存监控
  2903. stopMemoryMonitor() {
  2904. if (this.memoryMonitorTimer) {
  2905. clearInterval(this.memoryMonitorTimer);
  2906. this.memoryMonitorTimer = null;
  2907. }
  2908. },
  2909. // 获取活跃定时器数量
  2910. getActiveTimerCount() {
  2911. const timers = [
  2912. 'trafficTimer', 'pingTimeoutTimer', 'heartBeatTimer', 'liveViewDataTimer',
  2913. 'reconnectTimer', 'scrollTimer', 'searchTimer', 'purchasePromptTimer',
  2914. 'welcomeTimer', 'redTimer', 'liveStartTimer', 'lotteryTimer',
  2915. 'memoryMonitorTimer', 'networkStatusTimer', 'networkRetryTimer', 'generatingTimer',
  2916. 'videoCleanupTimer', 'countdownTimer', 'watchTimeTimer', 'pointsRetryTimer'
  2917. ];
  2918. return timers.filter(timer => this[timer] !== null).length;
  2919. },
  2920. // 清理未使用的定时器
  2921. cleanupUnusedTimers() {
  2922. // 检查并清理可能泄漏的定时器
  2923. const timers = [
  2924. 'trafficTimer', 'pingTimeoutTimer', 'heartBeatTimer', 'liveViewDataTimer',
  2925. 'reconnectTimer', 'scrollTimer', 'searchTimer', 'purchasePromptTimer',
  2926. 'welcomeTimer', 'redTimer', 'liveStartTimer', 'lotteryTimer', 'noticeTimer',
  2927. 'networkStatusTimer', 'networkRetryTimer', 'generatingTimer',
  2928. 'videoCleanupTimer', 'countdownTimer', 'watchTimeTimer', 'memoryMonitorTimer',
  2929. 'pointsRetryTimer'
  2930. ];
  2931. timers.forEach(timerName => {
  2932. if (this[timerName] && typeof this[timerName] === 'number') {
  2933. // 检查定时器是否还在运行
  2934. if (timerName.includes('Interval') || timerName.includes('Timer')) {
  2935. clearInterval(this[timerName]);
  2936. } else {
  2937. clearTimeout(this[timerName]);
  2938. }
  2939. this[timerName] = null;
  2940. console.log(`清理了可能泄漏的定时器: ${timerName}`);
  2941. }
  2942. });
  2943. },
  2944. // 增强的定时器清理方法
  2945. clearAllTimersEnhanced() {
  2946. // 先调用原有的清理方法
  2947. this.clearAllTimers();
  2948. // 额外清理新增的定时器
  2949. if (this.networkRetryTimer) {
  2950. clearTimeout(this.networkRetryTimer);
  2951. this.networkRetryTimer = null;
  2952. }
  2953. // 停止内存监控
  2954. this.stopMemoryMonitor();
  2955. // 清理缓存数据
  2956. this.userRandomColors = Object.create(null);
  2957. this.shownEntryUsers.clear();
  2958. // 重置性能监控数据
  2959. this.messageCount = 0;
  2960. this.errorCount = 0;
  2961. this.connectionLatency = 0;
  2962. this.lastPerformanceCheck = 0;
  2963. console.log('增强清理完成:所有定时器和缓存已清理');
  2964. },
  2965. goMiniProgram() {
  2966. uni.navigateTo({
  2967. url: '/pages_user/user/integralGoodsList'
  2968. })
  2969. },
  2970. // 阻止双击事件
  2971. preventDoubleClick(e) {
  2972. e.preventDefault();
  2973. e.stopPropagation();
  2974. return false;
  2975. },
  2976. // 清理所有定时器和内存
  2977. clearAllTimers() {
  2978. // 清理所有定时器
  2979. const timers = [
  2980. 'scrollTimer',
  2981. 'liveViewDataTimer',
  2982. 'redTimer',
  2983. 'liveStartTimer',
  2984. 'lotteryTimer',
  2985. 'noticeTimer',
  2986. 'welcomeTimer',
  2987. 'trafficInterval',
  2988. 'lookTimer',
  2989. 'trafficTimer',
  2990. 'intervalId',
  2991. 'reconnectTimer',
  2992. 'searchTimer',
  2993. 'purchasePromptTimer',
  2994. 'heartBeatTimer',
  2995. 'pingTimeoutTimer',
  2996. 'generatingTimer',
  2997. 'videoCleanupTimer',
  2998. 'countdownTimer',
  2999. 'watchTimeTimer',
  3000. 'memoryMonitorTimer',
  3001. 'networkStatusTimer',
  3002. 'networkRetryTimer',
  3003. 'pointsRetryTimer'
  3004. ];
  3005. timers.forEach((timer) => {
  3006. if (this[timer]) {
  3007. if (timer.includes('Interval') || timer.includes('Timer')) {
  3008. clearInterval(this[timer]);
  3009. } else {
  3010. clearTimeout(this[timer]);
  3011. }
  3012. this[timer] = null;
  3013. }
  3014. });
  3015. // 重置相关状态
  3016. this.stayTime = 0;
  3017. this.startTime = 0;
  3018. this.totalTraffic = 0;
  3019. this.scrollPending = false;
  3020. this.reconnectCount = 0;
  3021. this.heartBeatRetryCount = 0;
  3022. },
  3023. //直播计算流量
  3024. // startTrafficCalculation() {
  3025. // if (this.trafficTimer) {
  3026. // clearInterval(this.trafficTimer);
  3027. // this.trafficTimer = null;
  3028. // }
  3029. // this.startTime = Date.now();
  3030. // var that = this;
  3031. // // 计算码率
  3032. // let bitrate = this.calculateBitrate();
  3033. // this.trafficTimer = setInterval(() => {
  3034. // that.calculateTraffic(bitrate);
  3035. // }, 10000); // 每10秒计算一次
  3036. // },
  3037. //直播计算流量
  3038. startTrafficCalculation() {
  3039. // 检查必要数据
  3040. if (!this.liveItem || !this.liveItem.videoFileSize) {
  3041. console.warn('视频文件大小数据不完整,无法启动流量计算');
  3042. return;
  3043. }
  3044. // 检查视频总时长
  3045. const totalDuration = this.liveItem.videoDuration || this.liveItem.duration;
  3046. if (!totalDuration) {
  3047. console.warn('视频总时长数据不完整,无法启动流量计算');
  3048. return;
  3049. }
  3050. // 如果流量计算已经在进行中,且 trafficStartTime 已存在,不重复启动
  3051. // 避免重复累计流量
  3052. if (this.trafficTimer && this.trafficStartTime > 0) {
  3053. console.log('流量计算已在进行中,跳过重复启动');
  3054. return;
  3055. }
  3056. // 清除已有定时器
  3057. if (this.trafficTimer) {
  3058. clearInterval(this.trafficTimer);
  3059. this.trafficTimer = null;
  3060. }
  3061. // 如果之前有流量计算,先提交当前流量数据,避免丢失
  3062. if (this.trafficStartTime > 0 && this.videoLoaded) {
  3063. const watchDuration = Math.floor((this.getServerTimeNow() - this.trafficStartTime) / 1000);
  3064. if (watchDuration > 0) {
  3065. this.submitTraffic(watchDuration);
  3066. }
  3067. }
  3068. // 重置总流量
  3069. this.totalTraffic = 0;
  3070. // 记录流量计算开始时间
  3071. this.trafficStartTime = this.getServerTimeNow();
  3072. var that = this;
  3073. // 立即提交一次10s流量(模拟10秒观看)
  3074. setTimeout(() => {
  3075. that.submitTraffic(10);
  3076. }, 100); // 延迟100ms确保数据已准备好
  3077. // 启动定时器,每10秒计算并提交一次流量
  3078. this.trafficTimer = setInterval(() => {
  3079. that.calculateAndSubmitTraffic();
  3080. }, 10000); // 每10秒计算一次
  3081. },
  3082. // 计算流量
  3083. // calculateTraffic(bitrate) {
  3084. // const currentTime = Date.now();
  3085. // const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  3086. // // 流量 = 码率 × 时间
  3087. // // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  3088. // const trafficBits = bitrate * duration;
  3089. // // 转换为字节
  3090. // this.totalTraffic = trafficBits / 8;
  3091. // this.getLiveInternetTraffic();
  3092. // },
  3093. // calculateBitrate() {
  3094. // // 如果接口返回了视频文件大小和时长,使用这些数据计算码率
  3095. // if (this.liveItem.videoFileSize && this.liveItem.videoDuration) {
  3096. // // 码率 = 文件大小(字节) / 时长(秒) × 8 (转换为bps) × 5
  3097. // const calculatedBitrate = (this.liveItem.videoFileSize / this.liveItem.videoDuration) * 8 * 5;
  3098. // console.log(
  3099. // `使用接口数据计算码率: ${calculatedBitrate} bps (文件大小: ${this.liveItem.videoFileSize} 字节, 时长: ${this.liveItem.videoDuration} 秒)`
  3100. // );
  3101. // return calculatedBitrate;
  3102. // } else {
  3103. // // 如果任一字段为空,使用默认码率 1500 bps
  3104. // console.log('接口数据不完整,使用默认码率: 1500 bps');
  3105. // return 1500;
  3106. // }
  3107. // },
  3108. // calculateTraffic(bitrate) {
  3109. // const currentTime = Date.now();
  3110. // const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  3111. // // 流量 = 码率 × 时间
  3112. // // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  3113. // const trafficBits = bitrate * duration;
  3114. // // 转换为字节
  3115. // this.totalTraffic = trafficBits / 8;
  3116. // // 调用流量上报接口
  3117. // this.getLiveInternetTraffic();
  3118. // },
  3119. // 计算并提交流量
  3120. calculateAndSubmitTraffic() {
  3121. if (!this.liveItem || !this.liveItem.videoFileSize) {
  3122. const totalDuration = this.liveItem.videoDuration || this.liveItem.duration;
  3123. if (!totalDuration) {
  3124. return;
  3125. }
  3126. }
  3127. // 计算用户观看视频时长(秒)
  3128. //const watchDuration = Math.floor((Date.now() - this.trafficStartTime) / 1000);
  3129. const watchDuration = Math.floor((this.getServerTimeNow() - this.trafficStartTime) / 1000);
  3130. // 获取视频总时长(秒)
  3131. const totalDuration = this.liveItem.videoDuration || this.liveItem.duration || 0;
  3132. // 获取视频文件大小(字节)
  3133. const videoFileSize = this.liveItem.videoFileSize || 0;
  3134. if (totalDuration <= 0 || videoFileSize <= 0) {
  3135. console.warn('视频总时长或文件大小无效,无法计算流量');
  3136. return;
  3137. }
  3138. // 流量计算方法:用户观看视频时长/视频总时长*视频文件大小
  3139. const calculatedTraffic = (watchDuration / totalDuration) * videoFileSize;
  3140. // 更新总流量
  3141. this.totalTraffic = calculatedTraffic;
  3142. // 提交流量数据
  3143. this.submitTraffic(watchDuration);
  3144. },
  3145. // 提交流量数据到后端
  3146. submitTraffic(watchDuration) {
  3147. if (!this.liveId || !this.userInfo || !this.userInfo.userId) {
  3148. return;
  3149. }
  3150. // 计算当前观看时长对应的流量
  3151. const totalDuration = this.liveItem.videoDuration || this.liveItem.duration || 0;
  3152. const videoFileSize = this.liveItem.videoFileSize || 0;
  3153. if (totalDuration <= 0 || videoFileSize <= 0) {
  3154. console.warn('视频总时长或文件大小无效,无法提交流量', {
  3155. totalDuration,
  3156. videoFileSize,
  3157. videoDuration: this.liveItem.videoDuration,
  3158. duration: this.liveItem.duration
  3159. });
  3160. return;
  3161. }
  3162. // 流量 = 用户观看视频时长/视频总时长*视频文件大小
  3163. const traffic = (watchDuration / totalDuration) * videoFileSize;
  3164. const param = {
  3165. userId: this.userInfo.userId || '',
  3166. liveId: this.liveId || '',
  3167. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  3168. internetTraffic: Math.round(traffic), // 四舍五入到整数
  3169. watchDuration: watchDuration, // 观看时长(秒)
  3170. totalDuration: totalDuration, // 视频总时长(秒)
  3171. videoFileSize: videoFileSize // 视频文件大小(字节)
  3172. };
  3173. //console.log('提交流量数据:', param);
  3174. liveInternetTraffic(param).catch(err => {
  3175. console.error('流量数据提交失败:', err);
  3176. });
  3177. },
  3178. startTimer() {
  3179. this.startTime = Date.now();
  3180. this.lookTimer = setInterval(() => {
  3181. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000);
  3182. }, 1000);
  3183. },
  3184. //直播、录播缓冲
  3185. getLiveInternetTraffic() {
  3186. if (!this.liveId) return;
  3187. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  3188. const param = {
  3189. userId: this.userInfo.userId || '',
  3190. liveId: this.liveId || '',
  3191. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  3192. internetTraffic: this.totalTraffic
  3193. };
  3194. liveInternetTraffic(param);
  3195. },
  3196. // 回放、预告缓冲
  3197. getInternetTraffic() {
  3198. if (!this.liveId || !this.liveId || !this.userInfo.userId || !this.uuId) return;
  3199. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  3200. const param = {
  3201. videoType: this.liveItem.videoType,
  3202. videoId: this.liveItem.videoId,
  3203. userId: this.userInfo.userId,
  3204. liveId: this.liveId,
  3205. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  3206. duration: this.liveItem.duration,
  3207. bufferRate: currentTime
  3208. };
  3209. if (this.liveItem.status == 1) {
  3210. param.videoType = this.liveItem.previewVideoType || '';
  3211. param.videoId = this.liveItem.previewVideoId || '';
  3212. }
  3213. if (this.liveItem.liveType == 1) {
  3214. param.bufferRate = this.totalTraffic;
  3215. }
  3216. //internetTraffic(param);
  3217. },
  3218. scrollToBottom() {
  3219. const now = Date.now();
  3220. // 防抖检查:如果距离上次滚动时间太短,则忽略
  3221. if (now - this.lastScrollTime < this.scrollDebounceDelay) {
  3222. return;
  3223. }
  3224. this.lastScrollTime = now;
  3225. // 清理之前的定时器
  3226. if (this.scrollTimer) {
  3227. clearTimeout(this.scrollTimer);
  3228. this.scrollTimer = null;
  3229. }
  3230. // iOS 特殊处理:主要使用 scrollTop
  3231. if (this.isIOS) {
  3232. // iOS 方案:使用 scrollTop 滚动到底部
  3233. this.scrollIntoView = '';
  3234. this.scrollTop = 999999999;
  3235. this.$nextTick(() => {
  3236. setTimeout(() => {
  3237. this.scrollTop = 9999999999;
  3238. }, 100);
  3239. });
  3240. } else {
  3241. // 非 iOS 平台:直接设置滚动位置
  3242. this.scrollTop = 999999999;
  3243. }
  3244. },
  3245. // 启动内存监控
  3246. startMemoryMonitor() {
  3247. // 清理之前的监控
  3248. if (this.memoryMonitorTimer) {
  3249. clearInterval(this.memoryMonitorTimer);
  3250. }
  3251. // 每5分钟检查一次内存使用情况
  3252. this.memoryMonitorTimer = setInterval(() => {
  3253. this.checkAndCleanMemory();
  3254. }, 5 * 60 * 1000); // 5分钟
  3255. },
  3256. // 检查并清理内存
  3257. checkAndCleanMemory() {
  3258. try {
  3259. // 清理过多的聊天消息
  3260. if (this.talklist && this.talklist.length > 25) {
  3261. const keepCount = 20;
  3262. this.talklist.splice(0, this.talklist.length - keepCount);
  3263. }
  3264. // 清理用户颜色缓存(保留最近的50个)
  3265. if (this.userRandomColors && Object.keys(this.userRandomColors).length > 50) {
  3266. const entries = Object.entries(this.userRandomColors);
  3267. const keepEntries = entries.slice(-50);
  3268. this.userRandomColors = Object.fromEntries(keepEntries);
  3269. }
  3270. // 清理已显示用户集合(保留最近的100个)
  3271. if (this.shownEntryUsers && this.shownEntryUsers.size > 100) {
  3272. const array = Array.from(this.shownEntryUsers);
  3273. this.shownEntryUsers.clear();
  3274. array.slice(-100).forEach((id) => this.shownEntryUsers.add(id));
  3275. }
  3276. console.log('内存清理完成——————————————————————',this.shownEntryUsers);
  3277. } catch (error) {
  3278. console.error('内存清理失败:', error);
  3279. }
  3280. },
  3281. // 恢复页面活动
  3282. async resumePageActivity() {
  3283. if (this.liveItem) {
  3284. await this.getliving(this.liveId);
  3285. this.startTimeTimer(this.liveItem);
  3286. }
  3287. if (!this.isSocketAvailable()) {
  3288. this.initSocket();
  3289. }
  3290. },
  3291. // 获取用户专属随机色(缓存机制:同一用户始终用同一颜色)
  3292. getUserRandomColor(userId) {
  3293. if (!userId) {
  3294. return '#8978e2'; // 默认颜色
  3295. }
  3296. //如果缓存中已有该用户的颜色,直接返回
  3297. if (this.userRandomColors[userId]) {
  3298. return this.userRandomColors[userId];
  3299. }
  3300. //为新用户生成固定颜色(基于用户ID生成,不是完全随机)
  3301. const color = this.generateStableColor(userId);
  3302. this.userRandomColors[userId] = color;
  3303. // 存储到本地缓存,确保页面刷新后颜色不变
  3304. this.saveUserColorsToStorage();
  3305. return color;
  3306. }, // 基于用户ID生成稳定颜色(不是完全随机)
  3307. generateStableColor(userId) {
  3308. // 将用户ID转换为数字种子
  3309. let seed = 0;
  3310. for (let i = 0; i < userId.length; i++) {
  3311. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  3312. }
  3313. const colorPool = [
  3314. '#FF6B6B',
  3315. '#4ECDC4',
  3316. '#45B7D1',
  3317. '#96CEB4',
  3318. '#FFEAA7',
  3319. '#DDA0DD',
  3320. '#98D8C8',
  3321. '#F7DC6F',
  3322. '#BB8FCE',
  3323. '#85C1E9',
  3324. '#F8C471',
  3325. '#82E0AA',
  3326. '#F1948A',
  3327. '#85C1E9',
  3328. '#D7BDE2'
  3329. ];
  3330. return colorPool[seed % colorPool.length];
  3331. },
  3332. // 保存颜色映射到本地存储
  3333. saveUserColorsToStorage() {
  3334. try {
  3335. uni.setStorageSync('userRandomColors', this.userRandomColors);
  3336. } catch (e) {
  3337. console.warn('保存用户颜色缓存失败:', e);
  3338. }
  3339. },
  3340. // 从本地存储加载颜色映射
  3341. loadUserColorsFromStorage() {
  3342. try {
  3343. const cached = uni.getStorageSync('userRandomColors');
  3344. if (cached) {
  3345. this.userRandomColors = cached;
  3346. }
  3347. } catch (e) {
  3348. console.warn('加载用户颜色缓存失败:', e);
  3349. }
  3350. },
  3351. //头像名字
  3352. getNicknameInitial(nickName) {
  3353. if (!nickName || typeof nickName !== 'string') return '未';
  3354. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  3355. return nickName[0];
  3356. }
  3357. return nickName[0].toUpperCase();
  3358. },
  3359. async getUserInfo() {
  3360. await getUserInfo().then(
  3361. (res) => {
  3362. if (res.code == 200) {
  3363. this.userInfo = res.user;
  3364. this.isNow = dayjs(this.userInfo.updateTime).isSame(dayjs(), 'day')
  3365. } else {
  3366. uni.showToast({
  3367. icon: 'none',
  3368. title: '请求失败'
  3369. });
  3370. }
  3371. },
  3372. (rej) => {}
  3373. );
  3374. },
  3375. //订阅消息
  3376. handleAgreement() {
  3377. const templateId = this.templateId;
  3378. if (this.hasSubscribed) return;
  3379. uni.requestSubscribeMessage({
  3380. tmplIds: [templateId],
  3381. success: (res) => {
  3382. if (res[templateId] === 'accept') {
  3383. uni.showToast({
  3384. title: '订阅成功,开播将提醒您',
  3385. icon: 'none',
  3386. duration: 2500 // 成功提示延长到2.5秒
  3387. });
  3388. // 订阅成功时
  3389. this.hasSubscribed = true;
  3390. uni.setStorageSync('subscribe_status_' + this.liveId, true);
  3391. this.callSendMessageApi();
  3392. } else if (res[templateId] === 'reject') {
  3393. uni.showToast({
  3394. title: '您已拒绝订阅,将无法收到提醒',
  3395. icon: 'none',
  3396. duration: 2500 // 成功提示延长到2.5秒
  3397. });
  3398. } else if (res[templateId] === 'ban') {
  3399. uni.showToast({
  3400. title: '您已关闭所有订阅权限,请在设置中开启',
  3401. icon: 'none',
  3402. duration: 2500 // 成功提示延长到2.5秒
  3403. });
  3404. }
  3405. },
  3406. fail: (err) => {
  3407. console.error('订阅消息失败', err);
  3408. uni.showToast({
  3409. title: '订阅失败,请重试',
  3410. icon: 'none',
  3411. duration: 2500 // 成功提示延长到2.5秒
  3412. });
  3413. }
  3414. });
  3415. },
  3416. async callSendMessageApi() {
  3417. if (!this.userInfo.userId) return;
  3418. const templateData = {
  3419. liveId: this.liveId,
  3420. userId: this.userInfo.userId,
  3421. templateId: this.templateId, // 模板ID
  3422. maOpenId: this.userInfo.maOpenId,
  3423. appId: this.appid,
  3424. data: {
  3425. thing4: this.liveItem.liveName,
  3426. time2: this.liveItem.startTime,
  3427. date7: this.liveItem.startTime
  3428. }
  3429. };
  3430. subNotifyLive(templateData).then(
  3431. (res) => {
  3432. if (res.code == 200) {
  3433. this.isAgreement = true;
  3434. uni.setStorageSync('isAgreement', true);
  3435. } else {
  3436. uni.showToast({
  3437. title: res.msg,
  3438. icon: 'none'
  3439. });
  3440. }
  3441. },
  3442. (rej) => {}
  3443. );
  3444. },
  3445. //发送心跳
  3446. sendHeartBeat() {
  3447. if (!this.isSocketAvailable() || !this.isNetworkAvailable) {
  3448. console.warn('网络不可用或Socket连接异常,跳过心跳发送');
  3449. return;
  3450. }
  3451. this.lastHeartBeatTime = Date.now();
  3452. // 计算当前累计观看时长
  3453. const currentWatchDuration = this.getCurrentWatchDuration();
  3454. try {
  3455. const heartBeatMsg = JSON.stringify({
  3456. cmd: 'heartbeat',
  3457. msg: 'ping',
  3458. userId: this.userInfo.userId || '',
  3459. liveId: this.liveId,
  3460. timestamp: this.lastHeartBeatTime,
  3461. networkType: this.networkType,
  3462. data: String(currentWatchDuration)
  3463. });
  3464. this.socket.send({
  3465. data: heartBeatMsg,
  3466. success: () => {
  3467. this.heartBeatRetryCount = 0; // 成功后重置重试次数
  3468. this.adjustHeartBeatInterval(true); // 网络良好,可适当延长间隔
  3469. this.startPingTimeout(); // 启动超时检测
  3470. },
  3471. fail: (err) => {
  3472. console.error('心跳包发送失败:', err);
  3473. this.heartBeatRetryCount++;
  3474. this.adjustHeartBeatInterval(false); // 网络不稳定,缩短间隔
  3475. // 根据网络类型调整重试策略
  3476. const retryDelay = this.getRetryDelay();
  3477. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  3478. setTimeout(() => this.sendHeartBeat(), retryDelay);
  3479. } else {
  3480. this.heartBeatRetryCount = 0;
  3481. this.handleReconnect(); // 重试用完才重连
  3482. }
  3483. }
  3484. });
  3485. } catch (err) {
  3486. console.error('心跳发送异常:', err);
  3487. this.heartBeatRetryCount++;
  3488. const retryDelay = this.getRetryDelay();
  3489. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  3490. setTimeout(() => this.sendHeartBeat(), retryDelay);
  3491. } else {
  3492. this.heartBeatRetryCount = 0;
  3493. this.handleReconnect();
  3494. }
  3495. }
  3496. },
  3497. // 根据网络状态获取重试延迟
  3498. getRetryDelay() {
  3499. const baseDelay = 2000;
  3500. const retryMultiplier = Math.pow(1.5, this.heartBeatRetryCount); // 指数退避
  3501. // 根据网络类型调整延迟
  3502. let networkMultiplier = 1;
  3503. switch (this.networkType) {
  3504. case '2g':
  3505. networkMultiplier = 3;
  3506. break;
  3507. case '3g':
  3508. networkMultiplier = 2;
  3509. break;
  3510. case '4g':
  3511. case '5g':
  3512. networkMultiplier = 1;
  3513. break;
  3514. case 'wifi':
  3515. networkMultiplier = 0.8;
  3516. break;
  3517. default:
  3518. networkMultiplier = 1.5;
  3519. }
  3520. return Math.min(baseDelay * retryMultiplier * networkMultiplier, 10000); // 最大10秒
  3521. },
  3522. // 自适应调整心跳间隔
  3523. adjustHeartBeatInterval(isSuccess) {
  3524. if (isSuccess) {
  3525. // 连接稳定,可适当延长间隔(最大30秒)
  3526. this.adaptiveHeartBeatInterval = Math.min(this.adaptiveHeartBeatInterval * 1.1, 30000);
  3527. } else {
  3528. // 连接不稳定,缩短间隔(最小10秒)
  3529. this.adaptiveHeartBeatInterval = Math.max(this.adaptiveHeartBeatInterval * 0.9, 10000);
  3530. }
  3531. },
  3532. // 启动心跳超时检测
  3533. startPingTimeout() {
  3534. // 清除现有的ping超时定时器
  3535. if (this.pingTimeoutTimer) {
  3536. clearTimeout(this.pingTimeoutTimer);
  3537. this.pingTimeoutTimer = null;
  3538. }
  3539. // 启动新的ping超时定时器
  3540. this.pingTimeoutTimer = setTimeout(() => {
  3541. console.warn('心跳超时,触发重连');
  3542. // 清理当前定时器引用
  3543. this.pingTimeoutTimer = null;
  3544. // 增加心跳重试次数
  3545. this.heartBeatRetryCount++;
  3546. // 如果重试次数未达到上限,先尝试重发心跳
  3547. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  3548. console.log(
  3549. `心跳超时,尝试重发 (${this.heartBeatRetryCount}/${this.maxHeartBeatRetries})`);
  3550. setTimeout(() => this.sendHeartBeat(), 1000);
  3551. } else {
  3552. console.log('心跳重试次数用尽,触发重连');
  3553. this.heartBeatRetryCount = 0;
  3554. this.handleReconnect();
  3555. }
  3556. }, this.pingTimeout);
  3557. },
  3558. stopHeartBeat() {
  3559. if (this.heartBeatTimer) {
  3560. clearInterval(this.heartBeatTimer);
  3561. this.heartBeatTimer = null;
  3562. }
  3563. if (this.pingTimeoutTimer) {
  3564. clearTimeout(this.pingTimeoutTimer);
  3565. this.pingTimeoutTimer = null;
  3566. }
  3567. }, // 封装通用的连接状态校验方法
  3568. isSocketAvailable() {
  3569. // WebSocket readyState:0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
  3570. return this.socket && this.isSocketOpen && this.socket.readyState === 1;
  3571. },
  3572. // 处理重连逻辑
  3573. handleReconnect() {
  3574. if (this.isManualClose) {
  3575. console.log('手动关闭连接,不进行重连');
  3576. return;
  3577. }
  3578. // 防止重复重连
  3579. if (this.reconnectTimer) {
  3580. console.log('重连已在进行中,跳过重复重连');
  3581. return;
  3582. }
  3583. this.stopHeartBeat();
  3584. // 检查网络状态
  3585. if (!this.isNetworkAvailable) {
  3586. console.warn('网络不可用,延迟重连');
  3587. this.reconnectTimer = setTimeout(() => {
  3588. this.reconnectTimer = null;
  3589. this.handleReconnect();
  3590. }, 5000);
  3591. return;
  3592. }
  3593. if (this.reconnectCount < this.maxReconnectAttempts) {
  3594. this.reconnectCount++;
  3595. // 指数退避算法:基础延迟 * 2^(重连次数-1) + 随机抖动
  3596. const baseDelay = 1000;
  3597. const exponentialDelay = baseDelay * Math.pow(2, this.reconnectCount - 1);
  3598. const jitter = 10000 + Math.random() * 1000; // 随机抖动,避免同时重连
  3599. const totalDelay = Math.min(exponentialDelay + jitter, 30000); // 最大30秒
  3600. console.log(
  3601. `第${this.reconnectCount}次重连,延迟${Math.round(totalDelay)}ms,网络类型:${this.networkType}`
  3602. );
  3603. this.reconnectTimer = setTimeout(() => {
  3604. this.reconnectTimer = null; // 清理定时器引用
  3605. // 重连前再次检查网络状态和连接状态
  3606. if (this.isNetworkAvailable && !this.isManualClose && !this
  3607. .isSocketAvailable()) {
  3608. console.log('开始执行重连...');
  3609. this.initSocket();
  3610. } else if (this.isSocketAvailable()) {
  3611. console.log('连接已恢复,取消重连');
  3612. this.reconnectCount = 0; // 重置重连计数
  3613. } else {
  3614. console.warn('重连时网络不可用或已手动关闭');
  3615. this.handleReconnect(); // 递归重试
  3616. }
  3617. }, totalDelay);
  3618. } else {
  3619. console.log(`已达最大重连次数(${this.maxReconnectAttempts}),停止重连`);
  3620. this.showReconnectFailedMessage();
  3621. }
  3622. },
  3623. // 显示重连失败提示
  3624. showReconnectFailedMessage() {
  3625. uni.showToast({
  3626. title: '网络连接异常,请检查网络后重新进入',
  3627. icon: 'none',
  3628. duration: 3000
  3629. });
  3630. },
  3631. // 统一处理连接错误
  3632. handleConnectionError(errorType, error) {
  3633. console.error(`WebSocket ${errorType}:`, error);
  3634. // 根据错误类型进行不同处理
  3635. if (errorType === '连接请求失败') {
  3636. // 连接请求失败,可能是网络问题或服务器问题
  3637. if (!this.isNetworkAvailable) {
  3638. console.warn('网络不可用,等待网络恢复后重连');
  3639. return;
  3640. }
  3641. }
  3642. // 触发重连
  3643. this.handleReconnect();
  3644. },
  3645. // 重置重连状态
  3646. resetReconnectState() {
  3647. this.reconnectCount = 0;
  3648. this.heartBeatRetryCount = 0;
  3649. // 清理重连定时器
  3650. if (this.reconnectTimer) {
  3651. clearTimeout(this.reconnectTimer);
  3652. this.reconnectTimer = null;
  3653. }
  3654. // 重置自适应心跳间隔
  3655. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  3656. },
  3657. // 初始化网络状态监听
  3658. initNetworkStatusListener() {
  3659. // 获取当前网络状态
  3660. uni.getNetworkType({
  3661. success: (res) => {
  3662. this.networkType = res.networkType;
  3663. this.isNetworkAvailable = res.networkType !== 'none';
  3664. console.log('当前网络类型:', res.networkType);
  3665. }
  3666. });
  3667. // 监听网络状态变化
  3668. uni.onNetworkStatusChange((res) => {
  3669. const oldNetworkType = this.networkType;
  3670. const oldNetworkAvailable = this.isNetworkAvailable;
  3671. this.networkType = res.networkType;
  3672. this.isNetworkAvailable = res.isConnected;
  3673. console.log(
  3674. `网络状态变化: ${oldNetworkType} -> ${res.networkType}, 连接状态: ${res.isConnected}`
  3675. );
  3676. // 网络从不可用变为可用时,尝试重连
  3677. if (!oldNetworkAvailable && res.isConnected) {
  3678. console.log('网络恢复,尝试重连WebSocket');
  3679. this.resetReconnectState();
  3680. setTimeout(() => {
  3681. if (!this.isSocketAvailable()) {
  3682. this.initSocket();
  3683. }
  3684. }, 1000);
  3685. }
  3686. // 网络类型变化时,调整心跳策略
  3687. if (oldNetworkType !== res.networkType && res.isConnected) {
  3688. this.adjustHeartBeatForNetworkType(res.networkType);
  3689. }
  3690. // 网络断开时停止心跳
  3691. if (!res.isConnected) {
  3692. console.warn('网络断开,停止心跳');
  3693. this.stopHeartBeat();
  3694. }
  3695. });
  3696. },
  3697. // 根据网络类型调整心跳策略
  3698. adjustHeartBeatForNetworkType(networkType) {
  3699. let newInterval = this.heartBeatInterval;
  3700. switch (networkType) {
  3701. case '2g':
  3702. newInterval = 30000; // 2G网络,30秒间隔
  3703. break;
  3704. case '3g':
  3705. newInterval = 20000; // 3G网络,20秒间隔
  3706. break;
  3707. case '4g':
  3708. case '5g':
  3709. newInterval = 15000; // 4G/5G网络,15秒间隔
  3710. break;
  3711. case 'wifi':
  3712. newInterval = 10000; // WiFi网络,10秒间隔
  3713. break;
  3714. default:
  3715. newInterval = 15000; // 默认15秒
  3716. }
  3717. if (newInterval !== this.adaptiveHeartBeatInterval) {
  3718. this.adaptiveHeartBeatInterval = newInterval;
  3719. console.log(`根据网络类型(${networkType})调整心跳间隔为${newInterval}ms`);
  3720. // 如果当前有心跳在运行,重启心跳以应用新间隔
  3721. if (this.heartBeatTimer && this.isSocketAvailable()) {
  3722. this.startHeartBeat();
  3723. }
  3724. }
  3725. },
  3726. //输入框
  3727. inputFocus() {
  3728. // 立即更新状态,确保UI零延迟响应
  3729. this.isFocus = true;
  3730. this.isKeyboardShow = true;
  3731. this.scrollTop = 9999999
  3732. },
  3733. inputBlur() {
  3734. this.isFocus = false;
  3735. },
  3736. getTimeDifferenceInSeconds(createTimeStr, useServerTime = false) {
  3737. if (!createTimeStr) return;
  3738. // const createTime = new Date(createTimeStr.replace(/-/g, '/'));
  3739. // 使用服务器时间或本地时间
  3740. const now = useServerTime ? Number(this.getServerTimeNow()) : Date.now();
  3741. const timeDiffMs = now - createTimeStr;
  3742. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  3743. return Math.max(0, timeDiffSeconds);
  3744. },
  3745. // 录播时间点
  3746. onVideoMetaLoaded(e) {
  3747. console.log("录播时间点", e)
  3748. const width = e.detail.width;
  3749. const height = e.detail.height;
  3750. const res = uni.getSystemInfoSync();
  3751. const winH = res.windowHeight;
  3752. const winW = res.windowWidth;
  3753. //横屏
  3754. const wW = (winW / winH) * 100;
  3755. //竖屏
  3756. if (height > width) {
  3757. this.isHeight = true
  3758. }
  3759. const wH = (winH / winW) * 100;
  3760. this.videoProgressKey = `videoProgress_${this.liveId}`;
  3761. this.setVideoProgress();
  3762. // 视频加载成功后,启动流量计算
  3763. if (!this.videoLoaded) {
  3764. this.videoLoaded = true;
  3765. // 初始化视频更新时间
  3766. this.lastVideoUpdateTime = Date.now();
  3767. // 延迟一下确保数据已加载
  3768. setTimeout(() => {
  3769. // 只有在流量计算未启动时才启动,避免重复累计
  3770. if (!this.trafficTimer || this.trafficStartTime === 0) {
  3771. this.startTrafficCalculation();
  3772. }
  3773. }, 500);
  3774. }
  3775. },
  3776. setVideoProgress() {
  3777. // 只有录播和回放需要设置进度
  3778. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  3779. return;
  3780. }
  3781. let currentTime = 0;
  3782. if (this.liveItem.liveType === 2) {
  3783. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  3784. const diff = this.getTimeDifferenceInSeconds(this.liveItem.serviceStartTime, true);
  3785. if (diff > this.liveItem.duration) {
  3786. const storedProgress = uni.getStorageSync(this.videoProgressKey) || 0;
  3787. currentTime = storedProgress >= this.liveItem.duration ? 0 : storedProgress || 0;
  3788. this.isPlayback = true;
  3789. this.hasPlayback = true;
  3790. if (this.isPlayback) {
  3791. const hasWatchedKey = `hasWatchedReplay_${this.liveId}`;
  3792. const hasWatched = uni.getStorageSync(hasWatchedKey);
  3793. // 如果回放正在生成中,重置进度从头开始
  3794. if (this.generating) {
  3795. currentTime = 0;
  3796. // 清除存储的进度,确保从头开始
  3797. if (this.videoProgressKey) {
  3798. uni.removeStorageSync(this.videoProgressKey);
  3799. }
  3800. } else if (!hasWatched) {
  3801. // 首次观看且回放已生成完成(isPlayback = true),从0开始
  3802. currentTime = 0;
  3803. // 标记已观看过(只有在回放生成完成且 isPlayback = true 时才设置)
  3804. uni.setStorageSync(hasWatchedKey, true);
  3805. } else {
  3806. // 非首次观看,从存储中获取进度
  3807. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  3808. currentTime = storedProgress || 0;
  3809. }
  3810. }
  3811. } else {
  3812. currentTime = diff % this.liveItem.duration;
  3813. }
  3814. }
  3815. const videoId = `myVideo_${this.liveId}`;
  3816. const videoContext = uni.createVideoContext(videoId, this);
  3817. if (videoContext) {
  3818. videoContext.seek(currentTime);
  3819. }
  3820. },
  3821. onVideoWaiting(e) {
  3822. // console.log('视频等待加载', e);
  3823. if (this.liveItem.liveType == 2) {
  3824. // 录播:只有在流量计算未启动时才启动,避免重复累计
  3825. if (!this.trafficTimer || this.trafficStartTime === 0) {
  3826. this.startTrafficCalculation();
  3827. }
  3828. } else {
  3829. let that = this;
  3830. if (this.trafficInterval) {
  3831. clearInterval(this.trafficInterval);
  3832. this.trafficInterval = null;
  3833. }
  3834. this.trafficInterval = setInterval(function() {
  3835. that.getInternetTraffic();
  3836. }, 10000);
  3837. }
  3838. // 记录等待开始时间
  3839. if (!this.waitingStartTime) {
  3840. this.waitingStartTime = Date.now();
  3841. }
  3842. // 检测是否真的出现黑屏或卡顿(等待超过5秒且视频时间没有更新)
  3843. if (!this.waitingTimer) {
  3844. this.waitingTimer = setTimeout(() => {
  3845. const waitingDuration = Date.now() - this.waitingStartTime;
  3846. const timeSinceLastUpdate = Date.now() - this.lastVideoUpdateTime;
  3847. const now = Date.now();
  3848. const timeSinceLastToast = now - this.lastNetworkUnstableToastTime;
  3849. // 只有在等待超过5秒,且视频时间超过3秒没有更新时,才认为是真正的卡顿/黑屏
  3850. // 并且距离上次提示至少30秒,避免频繁弹出(特别是对于短时长的预告视频)
  3851. if (waitingDuration >= 5000 && timeSinceLastUpdate >= 3000) {
  3852. // 防抖:30秒内只弹出一次提示
  3853. if (timeSinceLastToast >= 30000 || this.lastNetworkUnstableToastTime === 0) {
  3854. this.$refs.customToast.show({
  3855. title: '当前您的网络不稳定',
  3856. duration: 2000
  3857. });
  3858. this.lastNetworkUnstableToastTime = now;
  3859. }
  3860. }
  3861. }, 5000); // 延迟5秒检测
  3862. }
  3863. },
  3864. // 视频时间更新
  3865. onVideoTimeUpdate(e) {
  3866. // 获取当前播放时间
  3867. this.videoCurrentTime = e.detail.currentTime;
  3868. // 更新视频最后更新时间(用于检测是否卡顿)
  3869. this.lastVideoUpdateTime = Date.now();
  3870. // 如果视频在更新,说明没有卡顿,清除等待状态
  3871. if (this.waitingStartTime && this.lastVideoUpdateTime - this.waitingStartTime < 1000) {
  3872. // 视频在1秒内恢复了,清除等待定时器
  3873. if (this.waitingTimer) {
  3874. clearTimeout(this.waitingTimer);
  3875. this.waitingTimer = null;
  3876. }
  3877. this.waitingStartTime = 0;
  3878. }
  3879. // 每隔1秒保存一次进度(避免频繁存储)
  3880. if (Math.floor(this.videoCurrentTime) % 1 === 0) {
  3881. this.saveVideoProgress();
  3882. }
  3883. // 使用服务器时间判断直播是否结束
  3884. const diff = this.getTimeDifferenceInSeconds(this.liveItem.serviceStartTime, true)
  3885. if (diff >= this.liveItem.duration) {
  3886. if (!this.hasPlayback) {
  3887. this.generating = true;
  3888. this.pauseVideo();
  3889. setTimeout(() => {
  3890. this.playVideo();
  3891. this.generating = false;
  3892. this.hasPlayback = true;
  3893. }, 180000);
  3894. this.isEnd = true;
  3895. }
  3896. }
  3897. // 观看时间 ljx
  3898. let currentTime = ''
  3899. const storedProgress = uni.getStorageSync(this.videoProgressKey) || 0;
  3900. currentTime = storedProgress >= this.liveItem.duration ? 0 : storedProgress || 0;
  3901. this.$nextTick(() => {
  3902. const difPlayback = currentTime;
  3903. const totalSeconds = Math.floor(difPlayback);
  3904. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  3905. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  3906. const seconds = this.padZero(totalSeconds % 60);
  3907. this.playbackTime = `${hours}:${minutes}:${seconds}`;
  3908. });
  3909. },
  3910. // 视频暂停
  3911. onVideoPause(e) {
  3912. // 暂停时保存进度
  3913. this.saveVideoProgress();
  3914. // 录播视频自动恢复播放(避免用户误操作导致暂停)
  3915. if (this.liveItem.liveType === 2 && !this.isManualPause) {
  3916. const videoId = `myVideo_${this.liveId}`;
  3917. const videoContext = uni.createVideoContext(videoId, this);
  3918. if (videoContext) {
  3919. // 延迟播放,避免立即触发导致循环
  3920. setTimeout(() => {
  3921. // 再次检查是否应该播放(防止用户手动暂停)
  3922. if (!this.isManualPause && this.liveItem && this.liveItem.liveType === 2) {
  3923. videoContext.play();
  3924. }
  3925. }, 200);
  3926. }
  3927. }
  3928. },
  3929. // 视频播放
  3930. onVideoPlay(e) {
  3931. //console.log("qxj onVideoPlay");
  3932. // 重置手动暂停标志
  3933. this.isManualPause = false;
  3934. // 清除等待定时器
  3935. if (this.waitingTimer) {
  3936. clearTimeout(this.waitingTimer);
  3937. this.waitingTimer = null;
  3938. }
  3939. this.waitingStartTime = 0;
  3940. this.lastVideoUpdateTime = Date.now(); // 更新最后更新时间
  3941. if (this.liveItem.status == 2) {
  3942. //this.startCountdown();
  3943. // 启动观看时长统计
  3944. //this.startWatchDurationTracking();
  3945. }
  3946. if (this.watchTimeTimer) {
  3947. clearInterval(this.watchTimeTimer);
  3948. this.watchTimeTimer = null;
  3949. this.saveWatchTime();
  3950. console.log("视频开始播放")
  3951. }
  3952. },
  3953. // 保存视频进度
  3954. saveVideoProgress() {
  3955. if (this.videoProgressKey) {
  3956. uni.setStorage({
  3957. key: this.videoProgressKey,
  3958. data: this.videoCurrentTime,
  3959. success: () => {},
  3960. fail: (err) => {
  3961. console.error('保存视频进度失败:', err);
  3962. }
  3963. });
  3964. }
  3965. },
  3966. // 点击红包
  3967. onRed() {
  3968. if (!this.liveId) return;
  3969. if (!this.redInfo?.redId) return;
  3970. if (this.redTimer) {
  3971. clearInterval(this.redTimer);
  3972. this.redTimer = null;
  3973. }
  3974. let data = {
  3975. liveId: this.liveId,
  3976. userId: this.userInfo.userId,
  3977. redId: this.redInfo.redId
  3978. };
  3979. liveRed(data).then((res) => {
  3980. this.isShowRed = false;
  3981. this.redCard = res;
  3982. this.isShowRedCard = true;
  3983. },
  3984. (rej) => {}
  3985. );
  3986. },
  3987. //领取优惠券
  3988. onCoupon() {
  3989. if (!this.couponInfo.couponIssueId) return;
  3990. let data = {
  3991. goodsId: this.couponInfo.goodsId,
  3992. couponIssueId: this.couponInfo.couponIssueId,
  3993. liveId: this.liveId
  3994. };
  3995. coupon(data).then((res) => {
  3996. this.isShowCoupon = false;
  3997. if (res.code == 200) {
  3998. uni.showToast({
  3999. title: res.msg,
  4000. icon: 'none'
  4001. });
  4002. } else {
  4003. uni.showToast({
  4004. title: res.msg,
  4005. icon: 'none'
  4006. });
  4007. }
  4008. })
  4009. .catch((rej) => {});
  4010. },
  4011. // 我的中奖名单
  4012. getMyLottery() {
  4013. this.winning = true;
  4014. myLottery()
  4015. .then((res) => {
  4016. if (res.code == 200) {
  4017. // console.log("我的中奖名单", res)
  4018. this.prizeAll = res.data.list || {};
  4019. } else {}
  4020. })
  4021. .catch((rej) => {});
  4022. },
  4023. // 抽奖
  4024. onLottery() {
  4025. if (!this.lotteryInfo) return;
  4026. this.isShowLottery = false
  4027. let data = {
  4028. lotteryId: this.lotteryInfo.lotteryId
  4029. };
  4030. liveLottery(data)
  4031. .then((res) => {
  4032. if (res.code == 200) {
  4033. const resData = res.data || {};
  4034. this.lotteryList = Array.isArray(resData) ? resData : [];
  4035. this.lotteryProducts = Array.isArray(resData.products) ? resData.products : [];
  4036. if (resData.duration) {
  4037. this.isShowLotteryPop = true;
  4038. }
  4039. } else {
  4040. uni.showToast({
  4041. title: res.msg,
  4042. icon: 'none'
  4043. });
  4044. this.lotteryList = [];
  4045. this.lotteryProducts = [];
  4046. }
  4047. })
  4048. .catch((rej) => {
  4049. uni.showToast({
  4050. title: '获取抽奖信息失败',
  4051. icon: 'none'
  4052. });
  4053. // 失败时强制重置为数组
  4054. this.lotteryList = [];
  4055. this.lotteryProducts = [];
  4056. });
  4057. },
  4058. // 参与抽奖
  4059. onClaim() {
  4060. let data = {
  4061. liveId: this.liveId,
  4062. lotteryId: this.lotteryInfo.lotteryId
  4063. };
  4064. claim(data).then(
  4065. (res) => {
  4066. if (res.code == 200) {
  4067. uni.showToast({
  4068. title: res.msg,
  4069. icon: 'none'
  4070. });
  4071. this.isShowLotteryPop = false;
  4072. this.havePrize = true;
  4073. uni.setStorageSync('havePrize', this.havePrize);
  4074. } else {
  4075. uni.showToast({
  4076. title: res.msg,
  4077. icon: 'none'
  4078. });
  4079. }
  4080. },
  4081. (rej) => {}
  4082. );
  4083. },
  4084. confirm() {
  4085. this.isShowPrize = false;
  4086. this.havePrize = false;
  4087. uni.setStorageSync('havePrize', this.havePrize);
  4088. },
  4089. // 商品收藏
  4090. onGoodsCollect(item) {
  4091. if (!item || item.length === 0 || !item.goodsId) {
  4092. return;
  4093. }
  4094. collectGoods(item.goodsId).then(
  4095. (res) => {
  4096. if (res.code == 200) {
  4097. uni.showToast({
  4098. title: res.msg,
  4099. icon: 'none'
  4100. });
  4101. item.isFavorite = !item.isFavorite;
  4102. } else {
  4103. uni.showToast({
  4104. title: res.msg,
  4105. icon: 'none'
  4106. });
  4107. }
  4108. },
  4109. (rej) => {}
  4110. );
  4111. },
  4112. //正在购买
  4113. getliveOrder(item) {
  4114. if (!this.liveId) {
  4115. return;
  4116. }
  4117. liveOrderUser(this.liveId).then(
  4118. (res) => {
  4119. if (res.code == 200) {
  4120. this.orderUser = res;
  4121. } else {
  4122. console.log('获取正在购买用户失败');
  4123. }
  4124. },
  4125. (rej) => {}
  4126. );
  4127. },
  4128. onLiveStateChange(e, liveItem) {
  4129. // 可以根据状态码处理不同的直播状态
  4130. const stateCode = e.detail.code;
  4131. if (e.detail.code == -2301 || e.detail.code == -2302) {
  4132. this.playVideo();
  4133. } else if (e.detail.code == 2004) {
  4134. this.calculateTimeDiff(this.liveItem);
  4135. // 直播:只有在流量计算未启动时才启动,避免重复累计
  4136. if (!this.trafficTimer || this.trafficStartTime === 0) {
  4137. this.startTrafficCalculation();
  4138. }
  4139. }
  4140. // 2001: 已经连接服务器
  4141. // 2002: 已经连接服务器,开始拉流
  4142. // 2003: 网络接收到首个视频数据包(IDR)
  4143. // 2004: 视频播放开始
  4144. // 2005: 视频播放进度
  4145. // 2006: 视频播放结束
  4146. // 2007: 视频播放Loading
  4147. // 2008: 解码器启动
  4148. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  4149. // -2302: 获取加速拉流地址失败
  4150. }, // 直播错误事件
  4151. onLiveError(e, liveItem) {
  4152. this.videoError(e, liveItem);
  4153. console.log('错误');
  4154. },
  4155. // 红包 卡片 抽奖
  4156. getCurrentActivities() {
  4157. if (!this.liveId) return;
  4158. currentActivities(this.liveId).then(
  4159. (res) => {
  4160. if (res.code === 200) {
  4161. // 提取数据(默认空数组/对象避免报错)
  4162. this.redInfo = (Array.isArray(res.red) ? res.red : [])[0] || {};
  4163. this.lotteryInfo = (Array.isArray(res.lottery) ? res.lottery : [])[0] || {};
  4164. this.goodsCard = res.goods || {};
  4165. this.notice = res.topMsg || {};
  4166. this.isShowGoods = this.goodsCard && this.goodsCard.status == 1;
  4167. this.isShowRed = this.redInfo && this.redInfo.redStatus == 1;
  4168. this.isShowLottery = this.lotteryInfo && this.lotteryInfo.lotteryStatus == 1;
  4169. if (this.notice.msg) {
  4170. this.noticeTimer = setInterval(() => {
  4171. const noticeCountdown = this.handleTime(this.notice.endTime, 0);
  4172. if (!noticeCountdown) {
  4173. this.isShowNotice = false;
  4174. clearInterval(this.noticeTimer);
  4175. } else {
  4176. this.isShowNotice = true
  4177. }
  4178. }, 1000);
  4179. }
  4180. // if(this.notice.msg&&this.notice){
  4181. // this.isShowNotice = true
  4182. // }else{
  4183. // this.isShowNotice = false
  4184. // }
  4185. if (this.isShowRed) {
  4186. this.redTimer = setInterval(() => {
  4187. const redCountdown = this.handleTime(this.redInfo.updateTime, this
  4188. .redInfo
  4189. .duration);
  4190. if (!redCountdown) {
  4191. this.isShowRed = false;
  4192. clearInterval(this.redTimer);
  4193. }
  4194. }, 1000);
  4195. }
  4196. // 处理抽奖定时器
  4197. if (this.isShowLottery) {
  4198. this.lotteryTimer = setInterval(() => {
  4199. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  4200. .lotteryInfo.duration);
  4201. }, 1000);
  4202. }
  4203. } else {
  4204. uni.showToast({
  4205. title: res.msg,
  4206. icon: 'none'
  4207. });
  4208. }
  4209. },
  4210. (rej) => {}
  4211. );
  4212. },
  4213. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  4214. calculateTimeDiff(item, type) {
  4215. if (!item.startTime) return;
  4216. // 提取对应场景的时间字符串(直播用startTime,抽奖用updateTime)
  4217. let timeStr = item.startTime;
  4218. // 转换时间格式(适配iOS,将 "-" 替换为 "/")
  4219. const time = new Date(timeStr.replace(/-/g, '/'));
  4220. if (isNaN(time.getTime())) {
  4221. return;
  4222. }
  4223. const now = new Date();
  4224. let diffMs = Math.max(0, now.getTime() - time.getTime());
  4225. // 转换为 时:分:秒(补零处理)
  4226. const totalSeconds = Math.floor(diffMs / 1000);
  4227. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  4228. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  4229. const seconds = this.padZero(totalSeconds % 60);
  4230. this.diffTotalTime = `${hours}:${minutes}:${seconds}`;
  4231. if (type) {
  4232. return `${hours}:${minutes}:${seconds}`;
  4233. }
  4234. },
  4235. // 启动当前直播间的时间差值定时器
  4236. startTimeTimer(item) {
  4237. if (!item) return;
  4238. // 立即计算一次(避免等待1秒才显示)
  4239. const totalTime = this.calculateTimeDiff(item);
  4240. item.timeTimer = setInterval(() => {
  4241. const totalTime = this.calculateTimeDiff(item);
  4242. }, 1000);
  4243. },
  4244. // toggleViewerList() {
  4245. // const now = Date.now();
  4246. // if (now - this.lastClickTime > this.clickDelay) {
  4247. // this.showadd = !this.showadd;
  4248. // if (this.showadd) {
  4249. // this.getliveUser(false); // 加载第一页观众
  4250. // }
  4251. // this.lastClickTime = now;
  4252. // }
  4253. // },
  4254. // 播放视频
  4255. playVideo() {
  4256. if (!this.liveItem) {
  4257. console.log('liveItem 为空,无法播放视频');
  4258. return;
  4259. }
  4260. try {
  4261. // 使用 $nextTick 确保 DOM 已更新
  4262. this.$nextTick(() => {
  4263. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  4264. // 直播流处理
  4265. return;
  4266. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  4267. const videoId = `myVideo_${this.liveId}`;
  4268. this._playVideoWithRetry(videoId, 0);
  4269. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem
  4270. .status == 2) {
  4271. const videoId = `myVideo_${this.liveId}`;
  4272. this._playVideoWithRetry(videoId, 0);
  4273. } else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem
  4274. .status == 4) {
  4275. const videoId = `myVideo_${this.liveId}`;
  4276. this._playVideoWithRetry(videoId, 0);
  4277. }
  4278. });
  4279. } catch (error) {
  4280. console.error('播放视频失败:', error);
  4281. }
  4282. },
  4283. // 带重试的视频播放方法
  4284. _playVideoWithRetry(videoId, retryCount) {
  4285. if (retryCount >= 3) {
  4286. console.error('视频播放失败,已达到最大重试次数');
  4287. uni.showToast({
  4288. title: '视频加载失败,请稍后重试',
  4289. icon: 'none',
  4290. duration: 2000
  4291. });
  4292. return;
  4293. }
  4294. const videoContext = uni.createVideoContext(videoId, this);
  4295. if (!videoContext) {
  4296. // 如果视频上下文不存在,延迟重试
  4297. setTimeout(() => {
  4298. this._playVideoWithRetry(videoId, retryCount + 1);
  4299. }, 300);
  4300. return;
  4301. }
  4302. // 检查视频元素是否存在(使用 uni-app 的方式)
  4303. this.$nextTick(() => {
  4304. const query = uni.createSelectorQuery().in(this);
  4305. query.select(`#${videoId}`).boundingClientRect((data) => {
  4306. if (!data && retryCount < 2) {
  4307. // 视频元素可能还未渲染,延迟重试
  4308. setTimeout(() => {
  4309. this._playVideoWithRetry(videoId, retryCount + 1);
  4310. }, 500);
  4311. return;
  4312. }
  4313. // 尝试播放视频
  4314. try {
  4315. videoContext.play();
  4316. console.log('视频播放成功');
  4317. } catch (error) {
  4318. console.error('调用 play() 失败:', error);
  4319. // 延迟重试
  4320. setTimeout(() => {
  4321. this._playVideoWithRetry(videoId, retryCount + 1);
  4322. }, 500);
  4323. }
  4324. }).exec();
  4325. });
  4326. },
  4327. pauseVideo() {
  4328. if (!this.liveItem) return;
  4329. try {
  4330. if (this.liveItem.status == 1) {
  4331. const videoId = `myVideo_${this.liveId}`;
  4332. const videoContext = uni.createVideoContext(videoId, this);
  4333. if (videoContext) {
  4334. videoContext.pause();
  4335. }
  4336. } else if (this.liveItem.status == 2) {
  4337. if (this.liveItem.liveType === 1) {
  4338. const livePlayerId = `myLivePlayer_${this.liveId}`;
  4339. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  4340. if (livePlayerContext) {
  4341. livePlayerContext.pause();
  4342. }
  4343. } else if (this.liveItem.liveType === 2) {
  4344. const videoId = `myVideo_${this.liveId}`;
  4345. const videoContext = uni.createVideoContext(videoId, this);
  4346. if (videoContext) {
  4347. videoContext.pause();
  4348. }
  4349. }
  4350. }
  4351. } catch (error) {
  4352. console.error('暂停视频失败:', error);
  4353. }
  4354. },
  4355. // 视频错误处理
  4356. videoError(e, liveItem) {
  4357. if (!liveItem || !this.liveId) return;
  4358. // 初始化重试计数
  4359. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  4360. this.videoRetryCounts[liveItem.liveId] = 0;
  4361. }
  4362. // 限制重试次数
  4363. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  4364. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  4365. // 显示错误提示
  4366. uni.showToast({
  4367. title: '视频加载失败,请检查网络',
  4368. icon: 'none',
  4369. duration: 2000
  4370. });
  4371. return;
  4372. }
  4373. this.videoRetryCounts[this.liveId]++;
  4374. // 延迟重试
  4375. setTimeout(() => {
  4376. if (this.liveId === this.liveId) {
  4377. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  4378. this.playVideo();
  4379. }
  4380. }, 2000);
  4381. },
  4382. openViews() {
  4383. // 计算scroll-view高度
  4384. this.$nextTick(() => {
  4385. const query = uni.createSelectorQuery().in(this);
  4386. query
  4387. .select('.view-box')
  4388. .boundingClientRect((data) => {
  4389. if (data) {
  4390. this.scrollHeight = data.height - 80; // 80是标题高度,120是底部高度
  4391. }
  4392. })
  4393. .exec();
  4394. });
  4395. },
  4396. // 滚动到底部触发
  4397. handleScrollToLower() {
  4398. // 清除上一次未执行的定时器,避免重复请求
  4399. if (this.scrollTimer) {
  4400. clearTimeout(this.scrollTimer);
  4401. }
  4402. // 延迟1秒执行接口请求
  4403. this.scrollTimer = setTimeout(() => {
  4404. this.getliveUser(true);
  4405. }, 1000);
  4406. },
  4407. async getMyLiveMsg(liveItem) {
  4408. console.log("不可见了")
  4409. if (!liveItem || !this.liveId) {
  4410. console.error('getLiveMsg 错误:无效的 liveItem');
  4411. return;
  4412. }
  4413. try {
  4414. const res = await myLiveMsg(this.liveId, 30, 1);
  4415. if (res.code == 200) {
  4416. const rows = Array.isArray(res.rows) ? res.rows : [];
  4417. const reversedTalkList = [...rows].reverse();
  4418. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  4419. // 获取历史消息后也滚动到底部
  4420. this.$nextTick(() => {
  4421. this.scrollToBottom();
  4422. });
  4423. } else {
  4424. this.talklist = [];
  4425. }
  4426. } catch (error) {
  4427. this.talklist = [];
  4428. console.error('获取聊天记录失败:', error);
  4429. }
  4430. },
  4431. async getLiveMsg(liveItem) {
  4432. if (!liveItem || !this.liveId) {
  4433. console.error('getLiveMsg 错误:无效的 liveItem');
  4434. return;
  4435. }
  4436. try {
  4437. const res = await liveMsg(this.liveId, 30, 1);
  4438. if (res.code == 200) {
  4439. const rows = Array.isArray(res.rows) ? res.rows : [];
  4440. const reversedTalkList = [...rows].reverse();
  4441. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  4442. // 获取历史消息后也滚动到底部
  4443. this.$nextTick(() => {
  4444. this.scrollToBottom();
  4445. });
  4446. } else {
  4447. this.talklist = [];
  4448. }
  4449. } catch (error) {
  4450. this.talklist = [];
  4451. console.error('获取聊天记录失败:', error);
  4452. }
  4453. },
  4454. //小黄车搜索商品
  4455. handleSearchInput() {
  4456. // 使用防抖优化性能,避免频繁请求
  4457. clearTimeout(this.searchTimer);
  4458. this.searchTimer = setTimeout(() => {
  4459. this.queryCollect();
  4460. }, 500); // 500毫秒延迟
  4461. },
  4462. // 显示购买提示信息
  4463. showPurchaseMessage() {
  4464. // 清除之前的定时器
  4465. if (this.purchasePromptTimer) {
  4466. clearTimeout(this.purchasePromptTimer);
  4467. }
  4468. // 显示提示
  4469. this.showPurchasePrompt = true;
  4470. // 2秒后自动隐藏
  4471. this.purchasePromptTimer = setTimeout(() => {
  4472. this.showPurchasePrompt = false;
  4473. }, 2000);
  4474. },
  4475. //名字超过省略
  4476. truncateString(str, maxLength) {
  4477. if (typeof str !== 'string' || str.length <= maxLength) {
  4478. return str;
  4479. }
  4480. return str.slice(0, maxLength) + '...'; // 截断后加省略号
  4481. },
  4482. // 跳转页面
  4483. navgetTo(url) {
  4484. uni.navigateTo({
  4485. url: url
  4486. });
  4487. },
  4488. // 查询用户积分领取记录
  4489. completionRecords() {
  4490. if (!this.liveId) return;
  4491. const data = {
  4492. liveId: this.liveId
  4493. }
  4494. completionRecords(data).then((res) => {
  4495. if (res.code == 200) {
  4496. const targetData = res.data.find(item => item.liveId == this.liveId);
  4497. if (targetData) {
  4498. // 找到匹配的数据
  4499. const receiveStatus = targetData.receiveStatus;
  4500. this.receiveStatus = true;
  4501. } else {
  4502. console.log('未找到liveId为', this.liveId, '的数据');
  4503. this.receiveStatus = false; // 或其他默认值
  4504. }
  4505. console.log("查询用户积分领取记录", res)
  4506. }
  4507. }).catch((error) => {
  4508. });
  4509. },
  4510. // 修改获取直播信息方法
  4511. async getliving(liveId) {
  4512. if (!liveId) return;
  4513. // 防止重复请求
  4514. if (this.isLoadingLiveInfo) {
  4515. console.log('正在加载直播间信息,跳过重复请求');
  4516. return;
  4517. }
  4518. this.isLoadingLiveInfo = true;
  4519. const param = {
  4520. id: liveId
  4521. };
  4522. try {
  4523. const res = await getlive(param);
  4524. this.isLoadingLiveInfo = false;
  4525. if (res.code !== 200) {
  4526. uni.showToast({
  4527. title: res.msg,
  4528. icon: 'none'
  4529. });
  4530. return;
  4531. }
  4532. this.liveItem = Object.assign({}, this.liveItem, res.data);
  4533. if(this.liveItem != null && this.liveItem.idDel != null && 1 == this.liveItem.idDel){
  4534. uni.showToast({
  4535. title: '直播间已删除',
  4536. icon: 'none'
  4537. });
  4538. return;
  4539. }
  4540. // 保存服务器时间对应的本地时间,用于计算服务器时间差值
  4541. if (res.serviceTime) {
  4542. this.liveItem._localTimeWhenReceived = Date.now();
  4543. this.$set(this.liveItem, 'serviceTime', res.serviceTime);
  4544. }
  4545. if (res.serviceStartTime) {
  4546. this.$set(this.liveItem, 'serviceStartTime', res.serviceStartTime);
  4547. }
  4548. if (res.data.globalVisible || res.data.singleVisible) {
  4549. this.myselfFlag = true;
  4550. }
  4551. //this.talklist = Array.isArray((res.data || {}).talklist) ? res.data.talklist : [];
  4552. //this.startTimeTimer(this.liveItem);
  4553. // 清除旧定时器(如预告倒计时)
  4554. if (this.liveStartTimer) {
  4555. clearInterval(this.liveStartTimer);
  4556. this.liveStartTimer = null;
  4557. }
  4558. if (res.data.status == 1) {
  4559. // 直播预告
  4560. this.liveStartTimer = setInterval(async () => {
  4561. this.liveCountdown = this.handleTime(res.data.startTime, 0);
  4562. if (!this.liveCountdown) {
  4563. uni.removeStorageSync('isAgreement');
  4564. await this.getliving(this.liveId);
  4565. clearInterval(this.liveStartTimer);
  4566. }
  4567. }, 1000);
  4568. this.$set(this.liveItem, 'previewUrl', res.data.previewUrl);
  4569. this.$set(this.liveItem, 'livingUrl', ''); // 清空直播流
  4570. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  4571. } else if (res.data.status == 2) {
  4572. if (res.data.liveType == 1) { // 直播流
  4573. let cTime = Math.floor(Math.random() * 10000) + 1;
  4574. let livingUrl = res.data.flvHlsUrl + '&t=' + cTime;
  4575. console.log('地址在', this.liveItem.livingUrl);
  4576. this.$set(this.liveItem, 'livingUrl', livingUrl);
  4577. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  4578. } else if (res.data.liveType === 2) {
  4579. // 回放视频 2录播 3直播回放
  4580. // let urlStr = 'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/10%E6%9C%8820%E6%97%A5%20%281%29.m3u8'
  4581. // this.$set(this.liveItem, 'videoUrl', urlStr);
  4582. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  4583. this.$set(this.liveItem, 'livingUrl', '');
  4584. }
  4585. } else if (res.data.status == 4 && res.data.liveType == 3) {
  4586. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  4587. this.$set(this.liveItem, 'livingUrl', '');
  4588. } else {
  4589. // 未开播
  4590. this.$set(this.liveItem, 'livingUrl', '');
  4591. this.$set(this.liveItem, 'videoUrl', '');
  4592. }
  4593. if (this.liveItem.configJson) {
  4594. this.completionRate = JSON.parse(this.liveItem.configJson).completionRate * 0.01
  4595. }
  4596. console.log("查询当前用户当前直播间领取积分的剩余时长", this.liveId)
  4597. if (this.liveItem.completionPointsEnabled) {
  4598. this.getRemainingTime(); //查询当前用户当前直播间领取积分的剩余时长
  4599. }
  4600. this.$set(this.liveItem, 'autoplay', res.data.liveType !== 0);
  4601. this.$set(this.liveItem, 'showType', res.data.showType);
  4602. this.storeId = res.storeId;
  4603. console.log("qxj living", this.liveItem);
  4604. // 使用服务器时间计算时间差,确保设备时间不一致时也能正确判断
  4605. this.diffLiveStartTime = this.calculateLiveTimeDiff(this.liveItem.serviceStartTime, true);
  4606. if (this.diffLiveStartTime < 0) { //预告
  4607. this.isPreview = true;
  4608. this.liveBeginWatchTime = this.getServerTimeNow();
  4609. } else {
  4610. // 直播已开始(基于服务器时间),确保 isPreview 为 false
  4611. this.isPreview = false;
  4612. if (!this.hasLiveEnd) { //没经历过直播结束
  4613. this.liveBeginWatchTime = this.getServerTimeNow();
  4614. }
  4615. }
  4616. this.getliveViewData();
  4617. this.completionRecords();
  4618. // 初始化观看时间统计
  4619. this.initWatchTime();
  4620. const diff = this.calculateLiveTimeDiff(this.liveItem.serviceStartTime, true)
  4621. if (diff >= this.liveItem.duration) {
  4622. const diffTime = diff - this.liveItem.duration
  4623. if (diffTime < 180) {
  4624. this.generating = true;
  4625. this.pauseWatchDurationTracking()
  4626. // 计算剩余等待时间
  4627. const remainingTime = Math.max(0, 180 - diffTime) * 1000;
  4628. if (this.generatingTimer) {
  4629. clearTimeout(this.generatingTimer);
  4630. }
  4631. this.generatingTimer = setTimeout(() => {
  4632. this.generating = false;
  4633. this.hasPlayback = true;
  4634. this.playVideo();
  4635. // this.closeWebSocket(true);
  4636. this.isEnd = true;
  4637. }, remainingTime);
  4638. } else {
  4639. // 已经超过18秒,应该直接播放
  4640. this.generating = false;
  4641. this.hasPlayback = true;
  4642. this.playVideo();
  4643. this.resumeWatchDurationTracking()
  4644. // this.closeWebSocket(true);
  4645. this.isEnd = true;
  4646. }
  4647. } else {
  4648. // 直播还未结束,正常播放
  4649. this.playVideo();
  4650. }
  4651. // 确保在获取直播信息后启动倒计时,使用服务器时间正确判断状态
  4652. this.$nextTick(() => {
  4653. if (this.liveItem.completionPointsEnabled) {
  4654. this.startCountdown();
  4655. }
  4656. });
  4657. } catch (err) {
  4658. this.isLoadingLiveInfo = false;
  4659. console.error('获取直播信息失败:', err);
  4660. uni.showToast({
  4661. title: '获取直播信息失败',
  4662. icon: 'none'
  4663. });
  4664. }
  4665. },
  4666. getPureDecimal(num, precision = 6) {
  4667. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  4668. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  4669. },
  4670. goBack() {
  4671. // 暂停当前视频
  4672. if (this.liveItem) {
  4673. this.pauseVideo();
  4674. }
  4675. // 关闭WebSocket连接
  4676. this.closeWebSocket(true);
  4677. // 导航返回
  4678. // const pages = getCurrentPages();
  4679. // if (pages.length > 1) {
  4680. // uni.navigateBack();
  4681. // } else {
  4682. // uni.reLaunch({
  4683. // url: '/pages_course/livingList'
  4684. // });
  4685. // }
  4686. const pages = getCurrentPages();
  4687. uni.reLaunch({
  4688. url: '/pages/home/index'
  4689. });
  4690. },
  4691. // 点赞
  4692. async onLike() {
  4693. if (!this.liveId) return;
  4694. try {
  4695. const res = await liveDataLike(this.liveId);
  4696. if (res?.like) {
  4697. this.liveViewData.like++; //只更新当前直播间的点赞数
  4698. } else {
  4699. uni.showToast({
  4700. title: res.msg,
  4701. icon: 'none'
  4702. });
  4703. }
  4704. } catch (error) {
  4705. console.error('点赞失败:', error);
  4706. }
  4707. },
  4708. //直播间点赞、关注、在线人数数据
  4709. getliveViewData() {
  4710. if (!this.liveId) return;
  4711. // 使用 Promise 包装,支持 await
  4712. return getLiveViewData(this.liveId).then((res) => {
  4713. if (res.code == 200) {
  4714. // 强制响应式更新,确保数据实时显示
  4715. this.liveViewData = res;
  4716. }
  4717. return res;
  4718. }).catch((error) => {
  4719. console.error('获取直播间数据失败:', error);
  4720. // 失败时兜底,避免显示异常
  4721. this.liveViewData = {
  4722. like: 0,
  4723. watchCount: 0
  4724. };
  4725. throw error;
  4726. });
  4727. },
  4728. // 30秒刷新一下直播间点赞数
  4729. // startLiveViewDataTimer() {
  4730. // // 先清除旧定时器(防止重复创建)
  4731. // if (this.liveViewDataTimer) {
  4732. // clearInterval(this.liveViewDataTimer);
  4733. // this.liveViewDataTimer = null;
  4734. // }
  4735. // this.getliveViewData();
  4736. // this.liveViewDataTimer = setInterval(() => {
  4737. // // 安全校验:确保liveItem和liveId存在(避免无效请求)
  4738. // if (this.liveId) {
  4739. // this.getliveViewData();
  4740. // }
  4741. // }, 20000);
  4742. // },
  4743. // 去购买,跳商品详情
  4744. async goShop(productId, goodsId) {
  4745. if (!this.liveId) return;
  4746. // 生成唯一key,用于标识正在处理的商品
  4747. const key = `${productId}_${goodsId}`;
  4748. // 防止重复点击:如果该商品正在处理中,直接返回
  4749. if (this.goShoppingMap[key]) {
  4750. console.log('该商品正在处理中,请勿重复点击');
  4751. return;
  4752. }
  4753. // 标记该商品正在处理中
  4754. this.$set(this.goShoppingMap, key, true);
  4755. try {
  4756. // 检查限购(跳转商品详情时,默认检查数量1)
  4757. const res = await checkPurchaseLimit({
  4758. productId: productId,
  4759. num: 1
  4760. });
  4761. if (res.code !== 200) {
  4762. this.$refs.customToast.show({
  4763. title: res.msg || '该商品限购,目前剩余可购买数量不足',
  4764. duration: 2000
  4765. });
  4766. // uni.showToast({
  4767. // icon: 'none',
  4768. // title: res.msg || '该商品限购,目前剩余可购买数量不足'
  4769. // });
  4770. return;
  4771. }
  4772. // 限购检查通过,进行跳转
  4773. uni.navigateTo({
  4774. url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' +
  4775. this.liveId +
  4776. '&goodsId=' + goodsId + '&storeId=' + this.storeId
  4777. });
  4778. } catch (error) {
  4779. console.error('检查限购失败:', error);
  4780. uni.showToast({
  4781. icon: 'none',
  4782. title: '检查限购失败,请稍后重试'
  4783. });
  4784. } finally {
  4785. // 延迟清除标志位,防止用户在跳转前再次点击(延迟500ms)
  4786. setTimeout(() => {
  4787. this.$delete(this.goShoppingMap, key);
  4788. }, 500);
  4789. }
  4790. },
  4791. // 查询店铺
  4792. async queryCollect() {
  4793. this.loadingProducts = true;
  4794. if (!this.liveId) return;
  4795. if (this.inputInfo == null) this.inputInfo = '';
  4796. uni.showLoading({
  4797. title: '加载中'
  4798. });
  4799. try {
  4800. const res = await liveStore(this.liveId, this.inputInfo);
  4801. uni.hideLoading();
  4802. this.shopping = true;
  4803. if (res.code === 200) {
  4804. // 数据绑定到当前 liveItem,避免全局污染
  4805. this.products = Array.isArray(res.data) ? res.data : [];
  4806. }
  4807. } catch (error) {
  4808. console.error('获取小黄车商品失败:', error);
  4809. } finally {
  4810. this.loadingProducts = false;
  4811. }
  4812. },
  4813. // 时间戳
  4814. initTime() {
  4815. const now = new Date();
  4816. this.timestamp = now.getTime();
  4817. },
  4818. openCart() {
  4819. this.queryCollect();
  4820. },
  4821. close() {
  4822. this.showadd = false;
  4823. },
  4824. // 关闭小黄车
  4825. closeShop() {
  4826. this.shopping = false;
  4827. },
  4828. closeMore() {
  4829. this.isMore = false;
  4830. },
  4831. closeWin() {
  4832. this.winning = false;
  4833. },
  4834. // 关闭WebSocket连接(isManual:是否手动关闭)
  4835. closeWebSocket(isManual = true) {
  4836. if (!this.socket || !this.isSocketOpen) {
  4837. // console.warn('WebSocket 任务不存在或未打开,无需关闭');
  4838. return;
  4839. }
  4840. console.log(`WebSocket连接关闭 - ${isManual ? '手动' : '自动'}`);
  4841. this.isManualClose = isManual;
  4842. // 清理所有定时器和状态
  4843. this.cleanupAllResources();
  4844. try {
  4845. // 先保存引用,避免在关闭过程中被置为null
  4846. const socketToClose = this.socket;
  4847. this.socket = null;
  4848. this.isSocketOpen = false;
  4849. this.isConnecting = false;
  4850. socketToClose.close({
  4851. code: 1000,
  4852. reason: isManual ? '主动关闭' : '异常关闭'
  4853. });
  4854. console.log('WebSocket连接已发起关闭');
  4855. } catch (err) {
  4856. console.error('关闭WebSocket失败:', err);
  4857. // 即使关闭失败,也要重置状态
  4858. this.socket = null;
  4859. this.isSocketOpen = false;
  4860. this.isConnecting = false;
  4861. }
  4862. },
  4863. // 清理所有资源
  4864. cleanupAllResources() {
  4865. // 停止心跳相关
  4866. this.stopHeartBeat();
  4867. // 清理ping超时定时器
  4868. if (this.pingTimeoutTimer) {
  4869. clearTimeout(this.pingTimeoutTimer);
  4870. this.pingTimeoutTimer = null;
  4871. }
  4872. // 清理网络状态定时器
  4873. if (this.networkStatusTimer) {
  4874. clearTimeout(this.networkStatusTimer);
  4875. this.networkStatusTimer = null;
  4876. }
  4877. // 重置重连状态
  4878. this.resetReconnectState();
  4879. // 重置心跳相关状态
  4880. this.heartBeatRetryCount = 0;
  4881. this.lastHeartBeatTime = 0;
  4882. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  4883. },
  4884. startHeartBeat() {
  4885. this.stopHeartBeat(); // 先停止现有心跳,防止重复
  4886. // 使用自适应间隔循环发送心跳
  4887. this.heartBeatTimer = setInterval(() => {
  4888. this.sendHeartBeat();
  4889. }, this.adaptiveHeartBeatInterval);
  4890. },
  4891. initSocket() {
  4892. // 检查是否正在连接中
  4893. if (this.isConnecting) {
  4894. console.log('WebSocket正在连接中,跳过重复连接');
  4895. return;
  4896. }
  4897. // 检查网络状态
  4898. if (!this.isNetworkAvailable) {
  4899. console.warn('网络不可用,延迟WebSocket连接');
  4900. // 使用定时器而不是递归调用,避免内存泄漏
  4901. if (!this.networkRetryTimer) {
  4902. this.networkRetryTimer = setTimeout(() => {
  4903. this.networkRetryTimer = null;
  4904. this.initSocket();
  4905. }, 3000);
  4906. }
  4907. return;
  4908. }
  4909. // 如果已经存在连接且状态为open,则退出
  4910. if (this.socket && this.socket.readyState === 1) {
  4911. console.log('WebSocket连接已存在且正常,无需重新连接');
  4912. // 重置重连计数
  4913. this.reconnectCount = 0;
  4914. return;
  4915. }
  4916. // 关闭现有连接
  4917. if (this.socket && (this.socket.readyState === 0 || this.socket.readyState ===
  4918. 1)) {
  4919. console.log('关闭现有WebSocket连接,创建新连接');
  4920. this.closeWebSocket(false); // 非手动关闭
  4921. // 等待一小段时间确保连接完全关闭
  4922. setTimeout(() => {
  4923. this.createWebSocketConnection();
  4924. }, 100);
  4925. return;
  4926. }
  4927. this.createWebSocketConnection();
  4928. },
  4929. createWebSocketConnection() {
  4930. // 校验必要参数
  4931. if (!this.liveId) {
  4932. console.error('缺失直播间ID,无法初始化WebSocket');
  4933. return;
  4934. }
  4935. if (!this.userInfo || !this.userInfo.userId) {
  4936. console.error('用户信息缺失,无法初始化WebSocket');
  4937. return;
  4938. }
  4939. // 设置连接状态
  4940. this.isConnecting = true;
  4941. this.isSocketOpen = false;
  4942. // 记录连接开始时间(性能监控)
  4943. this.connectionStartTime = Date.now();
  4944. // 清除之前的重连定时器
  4945. this.resetReconnectState();
  4946. const now = new Date();
  4947. this.timestamp = now.getTime(); // 生成签名
  4948. const signature = CryptoJS.HmacSHA256(
  4949. `${this.liveId}${this.userInfo.userId}${this.userType}${this.timestamp}`,
  4950. this.timestamp.toString()
  4951. ).toString(CryptoJS.enc.Hex);
  4952. try {
  4953. const baseWsUrl = 'wss://ws.klbycp.com/ws/app/webSocket';
  4954. // const baseWsUrl = 'wss://api.fhhx.runtzh.com/ws/app/webSocket';
  4955. // const baseWsUrl = 'ws://d6998672.natappfree.cc/ws/app/webSocket';
  4956. // const baseWsUrl = 'ws://nd967d83.natappfree.cc/ws/app/webSocket';
  4957. let wsUrl =
  4958. `${baseWsUrl}?userId=${this.userInfo.userId}&liveId=${this.liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`;
  4959. // let wsUrl =
  4960. // 'ws://q96d9752.natappfree.cc/ws/app/webSocket?liveId=128&userId=9769&userType=1&timestamp=1762501143712&signature=0498c66c3fca64ab009586200c04d51312ce44e36d5639e99b22e34f3bac8d13';
  4961. if (this.qrFrom) {
  4962. wsUrl += this.qrFrom;
  4963. }
  4964. if (this.urlOption.qwUserId) {
  4965. wsUrl += `&qwUserId=${this.urlOption.qwUserId}`;
  4966. }
  4967. if (this.urlOption.qwExternalId) {
  4968. wsUrl += `&externalContactId=${this.urlOption.qwExternalId}`;
  4969. }
  4970. // if(this.address){
  4971. // console.log("this.address是什么>>>", this.address)
  4972. wsUrl += `&location=${this.address}`;
  4973. // wsUrl += `&location=${encodeURIComponent(liveWatchUser)}`;
  4974. // }
  4975. console.log("qxj wsUrl", wsUrl);
  4976. console.log(
  4977. `尝试连接WebSocket: ${wsUrl.replace(/signature=[^&]+/, 'signature=***')}`
  4978. );
  4979. const socketTask = uni.connectSocket({
  4980. url: wsUrl,
  4981. success: () => {
  4982. console.log("WebSocket连接请求发送成功");
  4983. },
  4984. fail: (err) => {
  4985. console.error('WebSocket连接请求失败:', err);
  4986. this.isConnecting = false;
  4987. this.handleConnectionError('连接请求失败', err);
  4988. }
  4989. });
  4990. // 连接打开事件
  4991. socketTask.onOpen((res) => {
  4992. console.log("WebSocket连接已打开");
  4993. this.socket = socketTask;
  4994. this.isConnecting = false;
  4995. this.isSocketOpen = true;
  4996. // 计算连接延迟(性能监控)
  4997. if (this.connectionStartTime > 0) {
  4998. this.connectionLatency = Date.now() - this
  4999. .connectionStartTime;
  5000. console.log(`WebSocket连接延迟: ${this.connectionLatency}ms`);
  5001. }
  5002. this.reconnectCount = 0;
  5003. this.resetReconnectState();
  5004. this.heartBeatRetryCount = 0; // 重置心跳重试次数
  5005. this.shownEntryUsers.clear(); // 重连后重置进入提示记录
  5006. // 连接成功后显示提示(仅首次连接)
  5007. if (this.reconnectCount === 0) {
  5008. console.log('WebSocket连接建立成功');
  5009. } else {
  5010. console.log(`WebSocket重连成功(第${this.reconnectCount}次尝试)`);
  5011. }
  5012. this.startHeartBeat();
  5013. // 启动观看时长统计
  5014. //this.startWatchDurationTracking();
  5015. });
  5016. // 消息接收事件
  5017. socketTask.onMessage((res) => {
  5018. // 消息计数(性能监控)
  5019. this.messageCount++;
  5020. try {
  5021. //console.log("qxj onMessage handleSocketMessage",res);
  5022. const data = JSON.parse(res.data);
  5023. // 处理服务端心跳响应 - 修复:后端返回的是heartBeat而不是heartBeatAck
  5024. if (!!data.data && data.data.cmd === 'heartbeat') {
  5025. // console.log('收到心跳响应:', data.data);
  5026. // 清除ping超时定时器
  5027. if (this.pingTimeoutTimer) {
  5028. clearTimeout(this.pingTimeoutTimer);
  5029. this.pingTimeoutTimer = null;
  5030. }
  5031. // 重置心跳重试次数
  5032. this.heartBeatRetryCount = 0;
  5033. // 更新网络状态为良好
  5034. this.adjustHeartBeatInterval(true);
  5035. return;
  5036. }
  5037. this.handleSocketMessage(res);
  5038. } catch (err) {
  5039. console.error('消息解析异常:', err);
  5040. this.errorCount++; // 错误计数
  5041. }
  5042. });
  5043. // 连接错误事件
  5044. socketTask.onError((err) => {
  5045. console.error('WebSocket连接错误:', err);
  5046. this.errorCount++; // 错误计数
  5047. this.isSocketOpen = false;
  5048. this.isConnecting = false;
  5049. this.stopHeartBeat();
  5050. this.handleConnectionError('连接错误', err);
  5051. });
  5052. // 连接关闭事件
  5053. socketTask.onClose((res) => {
  5054. console.log('WebSocket连接关闭:', res);
  5055. this.isSocketOpen = false;
  5056. this.isConnecting = false;
  5057. this.stopHeartBeat(); // 清除心跳定时器
  5058. // 暂停观看时长统计
  5059. this.pauseWatchDurationTracking();
  5060. // 根据关闭原因决定是否重连
  5061. if (!this.isManualClose) {
  5062. if (res.code === 1000) {
  5063. console.log('WebSocket正常关闭,不进行重连');
  5064. } else {
  5065. console.warn(
  5066. `WebSocket异常关闭 (code: ${res.code}, reason: ${res.reason})`
  5067. );
  5068. this.handleReconnect();
  5069. }
  5070. } else {
  5071. console.log('WebSocket手动关闭,不进行重连');
  5072. }
  5073. });
  5074. } catch (e) {
  5075. console.error('创建WebSocket异常:', e);
  5076. this.handleReconnect();
  5077. }
  5078. },
  5079. handleTime(time, duration) {
  5080. let timeStamp;
  5081. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  5082. timeStamp = time;
  5083. } else if (typeof time === 'string' && time.trim() !== '') {
  5084. // 手动解析 CST 时间字符串
  5085. const match = time.match(
  5086. /^(\w{3}) (\w{3}) (\d{1,2}) (\d{1,2}):(\d{2}):(\d{2}) CST (\d{4})$/
  5087. );
  5088. if (match) {
  5089. const [, day, month, date, hours, minutes, seconds, year] = match;
  5090. // 月份映射
  5091. const monthMap = {
  5092. 'Jan': 0,
  5093. 'Feb': 1,
  5094. 'Mar': 2,
  5095. 'Apr': 3,
  5096. 'May': 4,
  5097. 'Jun': 5,
  5098. 'Jul': 6,
  5099. 'Aug': 7,
  5100. 'Sep': 8,
  5101. 'Oct': 9,
  5102. 'Nov': 10,
  5103. 'Dec': 11
  5104. };
  5105. // 创建日期对象(CST 是 UTC+8,与中国时区一致)
  5106. const jsDate = new Date(
  5107. parseInt(year),
  5108. monthMap[month],
  5109. parseInt(date),
  5110. parseInt(hours),
  5111. parseInt(minutes),
  5112. parseInt(seconds)
  5113. );
  5114. timeStamp = jsDate.getTime();
  5115. } else {
  5116. // 如果不是预期格式,回退到普通解析
  5117. const date = new Date(time);
  5118. if (!isNaN(date.getTime())) {
  5119. timeStamp = date.getTime();
  5120. } else {
  5121. console.error('无效的日期格式:', time);
  5122. return false;
  5123. }
  5124. }
  5125. } else {
  5126. console.error('time参数必须是有效的时间戳(数字)或日期字符串');
  5127. return false;
  5128. }
  5129. const targetTimestamp = timeStamp + duration * 60 * 1000;
  5130. const currentTimestamp = this.getServerTimeNow();
  5131. const timeDiffMs = targetTimestamp - currentTimestamp;
  5132. if (timeDiffMs <= 0) {
  5133. return false;
  5134. }
  5135. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  5136. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  5137. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  5138. const formatNum = (num) => num.toString().padStart(2, '0');
  5139. return {
  5140. hours: formatNum(hours),
  5141. minutes: formatNum(minutes),
  5142. seconds: formatNum(seconds)
  5143. };
  5144. },
  5145. // 限制聊天消息数量,防止内存泄漏
  5146. addToTalkList(message) {
  5147. // console.log("修改后的message>>", message)
  5148. // 减少最大消息数量,提升iPhone性能
  5149. const MAX_TALK_ITEMS = 30;
  5150. // 直接操作数组,避免创建新数组
  5151. if (!Array.isArray(this.talklist)) {
  5152. this.talklist = [];
  5153. }
  5154. const wasAtLimit = this.talklist.length >= MAX_TALK_ITEMS;
  5155. //console.log(`添加消息前: 当前消息数量=${this.talklist.length}, 是否达到限制=${wasAtLimit}`);
  5156. // 检查是否是自己发送的消息
  5157. const isMyMessage = message.userId === this.userInfo.userId;
  5158. //console.log(`消息来源: ${isMyMessage ? '自己' : '他人'}, userId=${message.userId}`);
  5159. // 给消息添加唯一ID
  5160. message.uniqueId = ++this.messageIdCounter;
  5161. let msgdata = JSON.parse(message.data);
  5162. message.msgId = msgdata.msgId;
  5163. this.talklist.push(message);
  5164. // 当消息超过限制时,批量删除旧消息
  5165. if (this.talklist.length > MAX_TALK_ITEMS) {
  5166. const removeCount = this.talklist.length - MAX_TALK_ITEMS;
  5167. //console.log(`消息超过限制,删除前${removeCount}条旧消息`);
  5168. this.talklist.splice(0, removeCount);
  5169. }
  5170. //console.log(`添加消息后: 当前消息数量=${this.talklist.length}`);
  5171. // 强制触发视图更新
  5172. this.$forceUpdate();
  5173. // 使用单次nextTick确保DOM更新后再滚动
  5174. // iOS 需要更长的延迟来确保 DOM 完全渲染
  5175. if (this.isIOS) {
  5176. this.$nextTick(() => {
  5177. // iOS 上需要额外延迟,确保消息元素完全渲染
  5178. setTimeout(() => {
  5179. this.forceScrollToBottomOnSend();
  5180. }, 100);
  5181. });
  5182. } else {
  5183. this.$nextTick(() => {
  5184. this.forceScrollToBottomOnSend();
  5185. });
  5186. }
  5187. },
  5188. // 处理Socket消息
  5189. async handleSocketMessage(message) {
  5190. try {
  5191. let data = JSON.parse(message.data);
  5192. const socketMessage = data.data; // 服务端返回的消息体
  5193. //console.log("qxj handleSocketMessage socketMessage",socketMessage);
  5194. if (data.code == 200) {
  5195. const messageData = {
  5196. ...socketMessage,
  5197. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  5198. ts: Date.now() // 时间戳
  5199. };
  5200. // 处理服务端返回的sendMsg消息,加入本地列表
  5201. if (socketMessage.cmd == 'sendMsg') {
  5202. if (!this.isSocketAvailable()) {
  5203. uni.showToast({
  5204. title: '连接已断开,正在重试...',
  5205. icon: 'none'
  5206. });
  5207. this.handleReconnect();
  5208. return;
  5209. }
  5210. this.addToTalkList(messageData);
  5211. } else if (socketMessage.cmd == 'red') {
  5212. const redData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  5213. this.redInfo = redData || {};
  5214. this.isShowRed = socketMessage.status === 1;
  5215. if (this.isShowRed) {
  5216. this.redTimer = setInterval(() => {
  5217. const redCountdown = this.handleTime(this
  5218. .redInfo.updateTime, this.redInfo
  5219. .duration);
  5220. if (!redCountdown) {
  5221. this.isShowRed = false;
  5222. clearInterval(this.redTimer);
  5223. }
  5224. }, 1000);
  5225. }
  5226. } else if (socketMessage.cmd == 'goods') {
  5227. const goodsData = socketMessage.data ? JSON.parse(socketMessage
  5228. .data) : {};
  5229. this.goodsCard = goodsData || {};
  5230. this.isShowGoods = socketMessage.status == 1;
  5231. } else if (socketMessage.cmd == 'coupon') {
  5232. const couponData = socketMessage.data ? JSON.parse(
  5233. socketMessage.data) : {};
  5234. this.couponInfo = couponData || {};
  5235. this.isShowCoupon = socketMessage.status === 1;
  5236. if (this.isShowCoupon) {}
  5237. } else if (socketMessage.cmd == 'likeDetail') {
  5238. this.liveViewData.like = Number(socketMessage.data);
  5239. } else if (socketMessage.cmd == 'lottery') {
  5240. const lotteryData = socketMessage.data ? JSON.parse(
  5241. socketMessage.data) : {};
  5242. this.lotteryInfo = lotteryData || {};
  5243. this.isShowLottery = socketMessage.status === 1;
  5244. if (socketMessage.status != 1) {
  5245. this.isShowLotteryPop = false;
  5246. }
  5247. // 清除已有定时器(无论状态是否为1,先清掉旧的)
  5248. clearInterval(this.lotteryTimer);
  5249. if (this.isShowLottery) {
  5250. this.lotteryTimer = setInterval(() => {
  5251. this.countdown = this.handleTime(this
  5252. .lotteryInfo.updateTime, this
  5253. .lotteryInfo.duration);
  5254. if (!this.countdown) {
  5255. console.log('倒计时', this.countdown);
  5256. this.isShowLottery = false;
  5257. this.isShowLotteryPop = false;
  5258. clearInterval(this.lotteryTimer);
  5259. }
  5260. }, 1000);
  5261. } else {
  5262. this.isShowLottery = false;
  5263. }
  5264. } else if (socketMessage.cmd == 'globalVisible' || socketMessage
  5265. .cmd == 'singleVisible') {
  5266. // status = 1的时候,用户消息自可见,其他消息丢失}
  5267. if (socketMessage.status == 1) {
  5268. this.myselfFlag = true;
  5269. } else {
  5270. this.myselfFlag = false;
  5271. }
  5272. } else if (socketMessage.cmd == 'sendPopMsg') {
  5273. this.popMsg = socketMessage.msg
  5274. this.isShowPopMsg = true
  5275. } else if (socketMessage.cmd == 'sendTopMsg') {
  5276. clearInterval(this.noticeTimer);
  5277. const noticeData = socketMessage.data ? JSON.parse(
  5278. socketMessage.data) : {};
  5279. this.notice = noticeData || {};
  5280. this.isShowNotice = true
  5281. if (this.isShowNotice) {
  5282. this.noticeTimer = setInterval(() => {
  5283. const noticeCountdown = this.handleTime(this
  5284. .notice.endTime, 0);
  5285. if (!noticeCountdown) {
  5286. this.isShowNotice = false;
  5287. clearInterval(this.noticeTimer);
  5288. }
  5289. }, 1000);
  5290. }
  5291. } else if (socketMessage.cmd == 'entry') {
  5292. try {
  5293. if (!this.liveUserCalled) {
  5294. this.liveUserCalled = true;
  5295. }
  5296. const userIdToEntry = socketMessage.userId;
  5297. const existingIndex = this.liveViewersData.findIndex((
  5298. item) => item.userId ===
  5299. userIdToEntry);
  5300. if (existingIndex === -1) {
  5301. const liveViewers = {
  5302. userId: socketMessage.userId,
  5303. nickName: socketMessage.nickName,
  5304. avatar: socketMessage.avatar
  5305. };
  5306. this.liveViewersData.push(liveViewers);
  5307. this.liveUserTotal++;
  5308. }
  5309. // 解析用户ID(根据实际接口字段调整,此处假设data含userId)
  5310. const userInfo = JSON.parse(socketMessage.data || '{}');
  5311. const userId = userInfo.userId || socketMessage
  5312. .userId; // 兼容不同字段
  5313. if (!userId) return; // 无用户ID不处理
  5314. // 仅新用户(未显示过)才触发提示
  5315. if (!this.shownEntryUsers.has(userId)) {
  5316. this.inAndOut = socketMessage;
  5317. this.showWelcomeMessage = true;
  5318. this.shownEntryUsers.add(userId); // 加入已显示集合
  5319. messageData.msg = '来了'
  5320. this.addToTalkList(messageData);
  5321. // 3秒后隐藏提示(可调整时长)
  5322. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  5323. this.welcomeTimer = setTimeout(() => {
  5324. this.showWelcomeMessage = false;
  5325. }, 3000);
  5326. }
  5327. } catch (err) {
  5328. console.error('解析entry用户数据失败:', err);
  5329. }
  5330. } else if (socketMessage.cmd == 'out') {
  5331. if (this.liveUserTotal > 0) {
  5332. const userIdToRemove = socketMessage.userId;
  5333. const index = this.liveViewersData.findIndex((item) => item
  5334. .userId === userIdToRemove);
  5335. if (index !== -1) {
  5336. this.liveViewersData.splice(index, 1);
  5337. this.liveUserTotal--; // 根据userId删除对应的用户数据
  5338. }
  5339. }
  5340. this.inAndOut = socketMessage;
  5341. this.showWelcomeMessage = true;
  5342. // 3秒后隐藏提示
  5343. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  5344. this.welcomeTimer = setTimeout(() => {
  5345. this.showWelcomeMessage = false;
  5346. }, 3000);
  5347. } else if (socketMessage.cmd == 'live_start' || socketMessage.cmd == 'live_end') {
  5348. // 开始直播,关闭直播
  5349. if (this.liveStartTimer) {
  5350. clearInterval(this.liveStartTimer);
  5351. this.liveStartTimer = null;
  5352. }
  5353. if (this.redTimer) {
  5354. clearInterval(this.redTimer);
  5355. this.redTimer = null;
  5356. }
  5357. if (socketMessage.cmd == 'live_start') {
  5358. this.liveBeginWatchTime = this.getServerTimeNow();
  5359. }
  5360. if (socketMessage.cmd == 'live_end') {
  5361. this.hasLiveEnd = true;
  5362. }
  5363. // 请求最新直播间数据
  5364. this.$nextTick(() => {
  5365. this.getliving(this.liveId);
  5366. });
  5367. } else if (socketMessage.cmd == 'Integral') {
  5368. this.integral = {
  5369. msg: socketMessage.msg,
  5370. status: true
  5371. };
  5372. }
  5373. // else if (socketMessage.cmd == 'completionPoints') {
  5374. // uni.showToast({
  5375. // title: socketMessage.msg,
  5376. // icon: 'none',
  5377. // duration: 3000
  5378. // });
  5379. // this.completionUnreceived()
  5380. // }
  5381. // else if (socketMessage.cmd == 'completionPoints') {
  5382. // // 先显示toast
  5383. // uni.showToast({
  5384. // title: socketMessage.msg,
  5385. // icon: 'none',
  5386. // duration: 3000
  5387. // });
  5388. // // 1秒后关闭弹窗并执行completionUnreceived
  5389. // setTimeout(() => {
  5390. // // 如果需要手动关闭toast(虽然设置了3秒自动关闭,但这里提前关闭)
  5391. // uni.hideToast();
  5392. // // 执行completionUnreceived方法
  5393. // this.completionUnreceived();
  5394. // }, 1000); // 1000毫秒 = 1秒
  5395. // }
  5396. else if (socketMessage.cmd == 'userCount') {
  5397. // 广播在线人数
  5398. this.virtualHuman = socketMessage.data * 10
  5399. } else if (socketMessage.cmd == 'deleteMsg') {
  5400. const index = this.talklist.findIndex(item => item.msgId ==
  5401. socketMessage.msg);
  5402. if (index !== -1) {
  5403. this.talklist.splice(index, 1);
  5404. }
  5405. } else if (socketMessage.cmd == 'LotteryDetail') {
  5406. try {
  5407. this.prizeInfo = Array.isArray(JSON.parse(socketMessage
  5408. .data || '[]')) ? JSON.parse(
  5409. socketMessage.data || '[]') : [];
  5410. } catch (err) {
  5411. console.error('解析抽奖结果失败:', err);
  5412. this.prizeInfo = [];
  5413. }
  5414. this.isShowPrize = true;
  5415. this.isShowLottery = false;
  5416. this.isShowLotteryPop = false;
  5417. } else if (socketMessage.cmd == 'blockUser') {
  5418. uni.removeStorage({
  5419. key: 'AppToken',
  5420. success: () => {
  5421. uni.reLaunch({
  5422. url: '/pages/auth/login'
  5423. });
  5424. }
  5425. });
  5426. }
  5427. } else {
  5428. uni.showToast({
  5429. title: data.msg,
  5430. icon: 'none'
  5431. });
  5432. }
  5433. } catch (error) {
  5434. console.error('Socket消息处理失败:', error);
  5435. }
  5436. },
  5437. sendMsg(retries = 1) {
  5438. // 防止连续点击发送两次(800ms短时锁定)
  5439. if (this.isSending) return;
  5440. this.isSending = true;
  5441. setTimeout(() => {
  5442. this.isSending = false;
  5443. }, 800);
  5444. const text = (this.value || '').trim();
  5445. if (!text) {
  5446. uni.showToast({
  5447. title: '不能发送空消息',
  5448. icon: 'none'
  5449. });
  5450. return;
  5451. }
  5452. if (!this.isSocketAvailable()) {
  5453. if (retries > 0) {
  5454. uni.showToast({
  5455. title: `连接不稳定,正在重试(${retries}次)...`,
  5456. icon: 'none'
  5457. });
  5458. // 延迟500ms重试,重试次数减1
  5459. setTimeout(() => this.sendMsg(retries - 1), 500);
  5460. } else {
  5461. uni.showToast({
  5462. title: '连接已断开,发送失败',
  5463. icon: 'none'
  5464. });
  5465. this.value = text; // 恢复输入框内容
  5466. }
  5467. return;
  5468. }
  5469. const liveId = this.liveId;
  5470. this.value = ''; // 立即清空输入框
  5471. // 构造发送给服务端的消息数据
  5472. const data = {
  5473. liveId,
  5474. userId: this.userInfo.userId,
  5475. userType: 0,
  5476. cmd: 'sendMsg',
  5477. msg: text,
  5478. nickName: this.userInfo.nickname || '未命名',
  5479. avatar: this.userInfo.avatar ||
  5480. 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar.png'
  5481. };
  5482. // 发送socket消息
  5483. try {
  5484. if (this.myselfFlag) {
  5485. this.addToTalkList(data);
  5486. this.forceScrollToBottomOnSend();
  5487. } else {
  5488. this.socket.send({
  5489. data: JSON.stringify(data),
  5490. success: () => {
  5491. this.value = '';
  5492. // 发送成功后强制滚动到底部,无论当前滚动位置如何
  5493. this.forceScrollToBottomOnSend();
  5494. },
  5495. fail: (err) => {
  5496. console.error('消息发送失败:', err);
  5497. if (retries > 0) {
  5498. uni.showToast({
  5499. title: `发送失败,正在重试(${retries}次)`,
  5500. icon: 'none'
  5501. });
  5502. setTimeout(() => this.sendMsg(retries - 1),
  5503. 500);
  5504. } else {
  5505. uni.showToast({
  5506. title: '发送失败,请稍后再试',
  5507. icon: 'none'
  5508. });
  5509. this.value = text; // 恢复输入框内容
  5510. }
  5511. }
  5512. });
  5513. }
  5514. } catch (err) {
  5515. console.error('发送消息异常:', err);
  5516. if (retries > 0) {
  5517. setTimeout(() => this.sendMsg(retries - 1), 500);
  5518. } else {
  5519. uni.showToast({
  5520. title: '发送失败,请稍后再试',
  5521. icon: 'none'
  5522. });
  5523. this.value = text;
  5524. }
  5525. }
  5526. },
  5527. formatUserNum() {
  5528. let userTotal = 0;
  5529. if (!this.liveUserTotal) {
  5530. this.liveUserTotal = 0;
  5531. }
  5532. if (this.liveUserTotal > 0) {
  5533. userTotal = this.liveUserTotal = 0;
  5534. }
  5535. if (this.liveUserTotal > 10000) {
  5536. userTotal = (this.liveUserTotal / 10000.0).toFixed(1);
  5537. userTotal = userTotal + "万";
  5538. }
  5539. console.log("qxj userTotal", userTotal);
  5540. return userTotal;
  5541. },
  5542. }
  5543. };
  5544. </script>
  5545. <style scoped lang="scss">
  5546. // 弹窗
  5547. .custom-toast {
  5548. position: fixed;
  5549. top: 50%;
  5550. left: 50%;
  5551. transform: translate(-50%, -50%);
  5552. z-index: 999999;
  5553. }
  5554. .toast-content {
  5555. background-color: rgba(0, 0, 0, 0.7);
  5556. color: white;
  5557. padding: 20rpx 40rpx;
  5558. border-radius: 16rpx;
  5559. max-width: 80vw;
  5560. text-align: center;
  5561. line-height: 1.5;
  5562. font-weight: 500;
  5563. font-size: 32rpx;
  5564. }
  5565. /* 退出全屏按钮 */
  5566. .fullscreen-exit-btn {
  5567. position: fixed;
  5568. bottom: 40rpx;
  5569. left: 82vh;
  5570. display: flex;
  5571. flex-direction: column;
  5572. align-items: center;
  5573. justify-content: center;
  5574. z-index: 100001;
  5575. background: rgba(57, 57, 57, 0.6);
  5576. border-radius: 40rpx;
  5577. padding: 20rpx 24rpx;
  5578. transition: all 0.3s ease;
  5579. &:active {
  5580. transform: scale(0.95);
  5581. background: rgba(50, 50, 50, 0.6);
  5582. }
  5583. .exit-fullscreen-icon {
  5584. width: 40rpx;
  5585. height: 40rpx;
  5586. margin-bottom: 10rpx;
  5587. }
  5588. .exit-text {
  5589. color: #ffffff;
  5590. font-size: 22rpx;
  5591. white-space: nowrap;
  5592. }
  5593. }
  5594. .video-container.fullscreen-mode .fullscreen-exit-btn {
  5595. z-index: 999999 !important;
  5596. }
  5597. .fullscreen-mode {
  5598. background-color: #000 !important;
  5599. }
  5600. /* 全屏模式样式 */
  5601. .video-container.fullscreen-mode {
  5602. // width: auto !important;
  5603. // height: auto !important;
  5604. z-index: 99999 !important;
  5605. background-color: #000 !important;
  5606. transform: rotate(90deg) !important;
  5607. transform-origin: center center !important;
  5608. .video-player {
  5609. width: 100vh !important;
  5610. height: 100vw !important;
  5611. // object-fit: contain !important;
  5612. }
  5613. }
  5614. /* 全屏时隐藏其他元素 */
  5615. .video-container.fullscreen-mode~* {
  5616. display: none !important;
  5617. }
  5618. .video-container {
  5619. position: relative;
  5620. bottom: -1px;
  5621. transition: all 0.3s ease;
  5622. }
  5623. .video-container2 {
  5624. position: relative;
  5625. bottom: -1px;
  5626. transition: all 0.3s ease;
  5627. }
  5628. .video-player.fullscreen {
  5629. width: 100vh !important;
  5630. height: 100vw !important;
  5631. object-fit: contain !important;
  5632. }
  5633. /* 全屏按钮样式优化 */
  5634. .custom-controls {
  5635. position: absolute;
  5636. bottom: 24rpx;
  5637. right: 40rpx;
  5638. z-index: 9999;
  5639. background: rgba(0, 0, 0, 0.6);
  5640. border-radius: 50%;
  5641. width: 80rpx;
  5642. height: 80rpx;
  5643. display: flex;
  5644. align-items: center;
  5645. justify-content: center;
  5646. transition: all 0.3s ease;
  5647. &:active {
  5648. transform: scale(0.95);
  5649. background: rgba(0, 0, 0, 0.8);
  5650. }
  5651. }
  5652. .control-icon {
  5653. width: 46rpx;
  5654. height: 46rpx;
  5655. }
  5656. @media screen and (orientation: landscape) {
  5657. .video-container.horizontal-layout {
  5658. width: 100%;
  5659. height: 100%;
  5660. }
  5661. // .video-player {
  5662. // width: 100vh !important;
  5663. // height: 100vw !important;
  5664. // }
  5665. }
  5666. // 重置按钮样式
  5667. .button-reset {
  5668. background-color: transparent !important;
  5669. padding: 0 !important;
  5670. line-height: 1 !important;
  5671. margin: 0 !important;
  5672. width: auto !important;
  5673. // font-weight: 500 !important;
  5674. border-radius: none !important;
  5675. &::after {
  5676. border: none !important;
  5677. padding: 0 !important;
  5678. margin: 0 !important;
  5679. }
  5680. }
  5681. // :deep(.u-tabs__wrapper__nav) {
  5682. // background-color: #fff !important;
  5683. // }
  5684. .swiper-wrapper {
  5685. /* 深色主题变量 */
  5686. --bottom-color: transparent;
  5687. --bg-color: #242424;
  5688. --text-color: #ffffff;
  5689. --name-color: #8CE7FF;
  5690. --normal-bg: rgba(0, 0, 0, 0.3);
  5691. --input-bg: rgba(0, 0, 0, 0.3);
  5692. --chat-bg: transparent;
  5693. --video-height: 100vh;
  5694. --chat-height: 30vh;
  5695. --pop-bg: #333333;
  5696. --notice-bg: rgba(9, 9, 9, 0.4);
  5697. }
  5698. .swiper-wrapper.horizontal {
  5699. --notice-bg: #fefae8;
  5700. --pop-bg: #ECF5F4;
  5701. /* 默认变量(浅色主题) */
  5702. --bottom-color: #fff;
  5703. --name-color: #666666;
  5704. --bg-color: #ffffff;
  5705. --text-color: #333333;
  5706. --normal-bg: #fff;
  5707. --input-bg: #F5F7FA;
  5708. --chat-bg: #ECF5F4; //对话聊天
  5709. --video-height: 500rpx;
  5710. --chat-height: clac(100% - 650rpx);
  5711. }
  5712. // 主容器
  5713. .swiper-wrapper {
  5714. position: relative;
  5715. width: 100%;
  5716. height: 100vh;
  5717. overflow: hidden;
  5718. /* 应用变量 */
  5719. background: var(--bg-color);
  5720. color: var(--text-color);
  5721. .container {
  5722. width: 100%;
  5723. height: 100%;
  5724. position: relative;
  5725. transition: opacity 0.3s ease;
  5726. transform: translateZ(0);
  5727. will-change: opacity;
  5728. // 预告直播盒子
  5729. .trailer-box {
  5730. width: calc(100% - 80rpx);
  5731. background: var(--pop-bg);
  5732. border-radius: 24rpx;
  5733. position: absolute;
  5734. top: 16%;
  5735. left: 50%;
  5736. transform: translateX(-50%);
  5737. display: flex;
  5738. flex-direction: column;
  5739. align-items: center;
  5740. color: var(--text-color);
  5741. padding: 20rpx;
  5742. z-index: 999;
  5743. box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.12);
  5744. transition: box-shadow 0.3s ease;
  5745. .trailer-video {
  5746. width: 100%;
  5747. height: 100%;
  5748. position: absolute;
  5749. z-index: 1;
  5750. border-radius: 20rpx;
  5751. }
  5752. .trailer-placeholder {
  5753. margin-bottom: 40rpx;
  5754. width: 240rpx;
  5755. height: 240rpx;
  5756. }
  5757. .countdown-container {
  5758. margin: 20rpx 0;
  5759. display: flex;
  5760. flex-direction: column;
  5761. align-items: center;
  5762. .live-name {
  5763. font-weight: 600;
  5764. font-size: 36rpx;
  5765. }
  5766. .countdown-display {
  5767. display: flex;
  5768. align-items: center;
  5769. margin: 30rpx 0;
  5770. .countdown-label {
  5771. font-size: 24rpx;
  5772. color: #999999;
  5773. }
  5774. .countdown-separator {
  5775. font-size: 24rpx;
  5776. color: #999999;
  5777. }
  5778. .countdown-unit {
  5779. width: 40rpx;
  5780. height: 40rpx;
  5781. background: #4D4D4D;
  5782. border-radius: 8rpx;
  5783. text-align: center;
  5784. overflow: hidden;
  5785. margin: 0 8rpx;
  5786. font-weight: 500;
  5787. font-size: 28rpx;
  5788. color: #FFFFFF;
  5789. line-height: 40rpx;
  5790. }
  5791. }
  5792. }
  5793. .trailer-actions {
  5794. display: flex;
  5795. justify-content: center;
  5796. align-items: center;
  5797. .action-button {
  5798. width: 280rpx;
  5799. height: 72rpx;
  5800. border-radius: 36rpx;
  5801. line-height: 72rpx;
  5802. text-align: center;
  5803. color: #fff;
  5804. &.reserve-button {
  5805. background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
  5806. }
  5807. &:not(.reserve-button) {
  5808. background: #F4A007;
  5809. }
  5810. .button-icon {
  5811. width: 32rpx;
  5812. height: 32rpx;
  5813. }
  5814. }
  5815. }
  5816. .no-live-title {
  5817. margin-top: 30rpx;
  5818. font-size: 42rpx;
  5819. font-weight: 500;
  5820. }
  5821. }
  5822. // 新预告直播盒子
  5823. .trailer-box2 {
  5824. width: 100%;
  5825. position: absolute;
  5826. top: 16%;
  5827. display: flex;
  5828. flex-direction: column;
  5829. align-items: center;
  5830. z-index: 999;
  5831. transition: box-shadow 0.3s ease;
  5832. height: 400rpx;
  5833. .trailer-video {
  5834. width: 100%;
  5835. height: 100%;
  5836. position: absolute;
  5837. z-index: 1;
  5838. }
  5839. .trailer-placeholder {
  5840. position: absolute;
  5841. top: 0;
  5842. left: 0;
  5843. width: 100%;
  5844. height: 100%;
  5845. z-index: -1;
  5846. /* 置于内容下方 */
  5847. }
  5848. .countdown-container {
  5849. padding-top: 15%;
  5850. margin: 20rpx 0;
  5851. display: flex;
  5852. flex-direction: column;
  5853. align-items: center;
  5854. .live-name {
  5855. font-weight: 600;
  5856. font-size: 36rpx;
  5857. }
  5858. .countdown-display {
  5859. display: flex;
  5860. align-items: center;
  5861. margin: 30rpx 0;
  5862. .countdown-label {
  5863. font-size: 32rpx;
  5864. color: rgba(250, 214, 176, 1);
  5865. //color:#fff
  5866. }
  5867. .countdown-separator {
  5868. font-size: 24rpx;
  5869. color: rgba(250, 214, 176, 1);
  5870. }
  5871. .countdown-unit {
  5872. width: 60rpx;
  5873. height: 60rpx;
  5874. background: rgba(255, 246, 214, 1);
  5875. border-radius: 8rpx;
  5876. text-align: center;
  5877. overflow: hidden;
  5878. margin: 0 8rpx;
  5879. font-weight: 500;
  5880. font-size: 36rpx;
  5881. //color: #a30c0b;
  5882. color: rgba(0, 75, 59, 1);
  5883. line-height: 60rpx;
  5884. }
  5885. }
  5886. }
  5887. .trailer-actions {
  5888. display: flex;
  5889. justify-content: center;
  5890. align-items: center;
  5891. .action-button {
  5892. width: 280rpx;
  5893. height: 72rpx;
  5894. border-radius: 36rpx;
  5895. display: flex;
  5896. justify-content: center;
  5897. align-items: center;
  5898. text-align: center;
  5899. //border: 1px solid rgba(151, 151, 151, 1);
  5900. border: 1px solid rgba(255, 246, 214, 1);
  5901. font-size: 36rpx;
  5902. font-weight: bold;
  5903. &.reserve-button {
  5904. color: rgba(0, 110, 80, 1);
  5905. //color: #a30c0b;
  5906. background: linear-gradient(231.51deg, rgba(249, 215, 178, 1) 0%, rgba(255, 255, 191, 1) 47.83%, rgba(255, 250, 229, 1) 65.77%, rgba(248, 214, 178, 1) 100%);
  5907. }
  5908. &:not(.reserve-button) {
  5909. color: rgba(255, 246, 214, 1);
  5910. background: rgba(0, 110, 80, 1);
  5911. // color: #fff;
  5912. // background: #a30c0b;
  5913. }
  5914. .button-icon {
  5915. width: 32rpx;
  5916. height: 32rpx;
  5917. }
  5918. }
  5919. }
  5920. .no-live-title {
  5921. margin-top: 30rpx;
  5922. font-size: 42rpx;
  5923. font-weight: 500;
  5924. }
  5925. }
  5926. // 主要内容区域
  5927. .content {
  5928. position: relative;
  5929. z-index: 2;
  5930. height: 100%;
  5931. width: 100%;
  5932. top: 0;
  5933. left: 0;
  5934. display: flex;
  5935. flex-direction: column;
  5936. &.horizontal-content {
  5937. z-index: 999;
  5938. }
  5939. &.trailer-content {
  5940. justify-content: space-between;
  5941. }
  5942. // 顶部信息栏
  5943. .top-info-bar {
  5944. position: fixed;
  5945. top: 0;
  5946. z-index: 5;
  5947. width: 100%;
  5948. padding: 0 24rpx;
  5949. box-sizing: border-box;
  5950. // margin-top:calc(var(--status-bar-height) + 10rpx);
  5951. display: flex;
  5952. justify-content: space-between;
  5953. flex-direction: column;
  5954. &.horizontal-top {
  5955. position: static;
  5956. margin-bottom: 30rpx;
  5957. }
  5958. .user-info-section {
  5959. display: flex;
  5960. align-items: center;
  5961. .back-icon {
  5962. width: 60rpx;
  5963. height: 64rpx;
  5964. }
  5965. .user-avatar-container {
  5966. padding: 6rpx 8rpx;
  5967. height: 64rpx;
  5968. background: var(--normal-bg);
  5969. border-radius: 32rpx;
  5970. display: flex;
  5971. align-items: center;
  5972. .user-name {
  5973. color: var(--text-color);
  5974. }
  5975. }
  5976. }
  5977. .viewers-section {
  5978. display: flex;
  5979. justify-content: flex-end;
  5980. align-items: center;
  5981. margin-top: 30rpx;
  5982. .viewer-avatar {
  5983. width: 52rpx;
  5984. height: 52rpx;
  5985. border-radius: 26rpx;
  5986. }
  5987. .viewer-avatar-placeholder {
  5988. width: 52rpx;
  5989. height: 52rpx;
  5990. border-radius: 50%;
  5991. display: flex;
  5992. align-items: center;
  5993. justify-content: center;
  5994. .avatar-initial {
  5995. color: var(--text-color);
  5996. font-size: 18rpx;
  5997. }
  5998. }
  5999. .viewer-count {
  6000. width: 80rpx;
  6001. height: 52rpx;
  6002. background: var(--normal-bg);
  6003. border-radius: 26rpx;
  6004. font-size: 30rpx;
  6005. color: var(--text-color);
  6006. text-align: center;
  6007. line-height: 52rpx;
  6008. }
  6009. }
  6010. }
  6011. // 购买提示
  6012. .purchase-prompt {
  6013. position: absolute;
  6014. bottom: 750rpx;
  6015. left: 24rpx;
  6016. padding: 6rpx 20rpx;
  6017. background: rgba(230, 154, 34, 0.7);
  6018. border-radius: 24rpx;
  6019. z-index: 9;
  6020. font-weight: 500;
  6021. color: #ffffff;
  6022. transition: opacity 0.3s ease;
  6023. font-size: 30rpx;
  6024. display: flex;
  6025. align-items: center;
  6026. .prompt-icon {
  6027. width: 32rpx;
  6028. height: 32rpx;
  6029. }
  6030. }
  6031. // 视频区域
  6032. .videolist {
  6033. position: relative;
  6034. // height: var(--video-height);
  6035. width: 100%;
  6036. &.screen {
  6037. width: 100%;
  6038. height: 100%;
  6039. //height: 100vh;
  6040. }
  6041. .video-container {
  6042. //height: var(--video-height);
  6043. width: 100%;
  6044. transform: translateZ(0);
  6045. backface-visibility: hidden;
  6046. perspective: 1000;
  6047. &.horizontal-layout {
  6048. // position: absolute;
  6049. // top: 20%;
  6050. // max-height: 450rpx;
  6051. // z-index: 99;
  6052. }
  6053. .complaint-box {
  6054. position: absolute;
  6055. // top: 20%;
  6056. right: 20rpx;
  6057. width: 140rpx;
  6058. margin-top: 20rpx;
  6059. display: flex;
  6060. align-items: center;
  6061. justify-content: center;
  6062. background-color: rgba(57, 57, 57, 0.6);
  6063. padding: 16rpx 0;
  6064. color: #fff;
  6065. border-radius: 28rpx;
  6066. z-index: 999999 !important;
  6067. &.complaint-full {
  6068. // top: 10rpx;
  6069. left: 82vh;
  6070. }
  6071. &:active {
  6072. transform: scale(0.95);
  6073. background: rgba(50, 50, 50, 0.6);
  6074. }
  6075. }
  6076. .txt {
  6077. text-align: center;
  6078. font-weight: 500;
  6079. font-size: 40rpx;
  6080. line-height: var(--video-height);
  6081. }
  6082. .video-player {
  6083. width: 100%;
  6084. height: 100%;
  6085. position: absolute;
  6086. z-index: 1;
  6087. }
  6088. .live-end-message {
  6089. position: absolute;
  6090. top: 50%;
  6091. left: 50%;
  6092. transform: translate(-50%, -50%);
  6093. font-size: 36rpx;
  6094. color: var(--text-color);
  6095. }
  6096. .replay-label {
  6097. position: absolute;
  6098. // top: 10%;
  6099. right: 24rpx;
  6100. background-color: rgba(57, 57, 57, 0.6);
  6101. width: 100rpx;
  6102. height: 70rpx;
  6103. line-height: 70rpx;
  6104. text-align: center;
  6105. color: #fff;
  6106. border-radius: 15rpx;
  6107. z-index: 999999 !important;
  6108. &.replay-full {
  6109. left: 82vh;
  6110. // top: 16% !important;
  6111. }
  6112. }
  6113. .look-time {
  6114. position: absolute;
  6115. left: 24rpx;
  6116. bottom: 24rpx;
  6117. font-size: 20rpx;
  6118. background-color: rgba(57, 57, 57, 0.6);
  6119. border-radius: 15rpx;
  6120. z-index: 999999 !important;
  6121. padding: 10rpx 16rpx;
  6122. color: #fff;
  6123. &.look-full {
  6124. left: 10vh;
  6125. }
  6126. }
  6127. }
  6128. }
  6129. }
  6130. // 侧边
  6131. .slide-group {
  6132. position: absolute;
  6133. right: 20rpx;
  6134. top: 60%;
  6135. z-index: 9000;
  6136. .action-button-group {
  6137. display: flex;
  6138. justify-content: space-between;
  6139. align-items: center;
  6140. margin-top: 50rpx;
  6141. }
  6142. .action-icon {
  6143. width: 88rpx;
  6144. height: 88rpx;
  6145. }
  6146. .icon-button {
  6147. // background: var(--normal-bg);
  6148. // border-radius: 50%;
  6149. width: 88rpx;
  6150. height: 88rpx;
  6151. display: flex;
  6152. justify-content: center;
  6153. align-items: center;
  6154. transition: transform 0.2s ease;
  6155. // margin-left: 10rpx;
  6156. &.like-container {
  6157. display: flex;
  6158. flex-direction: column;
  6159. justify-content: center;
  6160. align-items: center;
  6161. .like-count {
  6162. position: absolute;
  6163. bottom: -40rpx;
  6164. font-size: 24rpx;
  6165. color: #FA341E;
  6166. padding: 6rpx 16rpx;
  6167. background: #FFFFFF;
  6168. border-radius: 30rpx;
  6169. }
  6170. }
  6171. }
  6172. }
  6173. // 聊天区域
  6174. .chat-area-container {
  6175. background: var(--chat-bg);
  6176. position: fixed;
  6177. width: 100%;
  6178. bottom: 0;
  6179. z-index: 999;
  6180. transform: translateZ(0);
  6181. will-change: transform;
  6182. backface-visibility: hidden;
  6183. &.chat-area-container2 {
  6184. flex: 1;
  6185. min-height: 0; // 重要:允许收缩到0
  6186. position: relative;
  6187. transform: none; // 移除之前的变换
  6188. will-change: auto;
  6189. display: flex;
  6190. flex-direction: column;
  6191. }
  6192. &.chat-area-container3 {
  6193. height: calc(85% - 420rpx);
  6194. flex: 1;
  6195. transform: none; // 移除之前的变换
  6196. will-change: auto;
  6197. display: flex;
  6198. flex-direction: column;
  6199. position: absolute;
  6200. }
  6201. &.chat-area-container4 {
  6202. height: calc(85% - 680rpx);
  6203. flex: 1;
  6204. transform: none; // 移除之前的变换
  6205. will-change: auto;
  6206. display: flex;
  6207. flex-direction: column;
  6208. position: absolute;
  6209. // max-height: 40%;
  6210. // flex: 1;
  6211. // min-height: 0; // 重要:允许收缩到0
  6212. // // position: relative;
  6213. // transform: none; // 移除之前的变换
  6214. // will-change: auto;
  6215. // display: flex;
  6216. // flex-direction: column;
  6217. // position: absolute;
  6218. }
  6219. &.chat-area-container5 {
  6220. height: calc(85% - 450rpx);
  6221. flex: 1;
  6222. transform: none; // 移除之前的变换
  6223. will-change: auto;
  6224. display: flex;
  6225. flex-direction: column;
  6226. position: absolute;
  6227. // max-height: 40%;
  6228. // flex: 1;
  6229. // min-height: 0; // 重要:允许收缩到0
  6230. // // position: relative;
  6231. // transform: none; // 移除之前的变换
  6232. // will-change: auto;
  6233. // display: flex;
  6234. // flex-direction: column;
  6235. // position: absolute;
  6236. }
  6237. &.chat-area-focused {
  6238. transform: translateY(calc(-1 * var(--keyboard-height, 0rpx))) translateZ(0);
  6239. z-index: 1000;
  6240. }
  6241. .tabs_bg {
  6242. background-color: #fff;
  6243. padding: 0 40rpx;
  6244. display: flex;
  6245. justify-content: space-between;
  6246. align-items: center;
  6247. height: 96rpx;
  6248. .complaint-box {
  6249. width: 120rpx;
  6250. height: 48rpx;
  6251. background: #FFFFFF;
  6252. border-radius: 24rpx 24rpx 24rpx 24rpx;
  6253. border: 2rpx solid #EEEEEE;
  6254. display: flex;
  6255. justify-content: center;
  6256. align-items: center;
  6257. }
  6258. }
  6259. .chat-content-wrapper {
  6260. flex: 1;
  6261. height: 400rpx;
  6262. padding: 20rpx 0;
  6263. transform: translateZ(0);
  6264. will-change: height;
  6265. position: relative;
  6266. &.chat-content-focused {
  6267. height: 100rpx !important;
  6268. }
  6269. .notice-message {
  6270. font-size: 36rpx;
  6271. position: absolute;
  6272. bottom: 388rpx;
  6273. max-width: 80%;
  6274. padding: 24rpx;
  6275. background-color: var(--notice-bg);
  6276. margin: 0 0 20rpx 20rpx;
  6277. border-radius: 20rpx;
  6278. color: #0d0b05;
  6279. font-weight: 500;
  6280. overflow: hidden;
  6281. &.horizontal-notice {
  6282. top: 12rpx;
  6283. height: fit-content;
  6284. z-index: 2;
  6285. }
  6286. &.horizontal-notice2 {
  6287. color: #fff !important;
  6288. top: 12rpx;
  6289. height: fit-content;
  6290. z-index: 2;
  6291. }
  6292. }
  6293. .message-scroll-view {
  6294. width: calc(100% - 20rpx);
  6295. height: 100%;
  6296. padding-left: 20rpx;
  6297. display: flex;
  6298. flex: 1;
  6299. flex-direction: column;
  6300. -webkit-overflow-scrolling: touch;
  6301. &.message-scroll2 {
  6302. height: 300rpx;
  6303. }
  6304. }
  6305. .message-list {
  6306. width: 80%;
  6307. margin-bottom: 16rpx;
  6308. animation: simpleFade 0.2s;
  6309. .message-item {
  6310. display: flex;
  6311. justify-content: flex-start;
  6312. .message-content {
  6313. font-size: 30rpx;
  6314. max-width: 100%;
  6315. border-radius: 30rpx;
  6316. background: var(--normal-bg);
  6317. padding: 10rpx 30rpx;
  6318. line-height: 1.4;
  6319. word-break: break-all;
  6320. word-wrap: break-word;
  6321. overflow-wrap: break-word;
  6322. .user-nickname {
  6323. color: var(--name-color);
  6324. }
  6325. .message-text {
  6326. color: var(--text-color);
  6327. }
  6328. }
  6329. }
  6330. }
  6331. }
  6332. // 输入和操作区域
  6333. .input-actions-container {
  6334. position: relative;
  6335. z-index: 999999;
  6336. background-color: var(--bottom-color);
  6337. display: flex;
  6338. justify-content: space-between;
  6339. align-items: center;
  6340. padding: 24rpx;
  6341. &.input-actions-focused {
  6342. justify-content: flex-start !important;
  6343. align-items: stretch !important;
  6344. width: 100% !important;
  6345. display: flex !important;
  6346. }
  6347. .input-container {
  6348. background: var(--input-bg);
  6349. box-sizing: border-box;
  6350. border-radius: 36rpx;
  6351. display: flex;
  6352. align-items: center;
  6353. transform: translateZ(0);
  6354. will-change: transform;
  6355. backface-visibility: hidden;
  6356. perspective: 1000px;
  6357. &.input-container-normal {
  6358. padding: 18rpx 20rpx;
  6359. width: auto;
  6360. max-width: auto;
  6361. margin-right: 0;
  6362. justify-content: space-between;
  6363. }
  6364. &.input-container-focused {
  6365. padding: 10rpx 10rpx 10rpx 20rpx;
  6366. width: 100%;
  6367. max-width: calc(100% - 20rpx);
  6368. margin-right: 20rpx;
  6369. // flex: 1;
  6370. justify-content: flex-start;
  6371. }
  6372. .chat-input {
  6373. border: none !important;
  6374. font-size: 32rpx !important;
  6375. color: var(--text-color) !important;
  6376. background: transparent !important;
  6377. width: 70% !important;
  6378. transform: translateZ(0);
  6379. will-change: contents, width;
  6380. backface-visibility: hidden;
  6381. margin-left: 20rpx;
  6382. &.input-focused {
  6383. width: 100% !important;
  6384. flex: 1 !important;
  6385. min-width: 0 !important;
  6386. margin-left: 10rpx !important;
  6387. max-width: none !important;
  6388. }
  6389. }
  6390. .send-button {
  6391. background-color: #ffffff;
  6392. border-radius: 28rpx;
  6393. padding: 14rpx 16rpx;
  6394. color: #181818;
  6395. font-weight: 500;
  6396. min-width: 80rpx;
  6397. text-align: center;
  6398. flex-shrink: 0;
  6399. &.send2 {
  6400. background-color: #2fa9f1;
  6401. color: #ffffff;
  6402. }
  6403. }
  6404. }
  6405. .action-buttons {
  6406. display: flex;
  6407. justify-content: space-between;
  6408. align-items: center;
  6409. flex: auto;
  6410. // margin-right: 15rpx;
  6411. transform: translateZ(0);
  6412. justify-content: flex-end;
  6413. &.action-buttons-hidden {
  6414. opacity: 0;
  6415. visibility: hidden;
  6416. }
  6417. .action-icon {
  6418. width: 48rpx;
  6419. height: 48rpx;
  6420. }
  6421. .cart-icon {
  6422. width: 46rpx;
  6423. height: 58rpx;
  6424. }
  6425. }
  6426. }
  6427. }
  6428. // 商品卡片
  6429. .goods-card {
  6430. position: fixed;
  6431. bottom: 140rpx;
  6432. right: 24rpx;
  6433. z-index: 5;
  6434. background-color: #fff;
  6435. border-radius: 20rpx;
  6436. overflow: hidden;
  6437. width: 224rpx;
  6438. padding: 4rpx;
  6439. .goods-card-header {
  6440. position: absolute;
  6441. top: 4rpx;
  6442. display: flex;
  6443. justify-content: space-between;
  6444. align-items: center;
  6445. color: #fff;
  6446. width: 100%;
  6447. padding-right: 10rpx;
  6448. box-sizing: border-box;
  6449. .goods-status {
  6450. background: rgba(0, 0, 0, 0.4);
  6451. padding: 12rpx;
  6452. font-size: 22rpx;
  6453. display: flex;
  6454. justify-content: space-between;
  6455. align-items: center;
  6456. border-radius: 10rpx;
  6457. .status-icon {
  6458. width: 30rpx;
  6459. height: 30rpx;
  6460. }
  6461. }
  6462. .close-icon {
  6463. width: 24rpx;
  6464. height: 24rpx;
  6465. }
  6466. }
  6467. .goods-image {
  6468. width: 100%;
  6469. height: 224rpx;
  6470. border-radius: 16rpx 16rpx 0 0;
  6471. overflow: hidden;
  6472. }
  6473. .goods-info {
  6474. padding: 4rpx;
  6475. .goods-title {
  6476. font-weight: 500;
  6477. font-size: 24rpx;
  6478. margin: 10rpx 0 12rpx;
  6479. color: #111111;
  6480. }
  6481. .goods-action {
  6482. color: #fff;
  6483. text-align: center;
  6484. font-weight: 500;
  6485. font-size: 30rpx;
  6486. position: relative;
  6487. .goods-price {
  6488. left: 10rpx;
  6489. position: absolute;
  6490. top: 40%;
  6491. transform: translateY(-50%);
  6492. font-size: 30rpx;
  6493. z-index: 999;
  6494. .price-symbol {
  6495. font-weight: 600;
  6496. font-size: 20rpx;
  6497. color: #FFFFFF;
  6498. }
  6499. .price-integer {
  6500. font-size: 36rpx;
  6501. margin-right: 10rpx;
  6502. }
  6503. }
  6504. .shop-icon {
  6505. width: 204rpx;
  6506. height: 52rpx;
  6507. }
  6508. }
  6509. }
  6510. }
  6511. // 动画
  6512. @keyframes simpleFade {
  6513. from {
  6514. opacity: 0;
  6515. }
  6516. to {
  6517. opacity: 1;
  6518. }
  6519. }
  6520. .userlogo {
  6521. padding: 36rpx 40rpx;
  6522. color: #000000;
  6523. .mt42 {
  6524. margin-top: 42rpx;
  6525. }
  6526. .boxweixin {
  6527. width: 44rpx;
  6528. height: 44rpx;
  6529. border-radius: 50%;
  6530. text-align: center;
  6531. line-height: 34rpx;
  6532. color: #0a0;
  6533. }
  6534. .button-container {
  6535. position: relative;
  6536. margin: auto;
  6537. .hidden-input {
  6538. width: calc(100vw - 80rpx);
  6539. text-align: center;
  6540. height: 104rpx;
  6541. background: #07C160;
  6542. padding: 30rpx 0;
  6543. box-sizing: border-box;
  6544. border-radius: 12rpx;
  6545. font-size: 32rpx !important;
  6546. color: #FFFFFF !important;
  6547. /* 输入文字大小 */
  6548. }
  6549. /* 针对 placeholder 的样式 */
  6550. .hidden-input::placeholder {
  6551. font-size: 44rpx !important;
  6552. color: #FFFFFF !important;
  6553. }
  6554. /* 兼容微信小程序的 placeholder 样式 */
  6555. .hidden-input .placeholder {
  6556. font-size: 44rpx !important;
  6557. color: #FFFFFF !important;
  6558. }
  6559. }
  6560. .submitname {
  6561. height: 104rpx;
  6562. line-height: 104rpx;
  6563. background: #F2F2F2;
  6564. border-radius: 12rpx;
  6565. font-size: 32rpx;
  6566. color: #07C160;
  6567. margin-top: 32rpx;
  6568. text-align: center;
  6569. }
  6570. }
  6571. // 抽奖弹窗1
  6572. .lottery-popup {
  6573. position: relative;
  6574. border-radius: 40rpx;
  6575. height: fit-content;
  6576. .lottery-header-image {
  6577. width: 311rpx;
  6578. position: absolute;
  6579. top: -122rpx;
  6580. left: 50%;
  6581. transform: translateX(-50%);
  6582. }
  6583. .lottery-background-image {
  6584. position: absolute;
  6585. top: 0;
  6586. left: 0;
  6587. width: 100%;
  6588. height: 100%;
  6589. z-index: 1;
  6590. }
  6591. .lottery-content {
  6592. position: relative;
  6593. z-index: 2;
  6594. padding: 24rpx 0 68rpx;
  6595. .lottery-close-section {
  6596. display: flex;
  6597. justify-content: flex-end;
  6598. margin-right: 20rpx;
  6599. .close-button-wrapper {
  6600. .close-button {
  6601. width: 80rpx;
  6602. height: 80rpx;
  6603. display: flex;
  6604. justify-content: center;
  6605. align-items: center;
  6606. }
  6607. }
  6608. }
  6609. .lottery-main-content {
  6610. display: flex;
  6611. flex-direction: column;
  6612. align-items: center;
  6613. .lottery-title-image {
  6614. width: 446rpx;
  6615. height: 80rpx;
  6616. }
  6617. .lottery-countdown-section {
  6618. font-size: 24rpx;
  6619. color: #fff;
  6620. display: flex;
  6621. align-items: center;
  6622. margin: 30rpx 0;
  6623. .countdown-label {
  6624. margin-right: 10rpx;
  6625. }
  6626. .countdown-timer {
  6627. display: flex;
  6628. align-items: center;
  6629. .countdown-number {
  6630. width: 40rpx;
  6631. height: 40rpx;
  6632. text-align: center;
  6633. overflow: hidden;
  6634. background: #ffffff;
  6635. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #ffebb2;
  6636. border-radius: 8rpx;
  6637. margin: 4rpx;
  6638. font-weight: 600;
  6639. font-size: 24rpx;
  6640. color: #f85d22;
  6641. line-height: 40rpx;
  6642. }
  6643. }
  6644. }
  6645. .lottery-products-section {
  6646. width: 100%;
  6647. }
  6648. .lottery-indicators {
  6649. margin: 20rpx 0 50rpx;
  6650. display: flex;
  6651. gap: 6rpx;
  6652. .indicator-point {
  6653. width: 20rpx;
  6654. height: 8rpx;
  6655. background: rgba(255, 255, 255, 0.5);
  6656. border-radius: 4rpx;
  6657. &.selected {
  6658. background: #ffeb66;
  6659. }
  6660. }
  6661. }
  6662. .lottery-tip {
  6663. color: #fff;
  6664. font-size: 28rpx;
  6665. }
  6666. .lottery-action-button {
  6667. margin-top: 30rpx;
  6668. width: 520rpx;
  6669. height: 88rpx;
  6670. line-height: 88rpx;
  6671. background: linear-gradient(180deg, #fff4d6 0%, #ffeb66 100%);
  6672. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  6673. border-radius: 44rpx;
  6674. font-weight: 500;
  6675. font-size: 36rpx;
  6676. color: #f4410b;
  6677. text-align: center;
  6678. }
  6679. }
  6680. }
  6681. }
  6682. // 积分弹窗
  6683. .integral-popup {
  6684. min-width: 400rpx;
  6685. max-width: 600rpx;
  6686. display: flex;
  6687. flex-direction: column;
  6688. align-items: center;
  6689. border-radius: 20rpx;
  6690. overflow: hidden;
  6691. .integral-header {
  6692. width: 100%;
  6693. position: relative;
  6694. .integral-title {
  6695. width: 100%;
  6696. font-weight: 600;
  6697. font-size: 40rpx;
  6698. color: #ffffff;
  6699. text-shadow: 0px 4rpx 8rpx rgba(255, 89, 2, 0.8);
  6700. position: absolute;
  6701. top: 50rpx;
  6702. text-align: center;
  6703. }
  6704. .integral-background-image {
  6705. width: 100%;
  6706. }
  6707. }
  6708. .integral-content {
  6709. padding: 20rpx;
  6710. .integral-message {
  6711. font-weight: 500;
  6712. font-size: 32rpx;
  6713. text-align: center;
  6714. }
  6715. .integral-confirm-button {
  6716. font-size: 32rpx;
  6717. margin-top: 20rpx;
  6718. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  6719. color: #fff;
  6720. text-align: center;
  6721. padding: 18rpx 60rpx;
  6722. border-radius: 10rpx;
  6723. font-weight: 500;
  6724. }
  6725. }
  6726. }
  6727. // 红包弹窗
  6728. .red-envelope-popup {
  6729. width: 504rpx;
  6730. position: relative;
  6731. text-align: center;
  6732. height: 610rpx;
  6733. display: flex;
  6734. align-items: center;
  6735. .red-envelope-close-button {
  6736. position: absolute;
  6737. right: 0;
  6738. top: -180rpx;
  6739. width: 64rpx;
  6740. height: 64rpx;
  6741. }
  6742. .red-envelope-background {
  6743. width: 100%;
  6744. height: 100%;
  6745. }
  6746. .red-envelope-content {
  6747. position: absolute;
  6748. top: 0;
  6749. left: 50%;
  6750. transform: translateX(-50%);
  6751. display: flex;
  6752. flex-direction: column;
  6753. align-items: center;
  6754. height: auto;
  6755. .red-envelope-header {
  6756. margin-top: 68rpx;
  6757. display: flex;
  6758. align-items: center;
  6759. .header-decoration-left,
  6760. .header-decoration-right {
  6761. width: 44rpx;
  6762. height: 20rpx;
  6763. }
  6764. .header-title {
  6765. margin: 0 12rpx;
  6766. font-size: 28rpx;
  6767. color: #FFF1BC;
  6768. }
  6769. }
  6770. .red-envelope-text {
  6771. font-weight: 600;
  6772. font-size: 80rpx;
  6773. color: #FFF1BC;
  6774. margin-top: 42rpx;
  6775. }
  6776. .red-envelope-open-text {
  6777. font-weight: 800;
  6778. font-size: 110rpx;
  6779. color: #F41420;
  6780. margin-top: 70rpx;
  6781. }
  6782. }
  6783. }
  6784. // 抽奖弹窗2
  6785. .lottery-popup-v2 {
  6786. width: 504rpx;
  6787. position: relative;
  6788. text-align: center;
  6789. height: 556rpx;
  6790. display: flex;
  6791. align-items: center;
  6792. .lottery-close-button-v2 {
  6793. position: absolute;
  6794. right: 0;
  6795. top: -180rpx;
  6796. width: 64rpx;
  6797. height: 64rpx;
  6798. z-index: 9;
  6799. }
  6800. .lottery-top-image {
  6801. position: absolute;
  6802. top: -214rpx;
  6803. width: 100%;
  6804. }
  6805. .lottery-background-v2 {
  6806. width: 100%;
  6807. height: 100%;
  6808. }
  6809. .lottery-content-v2 {
  6810. position: absolute;
  6811. top: 0;
  6812. left: 50%;
  6813. transform: translateX(-50%);
  6814. display: flex;
  6815. flex-direction: column;
  6816. align-items: center;
  6817. height: auto;
  6818. .lottery-header-v2 {
  6819. margin-top: 68rpx;
  6820. display: flex;
  6821. align-items: center;
  6822. .lottery-header-decoration-left,
  6823. .lottery-header-decoration-right {
  6824. width: 44rpx;
  6825. height: 20rpx;
  6826. }
  6827. .lottery-header-title {
  6828. margin: 0 12rpx;
  6829. font-size: 28rpx;
  6830. color: #FFF1BC;
  6831. margin-top: 22rpx;
  6832. }
  6833. }
  6834. .lottery-text-v2 {
  6835. font-weight: 600;
  6836. font-size: 80rpx;
  6837. color: #FFF1BC;
  6838. &:last-of-type {
  6839. margin-bottom: 56rpx;
  6840. }
  6841. }
  6842. .lottery-action-button-v2 {
  6843. width: 424rpx;
  6844. height: 96rpx;
  6845. line-height: 96rpx;
  6846. background: linear-gradient(180deg, #FBF1CA 0%, #FFD684 100%);
  6847. border-radius: 48rpx;
  6848. font-weight: 600;
  6849. font-size: 36rpx;
  6850. color: #F12E2C;
  6851. margin-bottom: 52rpx;
  6852. }
  6853. }
  6854. }
  6855. // 红包卡片弹窗
  6856. .red-card-popup {
  6857. width: 550rpx;
  6858. height: 636rpx;
  6859. position: relative;
  6860. .red-card-image {
  6861. position: absolute;
  6862. width: 100%;
  6863. height: 100%;
  6864. }
  6865. .red-card-content {
  6866. position: relative;
  6867. z-index: 5;
  6868. display: flex;
  6869. flex-direction: column;
  6870. align-items: center;
  6871. .red-card-message {
  6872. font-size: 36rpx;
  6873. color: #ff3a1e;
  6874. margin: 180rpx 0 90rpx;
  6875. }
  6876. .red-card-tip {
  6877. font-size: 28rpx;
  6878. color: #ffecc3;
  6879. margin: 80rpx 0 40rpx;
  6880. }
  6881. .red-card-confirm-button {
  6882. width: 392rpx;
  6883. height: 96rpx;
  6884. line-height: 96rpx;
  6885. background: linear-gradient(180deg, #fff4d5 0%, #ffe5b1 100%);
  6886. border-radius: 48rpx;
  6887. font-weight: 600;
  6888. font-size: 36rpx;
  6889. color: #c32008;
  6890. text-align: center;
  6891. }
  6892. }
  6893. }
  6894. // 消息弹窗
  6895. .message-popup {
  6896. display: flex;
  6897. flex-direction: column;
  6898. position: relative;
  6899. align-items: center;
  6900. padding: 126rpx 48rpx 0;
  6901. width: 554rpx;
  6902. box-sizing: border-box;
  6903. background: linear-gradient(180deg, #E2FCEF 0%, rgba(226, 252, 239, 0) 100%);
  6904. border-radius: 62rpx 62rpx 0rpx 0rpx;
  6905. .message-close-icon {
  6906. position: absolute;
  6907. z-index: 9;
  6908. top: -74rpx;
  6909. width: 176rpx;
  6910. height: 176rpx;
  6911. }
  6912. .message-title {
  6913. font-weight: 600;
  6914. font-size: 36rpx;
  6915. color: #333333;
  6916. margin: 24rpx 0 28rpx;
  6917. }
  6918. .message-content {
  6919. margin-bottom: 52rpx;
  6920. font-weight: 400;
  6921. font-size: 28rpx;
  6922. color: #333333;
  6923. }
  6924. .message-confirm-button {
  6925. width: 358rpx;
  6926. height: 88rpx;
  6927. line-height: 88rpx;
  6928. background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
  6929. border-radius: 44rpx 44rpx 44rpx 44rpx;
  6930. font-weight: 600;
  6931. font-size: 32rpx;
  6932. text-align: center;
  6933. color: #FFFFFF;
  6934. }
  6935. .close {
  6936. position: absolute;
  6937. z-index: 9;
  6938. bottom: -168rpx;
  6939. width: 64rpx;
  6940. height: 64rpx;
  6941. }
  6942. }
  6943. // 中奖弹窗
  6944. .prize-popup {
  6945. width: 504rpx;
  6946. padding: 40rpx 40rpx 30rpx;
  6947. box-sizing: border-box;
  6948. display: flex;
  6949. flex-direction: column;
  6950. border-radius: 20rpx;
  6951. align-items: center;
  6952. background: linear-gradient(180deg, #f7823f 0%, #ffd4be 27%, #ffffff 100%);
  6953. position: relative;
  6954. .prize-header-image {
  6955. width: 311rpx;
  6956. position: absolute;
  6957. top: -122rpx;
  6958. left: 50%;
  6959. transform: translateX(-50%);
  6960. }
  6961. .prize-title {
  6962. color: #c32008;
  6963. font-size: 34rpx;
  6964. font-weight: 600;
  6965. margin: 20rpx 0 40rpx;
  6966. }
  6967. .prize-info-section {
  6968. width: 100%;
  6969. display: flex;
  6970. justify-content: space-between;
  6971. align-items: center;
  6972. font-size: 28rpx;
  6973. margin: 10rpx 0;
  6974. .prize-level {
  6975. font-weight: 600;
  6976. }
  6977. }
  6978. .prize-tip {
  6979. font-size: 28rpx;
  6980. color: #414141;
  6981. margin: 40rpx 0;
  6982. }
  6983. .prize-action-button {
  6984. width: 200rpx;
  6985. height: 70rpx;
  6986. line-height: 70rpx;
  6987. background: linear-gradient(180deg, #ff7c30 0%, #ff3a1e 100%);
  6988. border-radius: 28rpx;
  6989. font-weight: 500;
  6990. font-size: 32rpx;
  6991. color: #ffffff;
  6992. text-align: center;
  6993. }
  6994. }
  6995. // 未中奖弹窗
  6996. .no-prize-popup {
  6997. width: 504rpx;
  6998. padding: 40rpx 40rpx 30rpx;
  6999. box-sizing: border-box;
  7000. display: flex;
  7001. flex-direction: column;
  7002. border-radius: 20rpx;
  7003. align-items: center;
  7004. position: relative;
  7005. .no-prize-image {
  7006. margin-top: 40rpx;
  7007. width: 300rpx;
  7008. height: 300rpx;
  7009. }
  7010. .no-prize-tip {
  7011. font-size: 36rpx;
  7012. color: #414141;
  7013. margin: 40rpx 0;
  7014. }
  7015. .no-prize-confirm-button {
  7016. width: 220rpx;
  7017. height: 80rpx;
  7018. line-height: 80rpx;
  7019. background: linear-gradient(180deg, #fdfbb8 0%, #b79243 100%);
  7020. border-radius: 28rpx;
  7021. font-weight: 500;
  7022. font-size: 32rpx;
  7023. color: #ffffff;
  7024. text-align: center;
  7025. }
  7026. }
  7027. // 中奖记录弹窗
  7028. .winning-record-popup {
  7029. position: relative;
  7030. height: 800rpx;
  7031. .winning-record-header-bg {
  7032. position: absolute;
  7033. top: -125rpx;
  7034. left: 50%;
  7035. width: 311rpx;
  7036. transform: translateX(-50%);
  7037. }
  7038. .winning-record-background {
  7039. width: 100%;
  7040. height: 100%;
  7041. }
  7042. .winning-record-content {
  7043. position: absolute;
  7044. top: 50rpx;
  7045. color: #fff;
  7046. width: 100%;
  7047. padding: 0 36rpx;
  7048. box-sizing: border-box;
  7049. .winning-record-title {
  7050. text-align: center;
  7051. font-size: 40rpx;
  7052. font-weight: 500;
  7053. margin-bottom: 40rpx;
  7054. }
  7055. .winning-record-header {
  7056. display: flex;
  7057. justify-content: space-between;
  7058. text-align: center;
  7059. font-size: 34rpx;
  7060. margin-bottom: 40rpx;
  7061. .header-column {
  7062. &.time-column {
  7063. width: 45%;
  7064. }
  7065. &.status-column {
  7066. width: 20%;
  7067. }
  7068. &.prize-column {
  7069. width: 35%;
  7070. }
  7071. }
  7072. }
  7073. .winning-record-list {
  7074. height: 500rpx;
  7075. .winning-record-item {
  7076. display: flex;
  7077. justify-content: space-between;
  7078. text-align: center;
  7079. font-size: 34rpx;
  7080. margin-bottom: 20rpx;
  7081. .record-time {
  7082. width: 45%;
  7083. font-size: 30rpx;
  7084. }
  7085. .record-status-button {
  7086. width: 20%;
  7087. background-color: #fff;
  7088. border-radius: 20rpx;
  7089. color: #f4410b;
  7090. }
  7091. .record-status {
  7092. width: 20%;
  7093. }
  7094. .record-prize {
  7095. width: 35%;
  7096. }
  7097. }
  7098. }
  7099. .no-winning-records {
  7100. font-size: 36rpx;
  7101. margin-top: 150rpx;
  7102. text-align: center;
  7103. }
  7104. }
  7105. }
  7106. // 观众列表弹窗
  7107. .viewers-list-popup {
  7108. position: relative;
  7109. height: 40vh;
  7110. padding: 40rpx 0rpx;
  7111. box-sizing: border-box;
  7112. display: flex;
  7113. flex-direction: column;
  7114. .viewers-list-title {
  7115. font-size: 32rpx;
  7116. text-align: center;
  7117. }
  7118. .viewers-scroll-list {
  7119. flex: 1;
  7120. margin-top: 50rpx;
  7121. overflow-y: auto;
  7122. padding: 0 40rpx;
  7123. .viewer-list-item {
  7124. display: flex;
  7125. align-items: center;
  7126. font-size: 28rpx;
  7127. margin: 20rpx 0;
  7128. .rank-number {
  7129. width: 50rpx;
  7130. margin-right: 10rpx;
  7131. font-weight: normal;
  7132. &.rank-1 {
  7133. color: #FF3B30;
  7134. font-weight: bold;
  7135. }
  7136. &.rank-2 {
  7137. color: #FF9500;
  7138. font-weight: bold;
  7139. }
  7140. &.rank-3 {
  7141. color: #FFCC00;
  7142. font-weight: bold;
  7143. }
  7144. &:not(.rank-1):not(.rank-2):not(.rank-3) {
  7145. color: #8E8E93;
  7146. }
  7147. }
  7148. .viewer-avatar-placeholder {
  7149. width: 72rpx;
  7150. height: 72rpx;
  7151. border-radius: 50%;
  7152. display: flex;
  7153. align-items: center;
  7154. justify-content: center;
  7155. background-color: #8978e2;
  7156. .avatar-initial {
  7157. color: #ffffff;
  7158. font-size: 24rpx;
  7159. }
  7160. }
  7161. .viewer-name {
  7162. margin-left: 16rpx;
  7163. font-size: 30rpx;
  7164. }
  7165. }
  7166. }
  7167. }
  7168. // 更多操作弹窗
  7169. .more-actions-popup {
  7170. border-radius: 20rpx 0 0 20rpx;
  7171. padding: 70rpx 30rpx;
  7172. display: flex;
  7173. justify-content: space-between;
  7174. .more-action-item {
  7175. display: flex;
  7176. flex-direction: column;
  7177. align-items: center;
  7178. .action-icon {
  7179. width: 48rpx;
  7180. height: 48rpx;
  7181. }
  7182. .action-label {
  7183. color: #1e1e1e;
  7184. text-align: center;
  7185. margin-top: 10rpx;
  7186. }
  7187. }
  7188. }
  7189. // 商品弹窗
  7190. .shopping-popup {
  7191. padding: 22rpx 16rpx;
  7192. .shopping-header {
  7193. display: flex;
  7194. justify-content: space-between;
  7195. align-items: center;
  7196. padding: 0 16rpx 22rpx;
  7197. .search-input-container {
  7198. width: 414rpx;
  7199. height: 76rpx;
  7200. background: #ffffff;
  7201. border-radius: 36rpx;
  7202. margin-left: 20rpx;
  7203. padding: 0 32rpx;
  7204. box-sizing: border-box;
  7205. font-size: 24rpx;
  7206. margin-right: 24rpx;
  7207. display: flex;
  7208. align-items: center;
  7209. color: #000;
  7210. .search-icon {
  7211. width: 24rpx;
  7212. margin-right: 16rpx;
  7213. }
  7214. }
  7215. .shopping-action-button {
  7216. display: flex;
  7217. flex-direction: column;
  7218. align-items: center;
  7219. font-size: 20rpx;
  7220. color: #222222;
  7221. .action-button-icon {
  7222. width: 48rpx;
  7223. height: 48rpx;
  7224. }
  7225. .action-button-label {
  7226. text-align: center;
  7227. }
  7228. }
  7229. }
  7230. .products-list {
  7231. height: 30vh;
  7232. overflow: hidden;
  7233. .product-item {
  7234. display: flex;
  7235. align-items: center;
  7236. padding: 20rpx 16rpx;
  7237. background: #ffffff;
  7238. border-radius: 16rpx;
  7239. margin-bottom: 16rpx;
  7240. .product-image-container {
  7241. width: 200rpx;
  7242. height: 200rpx;
  7243. border-radius: 16rpx;
  7244. overflow: hidden;
  7245. position: relative;
  7246. margin-right: 24rpx;
  7247. .product-image {
  7248. width: 100%;
  7249. height: 100%;
  7250. }
  7251. .product-index-label {
  7252. position: absolute;
  7253. top: 0;
  7254. width: 64rpx;
  7255. height: 40rpx;
  7256. background: var(--normal-bg);
  7257. border-radius: 16rpx 0rpx 16rpx 0rpx;
  7258. text-align: center;
  7259. font-weight: 500;
  7260. font-size: 28rpx;
  7261. color: var(--text-color);
  7262. }
  7263. }
  7264. .product-info {
  7265. flex: 1;
  7266. .product-name {
  7267. font-weight: 500;
  7268. font-size: 30rpx;
  7269. color: #000000;
  7270. margin-bottom: 10rpx;
  7271. }
  7272. .product-sales {
  7273. font-size: 22rpx;
  7274. color: #e69a22;
  7275. height: 56rpx;
  7276. }
  7277. .product-action-section {
  7278. display: flex;
  7279. justify-content: space-between;
  7280. align-items: center;
  7281. .product-price {
  7282. color: #ff5c03;
  7283. font-size: 22rpx;
  7284. font-weight: 500;
  7285. .price-symbol {
  7286. font-size: 20rpx;
  7287. font-weight: 600;
  7288. }
  7289. .price-integer {
  7290. font-size: 36rpx;
  7291. font-weight: bold;
  7292. }
  7293. }
  7294. .product-action-buttons {
  7295. display: flex;
  7296. align-items: center;
  7297. text-align: center;
  7298. line-height: 56rpx;
  7299. .collect-button {
  7300. width: 72rpx;
  7301. height: 100%;
  7302. background: #f5f7fa;
  7303. border-radius: 8rpx 0rpx 0rpx 8rpx;
  7304. .collect-icon {
  7305. width: 36rpx;
  7306. height: 36rpx;
  7307. vertical-align: middle;
  7308. }
  7309. }
  7310. .buy-button {
  7311. width: 152rpx;
  7312. background: linear-gradient(270deg, #ff5c03 0%, #ffac64 100%);
  7313. border-radius: 0rpx 8rpx 8rpx 0rpx;
  7314. font-weight: 500;
  7315. font-size: 30rpx;
  7316. color: #ffffff;
  7317. &.disabled {
  7318. background: #cccccc;
  7319. }
  7320. }
  7321. }
  7322. }
  7323. }
  7324. }
  7325. }
  7326. }
  7327. .end {
  7328. justify-content: flex-end;
  7329. }
  7330. .progress-countdown {
  7331. position: absolute;
  7332. right: 20rpx;
  7333. top: calc(60% - 128rpx);
  7334. z-index: 9000;
  7335. width: 180rpx;
  7336. background: rgba(0, 0, 0, 0.3);
  7337. border-radius: 16rpx;
  7338. padding: 16rpx;
  7339. flex-direction: column;
  7340. &.progress-vertical {
  7341. top: 15%;
  7342. left: 24rpx;
  7343. }
  7344. .title {
  7345. width: 148rpx;
  7346. height: 28rpx;
  7347. }
  7348. .progress-bar-bg {
  7349. width: 148rpx;
  7350. height: 8rpx;
  7351. margin-top: 16rpx;
  7352. background: #FFFFFF;
  7353. border-radius: 6rpx 6rpx 6rpx 6rpx;
  7354. overflow: hidden;
  7355. margin-bottom: 16rpx;
  7356. .progress-bar-fill {
  7357. height: 100%;
  7358. // background: linear-gradient(90deg, #4CAF50, #8BC34A);
  7359. background: #FACE15;
  7360. border-radius: 6rpx 6rpx 6rpx 6rpx;
  7361. transition: width 1s linear;
  7362. }
  7363. }
  7364. .progress-text {
  7365. color: #fff;
  7366. font-size: 20rpx;
  7367. }
  7368. }
  7369. // 优惠券弹窗
  7370. .coupon-popup {
  7371. position: fixed;
  7372. bottom: 140rpx;
  7373. right: 100rpx;
  7374. z-index: 5;
  7375. border-radius: 20rpx;
  7376. width: 320rpx;
  7377. .coupon-container {
  7378. width: 100%;
  7379. position: relative;
  7380. .coupon-background {
  7381. height: 452rpx;
  7382. width: 100%;
  7383. }
  7384. .coupon-header {
  7385. position: absolute;
  7386. height: 120rpx;
  7387. top: -120rpx;
  7388. left: 0;
  7389. width: 100%;
  7390. z-index: 6;
  7391. }
  7392. .coupon-close-button {
  7393. position: absolute;
  7394. right: 10rpx;
  7395. top: 10rpx;
  7396. width: 40rpx;
  7397. height: 40rpx;
  7398. z-index: 99;
  7399. }
  7400. .coupon-content {
  7401. width: 100%;
  7402. position: absolute;
  7403. top: 20rpx;
  7404. display: flex;
  7405. flex-direction: column;
  7406. align-items: center;
  7407. color: #fff;
  7408. .coupon-name {
  7409. font-weight: 500;
  7410. font-size: 30rpx;
  7411. margin: 16rpx 0 12rpx;
  7412. }
  7413. .coupon-price {
  7414. font-size: 40rpx;
  7415. .coupon-price-integer {
  7416. font-size: 56rpx;
  7417. font-weight: 600;
  7418. }
  7419. }
  7420. .coupon-condition,
  7421. .coupon-description,
  7422. .coupon-validity {
  7423. font-weight: 500;
  7424. font-size: 30rpx;
  7425. margin: 5rpx 0;
  7426. }
  7427. .coupon-description {
  7428. margin-top: 26rpx;
  7429. }
  7430. .coupon-get-button {
  7431. background: linear-gradient(270deg, #fffce1 0%, #ffeaaf 100%);
  7432. color: #ff0004;
  7433. text-align: center;
  7434. padding: 16rpx 0;
  7435. border-radius: 40rpx;
  7436. font-weight: 500;
  7437. font-size: 30rpx;
  7438. width: 70%;
  7439. margin-top: 26rpx;
  7440. }
  7441. }
  7442. }
  7443. }
  7444. }
  7445. }
  7446. </style>