living.vue 169 KB

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