group.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. inputValidator(val) {
  291. if (val !== null && val.length > 0) return true;
  292. return '请输入内容';
  293. }
  294. }).then(({ value }) => {
  295. SendGroupMessage({ task_id: this.task_id, group_message_text: value }).then(() => {
  296. this.$message.success('发送成功');
  297. });
  298. });
  299. },
  300. chatBans() {
  301. common.roomUpdate({
  302. allow_chat: !this.roomData.allow_chat,
  303. roomUpdateSuccess(data) {
  304. console.log(data, '房间模板配置更新请求成功!');
  305. },
  306. roomUpdateFailed(data) {
  307. console.log(data, '房间模板配置更新请求失败! 请稍后再试!');
  308. }
  309. });
  310. },
  311. studentExitLiveRoom(room_user_id) {
  312. StudentExitLiveRoom({ task_id: this.task_id, room_user_id });
  313. },
  314. // 分组讨论
  315. stopGroup() {
  316. StopGroup({ task_id: this.task_id }).then(() => {
  317. this.$message.success('结束分组讨论成功');
  318. CreateEnterLiveRoomSession({
  319. task_id: this.task_id
  320. }).then(({ live_room_sys_user_id, room_id, session_id, room_user_id }) => {
  321. this.$router.push({
  322. path: `/live/teacher`,
  323. query: {
  324. live_room_sys_user_id,
  325. room_id,
  326. session_id,
  327. task_id: this.task_id,
  328. room_user_id
  329. }
  330. });
  331. });
  332. });
  333. },
  334. enterGroup(group_id) {
  335. JoinGroup_Teacher({ task_id: this.task_id, group_id })
  336. .then(({ room_id, session_id }) => {
  337. this.room_id = room_id;
  338. this.session_id = session_id;
  339. common.downloadWebSDK(this);
  340. this.isGroup = true;
  341. return GetMyGroupInfo_Teacher({ task_id: this.task_id });
  342. })
  343. .then(({ student_list }) => {
  344. this.noStreamList = student_list;
  345. this.student_list = student_list;
  346. });
  347. },
  348. searchStudentName(id) {
  349. let uid = id.split('-')[0];
  350. if (uid) {
  351. let student = this.student_list.find(item => item.room_user_id === uid);
  352. return student ? student.student_name : '';
  353. }
  354. return '';
  355. },
  356. exitCurGroup_Teacher() {
  357. ExitCurGroup_Teacher({ task_id: this.task_id }).then(() => {
  358. this.isGroup = false;
  359. this.room_id = '';
  360. this.session_id = '';
  361. common.closeVideo('main');
  362. this.streamList.forEach(item => {
  363. common.unSubscribeStream(item);
  364. });
  365. this.streamList = [];
  366. common.removeWebSDK();
  367. this.$message.success('退出小组讨论成功');
  368. });
  369. }
  370. }
  371. };
  372. </script>
  373. <style lang="scss" scoped>
  374. @import '~@/styles/mixin.scss';
  375. $live-bc: #3d3938;
  376. .live {
  377. @include container;
  378. // 顶部
  379. &-top {
  380. background-color: #fff;
  381. padding: 24px 32px;
  382. border-top-left-radius: 8px;
  383. border-top-right-radius: 8px;
  384. .live-title {
  385. display: flex;
  386. justify-content: space-between;
  387. &-name {
  388. font-size: 22px;
  389. }
  390. .el-button {
  391. border-radius: 4px;
  392. padding: 7px 12px;
  393. }
  394. }
  395. .live-course-name {
  396. font-size: 14px;
  397. color: #737373;
  398. line-height: 30px;
  399. }
  400. .live-teacher {
  401. margin-top: 12px;
  402. .svg-icon {
  403. margin-right: 8px;
  404. }
  405. &-name {
  406. margin-right: 60px;
  407. }
  408. }
  409. }
  410. // 主容器
  411. &-container {
  412. display: flex;
  413. justify-content: left;
  414. &-left {
  415. width: 832px;
  416. background-color: #fff;
  417. border-radius: 8px;
  418. .student-group {
  419. width: 100%;
  420. height: 468px;
  421. display: flex;
  422. flex-wrap: wrap;
  423. background-color: #4d4d4d;
  424. overflow: auto;
  425. padding: 10px 0 10px 24px;
  426. &-list {
  427. background-color: #646464;
  428. position: relative;
  429. padding: 24px;
  430. width: 255px;
  431. height: 144px;
  432. margin: 0 8px 8px 0;
  433. cursor: pointer;
  434. &-avatar {
  435. display: flex;
  436. height: 92px;
  437. flex-wrap: wrap;
  438. align-items: center;
  439. margin-top: 12px;
  440. overflow: auto;
  441. .el-avatar {
  442. margin: 0 7px 6px 0;
  443. }
  444. }
  445. .group-serial {
  446. position: absolute;
  447. display: inline-block;
  448. top: 0;
  449. left: 0;
  450. height: 24px;
  451. width: 24px;
  452. color: #fff;
  453. background-color: #3d3d3d;
  454. text-align: center;
  455. line-height: 24px;
  456. }
  457. }
  458. }
  459. // 分组讨论
  460. .group-discussion {
  461. display: flex;
  462. flex-wrap: wrap;
  463. width: 100%;
  464. height: 468px;
  465. position: relative;
  466. background-color: $live-bc;
  467. overflow: auto;
  468. .group-box {
  469. width: 256px;
  470. height: 144px;
  471. margin: 8px;
  472. &.student-info {
  473. display: flex;
  474. flex-direction: column;
  475. align-items: center;
  476. justify-content: space-between;
  477. border: 2px solid #625c5b;
  478. .el-avatar {
  479. margin-top: 12px;
  480. }
  481. .student_name {
  482. height: 28px;
  483. color: #fff;
  484. }
  485. }
  486. }
  487. .group-wrapper {
  488. position: relative;
  489. .live-wrapper-stream {
  490. position: absolute;
  491. top: 120px;
  492. height: 32px;
  493. width: calc(100% - 16px);
  494. background-color: #000;
  495. opacity: 0.7;
  496. color: #fff;
  497. line-height: 32px;
  498. text-align: center;
  499. margin: 0 8px;
  500. padding: 0 15px;
  501. transition: all 300ms ease-in 0s;
  502. > .svg-icon {
  503. margin-left: 12px;
  504. }
  505. }
  506. }
  507. }
  508. .button-group {
  509. display: flex;
  510. justify-content: space-between;
  511. height: 48px;
  512. background-color: #4d4d4d;
  513. padding: 0 15px;
  514. border-bottom-left-radius: 5px;
  515. .svg-icon {
  516. font-size: 20px;
  517. }
  518. &-left {
  519. .stop-group {
  520. color: #fff;
  521. }
  522. > span {
  523. display: inline-block;
  524. height: 100%;
  525. padding: 14px 16px;
  526. cursor: pointer;
  527. &:active,
  528. &:hover {
  529. background-color: #3d3d3d;
  530. }
  531. }
  532. }
  533. }
  534. // 聊天窗口
  535. &-chat {
  536. height: 278px;
  537. border: 1px solid #ccc;
  538. border-bottom-left-radius: 8px;
  539. display: flex;
  540. flex-direction: column;
  541. justify-content: space-between;
  542. .chat-top {
  543. display: flex;
  544. align-items: center;
  545. justify-content: space-between;
  546. padding: 15px 15px 10px;
  547. border-bottom: 1px solid #e6e6e6;
  548. color: #959595;
  549. label {
  550. cursor: pointer;
  551. }
  552. .allow-chat {
  553. margin-right: 12px;
  554. }
  555. }
  556. .chat-window {
  557. position: relative;
  558. width: 100%;
  559. height: 100%;
  560. overflow: hidden;
  561. &-ul {
  562. position: absolute;
  563. top: 0;
  564. left: 0;
  565. width: 100%;
  566. height: 100%;
  567. overflow: auto;
  568. .msg-normal {
  569. padding: 7px 16px;
  570. }
  571. }
  572. }
  573. .chat-speak {
  574. padding: 16px;
  575. }
  576. }
  577. }
  578. &-right {
  579. padding: 8px;
  580. height: 794px;
  581. background-color: #2c2c2c;
  582. border-end-end-radius: 8px;
  583. .live-teacher-lens {
  584. position: relative;
  585. overflow: hidden;
  586. #live {
  587. width: 352px;
  588. height: 198px;
  589. background-color: $live-bc;
  590. }
  591. .live-wrapper {
  592. position: absolute;
  593. height: 40px;
  594. width: 100%;
  595. background-color: #000;
  596. opacity: 0.7;
  597. color: #fff;
  598. line-height: 40px;
  599. padding: 0 16px;
  600. transition: all 300ms ease-in 0s;
  601. }
  602. }
  603. // 学员列表
  604. .student-list {
  605. width: 100%;
  606. padding: 24px 16px;
  607. margin-top: 2px;
  608. height: calc(100% - 200px);
  609. background-color: #2c2c2c;
  610. font-size: 14px;
  611. color: #fff;
  612. &-title {
  613. margin-bottom: 16px;
  614. }
  615. ul {
  616. height: calc(100% - 20px);
  617. overflow-x: auto;
  618. }
  619. li {
  620. display: flex;
  621. margin-bottom: 16px;
  622. .student-list-left {
  623. flex: 8;
  624. .name {
  625. vertical-align: super;
  626. margin-left: 8px;
  627. }
  628. }
  629. .student-list-right {
  630. flex: 2;
  631. .svg-icon {
  632. font-size: 18px;
  633. cursor: pointer;
  634. margin-top: 7px;
  635. margin-right: 8px;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. </style>