living.vue 181 KB

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