living.vue 226 KB

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