living.vue 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  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 == 'out') {
  1498. // console.log("进入:", liveItem);
  1499. console.log("有人退出了:");
  1500. } else if (socketMessage.cmd == 'Integral') {
  1501. // 观看奖励事件 弹出框2s 显示msg
  1502. } else if (socketMessage.cmd == 'blockUser') {
  1503. // 拉黑事件 主动删除用户token,强制跳转到登录页面
  1504. } else if (socketMessage.cmd == 'live_start') {
  1505. // 直播开始
  1506. } else if (socketMessage.cmd == 'live_end') {
  1507. // 直播结束
  1508. } else if (socketMessage.data.cmd == 'deleteId') {
  1509. uni.$emit('deleteId');
  1510. } else if (socketMessage.data.cmd == 'sendRedPacketQuestion') {
  1511. // const list = JSON.parse(socketMessage)
  1512. // liveItem.redanswerAll = [...liveItem.redanswerAll, ...list]
  1513. // if (liveItem.redanswerAll[1].randomAmount !== null) {
  1514. // liveItem.redanswertips = JSON.parse(liveItem.redanswerAll[0]
  1515. // .randomAmount)
  1516. // }
  1517. }
  1518. } else {
  1519. uni.showToast({
  1520. title: data.msg,
  1521. icon: 'none'
  1522. });
  1523. }
  1524. },
  1525. scheduleReconnect() {
  1526. if (this.isManualClose || this.reconnectCount >= this.maxReconnectAttempts) return;
  1527. this.reconnectCount++;
  1528. const delay = Math.min(3000 * this.reconnectCount, 30000);
  1529. clearInterval(this.reconnectTimer);
  1530. this.reconnectTimer = setTimeout(() => {
  1531. this.initSocket(this.list.find(item => item.liveId === liveId) || {
  1532. liveId
  1533. });
  1534. }, delay);
  1535. },
  1536. sendMsg(liveItem) {
  1537. if (!liveItem || !liveItem.liveId) return;
  1538. // 防止连续点击发送两次(短时锁定)
  1539. if (liveItem.isSending) return;
  1540. liveItem.isSending = true;
  1541. setTimeout(() => {
  1542. liveItem.isSending = false;
  1543. }, 800); // 800ms 内禁止再次发送
  1544. const text = (liveItem.value || '').trim();
  1545. if (!text) {
  1546. uni.showToast({
  1547. title: "不能发送空消息",
  1548. icon: 'none'
  1549. });
  1550. return;
  1551. }
  1552. const liveId = liveItem.liveId;
  1553. const socketItem = this.socketInstances[liveId];
  1554. // 乐观更新:立即把消息加入到本地聊天列表并清空输入(更好的体验)
  1555. const localMsg = {
  1556. cmd: 'sendMsg',
  1557. msg: text,
  1558. nickName: this.userinfo.nickName,
  1559. avatar: this.userinfo.avatar,
  1560. userId: this.userinfo.userId,
  1561. local: true, // 标记为本地消息(可用于样式或后续差异处理)
  1562. ts: Date.now()
  1563. };
  1564. this.$set(liveItem, 'talklist', [...(liveItem.talklist || []), localMsg]);
  1565. this.$set(liveItem, 'value', ''); // 立即清空输入
  1566. if (!socketItem || !socketItem.instance || !socketItem.isOpen) {
  1567. // 如果 socket 未连接,尝试建立连接(但不要阻塞用户)
  1568. this.initSocket(liveItem);
  1569. uni.showToast({
  1570. title: "连接未建立,正在重连",
  1571. icon: 'none'
  1572. });
  1573. return;
  1574. }
  1575. const data = {
  1576. liveId,
  1577. userId: this.userinfo.userId,
  1578. userType: 0,
  1579. cmd: "sendMsg",
  1580. msg: text,
  1581. nickName: this.userinfo.nickName,
  1582. avatar: this.userinfo.avatar
  1583. };
  1584. try {
  1585. socketItem.instance.send({
  1586. data: JSON.stringify(data),
  1587. success: () => {
  1588. // 成功后可以移除 local 标记(可选)
  1589. // 比如找到最后一条 local 消息并标记为 sent
  1590. },
  1591. fail: (err) => {
  1592. console.error("发送失败:", err);
  1593. uni.showToast({
  1594. title: "发送失败,请重试",
  1595. icon: 'none'
  1596. });
  1597. // 可选择回滚本地显示(此处简单提示即可)
  1598. }
  1599. });
  1600. } catch (err) {
  1601. console.error('socket send 异常', err);
  1602. }
  1603. }
  1604. }
  1605. };
  1606. </script>
  1607. <style scoped lang="scss">
  1608. .swiper-wrapper {
  1609. position: relative;
  1610. width: 100%;
  1611. height: 100vh;
  1612. overflow: hidden;
  1613. background-color: #000000;
  1614. }
  1615. .swiper-container {
  1616. width: 100%;
  1617. height: 100vh;
  1618. }
  1619. .container {
  1620. width: 100%;
  1621. height: 100%;
  1622. position: relative;
  1623. // 添加渐变过渡效果
  1624. transition: opacity 0.3s ease;
  1625. &.active {
  1626. opacity: 1;
  1627. }
  1628. // 非活动项半透明显示
  1629. // &:not(.active) {
  1630. // opacity: 0.7;
  1631. // }
  1632. }
  1633. .loading-tip {
  1634. position: absolute;
  1635. top: 50%;
  1636. left: 50%;
  1637. transform: translate(-50%, -50%);
  1638. display: flex;
  1639. flex-direction: column;
  1640. align-items: center;
  1641. justify-content: center;
  1642. z-index: 10;
  1643. .loading-text {
  1644. color: #ffffff;
  1645. font-size: 28rpx;
  1646. margin-top: 20rpx;
  1647. }
  1648. }
  1649. .loading-more,
  1650. .no-more {
  1651. display: flex;
  1652. justify-content: center;
  1653. align-items: center;
  1654. padding: 20rpx 0;
  1655. color: #999;
  1656. font-size: 24rpx;
  1657. }
  1658. .loading-more {
  1659. flex-direction: column;
  1660. }
  1661. .preload-indicator {
  1662. position: absolute;
  1663. top: 50%;
  1664. right: 30rpx;
  1665. transform: translateY(-50%);
  1666. z-index: 100;
  1667. background: rgba(0, 0, 0, 0.5);
  1668. border-radius: 50%;
  1669. padding: 16rpx;
  1670. }
  1671. /* button自带样式清除 */
  1672. .student-orther-icon button::after {
  1673. border: none !important;
  1674. padding: 0 !important;
  1675. margin: 0 !important;
  1676. }
  1677. .student-orther-icon button {
  1678. background-color: transparent !important;
  1679. padding: 0 !important;
  1680. line-height: inherit !important;
  1681. margin: 0 !important;
  1682. width: auto !important;
  1683. font-weight: 500 !important;
  1684. border-radius: none !important;
  1685. }
  1686. .welcome-message {
  1687. position: fixed;
  1688. width: 100%;
  1689. bottom: 460rpx;
  1690. left: 50%;
  1691. transform: translateX(-50%);
  1692. color: white;
  1693. padding: 10px 20px;
  1694. border-radius: 20px;
  1695. // animation: fadeOut 1s ease 1s forwards;
  1696. z-index: 1000;
  1697. transition: opacity 0.3s ease;
  1698. }
  1699. @keyframes fadeOut {
  1700. from {
  1701. opacity: 1;
  1702. }
  1703. to {
  1704. opacity: 0;
  1705. }
  1706. }
  1707. .send {
  1708. background-color: #4b4b4b;
  1709. border-radius: 28rpx;
  1710. padding: 14rpx 16rpx;
  1711. color: #fff;
  1712. }
  1713. // .container {
  1714. // position: relative;
  1715. // width: 100%;
  1716. // height: 100vh;
  1717. // overflow: hidden;
  1718. // }
  1719. // .talktext {
  1720. // border-radius: 8rpx;
  1721. // background-color: rgba(255, 255, 255, 0.1);
  1722. // view {
  1723. // width: 100%;
  1724. // }
  1725. // }
  1726. .talk-list {
  1727. border-radius: 30rpx;
  1728. background-color: rgba(33, 33, 33, 0.5);
  1729. padding: 10rpx 30rpx;
  1730. }
  1731. // .zoom-button-active {
  1732. // transform: scale(1.5);
  1733. // }
  1734. // .background-image {
  1735. // position: absolute;
  1736. // top: 0;
  1737. // left: -40rpx;
  1738. // width: 110%;
  1739. // height: 110%;
  1740. // object-fit: cover;
  1741. // filter: blur(20px);
  1742. // z-index: 0;
  1743. // }
  1744. // .background-images {
  1745. // position: absolute;
  1746. // top: 0;
  1747. // left: -40rpx;
  1748. // width: 110%;
  1749. // height: 110%;
  1750. // object-fit: cover;
  1751. // filter: blur(20px);
  1752. // z-index: 6;
  1753. // }
  1754. // .blackbg {
  1755. // position: absolute;
  1756. // top: 0;
  1757. // left: 0;
  1758. // width: 100%;
  1759. // height: 100%;
  1760. // background: rgba(0, 0, 0, 0.7);
  1761. // object-fit: cover;
  1762. // filter: blur(10px);
  1763. // z-index: 1;
  1764. // }
  1765. .content {
  1766. position: relative;
  1767. z-index: 2;
  1768. height: 100%;
  1769. width: 100%;
  1770. top: 0;
  1771. left: 0;
  1772. display: flex;
  1773. flex-direction: column;
  1774. justify-content: space-between;
  1775. .content-top {
  1776. width: 100%;
  1777. margin-top: 68rpx;
  1778. display: flex;
  1779. // align-items: center;
  1780. justify-content: space-between;
  1781. padding: 0 24rpx;
  1782. box-sizing: border-box;
  1783. .sum {
  1784. width: 80rpx;
  1785. height: 52rpx;
  1786. background: rgba(0, 0, 0, 0.5);
  1787. border-radius: 26rpx 26rpx 26rpx 26rpx;
  1788. font-size: 24rpx;
  1789. color: #FFFFFF;
  1790. text-align: center;
  1791. line-height: 52rpx;
  1792. }
  1793. }
  1794. .follow-btn {
  1795. padding: 8rpx 16rpx;
  1796. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1797. border-radius: 26rpx;
  1798. font-weight: 500;
  1799. font-size: 26rpx;
  1800. color: #FFFFFF;
  1801. }
  1802. }
  1803. .videolist {
  1804. position: relative;
  1805. .video {
  1806. height: 100vh;
  1807. /* 占屏幕高度的80% */
  1808. width: 100%;
  1809. background-color: rgba(57, 57, 57, 0.4);
  1810. .videotop {
  1811. width: 100%;
  1812. height: 100%;
  1813. }
  1814. .video_row {
  1815. width: 100%;
  1816. max-height: 500rpx;
  1817. overflow: hidden;
  1818. margin-top: 360rpx;
  1819. }
  1820. }
  1821. }
  1822. .goods {
  1823. position: fixed;
  1824. bottom: 120rpx;
  1825. right: 0rpx;
  1826. z-index: 5;
  1827. background-color: #fff;
  1828. border-radius: 20rpx;
  1829. overflow: hidden;
  1830. width: 200rpx;
  1831. height: 350rpx;
  1832. .top {}
  1833. }
  1834. // .icon-bg {
  1835. // background-color: rgba(157, 157, 157, 0.8);
  1836. // border-radius: 50%;
  1837. // width: 72rpx;
  1838. // height: 72rpx;
  1839. // display: flex;
  1840. // justify-content: center;
  1841. // align-items: center;
  1842. // transition: transform 0.2s ease;
  1843. // }
  1844. .list {
  1845. width: 80%;
  1846. margin-bottom: 20rpx;
  1847. animation: xxxawdawd .2s;
  1848. }
  1849. @keyframes xxxawdawd {
  1850. from {
  1851. margin-top: 0rpx;
  1852. opacity: 0;
  1853. }
  1854. to {
  1855. margin-top: 20rpx;
  1856. opacity: 1;
  1857. }
  1858. }
  1859. .shop-prompt {
  1860. position: absolute;
  1861. bottom: 600rpx;
  1862. left: 24rpx;
  1863. padding: 6rpx 20rpx;
  1864. background: rgba(230, 154, 34, 0.7);
  1865. border-radius: 24rpx;
  1866. z-index: 9;
  1867. font-weight: 500;
  1868. font-size: 26rpx;
  1869. color: #FFFFFF;
  1870. transition: opacity 0.3s ease;
  1871. }
  1872. .siderow-group {
  1873. position: absolute;
  1874. top: 65%;
  1875. right: 30rpx;
  1876. z-index: 9;
  1877. display: flex;
  1878. flex-direction: column;
  1879. align-items: center;
  1880. .side-item {
  1881. font-weight: 500;
  1882. font-size: 24rpx;
  1883. color: #FFFFFF;
  1884. margin-bottom: 32rpx;
  1885. text-align: center;
  1886. button {
  1887. background-color: transparent;
  1888. margin: 0;
  1889. line-height: 1;
  1890. padding: 0;
  1891. }
  1892. image {
  1893. width: 72rpx;
  1894. height: 72rpx;
  1895. }
  1896. }
  1897. }
  1898. .side-group {
  1899. position: absolute;
  1900. // top: 30%;
  1901. top: 65%;
  1902. right: 30rpx;
  1903. z-index: 9;
  1904. display: flex;
  1905. flex-direction: column;
  1906. align-items: center;
  1907. .side-item {
  1908. font-weight: 500;
  1909. font-size: 24rpx;
  1910. color: #FFFFFF;
  1911. margin-bottom: 32rpx;
  1912. text-align: center;
  1913. button {
  1914. background-color: transparent;
  1915. margin: 0;
  1916. line-height: 1;
  1917. padding: 0;
  1918. }
  1919. image {
  1920. width: 72rpx;
  1921. height: 72rpx;
  1922. }
  1923. }
  1924. }
  1925. .red-box {
  1926. .button {
  1927. margin: 0 auto;
  1928. width: 80%;
  1929. line-height: 88rpx;
  1930. height: 88rpx;
  1931. background: linear-gradient(90deg, #FF5701 0%, #FFB501 100%);
  1932. box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(238, 124, 80, 0.2);
  1933. border-radius: 44rpx 44rpx 44rpx 44rpx;
  1934. font-weight: 600;
  1935. font-size: 32rpx;
  1936. color: #FFFFFF;
  1937. text-align: center;
  1938. }
  1939. }
  1940. .view-box {
  1941. position: relative;
  1942. height: 40vh;
  1943. /* 设置弹出层高度为视窗高度的70% */
  1944. padding: 40rpx 0rpx 120rpx;
  1945. box-sizing: border-box;
  1946. display: flex;
  1947. flex-direction: column;
  1948. .scroll-content {
  1949. flex: 1;
  1950. overflow-y: auto;
  1951. padding: 0 40rpx;
  1952. }
  1953. .bottom {
  1954. padding: 20rpx 40rpx;
  1955. position: absolute;
  1956. bottom: 0;
  1957. width: 100%;
  1958. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  1959. background: #fff;
  1960. }
  1961. }
  1962. .shoppop {
  1963. padding: 22rpx 16rpx;
  1964. .shoppop-top {
  1965. display: flex;
  1966. justify-content: space-between;
  1967. align-items: center;
  1968. padding: 0 16rpx 22rpx;
  1969. .search-input {
  1970. width: 414rpx;
  1971. height: 76rpx;
  1972. background: #FFFFFF;
  1973. border-radius: 36rpx;
  1974. margin-left: 20rpx;
  1975. padding: 0 32rpx;
  1976. box-sizing: border-box;
  1977. font-size: 24rpx;
  1978. margin-right: 24rpx;
  1979. }
  1980. .search-top {
  1981. font-size: 20rpx;
  1982. color: #222222;
  1983. }
  1984. }
  1985. .shop-list {
  1986. overflow: hidden;
  1987. .list-item {
  1988. display: flex;
  1989. align-items: center;
  1990. padding: 20rpx 16rpx;
  1991. background: #FFFFFF;
  1992. border-radius: 16rpx;
  1993. margin-bottom: 16rpx;
  1994. .goods-img {
  1995. width: 200rpx;
  1996. height: 200rpx;
  1997. border-radius: 16rpx;
  1998. overflow: hidden;
  1999. position: relative;
  2000. margin-right: 24rpx;
  2001. image {
  2002. width: 100%;
  2003. height: 100%;
  2004. }
  2005. .goods-label {
  2006. position: absolute;
  2007. top: 0;
  2008. width: 64rpx;
  2009. height: 40rpx;
  2010. background: rgba(0, 0, 0, 0.5);
  2011. border-radius: 16rpx 0rpx 16rpx 0rpx;
  2012. text-align: center;
  2013. font-weight: 500;
  2014. font-size: 28rpx;
  2015. color: #FFFFFF;
  2016. }
  2017. }
  2018. .goods-right {
  2019. flex: 1;
  2020. .goods-title {
  2021. font-weight: 500;
  2022. font-size: 28rpx;
  2023. color: #000000;
  2024. }
  2025. .goods-details {
  2026. font-size: 24rpx;
  2027. color: #999999;
  2028. margin: 10rpx 0 20rpx;
  2029. }
  2030. .goods-people {
  2031. font-size: 22rpx;
  2032. color: #E69A22;
  2033. height: 56rpx;
  2034. }
  2035. .goods-shop {
  2036. display: flex;
  2037. justify-content: space-between;
  2038. .nummber {
  2039. color: #FF5C03;
  2040. font-size: 22rpx;
  2041. font-weight: 500;
  2042. }
  2043. .btn-group {
  2044. text-align: center;
  2045. line-height: 56rpx;
  2046. .collect-btn {
  2047. width: 72rpx;
  2048. background: #F5F7FA;
  2049. border-radius: 8rpx 0rpx 0rpx 8rpx;
  2050. }
  2051. .shop-btn {
  2052. width: 152rpx;
  2053. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2054. border-radius: 0rpx 8rpx 8rpx 0rpx;
  2055. font-weight: 500;
  2056. font-size: 26rpx;
  2057. color: #FFFFFF;
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. :deep(.u-list-item) {
  2066. width: 100%;
  2067. display: flex;
  2068. align-items: center;
  2069. }
  2070. :deep(.u-safe-area-inset-bottom) {
  2071. padding-bottom: 0
  2072. }
  2073. </style>