living827.vue 61 KB

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