index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <div class="pptEasyClass">
  3. <div class="pec_main" v-loading="pageLoading">
  4. <div class="pec_header">
  5. <div class="pec_h_left">
  6. <div @click.stop="back" class="backBtn" v-if="screenType != 2 || tType == 1">
  7. <img src="../../assets/icon/newIcon/return.svg" alt="" />
  8. </div>
  9. <div v-if="tcid" class="class-info-group">
  10. <span class="class-label">班级</span>
  11. <span class="class-value">{{ className }}</span>
  12. </div>
  13. <div v-if="tcid" class="class-info-group">
  14. <span class="class-label" v-if="inviteCode">识别码</span>
  15. <span class="class-value" v-if="inviteCode">{{ inviteCode }}</span>
  16. </div>
  17. </div>
  18. <div class="pec_h_center">
  19. <div class="pec_h_l_title">
  20. <span>{{ courseDetail.title }}</span>
  21. </div>
  22. <div class="free-browse-switch" v-if="courseDetail.userid == userid">
  23. <span class="switch-label" :class="{ active: freeBrowse }">{{ freeBrowse ? '自由浏览' : '跟随模式' }}</span>
  24. <el-switch
  25. v-model="freeBrowse"
  26. :active-value="true"
  27. :inactive-value="false"
  28. class="custom-switch"
  29. active-color="#FCCF00"
  30. inactive-color="#F53F3F"
  31. @change="onFreeBrowseChange"
  32. ></el-switch>
  33. </div>
  34. </div>
  35. <div class="pec_h_right">
  36. <div class="pec_h_r_btnArea">
  37. <!-- <el-tooltip effect="light" content="刷新" placement="top">
  38. <div class="pec_h_r_btn_refresh" @click="refreshCourse">
  39. <img src="../../assets/icon/newIcons/refresh.png" alt="" />
  40. <span>刷新</span>
  41. </div>
  42. </el-tooltip> -->
  43. <div class="pec_h_r_btn_afterClass" @click="afterClass" v-if="courseDetail.userid == userid">
  44. <img src="../../assets/icon/newIcon/afterClass.svg" alt="" />
  45. <span>下课</span>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="pec_content">
  51. <iframe allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read"
  52. webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" frameborder="no" border="0" :src="iframeSrc"
  53. v-if="showIframe" style="width: 100%; height: 100%; border: none" ref="ppt"></iframe>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { myMixin } from '../../mixins/mixin';
  60. export default {
  61. mixins: [myMixin],
  62. data() {
  63. return {
  64. id: this.$route.query.courseId,
  65. userid: this.$route.query.userid,
  66. classId: this.$route.query.cid,
  67. role: this.$route.query.role,
  68. oid: this.$route.query.oid,
  69. org: this.$route.query.org,
  70. tType: this.$route.query.tType,
  71. courseType: this.$route.query.type,
  72. screenType: this.$route.query.screenType,
  73. tcid2: this.$route.query.tcid,
  74. tcid: "",
  75. className: "",
  76. showIframe: false,
  77. iframeSrc: "",
  78. courseDetail: {},
  79. pageLoading: false,
  80. inviteCode: "",
  81. startTime: "",
  82. freeBrowse: true, // 默认自由浏览
  83. opertimer: null, // 定时器
  84. };
  85. },
  86. methods: {
  87. goTo(path) {
  88. this.$router.push(path);
  89. },
  90. refreshCourse() {
  91. this.getCourseDetail();
  92. },
  93. getCourseDetail() {
  94. this.pageLoading = true;
  95. let params = {
  96. courseId: this.id
  97. };
  98. this.ajax
  99. .get(this.$store.state.api + "selectCourseDetail3", params)
  100. .then(res => {
  101. console.log("getCourseDetail", res);
  102. this.courseDetail = res.data[0][0];
  103. this.courseDetail.chapters = JSON.parse(this.courseDetail.chapters);
  104. this.tcid = this.arrayToArray(
  105. this.courseDetail.juri ? this.courseDetail.juri.split(",") : [],
  106. this.tcid2 ? this.tcid2.split(",") : []
  107. )[0] || "";
  108. if (this.tcid && res.data[1].length) {
  109. let _inviteA = [];
  110. for (var ik = 0; ik < res.data[1].length; ik++) {
  111. _inviteA.push({
  112. cid: res.data[1][ik].classid,
  113. ic: res.data[1][ik].code,
  114. });
  115. }
  116. for (var ik = 0; ik < _inviteA.length; ik++) {
  117. if (
  118. this.arrayToArray(
  119. _inviteA[ik].cid.split(","),
  120. this.tcid.split(",")
  121. ).length
  122. ) {
  123. this.inviteCode = _inviteA[ik].ic;
  124. break;
  125. }
  126. }
  127. }
  128. this.setPptIframe()
  129. this.pageLoading = false;
  130. })
  131. .catch(err => {
  132. console.log(err);
  133. this.$message.error("获取课程数据失败");
  134. this.pageLoading = false;
  135. });
  136. },
  137. setPptIframe() {
  138. this.showIframe = false;
  139. this.$nextTick(() => {
  140. let api = ''
  141. if (this.$region == 'beta') {
  142. api = 'https://beta.ppt.cocorobo.cn'
  143. } else {
  144. api = 'https://ppt.cocorobo.cn'
  145. }
  146. let _url = api + `/?mode=student&courseid=${this.id}&userid=${this.userid}&oid=${this.oid}&org=${this.org}&cid=${this.tcid}&type=${this.tType}`;
  147. this.iframeSrc = _url;
  148. this.showIframe = true;
  149. });
  150. },
  151. arrayToArray(arrayo, arrayt) {
  152. let array1 = arrayo;
  153. let array2 = arrayt;
  154. let commonElements = [];
  155. for (let i = 0; i < array1.length; i++) {
  156. for (let j = 0; j < array2.length; j++) {
  157. if (array1[i] === array2[j]) {
  158. commonElements.push(array1[i]);
  159. }
  160. }
  161. }
  162. return commonElements;
  163. },
  164. async getClassName() {
  165. let courseGrade = await this.ajax.get(this.$store.state.api + "getClassById", { id: this.tcid2 });
  166. this.className = courseGrade.data[0][0].grade;
  167. },
  168. back() {
  169. if (this.tType != 2) {
  170. this.goTo(
  171. '/courseDetail?userid=' +
  172. this.userid +
  173. '&oid=' +
  174. this.oid +
  175. '&org=' +
  176. this.org +
  177. '&cid=' +
  178. this.classId +
  179. '&courseId=' +
  180. this.id +
  181. '&tType=' +
  182. this.tType +
  183. '&screenType=' +
  184. this.screenType
  185. )
  186. } else {
  187. this.goTo(
  188. '/index?userid=' +
  189. this.userid +
  190. '&oid=' +
  191. this.oid +
  192. '&org=' +
  193. this.org +
  194. '&cid=' +
  195. this.classId +
  196. '&tType=' +
  197. this.tType +
  198. '&screenType=' +
  199. this.screenType
  200. )
  201. }
  202. },
  203. afterClass() {
  204. this.$confirm('此操作将使当前课程内所有学生退出登录,是否继续?', '提示', {
  205. confirmButtonText: '确定',
  206. cancelButtonText: '取消',
  207. type: 'warning'
  208. }).then(() => {
  209. this.$refs.ppt.contentWindow.PPTistStudent.forceLogout();
  210. }).catch(() => {});
  211. },
  212. onFreeBrowseChange(value) {
  213. this.freeBrowse = value;
  214. console.log('自由浏览模式已切换为1:', this.freeBrowse);
  215. this.$refs.ppt.contentWindow.PPTistStudent.toggleFollowMode()
  216. },
  217. setOperationTime() {
  218. let _this = this;
  219. if (_this.opertimer) {
  220. clearInterval(_this.opertimer);
  221. _this.opertimer = null;
  222. }
  223. _this.opertimer = setInterval(() => {
  224. _this.setoTime("600");
  225. }, 600000);
  226. },
  227. setoTime(time) {
  228. let params = [
  229. {
  230. uid: this.userid,
  231. cid: this.id,
  232. type: "2",
  233. time: time,
  234. },
  235. ];
  236. this.ajax
  237. .post(this.$store.state.api + "addOperationTimeT2", params)
  238. .then((res) => {})
  239. .catch((err) => {
  240. console.error(err);
  241. });
  242. },
  243. },
  244. destroyed() {
  245. clearInterval(this.opertimer);
  246. this.opertimer = null;
  247. if (this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840') {
  248. let endTime = new Date().toLocaleString("zh-CN", {
  249. hour12: false,
  250. timeZone: "Asia/Shanghai"
  251. }).replace(/\//g, "-")
  252. let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
  253. this.syncClassData({
  254. courseId: this.id,
  255. title: this.courseDetail.title,
  256. courseGrade: this.tcid2 ? this.tcid2 : '',
  257. courseTime: courseTime,
  258. startTime: this.startTime,
  259. endTime: endTime,
  260. })
  261. console.log('同步数据')
  262. }
  263. },
  264. mounted() {
  265. this.startTime = new Date().toLocaleString("zh-CN", {
  266. hour12: false,
  267. timeZone: "Asia/Shanghai"
  268. }).replace(/\//g, "-")
  269. this.getClassName()
  270. this.getCourseDetail();
  271. this.setOperationTime();
  272. window.onFreeBrowseChange = (value) => {
  273. this.freeBrowse = value;
  274. console.log('自由浏览模式已切换为:', this.freeBrowse);
  275. }
  276. }
  277. };
  278. </script>
  279. <style scoped>
  280. .pptEasyClass {
  281. width: 100vw;
  282. height: 100vh;
  283. display: flex;
  284. flex-direction: column;
  285. overflow: hidden;
  286. box-sizing: border-box;
  287. background-color: #f2f2f2;
  288. }
  289. .pec_main {
  290. width: 100%;
  291. height: 100%;
  292. background-color: #fff;
  293. }
  294. .pec_header {
  295. width: 100%;
  296. height: 50px;
  297. background: #FCCF00;
  298. box-sizing: border-box;
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. position: relative;
  303. box-shadow: 0px 4px 12px 0px #3648601F;
  304. padding: 0 10px;
  305. box-sizing: border-box;
  306. }
  307. .pec_h_left {
  308. width: auto;
  309. height: 100%;
  310. display: flex;
  311. align-items: center;
  312. gap: 25px;
  313. /* 保持左侧靠左 */
  314. }
  315. .pec_h_center {
  316. position: absolute;
  317. left: 50%;
  318. top: 0;
  319. height: 100%;
  320. display: flex;
  321. align-items: center;
  322. transform: translateX(-50%);
  323. z-index: 1;
  324. }
  325. .pec_h_l_title {
  326. font-weight: bold;
  327. font-size: 20px;
  328. color: #0e1e33;
  329. }
  330. .pec_h_right {
  331. width: auto;
  332. height: 100%;
  333. display: flex;
  334. align-items: center;
  335. }
  336. .pec_h_r_btnArea {
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. }
  341. .pec_h_r_btnArea>div {
  342. width: auto;
  343. height: auto;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. padding: 10px 20px;
  348. background-color: #f0f4fa;
  349. border-radius: 4px;
  350. cursor: pointer;
  351. font-size: 14px;
  352. font-weight: 400;
  353. color: #000;
  354. border: 1px solid #cad1dc;
  355. }
  356. .pec_h_r_btnArea>div>img {
  357. width: 15px;
  358. height: 15px;
  359. margin-right: 5px;
  360. }
  361. .pec_h_r_btnArea>.pec_h_r_btn_refresh {
  362. color: #fff;
  363. background-color: #0061ff;
  364. border-color: #0061ff;
  365. }
  366. .pec_h_r_btnArea>.pec_h_r_btn_afterClass {
  367. border-color: #F0E1DD;
  368. background-color: #FFF7F5;
  369. color: #F53F3F;
  370. }
  371. .backBtn {
  372. width: 15px;
  373. height: 15px;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. cursor: pointer;
  378. }
  379. .backBtn img {
  380. width: 100%;
  381. height: 100%;
  382. }
  383. .class-info-group {
  384. display: flex;
  385. align-items: center;
  386. gap: 10px;
  387. }
  388. .class-label {
  389. font-size: 18px;
  390. font-weight: bold;
  391. color: #222;
  392. margin-right: 5px;
  393. }
  394. .class-value {
  395. font-size: 16px;
  396. color: #222;
  397. background: #FFFFFF3D;
  398. border: 1px solid #00000080;
  399. border-radius: 5px;
  400. padding: 5px 18px;
  401. min-width: 60px;
  402. text-align: center;
  403. display: inline-block;
  404. box-sizing: border-box;
  405. }
  406. .pec_content {
  407. width: 100%;
  408. height: calc(100% - 50px);
  409. border-radius: 0 0 12px 12px;
  410. background-color: #fff;
  411. }
  412. .free-browse-switch {
  413. display: flex;
  414. align-items: center;
  415. padding: 9px 10px;
  416. background: #FFF7F5;
  417. border-radius: 26px;
  418. margin-left: 15px;
  419. gap: 5px;
  420. }
  421. .switch-label {
  422. background: linear-gradient(to right, #F53F3F, #FCCF00);
  423. -webkit-background-clip: text;
  424. color: transparent;
  425. }
  426. </style>