living.vue 217 KB

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