livingQj.vue 221 KB

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