living.vue 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697
  1. <template>
  2. <view class="swiper-wrapper">
  3. <view class="container">
  4. <view class="content">
  5. <view style="position: fixed;top: 0;z-index: 5;" class="content-top">
  6. <view class="x-f">
  7. <image v-if="!scene" @click="goBack" class="w60 h64 mr26" src="/static/images/return3.png" />
  8. <view class="align-center"
  9. style="padding: 6rpx 8rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  10. <u-avatar :src="liveItem.liveImgUrl||'/static/images/avatar.png'" :size="32"></u-avatar>
  11. <view class="colorf ml10 mr6">
  12. <view>{{liveItem.liveName?truncateString(liveItem.liveName,8):"未命名"}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view v-if="Array.isArray(filteredViewers)" class=" align-center" @click="toggleViewerList"
  17. style="margin-top: 120rpx;">
  18. <view v-for="(item,viewerIndex) in filteredViewers" :key="viewerIndex">
  19. <image v-if="item.avatar" class="w52 h52 mr4" style="border-radius: 26rpx;"
  20. :src="item.avatar" />
  21. <view v-else class="w52 h52 mr4"
  22. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  23. <text class="text-white text-xs">{{getNicknameInitial(item.nickName)}}</text>
  24. </view>
  25. </view>
  26. <view class="sum">{{liveUserTotal||0}}</view>
  27. </view>
  28. </view>
  29. <!-- 右边的side -->
  30. <view class="side-group">
  31. <view class="side-item" @click="onLike">
  32. <LikeButton :initialCount="100" :heartsPerClick="5" @like="onLike" />
  33. <view>{{liveViewData && liveViewData.like||0}}</view>
  34. </view>
  35. <view class="side-item">
  36. <button open-type="share" class="button">
  37. <image class="image" src="/static/images/weixin.png" mode="widthFix" />
  38. </button>
  39. <view>分享</view>
  40. </view>
  41. </view>
  42. <view class="activity-box">
  43. <view class="item-box" @click="onRed()" v-if="isShowRed">
  44. <view class="x-f">
  45. <view class="tip">领红包</view>
  46. <view class="item">
  47. <image class="w70 img" src="/static/images/redbag.png" mode="widthFix" />
  48. </view>
  49. </view>
  50. </view>
  51. <view class="item-box" @click="onLottery()" v-if="isShowLottery&&countdown">
  52. <view class="x-f">
  53. <view class="tip">抽奖</view>
  54. <view class="item">
  55. <image class="w60" src="/static/images/lottery.png" mode="widthFix" />
  56. </view>
  57. </view>
  58. </view>
  59. <!-- v-if="isShowCoupon" -->
  60. <!-- <view class="item-box" @click="isShowCoupon=true">
  61. <view class="x-f">
  62. <view class="tip">优惠券</view>
  63. <view class="item">
  64. <image class="w60" src="/static/images/coupon.png" mode="widthFix" />
  65. </view>
  66. </view>
  67. </view> -->
  68. </view>
  69. <view class="shop-prompt f30 x-f"
  70. v-if="showPurchasePrompt&&orderUser&&orderUser.count&&liveItem.status==2">
  71. <image class="w32 h32 mr8" src="/static/images/shopping.png" />
  72. <text>{{ orderUser.count || 0 }}人正在去购买</text>
  73. </view>
  74. <view class="videolist" v-if="liveItem.status==2">
  75. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  76. <!-- 视频组件 -->
  77. <live-player v-if="liveItem.livingUrl && liveItem.liveType == 1" :id="'myLivePlayer_' + liveId"
  78. :src="liveItem.livingUrl" autoplay mode="live" object-fit="contain" :muted="false"
  79. orientation="vertical" :enable-play-gesture="true" min-cache="1" max-cache="3"
  80. @statechange="onLiveStateChange($event, liveItem)" @error="onLiveError($event, liveItem)"
  81. class="item"></live-player>
  82. <!-- 录播 -->
  83. <video v-if="liveItem.videoUrl&&liveItem.liveType==2" :id="`myVideo_${liveId}`" class="item"
  84. :src="liveItem.videoUrl" :controls="false" object-fit="contain" :custom-cache="false"
  85. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="true"
  86. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  87. @timeupdate="onVideoTimeUpdate" @loadeddata="onVideoLoaded"
  88. @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay">
  89. </video>
  90. <!-- 直播回放 -->
  91. <video v-if="liveItem.videoUrl&&liveItem.liveType==3" :id="`myVideo_${liveId}`" class="item"
  92. :src="liveItem.videoUrl" :controls="true" object-fit="contain" :custom-cache="false"
  93. :enable-progress-gesture="liveItem.isSpeedAllowed" vslide-gesture-in-fullscreen="true"
  94. :show-center-play-btn="true" :http-cache="false" loop @error="videoError"
  95. @timeupdate="onVideoTimeUpdate" @loadeddata="onVideoLoaded"
  96. @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay"
  97. @seek="onVideoSeek">
  98. </video>
  99. <view v-if="liveItem.videoUrl&&liveItem.liveType==2" class="time">{{liveItem.totalTime}}
  100. </view>
  101. <view v-if="liveItem.videoUrl&&liveItem.liveType==3" class="lable">直播回放</view>
  102. </view>
  103. </view>
  104. <view class="trailer-box" v-if="liveItem.status==1">
  105. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="item" :src="liveItem.previewUrl"
  106. :autoplay="true" :controls="false" object-fit="contain" :custom-cache="false"
  107. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  108. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  109. @loadeddata="onVideoLoaded" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  110. @play="onVideoPlay" :disable-progress="true">
  111. </video>
  112. <image v-if="liveItem.status==1&&!liveItem.previewUrl" class="img" src="/static/images/no_live.png">
  113. </image>
  114. <view class="countdown-item mt30 mb30" v-if="liveItem.status==1&&liveCountdown">
  115. 开播倒计时
  116. <view class="x-f">
  117. <view class="white">
  118. {{liveCountdown.hours||"00"}}
  119. </view>
  120. <view class="white">
  121. {{ liveCountdown.minutes||"00"}}
  122. </view>
  123. <view class="white">
  124. {{ liveCountdown.seconds||"00" }}
  125. </view>
  126. </view>
  127. </view>
  128. <view class="name"> {{liveItem.liveName}}</view>
  129. <view class="title" v-if="liveCountdown">暂未开播</view>
  130. <view class="button" v-if="!isAgreement" @click="handleAgreement">预约直播</view>
  131. <view class="button ash" v-if="isAgreement">已预约</view>
  132. <view class="title" v-if="!liveCountdown">主播还在来的路上</view>
  133. </view>
  134. <view class="trailer-box" v-if="!liveItem">
  135. <image class="img" src="/static/images/no_live.png">
  136. </image>
  137. <view class="title">暂无直播</view>
  138. </view>
  139. <!-- 底部聊天区域 -->
  140. <view :style="{position: 'fixed',width: '100%',bottom: chatHeight + 'rpx',zIndex:999}">
  141. <view class="mt20" :style="{ height: chatHeight ? '64rpx' : '30vh' }">
  142. <scroll-view v-if="Array.isArray(talklist)" enable-flex scroll-y="true"
  143. class=" pl20 scrolly flex-1 column" style="width: calc(100% - 20rpx); height: 100%;"
  144. :scroll-into-view="scrollIntoView">
  145. <view class="list justify-start" v-for="(item,talkIndex) in (talklist||[])" :key="talkIndex"
  146. :id="`list_${talkIndex}`" v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  147. <view class="talk-list justify-start">
  148. <view class="fs30" style="max-width: 100%;">
  149. <text style="color: #FFDA73;">{{item.nickName||"未命名"}}:</text>
  150. <text class='colorf'>{{item.msg}}</text>
  151. </view>
  152. </view>
  153. </view>
  154. <view v-if="showWelcomeMessage" class="welcome-message" style="max-width: 100%;">
  155. <view class="list justify-start" v-show="inAndOut.cmd=='entry'||inAndOut.cmd=='out'">
  156. <view class="talk-list justify-start">
  157. <view class="fs30">
  158. <text style="color: #ff89d6;">{{inAndOut.nickName||"未命名"}} </text>
  159. <text class='colorf'>
  160. {{inAndOut.msg}}直播间</text>
  161. </view>
  162. </view>
  163. </view>
  164. </view>
  165. </scroll-view>
  166. </view>
  167. <!-- 底部输入框和操作按钮 -->
  168. <view :class="{'justify-between': true,'p24': true,'pb40': isFocus}"
  169. :style="{background: isFocus ? '#fff' : 'transparent',}">
  170. <view class="x-f"
  171. :style="{background: isFocus ? '#ededed' : '#393939' ,padding: '10rpx 14rpx 10rpx 32rpx',boxSizing: 'border-box',borderRadius: '36rpx',width: isFocus ? '100%' : '580rpx'}">
  172. <u-input :placeholder="placeholderText" border="none" customStyle='font-size:24rpx;'
  173. v-model="value" shape='circle' :color="isFocus ? '#000000' : '#ffffff'"
  174. :placeholderStyle="{color:isFocus ? '#888888' : '#e7e7e7' }" :adjust-position="false"
  175. :scroll-with-animation="false" class="ml20" @focus="inputFocus" @blur="inputBlur">
  176. </u-input>
  177. <view :class="isFocus ? 'send-input' : 'send'" @click="sendMsg()">发送</view>
  178. </view>
  179. <view class="justify-between mr15 align-center" v-if="!isFocus">
  180. <view class="icon-bg ml20" @click="openCart()">
  181. <image src="/static/images/shopping.png" class="w58 h58" />
  182. </view>
  183. </view>
  184. </view>
  185. </view>
  186. </view>
  187. <view class="goods" v-if="isShowGoods">
  188. <view class="top">
  189. <view class="left">
  190. <image class="w30 h30 mr8" src="/static/images/signal.png" />讲解中
  191. </view>
  192. <image @click="isShowGoods=false" class="w40 h40 " src="/static/images/del2.png" />
  193. </view>
  194. <image class="photo" :src="goodsCard.imgUrl" />
  195. <view class="item">
  196. <view class="price"><text class="red">¥{{goodsCard.price}} </text><text
  197. class="del">¥{{goodsCard.otPrice}}</text></view>
  198. <view class="title oneline-hide">{{goodsCard.productName}}</view>
  199. <view class="button" @click="goShop(goodsCard.productId,goodsCard.goodsId)">
  200. 立即抢购
  201. </view>
  202. </view>
  203. </view>
  204. <u-popup :show="isShowLotteryPop&&countdown" round='40rpx'>
  205. <view class="prize-box" style="border-radius: 40rpx;height: fit-content;">
  206. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  207. <image class="bg-img " src="/static/images/red_bg.png" />
  208. <view class="prize-content">
  209. <view class=" mr20">
  210. <u-icon class="x-end" name="close" color="#fff" size="20"
  211. @click="isShowLotteryPop=false"></u-icon>
  212. </view>
  213. <view class="column align-center ">
  214. <image class="w446 h80" src="/static/images/red_title.png" />
  215. <view class="fs24 colorf x-f mt30 mb30">
  216. 开奖倒计时
  217. <view class="x-f">
  218. <view class="white-item">
  219. {{countdown.hours||"00"}}
  220. </view>
  221. <view class="white-item">
  222. {{ countdown.minutes||"00" }}
  223. </view>
  224. <view class="white-item">
  225. {{ countdown.seconds||"00" }}
  226. </view>
  227. </view>
  228. </view>
  229. <view class="item-group">
  230. <ThreeItemSwiper :products="lotteryProducts"></ThreeItemSwiper>
  231. </view>
  232. <view class="point-group" v-for="(item,index) in lotteryProducts" :key="index">
  233. </view>
  234. <view class="colorf fs28">
  235. 观看直播参与抽奖
  236. </view>
  237. <view class="button" @click="onClaim">参与抽奖</view>
  238. </view>
  239. </view>
  240. </view>
  241. </u-popup>
  242. <u-popup :show="!!integral.status" round='20rpx' mode="center" bgColor='#ffffff' zIndex='10076'>
  243. <view class="integral-box">
  244. <view class="top">
  245. <view class="title">观看视频领芳华币</view>
  246. <image class="photo" src="/static/images/integral_bg.png" mode="widthFix" />
  247. </view>
  248. <view class="item">
  249. <view class="title ">{{integral.msg}}</view>
  250. <view class="button" @click="integral.status=false">确认</view>
  251. </view>
  252. </view>
  253. </u-popup>
  254. <u-popup :show="isShowRedCard" round='20rpx' mode="center" bgColor='transparent' zIndex='10076'>
  255. <view class="red-card">
  256. <image class="img" src="/static/images/red_card.png" />
  257. <view class="red-content">
  258. <view class="title">{{redCard.msg}}</view>
  259. <view class="txt ">直播惊喜芳华币</view>
  260. <view class="button" @click="isShowRedCard=false">确认</view>
  261. </view>
  262. </view>
  263. </u-popup>
  264. <!-- 中奖和未中奖 -->
  265. <u-popup :show="isShowPrize" round='20rpx' mode="center" bgColor='#fff' zIndex='10076'>
  266. <view class="prize-card" v-if="isCurrentUserWon">
  267. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  268. <view class="title">{{prizeInfo.length}}位幸运观众</view>
  269. <view class="prize-content" v-for="(item,index) in (prizeInfo||[])" :key="index">
  270. <view>{{item.userName}}</view>
  271. <view>{{item.userId}}</view>
  272. <view class="txt">{{item.prizeLevel}}等奖</view>
  273. </view>
  274. <view class="tip">请截图联系客服领取奖品</view>
  275. <view class="button" @click="isShowPrize=false">确认</view>
  276. </view>
  277. <view class="no-prize-card" v-else>
  278. <image class="img" src="/static/images/no-prize.png" mode="widthFix" />
  279. <view class="tip">很遗憾 您未中奖</view>
  280. <view class="button" @click="isShowPrize=false">确认</view>
  281. </view>
  282. </u-popup>
  283. <!-- 观众列表弹窗 -->
  284. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff' zIndex='10077'>
  285. <view class="view-box">
  286. <view class="fs32" style="text-align: center;">在线观众</view>
  287. <scroll-view v-if="Array.isArray(liveViewers)" scroll-y class="scroll-content"
  288. :style="{height: scrollHeight + 'px'}" @scrolltolower="handleScrollToLower">
  289. <view class="fs28 x-f mb20 mt20" v-for="(item,index) in (liveViewers||[])" :key="index">
  290. <view
  291. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  292. class="mr10">{{index+1}}</view>
  293. <u-avatar v-if="item.avatar" :src="item.avatar" :size="36"></u-avatar>
  294. <view v-else class="w72 h72"
  295. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  296. <text class="text-white text-xs">{{getNicknameInitial(item.nickName)}}</text>
  297. </view>
  298. <text class="ml16 f30">{{item.nickName||"未命名"}}</text>
  299. </view>
  300. </scroll-view>
  301. </view>
  302. </u-popup>
  303. <!-- 商品弹窗 -->
  304. <u-popup :show="shopping" @close="closeShop" round='20rpx' bgColor='#f3f5f9' zIndex='10075'>
  305. <view class="shoppop">
  306. <view class="shoppop-top">
  307. <view class="search-input x-f">
  308. <image class="w24 mr16" src="/static/images/search.png" mode="widthFix" />
  309. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  310. </view>
  311. <view class=" search-top" @click="goOrderList()">
  312. <image class="w48 h48" src="/static/images/order.png" />
  313. <view>订单</view>
  314. </view>
  315. </view>
  316. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  317. <view class="list-item" v-for="(item,index) in products" :key="index">
  318. <view class="goods-img">
  319. <image class="img" :src="item.imgUrl" mode="widthFix" />
  320. <view class="goods-label">{{index+1}}</view>
  321. </view>
  322. <view class="goods-right">
  323. <view class="goods-title">{{item.productName}}</view>
  324. <view class="goods-people">{{item.sales}} 人已购</view>
  325. <view class="goods-shop">
  326. <text class="nummber"><text style="font-size: 20rpx;font-weight: 600;">¥</text><text
  327. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}</text>
  328. <view class="btn-group x-f">
  329. <view class="collect-btn">
  330. <image v-if="item.isFavorite" @click="onGoodsCollect(item)" class="w36 h36"
  331. style="vertical-align: middle;"
  332. src="/static/images/collect_select.png" />
  333. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  334. style="vertical-align: middle;" src="/static/images/collect.png" />
  335. </view>
  336. <view v-if="item.status==1" class="shop-btn"
  337. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  338. <view v-else-if="item.status==0" class="shop-btn">
  339. 已下架</view>
  340. </view>
  341. </view>
  342. </view>
  343. </view>
  344. </scroll-view>
  345. </view>
  346. </u-popup>
  347. <!-- 优惠券弹窗 -->
  348. <view class="coupon-pop" v-if="isShowCoupon">
  349. <view class="coupon-block">
  350. <image class="bg" src="/static/images/coupon_bg.png" />
  351. <image class="nav" src="/static/images/coupon_top.png" />
  352. <image @click="isShowCoupon=false" class="w40 h40 close" src="/static/images/close1.png" />
  353. <view class="item">
  354. <view class="title">{{couponInfo.couponName}}</view>
  355. <view class="price">¥<text class="bold">{{couponInfo.couponPrice}}</text></view>
  356. <view class="txt">满{{couponInfo.useMinPrice}}元可用</view>
  357. <view class="txt" style="margin-top: 26rpx;">指定商品可用</view>
  358. <view class="txt">自领取起{{couponInfo.couponTime}}天内有效</view>
  359. <view class="button" @click="onCoupon()">
  360. 立即领券
  361. </view>
  362. </view>
  363. </view>
  364. </view>
  365. <!-- <u-popup :show="true" @close="closeShop" round='20rpx' bgColor='#f3f5f9' zIndex='10075'>
  366. <view class="coupon">
  367. <view class="coupon-top">
  368. <view class=" search-top">
  369. <image class="w48 h48" src="/static/images/order.png" />
  370. <view>我的券码</view>
  371. </view>
  372. </view>
  373. <scroll-view enable-flex scroll-y :style="{ height: boxHeight + 'px' }">
  374. <div class="coupon-list" v-if="couponsList.length > 0">
  375. <div class="item acea-row row-center-wrapper" v-for="(item, index) in couponsList"
  376. :key="index">
  377. <div class="money">
  378. <image v-if="item.status==0" class="img" src="/static/images/coupon1.png"
  379. mode="widthFix"></image>
  380. <image v-if="item.status!=0" class="img" src="/static/images/coupon2.png"
  381. mode="widthFix"></image>
  382. <div style="z-index: 999;">
  383. ¥<span class="num">{{ item.couponPrice }}</span>
  384. </div>
  385. <div class="pic-num">满{{ item.useMinPrice }}元可用</div>
  386. </div>
  387. <div class="text">
  388. <div class="condition line1">
  389. {{ item.couponTitle }}
  390. </div>
  391. <div class="data acea-row row-between-wrapper">
  392. <div>{{ item.limitTime }}到期</div>
  393. <div class="bnt gray" v-if="item.status==1">已使用</div>
  394. <div class="bnt gray" v-if="item.status==-1">已过期</div>
  395. <div class="bnt bg-color-red" v-if="item.status==0">可使用</div>
  396. </div>
  397. </div>
  398. </div>
  399. </div>
  400. </scroll-view>
  401. <view v-if="couponsList.length == 0" class="no-data-box" @click="getMyCouponList()">
  402. <image src="/static/images/no_data.png" mode="aspectFit"></image>
  403. <view class="empty-title">暂无数据</view>
  404. </view>
  405. </view>
  406. </u-popup> -->
  407. <!-- <u-popup :show="true" @close="closeShop" round='20rpx' bgColor='#f3f5f9' zIndex='10075'>
  408. <view class="coupon">
  409. <scroll-view enable-flex scroll-y :style="{ height: boxHeight + 'px' }">
  410. <div class="coupon-list" v-if="couponsList.length > 0">
  411. <div class="item acea-row row-center-wrapper" v-for="(item, index) in couponsList"
  412. :key="index">
  413. <div class="money">
  414. <image v-if="item.status==0" class="img" src="/static/images/coupon1.png"
  415. mode="widthFix"></image>
  416. <image v-if="item.status!=0" class="img" src="/static/images/coupon2.png"
  417. mode="widthFix"></image>
  418. <div style="z-index: 999;">
  419. ¥<span class="num">{{ item.couponPrice }}</span>
  420. </div>
  421. <div class="pic-num">满{{ item.useMinPrice }}元可用</div>
  422. </div>
  423. <div class="text">
  424. <div class="condition line1">
  425. {{ item.couponTitle }}
  426. </div>
  427. <div class="data acea-row row-between-wrapper">
  428. <div>{{ item.limitTime }}到期</div>
  429. <div class="bnt gray" v-if="item.status==1">已使用</div>
  430. <div class="bnt gray" v-if="item.status==-1">已过期</div>
  431. <div class="bnt bg-color-red" v-if="item.status==0">可使用</div>
  432. </div>
  433. </div>
  434. </div>
  435. </div>
  436. </scroll-view>
  437. <view v-if="couponsList.length == 0" class="no-data-box" @click="getMyCouponList()">
  438. <image src="/static/images/no_data.png" mode="aspectFit"></image>
  439. <view class="empty-title">暂无数据</view>
  440. </view>
  441. </view>
  442. </u-popup> -->
  443. </view>
  444. </view>
  445. </template>
  446. <script>
  447. import LikeButton from '@/pages_course/components/like.vue'
  448. import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue'
  449. import CryptoJS from 'crypto-js'
  450. import {
  451. coupon, //领取优惠券
  452. liveLottery, // 抽奖查询
  453. claim, //抽奖
  454. liveRed, // 点击领红包
  455. liveDataLike, // 点赞
  456. collectStore, // 店铺收藏/取消收藏
  457. collectGoods, // 商品收藏/取消收藏
  458. watchUserList, //获取直播间用户(展示在线用户)
  459. liveMsg, //获取最近聊天记录
  460. // 小黄车
  461. liveStore, //店铺展示,
  462. liveOrderUser, //正在购买
  463. getLiveInfo, //获取直播间信息接口
  464. getLiveViewData, //直播间点赞、关注、在线人数数据
  465. currentActivities, //红包 卡片 抽奖
  466. getlive,
  467. subNotifyLive
  468. } from '@/api/living.js'
  469. import {
  470. getUserInfo
  471. } from '@/api/user'
  472. import {
  473. nextTick
  474. } from "vue"
  475. // var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
  476. // var pingpangTimes = null;
  477. // var initTimes = null;
  478. var isSocketOpen = false;
  479. var socket = null;
  480. export default {
  481. components: {
  482. ThreeItemSwiper,
  483. LikeButton
  484. },
  485. data() {
  486. return {
  487. isOnload: false,
  488. isConnecting: false, // 是否正在连接中
  489. previousToken: null,
  490. hasInitialized: false,
  491. couponsList: [{
  492. status: 0,
  493. couponPrice: 59,
  494. useMinPrice: 99,
  495. couponTitle: '包装袋',
  496. limitTime: 2
  497. }],
  498. liveViewersData: [],
  499. liveUserCalled: false, //调用过watchUserList没
  500. liveViewDataTimer: null,
  501. userRandomColors: {}, // 缓存用户ID -> 随机色的映射
  502. randomColor: '#8978e2',
  503. heartBeatRetryCount: 0, // 心跳发送重试次数(避免一次失败就重连)
  504. maxHeartBeatRetries: 2, // 心跳最大重试次数
  505. pingTimeout: 20000, // 心跳超时时间从10s延长到20s(应对网络波动)
  506. shownEntryUsers: new Set(), // 存储已显示过「进入提示」的用户ID
  507. isPageUnloading: false, // 标记页面是否正在卸载(区分主动离开vs重连out)
  508. templateId: 'fxYJu817lxHNKXl0hJypb54UnGRCNAoI72Qf-xjKCik',
  509. isAgreement: false,
  510. socket: null, // WebSocket 实例
  511. isSocketOpen: false, // 连接是否已打开
  512. heartBeatTimer: null, // 心跳定时器
  513. heartBeatInterval: 15000, // 心跳发送间隔(15秒)
  514. reconnectTimer: null, // 重连定时器
  515. reconnectCount: 0, // 当前重连次数
  516. maxReconnectAttempts: 3, // 最大重连次数
  517. isManualClose: false, // 是否手动关闭(用于区分主动关闭和异常断开)
  518. // pingTimeout: 10000, // 心跳响应超时时间(10秒)
  519. pingTimeoutTimer: null, // 心跳超时定时器
  520. // wsNewUrl: 'ws://192.168.10.126:7014/app/webSocket',
  521. // wsNewUrl: 'wss://api.fhhx.runtzh.com/app/webSocket',
  522. wsNewUrl: 'wss://api.fhhx.runtzh.com/ws/app/webSocket',
  523. // wsNewUrl: 'ws://192.168.10.166:7114/ws/app/webSocket',
  524. // wsNewUrl:'ws://192.168.10.166:7014/app/webSocket',
  525. qrFrom: null,
  526. scene: '',
  527. liveCountdown: {},
  528. countdown: {},
  529. liveViewData: {},
  530. chatHeight: 0,
  531. keyboardHeight: 0,
  532. videoCurrentTime: 0, // 当前视频播放时间
  533. isVideoPlaying: false, // 视频是否正在播放
  534. videoProgressKey: '', // 存储进度的key
  535. inAndOut: {},
  536. isShowPrize: false,
  537. isShowCoupon: false,
  538. prizeInfo: [],
  539. timeData: {},
  540. countDownKey: 0,
  541. lotteryProducts: [],
  542. lotteryList: [],
  543. talklist: [],
  544. isShowLotteryPop: false,
  545. liveItem: {},
  546. isSending: false,
  547. welcomeTimer: null,
  548. redTimer: null,
  549. liveStartTimer: null,
  550. lotteryTimer: null,
  551. isShowLottery: false,
  552. isShowRedCard: false,
  553. redCard: null, //点击红包出现弹窗
  554. integral: {},
  555. lotteryInfo: {},
  556. goodsCard: {},
  557. couponInfo: {},
  558. redInfo: {},
  559. storeId: null,
  560. isFocus: false,
  561. shopping: false,
  562. inputInfo: '',
  563. showWelcomeMessage: false,
  564. scrollIntoView: '',
  565. isShowGoods: false,
  566. isShowRed: false,
  567. lastClickTime: 0,
  568. clickDelay: 300, // 300ms内只响应一次点击
  569. videoRetryCounts: {}, // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  570. placeholderText: '说点什么...',
  571. liveUserTotal: 0,
  572. viewPageSize: 10, // 每页数量
  573. viewPageNum: 1, // 当前页码
  574. viewLoading: false, // 是否正在加载
  575. scrollHeight: 0,
  576. scrollTimer: null, // 滚动防抖定时器
  577. showRed: true,
  578. searchTimer: null,
  579. isCollect: false,
  580. showPurchasePrompt: false,
  581. purchasePromptTimer: null,
  582. prevOrderCount: 0, // 用于记录上一次的购买人数
  583. videoUrl: null,
  584. showType: 1, //横屏1 竖屏2
  585. boxHeight: 300, //小黄车高度
  586. liveViewers: [], //观众
  587. likeName: 0,
  588. hlsPlayer: null, // HLS播放器实例,
  589. livingUrl: "",
  590. products: [],
  591. store: {},
  592. orderUser: {}, //正在购买
  593. userType: 0,
  594. timestamp: '',
  595. liveId: null,
  596. userinfo: '', //用户信息
  597. // path: 'http://192.168.10.166/dev-api', //余红奇
  598. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  599. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  600. value: '',
  601. talkdisabled: false, //输入框是否禁用
  602. autoplay: false, //视频自动播放
  603. showadd: false,
  604. videoContext: '',
  605. livedata: {}, //直播间点赞、关注、在线人数数据
  606. userData: {},
  607. };
  608. },
  609. onLoad(options) {
  610. if (options.liveId) {
  611. this.liveId = options.liveId;
  612. }
  613. this.getUserInfo()
  614. this.previousToken = uni.getStorageSync('AppToken')
  615. this.initTime();
  616. this.userinfo = uni.getStorageSync("userInfo")
  617. this.userData = uni.getStorageSync("userData")
  618. console.log("全部参数", options)
  619. //获取键盘高度
  620. this.keyboardListener = uni.onKeyboardHeightChange(res => {
  621. console.log('键盘高度', res.height);
  622. this.keyboardHeight = res.height * 2;
  623. });
  624. // 扫码传来的参数
  625. if (options.scene) {
  626. this.scene = options.scene;
  627. const decodedScene = decodeURIComponent(this.scene);
  628. const params = {};
  629. decodedScene.split('&').forEach(item => {
  630. const [key, value] = item.split('=');
  631. params[key] = value;
  632. this.liveId = params.a;
  633. })
  634. if (params.b && params.c) {
  635. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  636. }
  637. }
  638. if (options.companyId && options.companyUserId) {
  639. this.qrFrom = `&companyId=${options.companyId}&companyUserId=${options.companyUserId}`;
  640. }
  641. // 初始化直播间列表
  642. this.$nextTick(() => {
  643. if (this.liveId) {
  644. this.getliving(this.liveId);
  645. this.isOnload = true
  646. } else {
  647. console.error("直播间 ID(liveId)未获取到");
  648. }
  649. })
  650. // if (!this.previousToken) {
  651. // console.log("未检测到AppToken,跳转到登录页");
  652. // // let backUrl = '/pages_course/living?liveId=' + (this.liveId || '');
  653. // uni.navigateTo({
  654. // url: '/pages/auth/login?&isLive=ture'
  655. // });
  656. // return;
  657. // }
  658. },
  659. async onShow() {
  660. if (this.liveId && !this.isOnload) {
  661. await this.getLiveMsg(this.liveItem);
  662. }
  663. if (!this.userData) {
  664. await this.getUserInfo()
  665. }
  666. const currentToken = await uni.getStorageSync('AppToken')
  667. console.log("token在这里", currentToken)
  668. const isLiveLogin = uni.getStorageSync('isLiveLogin')
  669. this.share = uni.getStorageSync('share')
  670. this.scene = uni.getStorageSync('scene')
  671. console.log("onshow分享", this.share)
  672. console.log("onshow扫码", this.scene)
  673. if (this.share && this.share.length > 0) {
  674. this.liveId = this.share.liveId
  675. this.qrFrom = `&companyId=${this.share.companyId}&companyUserId=${this.share.companyUserId}`;
  676. }
  677. if (this.scene) {
  678. console.log("有扫码")
  679. const decodedScene = decodeURIComponent(this.scene);
  680. console.log("有扫码decodedScene", decodedScene)
  681. const params = {};
  682. decodedScene.split('&').forEach(item => {
  683. const [key, value] = item.split('=');
  684. params[key] = value;
  685. console.log("扫码参数", params)
  686. this.liveId = params.a;
  687. })
  688. if (params.b && params.c) {
  689. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  690. }
  691. }
  692. if (isLiveLogin) {
  693. console.log("登录了")
  694. if (this.liveId) {
  695. await this.getliving(this.liveId)
  696. this.getCurrentActivities()
  697. this.getliveOrder()
  698. this.initSocket()
  699. }
  700. this.hasInitialized = true
  701. uni.removeStorageSync('isLiveLogin');
  702. }
  703. // 恢复播放和连接
  704. await this.resumePageActivity()
  705. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  706. // this.userData =await uni.getStorageSync("userData")
  707. this.isAgreement = uni.getStorageSync('isAgreement')
  708. this.previousToken = currentToken
  709. this.randomColor = this.getRandomHexColor()
  710. this.$nextTick(() => {
  711. this.setVideoProgress();
  712. });
  713. console.log("预约liveiD", this.liveId)
  714. },
  715. //分享给好友
  716. onShareAppMessage() {
  717. return {
  718. title: '邀请你来观看直播:' + this.liveItem.liveName,
  719. path: '/pages_course/living?companyId=-2&companyUserId=' + this.userData.userId + '&liveId=' + this.liveId,
  720. imageUrl: '/static/images/logo.png',
  721. success(res) {
  722. console.log("分享成功", res);
  723. },
  724. fail(err) {
  725. console.error("分享失败", err);
  726. }
  727. };
  728. },
  729. computed: {
  730. filteredViewers() {
  731. // 1. 强制兜底:若 liveViewers 不是数组(如 null/undefined),直接返回空数组
  732. const safeLiveViewers = Array.isArray(this.liveViewersData) ? this.liveViewersData : [];
  733. // 2. 截取前3项(空数组 slice 不会报错)
  734. return safeLiveViewers.slice(0, 3);
  735. },
  736. isCurrentUserWon() {
  737. // 兜底条件:确保prizeInfo是数组、当前用户ID存在
  738. if (!Array.isArray(this.prizeInfo) || !this.userData?.userId) {
  739. return false;
  740. }
  741. // 匹配逻辑:检查prizeInfo中是否有userId与当前用户一致的项
  742. return this.prizeInfo.some(item => {
  743. // 兼容item.userId可能是数字/字符串的情况,统一转为字符串比较
  744. return String(item.userId) === String(this.userData.userId);
  745. });
  746. }
  747. },
  748. onHide() {
  749. },
  750. onUnload() {
  751. this.suspendPageActivity()
  752. this.liveUserCalled = false
  753. // if (this.liveItem) {
  754. // this.pauseVideo();
  755. // this.clearTimeTimer();
  756. // }
  757. this.loadUserColorsFromStorage();
  758. if (this.liveViewDataTimer) {
  759. clearInterval(this.liveViewDataTimer);
  760. this.liveViewDataTimer = null;
  761. }
  762. // console.log('页面卸载,清理资源');
  763. this.isPageUnloading = true; // 标记为主动离开
  764. // 1. 先关闭WebSocket
  765. this.closeWebSocket(true);
  766. // 2. 清除所有定时器
  767. this.clearAllTimers();
  768. // 3. 暂停视频
  769. const videoId = `myVideo_${this.liveId}`;
  770. const videoContext = uni.createVideoContext(videoId, this);
  771. if (videoContext) {
  772. videoContext.pause();
  773. }
  774. // 4. 移除事件监听
  775. // 5. 清除特定定时器
  776. if (this.redTimer) {
  777. clearInterval(this.redTimer);
  778. this.redTimer = null;
  779. }
  780. if (this.liveStartTimer) {
  781. clearInterval(this.liveStartTimer);
  782. this.liveStartTimer = null;
  783. }
  784. if (this.lotteryTimer) {
  785. clearInterval(this.lotteryTimer);
  786. this.lotteryTimer = null;
  787. }
  788. if (this.welcomeTimer) {
  789. clearInterval(this.welcomeTimer);
  790. this.welcomeTimer = null;
  791. }
  792. },
  793. mounted() {
  794. this.getCurrentActivities();
  795. this.getliveOrder()
  796. },
  797. watch: {
  798. // 新增:监听liveItem.status的变化
  799. 'liveItem.status': {
  800. // status变化时执行的逻辑
  801. handler(newStatus, oldStatus) {
  802. // 1. 过滤无效场景:避免初始值/空值触发无效请求
  803. if (newStatus === undefined || oldStatus === undefined) return;
  804. // 2. 过滤相同状态:仅当状态真的变化时才请求(避免重复调用)
  805. if (newStatus === oldStatus) return;
  806. // 3. 确保liveId存在(getliving依赖liveId)
  807. if (!this.liveId) {
  808. console.warn("liveId不存在,无法触发getliving请求");
  809. return;
  810. }
  811. // 4. 状态变化时,调用getliving更新直播间数据
  812. console.log(`liveItem.status从${oldStatus}变为${newStatus},触发getliving请求`);
  813. this.getliving(this.liveId);
  814. },
  815. deep: true,
  816. // immediate: true(若需页面初始化时就触发一次,根据需求决定是否开启)
  817. },
  818. // 监听orderUser.count的变化
  819. 'orderUser.count': {
  820. handler(newVal, oldVal) {
  821. if (newVal !== this.prevOrderCount) {
  822. this.prevOrderCount = newVal;
  823. this.showPurchaseMessage();
  824. }
  825. },
  826. immediate: true
  827. }
  828. },
  829. methods: {
  830. // 恢复页面活动
  831. async resumePageActivity() {
  832. console.log("恢复了")
  833. if (this.liveItem) {
  834. this.playVideo()
  835. this.startTimeTimer(this.liveItem)
  836. }
  837. if (!this.isSocketAvailable()) {
  838. this.initSocket()
  839. }
  840. },
  841. // 暂停页面活动
  842. suspendPageActivity() {
  843. this.stopHeartBeat()
  844. this.saveVideoProgress()
  845. if (this.liveItem) {
  846. this.pauseVideo()
  847. this.clearTimeTimer()
  848. }
  849. },
  850. // 获取用户专属随机色(缓存机制:同一用户始终用同一颜色)
  851. getUserRandomColor(userId) {
  852. if (!userId) {
  853. return '#8978e2'; // 默认颜色
  854. }
  855. //如果缓存中已有该用户的颜色,直接返回
  856. if (this.userRandomColors[userId]) {
  857. return this.userRandomColors[userId];
  858. }
  859. //为新用户生成固定颜色(基于用户ID生成,不是完全随机)
  860. const color = this.generateStableColor(userId);
  861. this.userRandomColors[userId] = color;
  862. // 存储到本地缓存,确保页面刷新后颜色不变
  863. this.saveUserColorsToStorage();
  864. return color;
  865. }, // 基于用户ID生成稳定颜色(不是完全随机)
  866. generateStableColor(userId) {
  867. // 将用户ID转换为数字种子
  868. let seed = 0;
  869. for (let i = 0; i < userId.length; i++) {
  870. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  871. }
  872. const colorPool = [
  873. '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
  874. '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9',
  875. '#F8C471', '#82E0AA', '#F1948A', '#85C1E9', '#D7BDE2'
  876. ];
  877. return colorPool[seed % colorPool.length];
  878. }, // 保存颜色映射到本地存储
  879. saveUserColorsToStorage() {
  880. try {
  881. uni.setStorageSync('userRandomColors', this.userRandomColors);
  882. } catch (e) {
  883. console.warn('保存用户颜色缓存失败:', e);
  884. }
  885. },
  886. // 从本地存储加载颜色映射
  887. loadUserColorsFromStorage() {
  888. try {
  889. const cached = uni.getStorageSync('userRandomColors');
  890. if (cached) {
  891. this.userRandomColors = cached;
  892. }
  893. } catch (e) {
  894. console.warn('加载用户颜色缓存失败:', e);
  895. }
  896. },
  897. //头像名字
  898. getNicknameInitial(nickName) {
  899. if (!nickName || typeof nickName !== 'string') return '未';
  900. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  901. return nickName[0];
  902. }
  903. return nickName[0].toUpperCase();
  904. },
  905. // 引入前面的随机颜色方法
  906. getRandomHexColor() {
  907. const getValidValue = () => Math.floor(Math.random() * 130) + 100;
  908. const red = getValidValue().toString(16).padStart(2, '0');
  909. const green = getValidValue().toString(16).padStart(2, '0');
  910. const blue = getValidValue().toString(16).padStart(2, '0');
  911. return `#${red}${green}${blue}`;
  912. },
  913. async getUserInfo() {
  914. await getUserInfo().then(
  915. res => {
  916. if (res.code == 200) {
  917. console.log("用户信息>>", res)
  918. this.userData = res.user;
  919. } else {
  920. uni.showToast({
  921. icon: 'none',
  922. title: "请求失败",
  923. });
  924. }
  925. },
  926. rej => {}
  927. );
  928. }, // 检查WebSocket连接状态
  929. getSocketState() {
  930. if (!this.socket) return 'CLOSED';
  931. const states = {
  932. 0: 'CONNECTING',
  933. 1: 'OPEN',
  934. 2: 'CLOSING',
  935. 3: 'CLOSED'
  936. };
  937. return states[this.socket.readyState] || 'UNKNOWN';
  938. },
  939. // 在控制台输出连接状态(调试用)
  940. logSocketState() {
  941. console.log('WebSocket状态:', {
  942. socket: !!this.socket,
  943. isSocketOpen: this.isSocketOpen,
  944. readyState: this.getSocketState(),
  945. reconnectCount: this.reconnectCount
  946. });
  947. },
  948. handleAgreement() {
  949. const templateId = this.templateId; // 先保存到局部变量
  950. uni.requestSubscribeMessage({
  951. tmplIds: [templateId],
  952. success: (res) => { // 使用箭头函数保持this指向
  953. console.log("订阅结果", res);
  954. console.log("模板订阅状态", res[templateId]);
  955. if (res[templateId] === "accept") {
  956. uni.showToast({
  957. title: '订阅成功,开播将提醒您',
  958. icon: 'success'
  959. });
  960. this.callSendMessageApi()
  961. } else if (res[templateId] === 'reject') {
  962. uni.showToast({
  963. title: '您已拒绝订阅,将无法收到提醒',
  964. icon: 'none'
  965. });
  966. } else if (res[templateId] === 'ban') {
  967. uni.showToast({
  968. title: '您已关闭所有订阅权限,请在设置中开启',
  969. icon: 'none'
  970. });
  971. }
  972. },
  973. fail: (err) => {
  974. console.error('订阅消息失败', err);
  975. uni.showToast({
  976. title: '订阅失败,请重试',
  977. icon: 'none'
  978. });
  979. }
  980. });
  981. },
  982. // 调用后端发送订阅消息的接口
  983. async callSendMessageApi() {
  984. if (!this.userData.userId) return;
  985. console.log("订阅在这里", this.userData.userId)
  986. const templateData = {
  987. taskName: this.liveId,
  988. userId: this.userData.userId,
  989. templateId: this.templateId, // 你的模板ID
  990. data: {
  991. thing6: this.liveItem.liveName,
  992. date7: this.liveItem.startTime,
  993. }
  994. };
  995. // 调用后端接口(后端负责调用微信订阅消息发送接口)
  996. subNotifyLive(templateData).then(res => {
  997. if (res.code == 200) {
  998. this.isAgreement = true;
  999. uni.setStorageSync('isAgreement', true);
  1000. console.log("订阅消息", res)
  1001. } else {
  1002. uni.showToast({
  1003. title: res.msg,
  1004. icon: 'none'
  1005. });
  1006. }
  1007. },
  1008. rej => {}
  1009. );
  1010. },
  1011. sendHeartBeat() {
  1012. if (!this.isSocketAvailable()) return;
  1013. try {
  1014. const heartBeatMsg = JSON.stringify({
  1015. cmd: "heartbeat",
  1016. msg: "ping",
  1017. userId: this.userData.userId || '',
  1018. liveId: this.liveId
  1019. });
  1020. this.socket.send({
  1021. data: heartBeatMsg,
  1022. success: () => {
  1023. this.heartBeatRetryCount = 0; // 成功后重置重试次数
  1024. this.startPingTimeout(); // 启动超时检测
  1025. },
  1026. fail: (err) => {
  1027. console.error("心跳包发送失败:", err);
  1028. this.heartBeatRetryCount++;
  1029. // 心跳失败先重试,重试次数用完再重连
  1030. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1031. setTimeout(() => this.sendHeartBeat(), 2000); // 2秒后重试
  1032. } else {
  1033. this.heartBeatRetryCount = 0;
  1034. this.handleReconnect(); // 重试用完才重连
  1035. }
  1036. }
  1037. });
  1038. } catch (err) {
  1039. console.error("心跳发送异常:", err);
  1040. this.heartBeatRetryCount++;
  1041. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1042. setTimeout(() => this.sendHeartBeat(), 2000);
  1043. } else {
  1044. this.heartBeatRetryCount = 0;
  1045. this.handleReconnect();
  1046. }
  1047. }
  1048. }, // 启动心跳超时检测
  1049. startPingTimeout() {
  1050. // 清除之前的超时定时器
  1051. if (this.pingTimeoutTimer) {
  1052. clearTimeout(this.pingTimeoutTimer);
  1053. this.pingTimeoutTimer = null;
  1054. }
  1055. // 超时后触发重连
  1056. this.pingTimeoutTimer = setTimeout(() => {
  1057. // console.error("心跳响应超时,连接异常");
  1058. this.handleReconnect();
  1059. }, this.pingTimeout);
  1060. },
  1061. stopHeartBeat() {
  1062. if (this.heartBeatTimer) {
  1063. clearInterval(this.heartBeatTimer);
  1064. this.heartBeatTimer = null;
  1065. }
  1066. if (this.pingTimeoutTimer) {
  1067. clearTimeout(this.pingTimeoutTimer);
  1068. this.pingTimeoutTimer = null;
  1069. }
  1070. }, // 封装通用的连接状态校验方法
  1071. isSocketAvailable() {
  1072. // WebSocket readyState:0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
  1073. return this.socket && this.isSocketOpen && this.socket.readyState === 1;
  1074. },
  1075. // 处理重连逻辑
  1076. handleReconnect() {
  1077. this.resetReconnectState();
  1078. this.stopHeartBeat();
  1079. if (this.reconnectCount < this.maxReconnectAttempts) {
  1080. this.reconnectCount++;
  1081. const delay = 1000;
  1082. console.log(`第${this.reconnectCount}次重连,延迟${delay}ms`);
  1083. this.reconnectTimer = setInterval(() => {
  1084. this.initSocket();
  1085. }, delay);
  1086. } else {
  1087. console.log(`停止重连(手动关闭/已达最大次数)`);
  1088. this.closeWebSocket(true);
  1089. }
  1090. },
  1091. // 重置重连状态
  1092. resetReconnectState() {
  1093. this.reconnectCount = 0;
  1094. if (this.reconnectTimer) {
  1095. clearInterval(this.reconnectTimer);
  1096. this.reconnectTimer = null;
  1097. }
  1098. },
  1099. //输入框
  1100. inputFocus() {
  1101. this.chatHeight = this.keyboardHeight - 10;
  1102. this.isFocus = true;
  1103. },
  1104. inputBlur() {
  1105. this.chatHeight = 0;
  1106. this.isFocus = false
  1107. },
  1108. getTimeDifferenceInSeconds(createTimeStr) {
  1109. const createTime = new Date(createTimeStr.replace(/-/g, '/'));
  1110. const now = new Date();
  1111. const timeDiffMs = now - createTime;
  1112. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  1113. return Math.max(0, timeDiffSeconds);
  1114. },
  1115. // 录播时间点
  1116. onVideoMetaLoaded(e) {
  1117. this.videoProgressKey = `videoProgress_${this.liveId}`;
  1118. this.setVideoProgress();
  1119. },
  1120. setVideoProgress() {
  1121. // 只有录播和回放需要设置进度
  1122. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  1123. return;
  1124. }
  1125. let currentTime = 0;
  1126. if (this.liveItem.liveType === 2) {
  1127. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  1128. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  1129. currentTime = diff % this.liveItem.duration;
  1130. } else if (this.liveItem.liveType === 3) {
  1131. // 回放:从存储中获取进度
  1132. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  1133. currentTime = storedProgress || 0;
  1134. }
  1135. const videoId = `myVideo_${this.liveId}`;
  1136. const videoContext = uni.createVideoContext(videoId, this);
  1137. if (videoContext) {
  1138. videoContext.seek(currentTime);
  1139. console.log(`设置视频播放位置: ${currentTime}秒`);
  1140. }
  1141. },
  1142. // 视频数据加载完成
  1143. onVideoLoaded(e) {
  1144. console.log('视频数据加载完成');
  1145. },
  1146. // 视频时间更新
  1147. onVideoTimeUpdate(e) {
  1148. // 获取当前播放时间
  1149. this.videoCurrentTime = e.detail.currentTime;
  1150. // 每隔5秒保存一次进度(避免频繁存储)
  1151. if (Math.floor(this.videoCurrentTime) % 5 === 0) {
  1152. this.saveVideoProgress();
  1153. }
  1154. },
  1155. // 视频暂停
  1156. onVideoPause(e) {
  1157. // this.isVideoPlaying = false;
  1158. // 暂停时保存进度
  1159. this.saveVideoProgress();
  1160. },
  1161. // 视频播放
  1162. onVideoPlay(e) {
  1163. // this.isVideoPlaying = true;
  1164. },
  1165. // 设置视频当前时间
  1166. // setVideoCurrentTime(time) {
  1167. // if (!time) return;
  1168. // const videoId = `myVideo_${this.liveId}`;
  1169. // const videoContext = uni.createVideoContext(videoId, this);
  1170. // if (videoContext) {
  1171. // videoContext.seek(time);
  1172. // console.log(`设置视频播放位置: ${time}秒`);
  1173. // }
  1174. // },
  1175. // 保存视频进度
  1176. saveVideoProgress() {
  1177. if (this.videoProgressKey) {
  1178. uni.setStorage({
  1179. key: this.videoProgressKey,
  1180. data: this.videoCurrentTime,
  1181. success: () => {},
  1182. fail: (err) => {
  1183. console.error('保存视频进度失败:', err);
  1184. }
  1185. });
  1186. }
  1187. },
  1188. // 点击红包
  1189. onRed() {
  1190. if (!this.liveId) return;
  1191. if (!this.redInfo?.redId) return;
  1192. if (this.redTimer) {
  1193. clearInterval(this.redTimer);
  1194. this.redTimer = null;
  1195. }
  1196. let data = {
  1197. liveId: this.liveId,
  1198. userId: this.userData.userId,
  1199. redId: this.redInfo.redId,
  1200. }
  1201. liveRed(data).then(res => {
  1202. this.isShowRed = false
  1203. this.redCard = res
  1204. this.isShowRedCard = true
  1205. },
  1206. rej => {}
  1207. );
  1208. },
  1209. //领取优惠券
  1210. onCoupon() {
  1211. if (!this.couponInfo.couponIssueId) return;
  1212. let data = {
  1213. goodsId: this.couponInfo.goodsId,
  1214. couponIssueId: this.couponInfo.couponIssueId,
  1215. liveId: this.liveId
  1216. };
  1217. coupon(data)
  1218. .then(res => {
  1219. if (res.code == 200) {
  1220. uni.showToast({
  1221. title: res.msg,
  1222. icon: 'none'
  1223. });
  1224. this.isShowCoupon = false
  1225. // const couponData = res.data || {};
  1226. } else {
  1227. uni.showToast({
  1228. title: res.msg,
  1229. icon: 'none'
  1230. });
  1231. }
  1232. })
  1233. .catch(rej => {});
  1234. },
  1235. // 抽奖
  1236. onLottery() {
  1237. if (!this.lotteryInfo) return;
  1238. let data = {
  1239. lotteryId: this.lotteryInfo.lotteryId
  1240. };
  1241. liveLottery(data)
  1242. .then(res => {
  1243. if (res.code == 200) {
  1244. const resData = res.data || {}; // 兜底 res.data 为对象,避免访问 res.data.products 报错
  1245. this.lotteryList = Array.isArray(resData) ? resData : [];
  1246. // 兜底 products 为数组
  1247. this.lotteryProducts = Array.isArray(resData.products) ? resData.products : [];
  1248. if (resData.duration) {
  1249. this.isShowLotteryPop = true;
  1250. }
  1251. } else {
  1252. uni.showToast({
  1253. title: res.msg,
  1254. icon: 'none'
  1255. });
  1256. this.lotteryList = [];
  1257. this.lotteryProducts = [];
  1258. }
  1259. })
  1260. .catch(rej => {
  1261. uni.showToast({
  1262. title: '获取抽奖信息失败',
  1263. icon: 'none'
  1264. });
  1265. // 失败时强制重置为数组
  1266. this.lotteryList = [];
  1267. this.lotteryProducts = [];
  1268. });
  1269. },
  1270. // 参与抽奖
  1271. onClaim() {
  1272. let data = {
  1273. liveId: this.liveId,
  1274. lotteryId: this.lotteryInfo.lotteryId,
  1275. }
  1276. claim(data).then(res => {
  1277. if (res.code == 200) {
  1278. uni.showToast({
  1279. title: res.msg,
  1280. icon: 'none'
  1281. });
  1282. this.isShowLotteryPop = false
  1283. } else {
  1284. uni.showToast({
  1285. title: res.msg,
  1286. icon: 'none'
  1287. });
  1288. }
  1289. },
  1290. rej => {}
  1291. );
  1292. },
  1293. // 商品收藏
  1294. onGoodsCollect(item) {
  1295. if (!item || item.length === 0 || !item.goodsId) {
  1296. return;
  1297. }
  1298. collectGoods(item.goodsId).then(res => {
  1299. if (res.code == 200) {
  1300. uni.showToast({
  1301. title: res.msg,
  1302. icon: 'none'
  1303. });
  1304. item.isFavorite = !item.isFavorite
  1305. } else {
  1306. uni.showToast({
  1307. title: res.msg,
  1308. icon: 'none'
  1309. });
  1310. }
  1311. },
  1312. rej => {}
  1313. );
  1314. },
  1315. //正在购买
  1316. getliveOrder(item) {
  1317. if (!this.liveId) {
  1318. return;
  1319. }
  1320. liveOrderUser(this.liveId).then(res => {
  1321. // console.log("正在购买", res)
  1322. if (res.code == 200) {
  1323. this.orderUser = res;
  1324. } else {
  1325. console.log('获取正在购买用户失败');
  1326. }
  1327. },
  1328. rej => {}
  1329. );
  1330. },
  1331. onLiveStateChange(e, liveItem) {
  1332. // console.log('直播状态变化:', e.detail.code, e.detail);
  1333. // 可以根据状态码处理不同的直播状态
  1334. const stateCode = e.detail.code;
  1335. // 2001: 已经连接服务器
  1336. // 2002: 已经连接服务器,开始拉流
  1337. // 2003: 网络接收到首个视频数据包(IDR)
  1338. // 2004: 视频播放开始
  1339. // 2005: 视频播放进度
  1340. // 2006: 视频播放结束
  1341. // 2007: 视频播放Loading
  1342. // 2008: 解码器启动
  1343. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  1344. // -2302: 获取加速拉流地址失败
  1345. }, // 直播错误事件
  1346. onLiveError(e, liveItem) {
  1347. this.videoError(e, liveItem);
  1348. },
  1349. // 红包 卡片 抽奖
  1350. getCurrentActivities() {
  1351. if (!this.liveId) return;
  1352. currentActivities(this.liveId).then(res => {
  1353. if (res.code === 200) {
  1354. // 提取数据(默认空数组/对象避免报错)
  1355. this.redInfo = (res.red || [])[0];
  1356. this.lotteryInfo = (res.lottery || [])[0];
  1357. this.goodsCard = res.goods || {};
  1358. this.isShowGoods = this.goodsCard && this.goodsCard.status == 1;
  1359. this.isShowRed = this.redInfo && this.redInfo.redStatus == 1;
  1360. this.isShowLottery = this.lotteryInfo && this.lotteryInfo.lotteryStatus == 1;
  1361. if (this.isShowRed) {
  1362. this.redTimer = setInterval(() => {
  1363. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  1364. .duration)
  1365. if (!redCountdown) {
  1366. this.isShowRed = false
  1367. clearInterval(this.redTimer)
  1368. }
  1369. }, 1000);
  1370. }
  1371. // 处理抽奖定时器
  1372. if (this.isShowLottery) {
  1373. this.lotteryTimer = setInterval(() => {
  1374. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  1375. .lotteryInfo
  1376. .duration)
  1377. }, 1000);
  1378. }
  1379. } else {
  1380. uni.showToast({
  1381. title: res.msg,
  1382. icon: 'none'
  1383. });
  1384. }
  1385. }, rej => {});
  1386. },
  1387. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  1388. calculateTimeDiff(item) {
  1389. // 防御1:item 不存在直接返回
  1390. if (!item.startTime) return;
  1391. // 步骤1:提取对应场景的时间字符串(直播用startTime,抽奖用updateTime)
  1392. let timeStr = item.startTime;
  1393. // 转换时间格式(适配iOS,将 "-" 替换为 "/")
  1394. const iosCompatibleTime = timeStr.replace(/-/g, "/");
  1395. const time = new Date(iosCompatibleTime);
  1396. if (isNaN(time.getTime())) {
  1397. return;
  1398. }
  1399. const now = new Date();
  1400. let diffMs = Math.max(0, now - time); // 直播:已播放时长(现在-开始时间)
  1401. // 步骤4:转换为 时:分:秒(补零处理)
  1402. const totalSeconds = Math.floor(diffMs / 1000);
  1403. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  1404. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  1405. const seconds = this.padZero(totalSeconds % 60);
  1406. this.$set(this.liveItem, "totalTime", `${hours}:${minutes}:${seconds}`);
  1407. this.$set(this.liveItem, "totalSeconds", totalSeconds);
  1408. },
  1409. padZero(num) {
  1410. return num < 10 ? `0${num}` : num;
  1411. },
  1412. // 启动当前直播间的时间差值定时器
  1413. startTimeTimer(item) {
  1414. // 防御:若 item 不存在,直接返回
  1415. if (!item) return;
  1416. // 立即计算一次(避免等待1秒才显示)
  1417. const totalTime = this.calculateTimeDiff(item);
  1418. item.timeTimer = setInterval(() => {
  1419. const totalTime = this.calculateTimeDiff(item);
  1420. }, 1000);
  1421. },
  1422. // 清除指定直播间的时间定时器
  1423. clearTimeTimer() {
  1424. if (this.liveItem.timeTimer) {
  1425. clearInterval(this.liveItem.timeTimer);
  1426. this.liveItem.timeTimer = null; // 清空定时器标识
  1427. }
  1428. },
  1429. toggleViewerList() {
  1430. const now = Date.now();
  1431. if (now - this.lastClickTime > this.clickDelay) {
  1432. this.showadd = !this.showadd;
  1433. if (this.showadd) {
  1434. this.getliveUser(false); // 加载第一页观众
  1435. }
  1436. this.lastClickTime = now;
  1437. }
  1438. },
  1439. closeAllWebSockets() {
  1440. this.isManualClose = true;
  1441. this.isSocketOpen = false; // 应该是 this.isSocketOpen
  1442. this.closeWebSocket(true);
  1443. },
  1444. // 清理所有定时器
  1445. clearAllTimers() {
  1446. if (this.intervalId) {
  1447. clearInterval(this.intervalId);
  1448. this.intervalId = null;
  1449. }
  1450. // if (this.pingpangTimes) {
  1451. // clearInterval(this.pingpangTimes);
  1452. // this.pingpangTimes = null;
  1453. // }
  1454. if (this.reconnectTimer) {
  1455. clearInterval(this.reconnectTimer);
  1456. this.reconnectTimer = null;
  1457. }
  1458. if (this.scrollTimer) {
  1459. clearTimeout(this.scrollTimer);
  1460. this.scrollTimer = null;
  1461. }
  1462. if (this.searchTimer) {
  1463. clearTimeout(this.searchTimer);
  1464. this.searchTimer = null;
  1465. }
  1466. if (this.purchasePromptTimer) {
  1467. clearTimeout(this.purchasePromptTimer);
  1468. this.purchasePromptTimer = null;
  1469. }
  1470. },
  1471. // 播放视频
  1472. playVideo() {
  1473. if (!this.liveItem) {
  1474. console.log('liveItem 为空,无法播放视频');
  1475. return;
  1476. }
  1477. try {
  1478. // 直播流使用live-player
  1479. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  1480. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1481. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1482. if (livePlayerContext) {
  1483. livePlayerContext.play();
  1484. }
  1485. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  1486. const videoId = `myVideo_${this.liveId}`;
  1487. const videoContext = uni.createVideoContext(videoId, this);
  1488. if (videoContext) {
  1489. videoContext.play();
  1490. }
  1491. }
  1492. // 回放视频使用video
  1493. else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  1494. const videoId = `myVideo_${this.liveId}`;
  1495. const videoContext = uni.createVideoContext(videoId, this);
  1496. if (videoContext) {
  1497. videoContext.play();
  1498. }
  1499. } else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  1500. const videoId = `myVideo_${this.liveId}`;
  1501. const videoContext = uni.createVideoContext(videoId, this);
  1502. if (videoContext) {
  1503. videoContext.play();
  1504. }
  1505. }
  1506. } catch (error) {
  1507. console.error("播放视频失败:", error);
  1508. }
  1509. },
  1510. pauseVideo() {
  1511. if (!this.liveItem) return;
  1512. try {
  1513. // 直播流使用live-player
  1514. if (this.liveItem.status == 1) {
  1515. const videoId = `myVideo_${this.liveId}`;
  1516. const videoContext = uni.createVideoContext(videoId, this);
  1517. if (videoContext) {
  1518. videoContext.pause();
  1519. }
  1520. } else if (this.liveItem.status == 2) {
  1521. if (this.liveItem.liveType === 1) {
  1522. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1523. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1524. if (livePlayerContext) {
  1525. livePlayerContext.pause();
  1526. }
  1527. } else if (this.liveItem.liveType === 2) {
  1528. const videoId = `myVideo_${this.liveId}`;
  1529. const videoContext = uni.createVideoContext(videoId, this);
  1530. if (videoContext) {
  1531. videoContext.pause();
  1532. }
  1533. }
  1534. }
  1535. } catch (error) {
  1536. console.error("暂停视频失败:", error);
  1537. }
  1538. },
  1539. // 视频错误处理
  1540. videoError(e, liveItem) {
  1541. if (!liveItem || !this.liveId) return;
  1542. // 初始化重试计数
  1543. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  1544. this.videoRetryCounts[liveItem.liveId] = 0;
  1545. }
  1546. // 限制重试次数
  1547. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  1548. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  1549. // 显示错误提示
  1550. uni.showToast({
  1551. title: "视频加载失败,请检查网络",
  1552. icon: 'none',
  1553. duration: 2000
  1554. });
  1555. return;
  1556. }
  1557. this.videoRetryCounts[this.liveId]++;
  1558. // 延迟重试
  1559. setTimeout(() => {
  1560. if (this.liveId === this.liveId) {
  1561. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  1562. this.playVideo();
  1563. }
  1564. }, 2000);
  1565. },
  1566. openViews() {
  1567. // 计算scroll-view高度
  1568. this.$nextTick(() => {
  1569. const query = uni.createSelectorQuery().in(this);
  1570. query.select('.view-box').boundingClientRect(data => {
  1571. if (data) {
  1572. // 减去标题和底部固定区域的高度
  1573. this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
  1574. }
  1575. }).exec();
  1576. });
  1577. },
  1578. // 滚动到底部触发
  1579. handleScrollToLower() {
  1580. // 清除上一次未执行的定时器,避免重复请求
  1581. if (this.scrollTimer) {
  1582. clearTimeout(this.scrollTimer);
  1583. }
  1584. // 延迟0.5秒(500毫秒)执行接口请求
  1585. this.scrollTimer = setTimeout(() => {
  1586. this.getliveUser(true); // 加载更多数据
  1587. }, 1000); // 延迟时间:500毫秒
  1588. },
  1589. async getLiveMsg(liveItem) {
  1590. // 强化校验:确保 liveItem 存在且包含 liveId
  1591. if (!liveItem || !this.liveId) {
  1592. console.error('getLiveMsg 错误:无效的 liveItem', {
  1593. liveItem: liveItem,
  1594. currentIndex: this.currentSwiperIndex,
  1595. });
  1596. return; // 直接返回,不执行后续逻辑
  1597. }
  1598. try {
  1599. const res = await liveMsg(this.liveId, 30, 1);
  1600. if (res.code == 200) {
  1601. const rows = Array.isArray(res.rows) ? res.rows : [];
  1602. const reversedTalkList = [...rows].reverse();
  1603. // .reverse();
  1604. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  1605. this.$nextTick(() => {
  1606. this.scrollIntoView = `list_${reversedTalkList.length - 1}`;
  1607. });
  1608. } else {
  1609. this.talklist = [];
  1610. }
  1611. } catch (error) {
  1612. this.talklist = [];
  1613. console.error("获取聊天记录失败:", error);
  1614. }
  1615. },
  1616. // 获取直播间用户
  1617. // getliveUser(isLoadMore = false) {
  1618. // this.viewLoading = true;
  1619. // watchUserList(this.liveId, this.viewPageSize, this.viewPageNum, false)
  1620. // .then(res => {
  1621. // if (res.code === 200) {
  1622. // const userRows = Array.isArray(res.rows) ? res.rows : [];
  1623. // this.liveViewersData = userRows.map(item => ({
  1624. // avatar: item.avatar || '',
  1625. // userId: item.userId || '',
  1626. // nickName: item.nickName || '未命名'
  1627. // }));
  1628. // console.log("请求到了",this.liveViewersData)
  1629. // this.liveUserTotal = res.total || 0;
  1630. // const newRows = Array.isArray(res.rows) ? res.rows : [];
  1631. // const currentViewers = Array.isArray(this.liveViewers) ? this.liveViewers : [];
  1632. // this.liveViewers = isLoadMore ? [...currentViewers, ...newRows] : newRows;
  1633. // this.viewPageNum++;
  1634. // } else {
  1635. // this.liveViewers = []; // 接口失败时强制置空数组
  1636. // }
  1637. // })
  1638. // .catch(error => {
  1639. // console.error('获取观众列表失败:', error);
  1640. // this.liveViewers = []; // 捕获异常时强制置空数组
  1641. // })
  1642. // .finally(() => {
  1643. // this.viewLoading = false; // 无论成功失败都关闭加载状态
  1644. // });
  1645. // },
  1646. async getliveUser(isLoadMore = false) {
  1647. this.viewLoading = true;
  1648. try {
  1649. const res = await watchUserList(this.liveId, this.viewPageSize, this.viewPageNum, false);
  1650. if (res.code === 200) {
  1651. const userRows = Array.isArray(res.rows) ? res.rows : [];
  1652. this.liveViewersData = userRows.map(item => ({
  1653. avatar: item.avatar || '',
  1654. userId: item.userId || '',
  1655. nickName: item.nickName || '未命名'
  1656. }));
  1657. this.liveUserTotal = res.total || 0;
  1658. const newRows = Array.isArray(res.rows) ? res.rows : [];
  1659. const currentViewers = Array.isArray(this.liveViewers) ? this.liveViewers : [];
  1660. this.liveViewers = isLoadMore ? [...currentViewers, ...newRows] : newRows;
  1661. this.viewPageNum++;
  1662. }
  1663. } catch (error) {
  1664. console.error('获取观众列表失败:', error);
  1665. } finally {
  1666. this.viewLoading = false;
  1667. }
  1668. },
  1669. //小黄车搜索商品
  1670. handleSearchInput() {
  1671. // 使用防抖优化性能,避免频繁请求
  1672. clearTimeout(this.searchTimer);
  1673. this.searchTimer = setTimeout(() => {
  1674. this.queryCollect();
  1675. }, 500); // 500毫秒延迟
  1676. },
  1677. // 显示购买提示信息
  1678. showPurchaseMessage() {
  1679. // 清除之前的定时器
  1680. if (this.purchasePromptTimer) {
  1681. clearTimeout(this.purchasePromptTimer);
  1682. }
  1683. // 显示提示
  1684. this.showPurchasePrompt = true;
  1685. // 2秒后自动隐藏
  1686. this.purchasePromptTimer = setTimeout(() => {
  1687. this.showPurchasePrompt = false;
  1688. }, 2000);
  1689. },
  1690. //名字超过省略
  1691. truncateString(str, maxLength) {
  1692. if (typeof str !== 'string' || str.length <= maxLength) {
  1693. return str;
  1694. }
  1695. return str.slice(0, maxLength) + '...'; // 截断后加省略号
  1696. },
  1697. // 去订单列表
  1698. goOrderList() {
  1699. uni.navigateTo({
  1700. url: "/pages_shopping/live/order"
  1701. })
  1702. },
  1703. // 修改获取直播信息方法
  1704. async getliving(liveId) {
  1705. if (!liveId) return;
  1706. const param = {
  1707. id: liveId
  1708. };
  1709. try {
  1710. const res = await getlive(param);
  1711. if (res.code !== 200) {
  1712. uni.showToast({
  1713. title: res.msg,
  1714. icon: 'none'
  1715. });
  1716. return;
  1717. }
  1718. // 关键:用 Object.assign 合并旧数据与新数据,确保原有响应式属性不丢失
  1719. // 同时通过 $set 触发整体更新(若 liveItem 初始为空,需先初始化)
  1720. this.liveItem = Object.assign({}, this.liveItem, res.data);
  1721. // this.liveItem = res.data;
  1722. this.talklist = Array.isArray((res.data || {}).talklist) ? res.data.talklist : [];
  1723. this.startTimeTimer(this.liveItem);
  1724. // 清除旧定时器(如预告倒计时)
  1725. if (this.liveStartTimer) {
  1726. clearInterval(this.liveStartTimer);
  1727. this.liveStartTimer = null;
  1728. }
  1729. if (res.data.status == 1) {
  1730. // 直播预告
  1731. this.liveStartTimer = setInterval(async () => {
  1732. this.liveCountdown = this.handleTime(res.data.startTime, 0);
  1733. if (!this.liveCountdown) {
  1734. await this.getliving(this.liveId);
  1735. clearInterval(this.liveStartTimer);
  1736. }
  1737. }, 1000);
  1738. this.$set(this.liveItem, 'previewUrl', res.data.previewUrl);
  1739. this.$set(this.liveItem, 'livingUrl', ''); // 清空直播流
  1740. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  1741. } else if (res.data.status == 2) {
  1742. if (res.data.liveType == 1) {
  1743. // 直播流
  1744. let cTime = Math.floor(Math.random() * 10000) + 1;
  1745. let livingUrl = res.data.flvHlsUrl + "&t=" + cTime;
  1746. console.log("地址在", this.liveItem.livingUrl)
  1747. this.$set(this.liveItem, 'livingUrl', livingUrl);
  1748. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  1749. } else if (res.data.liveType === 2 || res.data.liveType === 3) {
  1750. // 回放视频 2录播 3直播回放
  1751. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  1752. this.$set(this.liveItem, 'livingUrl', '');
  1753. } else {
  1754. // 未开播
  1755. this.$set(this.liveItem, 'livingUrl', '');
  1756. this.$set(this.liveItem, 'videoUrl', '');
  1757. }
  1758. }
  1759. await this.getLiveMsg(this.liveItem);
  1760. await this.getliveViewData(this.liveItem);
  1761. this.$set(this.liveItem, 'autoplay', res.data.liveType !== 0);
  1762. this.$set(this.liveItem, 'showType', res.data.showType);
  1763. this.storeId = res.storeId;
  1764. // 2. 启动“10秒刷新直播间数据”的定时器
  1765. this.startLiveViewDataTimer();
  1766. this.playVideo();
  1767. // live_start 时主动初始化播放组件
  1768. // this.initPlayerComponent();
  1769. } catch (err) {
  1770. console.error("获取直播信息失败:", err);
  1771. uni.showToast({
  1772. title: "获取直播信息失败",
  1773. icon: 'none'
  1774. });
  1775. }
  1776. },
  1777. // initPlayerComponent() {
  1778. // const {
  1779. // liveType,
  1780. // status,
  1781. // liveId,
  1782. // livingUrl,
  1783. // videoUrl
  1784. // } = this.liveItem;
  1785. // // 仅在“直播中”(status:2)时初始化
  1786. // if (status !== 2) return;
  1787. // this.$nextTick(() => { // 等待视图更新后再操作组件
  1788. // // 1. 直播流(liveType:1):初始化 live-player
  1789. // if (liveType === 1 && livingUrl) {
  1790. // const livePlayerId = `myLivePlayer_${liveId}`;
  1791. // const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1792. // if (livePlayerContext) {
  1793. // livePlayerContext.stop(); // 先停止旧流
  1794. // livePlayerContext.play(); // 播放新流
  1795. // }
  1796. // }
  1797. // // 2. 录播/回放(liveType:2/3):初始化 video
  1798. // if ((liveType === 2 || liveType === 3) && videoUrl) {
  1799. // const videoId = `myVideo_${liveId}`;
  1800. // const videoContext = uni.createVideoContext(videoId, this);
  1801. // if (videoContext) {
  1802. // videoContext.stop(); // 停止旧视频
  1803. // videoContext.seek(0); // 重置到开头
  1804. // videoContext.play(); // 播放新视频
  1805. // }
  1806. // }
  1807. // });
  1808. // },
  1809. // 设置视频播放
  1810. maskString(str, maskChar = '*') {
  1811. // 如果str是undefined或null,直接返回空字符串
  1812. if (!str) return '';
  1813. // 确保str是字符串(如果是数字等类型,先转为字符串)
  1814. const strVal = String(str);
  1815. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join(
  1816. '');
  1817. },
  1818. getPureDecimal(num, precision = 6) {
  1819. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  1820. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  1821. },
  1822. // 返回上一个页面并关闭WebSocket
  1823. goBack() {
  1824. // 暂停当前视频
  1825. if (this.liveItem) {
  1826. this.pauseVideo();
  1827. }
  1828. // 关闭WebSocket连接
  1829. this.closeWebSocket(true);
  1830. // 导航返回
  1831. const pages = getCurrentPages();
  1832. if (pages.length > 1) {
  1833. uni.navigateBack();
  1834. } else {
  1835. uni.reLaunch({
  1836. url: '/pages_course/livingList'
  1837. });
  1838. }
  1839. },
  1840. // 点赞
  1841. async onLike() {
  1842. if (!this.liveId) return;
  1843. try {
  1844. const res = await liveDataLike(this.liveId);
  1845. if (res?.like) {
  1846. this.liveViewData.like++; // 只更新当前直播间的点赞数
  1847. } else {
  1848. uni.showToast({
  1849. title: res.msg,
  1850. icon: 'none'
  1851. });
  1852. }
  1853. } catch (error) {
  1854. console.error('点赞失败:', error);
  1855. }
  1856. },
  1857. //直播间点赞、关注、在线人数数据
  1858. getliveViewData(liveItem) {
  1859. if (!liveItem || !this.liveId) return;
  1860. getLiveViewData(this.liveId).then(res => {
  1861. if (res.code == 200) {
  1862. // 强制响应式更新,确保数据实时显示
  1863. this.liveViewData = res;
  1864. }
  1865. }).catch(error => {
  1866. console.error("获取直播间数据失败:", error);
  1867. // 失败时兜底,避免显示异常
  1868. this.liveViewData = {
  1869. like: 0,
  1870. watchCount: 0
  1871. };
  1872. });
  1873. },
  1874. startLiveViewDataTimer() {
  1875. // 先清除旧定时器(防止重复创建)
  1876. if (this.liveViewDataTimer) {
  1877. clearInterval(this.liveViewDataTimer);
  1878. this.liveViewDataTimer = null;
  1879. }
  1880. // 启动新定时器,每3秒执行一次
  1881. this.liveViewDataTimer = setInterval(() => {
  1882. // 安全校验:确保liveItem和liveId存在(避免无效请求)
  1883. if (this.liveItem && this.liveId) {
  1884. this.getliveViewData(this.liveItem);
  1885. }
  1886. }, 10000);
  1887. },
  1888. // 去购买,跳商品详情
  1889. goShop(productId, goodsId) {
  1890. if (!this.liveId) return;
  1891. uni.navigateTo({
  1892. url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' + this.liveId +
  1893. '&goodsId=' +
  1894. goodsId + '&storeId=' + this.storeId
  1895. })
  1896. },
  1897. // 查询店铺
  1898. async queryCollect() {
  1899. if (!this.liveId) return;
  1900. if (this.inputInfo == null) this.inputInfo = ''
  1901. try {
  1902. const res = await liveStore(this.liveId, this.inputInfo);
  1903. if (res.code === 200) {
  1904. // 数据绑定到当前 liveItem,避免全局污染
  1905. this.products = Array.isArray(res.data) ? res.data : [];
  1906. }
  1907. } catch (error) {
  1908. console.error('获取小黄车商品失败:', error);
  1909. }
  1910. },
  1911. // 时间戳
  1912. initTime() {
  1913. const now = new Date();
  1914. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  1915. },
  1916. openCart() {
  1917. this.queryCollect()
  1918. this.shopping = true
  1919. },
  1920. close() {
  1921. this.showadd = false
  1922. },
  1923. // 关闭小黄车
  1924. closeShop() {
  1925. this.shopping = false;
  1926. },
  1927. // 修改关闭WebSocket方法
  1928. // closeWebSocket() {
  1929. // this.socket?.close();
  1930. // },
  1931. // 关闭WebSocket连接(isManual:是否手动关闭)
  1932. closeWebSocket(isManual = true) {
  1933. // 修复判断条件:当 socket 为 null 或未打开时,直接返回
  1934. if (!this.socket || !this.isSocketOpen) {
  1935. console.warn("WebSocket 任务不存在或未打开,无需关闭");
  1936. return;
  1937. }
  1938. console.log("websocket 连接关闭");
  1939. this.isManualClose = isManual;
  1940. this.stopHeartBeat();
  1941. this.resetReconnectState();
  1942. try {
  1943. // 先保存引用,避免在关闭过程中被置为null
  1944. const socketToClose = this.socket;
  1945. this.socket = null;
  1946. this.isSocketOpen = false;
  1947. socketToClose.close({
  1948. code: 1000,
  1949. reason: isManual ? "主动关闭" : "异常关闭"
  1950. });
  1951. console.log("WebSocket连接已发起关闭");
  1952. } catch (err) {
  1953. console.error("关闭WebSocket失败:", err);
  1954. // 即使关闭失败,也要重置状态
  1955. this.socket = null;
  1956. this.isSocketOpen = false;
  1957. }
  1958. },
  1959. startHeartBeat() {
  1960. this.stopHeartBeat(); // 先停止现有心跳,防止重复
  1961. this.sendHeartBeat(); // 立即发送一次心跳
  1962. // 按间隔循环发送心跳
  1963. this.heartBeatTimer = setInterval(() => {
  1964. this.sendHeartBeat();
  1965. }, this.heartBeatInterval);
  1966. },
  1967. initSocket() {
  1968. if (!this.userData) {
  1969. this.getUserInfo()
  1970. }
  1971. if (this.isConnecting) {
  1972. return;
  1973. }
  1974. // 如果已经存在连接且状态为open,则退出
  1975. if (this.socket && this.socket.readyState === 1) {
  1976. return;
  1977. }
  1978. if (this.socket && (this.socket.readyState === 0 || this.socket.readyState === 1)) {
  1979. console.log('关闭现有WebSocket连接,创建新连接');
  1980. this.closeWebSocket(true);
  1981. }
  1982. // 校验必要参数
  1983. if (!this.liveId) {
  1984. console.error("缺失直播间ID,无法初始化WebSocket");
  1985. return;
  1986. }
  1987. console.log("用户信息", this.userData)
  1988. if (!this.userData || !this.userData.userId) {
  1989. console.error("用户信息缺失,无法初始化WebSocket");
  1990. return;
  1991. }
  1992. // 清除之前的重连定时器
  1993. this.resetReconnectState();
  1994. const now = new Date();
  1995. this.timestamp = now.getTime(); // 生成签名
  1996. const signature = CryptoJS.HmacSHA256(
  1997. `${this.liveId}${this.userData.userId}${this.userType}${this.timestamp}`,
  1998. this.timestamp.toString()
  1999. ).toString(CryptoJS.enc.Hex);
  2000. try {
  2001. const baseWsUrl = 'wss://api.fhhx.runtzh.com/ws/app/webSocket';
  2002. // const baseWsUrl = 'ws://192.168.10.166:7114/ws/app/webSocket';
  2003. let wsUrl =
  2004. `${baseWsUrl}?userId=${this.userData.userId}&liveId=${this.liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`;
  2005. if (this.qrFrom) {
  2006. wsUrl += this.qrFrom;
  2007. }
  2008. // console.log("创建新的WebSocket连接:", wsUrl);
  2009. const socketTask = uni.connectSocket({
  2010. url: wsUrl,
  2011. success: () => console.log("Socket连接请求发送成功"),
  2012. fail: (err) => {
  2013. console.error("Socket连接请求失败:", err);
  2014. this.handleReconnect();
  2015. }
  2016. });
  2017. // 连接打开事件
  2018. socketTask.onOpen((res) => {
  2019. console.log("WebSocket连接已打开");
  2020. this.socket = socketTask;
  2021. this.isConnecting = false;
  2022. this.isSocketOpen = true;
  2023. this.reconnectCount = 0;
  2024. this.resetReconnectState();
  2025. this.heartBeatRetryCount = 0; // 重置心跳重试次数
  2026. this.shownEntryUsers.clear(); // 重连后重置进入提示记录
  2027. this.startHeartBeat();
  2028. });
  2029. // 消息接收事件
  2030. socketTask.onMessage((res) => {
  2031. try {
  2032. const data = JSON.parse(res.data);
  2033. // 处理服务端心跳响应(根据服务端协议调整cmd字段)
  2034. if (data.cmd === "heartBeatAck") {
  2035. this.stopHeartBeat(); // 清除当前超时检测
  2036. this.startHeartBeat(); // 重新启动心跳周期
  2037. return;
  2038. }
  2039. this.handleSocketMessage(res);
  2040. } catch (err) {
  2041. console.error("消息解析异常:", err);
  2042. }
  2043. });
  2044. // 连接错误事件
  2045. socketTask.onError((err) => {
  2046. console.error("WebSocket连接错误:", err);
  2047. this.isSocketOpen = false;
  2048. this.stopHeartBeat();
  2049. this.isConnecting = false;
  2050. this.handleReconnect(); // 错误直接触发重连
  2051. });
  2052. // 连接关闭事件
  2053. socketTask.onClose((res) => {
  2054. console.log("WebSocket连接关闭:", res);
  2055. this.isSocketOpen = false;
  2056. this.isConnecting = false;
  2057. this.stopHeartBeat(); // 清除心跳定时器(复用之前的停止方法)
  2058. if (!this.isManualClose && this.reconnectCount < this.maxReconnectAttempts) {
  2059. this.handleReconnect();
  2060. } else {}
  2061. });
  2062. } catch (e) {
  2063. console.error("创建WebSocket异常:", e);
  2064. this.handleReconnect();
  2065. }
  2066. },
  2067. handleTime(time, duration) {
  2068. // 前置处理:将time转换为毫秒级时间戳
  2069. let timeStamp;
  2070. // 1. 如果time是数字且合理(毫秒级时间戳通常为13位左右的正数),视为有效时间戳
  2071. if (typeof time === 'number' && time > 0 && time < 9999999999999) { // 上限约为3000年
  2072. timeStamp = time;
  2073. }
  2074. // 2. 如果是字符串,尝试解析为日期后转为时间戳
  2075. else if (typeof time === 'string' && time.trim() !== '') {
  2076. // 处理兼容性:将"2025-09-25 17:30:00"转为ISO格式"2025-09-25T17:30:00"
  2077. const isoTime = time.replace(' ', 'T');
  2078. const date = new Date(isoTime);
  2079. // 校验日期是否有效
  2080. if (!isNaN(date.getTime())) {
  2081. timeStamp = date.getTime();
  2082. } else {
  2083. console.error('无效的日期格式:', time);
  2084. return false; // 格式错误时返回false
  2085. }
  2086. } else {
  2087. console.error('time参数必须是有效的时间戳(数字)或日期字符串');
  2088. return false;
  2089. }
  2090. // 后续逻辑保持不变(基于转换后的timeStamp计算)
  2091. const targetTimestamp = timeStamp + duration * 60 * 1000;
  2092. const currentTimestamp = new Date().getTime();
  2093. const timeDiffMs = targetTimestamp - currentTimestamp;
  2094. if (timeDiffMs <= 0) {
  2095. return false;
  2096. }
  2097. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  2098. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  2099. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  2100. const formatNum = (num) => num.toString().padStart(2, "0");
  2101. return {
  2102. hours: formatNum(hours),
  2103. minutes: formatNum(minutes),
  2104. seconds: formatNum(seconds)
  2105. };
  2106. },
  2107. // 处理Socket消息
  2108. async handleSocketMessage(message) {
  2109. let data = JSON.parse(message.data)
  2110. const socketMessage = data.data // 服务端返回的消息体
  2111. if (data.code == 200) {
  2112. const messageData = {
  2113. ...socketMessage,
  2114. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  2115. ts: Date.now() // 时间戳
  2116. };
  2117. // 处理服务端返回的sendMsg消息,加入本地列表
  2118. if (socketMessage.cmd == 'sendMsg') {
  2119. if (!this.isSocketAvailable()) {
  2120. uni.showToast({
  2121. title: '连接已断开,正在重试...',
  2122. icon: 'none'
  2123. });
  2124. this.handleReconnect(); // 主动触发重连
  2125. return;
  2126. }
  2127. const oldList = Array.isArray(this.talklist) ? this.talklist : [];
  2128. const newList = [...oldList, messageData];
  2129. this.talklist = newList;
  2130. // 1. 将消息追加到当前直播间的talklist中(响应式更新)
  2131. this.talklist = newList;
  2132. // 2. 延迟下一帧滚动到最新消息(确保DOM已更新)
  2133. this.$nextTick(() => {
  2134. const lastIndex = this.talklist.length - 1;
  2135. this.scrollIntoView = `list_${lastIndex}`;
  2136. });
  2137. } else if (socketMessage.cmd == 'red') {
  2138. this.redInfo = JSON.parse(socketMessage.data);
  2139. this.isShowRed = socketMessage.status === 1;
  2140. if (this.isShowRed) {
  2141. this.redTimer = setInterval(() => {
  2142. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  2143. .duration)
  2144. if (!redCountdown) {
  2145. this.isShowRed = false
  2146. clearInterval(this.redTimer)
  2147. }
  2148. }, 1000);
  2149. }
  2150. } else if (socketMessage.cmd == 'goods') {
  2151. this.goodsCard = JSON.parse(socketMessage.data);
  2152. this.isShowGoods = socketMessage.status == 1;
  2153. } else if (socketMessage.cmd == 'coupon') {
  2154. this.couponInfo = JSON.parse(socketMessage.data);
  2155. this.isShowCoupon = socketMessage.status === 1;
  2156. if (this.isShowCoupon) {
  2157. // this.couponTimer = setInterval(() => {
  2158. // const couponCountdown = this.handleTime(this.couponInfo.updateTime, this.couponInfo.duration)
  2159. // if (!couponCountdown) {
  2160. // this.isShowCoupon = false
  2161. // clearInterval(this.couponTimer)
  2162. // }
  2163. // }, 1000);
  2164. }
  2165. } else if (socketMessage.cmd == 'lottery') {
  2166. const parsedData = JSON.parse(socketMessage.data || '{}'); // 默认为空对象
  2167. this.lotteryInfo = parsedData || {}; // 确保是对象,避免 null
  2168. this.isShowLottery = socketMessage.status === 1;
  2169. if (socketMessage.status != 1) {
  2170. this.isShowLotteryPop = false
  2171. }
  2172. // 清除已有定时器(无论状态是否为1,先清掉旧的)
  2173. clearTimeout(this.lotteryTimer);
  2174. if (this.isShowLottery) {
  2175. this.lotteryTimer = setInterval(() => {
  2176. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this.lotteryInfo
  2177. .duration)
  2178. if (!this.countdown) {
  2179. console.log("倒计时", this.countdown)
  2180. this.isShowLottery = false;
  2181. this.isShowLotteryPop = false;
  2182. clearInterval(this.lotteryTimer)
  2183. }
  2184. }, 1000);
  2185. } else {
  2186. this.isShowLottery = false
  2187. }
  2188. } else if (socketMessage.cmd == 'entry') {
  2189. try {
  2190. if (!this.liveUserCalled) {
  2191. await this.getliveUser(false);
  2192. this.liveUserCalled = true;
  2193. }
  2194. const userIdToEntry = socketMessage.userId;
  2195. const existingIndex = this.liveViewersData.findIndex(item => item.userId ===
  2196. userIdToEntry);
  2197. if (existingIndex === -1) {
  2198. const liveViewers = {
  2199. userId: socketMessage.userId,
  2200. nickName: socketMessage.nickName,
  2201. avatar: socketMessage.avatar
  2202. }
  2203. this.liveViewersData.push(liveViewers);
  2204. console.log("在这里>>>", this.liveViewersData);
  2205. this.liveUserTotal++;
  2206. }
  2207. // 解析用户ID(根据实际接口字段调整,此处假设data含userId)
  2208. const userData = JSON.parse(socketMessage.data || '{}');
  2209. const userId = userData.userId || socketMessage.userId; // 兼容不同字段
  2210. if (!userId) return; // 无用户ID不处理
  2211. // 仅新用户(未显示过)才触发提示
  2212. if (!this.shownEntryUsers.has(userId)) {
  2213. this.inAndOut = socketMessage;
  2214. this.showWelcomeMessage = true;
  2215. this.shownEntryUsers.add(userId); // 加入已显示集合
  2216. // 3秒后隐藏提示(可调整时长)
  2217. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2218. this.welcomeTimer = setTimeout(() => {
  2219. this.showWelcomeMessage = false;
  2220. }, 3000);
  2221. }
  2222. } catch (err) {
  2223. console.error("解析entry用户数据失败:", err);
  2224. }
  2225. } else if (socketMessage.cmd == 'out') {
  2226. // console.log("用户离开");
  2227. if (this.liveUserTotal > 0) {
  2228. const userIdToRemove = socketMessage.userId;
  2229. const index = this.liveViewersData.findIndex(item => item.userId === userIdToRemove);
  2230. if (index !== -1) {
  2231. this.liveViewersData.splice(index, 1);
  2232. this.liveUserTotal--; // 根据userId删除对应的用户数据
  2233. }
  2234. }
  2235. this.inAndOut = socketMessage;
  2236. this.showWelcomeMessage = true;
  2237. // 3秒后隐藏提示
  2238. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2239. this.welcomeTimer = setTimeout(() => {
  2240. this.showWelcomeMessage = false;
  2241. }, 3000);
  2242. } else if (socketMessage.cmd == 'live_start' || socketMessage.cmd ==
  2243. 'live_end') {
  2244. // this.getliving(this.liveId);
  2245. // 开始直播,关闭直播
  2246. if (this.liveStartTimer) {
  2247. clearInterval(this.liveStartTimer);
  2248. this.liveStartTimer = null;
  2249. }
  2250. if (this.redTimer) {
  2251. clearInterval(this.redTimer);
  2252. this.redTimer = null;
  2253. }
  2254. // 2. 请求最新直播间数据
  2255. this.getliving(this.liveId); // 注意:需用 await 确保数据更新完成
  2256. // 3. 强制触发视图更新(兜底方案,若上述步骤仍不生效)
  2257. // this.$forceUpdate();
  2258. } else if (socketMessage.cmd == 'Integral') {
  2259. this.integral = {
  2260. msg: socketMessage.msg,
  2261. status: true
  2262. }
  2263. } else if (socketMessage.cmd == 'LotteryDetail') {
  2264. try {
  2265. // 1. 兜底空数据为 "[]",避免 JSON.parse(undefined) 报错
  2266. const parseData = socketMessage.data || '[]';
  2267. // 2. 解析 JSON 并捕获异常
  2268. const prizeData = JSON.parse(parseData);
  2269. // 3. 强制转为数组
  2270. this.prizeInfo = Array.isArray(prizeData) ? prizeData : [];
  2271. } catch (err) {
  2272. console.error('解析抽奖结果失败:', err);
  2273. // 4. 异常时兜底为数组
  2274. this.prizeInfo = [];
  2275. }
  2276. this.isShowPrize = true;
  2277. this.isShowLottery = false;
  2278. this.isShowLotteryPop = false;
  2279. } else if (socketMessage.cmd == 'blockUser') {
  2280. uni.removeStorage({
  2281. key: 'AppToken',
  2282. success: () => {
  2283. uni.reLaunch({
  2284. url: '/pages/auth/login'
  2285. });
  2286. }
  2287. });
  2288. }
  2289. } else {
  2290. uni.showToast({
  2291. title: data.msg,
  2292. icon: 'none'
  2293. });
  2294. }
  2295. },
  2296. sendMsg(retries = 1) {
  2297. // 防止连续点击发送两次(短时锁定)
  2298. if (this.isSending) return;
  2299. this.isSending = true;
  2300. setTimeout(() => {
  2301. this.isSending = false;
  2302. }, 800); // 800ms 内禁止再次发送
  2303. const text = (this.value || '').trim();
  2304. if (!text) {
  2305. uni.showToast({
  2306. title: "不能发送空消息",
  2307. icon: 'none'
  2308. });
  2309. return;
  2310. }
  2311. // 1. 连接状态校验:使用定义后的 retries
  2312. if (!this.isSocketAvailable()) {
  2313. if (retries > 0) {
  2314. uni.showToast({
  2315. title: `连接不稳定,正在重试(${retries}次)...`,
  2316. icon: 'none'
  2317. });
  2318. // 延迟500ms重试,重试次数减1
  2319. setTimeout(() => this.sendMsg(retries - 1), 500);
  2320. } else {
  2321. uni.showToast({
  2322. title: '连接已断开,发送失败',
  2323. icon: 'none'
  2324. });
  2325. this.value = text; // 恢复输入框内容
  2326. }
  2327. return;
  2328. }
  2329. const liveId = this.liveId;
  2330. this.value = ''; // 立即清空输入框,提升体验
  2331. // 构造发送给服务端的消息数据
  2332. const data = {
  2333. liveId,
  2334. userId: this.userData.userId,
  2335. userType: 0,
  2336. cmd: "sendMsg",
  2337. msg: text,
  2338. nickName: this.userData.nickname || '未命名',
  2339. avatar: this.userData.avatar || '/static/images/avatar.png'
  2340. };
  2341. // 发送socket消息
  2342. try {
  2343. this.socket.send({
  2344. data: JSON.stringify(data),
  2345. success: () => {
  2346. // console.log("发送成功");
  2347. this.value = '';
  2348. },
  2349. fail: (err) => {
  2350. console.error("消息发送失败:", err);
  2351. // 2. 发送失败重试:使用定义后的 retries
  2352. if (retries > 0) {
  2353. uni.showToast({
  2354. title: `发送失败,正在重试(${retries}次)`,
  2355. icon: 'none'
  2356. });
  2357. setTimeout(() => this.sendMsg(retries - 1), 500);
  2358. } else {
  2359. uni.showToast({
  2360. title: '发送失败,请稍后再试',
  2361. icon: 'none'
  2362. });
  2363. this.value = text; // 恢复输入框内容
  2364. }
  2365. }
  2366. });
  2367. } catch (err) {
  2368. console.error("发送消息异常:", err);
  2369. if (retries > 0) {
  2370. setTimeout(() => this.sendMsg(retries - 1), 500);
  2371. } else {
  2372. uni.showToast({
  2373. title: '发送失败,请稍后再试',
  2374. icon: 'none'
  2375. });
  2376. this.value = text;
  2377. }
  2378. }
  2379. }
  2380. }
  2381. };
  2382. </script>
  2383. <style scoped lang="scss">
  2384. ::v-deep .u-icon--right {
  2385. justify-content: flex-end !important;
  2386. }
  2387. // 无头像用户文字样式
  2388. .text-white {
  2389. color: #ffffff;
  2390. }
  2391. .text-xs {
  2392. font-size: 16rpx;
  2393. }
  2394. .text-sm {
  2395. font-size: 24rpx;
  2396. }
  2397. .w52,
  2398. .w72 {
  2399. display: flex;
  2400. align-items: center;
  2401. justify-content: center;
  2402. }
  2403. .coupon {
  2404. padding: 20rpx;
  2405. .coupon-top {}
  2406. .coupon-list {
  2407. margin-top: 0.25 * 100rpx;
  2408. box-sizing: border-box;
  2409. .item {
  2410. display: flex;
  2411. width: 100%;
  2412. height: 1.7 * 100rpx;
  2413. margin-bottom: 0.16 * 100rpx;
  2414. .money {
  2415. background-size: 100% 100%;
  2416. width: 2.4 * 100rpx;
  2417. height: 100%;
  2418. color: #fff;
  2419. font-size: 0.36 * 100rpx;
  2420. font-weight: bold;
  2421. text-align: center;
  2422. display: flex;
  2423. flex-direction: column;
  2424. align-items: center;
  2425. justify-content: center;
  2426. position: relative;
  2427. .img {
  2428. position: absolute;
  2429. width: 2.4 * 100rpx;
  2430. height: 100%;
  2431. color: #fff;
  2432. }
  2433. .num {
  2434. font-size: 0.6 * 100rpx;
  2435. }
  2436. .pic-num {
  2437. font-size: 20rpx;
  2438. z-index: 99;
  2439. }
  2440. }
  2441. .text {
  2442. width: 4.5 * 100rpx;
  2443. padding: 0 0.17 * 100rpx 0 0.24 * 100rpx;
  2444. background-color: #fff;
  2445. box-sizing: border-box;
  2446. .condition {
  2447. font-size: 0.3 * 100rpx;
  2448. color: #282828;
  2449. height: 0.93 * 100rpx;
  2450. line-height: 0.93 * 100rpx;
  2451. border-bottom: 1px solid #f0f0f0;
  2452. }
  2453. .data {
  2454. font-size: 0.2 * 100rpx;
  2455. color: #999;
  2456. height: 0.76 * 100rpx;
  2457. .bnt {
  2458. width: 1.36 * 100rpx;
  2459. height: 0.44 * 100rpx;
  2460. border-radius: 0.22 * 100rpx;
  2461. font-size: 0.22 * 100rpx;
  2462. color: #fff;
  2463. text-align: center;
  2464. line-height: 0.44 * 100rpx;
  2465. background-color: red;
  2466. .gray {
  2467. background-color: #ccc;
  2468. }
  2469. }
  2470. }
  2471. }
  2472. }
  2473. }
  2474. }
  2475. .swiper-wrapper {
  2476. position: relative;
  2477. width: 100%;
  2478. height: 100vh;
  2479. overflow: hidden;
  2480. background-color: #000000;
  2481. .container {
  2482. width: 100%;
  2483. height: 100%;
  2484. position: relative;
  2485. transition: opacity 0.3s ease;
  2486. transform: translateZ(0); // 开启GPU加速
  2487. will-change: opacity; // 告诉浏览器提前优化该属性
  2488. }
  2489. }
  2490. .loading-tip {
  2491. position: absolute;
  2492. top: 50%;
  2493. left: 50%;
  2494. transform: translate(-50%, -50%);
  2495. display: flex;
  2496. flex-direction: column;
  2497. align-items: center;
  2498. justify-content: center;
  2499. z-index: 10;
  2500. .loading-text {
  2501. color: #ffffff;
  2502. font-size: 28rpx;
  2503. margin-top: 20rpx;
  2504. }
  2505. }
  2506. .loading-more,
  2507. .no-more {
  2508. display: flex;
  2509. justify-content: center;
  2510. align-items: center;
  2511. padding: 20rpx 0;
  2512. color: #999;
  2513. font-size: 24rpx;
  2514. }
  2515. .loading-more {
  2516. flex-direction: column;
  2517. }
  2518. /* button自带样式清除 */
  2519. button::after {
  2520. border: none !important;
  2521. padding: 0 !important;
  2522. margin: 0 !important;
  2523. }
  2524. button {
  2525. background-color: transparent !important;
  2526. padding: 0 !important;
  2527. line-height: inherit !important;
  2528. margin: 0 !important;
  2529. width: auto !important;
  2530. font-weight: 500 !important;
  2531. border-radius: none !important;
  2532. }
  2533. .welcome-message {
  2534. position: fixed;
  2535. width: 100%;
  2536. bottom: 38vh;
  2537. left: 50%;
  2538. transform: translateX(-50%);
  2539. color: white;
  2540. padding: 10px 20px;
  2541. border-radius: 20px;
  2542. z-index: 10;
  2543. transition: opacity 0.3s ease;
  2544. }
  2545. @keyframes fadeOut {
  2546. from {
  2547. opacity: 1;
  2548. }
  2549. to {
  2550. opacity: 0;
  2551. }
  2552. }
  2553. .send {
  2554. background-color: #fafafa;
  2555. border-radius: 28rpx;
  2556. padding: 14rpx 16rpx;
  2557. color: #181818;
  2558. font-weight: 500;
  2559. }
  2560. .send-input {
  2561. background-color: #ffb082;
  2562. border-radius: 28rpx;
  2563. padding: 14rpx 16rpx;
  2564. color: #ffffff;
  2565. font-weight: 500;
  2566. }
  2567. .talk-list {
  2568. max-width: 100%;
  2569. border-radius: 30rpx;
  2570. background-color: rgba(33, 33, 33, 0.5);
  2571. padding: 10rpx 30rpx;
  2572. }
  2573. .content {
  2574. position: relative;
  2575. z-index: 2;
  2576. height: 100%;
  2577. width: 100%;
  2578. top: 0;
  2579. left: 0;
  2580. display: flex;
  2581. flex-direction: column;
  2582. justify-content: space-between;
  2583. .activity-box {
  2584. position: fixed;
  2585. top: 188rpx;
  2586. left: 30rpx;
  2587. z-index: 5;
  2588. display: flex;
  2589. align-items: center;
  2590. .item-box {
  2591. border-radius: 16rpx;
  2592. background-color: rgba(77, 77, 77, 0.5);
  2593. width: 90rpx;
  2594. height: 100rpx;
  2595. margin-right: 20rpx;
  2596. position: relative;
  2597. z-index: 999;
  2598. .tip {
  2599. position: absolute;
  2600. width: 100%;
  2601. bottom: 0;
  2602. color: #fafcff;
  2603. font-size: 26rpx;
  2604. background-color: rgba(15, 15, 15, 0.8);
  2605. border-radius: 16rpx;
  2606. text-align: center;
  2607. }
  2608. .item {
  2609. margin: 0 auto;
  2610. padding: 10rpx 0;
  2611. .img {
  2612. height: 100%;
  2613. }
  2614. }
  2615. }
  2616. }
  2617. .side-group {
  2618. position: absolute;
  2619. top: 65%;
  2620. right: 30rpx;
  2621. z-index: 1000;
  2622. display: flex;
  2623. flex-direction: column;
  2624. align-items: center;
  2625. .side-item {
  2626. font-weight: 500;
  2627. font-size: 24rpx;
  2628. color: #FFFFFF;
  2629. margin-bottom: 32rpx;
  2630. text-align: center;
  2631. .image {
  2632. width: 72rpx;
  2633. height: 72rpx;
  2634. }
  2635. }
  2636. }
  2637. .content-top {
  2638. width: 100%;
  2639. margin-top: 48rpx;
  2640. display: flex;
  2641. justify-content: space-between;
  2642. padding: 0 24rpx;
  2643. box-sizing: border-box;
  2644. .sum {
  2645. width: 80rpx;
  2646. height: 52rpx;
  2647. background: rgba(0, 0, 0, 0.5);
  2648. border-radius: 26rpx 26rpx 26rpx 26rpx;
  2649. font-size: 24rpx;
  2650. color: #FFFFFF;
  2651. text-align: center;
  2652. line-height: 52rpx;
  2653. }
  2654. }
  2655. .follow-btn {
  2656. padding: 8rpx 16rpx;
  2657. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2658. border-radius: 26rpx;
  2659. font-weight: 500;
  2660. font-size: 26rpx;
  2661. color: #FFFFFF;
  2662. }
  2663. }
  2664. .trailer-box {
  2665. position: relative;
  2666. top: 15%;
  2667. display: flex;
  2668. flex-direction: column;
  2669. align-items: center;
  2670. color: #ffffff;
  2671. padding: 20rpx;
  2672. .button {
  2673. margin-top: 20rpx;
  2674. background: #6d7bd4;
  2675. color: #fff;
  2676. border-radius: 20rpx;
  2677. padding: 20rpx 30rpx;
  2678. position: relative;
  2679. z-index: 99999;
  2680. }
  2681. .ash {
  2682. background: #636363;
  2683. }
  2684. .countdown-item {
  2685. display: flex;
  2686. flex-direction: column;
  2687. align-items: center;
  2688. .white {
  2689. width: 60rpx;
  2690. height: 60rpx;
  2691. text-align: center;
  2692. overflow: hidden;
  2693. background: #FFFFFF;
  2694. border-radius: 8rpx;
  2695. margin: 30rpx 10rpx 0;
  2696. font-weight: 600;
  2697. font-size: 24rpx;
  2698. color: #000000;
  2699. line-height: 60rpx;
  2700. }
  2701. }
  2702. .item {
  2703. width: 100%;
  2704. height: 400rpx;
  2705. }
  2706. .name {
  2707. font-size: 34rpx;
  2708. }
  2709. .img {
  2710. margin-bottom: 40rpx;
  2711. width: 240rpx;
  2712. height: 240rpx;
  2713. }
  2714. .title {
  2715. margin-top: 30rpx;
  2716. font-size: 42rpx;
  2717. font-weight: 500;
  2718. }
  2719. }
  2720. .videolist {
  2721. position: relative;
  2722. height: 100vh;
  2723. width: 100%;
  2724. .video {
  2725. height: 100vh;
  2726. width: 100%;
  2727. background-color: rgba(57, 57, 57, 0.4);
  2728. .item {
  2729. width: 100%;
  2730. height: 100%;
  2731. }
  2732. .time {
  2733. color: #ffffff;
  2734. font-size: 20rpx;
  2735. margin-left: 10rpx;
  2736. }
  2737. .lable {
  2738. position: absolute;
  2739. top: 50rpx;
  2740. right: 16rpx;
  2741. background-color: rgba(57, 57, 57, 0.6);
  2742. padding: 4rpx 10rpx;
  2743. color: #fff;
  2744. border-radius: 15rpx;
  2745. }
  2746. }
  2747. .video_row {
  2748. position: absolute;
  2749. top: 20%;
  2750. max-height: 450rpx;
  2751. z-index: 99;
  2752. }
  2753. }
  2754. .prize-card {
  2755. width: 504rpx;
  2756. padding: 40rpx 40rpx 30rpx;
  2757. box-sizing: border-box;
  2758. display: flex;
  2759. flex-direction: column;
  2760. border-radius: 20rpx;
  2761. align-items: center;
  2762. background: linear-gradient(180deg, #f7823f 0%, #ffd4be 27%, #ffffff 100%);
  2763. position: relative;
  2764. .nav-img {
  2765. width: 311rpx;
  2766. position: absolute;
  2767. top: -122rpx;
  2768. left: 50%;
  2769. transform: translateX(-50%);
  2770. }
  2771. .title {
  2772. color: #C32008;
  2773. font-size: 34rpx;
  2774. font-weight: 600;
  2775. margin: 20rpx 0 40rpx;
  2776. }
  2777. .prize-content {
  2778. width: 100%;
  2779. display: flex;
  2780. justify-content: space-between;
  2781. align-items: center;
  2782. font-size: 28rpx;
  2783. margin: 10rpx 0;
  2784. .txt {
  2785. font-weight: 600;
  2786. }
  2787. }
  2788. .tip {
  2789. font-size: 28rpx;
  2790. color: #414141;
  2791. margin: 40rpx 0;
  2792. }
  2793. .button {
  2794. width: 200rpx;
  2795. height: 70rpx;
  2796. line-height: 70rpx;
  2797. background: linear-gradient(180deg, #ff7c30 0%, #FF3A1E 100%);
  2798. border-radius: 28rpx;
  2799. font-weight: 500;
  2800. font-size: 32rpx;
  2801. color: #ffffff;
  2802. text-align: center;
  2803. }
  2804. }
  2805. .no-prize-card {
  2806. width: 504rpx;
  2807. padding: 40rpx 40rpx 30rpx;
  2808. box-sizing: border-box;
  2809. display: flex;
  2810. flex-direction: column;
  2811. border-radius: 20rpx;
  2812. align-items: center;
  2813. position: relative;
  2814. .img {
  2815. margin-top: 40rpx;
  2816. width: 300rpx;
  2817. height: 300rpx;
  2818. }
  2819. .tip {
  2820. font-size: 36rpx;
  2821. color: #414141;
  2822. margin: 40rpx 0;
  2823. }
  2824. .button {
  2825. width: 220rpx;
  2826. height: 80rpx;
  2827. line-height: 80rpx;
  2828. background: linear-gradient(180deg, #fdfbb8 0%, #b79243 100%);
  2829. border-radius: 28rpx;
  2830. font-weight: 500;
  2831. font-size: 32rpx;
  2832. color: #ffffff;
  2833. text-align: center;
  2834. }
  2835. }
  2836. .red-card {
  2837. width: 550rpx;
  2838. height: 636rpx;
  2839. position: relative;
  2840. .img {
  2841. position: absolute;
  2842. width: 100%;
  2843. height: 100%;
  2844. }
  2845. .red-content {
  2846. position: relative;
  2847. z-index: 5;
  2848. display: flex;
  2849. flex-direction: column;
  2850. align-items: center;
  2851. .title {
  2852. font-size: 36rpx;
  2853. color: #FF3A1E;
  2854. margin: 180rpx 0 90rpx;
  2855. }
  2856. .txt {
  2857. font-size: 28rpx;
  2858. color: #FFECC3;
  2859. margin: 80rpx 0 40rpx;
  2860. }
  2861. .button {
  2862. width: 392rpx;
  2863. height: 96rpx;
  2864. line-height: 96rpx;
  2865. background: linear-gradient(180deg, #FFF4D5 0%, #FFE5B1 100%);
  2866. border-radius: 48rpx 48rpx 48rpx 48rpx;
  2867. font-weight: 600;
  2868. font-size: 36rpx;
  2869. color: #C32008;
  2870. text-align: center;
  2871. }
  2872. }
  2873. }
  2874. .integral-box {
  2875. min-width: 400rpx;
  2876. max-width: 600rpx;
  2877. display: flex;
  2878. flex-direction: column;
  2879. align-items: center;
  2880. border-radius: 20rpx;
  2881. overflow: hidden;
  2882. .top {
  2883. width: 100%;
  2884. position: relative;
  2885. .title {
  2886. width: 100%;
  2887. font-weight: 600;
  2888. font-size: 40rpx;
  2889. color: #FFFFFF;
  2890. text-shadow: 0px 4px 8px rgba(255, 89, 2, 0.8);
  2891. position: absolute;
  2892. top: 50rpx;
  2893. text-align: center;
  2894. }
  2895. .photo {
  2896. width: 100%;
  2897. }
  2898. }
  2899. .item {
  2900. padding: 20rpx;
  2901. .title {
  2902. font-weight: 500;
  2903. font-size: 32rpx;
  2904. text-align: center;
  2905. }
  2906. .button {
  2907. font-size: 32rpx;
  2908. margin-top: 20rpx;
  2909. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2910. color: #fff;
  2911. text-align: center;
  2912. padding: 18rpx 60rpx;
  2913. border-radius: 10rpx;
  2914. font-weight: 500;
  2915. }
  2916. }
  2917. }
  2918. .goods {
  2919. position: fixed;
  2920. bottom: 140rpx;
  2921. right: 104rpx;
  2922. z-index: 5;
  2923. background-color: #fff;
  2924. border-radius: 20rpx;
  2925. overflow: hidden;
  2926. width: 280rpx;
  2927. padding: 4rpx;
  2928. .top {
  2929. position: absolute;
  2930. top: 4rpx;
  2931. display: flex;
  2932. justify-content: space-between;
  2933. align-items: center;
  2934. color: #fff;
  2935. width: 100%;
  2936. padding-right: 10rpx;
  2937. box-sizing: border-box;
  2938. .left {
  2939. background-color: rgba(0, 0, 0, 0.8);
  2940. padding: 12rpx;
  2941. font-size: 22rpx;
  2942. display: flex;
  2943. justify-content: space-between;
  2944. align-items: center;
  2945. border-radius: 10rpx;
  2946. }
  2947. }
  2948. .photo {
  2949. width: 100%;
  2950. height: 180rpx;
  2951. border-radius: 16rpx 16rpx 0 0;
  2952. overflow: hidden;
  2953. }
  2954. .item {
  2955. padding: 4rpx;
  2956. .price {
  2957. font-size: 30rpx;
  2958. .red {
  2959. color: #FF5701;
  2960. font-weight: 600;
  2961. margin-right: 10rpx;
  2962. }
  2963. .del {
  2964. color: #828282;
  2965. font-weight: 500;
  2966. font-size: 28rpx;
  2967. text-decoration: line-through
  2968. }
  2969. }
  2970. .title {
  2971. font-weight: 500;
  2972. font-size: 30rpx;
  2973. margin: 10rpx 0 12rpx;
  2974. }
  2975. .button {
  2976. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2977. color: #fff;
  2978. text-align: center;
  2979. padding: 16rpx 0;
  2980. border-radius: 10rpx;
  2981. font-weight: 500;
  2982. font-size: 30rpx;
  2983. }
  2984. }
  2985. }
  2986. .coupon-pop {
  2987. position: fixed;
  2988. bottom: 140rpx;
  2989. right: 100rpx;
  2990. z-index: 5;
  2991. border-radius: 20rpx;
  2992. width: 320rpx;
  2993. .coupon-block {
  2994. width: 100%;
  2995. position: relative;
  2996. .item {
  2997. width: 100%;
  2998. position: absolute;
  2999. top: 20rpx;
  3000. display: flex;
  3001. flex-direction: column;
  3002. align-items: center;
  3003. color: #fff;
  3004. .title {
  3005. font-weight: 500;
  3006. font-size: 30rpx;
  3007. margin: 16rpx 0 12rpx;
  3008. }
  3009. .price {
  3010. font-size: 40rpx;
  3011. .bold {
  3012. font-size: 56rpx;
  3013. font-weight: 600;
  3014. }
  3015. }
  3016. .txt {
  3017. font-weight: 500;
  3018. font-size: 30rpx;
  3019. margin: 5rpx 0;
  3020. }
  3021. .button {
  3022. background: linear-gradient(270deg, #fffce1 0%, #ffeaaf 100%);
  3023. color: #ff0004;
  3024. text-align: center;
  3025. padding: 16rpx 0;
  3026. border-radius: 40rpx;
  3027. font-weight: 500;
  3028. font-size: 30rpx;
  3029. width: 70%;
  3030. margin-top: 26rpx;
  3031. }
  3032. }
  3033. .bg {
  3034. height: 432rpx;
  3035. width: 100%;
  3036. }
  3037. .nav {
  3038. position: absolute;
  3039. height: 120rpx;
  3040. top: -120rpx;
  3041. left: 0;
  3042. width: 100%;
  3043. z-index: 6;
  3044. }
  3045. .close {
  3046. position: absolute;
  3047. right: 10rpx;
  3048. top: 10rpx;
  3049. }
  3050. }
  3051. }
  3052. .icon-bg {
  3053. background-color: rgba(57, 57, 57, 0.8);
  3054. border-radius: 50%;
  3055. width: 88rpx;
  3056. height: 88rpx;
  3057. display: flex;
  3058. justify-content: center;
  3059. align-items: center;
  3060. transition: transform 0.2s ease;
  3061. }
  3062. .list {
  3063. width: 80%;
  3064. margin-bottom: 20rpx;
  3065. animation: xxxawdawd .2s;
  3066. }
  3067. @keyframes xxxawdawd {
  3068. from {
  3069. margin-top: 0rpx;
  3070. opacity: 0;
  3071. }
  3072. to {
  3073. margin-top: 20rpx;
  3074. opacity: 1;
  3075. }
  3076. }
  3077. .shop-prompt {
  3078. position: absolute;
  3079. bottom: 750rpx;
  3080. left: 24rpx;
  3081. padding: 6rpx 20rpx;
  3082. background: rgba(230, 154, 34, 0.7);
  3083. border-radius: 24rpx;
  3084. z-index: 9;
  3085. font-weight: 500;
  3086. color: #FFFFFF;
  3087. transition: opacity 0.3s ease;
  3088. }
  3089. .red-box {
  3090. .button {
  3091. margin: 0 auto;
  3092. width: 80%;
  3093. line-height: 88rpx;
  3094. height: 88rpx;
  3095. background: linear-gradient(90deg, #FF5701 0%, #FFB501 100%);
  3096. box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(238, 124, 80, 0.2);
  3097. border-radius: 44rpx 44rpx 44rpx 44rpx;
  3098. font-weight: 600;
  3099. font-size: 32rpx;
  3100. color: #FFFFFF;
  3101. text-align: center;
  3102. }
  3103. }
  3104. .view-box {
  3105. position: relative;
  3106. height: 40vh;
  3107. /* 设置弹出层高度为视窗高度的70% */
  3108. padding: 40rpx 0rpx 120rpx;
  3109. box-sizing: border-box;
  3110. display: flex;
  3111. flex-direction: column;
  3112. .scroll-content {
  3113. flex: 1;
  3114. overflow-y: auto;
  3115. padding: 0 40rpx;
  3116. }
  3117. .bottom {
  3118. padding: 20rpx 40rpx;
  3119. position: absolute;
  3120. bottom: 0;
  3121. width: 100%;
  3122. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  3123. background: #fff;
  3124. }
  3125. }
  3126. // 抽奖
  3127. .prize-box {
  3128. position: relative;
  3129. .nav-img {
  3130. width: 311rpx;
  3131. position: absolute;
  3132. top: -122rpx;
  3133. left: 50%;
  3134. transform: translateX(-50%);
  3135. }
  3136. .bg-img {
  3137. position: absolute;
  3138. top: 0;
  3139. left: 0;
  3140. width: 100%;
  3141. height: 100%;
  3142. z-index: 1;
  3143. }
  3144. .prize-content {
  3145. position: relative;
  3146. z-index: 2;
  3147. padding: 24rpx 0 68rpx;
  3148. .white-item {
  3149. width: 40rpx;
  3150. height: 40rpx;
  3151. text-align: center;
  3152. overflow: hidden;
  3153. background: #FFFFFF;
  3154. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #FFEBB2;
  3155. border-radius: 8rpx;
  3156. margin: 4rpx;
  3157. font-weight: 600;
  3158. font-size: 24rpx;
  3159. color: #F85D22;
  3160. line-height: 40rpx;
  3161. }
  3162. .item-group {
  3163. width: 100%;
  3164. }
  3165. .point-group {
  3166. margin: 20rpx 0 50rpx;
  3167. display: flex;
  3168. gap: 6rpx;
  3169. .item {
  3170. width: 20rpx;
  3171. height: 8rpx;
  3172. background: rgba(255, 255, 255, 0.5);
  3173. border-radius: 4rpx 4rpx 4rpx 4rpx;
  3174. }
  3175. .selected {
  3176. background: #FFEB66;
  3177. }
  3178. }
  3179. .button {
  3180. margin-top: 30rpx;
  3181. width: 520rpx;
  3182. height: 88rpx;
  3183. line-height: 88rpx;
  3184. background: linear-gradient(180deg, #FFF4D6 0%, #FFEB66 100%);
  3185. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  3186. border-radius: 44rpx;
  3187. font-weight: 500;
  3188. font-size: 36rpx;
  3189. color: #F4410B;
  3190. text-align: center;
  3191. }
  3192. }
  3193. }
  3194. .shoppop {
  3195. padding: 22rpx 16rpx;
  3196. .shoppop-top {
  3197. display: flex;
  3198. justify-content: space-between;
  3199. align-items: center;
  3200. padding: 0 16rpx 22rpx;
  3201. .search-input {
  3202. width: 414rpx;
  3203. height: 76rpx;
  3204. background: #FFFFFF;
  3205. border-radius: 36rpx;
  3206. margin-left: 20rpx;
  3207. padding: 0 32rpx;
  3208. box-sizing: border-box;
  3209. font-size: 24rpx;
  3210. margin-right: 24rpx;
  3211. }
  3212. .search-top {
  3213. font-size: 20rpx;
  3214. color: #222222;
  3215. }
  3216. }
  3217. .shop-list {
  3218. overflow: hidden;
  3219. .list-item {
  3220. display: flex;
  3221. align-items: center;
  3222. padding: 20rpx 16rpx;
  3223. background: #FFFFFF;
  3224. border-radius: 16rpx;
  3225. margin-bottom: 16rpx;
  3226. .goods-img {
  3227. width: 200rpx;
  3228. height: 200rpx;
  3229. border-radius: 16rpx;
  3230. overflow: hidden;
  3231. position: relative;
  3232. margin-right: 24rpx;
  3233. .img {
  3234. width: 100%;
  3235. height: 100%;
  3236. }
  3237. .goods-label {
  3238. position: absolute;
  3239. top: 0;
  3240. width: 64rpx;
  3241. height: 40rpx;
  3242. background: rgba(0, 0, 0, 0.5);
  3243. border-radius: 16rpx 0rpx 16rpx 0rpx;
  3244. text-align: center;
  3245. font-weight: 500;
  3246. font-size: 28rpx;
  3247. color: #FFFFFF;
  3248. }
  3249. }
  3250. .goods-right {
  3251. flex: 1;
  3252. .goods-title {
  3253. font-weight: 500;
  3254. font-size: 30rpx;
  3255. color: #000000;
  3256. margin-bottom: 10rpx;
  3257. }
  3258. .goods-details {
  3259. font-size: 24rpx;
  3260. color: #999999;
  3261. margin: 10rpx 0 20rpx;
  3262. }
  3263. .goods-people {
  3264. font-size: 22rpx;
  3265. color: #E69A22;
  3266. height: 56rpx;
  3267. }
  3268. .goods-shop {
  3269. display: flex;
  3270. justify-content: space-between;
  3271. .nummber {
  3272. color: #FF5C03;
  3273. font-size: 22rpx;
  3274. font-weight: 500;
  3275. }
  3276. .btn-group {
  3277. text-align: center;
  3278. line-height: 56rpx;
  3279. .collect-btn {
  3280. width: 72rpx;
  3281. height: 100%;
  3282. background: #F5F7FA;
  3283. border-radius: 8rpx 0rpx 0rpx 8rpx;
  3284. }
  3285. .shop-btn {
  3286. width: 152rpx;
  3287. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  3288. border-radius: 0rpx 8rpx 8rpx 0rpx;
  3289. font-weight: 500;
  3290. font-size: 30rpx;
  3291. color: #FFFFFF;
  3292. }
  3293. }
  3294. }
  3295. }
  3296. }
  3297. }
  3298. }
  3299. </style>