living.vue 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. <template>
  2. <view class="container">
  3. <!-- <view class="popup-video " v-if="!autoplay">
  4. <view class="fs36 bold" v-if="livedata.status==1">——直播还未开始——</view>
  5. <view class="fs36 bold" v-if="livedata.status==3">——直播已经结束——</view>
  6. <view class="fs28 mtb20">了解更多,点击下方联系老师</view>
  7. <view class="more" @click="showadd=!showadd">联系老师</view>
  8. </view> -->
  9. <!-- <image :src="livedata.liveImgUrl"
  10. :class="livedata.status!=2?'background-images':'background-image'"></image> -->
  11. <view class="blackbg"></view>
  12. <view class="content">
  13. <!-- 页面内容 -->
  14. <view style=" position: fixed;top: 0;z-index: 5;" class="content-top">
  15. <view class="u-flex-y-center">
  16. <image @click="goBack" style="width: 60rpx;height: 64rpx;margin-right: 26rpx;"
  17. src="@/static/images/live/return.png"></image>
  18. <view class=" align-center"
  19. style="padding: 6rpx 4rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  20. <u-avatar :src="livedata.liveImgUrl" size="32"></u-avatar>
  21. <view class="colorf" style="margin-left: 8rpx;">
  22. <view>{{livedata.liveName?livedata.liveName:"芳华未来"}}</view>
  23. <view style="font-size: 16rpx;">
  24. {{ liveViewData.follow || liveViewData.follow === 0 ? liveViewData.follow : 0 }}位粉丝
  25. </view>
  26. </view>
  27. <view v-if="isFollow" @click="onFollow" class="follow-btn ml20">关注</view>
  28. <view v-else @click="onFollow" class="follow-btn ml20">已关注</view>
  29. </view>
  30. </view>
  31. <view class="u-flex-end align-center">
  32. <image class="w52 h52 mr4" v-for="(item,index) in filteredViewers" :key="index"
  33. style="border-radius: 26rpx;" :src="item.avatar"></image>
  34. <view class="sum">{{liveViewData.online}}</view>
  35. </view>
  36. </view>
  37. <!-- 右边的 -->
  38. <view class="side-group">
  39. <view class="side-item">
  40. <image @click="onLike()" src="/static/images/live/like.png"></image>
  41. <view>{{liveViewData.like}}</view>
  42. <!-- <view>{{liveData likeName}}</view> -->
  43. </view>
  44. <view class="side-item" @click="goStore()">
  45. <image src="/static/images/live/shop.png"></image>
  46. <view>店铺</view>
  47. </view>
  48. <view class="side-item">
  49. <image src="/static/images/live/share.png"></image>
  50. <view>分享</view>
  51. </view>
  52. </view>
  53. <view class="shop-prompt u-flex-y-center">
  54. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  55. <text> {{orderUser.userName ? maskString(orderUser.userName) : ''}} 等 {{orderUser.count || 0}}
  56. 人正在去购买</text>
  57. </view>
  58. <!-- <view class="videolist " style="margin: auto 0">
  59. <view class="vedio" :style="{height:isScreen?'100vh':''}">
  60. <video id="myVideo" class="videotop" :src="livingUrl" :autoplay="autoplay" :controls='false'
  61. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"></video>
  62. </view>
  63. </view> -->
  64. <!-- object-fit:fill; -->
  65. <view class="videolist " style="margin: auto 0">
  66. <view class="vedio" :style="{height:isScreen?'100vh':''}">
  67. <!-- 修改video组件以支持HLS -->
  68. <video id="myVideo" class="videotop" :src="livingUrl" :autoplay="autoplay" :controls='false'
  69. :custom-cache="false" :enable-progress-gesture="false" vslide-gesture-in-fullscreen='true'
  70. :show-center-play-btn="false" :http-cache="false" @error="videoError">
  71. </video>
  72. </view>
  73. </view>
  74. <view class="pb40 mt90" style="position: fixed;bottom: 0;">
  75. <view class="w100 h300 mt20">
  76. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  77. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  78. :scroll-into-view="scrollIntoView">
  79. <view>
  80. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  81. :id="`list_${index}`" v-show="item.cmd=='announcement'">
  82. <view class="talk-list ml16 justify-start">
  83. <view class="fs24">
  84. <text class='fs24 colorf'> {{item.msg}}直播间{{messageContent}}</text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 弹幕 -->
  90. <!-- <u-list class="chat-list" height="184" @scrolltolower="scrollchat">
  91. <u-list-item class="chat-item" v-for="(item,index) in chatList" :key="index">
  92. <view class="chat-lable u-flex-y-center mr8" v-if="item.lable">
  93. <image class="w24 h24 mr8" src="@/static/images/live/diamond.png"></image>
  94. <text>{{item.lable}}</text>
  95. </view>
  96. <text style="color: #FFDA73;white-space: nowrap;" class=" mr8">{{item.name}}:</text>
  97. <text style="flex: 1;min-width: 0;word-break: break-word;">{{item.txt}}</text>
  98. </u-list-item>
  99. </u-list> -->
  100. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  101. :id="`list_${index}`" v-show="item.cmd=='sendMsg'">
  102. <view class="talk-list ml16 justify-start">
  103. <view class="fs24">
  104. <!-- <text style="color: #3fc69b;transform: scale(0.8);display: inline-block; "v-if="item.userId==userinfo.userId&&item.cmd=='sendMsg'">我</text> -->
  105. <!-- <text style="color: #c84e1e;transform: scale(0.8);display: inline-block;" v-if="item.userType==1">[ 管理员 ]</text> -->
  106. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  107. <text class='fs24 colorf'>{{item.msg}}</text>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  112. :id="`list_${index}`" v-show="item.cmd=='sendMsg'">
  113. <view class="talk-list ml16 justify-start">
  114. <view class="fs24">
  115. <text style="color: #3fc69b;transform: scale(0.8);display: inline-block; "
  116. v-if="item.userId==userinfo.userId&&item.cmd=='sendMsg'">我</text>
  117. <text style="color: #c84e1e;transform: scale(0.8);display: inline-block;" v-if="item.userType==1">
  118. [ 管理员 ]</text>
  119. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  120. <text class='fs24 colorf'>{{item.msg}}</text>
  121. </view>
  122. </view>
  123. </view> -->
  124. <view v-if="showWelcomeMessage" class="welcome-message">
  125. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  126. :id="`list_${index}`" v-show="item.cmd=='entry'||item.cmd=='out'">
  127. <view class="talk-list ml16 justify-start">
  128. <view class="fs24">
  129. <text style="color: #ff89d6;">{{item.nickName}} </text>
  130. <text class='fs24 colorf'> {{item.msg}}直播间{{messageContent}}</text>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </scroll-view>
  136. </view>
  137. <view class="justify-between p24">
  138. <view class="u-flex-y-center"
  139. style="background:rgba(255,255,255,0.2);padding:18rpx 14rpx 18rpx 32rpx;width: 526rpx;box-sizing:border-box;border-radius:36rpx;">
  140. <u-input :placeholder="placeholderText" border="none" customStyle='font-size:24rpx;'
  141. v-model="value" shape='circle' color='#fff' placeholderStyle='color:#e7e7e7' class="ml20"
  142. @keydown.enter="sendMsg" @confirm="sendMsg">
  143. </u-input>
  144. <!-- <image @click="sendMsg" class="w44 h44" src="@/static/images/live/like.png"></image> -->
  145. </view>
  146. <!-- :disabled='talkdisabled' ></u-input> -->
  147. <!-- <view @click="sendMsg" class="colorf center ml10 fs24">发送</view> -->
  148. <view class="justify-between mr30 align-center">
  149. <!-- <view class="icon-bg ml20" @click="answerbtn=!answerbtn">
  150. <image src="/static/images/redbag.png" class="w40 h40"></image>
  151. </view> -->
  152. <view class="icon-bg ml20" @click="shopping=!shopping">
  153. <image src="/static/images/shopping.png" class="w48 h48"></image>
  154. </view>
  155. <view class="icon-bg ml20" @click="showziliao=!showziliao">
  156. <image src="/static/images/more-icon.png" class="w48 h48"></image>
  157. </view>
  158. <!-- <view class="icon-bg ml20" :class="{ 'zoom-button-active': isZoom }"
  159. @touchstart="handleTouchStart" @touchend="handleTouchEnd">
  160. <image src="/static/images/dianzan.png" class="w40 h40"></image>
  161. </view> -->
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. <!-- <u-popup :show="showadd" @close="close" @open="open" round='20rpx' bgColor='#fffee1'>
  167. <view class="addchat p20">
  168. <view class="u-flex-row-reverse u-flex">
  169. <u-icon name="close" size="18" @click="showadd=!showadd"></u-icon>
  170. </view>
  171. <view class="column align-center">
  172. <view class="fs36" style="color: #ff5c03;">扫码添加助教老师</view>
  173. <view class="fs28 color6">扫码添加助教老师</view>
  174. <view class="p10 mt40" style="border: #ff5c03 solid 2rpx;">
  175. <image :src="codeimg" class="wh180" @touchstart="longPress" @touchend="cancelLongPress">
  176. </image>
  177. </view>
  178. <view class="color6 mt20">长按识别二维码</view>
  179. </view>
  180. </view>
  181. </u-popup> -->
  182. <u-popup :show="showziliao" @close="closes" round='20' bgColor='#fffee1'>
  183. <view class="addchat p20 bgf" style="border-radius: 20rpx;">
  184. <view class="u-flex-row-reverse u-flex">
  185. <u-icon name="close" size="18" @click="showziliao=!showziliao"></u-icon>
  186. </view>
  187. <view class="column align-center h400">
  188. <view class="fs36 " style="color: #ff5c03;">资料</view>
  189. <view v-html="livedata.liveDesc"></view>
  190. </view>
  191. </view>
  192. </u-popup>
  193. <!-- 抽奖 -->
  194. <!-- <u-popup :show="answerbtn" @close="closeanswer" round='40rpx' bgColor='#fff'>
  195. <view class=" p20 bgf" style="border-radius: 40rpx;height: fit-content;">
  196. <view class="u-flex-row-reverse u-flex">
  197. <u-icon name="close" size="18" @click="answerbtn=!answerbtn"></u-icon>
  198. </view>
  199. <view class="column align-center h400">
  200. <view class="fs36 " style="color: #000000;font-weight: bold;">答题获取红包/积分奖励</view>
  201. <view class="answerpop" @click="noredanswer">
  202. <view class="color6 w350 fs24">
  203. 边玩边学,解锁你的知识巅峰!
  204. </view>
  205. <view class="answera">答题挑战</view>
  206. </view>
  207. <view class="answerpop">
  208. <view class="color6 fs24" v-if='redanswertips&&redanswertips.length>0'>
  209. 🔥 <text style="color: #ff5c03;" class="fs30 bold">{{redanswertips[1].probability}}</text>
  210. %用户首抽得
  211. <text style="color: #ff5c03;" class="fs40 bold">{{redanswertips[1].maxAmount}}</text>元
  212. </view>
  213. <view v-else class="color6 w350 fs24">
  214. 随机奖励
  215. </view>
  216. <view class="answera" @click="redbagAnswer">
  217. <image src="/static/images/baganswer.png"></image>
  218. <view> 获得红包</view>
  219. </view>
  220. </view>
  221. </view>
  222. </view>
  223. </u-popup> -->
  224. <!-- <u-popup :show="showAnswer" @close="closest" round='40' bgColor='#fffee1' mode="center">
  225. <view class="answerbox p20 bgf">
  226. <view class="u-flex-row-reverse u-flex">
  227. <u-icon name="close" size="18" @click="closest"></u-icon>
  228. </view>
  229. <view class="column align-center ">
  230. <view v-if="answerlist.type==1" style="width: 100%;">
  231. <view class="mb40" style="text-align: center;">
  232. <text class="color9 fs24">(单选)</text>{{answerlist.title}}
  233. </view>
  234. <view v-for="(item,index) in answerlist.content" :key="index"
  235. :class=" checkboxValue[0]== item.label?'answeract itemanswer':'itemanswer' "
  236. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  237. </view>
  238. <view v-if="answerlist.type==2" style="width: 100%;">
  239. <view class="mb40 " style="text-align: center;">
  240. <text class="color9 fs24">(多选)</text>{{answerlist.title}}
  241. </view>
  242. <view v-for="(item,index) in answerlist.content" :key="index"
  243. :class=" checkboxValue.includes(item.label)?'answeract itemanswer':'itemanswer' "
  244. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  245. <view class=" submitbtn" @click="submitAnswers">确认</view>
  246. </view>
  247. <view class="fs24 mtb20 " style="color: #717171;">
  248. {{answerfrist+1}}/{{Answerlistall}}
  249. </view>
  250. </view>
  251. </view>
  252. </u-popup> -->
  253. <!-- <u-popup :show="showAnswerred" @close="closestred" round='40' bgColor='#fffee1' mode="center">
  254. <view class="answerbox p20 bgf">
  255. <view class="u-flex-row-reverse u-flex">
  256. <u-icon name="close" size="18" @click="closestred"></u-icon>
  257. </view>
  258. <view class="column align-center ">
  259. <view v-if="answerlist.type==1" style="width: 100%;">
  260. <view class="mb40" style="text-align: center;">
  261. <text class="color9 fs24">(单选)</text>{{answerlist.title}}
  262. </view>
  263. <view v-for="(item,index) in answerlist.content" :key="index"
  264. :class=" checkboxValue[0]== item.label?'answeract itemanswer':'itemanswer' "
  265. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  266. </view>
  267. <view v-if="answerlist.type==2" style="width: 100%;">
  268. <view class="mb40 " style="text-align: center;">
  269. <text class="color9 fs24">(多选)</text>{{answerlist.title}}
  270. </view>
  271. <view v-for="(item,index) in answerlist.content" :key="index"
  272. :class=" checkboxValue.includes(item.label)?'answeract itemanswer':'itemanswer' "
  273. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  274. <view class=" submitbtn" @click="submitAnswers">确认</view>
  275. </view>
  276. <view class="fs24 mtb20 " style="color: #717171;">
  277. {{answerfrist+1}}/{{Answerlistall}}
  278. </view>
  279. </view>
  280. </view>
  281. </u-popup> -->
  282. <!-- 小黄车弹窗 -->
  283. <u-popup :show="shopping" @close="closeshop" @open="open" round='20rpx' bgColor='#f3f5f9'>
  284. <view class="shoppop">
  285. <view class="shoppop-top">
  286. <u-avatar :src="livedata.liveImgUrl" size="36" class="ml16"></u-avatar>
  287. <view class="search-input u-flex-y-center">
  288. <image style="width: 24rpx;height: 24rpx;margin-right: 16rpx;" src="@/static/images/search.png">
  289. </image>
  290. <input placeholder="搜索商品或序号" />
  291. </view>
  292. <view class="t-c search-top" style="margin-right: 48rpx;" @click="onCollect">
  293. <image style="width: 32rpx;height: 32rpx;" src="@/static/images/collect.png"></image>
  294. <view>收藏</view>
  295. </view>
  296. <view class="t-c search-top" @click="goOrderList">
  297. <image style="width: 32rpx;height: 32rpx;" src="@/static/images/order.png"></image>
  298. <view>订单</view>
  299. </view>
  300. </view>
  301. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  302. <view class="list-item " v-for="(item,index) in products" :key="index">
  303. <view class="goods-img">
  304. <image :src="item.imgUrl" mode="widthFix"></image>
  305. <view class="goods-label">{{index+1}}</view>
  306. </view>
  307. <view class="goods-right">
  308. <view class="goods-title">{{item.productName}}</view>
  309. <view class="goods-details">{{item.productIntroduce}}</view>
  310. <view class="goods-people">{{item.sales}} 人已购</view>
  311. <view class="goods-shop">
  312. <text class="nummber"><text style="font-size: 20rpx;font-weight: 600;">¥</text><text
  313. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  314. <view class="btn-group u-flex-y-center">
  315. <view class="collect-btn">
  316. <image @click="onCollect(item)" style="width: 32rpx;height: 32rpx;"
  317. src="/static/images/collect.png">
  318. </image>
  319. </view>
  320. <view v-if="item.status==1" class="shop-btn" @click="goShop(item.productId)">去购买
  321. </view>
  322. <view v-else-if="item.status==0" @click="goShop(item.productId)" class="shop-btn">
  323. 已下架</view>
  324. </view>
  325. </view>
  326. </view>
  327. </view>
  328. </scroll-view>
  329. </view>
  330. </u-popup>
  331. </view>
  332. </template>
  333. <script>
  334. import Hls from 'hls.js';
  335. import CryptoJS from 'crypto-js'
  336. import {
  337. liveDataLike, // 点赞
  338. collectStore, // 收藏/取消收藏
  339. follow, // 关注/取消关注
  340. getRecentLiveViewers, //获取直播间用户(展示在线用户)
  341. // 小黄车
  342. liveStore, //店铺展示,
  343. // liveGoodsDetail, //商品详情,
  344. liveOrderUser, //正在购买
  345. getLiveInfo, //获取直播间信息接口
  346. getLiveViewData //直播间点赞、关注、在线人数数据
  347. } from '@/api/live'
  348. import {
  349. liveOrderList, // 订单列表
  350. } from '@/api/order'
  351. import parse from '../../uni_modules/uview-plus/libs/config/props/parse';
  352. import {
  353. LiveWS
  354. } from '@/utils/liveWS.js'
  355. import {
  356. getlive,
  357. gettextlist,
  358. getAnswerlist,
  359. submitAnswer
  360. } from '@/api/home'
  361. // var wsUrl = "ws://192.168.10.166:17114/app/webSocket";
  362. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  363. var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  364. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  365. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  366. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  367. var pingpangTimes = null;
  368. var initTimes = null;
  369. var isSocketOpen = false;
  370. var socket = null;
  371. export default {
  372. data() {
  373. return {
  374. boxHeight: 300, //小黄车高度
  375. isFollow: true,
  376. liveViewData: {},
  377. liveViewers: [], //观众
  378. likeName: 0,
  379. hlsPlayer: null, // HLS播放器实例,
  380. livingUrl: "",
  381. products: {},
  382. store: {},
  383. orderUser: {}, //正在购买
  384. userType: 0,
  385. timestamp: '',
  386. liveId: null,
  387. // userId: uni.getStorageSync("userInfo.userId"),
  388. livedata: {},
  389. codeimg: '',
  390. placeholderText: '说点什么...',
  391. isZoom: false, //点赞按钮控制是否放大
  392. userinfo: '', //用户信息
  393. // path: 'http://192.168.10.166/dev-api', //余红奇
  394. path: 'http://v56c9b8e.natappfree.cc', //余红奇
  395. // path: 'http://192.168.10.170/dev-api', //陈果
  396. value: '',
  397. talkdisabled: false, //输入框是否禁用
  398. autoplay: false, //视频自动播放
  399. showadd: false,
  400. talklist: [],
  401. scrollIntoView: '',
  402. bufferRate: 0, //视频缓冲时间
  403. playDuration: 0, //视频播放时间
  404. videoContext: '',
  405. thistime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
  406. upDown: true, //是否视频显示隐藏
  407. isLongPress: false, // 是否长按
  408. timeout: null, // 计时器
  409. showWelcomeMessage: false,
  410. isSubmit: false,
  411. messageContent: "",
  412. showziliao: false,
  413. isScreen: true,
  414. showAnswer: false, //展示答题
  415. Answerlistall: {}, //所有题目
  416. answerlist: {}, //当前题目
  417. answerfrist: 0, //当前选择
  418. checkboxValue: [], //多选数据
  419. checkboxFormValue: "", //多选数据
  420. allAnswerLists: [], // 新增:存储所有题目列表
  421. showAnswerred: false, //展示红包答题
  422. answerbtn: false, //答题按钮弹窗
  423. redallAnswerLists: [], //储存所有红包答题列表
  424. redanswerAll: [], //红包当前题目
  425. redanswerList: [], //红包答题列表
  426. redanswertips: [], //红包答题提示
  427. shopping: false, //小黄车弹窗
  428. scrollTop: 0, //弹幕
  429. old: {
  430. scrollTop: 0
  431. },
  432. liveData: {}, //直播间点赞、关注、在线人数数据
  433. // shopList: [{
  434. // title: '史士昊老师四神汤健脾消食疗法',
  435. // details: '看它来喘口气,小小震撼,',
  436. // people: '45708 '
  437. // },{
  438. // title: '史士昊老师四神汤健脾消食疗法',
  439. // details: '看它来喘口气,小小震撼,',
  440. // people: '45708 '
  441. // }],
  442. // chatList: [{
  443. // lable: '达人',
  444. // name: '锅巴',
  445. // txt: '中医调节身体确实'
  446. // },
  447. // {
  448. // lable: '',
  449. // name: '从芯开始',
  450. // txt: '来了'
  451. // }
  452. // {
  453. // lable: '',
  454. // name: '北京的帅小伙:',
  455. // txt: '来了来了,上茶'
  456. // },
  457. // {
  458. // lable: '',
  459. // name: '萍萍',
  460. // txt: '来了'
  461. // }
  462. // ]
  463. };
  464. },
  465. onLoad(options) {
  466. if (options.liveId) {
  467. this.liveId = options.liveId;
  468. // this.liveId = decodeURIComponent(options.liveId);
  469. console.log("接收到的liveId:", this.liveId);
  470. }
  471. },
  472. computed: {
  473. filteredViewers() {
  474. // 只返回前3项(索引0、1、2)
  475. return this.liveViewers.slice(0, 3);
  476. }
  477. },
  478. // computed: {
  479. // userId() {
  480. // return this.$store.state.user.userId
  481. // }
  482. // },
  483. mounted() {
  484. // this.onLike()
  485. this.getliveViewData() ////直播间点赞、关注、在线人数数据
  486. this.intervalId = setInterval(() => {
  487. this.getliveViewData();
  488. }, 60 * 1000);
  489. // this.getLiveinformation() // 获取直播间信息接口
  490. this.getliveOrder() //正在购买
  491. this.getliveStore() // 获取小黄车 店铺展示
  492. // this.getliveGoods() // 获取小黄车 商品详情
  493. this.getliveUser() // 获取直播间用户
  494. this.initTime()
  495. // this.initWebSocket()
  496. this.initSocket()
  497. var that = this;
  498. uni.$on('initSocket', () => {
  499. that.initSocket()
  500. })
  501. uni.$on('sendMsg', (item) => {
  502. that.sendMsg(item)
  503. })
  504. uni.$on('closeWebSocket', () => {
  505. that.closeWebSocket()
  506. })
  507. this.getEWechatSdk();
  508. this.getliving() //hls
  509. this.gettalklist()
  510. // this.getAnswerlists()
  511. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  512. },
  513. onReady: function(res) {
  514. this.videoContext = uni.createVideoContext('myVideo')
  515. // console.log(this.videoContext)
  516. },
  517. onUnload() {
  518. // 销毁HLS播放器
  519. if (this.hlsPlayer) {
  520. this.hlsPlayer.destroy();
  521. this.hlsPlayer = null;
  522. }
  523. },
  524. methods: {
  525. goStore() {
  526. uni.navigateTo({
  527. url: '/pages_shop/store?liveId=' + this.liveId
  528. })
  529. // uni.navigateTo({
  530. // url: "/pages_shop/store"
  531. // })
  532. },
  533. // 去订单列表
  534. goOrderList() {
  535. uni.navigateTo({
  536. url: "/pages_shop/order"
  537. })
  538. },
  539. // 初始化HLS播放器
  540. initHlsPlayer() {
  541. if (Hls.isSupported() && this.livingUrl) {
  542. const video = document.getElementById('myVideo');
  543. if (video) {
  544. this.hlsPlayer = new Hls();
  545. this.hlsPlayer.loadSource(this.livingUrl);
  546. this.hlsPlayer.attachMedia(video);
  547. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  548. video.play();
  549. });
  550. }
  551. }
  552. },
  553. // 视频错误处理
  554. videoError(e) {
  555. console.error('视频播放错误:', e.detail.errMsg);
  556. // 尝试重新加载或切换到备用流
  557. if (this.livingUrl) {
  558. setTimeout(() => {
  559. this.videoContext.play();
  560. }, 2000);
  561. }
  562. },
  563. getliving() {
  564. const param = {
  565. id: this.liveId
  566. }
  567. getlive(param).then(res => {
  568. if (res.code == 200) {
  569. this.livedata = res.data
  570. // this.codeimg = res.data.qwQrCode
  571. this.livingUrl = res.data.livingUrl; // 确保设置livingUrl
  572. // 检查是否是HLS流
  573. if (this.livingUrl && this.livingUrl.indexOf('.m3u8') > -1) {
  574. // 在H5平台初始化HLS播放器
  575. // #ifdef H5
  576. this.initHlsPlayer();
  577. // #endif
  578. // 其他平台(App、小程序)原生支持HLS
  579. this.$nextTick(() => {
  580. if (this.videoContext) {
  581. this.videoContext.play();
  582. }
  583. });
  584. } else {
  585. // 非HLS流正常播放
  586. if (this.livedata.liveType == 1) {
  587. this.autoplay = true
  588. this.livingUrl=res.videoUrl
  589. this.videoContext.seek(this.livedata.nowDuration)
  590. } else if(this.livedata.liveType == 2) {
  591. this.autoplay = true
  592. this.getLiveinformation()
  593. // this.livingUrl=res.livingUrl
  594. } else {
  595. this.autoplay = false
  596. this.placeholderText = "直播开始才能发言讨论"
  597. this.talkdisabled = true
  598. }
  599. }
  600. } else {
  601. uni.showToast({
  602. title: res.msg,
  603. icon: 'none',
  604. duration: 2000
  605. });
  606. }
  607. })
  608. },
  609. maskString(str, maskChar = '*') {
  610. // 新增:如果str是undefined或null,直接返回空字符串
  611. if (!str) return '';
  612. // 确保str是字符串(如果是数字等类型,先转为字符串)
  613. const strVal = String(str);
  614. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  615. },
  616. getPureDecimal(num, precision = 6) {
  617. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  618. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  619. },
  620. // 返回上一个页面并关闭WebSocket
  621. goBack() {
  622. uni.navigateBack();
  623. closeWebSocket();
  624. },
  625. // // 收藏商品
  626. // collectProducts(){
  627. // },
  628. //直播间点赞、关注、在线人数数据
  629. getliveViewData() {
  630. getLiveViewData(this.liveId).then(res => {
  631. if (res.code == 200) {
  632. // console.log("直播间点赞、关注、在线人数数据>>>>", res)
  633. this.liveViewData = res
  634. } else {
  635. uni.showToast({
  636. title: res.msg,
  637. icon: 'none'
  638. });
  639. }
  640. },
  641. rej => {}
  642. );
  643. },
  644. //正在购买
  645. getliveOrder() {
  646. liveOrderUser(this.liveId).then(res => {
  647. if (res.code == 200) {
  648. console.log("正在购买>>>>", res)
  649. this.orderUser = res
  650. } else {
  651. uni.showToast({
  652. title: res.msg,
  653. icon: 'none'
  654. });
  655. }
  656. },
  657. rej => {}
  658. );
  659. },
  660. //小黄车 店铺展示
  661. getliveStore() {
  662. let data = {
  663. pageSize: 10,
  664. page: 1
  665. }
  666. liveStore(this.liveId, data).then(res => {
  667. if (res.code == 200) {
  668. console.log("小黄车 店铺展示>>>>", res)
  669. this.products = res.data
  670. // this.store = res.store
  671. } else {
  672. uni.showToast({
  673. title: res.msg,
  674. icon: 'none'
  675. });
  676. }
  677. },
  678. rej => {}
  679. );
  680. },
  681. // 获取直播间信息接口
  682. getLiveinformation() {
  683. getLiveInfo(this.liveId).then(res => {
  684. if (res.code == 200) {
  685. console.log("获取直播间信息接口>>>>", res)
  686. this.livingUrl = res.livingUrl
  687. } else {
  688. uni.showToast({
  689. title: res.msg,
  690. icon: 'none'
  691. });
  692. }
  693. },
  694. rej => {}
  695. );
  696. },
  697. // 获取直播间用户
  698. getliveUser() {
  699. getRecentLiveViewers(this.liveId).then(res => {
  700. if (res.code == 200) {
  701. console.log("获取直播间用户>>>>", res)
  702. this.liveViewers = res.recentLiveViewers
  703. } else {
  704. uni.showToast({
  705. title: res.msg,
  706. icon: 'none'
  707. });
  708. }
  709. },
  710. rej => {}
  711. );
  712. },
  713. // 点赞
  714. onLike() {
  715. liveDataLike(this.liveId).then(res => {
  716. if (res.code == 200) {
  717. if (
  718. typeof res.msg === 'number' || (typeof res.msg === 'string' && /^\d+$/.test(res.msg
  719. .trim()))
  720. ) {
  721. this.liveData++
  722. } else {
  723. uni.showToast({
  724. title: res.msg,
  725. icon: 'none'
  726. });
  727. }
  728. } else {
  729. uni.showToast({
  730. title: res.msg,
  731. icon: 'none'
  732. });
  733. }
  734. },
  735. rej => {}
  736. );
  737. },
  738. // 去购买,跳商品详情
  739. goShop(item) {
  740. console.log("去购买,跳商品详情", item)
  741. uni.navigateTo({
  742. url: '/pages_shop/goods?productId=' + item + '&liveId=' + this.liveId
  743. })
  744. },
  745. // 收藏
  746. onCollect(item) {
  747. console.log("item>>>", item.productId)
  748. uni.setStorageSync("storeId", storeId);
  749. let data = {
  750. liveId: this.liveId,
  751. productId: item.productId,
  752. storeId: this.store.storeId
  753. }
  754. collectStore(data).then(res => {
  755. if (res.code == 200) {
  756. console.log("收藏lcollectStore>>>>", res)
  757. } else {
  758. uni.showToast({
  759. title: res.msg,
  760. icon: 'none'
  761. });
  762. }
  763. },
  764. rej => {}
  765. );
  766. },
  767. // 关注
  768. onFollow() {
  769. follow(this.liveId).then(res => {
  770. this.isFollow = !this.isFollow
  771. uni.showToast({
  772. title: res.msg,
  773. icon: 'none'
  774. });
  775. },
  776. rej => {}
  777. );
  778. },
  779. initTime() {
  780. const now = new Date();
  781. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  782. // 或者使用其他格式化方法,例如:
  783. // this.currentTime = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
  784. },
  785. // initWebSocket() {
  786. // const liveWS = new LiveWS('ws://your-server.com', 123, 456);
  787. // // 从 URL 中解析 timestamp
  788. // const urlParams = new URL(liveWS.url).searchParams;
  789. // this.timestamp = urlParams.get('timestamp');
  790. // // console.log('Timestamp:', timestamp);
  791. // },
  792. // 弹幕滚动
  793. lowerChat: function(e) {
  794. console.log(e)
  795. },
  796. scroll: function(e) {
  797. console.log(e)
  798. this.old.scrollTop = e.detail.scrollTop
  799. },
  800. loadmore() {
  801. // for (let i = 0; i < 30; i++) {
  802. // this.indexList.push({
  803. // url: this.shopList[uni.$u.random(0, this.shopList.length - 1)],
  804. // });
  805. // }
  806. },
  807. // 弹幕
  808. scrollchat() {
  809. // this.loadmore();
  810. },
  811. noredanswer() {
  812. if (this.Answerlistall > 0) {
  813. this.showAnswer = !this.this.showAnswer
  814. } else {
  815. uni.showToast({
  816. title: '暂无题目',
  817. icon: 'none',
  818. });
  819. }
  820. },
  821. redbagAnswer() {
  822. this.showAnswerred = !this.showAnswerred
  823. this.answerbtn = !this.answerbtn
  824. },
  825. submitAnswers() {
  826. if (this.isSubmit) return;
  827. this.isSubmit = true;
  828. const data = {
  829. questionId: this.answerlist.id,
  830. answer: this.checkboxFormValue
  831. }
  832. submitAnswer(data).then(res => {
  833. if (res.code == 200) {
  834. uni.showToast({
  835. title: res.msg,
  836. icon: 'none',
  837. });
  838. }
  839. // 本地切换下一题
  840. if (this.answerfrist < this.Answerlistall - 1) {
  841. this.answerfrist++;
  842. this.answerlist = this.allAnswerLists[this.answerfrist];
  843. this.answerlist.content = JSON.parse(this.answerlist.content);
  844. } else {
  845. uni.showToast({
  846. title: '已是最后一题',
  847. icon: 'none'
  848. });
  849. this.showAnswer = false; // 自动关闭弹窗
  850. }
  851. this.checkboxValue = []
  852. this.checkboxFormValue = "";
  853. uni.showToast({
  854. title: res.msg,
  855. icon: 'none'
  856. });
  857. }).finally(e => {
  858. this.isSubmit = false;
  859. })
  860. },
  861. handleCheckboxSelect(value) {
  862. const index = this.checkboxValue.indexOf(value)
  863. console.log(value)
  864. if (this.answerlist.type == 1) {
  865. this.checkboxValue = [value]
  866. this.checkboxFormValue = this.checkboxValue.join(',')
  867. // setTimeout(() => {
  868. // uni.showToast({
  869. // title: '准备下一题',
  870. // icon: 'none',
  871. // duration: 2000
  872. // });
  873. // }, 1000);
  874. this.submitAnswers()
  875. console.log(this.checkboxValue)
  876. } else if (this.answerlist.type == 2) {
  877. if (index > -1) {
  878. this.checkboxValue.splice(index, 1)
  879. this.checkboxFormValue = this.checkboxValue.join(',')
  880. } else {
  881. this.checkboxValue.push(value)
  882. this.checkboxFormValue = this.checkboxValue.join(',')
  883. }
  884. console.log(this.checkboxFormValue)
  885. }
  886. },
  887. getAnswerlists() {
  888. console.log(123)
  889. const data = {
  890. liveId: this.liveId
  891. }
  892. getAnswerlist(data).then(res => {
  893. if (res.code == 200) {
  894. if (res.data.length > 0) {
  895. this.allAnswerLists = res.data; // 存储所有题目
  896. this.Answerlistall = res.data.length;
  897. if (this.allAnswerLists.length > 0) {
  898. this.answerlist = this.allAnswerLists[0];
  899. this.answerlist.content = JSON.parse(this.allAnswerLists[0].content);
  900. }
  901. this.showAnswer = true
  902. } else {
  903. this.showAnswer = false
  904. }
  905. }
  906. })
  907. },
  908. gettalklist() {
  909. const param = {
  910. id: this.liveId
  911. }
  912. gettextlist(param).then(res => {
  913. if (res.code == 200) {
  914. this.talklist = res.data
  915. // console.log(res.data);
  916. this.$nextTick(() => {
  917. this.scrollIntoView = `list_${this.talklist.length-1}`
  918. })
  919. }
  920. })
  921. },
  922. open() {
  923. },
  924. close() {
  925. this.showadd = !this.showadd
  926. },
  927. closes() {
  928. this.showziliao = !this.showziliao
  929. },
  930. closest() {
  931. this.showAnswer = !this.showAnswer
  932. },
  933. closestred() {
  934. this.showAnswerred = !this.showAnswerred
  935. },
  936. closeanswer() {
  937. this.answerbtn = !this.answerbtn
  938. },
  939. // 关闭小黄车
  940. closeshop() {
  941. this.shopping = !this.shopping
  942. },
  943. longPress() {
  944. this.timeout = setTimeout(() => {
  945. this.isLongPress = true;
  946. // 执行保存图片的操作
  947. uni.saveImageToPhotosAlbum({
  948. filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径
  949. success: () => {
  950. uni.showToast({
  951. title: '保存成功'
  952. });
  953. },
  954. fail: () => {
  955. uni.showToast({
  956. title: '',
  957. icon: 'none'
  958. });
  959. }
  960. });
  961. }, 500); // 设置长按的阈值时间,这里是500毫秒
  962. },
  963. cancelLongPress() {
  964. clearTimeout(this.timeout);
  965. this.isLongPress = false;
  966. },
  967. // 触摸开始
  968. handleTouchStart() {
  969. this.isZoom = true; // 触发放大效果
  970. },
  971. // 触摸结束
  972. handleTouchEnd() {
  973. this.isZoom = false; // 恢复原状
  974. },
  975. // getliving() {
  976. // const param = {
  977. // id: this.liveId
  978. // }
  979. // getlive(param).then(res => {
  980. // if (res.code == 200) {
  981. // this.livedata = res.data
  982. // this.codeimg = res.data.qwQrCode
  983. // if (this.livedata.status == 1) {
  984. // this.autoplay = true
  985. // this.videoContext.seek(this.livedata.nowDuration)
  986. // // console.log(this.autoplay)
  987. // } else {
  988. // this.autoplay = false
  989. // this.placeholderText = "直播开始才能发言讨论"
  990. // this.talkdisabled = true
  991. // }
  992. // console.log(this.autoplay)
  993. // } else {
  994. // uni.showToast({
  995. // title: res.msg,
  996. // icon: 'none',
  997. // duration: 2000
  998. // });
  999. // }
  1000. // })
  1001. // },
  1002. getEWechatSdk() {
  1003. // 只在H5平台执行
  1004. // #ifdef H5
  1005. let eWechatSdk = '';
  1006. if (/(Android)/i.test(navigator.userAgent)) {
  1007. eWechatSdk = 'jWeixin';
  1008. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  1009. eWechatSdk = 'wx';
  1010. } else {
  1011. eWechatSdk = 'jWeixin';
  1012. }
  1013. uni.setStorageSync("wxSdk", eWechatSdk);
  1014. // #endif
  1015. },
  1016. closeWebSocket() {
  1017. if (socket != null) {
  1018. uni.closeSocket();
  1019. }
  1020. clearInterval(pingpangTimes)
  1021. },
  1022. reConnect() {
  1023. var that = this;
  1024. try {
  1025. uni.closeSocket();
  1026. } catch (e) {
  1027. }
  1028. setTimeout(function() {
  1029. that.initSocket();
  1030. }, 10000);
  1031. },
  1032. initSocket() {
  1033. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  1034. // console.log("liveId", this.liveId);
  1035. // console.log("userId", this.userinfo.userId);
  1036. // console.log("userType", this.userType);
  1037. // console.log("timestamp", this.timestamp);
  1038. let signature = CryptoJS.HmacSHA256(
  1039. CryptoJS.enc.Utf8.parse(this.liveId.toString() + this.userinfo.userId + this.userType + this
  1040. .timestamp),
  1041. CryptoJS.enc.Utf8.parse(this.timestamp)).toString(CryptoJS.enc.Hex)
  1042. var that = this;
  1043. // console.log("initSocket")
  1044. //创建一个socket连接
  1045. socket = uni.connectSocket({
  1046. // url: wsUrl+"?userId=40486&liveId=2",
  1047. // url: wsUrl + "?userId=" + this.userid + "&liveId=" +
  1048. // this.liveId+"&AppToken="+'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI0IiwiaWF0IjoxNzQwNzIxMDQ1LCJleHAiOjE3NDEzMjU4NDV9.PgS83JTMSJgVFD6vGAhUsEPbS6Az4yMyX8wVug61TZNTB3092CtvANo-AB9ZG4NdSBLgLrf4litM3vvTk-FK0g',
  1049. //
  1050. // url: wsUrl + "?userId=" + this.userId + "&liveId=" + this.liveId + "&AppToken=" + uni
  1051. // .getStorageSync('AppToken'),
  1052. url: wsUrl + "?userId=" + this.userinfo.userId + "&liveId=" + this.liveId + "&userType=" + this
  1053. .userType +
  1054. "&timestamp=" + this.timestamp + "&signature=" + signature,
  1055. multiple: true,
  1056. success: res => {
  1057. //先确保清除了之前的心跳定时器
  1058. clearInterval(pingpangTimes)
  1059. uni.onSocketMessage((res) => {
  1060. if (res.data.code == 500) {
  1061. uni.showToast({
  1062. title: res.data.msg,
  1063. icon: 'none',
  1064. duration: 2000
  1065. });
  1066. }
  1067. const redata = JSON.parse(res.data);
  1068. console.log("WebSocket拿到的东西", redata)
  1069. this.talklist.push(redata.data)
  1070. this.$nextTick(() => {
  1071. this.scrollIntoView = `list_${this.talklist.length-1}`
  1072. })
  1073. if (redata.cmd == 'deleteId') {
  1074. uni.$emit('deleteId');
  1075. } else if (redata.cmd == 'init') {
  1076. uni.$emit('init', redata.data);
  1077. } else if (redata.cmd == 'reload') {
  1078. uni.$emit('reload');
  1079. } else if (redata.data.cmd == 'sendRedPacketQuestion') {
  1080. const list = JSON.parse(redata.data.data)
  1081. this.redanswerAll = [...this.redanswerAll, ...list]
  1082. if (this.redanswerAll[1].randomAmount !== null) {
  1083. this.redanswertips = JSON.parse(this.redanswerAll[0].randomAmount)
  1084. }
  1085. console.log(this.redanswertips)
  1086. console.log(this.redanswerAll)
  1087. } else if (redata.data.cmd == 'entry') {
  1088. this.showWelcomeMessage = true
  1089. // setTimeout(() => {
  1090. // this.showWelcomeMessage = false;
  1091. // }, 1000);
  1092. uni.$emit('entry', redata.data);
  1093. // console.log(redata.data)/
  1094. }
  1095. })
  1096. },
  1097. error: res => {
  1098. uni.$emit('websocket', 0);
  1099. console.log(res)
  1100. },
  1101. })
  1102. //监听socket打开
  1103. uni.onSocketOpen(() => {
  1104. isSocketOpen = true
  1105. console.log('WebSocket连接已打开!!');
  1106. // uni.$emit('websocket',1);
  1107. uni.showToast({
  1108. title: "插件已打开",
  1109. icon: 'none',
  1110. });
  1111. })
  1112. //监听socket关闭
  1113. uni.onSocketClose(() => {
  1114. isSocketOpen = false
  1115. clearInterval(pingpangTimes)
  1116. console.log('WebSocket连接已关闭!');
  1117. // uni.$emit('websocket',0);
  1118. uni.showToast({
  1119. title: "插件离线",
  1120. icon: 'none',
  1121. });
  1122. //重连
  1123. that.reConnect()
  1124. })
  1125. //监听socket错误
  1126. uni.onSocketError(() => {
  1127. isSocketOpen = false
  1128. clearInterval(pingpangTimes)
  1129. console.log('WebSocket连接打开失败');
  1130. // uni.$emit('websocket',0);
  1131. uni.showToast({
  1132. title: "插件离线",
  1133. icon: 'none',
  1134. });
  1135. uni.showModal({
  1136. content: '聊天连接失败是否重新尝试连接',
  1137. success() {
  1138. that.reConnect()
  1139. }
  1140. })
  1141. })
  1142. },
  1143. sendMsg() {
  1144. // this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  1145. if (isSocketOpen) {
  1146. const data = {
  1147. liveId: this.liveId,
  1148. userId: this.userinfo.userId,
  1149. userType: 0,
  1150. cmd: "sendMsg",
  1151. msg: this.value,
  1152. nickName: this.userinfo.nickName,
  1153. avatar: this.userinfo.avatar
  1154. }
  1155. if (this.value == "") {
  1156. uni.showToast({
  1157. title: "不能发送空消息",
  1158. icon: 'none',
  1159. });
  1160. } else {
  1161. socket.send({
  1162. data: JSON.stringify(data),
  1163. success: () => {
  1164. // this.gettalklist()
  1165. console.log("发送成功")
  1166. this.value = ''
  1167. },
  1168. fail: () => {
  1169. console.log("发送失败")
  1170. }
  1171. })
  1172. }
  1173. }
  1174. },
  1175. },
  1176. };
  1177. </script>
  1178. <style scoped lang="scss">
  1179. // 抽奖
  1180. // .answerpop {
  1181. // background: linear-gradient(to right, #fff7f8, #fee1e2);
  1182. // margin-top: 30rpx;
  1183. // padding: 10rpx 20rpx;
  1184. // width: calc(100% - 40rpx);
  1185. // border-radius: 20rpx;
  1186. // display: flex;
  1187. // align-items: center;
  1188. // justify-content: space-between;
  1189. // box-shadow: 2px 2px 4px 0 rgba(255, 124, 126, 0.1);
  1190. // .answera {
  1191. // display: flex;
  1192. // justify-content: center;
  1193. // background-color: #fff;
  1194. // padding: 20rpx 0;
  1195. // width: 35%;
  1196. // border-radius: 40rpx;
  1197. // align-items: center;
  1198. // margin: 10rpx 0;
  1199. // box-shadow: 2px 2px 4px 0 rgba(72, 72, 72, 0.1);
  1200. // image {
  1201. // width: 40rpx;
  1202. // height: 40rpx;
  1203. // margin-right: 10rpx;
  1204. // }
  1205. // }
  1206. // }
  1207. // .submitbtn {
  1208. // width: 260rpx;
  1209. // margin: 0 auto;
  1210. // text-align: center;
  1211. // border-radius: 80rpx;
  1212. // padding: 20rpx 0;
  1213. // color: #fff;
  1214. // background-color: #ff5c03;
  1215. // }
  1216. // .itemanswer {
  1217. // padding: 20rpx 20rpx;
  1218. // text-align: center;
  1219. // border-radius: 80rpx;
  1220. // border: 2rpx solid #dddddd;
  1221. // margin: 12rpx 0;
  1222. // color: #555;
  1223. // width: calc(100% - 40rpx);
  1224. // }
  1225. // .answeract {
  1226. // background-color: rgba(0, 202, 166, 1);
  1227. // color: #fff;
  1228. // }
  1229. // .answerbox {
  1230. // width: 600rpx;
  1231. // border-radius: 20rpx;
  1232. // }
  1233. // .welcome-message {
  1234. // position: fixed;
  1235. // width: 100%;
  1236. // bottom: 120rpx;
  1237. // left: 50%;
  1238. // transform: translateX(-50%);
  1239. // color: white;
  1240. // padding: 10px 20px;
  1241. // border-radius: 20px;
  1242. // animation: fadeOut 1s ease 1s forwards;
  1243. // z-index: 1000;
  1244. // }
  1245. // @keyframes fadeOut {
  1246. // from {
  1247. // opacity: 1;
  1248. // }
  1249. // to {
  1250. // opacity: 0;
  1251. // }
  1252. // }
  1253. // .container {
  1254. // position: relative;
  1255. // width: 100%;
  1256. // height: 100vh;
  1257. // overflow: hidden;
  1258. // }
  1259. // .talktext {
  1260. // border-radius: 8rpx;
  1261. // background-color: rgba(255, 255, 255, 0.1);
  1262. // view {
  1263. // width: 100%;
  1264. // }
  1265. // }
  1266. // .talk-list {
  1267. // border-radius: 30rpx;
  1268. // background-color: rgba(255, 255, 255, 0.1);
  1269. // padding: 10rpx 30rpx;
  1270. // }
  1271. // .zoom-button-active {
  1272. // transform: scale(1.5);
  1273. // }
  1274. // .background-image {
  1275. // position: absolute;
  1276. // top: 0;
  1277. // left: -40rpx;
  1278. // width: 110%;
  1279. // height: 110%;
  1280. // object-fit: cover;
  1281. // filter: blur(20px);
  1282. // z-index: 0;
  1283. // }
  1284. // .background-images {
  1285. // position: absolute;
  1286. // top: 0;
  1287. // left: -40rpx;
  1288. // width: 110%;
  1289. // height: 110%;
  1290. // object-fit: cover;
  1291. // filter: blur(20px);
  1292. // z-index: 6;
  1293. // }
  1294. // .blackbg {
  1295. // position: absolute;
  1296. // top: 0;
  1297. // left: 0;
  1298. // width: 100%;
  1299. // height: 100%;
  1300. // background: rgba(0, 0, 0, 0.7);
  1301. // object-fit: cover;
  1302. // filter: blur(10px);
  1303. // z-index: 1;
  1304. // }
  1305. .content {
  1306. position: relative;
  1307. z-index: 2;
  1308. height: 100%;
  1309. width: 100%;
  1310. top: 0;
  1311. left: 0;
  1312. display: flex;
  1313. flex-direction: column;
  1314. justify-content: space-between;
  1315. .content-top {
  1316. width: 100%;
  1317. margin-top: 150rpx;
  1318. display: flex;
  1319. align-items: center;
  1320. justify-content: space-between;
  1321. padding: 0 24rpx;
  1322. box-sizing: border-box;
  1323. .sum {
  1324. width: 80rpx;
  1325. height: 52rpx;
  1326. background: rgba(0, 0, 0, 0.5);
  1327. border-radius: 26rpx 26rpx 26rpx 26rpx;
  1328. font-size: 24rpx;
  1329. color: #FFFFFF;
  1330. text-align: center;
  1331. line-height: 52rpx;
  1332. }
  1333. }
  1334. .follow-btn {
  1335. padding: 8rpx 16rpx;
  1336. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1337. border-radius: 26rpx;
  1338. font-weight: 500;
  1339. font-size: 26rpx;
  1340. color: #FFFFFF;
  1341. }
  1342. }
  1343. .videolist {
  1344. position: relative;
  1345. }
  1346. .vedio {
  1347. // height: 500rpx;
  1348. height: 100vh;
  1349. /* 占屏幕高度的80% */
  1350. width: 100%;
  1351. background-color: rgba(0, 0, 0, 0.6);
  1352. }
  1353. .videotop {
  1354. width: 100%;
  1355. height: 100%;
  1356. }
  1357. .popup-video {
  1358. position: absolute;
  1359. top: 30%;
  1360. height: 500rpx;
  1361. display: flex;
  1362. flex-direction: column;
  1363. align-items: center;
  1364. justify-content: center;
  1365. width: 100%;
  1366. color: #fff;
  1367. z-index: 9;
  1368. .more {
  1369. background-color: #3280fe;
  1370. border-radius: 80rpx;
  1371. width: 280rpx;
  1372. text-align: center;
  1373. height: 60rpx;
  1374. line-height: 60rpx;
  1375. }
  1376. }
  1377. .icon-bg {
  1378. background-color: rgba(255, 255, 255, 0.2);
  1379. border-radius: 50%;
  1380. width: 72rpx;
  1381. height: 72rpx;
  1382. display: flex;
  1383. justify-content: center;
  1384. align-items: center;
  1385. transition: transform 0.2s ease;
  1386. }
  1387. .list {
  1388. width: 80%;
  1389. margin-bottom: 20rpx;
  1390. animation: xxxawdawd .2s;
  1391. }
  1392. @keyframes xxxawdawd {
  1393. from {
  1394. margin-top: 0rpx;
  1395. opacity: 0;
  1396. }
  1397. to {
  1398. margin-top: 20rpx;
  1399. opacity: 1;
  1400. }
  1401. }
  1402. .shop-prompt {
  1403. position: absolute;
  1404. bottom: 600rpx;
  1405. left: 24rpx;
  1406. padding: 6rpx 20rpx;
  1407. background: rgba(230, 154, 34, 0.7);
  1408. border-radius: 24rpx;
  1409. z-index: 9;
  1410. font-weight: 500;
  1411. font-size: 26rpx;
  1412. color: #FFFFFF;
  1413. }
  1414. .side-group {
  1415. position: absolute;
  1416. top: 30%;
  1417. right: 50rpx;
  1418. z-index: 9;
  1419. display: flex;
  1420. flex-direction: column;
  1421. align-items: center;
  1422. .side-item {
  1423. font-weight: 500;
  1424. font-size: 24rpx;
  1425. color: #FFFFFF;
  1426. margin-bottom: 32rpx;
  1427. text-align: center;
  1428. image {
  1429. width: 72rpx;
  1430. height: 72rpx;
  1431. }
  1432. }
  1433. }
  1434. .shoppop {
  1435. padding: 22rpx 16rpx;
  1436. .shoppop-top {
  1437. display: flex;
  1438. justify-content: space-between;
  1439. align-items: center;
  1440. padding: 0 16rpx 22rpx;
  1441. .search-input {
  1442. width: 414rpx;
  1443. height: 76rpx;
  1444. background: #FFFFFF;
  1445. border-radius: 36rpx;
  1446. margin-left: 20rpx;
  1447. padding: 0 32rpx;
  1448. box-sizing: border-box;
  1449. font-size: 24rpx;
  1450. margin-right: 24rpx;
  1451. }
  1452. .search-top {
  1453. font-size: 18rpx;
  1454. color: #222222;
  1455. }
  1456. }
  1457. .shop-list {
  1458. overflow: hidden;
  1459. .list-item {
  1460. display: flex;
  1461. align-items: center;
  1462. padding: 20rpx 16rpx;
  1463. background: #FFFFFF;
  1464. border-radius: 16rpx;
  1465. margin-bottom: 16rpx;
  1466. .goods-img {
  1467. width: 200rpx;
  1468. height: 200rpx;
  1469. border-radius: 16rpx;
  1470. overflow: hidden;
  1471. position: relative;
  1472. margin-right: 24rpx;
  1473. image {
  1474. width: 100%;
  1475. height: 100%;
  1476. }
  1477. .goods-label {
  1478. position: absolute;
  1479. top: 0;
  1480. width: 64rpx;
  1481. height: 40rpx;
  1482. background: rgba(0, 0, 0, 0.5);
  1483. border-radius: 16rpx 0rpx 16rpx 0rpx;
  1484. text-align: center;
  1485. font-weight: 500;
  1486. font-size: 28rpx;
  1487. color: #FFFFFF;
  1488. }
  1489. }
  1490. .goods-right {
  1491. flex: 1;
  1492. .goods-title {
  1493. font-weight: 500;
  1494. font-size: 28rpx;
  1495. color: #000000;
  1496. }
  1497. .goods-details {
  1498. font-size: 24rpx;
  1499. color: #999999;
  1500. margin: 10rpx 0 20rpx;
  1501. }
  1502. .goods-people {
  1503. font-size: 22rpx;
  1504. color: #E69A22;
  1505. height: 56rpx;
  1506. }
  1507. .goods-shop {
  1508. display: flex;
  1509. justify-content: space-between;
  1510. .nummber {
  1511. color: #FF5C03;
  1512. font-size: 22rpx;
  1513. font-weight: 500;
  1514. }
  1515. .btn-group {
  1516. text-align: center;
  1517. line-height: 56rpx;
  1518. .collect-btn {
  1519. width: 72rpx;
  1520. background: #F5F7FA;
  1521. border-radius: 8rpx 0rpx 0rpx 8rpx;
  1522. }
  1523. .shop-btn {
  1524. width: 152rpx;
  1525. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1526. border-radius: 0rpx 8rpx 8rpx 0rpx;
  1527. font-weight: 500;
  1528. font-size: 26rpx;
  1529. color: #FFFFFF;
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. :deep(.u-list-item) {
  1538. width: 100%;
  1539. display: flex;
  1540. align-items: center;
  1541. }
  1542. </style>