living.vue 93 KB

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