group.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <template>
  2. <div class="group">
  3. <!--顶部-->
  4. <div class="group-top">
  5. <div class="live-title">
  6. <div class="live-title-name">{{ roomInfo.cs_item_name }} {{ roomInfo.task_name }}</div>
  7. <div>
  8. <el-button @click="exitRoom">退出房间</el-button>
  9. </div>
  10. </div>
  11. <div class="live-course-name">{{ roomInfo.course_name }}</div>
  12. <div class="live-teacher">
  13. <span class="live-teacher-name">
  14. <svg-icon icon-class="person" />{{ roomInfo.teacher_name }}
  15. </span>
  16. <span><svg-icon icon-class="people" />{{ roomInfo.student_count }}</span>
  17. </div>
  18. </div>
  19. <!-- 主容器 -->
  20. <div class="group-container">
  21. <!-- 左侧 -->
  22. <div class="group-container-left">
  23. <div class="group-discussion">
  24. <div v-show="localStream" id="group-local" class="group-box"></div>
  25. <div v-show="!localStream" class="group-box student-info">
  26. <el-avatar icon="el-icon-user" :src="studentSelf.student_image_url" :size="100" />
  27. <span class="student_name">{{ studentSelf.student_name }}</span>
  28. </div>
  29. <div
  30. v-for="(item, i) in streamList"
  31. :id="`group-${i}`"
  32. :key="item.id()"
  33. class="group-box"
  34. ></div>
  35. <div v-for="item in noStreamList" :key="item.student_id" class="group-box student-info">
  36. <el-avatar icon="el-icon-user" :src="item.student_image_url" :size="80" />
  37. <span class="student_name">{{ item.student_name }}</span>
  38. </div>
  39. </div>
  40. <div class="button-group">
  41. <div class="button-group-left"></div>
  42. <div class="button-group-right"></div>
  43. </div>
  44. <div class="group-container-left-chat">
  45. <div class="chat-top">
  46. <span>聊天</span>
  47. </div>
  48. <div class="chat-window">
  49. <ul ref="chat" class="chat-window-ul">
  50. <li v-for="(item, i) in chatList" :key="i">
  51. <div class="msg-normal">
  52. <span>{{ item.username }}: </span>
  53. <span>{{ item.msg }}</span>
  54. </div>
  55. </li>
  56. </ul>
  57. </div>
  58. <div class="chat-speak">
  59. <el-input
  60. v-model="msg"
  61. placeholder="输入发言"
  62. maxlength="400"
  63. @keydown.enter.native="sendMsg"
  64. >
  65. <el-button slot="append" @click="sendMsg">发送</el-button>
  66. </el-input>
  67. </div>
  68. </div>
  69. </div>
  70. <!-- 右侧 -->
  71. <div class="group-container-right">
  72. <div
  73. class="live-teacher-lens"
  74. @mouseover="liveMenuShow = true"
  75. @mouseout="liveMenuShow = false"
  76. >
  77. <div class="live-container">
  78. <div v-show="is_teacher_in_group" id="live" />
  79. <el-image
  80. v-show="!is_teacher_in_group"
  81. :src="roomInfo.teacher_image_url"
  82. fit="contain"
  83. />
  84. </div>
  85. <div :style="{ bottom: liveMenuShow ? '0' : '-40px' }" class="live-wrapper">
  86. <div>
  87. {{ roomInfo.teacher_name }}
  88. </div>
  89. <div></div>
  90. </div>
  91. </div>
  92. <div class="student-list">
  93. <div class="student-list-title">小组成员</div>
  94. <ul>
  95. <li v-for="item in student_list" :key="item.room_user_id">
  96. <div class="student-list-left">
  97. <el-avatar icon="el-icon-user" size="small" :src="item.student_image_url" />
  98. <span class="name">{{ item.student_name }}</span>
  99. </div>
  100. </li>
  101. </ul>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import {
  109. StudentExitLiveRoom,
  110. GetLiveRoomInfo,
  111. GetGroupStatus,
  112. GetMyGroupInfo_Student,
  113. CreateEnterLiveRoomSession
  114. } from '@/api/live';
  115. import * as common from './group';
  116. export default {
  117. data() {
  118. return {
  119. task_id: this.$route.query.task_id,
  120. room_user_id: '',
  121. session_id: '',
  122. live_room_sys_user_id: '',
  123. room_id: '',
  124. localStream: false,
  125. // 定时器
  126. timer: null,
  127. rtc: null,
  128. streamList: [],
  129. roomData: {
  130. desc: '直播间标题',
  131. name: '姓名',
  132. user: {
  133. id: '',
  134. name: '',
  135. role: 'talker',
  136. rommid: ''
  137. },
  138. max_users: 1,
  139. allow_chat: true,
  140. allow_audio: true,
  141. allow_speak: true
  142. },
  143. roomInfo: {
  144. room_id: '',
  145. video_mode: 1,
  146. task_name: '',
  147. cs_item_name: '',
  148. course_name: '',
  149. teacher_name: '',
  150. student_count: 0,
  151. teacher_image_url: ''
  152. },
  153. loadedNumber: 0,
  154. speakData: {},
  155. roomContext: {},
  156. msg: '',
  157. chatList: [],
  158. // 直播间学员列表
  159. student_list: [],
  160. // 直播状态
  161. liveStat: false,
  162. liveMenuShow: false,
  163. is_teacher_in_group: false,
  164. // 无远程流学员列表
  165. noStreamList: [],
  166. // 学员自身信息
  167. studentSelf: {}
  168. };
  169. },
  170. watch: {
  171. loadedNumber(newVal) {
  172. if (newVal === 5) {
  173. common.createScript(
  174. 'https://class.csslcloud.net/static/SDK/docSDK/drawSdk_3.0.js'
  175. ).onload = () => {
  176. this.rtc = common.initSDK({
  177. userid: this.live_room_sys_user_id,
  178. roomid: this.room_id,
  179. sessionid: this.session_id
  180. });
  181. common.initListener(this); // 注册监听事件
  182. this.getLiveStat();
  183. this.$loading().close();
  184. };
  185. }
  186. },
  187. streamList(newVal) {
  188. let list = this.student_list.filter(item => {
  189. if (item.is_self === 'false') {
  190. let isNoStream = true;
  191. for (let i = 0; i < newVal.length; i++) {
  192. if (newVal[i].id().split('-')[0] === item.room_user_id) isNoStream = false;
  193. }
  194. return isNoStream;
  195. }
  196. return false;
  197. });
  198. this.noStreamList = list;
  199. if (newVal.length > 0) {
  200. this.$nextTick(() => {
  201. newVal[newVal.length - 1].show(`group-${newVal.length - 1}`);
  202. });
  203. }
  204. },
  205. // 聊天列表滚动
  206. chatList() {
  207. common.chatRoll(this);
  208. }
  209. },
  210. created() {
  211. this.getLiveRoomInfo();
  212. this.getMyGroupInfo_Student();
  213. },
  214. mounted() {
  215. this.GetGroupStatus();
  216. },
  217. beforeDestroy() {
  218. clearInterval(this.timer);
  219. StudentExitLiveRoom({ task_id: this.task_id, room_user_id: this.room_user_id });
  220. common.handsDown({
  221. uid: this.room_user_id,
  222. success: str => {
  223. console.log('下麦成功', str);
  224. },
  225. fail: data => {
  226. console.log('下麦失败', data);
  227. common.closeVideo('picture');
  228. }
  229. });
  230. this.streamList.forEach(item => {
  231. common.unSubscribeStream(item);
  232. });
  233. },
  234. methods: {
  235. getLiveRoomInfo() {
  236. GetLiveRoomInfo({ task_id: this.task_id }).then(
  237. ({
  238. room_id,
  239. video_mode,
  240. task_name,
  241. cs_item_name,
  242. course_name,
  243. teacher_name,
  244. student_count,
  245. teacher_image_url
  246. }) => {
  247. this.roomInfo = {
  248. room_id,
  249. video_mode,
  250. task_name,
  251. cs_item_name,
  252. course_name,
  253. teacher_name,
  254. student_count,
  255. teacher_image_url
  256. };
  257. }
  258. );
  259. },
  260. exitRoom() {
  261. StudentExitLiveRoom({ task_id: this.task_id, room_user_id: this.room_user_id }).then(() => {
  262. this.$router.push('/');
  263. });
  264. },
  265. getLiveStat() {
  266. common.getLiveStat({
  267. success: data => {
  268. this.liveStat = data.started;
  269. },
  270. fail: str => {
  271. this.liveStat = false;
  272. console.log('直播关闭状态或查询直播失败', str);
  273. }
  274. });
  275. },
  276. // 发消息
  277. sendMsg() {
  278. common.sendMsg(this.msg);
  279. this.msg = '';
  280. },
  281. // 分组讨论
  282. GetGroupStatus() {
  283. this.timer = setInterval(() => {
  284. GetGroupStatus({ task_id: this.task_id })
  285. .then(({ is_enable_group }) => {
  286. if (is_enable_group === 'false') {
  287. clearInterval(this.timer);
  288. CreateEnterLiveRoomSession({
  289. task_id: this.task_id
  290. }).then(({ live_room_sys_user_id, room_id, session_id, room_user_id }) => {
  291. this.$router.push({
  292. path: `/live/student`,
  293. query: {
  294. live_room_sys_user_id,
  295. room_id,
  296. session_id,
  297. task_id: this.task_id,
  298. room_user_id
  299. }
  300. });
  301. });
  302. }
  303. })
  304. .catch(() => {
  305. clearInterval(this.timer);
  306. });
  307. }, 5000);
  308. },
  309. getMyGroupInfo_Student() {
  310. GetMyGroupInfo_Student({
  311. task_id: this.task_id
  312. }).then(({ live_room_sys_user_id, room_id, student_list }) => {
  313. let data = student_list.find(el => {
  314. return el.is_self === 'true';
  315. });
  316. this.session_id = data.session_id;
  317. this.room_user_id = data.room_user_id;
  318. this.live_room_sys_user_id = live_room_sys_user_id;
  319. this.room_id = room_id;
  320. this.student_list = student_list;
  321. this.noStreamList = student_list.filter(item => item.is_self === 'false');
  322. this.studentSelf = student_list.find(item => item.is_self === 'true');
  323. common.downloadWebSDK(this);
  324. });
  325. }
  326. }
  327. };
  328. </script>
  329. <style lang="scss">
  330. @import '~@/styles/mixin.scss';
  331. $live-bc: #3d3938;
  332. .group {
  333. @include container;
  334. // 顶部
  335. &-top {
  336. background-color: #fff;
  337. padding: 24px 32px;
  338. border-top-left-radius: 8px;
  339. border-top-right-radius: 8px;
  340. .live-title {
  341. display: flex;
  342. justify-content: space-between;
  343. &-name {
  344. font-size: 22px;
  345. }
  346. .el-button {
  347. border-radius: 4px;
  348. padding: 7px 12px;
  349. }
  350. }
  351. .live-course-name {
  352. font-size: 14px;
  353. color: #737373;
  354. line-height: 30px;
  355. }
  356. .live-teacher {
  357. margin-top: 12px;
  358. .svg-icon {
  359. margin-right: 8px;
  360. }
  361. &-name {
  362. margin-right: 60px;
  363. }
  364. }
  365. }
  366. // 主容器
  367. &-container {
  368. display: flex;
  369. justify-content: left;
  370. &-left {
  371. width: 832px;
  372. background-color: #fff;
  373. border-radius: 8px;
  374. // 分组讨论
  375. .group-discussion {
  376. display: flex;
  377. flex-wrap: wrap;
  378. width: 100%;
  379. height: 468px;
  380. position: relative;
  381. background-color: $live-bc;
  382. overflow: hidden;
  383. .group-box {
  384. width: 256px;
  385. height: 144px;
  386. margin: 8px;
  387. &.student-info {
  388. display: flex;
  389. flex-direction: column;
  390. align-items: center;
  391. justify-content: space-between;
  392. border: 2px solid #625c5b;
  393. .el-avatar {
  394. margin-top: 12px;
  395. }
  396. .student_name {
  397. height: 28px;
  398. color: #fff;
  399. }
  400. }
  401. }
  402. }
  403. .button-group {
  404. display: flex;
  405. justify-content: space-between;
  406. height: 48px;
  407. background-color: #4d4d4d;
  408. padding: 0 15px;
  409. border-bottom-left-radius: 5px;
  410. .svg-icon {
  411. font-size: 20px;
  412. }
  413. &-left {
  414. > span {
  415. display: inline-block;
  416. height: 100%;
  417. padding: 14px 16px;
  418. cursor: pointer;
  419. &:active,
  420. &:hover {
  421. background-color: #3d3d3d;
  422. }
  423. }
  424. }
  425. }
  426. // 聊天窗口
  427. &-chat {
  428. height: 278px;
  429. border: 1px solid #ccc;
  430. border-bottom-left-radius: 8px;
  431. display: flex;
  432. flex-direction: column;
  433. justify-content: space-between;
  434. .chat-top {
  435. display: flex;
  436. justify-content: space-between;
  437. padding: 15px 15px 10px;
  438. border-bottom: 1px solid #e6e6e6;
  439. color: #959595;
  440. label {
  441. cursor: pointer;
  442. }
  443. .allow-chat {
  444. margin-right: 12px;
  445. }
  446. }
  447. .chat-window {
  448. position: relative;
  449. width: 100%;
  450. height: 100%;
  451. overflow: hidden;
  452. &-ul {
  453. position: absolute;
  454. top: 0;
  455. left: 0;
  456. width: 100%;
  457. height: 100%;
  458. overflow: auto;
  459. .msg-normal {
  460. padding: 7px 16px;
  461. }
  462. }
  463. }
  464. .chat-speak {
  465. padding: 16px;
  466. }
  467. }
  468. }
  469. &-right {
  470. padding: 8px;
  471. background-color: #2c2c2c;
  472. border-end-end-radius: 8px;
  473. .live-teacher-lens {
  474. position: relative;
  475. overflow: hidden;
  476. .live-container {
  477. width: 352px;
  478. height: 198px;
  479. background-color: $live-bc;
  480. #live {
  481. width: 100%;
  482. height: 100%;
  483. }
  484. .el-image {
  485. width: 100%;
  486. height: 100%;
  487. }
  488. }
  489. .live-wrapper {
  490. position: absolute;
  491. height: 40px;
  492. width: 100%;
  493. background-color: #000;
  494. opacity: 0.7;
  495. color: #fff;
  496. line-height: 40px;
  497. padding: 0 16px;
  498. transition: all 300ms ease-in 0s;
  499. }
  500. }
  501. .student-list {
  502. width: 100%;
  503. padding: 24px 16px;
  504. margin-top: 2px;
  505. height: calc(100% - 200px);
  506. background-color: #2c2c2c;
  507. font-size: 14px;
  508. color: #fff;
  509. &-title {
  510. margin-bottom: 16px;
  511. }
  512. li {
  513. display: flex;
  514. margin-bottom: 16px;
  515. .student-list-left {
  516. .name {
  517. vertical-align: super;
  518. margin-left: 8px;
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. </style>