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