living.vue 185 KB

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