living.vue 175 KB

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