group.vue 18 KB

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