living.vue 167 KB

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