living.vue 47 KB

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