living1.vue 100 KB

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