group.vue 21 KB

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