living.vue 222 KB

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