living.vue 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. <template>
  2. <view class="swiper-wrapper">
  3. <swiper class="swiper-container" :current="currentSwiperIndex" :circular="false" vertical
  4. @change="onSwiperChange" :style="{height: '100vh'}" :duration="swiperDuration">
  5. <swiper-item v-for="(liveItem, index) in list" :key="liveItem.liveId">
  6. <view class="container" :class="{active: currentSwiperIndex === index}">
  7. <view class="blackbg"></view>
  8. <view class="content">
  9. <!-- 页面内容 -->
  10. <view style=" position: fixed;top: 0;z-index: 5;" class="content-top">
  11. <view class="u-flex-y-center">
  12. <image @click="goBack" style="width: 60rpx;height: 64rpx;margin-right: 26rpx;"
  13. src="@/static/images/live/return.png"></image>
  14. <view class=" align-center"
  15. style="padding: 6rpx 4rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  16. <u-avatar :src="liveItem.liveImgUrl||$img.logo" size="32"></u-avatar>
  17. <view class="colorf ml10 mr6">
  18. <view>{{liveItem.liveName?truncateString(liveItem.liveName,5):"未命名"}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="u-flex-end align-center" @click="showadd=!showadd" style="margin-top: 100rpx;">
  23. <image class="w52 h52 mr4" v-for="(item,viewerIndex) in filteredViewers"
  24. :key="viewerIndex" style="border-radius: 26rpx;" :src="item.avatar||$img.logo">
  25. </image>
  26. <view class="sum">{{liveUserTotal||0}}</view>
  27. </view>
  28. </view>
  29. <!-- 页面内容 -->
  30. <view style=" position: fixed;top:120rpx;left: 0rpx; z-index: 5;" class="content-top">
  31. <view class="u-flex-y-center">
  32. <image @click="onRed(liveItem)" v-if="liveItem.redInfo?.redStatus==1"
  33. style="width: 70rpx;height: 70rpx;" src="@/static/images/hongbao.png"></image>
  34. </view>
  35. </view>
  36. <!-- 右边的 -->
  37. <!-- <view :class=" liveItem.showType==1 ? 'siderow-group' : 'side-group'">
  38. <view class="side-item">
  39. <image class="image" @click="onLike(liveItem)" src="/static/images/live/like.png"></image>
  40. <view>{{liveItem.liveViewData?.like||0}}</view>
  41. </view>
  42. <view class="side-item">
  43. <button open-type="share" class="button">
  44. <image class="image" src="/static/images/live/share.png" mode="widthFix"></image>
  45. </button>
  46. <view>分享</view>
  47. </view>
  48. <view class="side-item">
  49. <image @click="goStore(liveItem)" src="/static/images/live/shop.png"></image>
  50. <view>店铺</view>
  51. </view>
  52. </view> -->
  53. <view class="shop-prompt u-flex-y-center" v-if="showPurchasePrompt&&orderUser?.count">
  54. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  55. <text> {{orderUser.userName ? maskString(orderUser.userName) : ''}} 等
  56. {{orderUser.count || 0}}
  57. 人正在去购买</text>
  58. </view>
  59. <view class="videolist " style="margin: auto 0">
  60. <view class="video" style="height:100vh">
  61. <!-- 修改video组件以支持HLS -->
  62. <!-- showType 1 横屏 2 竖屏 -->
  63. <video v-if="liveItem.livingUrl" :id="'myVideo_' + liveItem.liveId"
  64. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.livingUrl"
  65. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  66. :custom-cache="false" :enable-progress-gesture="false"
  67. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  68. :http-cache="false" @error="videoError">
  69. </video>
  70. <video v-if="liveItem.videoUrl"
  71. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.videoUrl"
  72. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  73. :custom-cache="false" :enable-progress-gesture="false"
  74. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  75. :http-cache="false" loop @error="videoError">
  76. </video>
  77. <!-- 加载提示 -->
  78. <view v-if="liveItem.loading" class="loading-tip">
  79. <u-loading mode="circle" color="#ffffff" size="36"></u-loading>
  80. <text class="loading-text">加载中...</text>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="pb40 mt90" style="position: fixed;bottom: 0;width: 100%;">
  85. <view class="w100 h300 mt20">
  86. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  87. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  88. :scroll-into-view="liveItem.scrollIntoView">
  89. <view>
  90. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  91. :key="talkIndex" v-show="item.cmd=='announcement'">
  92. <view class="talk-list ml16 justify-start">
  93. <view class="fs24">
  94. <text class='fs24 colorf'>
  95. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  101. :key="talkIndex" :id="`list_${talkIndex}`"
  102. v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  103. <view class="talk-list ml16 justify-start">
  104. <view class="fs24">
  105. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  106. <text class='fs24 colorf'>{{item.msg}}</text>
  107. </view>
  108. </view>
  109. </view>
  110. <view v-if="liveItem.showWelcomeMessage" class="welcome-message">
  111. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  112. :key="talkIndex" v-show="item.cmd=='entry'||item.cmd=='out'">
  113. <view class="talk-list ml16 justify-start">
  114. <view class="fs24">
  115. <text style="color: #ff89d6;">{{item.nickName}} </text>
  116. <!-- <text class='fs24 colorf'>
  117. {{item.msg}}直播间{{liveItem.messageContent}}</text> -->
  118. <text class='fs24 colorf'>
  119. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. </scroll-view>
  125. </view>
  126. <view class="justify-between p24">
  127. <view class="u-flex-y-center"
  128. style="background:rgba(57, 57, 57, 0.8);padding:10rpx 14rpx 10rpx 32rpx;width: 500rpx;box-sizing:border-box;border-radius:36rpx;">
  129. <u-input :placeholder="liveItem.placeholderText" border="none"
  130. customStyle='font-size:24rpx;' v-model="liveItem.value" shape='circle'
  131. color='#fff' placeholderStyle='color:#e7e7e7' class="ml20">
  132. </u-input>
  133. <view class="send" @click="sendMsg(liveItem)">发送</view>
  134. </view>
  135. <view class="justify-between mr15 align-center">
  136. <!-- <view class="side-item">
  137. <image class="image" @click="onLike(liveItem)" src="/static/images/live/like.png"></image>
  138. <view>{{liveItem.liveViewData?.like||0}}</view>
  139. </view>
  140. <view class="side-item">
  141. <button open-type="share" class="button">
  142. <image class="image" src="/static/images/live/share.png" mode="widthFix"></image>
  143. </button>
  144. <view>分享</view>
  145. </view>
  146. -->
  147. <view class="icon ml20" @click="onLike(liveItem)">
  148. <image src="/static/images/live/like.png" class="w56 h56"></image>
  149. <view>{{liveItem.liveViewData?.like||0}}</view>
  150. </view>
  151. <view class="icon ml20">
  152. <button open-type="share" class="button">
  153. <image src="/static/images/live/share.png" class="w56 h56"></image>
  154. </button>
  155. <view>分享</view>
  156. </view>
  157. <!-- <view class="icon-bg ml20" @click="openCart(liveItem)">
  158. <image src="/static/images/shopping.png" class="w48 h48"></image>
  159. </view> -->
  160. <!-- <view class="icon-bg ml20" @click="liveItem.showziliao=!liveItem.showziliao">
  161. <image src="/static/images/more-icon.png" class="w48 h48"></image>
  162. </view> -->
  163. </view>
  164. </view>
  165. </view>
  166. <!-- 弹出商品 -->
  167. <view @click="" class="goods">
  168. <view class="top">
  169. <view class="left">
  170. <image class="w30 h30" src="/static/images/signal.png"></image>讲解中
  171. </view>
  172. <image class="w30 h30" src="/static/images/close.png"></image>
  173. </view>
  174. <image class="photo" src="@/static/images/a.jpg"></image>
  175. <view class="item">
  176. <view class="price"><text class="red">23.55</text><text class="del">26.66</text></view>
  177. <view class="title">新鲜土鸡蛋</view>
  178. <view class="button">立即抢购</view>
  179. </view>
  180. </view>
  181. </view>
  182. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff'>
  183. <view class="view-box">
  184. <view class="t-c fs30">在线观众</view>
  185. <scroll-view scroll-y class="scroll-content" :style="{height: scrollHeight + 'px'}"
  186. @scrolltolower="handleScrollToLower">
  187. <view class="fs24 u-flex-y-center mb20" v-for="(item,index) in liveViewers"
  188. :key="index">
  189. <view
  190. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  191. class="mr10">{{index+1}}</view>
  192. <u-avatar :src="item.avatar||$img.logo" size="32"></u-avatar>
  193. <text class="ml16">{{item.nickName||"未命名"}}</text>
  194. </view>
  195. <view class="no-more" v-if="viewNoMoreData && liveViewers.length > 0">
  196. <text>没有更多了</text>
  197. </view>
  198. </scroll-view>
  199. <!-- <view class="fs24 u-flex-y-center bottom">
  200. <view class="mr10" style="width:50rpx">我</view>
  201. <u-avatar :src="livedata.liveImgUrl||$img.logo" size="32"></u-avatar>
  202. <text class="ml16">{{livedata.liveName||"未命名"}}</text>
  203. </view> -->
  204. </view>
  205. </u-popup>
  206. <u-popup :show="liveItem.shopping" @close="closeShop" @open="openShop" round='20rpx'
  207. bgColor='f3f5f9'>
  208. <view class="shoppop">
  209. <view class="shoppop-top">
  210. <u-avatar :src="store.logoUrl" size="36" class="ml16"></u-avatar>
  211. <view class="search-input u-flex-y-center">
  212. <image style="width: 24rpx;margin-right: 16rpx;" src="@/static/images/search.png"
  213. mode="widthFix">
  214. </image>
  215. <input placeholder="请搜索商品" v-model="liveItem.inputInfo"
  216. @input="handleSearchInput" />
  217. </view>
  218. <view class="t-c search-top" style="margin-right: 48rpx;">
  219. <image @click="onStoreCollect(liveItem)" v-if="store.isFavorite"
  220. style="width:40rpx;height: 40rpx;" src="@/static/images/collect_select.png">
  221. </image>
  222. <image v-else @click="onStoreCollect(liveItem)" style="width: 32rpx;height: 32rpx;"
  223. src="@/static/images/collect.png"></image>
  224. <view>收藏</view>
  225. </view>
  226. <view class="t-c search-top" @click="goOrderList(liveItem)">
  227. <image style="width: 40rpx;height: 40rpx;" src="@/static/images/order.png"></image>
  228. <view>订单</view>
  229. </view>
  230. </view>
  231. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  232. <view class="list-item " v-for="(item,index) in products" :key="index">
  233. <view class="goods-img">
  234. <image :src="item.imgUrl" mode="widthFix"></image>
  235. <view class="goods-label">{{index+1}}</view>
  236. </view>
  237. <view class="goods-right">
  238. <view class="goods-title">{{item.productName}}</view>
  239. <view class="goods-people">{{item.sales}} 人已购</view>
  240. <view class="goods-shop">
  241. <text class="nummber"><text
  242. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  243. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  244. <view class="btn-group u-flex-y-center">
  245. <view class="collect-btn">
  246. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  247. style="width: 32rpx;height: 32rpx;"
  248. src="/static/images/collect_select.png">
  249. </image>
  250. <image v-else @click="onGoodsCollect(item)"
  251. style="width: 32rpx;height: 32rpx;"
  252. src="/static/images/collect.png">
  253. </image>
  254. </view>
  255. <view v-if="item.status==1" class="shop-btn"
  256. @click="goShop(item.productId,item.goodsId)">去购买
  257. </view>
  258. <view v-else-if="item.status==0" @click="goShop(item.productId)"
  259. class="shop-btn">
  260. 已下架</view>
  261. </view>
  262. </view>
  263. </view>
  264. </view>
  265. </scroll-view>
  266. </view>
  267. </u-popup>
  268. </view>
  269. </swiper-item>
  270. </swiper>
  271. </view>
  272. </template>
  273. <script>
  274. import Hls from 'hls.js';
  275. import CryptoJS from 'crypto-js'
  276. import {
  277. liveList
  278. } from '@/api/list'
  279. import {
  280. liveRed, // 点击领红包
  281. liveDataLike, // 点赞
  282. collectStore, // 店铺收藏/取消收藏
  283. collectGoods, // 商品收藏/取消收藏
  284. store, // 查询店铺
  285. // follow, // 关注/取消关注
  286. watchUserList, //获取直播间用户(展示在线用户)
  287. liveMsg, //获取最近聊天记录
  288. // 小黄车
  289. liveStore, //店铺展示,
  290. // liveGoodsDetail, //商品详情,
  291. liveOrderUser, //正在购买
  292. getLiveInfo, //获取直播间信息接口
  293. getLiveViewData //直播间点赞、关注、在线人数数据
  294. } from '@/api/live'
  295. import {
  296. liveOrderList, // 订单列表
  297. } from '@/api/order'
  298. import parse from '/uni_modules/uview-plus/libs/config/props/parse';
  299. import {
  300. LiveWS
  301. } from '@/utils/liveWS.js'
  302. import {
  303. getlive,
  304. // gettextlist,
  305. getAnswerlist,
  306. submitAnswer
  307. } from '@/api/home'
  308. var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  309. // var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
  310. // var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
  311. // var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
  312. // var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  313. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  314. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  315. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  316. var pingpangTimes = null;
  317. var initTimes = null;
  318. var isSocketOpen = false;
  319. var socket = null;
  320. export default {
  321. data() {
  322. return {
  323. lastClickTime: 0,
  324. clickDelay: 300, // 300ms内只响应一次点击
  325. connectingLiveId: null, // 记录正在连接的直播间ID
  326. swiperDuration: 0, // 初始化为0,首次加载无动画
  327. videoRetryCounts: {}, // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  328. socketInstances: {}, // 改为对象存储多个socket实例
  329. currentSwiperIndex: 0, // 当前swiper索引
  330. list: [], // 直播间列表
  331. preloading: false, // 预加载状态
  332. liveUserTotal: null,
  333. viewPageSize: 10, // 每页数量
  334. viewPageNum: 1, // 当前页码
  335. viewLoading: false, // 是否正在加载
  336. viewNoMoreData: false, // 是否没有更多数据
  337. scrollHeight: 0,
  338. scrollTimer: null, // 滚动防抖定时器
  339. socketInstance: null, // 统一管理 socket 实例
  340. reconnectCount: 0,
  341. maxReconnectAttempts: 3,
  342. isManualClose: false, // 标记是否手动关闭
  343. showRed: true,
  344. // redInfo: {},
  345. // inputInfo: '',
  346. searchTimer: null,
  347. // storeId: null,
  348. reconnectTimer: null,
  349. isCollect: false,
  350. showPurchasePrompt: false,
  351. purchasePromptTimer: null,
  352. prevOrderCount: 0, // 用于记录上一次的购买人数
  353. videoUrl: null,
  354. showType: 1, //横屏1 竖屏2
  355. boxHeight: 300, //小黄车高度
  356. // isFollow: false,
  357. // liveViewData: {},
  358. liveViewers: [], //观众
  359. likeName: 0,
  360. hlsPlayer: null, // HLS播放器实例,
  361. livingUrl: "",
  362. products: {},
  363. store: {},
  364. orderUser: {}, //正在购买
  365. userType: 0,
  366. timestamp: '',
  367. liveId: null,
  368. // userId: uni.getStorageSync("userInfo.userId"),
  369. isZoom: false, //点赞按钮控制是否放大
  370. userinfo: '', //用户信息
  371. // path: 'http://192.168.10.166/dev-api', //余红奇
  372. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  373. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  374. // path: 'http://192.168.10.170/dev-api', //陈果
  375. // value: '',
  376. talkdisabled: false, //输入框是否禁用
  377. autoplay: false, //视频自动播放
  378. showadd: false,
  379. // talklist: [],
  380. scrollIntoView: '',
  381. videoContext: '',
  382. thistime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
  383. // showWelcomeMessage: false,
  384. isSubmit: false,
  385. messageContent: "",
  386. showziliao: false,
  387. isScreen: true,
  388. // shopping: false, //小黄车弹窗
  389. scrollTop: 0, //弹幕
  390. old: {
  391. scrollTop: 0
  392. },
  393. livedata: {}, //直播间点赞、关注、在线人数数据
  394. };
  395. },
  396. onLoad(options) {
  397. this.initTime();
  398. if (options.liveId) {
  399. this.liveId = options.liveId; // 仅当 liveId 变化时更新
  400. }
  401. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  402. // 初始化直播间列表
  403. this.initLiveList(options);
  404. this.getliveUser(false); // 调用获取在线用户接口
  405. const platform = uni.getWindowInfo().platform;
  406. // 初始化直播间列表
  407. if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
  408. // 确保 API 存在再调用
  409. if (uni.showShareMenu) {
  410. uni.showShareMenu({
  411. withShareTicket: true, // 可选参数,根据需求配置
  412. success: () => {
  413. console.log('分享菜单显示成功');
  414. },
  415. fail: (err) => {
  416. console.error('分享菜单显示失败:', err);
  417. }
  418. });
  419. } else {
  420. console.warn('当前平台不支持 uni.showShareMenu');
  421. }
  422. } else {
  423. // console.log('当前平台无需显示分享菜单');
  424. }
  425. },
  426. onReady() {},
  427. onShareAppMessage() {
  428. return {
  429. // title: this.product.title,
  430. title: this.livedata.liveName,
  431. path: '/pages/home/living',
  432. imageUrl: this.products.image,
  433. success(res) {
  434. console.log("分享成功", res);
  435. },
  436. fail(err) {
  437. console.error("分享失败", err);
  438. }
  439. };
  440. },
  441. computed: {
  442. filteredViewers() {
  443. if (!this.liveViewers) {
  444. return
  445. } else {
  446. return this.liveViewers.slice(0, 3);
  447. }
  448. }
  449. },
  450. onHide() {
  451. const currentLive = this.list[this.currentSwiperIndex];
  452. if (currentLive) {
  453. this.pauseVideo(currentLive);
  454. } // 隐藏时关闭所有连接
  455. this.closeAllWebSockets();
  456. },
  457. onUnload() {
  458. // 关闭所有WebSocket连接
  459. this.closeAllWebSockets();
  460. this.socketInstances = {}; // 强制清空实例对象
  461. // 移除所有全局事件监听
  462. this.removeAllEventListeners();
  463. // 清理定时器
  464. this.clearAllTimers();
  465. // 销毁HLS播放器(如果使用了hls.js)
  466. if (this.hlsPlayer) {
  467. this.hlsPlayer.destroy();
  468. this.hlsPlayer = null;
  469. }
  470. this.list.forEach(liveItem => {
  471. const videoId = `myVideo_${liveItem.liveId}`;
  472. const videoContext = uni.createVideoContext(videoId, this);
  473. if (videoContext) {
  474. videoContext.pause(); // 仅暂停视频即可
  475. }
  476. });
  477. },
  478. watch: {
  479. // 监听orderUser.count的变化
  480. 'orderUser.count': {
  481. handler(newVal, oldVal) {
  482. if (newVal !== this.prevOrderCount) {
  483. this.prevOrderCount = newVal;
  484. this.showPurchaseMessage();
  485. }
  486. },
  487. immediate: true
  488. }
  489. },
  490. methods: {
  491. toggleViewerList() {
  492. const now = Date.now()
  493. if (now - this.lastClickTime > this.clickDelay) {
  494. this.showadd = !this.showadd
  495. this.lastClickTime = now
  496. }
  497. },
  498. // 重置在线用户列表的分页参数
  499. resetUserListParams() {
  500. this.viewPageNum = 1; // 重置页码为第一页
  501. this.viewNoMoreData = false; // 重置“没有更多数据”状态
  502. this.liveViewers = []; // 清空现有列表
  503. },
  504. closeAllWebSockets() {
  505. this.isManualClose = true;
  506. // 关闭所有连接
  507. Object.keys(this.socketInstances).forEach(liveId => {
  508. try {
  509. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  510. this.socketInstances[liveId].instance.close({
  511. code: 1000,
  512. reason: '页面关闭'
  513. });
  514. console.log(`直播间 ${liveId} WebSocket 已关闭`);
  515. }
  516. } catch (e) {
  517. console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
  518. }
  519. });
  520. this.socketInstances = {};
  521. isSocketOpen = false;
  522. }, // 移除所有全局事件监听器
  523. removeAllEventListeners() {
  524. uni.$off('initSocket');
  525. uni.$off('sendMsg');
  526. uni.$off('closeWebSocket');
  527. uni.$off('refreshOrder');
  528. // 可以根据实际情况添加其他需要移除的事件
  529. }, // 清理所有定时器
  530. clearAllTimers() {
  531. if (this.intervalId) {
  532. clearInterval(this.intervalId);
  533. this.intervalId = null;
  534. }
  535. if (this.pingpangTimes) {
  536. clearInterval(this.pingpangTimes);
  537. this.pingpangTimes = null;
  538. }
  539. if (this.reconnectTimer) {
  540. clearInterval(this.reconnectTimer);
  541. this.reconnectTimer = null;
  542. }
  543. if (this.scrollTimer) {
  544. clearTimeout(this.scrollTimer);
  545. this.scrollTimer = null;
  546. }
  547. if (this.searchTimer) {
  548. clearTimeout(this.searchTimer);
  549. this.searchTimer = null;
  550. }
  551. if (this.purchasePromptTimer) {
  552. clearTimeout(this.purchasePromptTimer);
  553. this.purchasePromptTimer = null;
  554. }
  555. },
  556. // 初始化当前直播间数据
  557. async initCurrentLiveData() {
  558. const currentLive = this.list[this.currentSwiperIndex];
  559. if (!currentLive) return;
  560. // 设置加载状态
  561. currentLive.loading = true;
  562. try {
  563. // 先初始化WebSocket连接
  564. await this.initSocket(currentLive);
  565. // 然后并行加载其他数据
  566. await Promise.allSettled([
  567. this.getLiveMsg(currentLive),
  568. this.getliveViewData(currentLive),
  569. this.getliving(currentLive)
  570. ]);
  571. currentLive.loaded = true;
  572. } catch (error) {
  573. console.error("初始化直播间数据失败:", error);
  574. } finally {
  575. currentLive.loading = false;
  576. }
  577. },
  578. // 初始化直播间列表
  579. async initLiveList(options) {
  580. try {
  581. await this.getList(); // 先加载直播间列表
  582. if (this.list.length === 0) {
  583. console.error("直播间列表为空,无法初始化");
  584. return;
  585. }
  586. // 设置初始直播间索引(原逻辑保留)
  587. if (options.liveId) {
  588. const index = this.list.findIndex(item => item.liveId == options.liveId);
  589. this.currentSwiperIndex = index !== -1 ? index : 0;
  590. } else {
  591. this.currentSwiperIndex = 0;
  592. }
  593. // 延迟设置动画时间(原逻辑保留)
  594. setTimeout(() => {
  595. this.swiperDuration = 300;
  596. }, 100);
  597. // 获取当前直播间的liveItem
  598. const currentLive = this.list[this.currentSwiperIndex];
  599. if (currentLive) {
  600. this.liveId = currentLive.liveId;
  601. // 重置用户列表参数
  602. this.resetUserListParams();
  603. // 预加载相邻直播间(不初始化WebSocket)
  604. this.preloadNearbyLives(false);
  605. // 初始化当前直播间数据(包含WebSocket连接)
  606. await this.initCurrentLiveData();
  607. // 获取在线用户
  608. this.getliveUser(false);
  609. // 延迟播放视频
  610. setTimeout(() => {
  611. this.playVideo(currentLive);
  612. }, 500);
  613. }
  614. } catch (error) {
  615. console.error("初始化失败:", error);
  616. }
  617. },
  618. // Swiper切换事件
  619. async onSwiperChange(e) {
  620. const newIndex = e.detail.current;
  621. const oldIndex = this.currentSwiperIndex;
  622. if (newIndex === oldIndex) return;
  623. // 1. 立即关闭旧直播间的WebSocket(同步操作)
  624. const oldLive = this.list[oldIndex];
  625. if (oldLive) {
  626. this.pauseVideo(oldLive);
  627. // 强制关闭并删除实例,确保连接被释放
  628. if (this.socketInstances[oldLive.liveId]) {
  629. try {
  630. this.socketInstances[oldLive.liveId].instance.close({
  631. code: 1000,
  632. reason: '切换直播间'
  633. });
  634. console.log(`关闭旧直播间 ${oldLive.liveId} WebSocket`);
  635. } catch (e) {
  636. console.error('关闭旧连接失败:', e);
  637. }
  638. delete this.socketInstances[oldLive.liveId]; // 彻底删除实例
  639. }
  640. }
  641. // 2. 处理新直播间(后续逻辑不变)
  642. this.currentSwiperIndex = newIndex;
  643. const newLive = this.list[newIndex];
  644. if (!newLive) return;
  645. this.liveId = newLive.liveId;
  646. this.resetUserListParams();
  647. await this.initCurrentLiveData();
  648. this.getliveUser(false);
  649. setTimeout(() => {
  650. this.playVideo(newLive);
  651. }, 100);
  652. },
  653. // 获取直播间列表
  654. async getList() {
  655. const data = {
  656. page: 1,
  657. page_size: 20
  658. };
  659. try {
  660. const res = await liveList(data);
  661. if (res.code === 200) {
  662. this.list = res.rows.map(item => ({
  663. ...item,
  664. talklist: [],
  665. loading: false,
  666. loaded: false,
  667. shopping: false,
  668. inputInfo: '',
  669. showWelcomeMessage: false,
  670. redInfo: {}
  671. // 其他初始化字段...
  672. }));
  673. console.log("直播间列表加载成功,数量:", this.list.length); // 确认数量是否 > 0
  674. } else {
  675. uni.showToast({
  676. title: res.msg,
  677. icon: "none"
  678. });
  679. this.list = []; // 接口失败时清空列表,避免后续错误
  680. }
  681. } catch (error) {
  682. console.error("获取直播间列表失败:", error);
  683. this.list = []; // 异常时清空列表
  684. }
  685. },
  686. // 播放视频
  687. playVideo(liveItem) {
  688. if (!liveItem) return;
  689. try {
  690. const videoId = `myVideo_${liveItem.liveId}`;
  691. const videoContext = uni.createVideoContext(videoId, this);
  692. if (videoContext) {
  693. videoContext.pause(() => {
  694. // 暂停完成后再播放
  695. videoContext.play();
  696. });
  697. }
  698. } catch (error) {
  699. console.error("播放视频失败:", error);
  700. }
  701. },
  702. pauseVideo(liveItem) {
  703. if (!liveItem) return;
  704. try {
  705. const videoId = `myVideo_${liveItem.liveId}`;
  706. const videoContext = uni.createVideoContext(videoId, this);
  707. if (videoContext) {
  708. videoContext.pause();
  709. }
  710. } catch (error) {
  711. console.error("暂停视频失败:", error);
  712. }
  713. },
  714. // 预加载相邻直播间
  715. async preloadNearbyLives(includeWebSocket = false) {
  716. this.preloading = true;
  717. const currentIndex = this.currentSwiperIndex;
  718. const preloadIndexes = [];
  719. // 只预加载数据,不初始化WebSocket(强制关闭WebSocket预加载)
  720. includeWebSocket = false; // 关键:强制不预加载WebSocket
  721. if (currentIndex > 0) preloadIndexes.push(currentIndex - 1);
  722. if (currentIndex < this.list.length - 1) preloadIndexes.push(currentIndex + 1);
  723. for (const index of preloadIndexes) {
  724. const liveItem = this.list[index];
  725. if (!liveItem || liveItem.loaded || liveItem.loading) continue;
  726. liveItem.loading = true;
  727. try {
  728. // 只加载基础数据,不初始化WebSocket
  729. await Promise.all([
  730. this.getliving(liveItem),
  731. this.getLiveMsg(liveItem),
  732. this.getliveViewData(liveItem)
  733. ]);
  734. liveItem.loaded = true;
  735. } catch (error) {
  736. console.error(`预加载直播间 ${index} 失败:`, error);
  737. liveItem.loaded = false;
  738. } finally {
  739. liveItem.loading = false;
  740. }
  741. }
  742. this.preloading = false;
  743. },
  744. openViews() {
  745. // 计算scroll-view高度
  746. this.$nextTick(() => {
  747. const query = uni.createSelectorQuery().in(this);
  748. query.select('.view-box').boundingClientRect(data => {
  749. if (data) {
  750. // 减去标题和底部固定区域的高度
  751. this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
  752. }
  753. }).exec();
  754. });
  755. },
  756. // 重置直播间数据
  757. resetLiveData() {
  758. // 保留不需要重置的数据(如用户信息等)
  759. const keepData = {
  760. userinfo: this.userinfo,
  761. list: this.list,
  762. currentSwiperIndex: this.currentSwiperIndex
  763. };
  764. // 重置其他直播间特定数据
  765. this.liveUserTotal = null;
  766. // this.liveViewData = {};
  767. this.liveViewers = [];
  768. this.livingUrl = "";
  769. this.videoUrl = null;
  770. this.products = {};
  771. this.store = {};
  772. this.orderUser = {};
  773. this.talklist = [];
  774. this.livedata = {};
  775. // this.isFollow = false;
  776. this.shopping = false;
  777. this.inputInfo = ''
  778. // 恢复需要保留的数据
  779. Object.assign(this, keepData);
  780. },
  781. // 获取直播间用户
  782. async getliveUser(isLoadMore = false) {
  783. // 强制使用当前 liveId,避免使用旧值
  784. const currentLiveId = this.liveId;
  785. if (!currentLiveId) return;
  786. // if (this.viewLoading || this.viewNoMoreData) return;
  787. this.viewLoading = true;
  788. try {
  789. const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
  790. if (res.code === 200) {
  791. // 若请求期间已切换直播间,忽略旧数据
  792. if (this.liveId !== currentLiveId) return;
  793. this.liveUserTotal = res.total;
  794. if (res.rows.length === 0) {
  795. this.viewNoMoreData = true;
  796. return;
  797. }
  798. this.liveViewers = isLoadMore ? [...this.liveViewers, ...res.rows] :res.rows; // 首次加载/切换直播间时重置数据
  799. this.viewPageNum++;
  800. // console.log("在线观众", this.liveViewers)
  801. }
  802. } catch (error) {
  803. console.error('获取观众列表失败:', error);
  804. } finally {
  805. this.viewLoading = false;
  806. }
  807. },
  808. // 滚动到底部触发
  809. handleScrollToLower() {
  810. // 清除上一次未执行的定时器,避免重复请求
  811. if (this.scrollTimer) {
  812. clearTimeout(this.scrollTimer);
  813. }
  814. // 延迟0.5秒(500毫秒)执行接口请求
  815. this.scrollTimer = setTimeout(() => {
  816. this.getliveUser(true); // 加载更多数据
  817. }, 1000); // 延迟时间:500毫秒
  818. },
  819. async getLiveMsg(liveItem) {
  820. // 强化校验:确保 liveItem 存在且包含 liveId
  821. if (!liveItem || !liveItem.liveId) {
  822. console.error('getLiveMsg 错误:无效的 liveItem', {
  823. liveItem: liveItem,
  824. currentIndex: this.currentSwiperIndex,
  825. listLength: this.list.length
  826. });
  827. return; // 直接返回,不执行后续逻辑
  828. }
  829. try {
  830. const res = await liveMsg(liveItem.liveId, 30, 1);
  831. if (res.code == 200) {
  832. // 确保使用响应式更新
  833. this.$set(liveItem, 'talklist', [...res.rows]);
  834. this.$nextTick(() => {
  835. this.$set(liveItem, 'scrollIntoView', `list_${liveItem.talklist.length-1}`);
  836. });
  837. }
  838. } catch (error) {
  839. console.error("获取聊天记录失败:", error);
  840. }
  841. },
  842. // 点击红包
  843. onRed(item) {
  844. // console.log("点了this.liveId", item)
  845. if (!item.liveId) return;
  846. // console.log("点了this.liveId", this.liveId)
  847. if (!item.redInfo?.redId) return;
  848. // console.log("点了this.redInfo?.redId", this.redInfo.redId)
  849. // console.log("点了this.userinfo.userId", this.userinfo.userId)
  850. let data = {
  851. liveId: item.liveId,
  852. userId: this.userinfo.userId,
  853. redId: item.redInfo.redId,
  854. }
  855. console.log("点了this.liveId", data)
  856. liveRed(data).then(res => {
  857. if (res.code == 200) {
  858. uni.showToast({
  859. title: res.msg,
  860. icon: 'none'
  861. });
  862. } else {
  863. uni.showToast({
  864. title: res.msg,
  865. icon: 'none'
  866. });
  867. }
  868. },
  869. rej => {}
  870. );
  871. },
  872. handleSearchInput() {
  873. // 使用防抖优化性能,避免频繁请求
  874. clearTimeout(this.searchTimer);
  875. this.searchTimer = setTimeout(() => {
  876. this.queryCollect();
  877. }, 500); // 500毫秒延迟
  878. },
  879. // 显示购买提示信息
  880. showPurchaseMessage() {
  881. // 清除之前的定时器
  882. if (this.purchasePromptTimer) {
  883. clearTimeout(this.purchasePromptTimer);
  884. }
  885. // 显示提示
  886. this.showPurchasePrompt = true;
  887. // 2秒后自动隐藏
  888. this.purchasePromptTimer = setTimeout(() => {
  889. this.showPurchasePrompt = false;
  890. }, 2000);
  891. },
  892. truncateString(str, maxLength) {
  893. return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;
  894. },
  895. goStore(item) {
  896. console.log("带过去storeId", item)
  897. if (!item.storeId) {
  898. uni.showToast({
  899. title: "当前直播间暂未开通店铺",
  900. icon: 'none'
  901. });
  902. return;
  903. }
  904. uni.navigateTo({
  905. url: '/pages_shop/store?liveId=' + item.liveId + "&storeId=" + item.storeId
  906. })
  907. },
  908. // 去订单列表
  909. goOrderList() {
  910. uni.navigateTo({
  911. url: "/pages_shop/order"
  912. })
  913. },
  914. // 初始化HLS播放器
  915. initHlsPlayer() {
  916. if (Hls.isSupported() && this.livingUrl) {
  917. const video = document.getElementById('myVideo');
  918. if (video) {
  919. this.hlsPlayer = new Hls();
  920. this.hlsPlayer.loadSource(this.livingUrl);
  921. this.hlsPlayer.attachMedia(video);
  922. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  923. video.play();
  924. });
  925. }
  926. }
  927. },
  928. // 视频错误处理
  929. videoError(e, liveItem) {
  930. // 检查是否是当前直播间,避免处理非活跃直播间的错误
  931. if (!liveItem || liveItem.liveId !== this.liveId) return;
  932. // 限制重试次数
  933. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  934. console.error(`直播间 ${liveItem.liveId} 视频加载失败`);
  935. return;
  936. }
  937. this.videoRetryCounts[liveItem.liveId]++;
  938. // 延迟重试,避免与切换操作冲突
  939. setTimeout(() => {
  940. if (liveItem.liveId === this.liveId) {
  941. this.playVideo(liveItem);
  942. }
  943. }, 2000);
  944. },
  945. // 修改获取直播信息方法
  946. async getliving(liveItem) {
  947. if (!liveItem || !liveItem.liveId) return;
  948. // console.log("获取直播信息:", liveItem.liveId);
  949. const param = {
  950. id: liveItem.liveId
  951. };
  952. try {
  953. const res = await getlive({
  954. id: liveItem.liveId
  955. });
  956. if (res.code !== 200) {
  957. uni.showToast({
  958. title: res.msg,
  959. icon: 'none'
  960. });
  961. return;
  962. }
  963. // 强制更新视频源(覆盖旧值)
  964. if (res.data.liveType === 2) {
  965. // 回放视频
  966. this.$set(liveItem, 'videoUrl', res.data.videoUrl);
  967. this.$set(liveItem, 'livingUrl', ''); // 清空直播流
  968. this.$set(liveItem, 'placeholderText', "说点什么...");
  969. } else if (res.data.liveType === 1) {
  970. // 直播流
  971. this.$set(liveItem, 'livingUrl', res.data.flvHlsUrl);
  972. this.$set(liveItem, 'videoUrl', ''); // 清空回放视频
  973. this.$set(liveItem, 'placeholderText', "说点什么...");
  974. } else {
  975. // 未开播
  976. this.$set(liveItem, 'livingUrl', '');
  977. this.$set(liveItem, 'videoUrl', '');
  978. }
  979. // 更新其他直播信息
  980. // 仅当是当前激活的直播间时,才允许自动播放
  981. const isCurrentLive = this.currentSwiperIndex === this.list.findIndex(item => item.liveId ===
  982. liveItem.liveId);
  983. this.$set(liveItem, 'autoplay', isCurrentLive && res.data.liveType !== 0);
  984. this.$set(liveItem, 'showType', res.data.showType);
  985. this.$set(liveItem, 'storeId', res.storeId);
  986. this.queryCollect();
  987. } catch (err) {
  988. console.error("获取直播信息失败:", err);
  989. uni.showToast({
  990. title: "获取直播信息失败",
  991. icon: 'none'
  992. });
  993. }
  994. }, // 设置视频播放
  995. setupVideoPlayback(liveItem, liveData) {
  996. if (!liveItem.livingUrl) return;
  997. // H5 平台:使用 HLS.js 处理 .m3u8 流
  998. // #ifdef H5
  999. if (liveItem.livingUrl.includes('.m3u8')) {
  1000. this.initHlsPlayer(liveItem);
  1001. return;
  1002. }
  1003. // #endif
  1004. // 小程序/App 平台:直接使用 video 组件
  1005. const videoId = `myVideo_${liveItem.liveId}`;
  1006. const videoContext = uni.createVideoContext(videoId, this);
  1007. if (liveData.liveType === 1) {
  1008. // 回放:跳转到指定位置
  1009. videoContext.seek(liveData.nowDuration || 0);
  1010. } else {
  1011. // 直播:直接播放
  1012. videoContext.play();
  1013. }
  1014. },
  1015. maskString(str, maskChar = '*') {
  1016. // 如果str是undefined或null,直接返回空字符串
  1017. if (!str) return '';
  1018. // 确保str是字符串(如果是数字等类型,先转为字符串)
  1019. const strVal = String(str);
  1020. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  1021. },
  1022. getPureDecimal(num, precision = 6) {
  1023. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  1024. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  1025. },
  1026. // 返回上一个页面并关闭WebSocket
  1027. goBack() {
  1028. // 暂停当前视频
  1029. const currentLive = this.list[this.currentSwiperIndex];
  1030. if (currentLive) {
  1031. this.pauseVideo(currentLive);
  1032. }
  1033. // 关闭所有WebSocket连接
  1034. this.closeWebSocket();
  1035. // 导航返回
  1036. const pages = getCurrentPages();
  1037. if (pages.length > 1) {
  1038. uni.navigateBack();
  1039. } else {
  1040. uni.reLaunch({
  1041. url: '/pages/list/index'
  1042. });
  1043. }
  1044. },
  1045. //正在购买
  1046. async getliveOrder() {
  1047. const currentLiveId = this.liveId;
  1048. if (!currentLiveId) return;
  1049. try {
  1050. const res = await liveOrderUser(currentLiveId);
  1051. if (res.code === 200) {
  1052. // 绑定到当前 liveItem
  1053. const currentLive = this.list[this.currentSwiperIndex];
  1054. if (currentLive) {
  1055. this.$set(currentLive, 'orderUser', res);
  1056. this.orderUser = res; // 同步全局变量
  1057. }
  1058. }
  1059. } catch (error) {
  1060. console.error('获取正在购买用户失败:', error);
  1061. }
  1062. },
  1063. // 获取直播间信息接口
  1064. getLiveinformation() {
  1065. if (!this.liveId) return;
  1066. getLiveInfo(this.liveId).then(res => {
  1067. if (res.code == 200) {
  1068. console.log("获取直播间信息接口>>>>", res)
  1069. this.livingUrl = res.livingUrl
  1070. } else {
  1071. uni.showToast({
  1072. title: res.msg,
  1073. icon: 'none'
  1074. });
  1075. }
  1076. },
  1077. rej => {}
  1078. );
  1079. },
  1080. // 点赞
  1081. async onLike(liveItem) {
  1082. // 基础校验
  1083. if (!liveItem || !liveItem.liveId) return;
  1084. // 确保liveViewData存在(初始化默认值)
  1085. if (!liveItem.liveViewData) {
  1086. await this.getliveViewData(liveItem);
  1087. if (!liveItem.liveViewData) {
  1088. uni.showToast({
  1089. title: "数据加载中,请稍后再试",
  1090. icon: 'none'
  1091. });
  1092. return;
  1093. }
  1094. // 初始化点赞数(防止undefined)
  1095. liveItem.liveViewData.like = liveItem.liveViewData.like || 0;
  1096. }
  1097. // 限制最多10次点赞
  1098. const maxLikeCount = 10;
  1099. if (liveItem.liveViewData.like >= maxLikeCount) {
  1100. uni.showToast({
  1101. title: "最多可点赞10次哦~",
  1102. icon: 'none'
  1103. });
  1104. return;
  1105. }
  1106. try {
  1107. const res = await liveDataLike(liveItem.liveId);
  1108. if (res.code === 200) {
  1109. // 无论后端是否返回res.like,前端按规则累加(最多到10次)
  1110. const newLikeCount = Math.min(liveItem.liveViewData.like + 1, maxLikeCount);
  1111. liveItem.liveViewData.like = newLikeCount;
  1112. } else {
  1113. uni.showToast({
  1114. title: res.msg || "点赞失败",
  1115. icon: 'none'
  1116. });
  1117. }
  1118. } catch (error) {
  1119. console.error('点赞失败:', error);
  1120. uni.showToast({
  1121. title: "网络异常,点赞失败",
  1122. icon: 'none'
  1123. });
  1124. }
  1125. },
  1126. //直播间点赞、关注、在线人数数据
  1127. async getliveViewData(liveItem) {
  1128. if (!liveItem || !liveItem.liveId) return;
  1129. try {
  1130. const res = await getLiveViewData(liveItem.liveId);
  1131. if (res.code == 200) {
  1132. // 强制响应式更新,确保数据实时显示
  1133. this.$set(liveItem, 'liveViewData', res);
  1134. }
  1135. } catch (error) {
  1136. console.error("获取直播间数据失败:", error);
  1137. // 失败时兜底,避免显示异常
  1138. this.$set(liveItem, 'liveViewData', {
  1139. like: 0,
  1140. watchCount: 0
  1141. });
  1142. }
  1143. },
  1144. // 去购买,跳商品详情
  1145. goShop(productId, goodsId) {
  1146. const currentLive = this.list[this.currentSwiperIndex];
  1147. if (!currentLive || !currentLive.liveId) return;
  1148. // console.log("拿现在的item", currentLive)
  1149. uni.navigateTo({
  1150. url: '/pages_shop/goods?productId=' + productId + '&liveId=' + currentLive.liveId +
  1151. '&goodsId=' +
  1152. goodsId + '&storeId=' + currentLive.storeId
  1153. })
  1154. },
  1155. // 查询店铺
  1156. async queryCollect() {
  1157. const currentLive = this.list[this.currentSwiperIndex];
  1158. if (!currentLive || !currentLive.liveId) return;
  1159. const {
  1160. storeId
  1161. } = currentLive;
  1162. // console.log("小黄车数据>>>", currentLive)
  1163. if (!storeId) return;
  1164. try {
  1165. const res = await store(currentLive.storeId, currentLive.inputInfo, currentLive.liveId);
  1166. if (res.code === 200) {
  1167. // 数据绑定到当前 liveItem,避免全局污染
  1168. this.$set(currentLive, 'products', res.data.goodsList);
  1169. this.$set(currentLive, 'store', res.data);
  1170. // 同步更新全局变量(供弹窗使用)
  1171. this.products = res.data.goodsList;
  1172. this.store = res.data;
  1173. }
  1174. } catch (error) {
  1175. console.error('获取小黄车商品失败:', error);
  1176. }
  1177. },
  1178. // 店铺收藏
  1179. onStoreCollect(liveItem) {
  1180. console.log("店铺收藏", liveItem)
  1181. if (!liveItem.storeId) return;
  1182. collectStore(liveItem.storeId).then(res => {
  1183. if (res.code == 200) {
  1184. uni.showToast({
  1185. title: res.msg,
  1186. icon: 'none'
  1187. });
  1188. liveItem.store.isFavorite = !liveItem.store.isFavorite
  1189. } else {
  1190. uni.showToast({
  1191. title: res.msg,
  1192. icon: 'none'
  1193. });
  1194. }
  1195. },
  1196. rej => {}
  1197. );
  1198. },
  1199. // 商品收藏
  1200. onGoodsCollect(item) {
  1201. console.log("商品收藏", item)
  1202. if (!item || item.length === 0 || !item.goodsId) {
  1203. return;
  1204. }
  1205. collectGoods(item.goodsId).then(res => {
  1206. if (res.code == 200) {
  1207. uni.showToast({
  1208. title: res.msg,
  1209. icon: 'none'
  1210. });
  1211. item.isFavorite = !item.isFavorite
  1212. } else {
  1213. uni.showToast({
  1214. title: res.msg,
  1215. icon: 'none'
  1216. });
  1217. }
  1218. },
  1219. rej => {}
  1220. );
  1221. },
  1222. // 关注
  1223. // async onFollow(liveItem) {
  1224. // if (!liveItem || !liveItem.liveId) return;
  1225. // try {
  1226. // const res = await follow(liveItem.liveId);
  1227. // liveItem.isFollow = !liveItem.isFollow;
  1228. // uni.showToast({
  1229. // title: res.msg,
  1230. // icon: 'none'
  1231. // });
  1232. // } catch (error) {
  1233. // console.error("关注操作失败:", error);
  1234. // }
  1235. // },
  1236. // 时间戳
  1237. initTime() {
  1238. const now = new Date();
  1239. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  1240. },
  1241. openShop() {
  1242. },
  1243. openViews() {
  1244. this.$nextTick(() => {
  1245. const query = uni.createSelectorQuery().in(this);
  1246. query.select('.view-box').boundingClientRect(data => {
  1247. if (data) {
  1248. this.scrollHeight = data.height - 80 - 120;
  1249. }
  1250. }).exec();
  1251. });
  1252. },
  1253. // openCart(liveItem) {
  1254. // if (!liveItem.storeId) {
  1255. // uni.showToast({
  1256. // title: "当前直播间暂未开通店铺",
  1257. // icon: 'none'
  1258. // });
  1259. // return;
  1260. // }
  1261. // liveItem.shopping = !liveItem.shopping
  1262. // },
  1263. close() {
  1264. this.showadd = false
  1265. },
  1266. closes() {
  1267. this.showziliao = !this.showziliao
  1268. },
  1269. // 关闭小黄车
  1270. closeShop() {
  1271. // 通过当前swiper索引获取当前直播间实例
  1272. const currentLive = this.list[this.currentSwiperIndex];
  1273. if (currentLive) {
  1274. this.$set(currentLive, 'shopping', !currentLive.shopping);
  1275. }
  1276. },
  1277. // 关闭红包
  1278. closeRed() {
  1279. this.showRed = !this.showRed
  1280. },
  1281. // 触摸结束
  1282. handleTouchEnd() {
  1283. this.isZoom = false; // 恢复原状
  1284. },
  1285. getEWechatSdk() {
  1286. // 只在H5平台执行
  1287. // #ifdef H5
  1288. let eWechatSdk = '';
  1289. if (/(Android)/i.test(navigator.userAgent)) {
  1290. eWechatSdk = 'jWeixin';
  1291. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  1292. eWechatSdk = 'wx';
  1293. } else {
  1294. eWechatSdk = 'jWeixin';
  1295. }
  1296. uni.setStorageSync("wxSdk", eWechatSdk);
  1297. // #endif
  1298. },
  1299. // 修改关闭WebSocket方法
  1300. closeWebSocket(liveId = null) {
  1301. this.isManualClose = true;
  1302. // 清除所有定时器
  1303. clearInterval(this.pingpangTimes);
  1304. clearInterval(this.reconnectTimer);
  1305. // 关闭指定或所有WebSocket连接
  1306. if (liveId) {
  1307. // 关闭指定直播间的连接
  1308. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  1309. try {
  1310. this.socketInstances[liveId].instance.close(); // socketTask.close()
  1311. console.log(`直播间 ${liveId} WebSocket 已安全关闭`);
  1312. } catch (e) {
  1313. console.error('关闭失败', e);
  1314. }
  1315. delete this.socketInstances[liveId];
  1316. }
  1317. } else {
  1318. // 关闭所有连接
  1319. Object.keys(this.socketInstances).forEach(liveId => {
  1320. try {
  1321. uni.closeSocket({
  1322. instance: this.socketInstances[liveId]
  1323. });
  1324. console.log(`直播间 ${liveId} WebSocket 已安全关闭`);
  1325. } catch (e) {
  1326. console.error('关闭 WebSocket 时出错:', e);
  1327. }
  1328. });
  1329. this.socketInstances = {};
  1330. }
  1331. isSocketOpen = false;
  1332. },
  1333. reConnect() {
  1334. var that = this;
  1335. try {
  1336. uni.closeSocket();
  1337. } catch (e) {
  1338. }
  1339. setTimeout(function() {
  1340. that.initSocket();
  1341. }, 10000);
  1342. },
  1343. startHeartbeat(liveId) {
  1344. clearInterval(this.pingpangTimes);
  1345. this.pingpangTimes = setInterval(() => {
  1346. const inst = this.socketInstances[liveId];
  1347. if (!inst || !inst.isOpen || !inst.instance) return;
  1348. const pingData = {
  1349. cmd: 'ping',
  1350. timestamp: Date.now()
  1351. };
  1352. try {
  1353. inst.instance.send({
  1354. data: JSON.stringify(pingData)
  1355. });
  1356. } catch (err) {
  1357. console.error('心跳发送失败:', err);
  1358. this.scheduleReconnect(liveId);
  1359. }
  1360. }, 30000);
  1361. },
  1362. async initSocket(liveItem) {
  1363. const currentLive = this.list[this.currentSwiperIndex];
  1364. if (!currentLive || currentLive.liveId !== liveItem.liveId) {
  1365. console.log(`拒绝为非活跃直播间 ${liveItem.liveId} 建立WebSocket`);
  1366. return;
  1367. }
  1368. if (!liveItem || !liveItem.liveId) return;
  1369. const liveId = liveItem.liveId;
  1370. // 检查是否已经是当前连接或正在连接
  1371. if (this.connectingLiveId === liveId ||
  1372. (this.socketInstances[liveId] && this.socketInstances[liveId].isOpen)) {
  1373. console.log(`直播间 ${liveId} 的WebSocket已经连接或正在连接,跳过初始化`);
  1374. return;
  1375. }
  1376. // 检查是否是当前活跃的直播间
  1377. if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
  1378. console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
  1379. return;
  1380. }
  1381. // 关闭之前的连接(如果存在)
  1382. if (this.socketInstances[liveId]) {
  1383. this.closeWebSocket(liveId);
  1384. }
  1385. // 设置正在连接的直播间ID
  1386. this.connectingLiveId = liveId;
  1387. // 防止重复创建
  1388. if (this.reconnectCount >= this.maxReconnectAttempts) {
  1389. this.connectingLiveId = null;
  1390. return;
  1391. }
  1392. this.isManualClose = false;
  1393. // 生成签名
  1394. const signature = CryptoJS.HmacSHA256(
  1395. `${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
  1396. this.timestamp.toString()
  1397. ).toString(CryptoJS.enc.Hex);
  1398. // 初始化实例状态
  1399. this.socketInstances[liveId] = {
  1400. instance: null,
  1401. isOpen: false
  1402. };
  1403. try {
  1404. const socketTask = uni.connectSocket({
  1405. url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
  1406. success: () => {
  1407. console.log('WebSocket API 调用成功,正在建立连接...');
  1408. },
  1409. fail: (err) => {
  1410. console.error('WebSocket 连接失败:', err);
  1411. this.connectingLiveId = null;
  1412. this.scheduleReconnect(liveId);
  1413. }
  1414. });
  1415. socketTask.onOpen((res) => {
  1416. console.log('WebSocket 连接已成功建立', res);
  1417. this.socketInstances[liveId].instance = socketTask;
  1418. this.socketInstances[liveId].isOpen = true;
  1419. isSocketOpen = true;
  1420. this.connectingLiveId = null;
  1421. this.reconnectCount = 0;
  1422. // 改用 socketTask 的 send 作为心跳
  1423. this.startHeartbeat(liveId); // 修改 startHeartbeat 以接受 liveId 并使用 socketTask.send
  1424. });
  1425. socketTask.onMessage((res) => {
  1426. // 找到对应的直播间并更新数据
  1427. const targetLive = this.list.find(item => item.liveId === liveId);
  1428. if (targetLive) {
  1429. this.handleSocketMessage(res, targetLive);
  1430. }
  1431. });
  1432. socketTask.onError((err) => {
  1433. console.error('WebSocket 连接错误:', err);
  1434. this.connectingLiveId = null;
  1435. this.scheduleReconnect(liveId);
  1436. });
  1437. socketTask.onClose(() => {
  1438. console.log(`WebSocket 连接已关闭: ${liveId}`);
  1439. this.connectingLiveId = null;
  1440. });
  1441. } catch (e) {
  1442. console.error('创建 WebSocket 异常:', e);
  1443. this.connectingLiveId = null;
  1444. this.scheduleReconnect(liveId);
  1445. }
  1446. },
  1447. // 处理Socket消息
  1448. handleSocketMessage(message, liveItem) {
  1449. let data = JSON.parse(message.data)
  1450. const socketMessage = data.data
  1451. // console.log("处理",data)
  1452. if (data.code == 200) {
  1453. const messageData = {
  1454. ...socketMessage, // 原数据(可能包含部分字段)
  1455. cmd: socketMessage.cmd || '' // 强制添加cmd,确保存在(默认空字符串)
  1456. };
  1457. // console.log("messageData是",messageData)
  1458. if (socketMessage.cmd == 'sendMsg') {
  1459. // this.$set(liveItem, 'talklist', [...liveItem.talklist, messageData]);
  1460. this.$nextTick(() => {
  1461. this.$set(liveItem, 'scrollIntoView', `list_${liveItem.talklist.length-1}`);
  1462. });
  1463. } else if (socketMessage.cmd == 'red') {
  1464. // 领红包
  1465. this.$set(liveItem, 'redInfo', JSON.parse(socketMessage.data));
  1466. console.log("红包是liveItem.redInfo", liveItem)
  1467. // liveItem.redInfo = JSON.parse(message.data.data);
  1468. } else if (socketMessage.cmd == 'sendRedPacketQuestion') {
  1469. const list = JSON.parse(message.data.data);
  1470. // 处理红包答题逻辑
  1471. } else if (socketMessage.cmd == 'entry' || socketMessage.cmd == 'out') {
  1472. this.$set(liveItem, 'talklist', [...liveItem.talklist, messageData]);
  1473. // 先重置为 false(避免残留状态)
  1474. this.$set(liveItem, 'showWelcomeMessage', false);
  1475. // 立即设为 true(触发 DOM 更新)
  1476. this.$set(liveItem, 'showWelcomeMessage', true);
  1477. this.getliveUser(false); // 调用获取在线用户接口
  1478. // console.log("开启欢迎消息:", liveItem.showWelcomeMessage);
  1479. if (liveItem.welcomeTimer) {
  1480. clearTimeout(liveItem.welcomeTimer);
  1481. }
  1482. // 存储定时器到 liveItem 中(避免引用丢失)
  1483. liveItem.welcomeTimer = setTimeout(() => {
  1484. this.$set(liveItem, 'showWelcomeMessage', false);
  1485. // console.log("关闭欢迎消息:", liveItem.showWelcomeMessage);
  1486. }, 1000); // 1秒后隐藏
  1487. } else if (socketMessage.cmd == 'Integral') {
  1488. uni.showToast({
  1489. title: socketMessage.msg,
  1490. icon: 'none',
  1491. duration: 20000
  1492. });
  1493. // 观看奖励事件 弹出框2s 显示msg
  1494. } else if (socketMessage.cmd == 'blockUser') {
  1495. //拉黑事件 主动删除用户token,强制跳转到登录页面
  1496. uni.removeStorage({
  1497. key: 'AppToken', // 存储 Token 时的 key
  1498. success: () => {
  1499. uni.reLaunch({
  1500. url: '/pages/auth/login' // 登录页路径,需根据项目实际路径调整
  1501. });
  1502. console.log('Token 删除成功');
  1503. },
  1504. fail: (err) => {
  1505. console.error('Token 删除失败:', err);
  1506. }
  1507. });
  1508. }
  1509. // else if (socketMessage.data.cmd == 'deleteId') {
  1510. // } else if (socketMessage.data.cmd =='sendRedPacketQuestion') {
  1511. // }
  1512. } else {
  1513. uni.showToast({
  1514. title: data.msg,
  1515. icon: 'none'
  1516. });
  1517. }
  1518. },
  1519. scheduleReconnect() {
  1520. if (this.isManualClose || this.reconnectCount >= this.maxReconnectAttempts) return;
  1521. this.reconnectCount++;
  1522. const delay = Math.min(3000 * this.reconnectCount, 30000);
  1523. clearInterval(this.reconnectTimer);
  1524. this.reconnectTimer = setTimeout(() => {
  1525. this.initSocket(this.list.find(item => item.liveId === liveId) || {
  1526. liveId
  1527. });
  1528. }, delay);
  1529. },
  1530. sendMsg(liveItem) {
  1531. if (!liveItem || !liveItem.liveId) return;
  1532. // 防止连续点击发送两次(短时锁定)
  1533. if (liveItem.isSending) return;
  1534. liveItem.isSending = true;
  1535. setTimeout(() => {
  1536. liveItem.isSending = false;
  1537. }, 800); // 800ms 内禁止再次发送
  1538. const text = (liveItem.value || '').trim();
  1539. if (!text) {
  1540. uni.showToast({
  1541. title: "不能发送空消息",
  1542. icon: 'none'
  1543. });
  1544. return;
  1545. }
  1546. const liveId = liveItem.liveId;
  1547. const socketItem = this.socketInstances[liveId];
  1548. // 乐观更新:立即把消息加入到本地聊天列表并清空输入(更好的体验)
  1549. const localMsg = {
  1550. cmd: 'sendMsg',
  1551. msg: text,
  1552. nickName: this.userinfo.nickName,
  1553. avatar: this.userinfo.avatar,
  1554. userId: this.userinfo.userId,
  1555. local: true, // 标记为本地消息(可用于样式或后续差异处理)
  1556. ts: Date.now()
  1557. };
  1558. this.$set(liveItem, 'talklist', [...(liveItem.talklist || []), localMsg]);
  1559. this.$set(liveItem, 'value', ''); // 立即清空输入
  1560. if (!socketItem || !socketItem.instance || !socketItem.isOpen) {
  1561. // 如果 socket 未连接,尝试建立连接(但不要阻塞用户)
  1562. this.initSocket(liveItem);
  1563. uni.showToast({
  1564. title: "连接未建立,正在重连",
  1565. icon: 'none'
  1566. });
  1567. return;
  1568. }
  1569. const data = {
  1570. liveId,
  1571. userId: this.userinfo.userId,
  1572. userType: 0,
  1573. cmd: "sendMsg",
  1574. msg: text,
  1575. nickName: this.userinfo.nickName,
  1576. avatar: this.userinfo.avatar
  1577. };
  1578. try {
  1579. socketItem.instance.send({
  1580. data: JSON.stringify(data),
  1581. success: () => {
  1582. // 比如找到最后一条 local 消息并标记为 sent
  1583. },
  1584. fail: (err) => {
  1585. console.error("发送失败:", err);
  1586. uni.showToast({
  1587. title: "发送失败,请重试",
  1588. icon: 'none'
  1589. });
  1590. // 可选择回滚本地显示(此处简单提示即可)
  1591. }
  1592. });
  1593. } catch (err) {
  1594. console.error('socket send 异常', err);
  1595. }
  1596. }
  1597. }
  1598. };
  1599. </script>
  1600. <style scoped lang="scss">
  1601. .swiper-wrapper {
  1602. position: relative;
  1603. width: 100%;
  1604. height: 100vh;
  1605. overflow: hidden;
  1606. background-color: #000000;
  1607. }
  1608. .swiper-container {
  1609. width: 100%;
  1610. height: 100vh;
  1611. }
  1612. .container {
  1613. width: 100%;
  1614. height: 100%;
  1615. position: relative;
  1616. // 添加渐变过渡效果
  1617. transition: opacity 0.3s ease;
  1618. &.active {
  1619. opacity: 1;
  1620. }
  1621. // 非活动项半透明显示
  1622. // &:not(.active) {
  1623. // opacity: 0.7;
  1624. // }
  1625. }
  1626. .loading-tip {
  1627. position: absolute;
  1628. top: 50%;
  1629. left: 50%;
  1630. transform: translate(-50%, -50%);
  1631. display: flex;
  1632. flex-direction: column;
  1633. align-items: center;
  1634. justify-content: center;
  1635. z-index: 10;
  1636. .loading-text {
  1637. color: #ffffff;
  1638. font-size: 28rpx;
  1639. margin-top: 20rpx;
  1640. }
  1641. }
  1642. .loading-more,
  1643. .no-more {
  1644. display: flex;
  1645. justify-content: center;
  1646. align-items: center;
  1647. padding: 20rpx 0;
  1648. color: #999;
  1649. font-size: 24rpx;
  1650. }
  1651. .loading-more {
  1652. flex-direction: column;
  1653. }
  1654. .preload-indicator {
  1655. position: absolute;
  1656. top: 50%;
  1657. right: 30rpx;
  1658. transform: translateY(-50%);
  1659. z-index: 100;
  1660. background: rgba(0, 0, 0, 0.5);
  1661. border-radius: 50%;
  1662. padding: 16rpx;
  1663. }
  1664. /* button自带样式清除 */
  1665. .student-orther-icon button::after {
  1666. border: none !important;
  1667. padding: 0 !important;
  1668. margin: 0 !important;
  1669. }
  1670. .student-orther-icon button {
  1671. background-color: transparent !important;
  1672. padding: 0 !important;
  1673. line-height: inherit !important;
  1674. margin: 0 !important;
  1675. width: auto !important;
  1676. font-weight: 500 !important;
  1677. border-radius: none !important;
  1678. }
  1679. .welcome-message {
  1680. position: fixed;
  1681. width: 100%;
  1682. bottom: 460rpx;
  1683. left: 50%;
  1684. transform: translateX(-50%);
  1685. color: white;
  1686. padding: 10px 20px;
  1687. border-radius: 20px;
  1688. // animation: fadeOut 1s ease 1s forwards;
  1689. z-index: 1000;
  1690. transition: opacity 0.3s ease;
  1691. }
  1692. @keyframes fadeOut {
  1693. from {
  1694. opacity: 1;
  1695. }
  1696. to {
  1697. opacity: 0;
  1698. }
  1699. }
  1700. .send {
  1701. background-color: #fafafa;
  1702. border-radius: 28rpx;
  1703. padding: 14rpx 16rpx;
  1704. color: #181818;
  1705. font-weight: 500;
  1706. }
  1707. // .container {
  1708. // position: relative;
  1709. // width: 100%;
  1710. // height: 100vh;
  1711. // overflow: hidden;
  1712. // }
  1713. // .talktext {
  1714. // border-radius: 8rpx;
  1715. // background-color: rgba(255, 255, 255, 0.1);
  1716. // view {
  1717. // width: 100%;
  1718. // }
  1719. // }
  1720. .talk-list {
  1721. border-radius: 30rpx;
  1722. background-color: rgba(33, 33, 33, 0.5);
  1723. padding: 10rpx 30rpx;
  1724. }
  1725. // .zoom-button-active {
  1726. // transform: scale(1.5);
  1727. // }
  1728. // .background-image {
  1729. // position: absolute;
  1730. // top: 0;
  1731. // left: -40rpx;
  1732. // width: 110%;
  1733. // height: 110%;
  1734. // object-fit: cover;
  1735. // filter: blur(20px);
  1736. // z-index: 0;
  1737. // }
  1738. // .background-images {
  1739. // position: absolute;
  1740. // top: 0;
  1741. // left: -40rpx;
  1742. // width: 110%;
  1743. // height: 110%;
  1744. // object-fit: cover;
  1745. // filter: blur(20px);
  1746. // z-index: 6;
  1747. // }
  1748. // .blackbg {
  1749. // position: absolute;
  1750. // top: 0;
  1751. // left: 0;
  1752. // width: 100%;
  1753. // height: 100%;
  1754. // background: rgba(0, 0, 0, 0.7);
  1755. // object-fit: cover;
  1756. // filter: blur(10px);
  1757. // z-index: 1;
  1758. // }
  1759. .content {
  1760. position: relative;
  1761. z-index: 2;
  1762. height: 100%;
  1763. width: 100%;
  1764. top: 0;
  1765. left: 0;
  1766. display: flex;
  1767. flex-direction: column;
  1768. justify-content: space-between;
  1769. .content-top {
  1770. width: 100%;
  1771. margin-top: 68rpx;
  1772. display: flex;
  1773. // align-items: center;
  1774. justify-content: space-between;
  1775. padding: 0 24rpx;
  1776. box-sizing: border-box;
  1777. .sum {
  1778. width: 80rpx;
  1779. height: 52rpx;
  1780. background: rgba(0, 0, 0, 0.5);
  1781. border-radius: 26rpx 26rpx 26rpx 26rpx;
  1782. font-size: 24rpx;
  1783. color: #FFFFFF;
  1784. text-align: center;
  1785. line-height: 52rpx;
  1786. }
  1787. }
  1788. .follow-btn {
  1789. padding: 8rpx 16rpx;
  1790. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1791. border-radius: 26rpx;
  1792. font-weight: 500;
  1793. font-size: 26rpx;
  1794. color: #FFFFFF;
  1795. }
  1796. }
  1797. .videolist {
  1798. position: relative;
  1799. .video {
  1800. height: 100vh;
  1801. /* 占屏幕高度的80% */
  1802. width: 100%;
  1803. background-color: rgba(57, 57, 57, 0.4);
  1804. .videotop {
  1805. width: 100%;
  1806. height: 100%;
  1807. }
  1808. .video_row {
  1809. width: 100%;
  1810. max-height: 500rpx;
  1811. overflow: hidden;
  1812. margin-top: 360rpx;
  1813. }
  1814. }
  1815. }
  1816. .goods {
  1817. position: fixed;
  1818. bottom: 160rpx;
  1819. right: 10rpx;
  1820. z-index: 5;
  1821. background-color: #fff;
  1822. border-radius: 20rpx;
  1823. overflow: hidden;
  1824. width: 220rpx;
  1825. padding: 4rpx;
  1826. .top {
  1827. position: absolute;
  1828. top: 4rpx;
  1829. display: flex;
  1830. justify-content: space-between;
  1831. align-items: center;
  1832. color: #fff;
  1833. width: 100%;
  1834. padding-right: 10rpx;
  1835. box-sizing: border-box;
  1836. .left {
  1837. background-color: rgba(0, 0, 0, 0.8);
  1838. padding: 10rpx;
  1839. font-size: 20rpx;
  1840. display: flex;
  1841. justify-content: space-between;
  1842. align-items: center;
  1843. border-radius: 10rpx;
  1844. }
  1845. }
  1846. .photo {
  1847. width: 100%;
  1848. height: 200rpx;
  1849. border-radius: 16rpx 16rpx 0 0;
  1850. overflow: hidden;
  1851. }
  1852. .item {
  1853. padding: 4rpx;
  1854. .price {
  1855. .red {
  1856. color: #FF5701;
  1857. font-weight: 600;
  1858. margin-right: 10rpx;
  1859. }
  1860. .del {
  1861. color: #828282;
  1862. font-weight: 500;
  1863. font-size: 24rpx;
  1864. text-decoration: line-through
  1865. }
  1866. }
  1867. .title {
  1868. font-weight: 500;
  1869. font-size: 26rpx;
  1870. margin: 10rpx 0 12rpx;
  1871. }
  1872. .button {
  1873. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  1874. color: #fff;
  1875. text-align: center;
  1876. padding: 16rpx 0;
  1877. border-radius: 10rpx;
  1878. font-weight: 500;
  1879. }
  1880. }
  1881. }
  1882. .icon {
  1883. font-weight: 500;
  1884. font-size: 24rpx;
  1885. color: #FFFFFF;
  1886. text-align: center;
  1887. margin-bottom: -10rpx;
  1888. .button {
  1889. background-color: transparent;
  1890. margin: 0;
  1891. line-height: 1;
  1892. padding: 0;
  1893. }
  1894. }
  1895. .icon-bg {
  1896. background-color: rgba(157, 157, 157, 0.8);
  1897. border-radius: 50%;
  1898. width: 72rpx;
  1899. height: 72rpx;
  1900. display: flex;
  1901. justify-content: center;
  1902. align-items: center;
  1903. transition: transform 0.2s ease;
  1904. .button {
  1905. background-color: transparent;
  1906. margin: 0;
  1907. line-height: 1;
  1908. padding: 0;
  1909. }
  1910. }
  1911. .list {
  1912. width: 80%;
  1913. margin-bottom: 20rpx;
  1914. animation: xxxawdawd .2s;
  1915. }
  1916. @keyframes xxxawdawd {
  1917. from {
  1918. margin-top: 0rpx;
  1919. opacity: 0;
  1920. }
  1921. to {
  1922. margin-top: 20rpx;
  1923. opacity: 1;
  1924. }
  1925. }
  1926. .shop-prompt {
  1927. position: absolute;
  1928. bottom: 600rpx;
  1929. left: 24rpx;
  1930. padding: 6rpx 20rpx;
  1931. background: rgba(230, 154, 34, 0.7);
  1932. border-radius: 24rpx;
  1933. z-index: 9;
  1934. font-weight: 500;
  1935. font-size: 26rpx;
  1936. color: #FFFFFF;
  1937. transition: opacity 0.3s ease;
  1938. }
  1939. .siderow-group {
  1940. position: absolute;
  1941. top: 65%;
  1942. right: 30rpx;
  1943. z-index: 9;
  1944. display: flex;
  1945. flex-direction: column;
  1946. align-items: center;
  1947. .side-item {
  1948. font-weight: 500;
  1949. font-size: 24rpx;
  1950. color: #FFFFFF;
  1951. margin-bottom: 32rpx;
  1952. text-align: center;
  1953. .button {
  1954. background-color: transparent;
  1955. margin: 0;
  1956. line-height: 1;
  1957. padding: 0;
  1958. }
  1959. .image {
  1960. width: 72rpx;
  1961. height: 72rpx;
  1962. }
  1963. }
  1964. }
  1965. .side-group {
  1966. position: absolute;
  1967. // top: 30%;
  1968. top: 65%;
  1969. right: 30rpx;
  1970. z-index: 9;
  1971. display: flex;
  1972. flex-direction: column;
  1973. align-items: center;
  1974. .side-item {
  1975. font-weight: 500;
  1976. font-size: 24rpx;
  1977. color: #FFFFFF;
  1978. margin-bottom: 32rpx;
  1979. text-align: center;
  1980. button {
  1981. background-color: transparent;
  1982. margin: 0;
  1983. line-height: 1;
  1984. padding: 0;
  1985. }
  1986. image {
  1987. width: 72rpx;
  1988. height: 72rpx;
  1989. }
  1990. }
  1991. }
  1992. .red-box {
  1993. .button {
  1994. margin: 0 auto;
  1995. width: 80%;
  1996. line-height: 88rpx;
  1997. height: 88rpx;
  1998. background: linear-gradient(90deg, #FF5701 0%, #FFB501 100%);
  1999. box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(238, 124, 80, 0.2);
  2000. border-radius: 44rpx 44rpx 44rpx 44rpx;
  2001. font-weight: 600;
  2002. font-size: 32rpx;
  2003. color: #FFFFFF;
  2004. text-align: center;
  2005. }
  2006. }
  2007. .view-box {
  2008. position: relative;
  2009. height: 40vh;
  2010. /* 设置弹出层高度为视窗高度的70% */
  2011. padding: 40rpx 0rpx 120rpx;
  2012. box-sizing: border-box;
  2013. display: flex;
  2014. flex-direction: column;
  2015. .scroll-content {
  2016. flex: 1;
  2017. overflow-y: auto;
  2018. padding: 0 40rpx;
  2019. }
  2020. .bottom {
  2021. padding: 20rpx 40rpx;
  2022. position: absolute;
  2023. bottom: 0;
  2024. width: 100%;
  2025. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  2026. background: #fff;
  2027. }
  2028. }
  2029. .shoppop {
  2030. padding: 22rpx 16rpx;
  2031. .shoppop-top {
  2032. display: flex;
  2033. justify-content: space-between;
  2034. align-items: center;
  2035. padding: 0 16rpx 22rpx;
  2036. .search-input {
  2037. width: 414rpx;
  2038. height: 76rpx;
  2039. background: #FFFFFF;
  2040. border-radius: 36rpx;
  2041. margin-left: 20rpx;
  2042. padding: 0 32rpx;
  2043. box-sizing: border-box;
  2044. font-size: 24rpx;
  2045. margin-right: 24rpx;
  2046. }
  2047. .search-top {
  2048. font-size: 20rpx;
  2049. color: #222222;
  2050. }
  2051. }
  2052. .shop-list {
  2053. overflow: hidden;
  2054. .list-item {
  2055. display: flex;
  2056. align-items: center;
  2057. padding: 20rpx 16rpx;
  2058. background: #FFFFFF;
  2059. border-radius: 16rpx;
  2060. margin-bottom: 16rpx;
  2061. .goods-img {
  2062. width: 200rpx;
  2063. height: 200rpx;
  2064. border-radius: 16rpx;
  2065. overflow: hidden;
  2066. position: relative;
  2067. margin-right: 24rpx;
  2068. image {
  2069. width: 100%;
  2070. height: 100%;
  2071. }
  2072. .goods-label {
  2073. position: absolute;
  2074. top: 0;
  2075. width: 64rpx;
  2076. height: 40rpx;
  2077. background: rgba(0, 0, 0, 0.5);
  2078. border-radius: 16rpx 0rpx 16rpx 0rpx;
  2079. text-align: center;
  2080. font-weight: 500;
  2081. font-size: 28rpx;
  2082. color: #FFFFFF;
  2083. }
  2084. }
  2085. .goods-right {
  2086. flex: 1;
  2087. .goods-title {
  2088. font-weight: 500;
  2089. font-size: 28rpx;
  2090. color: #000000;
  2091. }
  2092. .goods-details {
  2093. font-size: 24rpx;
  2094. color: #999999;
  2095. margin: 10rpx 0 20rpx;
  2096. }
  2097. .goods-people {
  2098. font-size: 22rpx;
  2099. color: #E69A22;
  2100. height: 56rpx;
  2101. }
  2102. .goods-shop {
  2103. display: flex;
  2104. justify-content: space-between;
  2105. .nummber {
  2106. color: #FF5C03;
  2107. font-size: 22rpx;
  2108. font-weight: 500;
  2109. }
  2110. .btn-group {
  2111. text-align: center;
  2112. line-height: 56rpx;
  2113. .collect-btn {
  2114. width: 72rpx;
  2115. background: #F5F7FA;
  2116. border-radius: 8rpx 0rpx 0rpx 8rpx;
  2117. }
  2118. .shop-btn {
  2119. width: 152rpx;
  2120. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2121. border-radius: 0rpx 8rpx 8rpx 0rpx;
  2122. font-weight: 500;
  2123. font-size: 26rpx;
  2124. color: #FFFFFF;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. :deep(.u-list-item) {
  2133. width: 100%;
  2134. display: flex;
  2135. align-items: center;
  2136. }
  2137. :deep(.u-safe-area-inset-bottom) {
  2138. padding-bottom: 0
  2139. }
  2140. </style>