living - two.vue 216 KB

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