group.vue 16 KB

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