group.vue 15 KB

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