living.vue 62 KB

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