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