index.html 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. {extend name="public/container"}
  2. {block name="title"}{$live_title}{/block}
  3. {block name="head_top"}
  4. <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.3/skins/default/aliplayer-min.css">
  5. <script src="https://g.alicdn.com/de/prismplayer/2.9.3/aliplayer-min.js"></script>
  6. <script src="{__WAP_PATH}zsff/layer_mobile/layer.js"></script>
  7. <script src="https://g.alicdn.com/de/prismplayer/2.9.3/hls/aliplayer-hls-min.js"></script>
  8. <script>
  9. window.room = {$room};
  10. window.workermanConfig = {$workerman};
  11. window.uids = "{$userInfo['uid']}";
  12. window.socketDebug = true;
  13. </script>
  14. <style>
  15. html,
  16. body,
  17. #app {
  18. height: 100%;
  19. }
  20. .live .chat .item .text .info img.cont {
  21. width: 50%;
  22. }
  23. .preview .layui-m-layercont {
  24. padding: 0;
  25. }
  26. .preview .layui-m-layercont img {
  27. display: block;
  28. width: 100%;
  29. object-fit: scale-down;
  30. }
  31. .loading {
  32. padding-top: .1rem;
  33. padding-bottom: .1rem;
  34. font-size: .28rem;
  35. text-align: center;
  36. color: #999;
  37. }
  38. .loading .fa {
  39. font-size: .4rem;
  40. }
  41. .loaded {
  42. font-size: .28rem;
  43. line-height: .72rem;
  44. text-align: center;
  45. color: #999;
  46. }
  47. .nothing {
  48. position: absolute;
  49. top: 30%;
  50. left: 50%;
  51. width: 4rem;
  52. height: 4rem;
  53. background: url("{__WAP_PATH}zsff/images/nothing.png") center/contain no-repeat;
  54. -webkit-transform: translate(-50%, -50%);
  55. transform: translate(-50%, -50%);
  56. }
  57. .footer{
  58. z-index:10;background-color: #fff;
  59. }
  60. </style>
  61. {/block}
  62. {block name="content"}
  63. <div v-cloak id="app">
  64. <div class="live">
  65. <div :style="{ height: playerHeight + 'px' }" class="header">
  66. <div v-show="liveInfo.is_play || PullUrl" class="prism-player" id="J_prismPlayer"></div>
  67. <div v-show="!liveInfo.is_play && !PullUrl" class="text">
  68. <div>{{ liveText }}</div>
  69. <count-down v-show="!live_status" :day-show="false" :sec-show="false" :time="datatime"></count-down>
  70. </div>
  71. </div>
  72. <div class="nav">
  73. <div :class="{ active: navActive === 0 }" class="item" @click="navActive = 0">聊天</div>
  74. <div :class="{ active: navActive === 1 }" class="item" @click="navActive = 1">课堂</div>
  75. <div :class="{ active: navActive === 2 }" class="item" @click="navActive = 2">推荐</div>
  76. <div :class="{ active: navActive === 3 }" class="item" @click="navActive = 3">排行</div>
  77. </div>
  78. <div ref="main" class="main">
  79. <!-- 聊天 -->
  80. <div v-show="navActive === 0" class="section" @click="emojiKeyboardHide" @scroll="chatScroll">
  81. <div ref="chat" class="chat">
  82. <div class="loading">
  83. <span v-show="Oloading" class="fa fa-spinner"></span>
  84. <div v-if="Oloadend && Opage > 2">已全部加载</div>
  85. </div>
  86. <div v-if="OpenCommentList.length" class="list">
  87. <div v-for="(item, index) in OpenCommentList" :key="index" class="item">
  88. <div class="avatar">
  89. <img :src="item.avatar" class="img">
  90. </div>
  91. <div class="text">
  92. <div class="name" v-text="item.nickname" v-if="item.user_type==2 && user_type == 2">加载中</div>
  93. <div class="name" v-else>
  94. <span v-if="item.user_type==1">[讲师]</span>
  95. <span v-else-if="item.user_type==0">[助教]</span>
  96. <span>{{item.nickname}}</span>
  97. <span class="return" v-if="user_type != 2 && item.uid != 0 " @click="recall(item.id,index)">撤回</span>
  98. </div>
  99. <div class="info" v-if="item.type==1">
  100. <div class="cont" v-html="item.content"></div>
  101. </div>
  102. <div class="info" v-else-if="item.type==2 && item.content">
  103. <img :src="item.content" class="cont" @click="preview(item.content)">
  104. </div>
  105. <div class="info" v-else-if="item.type==3">
  106. <div class="cont" v-if="userInfo.uid == item.uid " @click="play_audio(item,index,'OpenCommentList')">{{item.duration || 0}}’’
  107. <img :src="item.is_play ? '/wap/first/zsff/images/signal2.gif':'/wap/first/zsff/images/signal.png'" class="signal signalR" style="margin-left:0.27rem;cursor: pointer">
  108. </div>
  109. <div class="conter acea-row row-middle" v-else @click="play_audio(item,index,'OpenCommentList')">
  110. <img :src="item.is_play ? '/wap/first/zsff/images/signal2.gif':'/wap/first/zsff/images/signal.png'" class="signal" style="margin-left:0.27rem;cursor: pointer;">{{item.duration || 0}}’’
  111. </div>
  112. <div class="spot" v-if="item.is_play"></div>
  113. </div>
  114. <div v-else-if="item.type === 4" class="info">
  115. <div class="cont">{{ item.content }}{{ item.gift_name }}<img :src="item.gift_image">×{{ item.gift_num }}</div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <!-- 课堂 -->
  123. <div v-show="navActive === 1" class="section class" @click="emojiKeyboardHide">
  124. <div ref="lesson" class="chat">
  125. <div class="load">
  126. <span v-show="loading==true" class="fa fa-spinner"></span>
  127. <span v-text="loadTitle" @click="getCommentList">点击加载更多</span>
  128. </div>
  129. <div class="list">
  130. <div v-for="(item, index) in CommentList" :key="index" class="item">
  131. <div class="avatar">
  132. <img :src="item.avatar" class="img">
  133. </div>
  134. <div class="text">
  135. <div class="name" v-text="item.nickname" v-if="item.user_type==2 && user_type == 2">加载中</div>
  136. <div class="name" v-else>
  137. <span v-if="item.user_type==1">[讲师]</span>
  138. <span v-else-if="item.user_type==0">[助教]</span>
  139. <span>{{item.nickname}}</span>
  140. <span class="return" v-if="user_type != 2 && item.uid != 0" @click="recall(item.id,index)">撤回</span>
  141. </div>
  142. <div class="info" v-if="item.type==1">
  143. <div class="cont" v-html="item.content"></div>
  144. </div>
  145. <div class="info" v-else-if="item.type==2 && item.content">
  146. <img :src="item.content" class="cont" @click="preview(item.content)">
  147. </div>
  148. <div class="info" v-else-if="item.type==3">
  149. <div class="cont" v-if="userInfo.uid == item.uid " @click="play_audio(item,index,'CommentList')">
  150. {{item.duration || 0}}’’
  151. <img :src="item.is_play ? '/wap/first/zsff/images/signal2.gif':'/wap/first/zsff/images/signal.png'" class="signal signalR" style="margin-left:0.27rem;cursor: pointer;">
  152. </div>
  153. <div class="cont" v-else @click="play_audio(item,index,'CommentList')">
  154. <img :src="item.is_play ? '/wap/first/zsff/images/signal2.gif':'/wap/first/zsff/images/signal.png'" class="signal" style="margin-left:0.27rem;cursor: pointer;">{{item.duration || 0}}’’
  155. </div>
  156. <div class="spot" v-if="item.is_play"></div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <!-- 推荐 -->
  164. <div v-show="navActive === 2" class="section recom">
  165. <div class="list">
  166. <div v-for="(item, index) in updateRecomList" :key="item.id" class="item">
  167. <div class="image">
  168. <div class="tag">{{ item.gfake_type ? '商品' : '专题' }}</div>
  169. <img :src="item.image" class="img">
  170. </div>
  171. <div class="text">
  172. <div class="name">{{ item.title }}</div>
  173. <div class="label">
  174. <div v-for="(itm, idx) in item.label" :key="idx" class="cell">{{ itm }}</div>
  175. </div>
  176. <div class="money">
  177. <div class="sell">¥<span class="num">{{ item.money }}</span></div>
  178. </div>
  179. <a :href="$h.U({c: 'special', a: 'details', q: {id: item.id}})" v-if="item.gfake_type==0" class="link">去订购</a>
  180. <a :href="$h.U({c: 'store', a: 'detail', q: {id: item.id}})" v-else class="link">去订购</a>
  181. </div>
  182. </div>
  183. </div>
  184. <div v-show="loadings" class="loading">
  185. <span class="fa fa-spinner"></span>
  186. </div>
  187. <div v-if="!loadings && !recomList.length" class="nothing"></div>
  188. </div>
  189. <!-- 排行 -->
  190. <div v-show="navActive === 3" class="section rank">
  191. <div v-if="rankList.length" class="list">
  192. <template v-for="(item, index) in rankList">
  193. <div v-if="item.uid === userInfo.uid" :key="index" class="item">
  194. <div class="type">
  195. <img v-if="index === 0" src="{__WAP_PATH}zsff/images/medal01.png" class="img">
  196. <img v-else-if="index === 1" src="{__WAP_PATH}zsff/images/medal02.png" class="img">
  197. <img v-else-if="index === 2" src="{__WAP_PATH}zsff/images/medal03.png" class="img">
  198. <template v-else>{{ index + 1 }}</template>
  199. </div>
  200. <div class="image">
  201. <img :src="item.avatar ? item.avatar : '{__WAP_PATH}zsff/images/avatar_default.png'" class="img">
  202. </div>
  203. <div class="name">{{ item.nickname }}</div>
  204. <div :style="{ backgroundImage: 'url(' + goldInfo.gold_image + ')' }" class="num">{{ item.total_price }}</div>
  205. </div>
  206. </template>
  207. </div>
  208. <div v-if="rankList.length" class="list">
  209. <div v-for="(item, index) in rankList" :key="index" class="item">
  210. <div class="type">
  211. <img v-if="index === 0" src="{__WAP_PATH}zsff/images/medal01.png" class="img">
  212. <img v-else-if="index === 1" src="{__WAP_PATH}zsff/images/medal02.png" class="img">
  213. <img v-else-if="index === 2" src="{__WAP_PATH}zsff/images/medal03.png" class="img">
  214. <template v-else>{{ index + 1 }}</template>
  215. </div>
  216. <div class="image">
  217. <img :src="item.avatar ? item.avatar : '{__WAP_PATH}zsff/images/avatar_default.png'" class="img">
  218. </div>
  219. <div class="name">{{ item.nickname }}</div>
  220. <div :style="{ backgroundImage: 'url(' + goldInfo.gold_image + ')' }" class="num">{{ item.total_price }}</div>
  221. </div>
  222. </div>
  223. <div v-show="loadings" class="loading">
  224. <span class="fa fa-spinner"></span>
  225. </div>
  226. <div v-if="!loadings && !rankList.length" class="nothing"></div>
  227. </div>
  228. <!-- 欢迎语 -->
  229. <div :class="{ on: notice }" class="welcome"><span class="name">{{ notice }}</span> 直播间</div>
  230. <!-- 在线人数 -->
  231. <div v-show="2 > navActive" ref="online" class="online">{{ UserSum }} 人</div>
  232. <!-- 右侧按钮 -->
  233. <div v-show="2 > navActive" ref="menu" class="side-menu">
  234. <button v-show="navActive === 1" class="btn barrage-btn" type="button" @click="barrage = !barrage">
  235. <img :src="barrage ? '{__WAP_PATH}zsff/images/barrage1.png' : '{__WAP_PATH}zsff/images/barrage2.png'">
  236. </button>
  237. <button v-show="giftList.length" class="btn" type="button" @click="giftShow = true">
  238. <img class="img" src="{__WAP_PATH}zsff/images/gift1.png">
  239. </button>
  240. </div>
  241. <!-- 礼物特效 -->
  242. <div v-if="giftFloat" :class="{ on: giftFloat }" class="gift-float">
  243. <div class="cont">
  244. <div :style="{ backgroundImage: 'url(' + giftFloat.user_avatar + ')' }" class="avatar"></div>
  245. <div class="text">
  246. <div class="name">{{ giftFloat.username }}</div>
  247. 送出 {{ giftFloat.gift.live_gift_name }}
  248. </div>
  249. <div :style="{ backgroundImage: 'url(' + giftFloat.gift.live_gift_show_img + ')' }" class="image"></div>
  250. </div>
  251. <div class="num">×{{ giftFloat.live_gift_num }}</div>
  252. </div>
  253. <!-- 弹幕 -->
  254. <div v-show="navActive === 1" ref="barrage" :class="{ on: barrage }" :style="{ top: barrageTop + 'px', bottom: barrageTottom + 10 + 'px' }" class="barrage">
  255. <div class="item acea-row row-middle row-right" v-for="item in BarrageList">
  256. <div class="text" v-html="item.content" v-if="item.type!=2"></div>
  257. <div class="text" v-else>
  258. <img :src="item.content" alt="" style="width: 1.5rem;height: auto;">
  259. </div>
  260. <div class="pictrue">
  261. <img :src="item.avatar">
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. <div v-show="2 > navActive" class="footer">
  267. <!-- 输入 -->
  268. <div class="control">
  269. <button class="button" type="button" @click="emoticon">
  270. <img class="img" :src="emojiShow ? '{__WAP_PATH}zsff/images/keyboard.png' : '{__WAP_PATH}zsff/images/face.png'">
  271. </button>
  272. <button v-if="user_type == 0 || user_type == 1" class="button" type="button" @click="push">
  273. <img class="img" src="{__WAP_PATH}zsff/images/plus.png">
  274. </button>
  275. <form class="form" @submit.prevent="push">
  276. <input ref="input" v-model="content" class="text" type="text">
  277. <input v-show="content" class="submit" type="submit" value="">
  278. </form>
  279. </div>
  280. <!-- 表情包 -->
  281. <div v-show="emojiShow" id="emoji" class="swiper-container">
  282. <div class="swiper-wrapper">
  283. <div v-for="(item, index) in emojiList" :key="index" class="swiper-slide">
  284. <button v-for="(itm, idx) in item" :key="idx" class="button" type="button">
  285. <img :src="itm.url" class="img" @click="mine(itm)">
  286. </button>
  287. <button class="button" type="button" @click="delEmoji">
  288. <img class="img" src="{__WAP_PATH}zsff/images/del.png">
  289. </button>
  290. </div>
  291. </div>
  292. <div id="emoji-pagination" class="swiper-pagination"></div>
  293. </div>
  294. </div>
  295. <!-- 打赏 -->
  296. <div :class="{ mask: giftShow }" @click="giftShow = false"></div>
  297. <div v-show="giftShow" class="gift-wrapper">
  298. <div id="gift" class="swiper-container gift">
  299. <div class="swiper-wrapper">
  300. <div v-for="(item, index) in updateGiftList" :key="index" class="swiper-slide">
  301. <div v-for="(itm, idx) in item" :key="itm.id" :class="{ on: idx === giftIndexOn }" class="item" @click="giftIndexOn = idx; giftOn = itm">
  302. <div class="image">
  303. <img :src="itm.live_gift_show_img" class="img">
  304. </div>
  305. <div class="name">{{ itm.live_gift_name }}</div>
  306. <div :style="{ backgroundImage: 'url(' + goldInfo.gold_image + ')' }" class="num">{{ itm.live_gift_price }}</div>
  307. </div>
  308. </div>
  309. </div>
  310. <div v-show="updateGiftList.length > 1" id="gift-pagination" class="swiper-pagination"></div>
  311. </div>
  312. <div class="foot">
  313. <a :href="$h.U({c: 'special', a: 'recharge_index'}) + '?from=live&stream_name=' + liveInfo.stream_name + '&record_id=' + recordId" class="text-group">
  314. <span v-if="userInfo.gold_num" :style="{ backgroundImage: 'url(' + goldInfo.gold_image + ')' }" class="number">{{ userInfo.gold_num }}</span>
  315. <span v-else>充值</span>
  316. <span class="knowledge iconxiangyou"></span>
  317. </a>
  318. <div class="button-group">
  319. <button class="button select" type="button" @click="giftSelectShow = !giftSelectShow">
  320. {{ giftNumSelected }}<span :class="['knowledge', giftSelectShow ? 'iconxiangxia' : 'iconxiangshang']"></span>
  321. <ul v-show="giftSelectShow" class="list">
  322. <li v-for="(item, index) in giftOn.live_gift_num" :key="item" @click.prevent="giftNumSelected = item">{{ item }}</li>
  323. </ul>
  324. </button>
  325. <button class="button post" type="button" @click="giveGift">赠送</button>
  326. </div>
  327. </div>
  328. </div>
  329. </div>
  330. <shortcut></shortcut>
  331. </div>
  332. <script charset="utf-8" type="text/javascript" src="{__WAP_PATH}zsff/js/WebSocket.js"></script>
  333. <script>
  334. var liveInfo = {$liveInfo},
  335. PullUrl = '{$PullUrl? $PullUrl: ""}',
  336. datatime = {$datatime},
  337. phone_type = {$phone_type},
  338. isWechat = {$isWechat? 'true' : 'false'},
  339. userInfo = {:json_encode($userInfo)},
  340. live_status = {$live_status},
  341. user_type = {$user_type},
  342. OpenCommentCount = {$OpenCommentCount},
  343. CommentCount = {$CommentCount},
  344. OpenCommentTime = {$OpenCommentTime? $OpenCommentTime : 0},
  345. CommentTime = {$CommentTime? $CommentTime : 0},
  346. is_ban = {$is_ban},
  347. UserSum = {$UserSum},
  348. goldInfo = {$goldInfo};
  349. </script>
  350. <script>
  351. require(['vue', 'store', 'helper', '{__WAP_PATH}zsff/face/emoji.js', '{__WAP_PATH}zsff/js/countdown.js', '{__WAP_PATH}zsff/js/shortcut.js'], function (Vue, store, $h, emoji) {
  352. var vm = new Vue({
  353. el: '#app',
  354. data: {
  355. windowWidth: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
  356. bottom: '',
  357. phone_type: phone_type,
  358. UserSum: UserSum,
  359. isWechat: isWechat,
  360. OpenCommentCount: OpenCommentCount,
  361. user_type: user_type,
  362. userInfo: userInfo,
  363. barrage: true,
  364. discuss: false,
  365. datatime: datatime,
  366. voice: false,
  367. speak: '按住 说话',
  368. recording: false,
  369. is_ban: is_ban,
  370. live_error: '',
  371. liveInfo: liveInfo,
  372. PullUrl: PullUrl,
  373. player: null,
  374. //讲师助教区域
  375. CommentList: [],
  376. //弹幕列表
  377. BarrageList: [],
  378. //展开的评论区域列表
  379. OpenCommentList: [],
  380. loading: false,
  381. loadend: false,
  382. loadTitle: '点击加载更多',
  383. Oloading: false,
  384. Oloadend: false,
  385. // OloadTitle: '点击加载更多',
  386. content: '',
  387. live_status: live_status,
  388. layerIndex: null,
  389. page: 1,
  390. limit: 16,
  391. Olimit: 7,
  392. Opage: 1,
  393. cd: 3,
  394. is_SendOut: true,
  395. isAnimate: false,//是否回到底部
  396. starttime: 0,
  397. endtime: 0,
  398. timeEnd: 60,
  399. autoCloseRecord: null,
  400. notice: '',
  401. emojiList: emoji,
  402. emojiShow: false,
  403. giftList: [],
  404. giftIndexOn: 0,
  405. giftOn: {},
  406. giftSelectShow: false,
  407. giftShow: false,
  408. giftNumSelected: 1,
  409. giftFloat: null,
  410. goldInfo: goldInfo,
  411. recomList: [],
  412. rankList: [],
  413. navActive: 0,
  414. loadings: false,
  415. barrageTop: 0,
  416. barrageTottom: 0
  417. },
  418. computed: {
  419. playerHeight: function () {
  420. return Math.floor(this.windowWidth * 9 / 16);
  421. },
  422. liveText: function () {
  423. switch (this.live_status) {
  424. case 0:
  425. return '直播即将开始';
  426. break;
  427. case -1:
  428. case 1:
  429. return '讲师离开一会~马上回来';
  430. break;
  431. case 2:
  432. return '直播已结束';
  433. break;
  434. }
  435. },
  436. updateGiftList: function () {
  437. var that = this,
  438. list = that.giftList,
  439. listLen = list.length,
  440. slideLen = listLen % 8 ? Math.floor(listLen / 8 + 1) : listLen / 8,
  441. index = 0,
  442. temp = [],
  443. arr = [];
  444. for (index = 0; index < slideLen; index++) {
  445. temp = list.slice(index * 8, index * 8 + 8);
  446. arr.push(temp);
  447. }
  448. return arr;
  449. },
  450. updateRecomList: function () {
  451. var that = this;
  452. return that.recomList.map(function (value) {
  453. if (typeof value.label === 'string') {
  454. value.label = JSON.parse(value.label);
  455. }
  456. if (that.userInfo.level && value.member_pay_type) {
  457. value.money = value.member_money;
  458. }
  459. return value;
  460. });
  461. }
  462. },
  463. watch: {
  464. giftIndexOn: function () {
  465. this.giftSelectShow = false;
  466. },
  467. notice: function (value) {
  468. var that = this;
  469. if (!value) {
  470. return;
  471. }
  472. setTimeout(function () {
  473. that.notice = '';
  474. }, 1500);
  475. },
  476. giftFloat: function (value) {
  477. var that = this;
  478. if (!value) {
  479. return;
  480. }
  481. setTimeout(function () {
  482. that.giftFloat = null;
  483. }, 2000);
  484. },
  485. CommentList: function () {
  486. if (this.navActive !== 1) {
  487. return;
  488. }
  489. this.contentScroll(this.$refs.lesson);
  490. },
  491. OpenCommentList: function () {
  492. if (this.navActive !== 0) {
  493. return;
  494. }
  495. this.contentScroll(this.$refs.chat);
  496. },
  497. emojiShow: function () {
  498. var dom = this.$refs.lesson;
  499. if (this.navActive === 1) {
  500. dom = this.$refs.chat;
  501. }
  502. this.contentScroll(dom);
  503. },
  504. BarrageList: function () {
  505. this.$nextTick(function () {
  506. this.$refs.barrage.scrollTop = this.$refs.barrage.scrollHeight;
  507. });
  508. },
  509. navActive: function (value) {
  510. switch (value) {
  511. case 1:
  512. this.$nextTick(function () {
  513. this.barrageTottom = this.$refs.main.offsetHeight - this.$refs.menu.offsetTop;
  514. });
  515. break;
  516. case 2:
  517. this.getRecomList();
  518. break;
  519. case 3:
  520. this.getRankList();
  521. break;
  522. }
  523. },
  524. giftList: function () {
  525. this.$nextTick(function () {
  526. this.barrageTottom = this.$refs.main.offsetHeight - this.$refs.menu.offsetTop;
  527. });
  528. }
  529. },
  530. created: function () {
  531. this.recordId = this.getUrlStr('record_id');
  532. },
  533. mounted: function () {
  534. this.$nextTick(function () {
  535. this.barrageTop = this.$refs.online.offsetTop + this.$refs.online.offsetHeight;
  536. this.barrageTottom = this.$refs.main.offsetHeight - this.$refs.menu.offsetTop;
  537. var that = this;
  538. window.addEventListener('resize', function () {
  539. that.windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  540. });
  541. var skinLayoutchildren = [
  542. { name: "progress", align: "blabs", x: 0, y: 44 },
  543. { name: "playButton", align: "tl", x: 15, y: 12 },
  544. { name: "timeDisplay", align: "tl", x: 10, y: 7 },
  545. { name: "setting", align: "tr", x: 15, y: 12 },
  546. { name: "fullScreenButton", align: "tr", x: 10, y: 10 },
  547. { name: "subtitle", align: "tr", x: 15, y: 12 },
  548. { name: "volume", align: "tr", x: 5, y: 10 }
  549. ];
  550. if (this.liveInfo.is_play) {
  551. skinLayoutchildren = [
  552. { name: "liveDisplay", align: "tlabs", x: 15, y: 6 },
  553. { name: "fullScreenButton", align: "tr", x: 10, y: 10 },
  554. { name: "volume", align: "tr", x: 5, y: 10 }
  555. ];
  556. }
  557. if (this.PullUrl || this.liveInfo.is_play) {
  558. this.player = new Aliplayer({
  559. id: 'J_prismPlayer',
  560. width: '100%',
  561. height: '100%',
  562. autoplay: true,
  563. isLive: this.liveInfo.is_play ? true : false,
  564. source: this.PullUrl,
  565. skinLayout: [
  566. { name: "bigPlayButton", align: "cc" },
  567. { name: "errorDisplay", align: "tlabs", x: 0, y: 0 },
  568. { name: "infoDisplay", align: "cc" },
  569. {
  570. name: "controlBar", align: "blabs", x: 0, y: 0,
  571. children: skinLayoutchildren
  572. }
  573. ]
  574. }, function (player) {
  575. console.log('播放器创建好了。')
  576. if (!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) && that.liveInfo.is_play) {
  577. player.on('pause', function () {
  578. player.play()
  579. })
  580. }
  581. });
  582. this.bindEvevt();
  583. }
  584. window.overallShare = false;
  585. mapleWx($jssdk(), function () {
  586. this.onMenuShareAll({
  587. title: that.liveInfo.live_title,
  588. desc: that.liveInfo.abstract,
  589. imgUrl: that.liveInfo.live_image,
  590. link: location.href.indexOf('?') == -1 ?
  591. location.href + '?spread_uid=' + that.userInfo.uid :
  592. location.href + '&spread_uid=' + that.userInfo.uid,
  593. });
  594. });
  595. document.addEventListener('touchstart', function (event) {
  596. var target = event.target;
  597. if (target.classList.contains('preview-img')) {
  598. layer.closeAll();
  599. }
  600. });
  601. $(document).on("change", ".images", function () {
  602. if (this.files.length > 1) return that.msg('您上传的图片不能大与1张');
  603. var file = this.files[0];
  604. if (file) {
  605. var formData = new FormData();
  606. formData.append('file', file);
  607. $.ajax({
  608. url: '{:Url("auth_api/upload")}',
  609. type: 'POST',
  610. data: formData,
  611. contentType: false,
  612. processData: false,
  613. dataType: 'json',
  614. success: function (res) {
  615. console.log(res);
  616. if (res.code == 200) {
  617. that.isAnimate = true;
  618. socket.ws.send('{"room":' + that.liveInfo.id + ',"uid":' + window.uids + ',"content":"' + res.data.url + '","ms_type":"2","type":"send"}');
  619. } else {
  620. that.msg(res.msg);
  621. }
  622. }
  623. })
  624. }
  625. });
  626. window.vm = vm;
  627. this.KeyboardStatus();
  628. this.getCommentList();
  629. this.getOpenCommtList();
  630. this.createEmojiSwiper();
  631. this.createGiftSwiper();
  632. this.getGiftList();
  633. this.getRecomList();
  634. this.getRankList();
  635. });
  636. },
  637. methods: {
  638. // 向下滚动加载
  639. chatScroll: function (event) {
  640. var target = event.target;
  641. if (target.scrollTop) {
  642. return;
  643. }
  644. switch (this.navActive) {
  645. case 0:
  646. this.isDown = false;
  647. this.scrollHeight = target.scrollHeight;
  648. this.getOpenCommtList();
  649. break;
  650. case 1:
  651. this.getCommentList();
  652. break;
  653. }
  654. },
  655. // 预览图片
  656. preview: function (img) {
  657. layer.open({
  658. style: 'background:none',
  659. className: 'preview',
  660. content: '<img class="preview-img" src="' + img + '">'
  661. });
  662. },
  663. getUrlStr: function (name) {
  664. var pattern = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'),
  665. array = document.location.search.slice(1).match(pattern);
  666. if (array) {
  667. return decodeURI(array[2]);
  668. }
  669. return null;
  670. },
  671. emojiKeyboardHide: function () {
  672. if (this.emojiShow) {
  673. this.emojiShow = false;
  674. }
  675. },
  676. // 滚动条滚到底部
  677. contentScroll: function (params) {
  678. this.$nextTick(function () {
  679. params.parentNode.scrollTop = this.isDown ? params.scrollHeight : params.scrollHeight - this.scrollHeight;
  680. });
  681. },
  682. // 设置赠送礼物后的功功能
  683. setGiftFloat: function (res) {
  684. var cont = '赠送给主播',
  685. gift = null,
  686. type = 1;
  687. if (!res.recharge_status) {
  688. return this.msg('您的' + this.goldInfo.gold_name + '不足,请先去充值');
  689. }
  690. gift = this.giftList.find(function (value) {
  691. return value.id === res.live_gift_id;
  692. });
  693. if (!gift) {
  694. return this.msg('gift异常');
  695. }
  696. res.gift = gift
  697. this.giftFloat = res;
  698. cont += gift.live_gift_name + '<img src="' + res.gift.live_gift_show_img + '"> ×' + res.live_gift_num;
  699. this.BarrageList.push({
  700. avatar: res.user_avatar,
  701. content: cont,
  702. type: type
  703. });
  704. this.OpenCommentList.push({
  705. nickname: res.username,
  706. uid: res.uid,
  707. content: cont,
  708. type: type,
  709. avatar: res.user_avatar,
  710. user_type: res.user_type
  711. });
  712. if (res.uid === this.userInfo.uid) {
  713. this.isDown = true;
  714. this.userInfo.gold_num = this.userInfo.gold_num - gift.live_gift_price * res.live_gift_num;
  715. }
  716. },
  717. // 赠送
  718. giveGift: function () {
  719. var data = {
  720. type: 'live_reward',
  721. uid: this.userInfo.uid,
  722. live_gift_id: this.giftOn.id,
  723. live_gift_num: this.giftNumSelected,
  724. live_id: window.room,
  725. special_id: this.liveInfo.special_id
  726. };
  727. if (!this.userInfo.gold_num) {
  728. return this.msg('您的' + this.goldInfo.gold_name + '不足,请先去充值');
  729. }
  730. if (this.giftNumSelected * this.giftOn.live_gift_price > this.userInfo.gold_num) {
  731. return this.msg('您的' + this.goldInfo.gold_name + '不足,请先去充值');
  732. }
  733. this.giftShow = false;
  734. socket.ws.send(JSON.stringify(data));
  735. },
  736. // 获取榜单
  737. getRankList: function () {
  738. var that = this;
  739. that.loadings = true;
  740. store.basePost($h.U({ c: 'live', a: 'get_live_reward' }), {uid: that.userInfo.uid, live_id: that.liveInfo.id}, function (res) {
  741. var list = res.data.data.list;
  742. that.loadings = false;
  743. if (!list.length) {
  744. return;
  745. }
  746. that.rankList = list;
  747. }, function (res) {
  748. that.loadings = false;
  749. that.msg(res.data.data.msg);
  750. });
  751. },
  752. // 获取主播推荐
  753. getRecomList: function () {
  754. var that = this;
  755. that.loadings = true;
  756. store.baseGet($h.U({ c: 'live', a: 'live_goods_list', q: {live_id: that.liveInfo.id}}), function (res) {
  757. var list = res.data.data.list;
  758. that.loadings = false;
  759. if (!list.length) {
  760. return;
  761. }
  762. that.recomList = list;
  763. }, function (res) {
  764. that.loadings = false;
  765. that.msg(res.data.data.msg);
  766. });
  767. },
  768. // 获取打赏礼物
  769. getGiftList: function () {
  770. var that = this;
  771. store.baseGet($h.U({ c: 'live', a: 'live_gift_list' }), function (res) {
  772. var list = res.data.data;
  773. if (!list.length) {
  774. return;
  775. }
  776. list.forEach(function (value) {
  777. value.live_gift_num.reverse();
  778. });
  779. that.giftList = list;
  780. that.giftOn = list[0];
  781. }, function (res) {
  782. that.msg(res.msg);
  783. });
  784. },
  785. // 创建表情包面板
  786. createEmojiSwiper: function () {
  787. new Swiper('#emoji', {
  788. pagination: '#emoji-pagination',
  789. paginationClickable: false,
  790. speed: 1000,
  791. autoplayDisableOnInteraction: false,
  792. observer: true,
  793. observeParents: true
  794. });
  795. },
  796. // 创建打赏礼物面板
  797. createGiftSwiper: function () {
  798. new Swiper('#gift', {
  799. pagination: '#gift-pagination',
  800. paginationClickable: false,
  801. speed: 1000,
  802. autoplayDisableOnInteraction: false,
  803. observer: true,
  804. observeParents: true
  805. });
  806. },
  807. play_audio: function (item, index, name) {
  808. var that = this;
  809. var is_play = item.is_play === undefined ? true : !item.is_play;
  810. $.each(that[name], function (key, item) {
  811. if (index != key) {
  812. item.is_play = false;
  813. if (item.audio && !item.audio.paused) item.audio.pause();
  814. item.audio = null;
  815. };
  816. });
  817. this.$set(that, name, this[name]);
  818. mapleWx($jssdk(), function () {
  819. console.log(this);
  820. })
  821. if (is_play) {
  822. audio = new Audio(item.content);
  823. audio.load();
  824. audio.preload = 'none';
  825. var plalyPromis = audio.play();
  826. if (plalyPromis !== null)
  827. plalyPromis.catch(function () {
  828. audio.play();
  829. })
  830. document.addEventListener('DOMContentLoaded', function () {
  831. function audioAutoPlay() {
  832. audio.play();
  833. document.addEventListener("WeixinJSBridgeReady", function () {
  834. audio.play();
  835. }, false);
  836. }
  837. audioAutoPlay();
  838. });
  839. audio.addEventListener('ended', function () {
  840. that.$set(that[name][index], 'is_play', false);
  841. });
  842. }
  843. this.$set(this[name][index], 'is_play', is_play);
  844. this.$set(this[name][index], 'audio', audio);
  845. },
  846. msg: function (err, success) {
  847. layer.open({ content: err, skin: 'msg', time: 2, success: success });
  848. },
  849. layerLoading: function (type, content) {
  850. type = type == undefined ? 2 : type;
  851. this.layerIndex = layer.open({ type: type, content: content });
  852. },
  853. layerLoadClose: function () {
  854. layer.close(this.layerIndex);
  855. },
  856. // 获取聊天内容
  857. getOpenCommtList: function () {
  858. var that = this;
  859. if (that.Oloading || that.Oloadend) {
  860. return;
  861. }
  862. that.Oloading = true;
  863. store.baseGet($h.U({ c: 'live', a: 'get_open_comment_list', q: { page: that.Opage, limit: that.Olimit, live_id: that.liveInfo.id, add_time: OpenCommentTime } }), function (res) {
  864. res = res.data.data.list;
  865. that.Oloading = false;
  866. res.forEach(value => {
  867. if (value.type == 1) {
  868. value.content = that.replace_em(value.content);
  869. }
  870. that.OpenCommentList.unshift(value);
  871. });
  872. setTimeout(function () {
  873. if (that.Opage++ == 1) {
  874. that.countRoomUser();
  875. that.isDown = true;
  876. }
  877. }, 1500);
  878. that.Oloadend = res.length < that.Olimit;
  879. }, function (res) {
  880. that.Oloading = false;
  881. });
  882. },
  883. // 获取课堂内容
  884. getCommentList: function () {
  885. var that = this;
  886. if (that.loading) return;
  887. if (that.loadend) return;
  888. that.loading = true;
  889. that.loadTitle = '';
  890. store.baseGet($h.U({ c: 'live', a: 'get_comment_list', q: { page: that.page, limit: that.limit, live_id: that.liveInfo.id, add_time: CommentTime } }), function (res) {
  891. that.loading = false;
  892. var list = res.data.data.list;
  893. res = res.data.data.list;
  894. $.each(list, function (index, item) {
  895. if (item.type == 1) item.content = that.replace_em(item.content);
  896. that.CommentList.push(item);
  897. });
  898. if (that.page == Math.ceil(CommentCount / this.limit)) that.isAnimate = true;
  899. that.page++;
  900. that.$set(that, 'CommentList', that.CommentList);
  901. that.loadend = list.length < that.limit;
  902. that.loadTitle = that.loadend ? '已全部加载' : '点击加载更多';
  903. if (!list.length) {
  904. return;
  905. }
  906. that.anchor = {};
  907. for (const key in list[0]) {
  908. if (list[0].hasOwnProperty(key)) {
  909. that.anchor[key] = list[0][key];
  910. }
  911. }
  912. that.anchor.type = 1;
  913. }, function (res) {
  914. that.loading = false;
  915. that.loadTitle = '点击加载更多';
  916. });
  917. },
  918. //滑动底部加载
  919. bScrollInit: function (Fnname) {
  920. var that = this;
  921. $h.EventUtil.listenTouchDirection(document, false, false, false, function () {
  922. that[Fnname] && that[Fnname]();
  923. }, false);
  924. },
  925. wechatUploadImg: function (wxApi, count, successCallback, errorCallback) {
  926. var that = this;
  927. wxApi.chooseImage({ count: count, sizeType: ['compressed'] }, function (localIds) {
  928. that.layerLoading(2, '图片上传中...');
  929. wxApi.uploadImage(localIds, function (serverIds) {
  930. store.baseGet($h.U({ c: 'public_api', a: 'wechat_media_id_by_image', p: { mediaIds: serverIds } }), function (res) {
  931. that.layerLoadClose();
  932. if (!res.data.data) {
  933. that.msg('请选择上传图片!');
  934. errorCallback && errorCallback(err);
  935. return;
  936. }
  937. successCallback && successCallback(res.data.data);
  938. }, function (res) {
  939. that.layerLoadClose();
  940. that.msg('上传失败!');
  941. errorCallback && errorCallback(err);
  942. });
  943. })
  944. });
  945. },
  946. //发送图文消息处理
  947. push: function () {
  948. var that = this;
  949. if (that.is_ban) return that.msg('您已被禁言!');
  950. if (this.content) {
  951. that.sendMessage(this.content, 1);
  952. } else {
  953. //发送图片微信端
  954. if (isWechat) {
  955. mapleWx($jssdk(), function () {
  956. that.wechatUploadImg(this, 1, function (res) {
  957. that.sendMessage(res[0], 2);
  958. that.isAnimate = true;
  959. });
  960. });
  961. } else {
  962. //其他端
  963. if (!$('.images').length) $('body').append('<input type="file" name="images" style="display: none" class="images">');
  964. $('.images').click();
  965. }
  966. }
  967. },
  968. /*
  969. *获取直播间人数
  970. * */
  971. countRoomUser: function () {
  972. var joint = '{"type":"room_user_count","uid":' + window.uids + ',"room":' + window.room + '}';
  973. socket.ws.send(joint);
  974. },
  975. /*
  976. * 本人撤回消息
  977. * */
  978. recall: function (id, indexList) {
  979. var that = this;
  980. layer.open({
  981. content: '是否要撤回此消息?'
  982. , btn: ['是的', '不要']
  983. , yes: function (index) {
  984. socket.ws.send('{"room":' + that.liveInfo.id + ',"type":"recall","id":' + id + '}');
  985. that.CommentList.splice(indexList, 1);
  986. $.each(that.OpenCommentList, function (indexs, item) {
  987. if (item != undefined && item.id == id) that.OpenCommentList.splice(indexs, 1);
  988. });
  989. layer.close(index);
  990. that.$set(that, 'CommentList', that.CommentList);
  991. that.$set(that, 'OpenCommentList', that.OpenCommentList);
  992. }
  993. });
  994. },
  995. /*
  996. * socket回撤直播间消息回调
  997. * */
  998. CommentRecall: function (id) {
  999. var that = this;
  1000. $.each(this.CommentList, function (index, item) {
  1001. if (item.id == id) that.CommentList.splice(index, 1);
  1002. });
  1003. $.each(this.OpenCommentList, function (index, item) {
  1004. if (item.id == id) that.OpenCommentList.splice(index, 1);
  1005. });
  1006. this.OpenCommentCount--;
  1007. that.$set(that, 'CommentList', that.CommentList);
  1008. that.$set(that, 'OpenCommentList', that.OpenCommentList);
  1009. },
  1010. // 更新直播间在线人数和欢迎回调
  1011. setUserCount: function (onLine_user_count, notice_content, user_type) {
  1012. var anchor = this.anchor,
  1013. obj = null;
  1014. this.UserSum = onLine_user_count;
  1015. this.notice = notice_content;
  1016. if (anchor && typeof anchor === 'object') {
  1017. obj = {};
  1018. for (const key in anchor) {
  1019. if (anchor.hasOwnProperty(key)) {
  1020. obj[key] = anchor[key];
  1021. }
  1022. }
  1023. obj.content = notice_content;
  1024. this.OpenCommentList.push(obj);
  1025. }
  1026. },
  1027. // 用户禁言回调
  1028. setBanUser: function (value) {
  1029. this.is_ban = value;
  1030. },
  1031. // 设置聊天和课堂内容
  1032. setCommentArea: function (content, type, toUserInfo, user_type, id) {
  1033. switch (user_type) {
  1034. case 0: case 1:
  1035. this.CommentList.push({
  1036. nickname: toUserInfo.nickname,
  1037. uid: toUserInfo.uid,
  1038. content: type == 1 ? this.replace_em(content) : content,
  1039. type: type,
  1040. avatar: toUserInfo.avatar,
  1041. user_type: user_type,
  1042. id: id,
  1043. });
  1044. this.$set(this, 'CommentList', this.CommentList);
  1045. break;
  1046. default:
  1047. this.BarrageList.push({
  1048. avatar: toUserInfo.avatar,
  1049. content: type == 1 ? this.replace_em(content) : content,
  1050. type: type
  1051. });
  1052. this.$set(this, 'BarrageList', this.BarrageList);
  1053. break;
  1054. }
  1055. this.OpenCommentList.push({
  1056. nickname: toUserInfo.nickname,
  1057. uid: toUserInfo.uid,
  1058. content: type == 1 ? this.replace_em(content) : content,
  1059. type: type,
  1060. avatar: toUserInfo.avatar,
  1061. user_type: user_type,
  1062. id: id
  1063. });
  1064. this.isDown = true;
  1065. this.OpenCommentCount++;
  1066. },
  1067. /*
  1068. * 发送消息
  1069. * */
  1070. sendMessage: function (content, type) {
  1071. var that = this;
  1072. if (that.is_SendOut === false) return that.msg('您发送消息过于频繁!');
  1073. that.isAnimate = true;
  1074. var cd = that.cd;
  1075. var index = setInterval(function () {
  1076. cd--;
  1077. if (cd <= 0) {
  1078. clearInterval(index);
  1079. that.is_SendOut = true;
  1080. }
  1081. }, 1000);
  1082. that.content = '';
  1083. socket.sendOut();
  1084. socket.ws.send('{"room":' + this.liveInfo.id + ',"uid":' + window.uids + ',"content":"' + content + '","ms_type":"' + type + '","type":"send"}');
  1085. },
  1086. KeyboardStatus: function () {
  1087. var winHeight = $(window).height(), that = this, interval = null, bfscrolltop = document.body.scrollTop;; //获取当前页面高度
  1088. if (phone_type == 2) {
  1089. $(window).resize(function () {
  1090. var thisHeight = $(this).height();
  1091. if (winHeight - thisHeight > 50) {
  1092. //当软键盘弹出,在这里面操作
  1093. that.emojiShow = false;
  1094. } else {
  1095. //当软键盘收起,在此处操作
  1096. }
  1097. });
  1098. $(that.$refs.input).keydown(function (event) {
  1099. if (event.keyCode == 13 && that.content) {
  1100. that.sendMessage($(that.$refs.input).val(), 1);
  1101. that.$refs.input.blur();
  1102. }
  1103. }).focus(function (e) {
  1104. that.isAnimate = true;
  1105. document.body.scrollTop = document.body.scrollHeight;
  1106. that.focusInput(e);
  1107. })
  1108. } else if (phone_type == 1) {
  1109. $(that.$refs.input).focus(function (e) {
  1110. that.isAnimate = true;
  1111. that.$nextTick(function () {
  1112. that.emojiShow = false;
  1113. })
  1114. interval = setInterval(function () {
  1115. document.documentElement.scrollTop = $("#app").height();
  1116. }, 100)
  1117. }).blur(function () {
  1118. clearInterval(interval);
  1119. document.documentElement.scrollTop = $("#app").height();
  1120. })
  1121. }
  1122. $(that.$refs.input).keydown(function (event) {
  1123. if (event.keyCode == 13 && that.content) {
  1124. that.sendMessage($(that.$refs.input).val(), 1);
  1125. that.$refs.input.blur();
  1126. }
  1127. });
  1128. $(that.$refs.chatList).click(function (event) {
  1129. event.stopPropagation();
  1130. if (that.emojiShow) that.emojiShow = false;
  1131. })
  1132. $(that.$refs.chat).click(function (event) {
  1133. event.stopPropagation();
  1134. if (that.emojiShow) that.emojiShow = false;
  1135. })
  1136. },
  1137. changeContent: function (e) {
  1138. // this.msg(e.value);
  1139. },
  1140. focusInput: function (obj) {
  1141. var isAndroid = navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1;
  1142. var isIos = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  1143. if (isAndroid) {
  1144. window.addEventListener('resize', () => {
  1145. if (document.activeElement.tagName == 'INPUT') {
  1146. window.setTimeout(() => {
  1147. document.activeElement.scrollIntoViewIfNeeded()
  1148. }, 0)
  1149. }
  1150. })
  1151. } else if (isIos) {
  1152. // 使用定时器是为了让输入框上滑时更加自然
  1153. var input_demo = document.getElementsByTagName('input')[0];
  1154. setTimeout(function () {
  1155. input_demo.scrollIntoViewIfNeeded();
  1156. document.activeElement.scrollIntoViewIfNeeded()
  1157. }, 100);
  1158. // $('.footer').css('position','relative');
  1159. window.addEventListener('focusin', () => {
  1160. scrollTops = document.body.scrollHeight;
  1161. })
  1162. window.addEventListener('focusout', () => {
  1163. window.scrollTo(0, 0);
  1164. })
  1165. $(this.$refs.chat).animate({ scrollTop: $(this.$refs.chat).scrollTop() + 300 }, 300);
  1166. }
  1167. },
  1168. changeText: function (e) {
  1169. var input = this.$refs.input;
  1170. input.focus();
  1171. //input.scrollTop = input.scrollHeigHt;
  1172. },
  1173. mine: function (item) {
  1174. this.$refs.input.value += item.type;
  1175. this.content = this.$refs.input.value;
  1176. },
  1177. /*
  1178. * 替换表情
  1179. * */
  1180. replace_em: function (str) {
  1181. str = str.replace(/\</g, '&lt;');
  1182. str = str.replace(/\>/g, '&gt;');
  1183. str = str.replace(/\n/g, '<br/>');
  1184. str = str.replace(/\[qq_([0-9]*)\]/g, "<img class='img' src='/wap/first/zsff/face/emoji1/$1.gif' />");
  1185. str = str.replace(/\[em_([0-9]*)\]/g, "<img class='img' src='/wap/first/zsff/face/emoji2/$1.png' />");
  1186. str = str.replace(/\[other_([0-9]*)\]/g, "<img class='img' src='/wap/first/zsff/face/emoji3/$1.png' />");
  1187. return str;
  1188. },
  1189. delEmoji: function () {
  1190. this.content = this.content.substring(0, this.content.length - 1);
  1191. },
  1192. /*
  1193. * 播放器错误事件处理
  1194. *
  1195. * */
  1196. bindEvevt: function () {
  1197. var that = this;
  1198. this.player.on('onM3u8Retry', function () {
  1199. if (that.player) that.player.dispose();
  1200. that.live_error = '主播暂时离开,请稍后.';
  1201. that.live_status = -1;
  1202. console.log('主播暂时离开,请稍后......');
  1203. });
  1204. this.player.on('liveStreamStop', function () {
  1205. console.log('直播失败或直播已结束');
  1206. that.live_error = '直播失败或直播已结束';
  1207. that.live_status = -1;
  1208. if (that.player) that.player.dispose();
  1209. });
  1210. this.player.on('error', function (e) {
  1211. //隐藏
  1212. $('.prism-ErrorMessage').hide();
  1213. //解析
  1214. var errorData = e.paramData;
  1215. that.live_error = '直播失败或直播已结束';
  1216. that.live_status = -1;
  1217. if (that.player) that.player.dispose();
  1218. });
  1219. },
  1220. touchmoveDefault: function (e) {
  1221. e.preventDefault();
  1222. },
  1223. start(e) {
  1224. var that = this;
  1225. if (this.timeOutEvent) clearTimeout(this.timeOutEvent);
  1226. if (this.autoCloseRecord) clearInterval(this.autoCloseRecord);
  1227. this.longClick = 0;
  1228. this.starttime = new Date().getTime();
  1229. this.autoCloseRecord = setInterval(function () {
  1230. that.timeEnd--;
  1231. if (that.timeEnd === 10) that.showTimer = true;
  1232. if (that.timeEnd === 0) that.end(e);
  1233. })
  1234. this.timeOutEvent = setTimeout(function () {
  1235. e.preventDefault();
  1236. that.longClick = 1;
  1237. if (isWechat) {
  1238. mapleWx($jssdk(), function () {
  1239. this.startRecord();
  1240. });
  1241. }
  1242. }, 500);
  1243. that.speak = '松开 结束';
  1244. that.recording = true;
  1245. return false;
  1246. },
  1247. move(e) {
  1248. this.timeOutEvent = 0;
  1249. e.preventDefault();
  1250. },
  1251. end(e) {
  1252. var that = this;
  1253. this.msg('333');
  1254. clearInterval(that.autoCloseRecord);
  1255. this.endtime = new Date().getTime();
  1256. if ((this.endtime - this.starttime) < 2) {
  1257. this.endtime = 0;
  1258. this.starttime = 0;
  1259. clearTimeout(this.timeOutEvent);
  1260. that.msg('说话时间太短');
  1261. mapleWx($jssdk(), function () {
  1262. this.stopRecord();
  1263. })
  1264. } else {
  1265. mapleWx($jssdk(), function () {
  1266. var wx = this;
  1267. this.stopRecord(function (localId, res) {
  1268. wx.uploadVoice(localId, function (serverId) {
  1269. store.basePost($h.U({ c: 'live', a: 'upload_voice' }), { server_id: serverId }, function (res) {
  1270. socket.ws.send('{"room":' + that.liveInfo.id + ',"content":"' + Ks3Host + '/' + res.data.data.url + '","ms_type":3,"type":"send"}');
  1271. });
  1272. }, 0)
  1273. });
  1274. })
  1275. }
  1276. e.preventDefault();
  1277. this.speak = '按住 结束';
  1278. this.recording = false;
  1279. return false;
  1280. },
  1281. voiceBnt: function () {
  1282. this.emojiShow = false;
  1283. if (this.voice == true) {
  1284. this.voice = false;
  1285. this.$nextTick(function () {
  1286. this.$refs.input.focus();
  1287. });
  1288. } else {
  1289. this.voice = true;
  1290. }
  1291. },
  1292. emoticon: function () {
  1293. var that = this;
  1294. this.voice = false;
  1295. if (this.emojiShow == true) {
  1296. this.emojiShow = false;
  1297. this.$nextTick(function () {
  1298. that.$refs.input.focus();
  1299. })
  1300. } else {
  1301. this.emojiShow = true;
  1302. this.$nextTick(function () {
  1303. that.$refs.input.blur();
  1304. });
  1305. }
  1306. },
  1307. openBarrage: function () {
  1308. this.barrage = !this.barrage
  1309. },
  1310. openDiscuss: function () {
  1311. this.discuss = true;
  1312. $(this.$refs.chatlist).css({ overflow: 'hidden' });
  1313. },
  1314. closeDiscuss: function () {
  1315. this.discuss = false;
  1316. $(this.$refs.chatlist).css({ overflow: 'auto' });
  1317. },
  1318. changLive: function (type, pullUrl) {
  1319. //销毁播放器
  1320. var that = this;
  1321. if (this.player) this.player.dispose();
  1322. if (type) {
  1323. this.liveInfo.is_play = 1;
  1324. this.PullUrl = pullUrl;
  1325. this.$nextTick(function () {
  1326. that.player = new Aliplayer({
  1327. id: 'J_prismPlayer',
  1328. width: '100%',
  1329. height: '100%',
  1330. autoplay: false,
  1331. isLive: true,
  1332. source: pullUrl,
  1333. }, function (player) {
  1334. console.log('播放器创建好了。')
  1335. });
  1336. this.$nextTick(function () {
  1337. $('#J_prismPlayer').css({ height: '4.22rem' });
  1338. });
  1339. that.bindEvevt();
  1340. })
  1341. } else {
  1342. this.PullUrl = false;
  1343. this.live_status = 1;
  1344. this.$set(this.liveInfo, 'is_play', 0);
  1345. this.$nextTick(function () {
  1346. $(that.$refs.column).css({ height: 'auto' });
  1347. });
  1348. }
  1349. }
  1350. }
  1351. });
  1352. });
  1353. </script>
  1354. {/block}