living.vue 171 KB

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