living - 副本.vue 61 KB

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