living.vue 195 KB

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