indexPS.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. <template>
  2. <div class="pptEasyClass">
  3. <div class="pec_main" v-loading="pageLoading">
  4. <!-- 录音转文字 -->
  5. <iframe allow="camera *; microphone *;display-capture;midi;encrypted-media;" :src="iframeSrcop" ref="iiframe"
  6. v-show="false"></iframe>
  7. <div class="pec_header">
  8. <div class="pec_h_left">
  9. <!-- || tType == 1 -->
  10. <div @click.stop="back" class="backBtn" v-if="screenType != 2">
  11. <img src="../../assets/icon/newIcon/return.svg" alt="" />
  12. </div>
  13. <div @click.stop="gotoCourseManage" class="backBtn" v-if="screenType == 2 && tType == 1">
  14. <img src="../../assets/icon/newIcon/return.svg" alt="" />
  15. </div>
  16. <div v-if="tcid" class="class-info-group">
  17. <span class="class-label">{{ lang.ssClass }}</span>
  18. <span class="class-value class-value2" @click="openSelectClass">
  19. {{ className }}
  20. <svg t="1776672009773" class="xia-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
  21. p-id="4735" xmlns:xlink="http://www.w3.org/1999/xlink" width="12" height="12">
  22. <path
  23. d="M562.5 771c-14.3 14.3-33.7 27.5-52 23.5-18.4 3.1-35.7-11.2-50-23.5L18.8 327.3c-22.4-22.4-22.4-59.2 0-81.6s59.2-22.4 81.6 0L511.5 668l412.1-422.3c22.4-22.4 59.2-22.4 81.6 0s22.4 59.2 0 81.6L562.5 771z"
  24. p-id="4736" fill="currentColor"></path>
  25. </svg>
  26. </span>
  27. </div>
  28. <div v-if="tcid" class="class-info-group">
  29. <span class="class-label" v-if="inviteCode">{{ lang.ssInviteCode }}</span>
  30. <span class="class-value" v-if="inviteCode">{{ inviteCode }}</span>
  31. </div>
  32. <div @click.stop="openShareDialog" class="shareBtn" v-if="tcid && tType == 1">
  33. <img src="../../assets/share.svg" alt="" />
  34. </div>
  35. </div>
  36. <div class="pec_h_center">
  37. <el-tooltip effect="dark" :content="lang.ssRefresh" placement="bottom">
  38. <div class="refresh_icon" @click="refreshCourse">
  39. <img src="../../assets/icon/course/refresh-2.svg" />
  40. </div>
  41. </el-tooltip>
  42. <el-tooltip class="item" effect="dark"
  43. :content="recordedForm.status == 1 ? lang.ssFinishClassRecording : lang.ssBeginClassRecording"
  44. placement="bottom"
  45. v-show="(jArray.includes(oid) || jArray.includes(org)) && courseDetail.userid == userid && tcid">
  46. <div class="pec_h_r_btn_refresh" :class="{ 'recording': recordedForm.status == 1 }"
  47. @click="toggleRecording">
  48. <svg t="1772588344140" viewBox="0 0 1024 1024" p-id="1693" width="200" height="200">
  49. <path
  50. d="M512 1024a512.568889 512.568889 0 0 1-512-512 512.625778 512.625778 0 0 1 512-512 512.568889 512.568889 0 0 1 512 512 512.568889 512.568889 0 0 1-512 512zM512 73.329778c-241.948444 0-438.670222 196.835556-438.670222 438.670222S270.051556 950.670222 512 950.670222s438.670222-196.835556 438.670222-438.670222S753.948444 73.329778 512 73.329778z m0 686.592a245.191111 245.191111 0 1 1 0-490.382222 245.191111 245.191111 0 0 1 0 490.382222z"
  51. p-id="1694"></path>
  52. </svg>
  53. <span>{{ recordedForm.status == 1 ? lang.ssStopRecording2 : lang.ssRecord }}</span>
  54. </div>
  55. </el-tooltip>
  56. <el-tooltip effect="dark" :content="courseDetail.title" placement="bottom">
  57. <div class="pec_h_l_title">
  58. <span>{{ courseDetail.title }}</span>
  59. </div>
  60. </el-tooltip>
  61. <div class="free-browse-switch" v-if="courseDetail.userid == userid">
  62. <el-switch v-model="freeBrowse" :active-value="false" :inactive-value="true" class="custom-switch"
  63. active-color="#03ae2b" inactive-color="#d8d8d8" @change="onFreeBrowseChange"></el-switch>
  64. <span class="switch-label" :class="{ active: freeBrowse }">{{ freeBrowse ? lang.ssFreeBrowse :
  65. lang.ssFollowMode }}</span>
  66. </div>
  67. <div class="free-browse-switch" v-if="tType == 2">
  68. <span class="switch-label" :class="{ active: freeBrowse }">{{ freeBrowse ? lang.ssFreeBrowse :
  69. lang.ssFollowMode }}</span>
  70. </div>
  71. </div>
  72. <div class="pec_h_right">
  73. <div class="pec_h_r_btnArea">
  74. <!-- openObserveDialog -->
  75. <!-- toggleRecording -->
  76. <div class="pec_h_r_btn_uploadVoiceBtn" @click="uploadVoiceBtn" v-if="courseDetail.userid == userid"
  77. v-show="false">
  78. <span>{{ lang.ssUploadRecordingFile }}</span>
  79. </div>
  80. <div class="pec_h_r_btn_afterClass" @click="afterClass" v-if="courseDetail.userid == userid">
  81. <img src="../../assets/icon/newIcon/afterClass.svg" alt="" />
  82. <span>{{ lang.ssEndClass }}</span>
  83. </div>
  84. <div class="name_box" v-if="tType == 2">
  85. {{ userJson.username }}
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="pec_content">
  91. <iframe allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read"
  92. webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" frameborder="no" border="0" :src="iframeSrc"
  93. v-if="showIframe" style="width: 100%; height: 100%; border: none" ref="ppt"></iframe>
  94. </div>
  95. </div>
  96. <!-- 课堂观察弹窗 -->
  97. <el-dialog :visible.sync="showObserveDialog" :close-on-click-modal="false" :close-on-press-escape="false"
  98. :show-close="true" width="90%" top="5vh" class="observe-dialog">
  99. <iframe v-if="showObserveDialog" :src="observeDialogUrl" frameborder="0"
  100. style="width: 100%; height: 85vh; border: none;"></iframe>
  101. </el-dialog>
  102. <selectTeachingClassDialog :courseDetail="courseDetail" :userId="userid" ref="selectTeachingClassDialogRef" @success="selectClassSuccess" @changeClassList="changeClassList"/>
  103. <!-- 消息提示组件 -->
  104. <messageInstruction ref="messageInstructionRef"></messageInstruction>
  105. <!-- 确认提示组件 -->
  106. <confirmInstruction ref="confirmInstructionRef"></confirmInstruction>
  107. <!-- 分享弹窗 -->
  108. <shareDialog ref="shareDialogRef"></shareDialog>
  109. </div>
  110. </template>
  111. <script>
  112. import { myMixin } from '../../mixins/mixin';
  113. import selectTeachingClassDialog from "../dialog/selectTeachingClassDialog2.vue";
  114. import messageInstruction from '../components/messageInstruction.vue';
  115. import confirmInstruction from '../components/confirmInstruction.vue';
  116. import shareDialog from './shareDialog.vue';
  117. export default {
  118. mixins: [myMixin],
  119. components: {
  120. messageInstruction,
  121. confirmInstruction,
  122. selectTeachingClassDialog,
  123. shareDialog
  124. },
  125. data() {
  126. return {
  127. id: this.$route.query.courseId,
  128. userid: this.$route.query.userid,
  129. classId: this.$route.query.cid,
  130. role: this.$route.query.role,
  131. oid: this.$route.query.oid,
  132. org: this.$route.query.org,
  133. tType: this.$route.query.tType,
  134. courseType: this.$route.query.type,
  135. screenType: this.$route.query.screenType,
  136. tcid2: this.$route.query.tcid,
  137. classList: [],
  138. tcid: "",
  139. className: "",
  140. showIframe: false,
  141. iframeSrc: "",
  142. courseDetail: {},
  143. pageLoading: false,
  144. inviteCode: "",
  145. startTime: "",
  146. freeBrowse: true, // 默认自由浏览
  147. opertimer: null, // 定时器
  148. jArray: [],
  149. // 录音相关变量
  150. languageRadio: 2, // 语言选择
  151. recordedForm: {
  152. status: 0, // 0: 未开始, 1: 录音中, 2: 暂停, 3: 结束
  153. startTime: 0,
  154. endTime: 0,
  155. timeDuration: 0,
  156. textList: [],
  157. audioBlob: []
  158. },
  159. controlsStatus: 0, // 控制状态
  160. showIndexPage: true, // 显示索引页
  161. pageStatus: 1, // 页面状态
  162. editorBarData: {
  163. type: "0",
  164. content: ""
  165. },
  166. uploadFileLoading: false, // 上传文件加载状态
  167. transcriptionData: {
  168. content: ""
  169. },
  170. showGetTextLoading: false, // 显示获取文本加载状态
  171. // 弹窗相关
  172. showObserveDialog: false, // 显示课堂观察弹窗
  173. observeDialogUrl: "", // 课堂观察链接
  174. // 录音时间记录
  175. recordingStartTime: "", // 开始录音时间
  176. recordingEndTime: "", // 结束录音时间
  177. };
  178. },
  179. computed: {
  180. iframeSrcop() {
  181. if (this.$region == 'hk') {
  182. return `https://cloud.cocorobo.hk/browser/public/index.html`;
  183. } else if (this.$region == 'com') {
  184. return `https://cloud.cocorobo.com/browser/public/index.html`;
  185. } else {
  186. return `https://beta.cloud.cocorobo.cn/browser/public/index.html`;
  187. }
  188. }
  189. },
  190. methods: {
  191. openSelectClass(){
  192. this.$refs.selectTeachingClassDialogRef.open({classList:this.classList}, this.tcid2)
  193. },
  194. addInviteCodeOne(cid) {
  195. return new Promise((resolve)=>{
  196. let params = [
  197. {
  198. courseId: this.id,
  199. inviteCode: cid,
  200. },
  201. ];
  202. this.ajax
  203. .post(this.$store.state.api + "add_courseInviteCode2", params)
  204. .then((res) => {
  205. console.log(res.data)
  206. resolve(res.data)
  207. })
  208. .catch((err) => {
  209. resolve(err.messages)
  210. console.error(err);
  211. });
  212. })
  213. },
  214. async selectClassSuccess(classId){
  215. if(classId){
  216. let data = await this.addInviteCodeOne(classId)
  217. console.log("addInviteCodeOne",data)
  218. this.tcid2 = classId
  219. this.getClassName()
  220. this.getCourseDetail();
  221. }else if(this.tcid2){
  222. this.ticd2 = ''
  223. this.getCourseDetail();
  224. }
  225. // this.gotoCourse(classId);
  226. this.$refs.selectTeachingClassDialogRef.close();
  227. this.setoTime("1");
  228. },
  229. async changeClassList(data){
  230. this.classList = JSON.parse(JSON.stringify(data))
  231. let params = [{
  232. cid:this.id,
  233. juri:this.classList.map(i=>i.id).join(',')
  234. }]
  235. this.ajax.post(this.$store.state.api+"update_CourseJuriById",params).then(res=>{
  236. if(res.data==1){
  237. console.log(this.lang.ssModifySuccess)
  238. }
  239. })
  240. //this.inviteCodeFn();
  241. },
  242. goTo(path) {
  243. this.$router.push(path);
  244. },
  245. refreshCourse() {
  246. this.getCourseDetail();
  247. },
  248. audioStart() {
  249. this.onStartRecordWithMicrosoft();
  250. },
  251. toggleRecording() {
  252. return new Promise(resolve => {
  253. if (this.recordedForm.status == 1) {
  254. // 检查录音时间是否至少为5秒
  255. const now = new Date();
  256. const duration = (now - new Date(this.recordingStartTime)) / 1000;
  257. if (duration < 5) {
  258. this.$message.warning(this.lang.ssRecordingTimeAtLeast5Seconds);
  259. return;
  260. }
  261. this.$refs.confirmInstructionRef.open({
  262. title: this.lang.ssStopRecordingConfirm,
  263. message: this.lang.ssStopRecordingNotice,
  264. cancelText: this.lang.ssCancel,
  265. submitText: this.lang.ssConfirm,
  266. submitCallback: () => {
  267. console.log("确定")
  268. this.onFinishRecordWithMicrosoft().then(() => {
  269. resolve(true)
  270. });
  271. },
  272. cancelCallback: () => {
  273. console.log("取消")
  274. resolve(false)
  275. },
  276. })
  277. // this.$confirm(this.lang.ssStopRecordingNotice, this.lang.ssStopRecordingConfirm, {
  278. // confirmButtonText: this.lang.ssConfirm,
  279. // cancelButtonText: this.lang.ssCancel,
  280. // confirmButtonClass: "pptEasyClassConfirmButtonText",
  281. // cancelButtonClass: "pptEasyClassCancelButtonText"
  282. // }).then(() => {
  283. // console.log("确定")
  284. // // this.$message({
  285. // // dangerouslyUseHTMLString: true,
  286. // // customClass:"pptEasyClassMessage",
  287. // // message: '已停止录制 <p style="color:#3AB855;text-decoration: underline;cursor: pointer;float:right;margin-left:10px" target="_blank">查看结果</p>'
  288. // // });
  289. // this.onFinishRecordWithMicrosoft().then(() => {
  290. // resolve(true)
  291. // });
  292. // }).catch(() => {
  293. // console.log("取消")
  294. // resolve(false)
  295. // });
  296. } else {
  297. const now = new Date();
  298. const duration = (now - new Date(this.recordingEndTime)) / 1000;
  299. if (duration < 5) {
  300. this.$message.warning('录音时间至少间距5秒');
  301. return;
  302. }
  303. this.onStartRecordWithMicrosoft();
  304. resolve(true)
  305. }
  306. })
  307. // })
  308. },
  309. // ============ start 微软录音转译
  310. onStartRecordWithMicrosoft() {
  311. let iiframe = this.$refs["iiframe"];
  312. iiframe.contentWindow.window.document.getElementById(
  313. "languageOptions"
  314. ).selectedIndex = this.languageRadio;
  315. // 录音开始
  316. let flag = true;
  317. console.log("开始录音", iiframe);
  318. this.recordedForm.status = 1;
  319. // 记录开始录音时间
  320. this.recordingStartTime = new Date().toLocaleString("zh-CN", {
  321. hour12: false,
  322. timeZone: "Asia/Shanghai"
  323. }).replace(/\//g, "-");
  324. iiframe.contentWindow.window.onRecognizedResult = e => {
  325. console.log("onRecognizedResult", e);
  326. this.recordedForm.endTime = this.recordedForm.timeDuration;
  327. if (flag) {
  328. this.controlsStatus = 1;
  329. this.showIndexPage = false;
  330. this.pageStatus = 2;
  331. this.editorBarData.type = "0";
  332. flag = false;
  333. this.uploadFileLoading = false;
  334. this.transcriptionData.content = "";
  335. this.editorBarData.content = "";
  336. this.recordedForm.textList = [];
  337. }
  338. this.showGetTextLoading = true;
  339. let privText = e.privText;
  340. let privSpeakerId = e.privSpeakerId;
  341. let _copyPrivSpeakerId = privSpeakerId;
  342. console.log("👇转译对象👇");
  343. console.log(e);
  344. console.log("👇转译结果👇");
  345. console.log(privText);
  346. if (!privText || !privSpeakerId || privSpeakerId == "Unknown") {
  347. return;
  348. }
  349. const newItem = {
  350. value: privText,
  351. role: "",
  352. startTime: this.updateRecordedTime({
  353. duration: this.recordedForm.startTime
  354. }),
  355. endTime: this.updateRecordedTime({
  356. duration: this.recordedForm.endTime
  357. }),
  358. time: this.updateRecordedTime({
  359. duration: this.recordedForm.endTime - this.recordedForm.startTime
  360. })
  361. };
  362. this.recordedForm.textList.push(newItem);
  363. this.recordedForm.startTime = this.recordedForm.timeDuration + 1;
  364. this.transcriptionData.content +=
  365. _copyPrivSpeakerId + ":" + privText + "\n";
  366. this.onRecordAddLine(newItem);
  367. };
  368. iiframe.contentWindow.ConversationTranscriber();
  369. setTimeout(() => {
  370. navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(permissionStatus => {
  371. if (permissionStatus.state !== "granted") {
  372. // 没有开启录音权限,直接确定停止录音
  373. this.recordedForm.status = "0";
  374. let iframe = this.$refs["iiframe"];
  375. iframe.contentWindow.onSessionStopped = null;
  376. iframe.contentWindow.window.onRecognizedResult = null;
  377. this.$message.success(this.lang.ssNoPermStop);
  378. return;
  379. }
  380. })
  381. }, 10000)
  382. },
  383. async onFinishRecordWithMicrosoft() {
  384. return new Promise(resolve => {
  385. navigator.permissions && navigator.permissions.query({ name: 'microphone' }).then(async permissionStatus => {
  386. if (permissionStatus.state !== "granted") {
  387. // 没有开启录音权限,直接确定停止录音
  388. this.recordedForm.status = "0";
  389. let iframe = this.$refs["iiframe"];
  390. iframe.contentWindow.onSessionStopped = null;
  391. iframe.contentWindow.window.onRecognizedResult = null;
  392. this.$message.success(this.lang.ssNoPermStop);
  393. return;
  394. }
  395. if (this.recordedForm.status == 1) {
  396. //正在录音时
  397. let iiframe = this.$refs["iiframe"];
  398. iiframe.contentWindow.window.document
  399. .getElementById("scenarioStopButton")
  400. .click();
  401. // 录音借宿
  402. iiframe.contentWindow.onSessionStopped = async (s, e) => {
  403. this.recordedForm.status = 0;
  404. this.controlsStatus = 2;
  405. this.showGetTextLoading = false;
  406. // this.$message.success("已结束录音");
  407. console.log("结束录音👇");
  408. console.log("结束录音", e);
  409. this.recordedForm.audioBlob.push(e.preaudio);
  410. let blob = new Blob(this.recordedForm.audioBlob, {
  411. type: "audio/wav"
  412. });
  413. let file = new File([blob], "recordedFile.wav", {
  414. type: "audio/wav"
  415. });
  416. // 存储文件和文本到全局对象
  417. await this.storeRecordingData(file);
  418. // 记录结束录音时间
  419. this.recordingEndTime = new Date().toLocaleString("zh-CN", {
  420. hour12: false,
  421. timeZone: "Asia/Shanghai"
  422. }).replace(/\//g, "-");
  423. // 调用 addPPTClass 接口
  424. this.addPPTClass(file);
  425. iiframe.contentWindow.onSessionStopped = null;
  426. iiframe.contentWindow.window.onRecognizedResult = null;
  427. resolve(true)
  428. };
  429. } else if (this.recordedForm.status == 2) {
  430. //暂停录音时
  431. this.recordedForm.status = 0;
  432. this.controlsStatus = 2;
  433. this.showGetTextLoading = false;
  434. let blob = new Blob(this.recordedForm.audioBlob, {
  435. type: "audio/wav"
  436. });
  437. let file = new File([blob], "recordedFile.wav", { type: "audio/wav" });
  438. // 存储文件和文本到全局对象
  439. await this.storeRecordingData(file);
  440. // 记录结束录音时间
  441. this.recordingEndTime = new Date().toLocaleString("zh-CN", {
  442. hour12: false,
  443. timeZone: "Asia/Shanghai"
  444. }).replace(/\//g, "-");
  445. // 调用 addPPTClass 接口
  446. this.addPPTClass(file);
  447. resolve(true)
  448. }
  449. })
  450. })
  451. },
  452. storeRecordingData(file) {
  453. // 配置全局 window 对象存储录音数据
  454. return new Promise((resolve) => {
  455. if (!window.recordingData) {
  456. window.recordingData = {};
  457. }
  458. window.recordingData.file = file;
  459. window.recordingData.text = this.transcriptionData.content;
  460. window.recordingData.textList = this.recordedForm.textList;
  461. // 将录音文件转为base64并存入localStorage
  462. // const reader = new FileReader();
  463. // reader.onload = function(e) {
  464. // const base64data = e.target.result;
  465. // try {
  466. // localStorage.setItem("recordedFileBase64", base64data);
  467. // localStorage.setItem('recordedFileName', file.name);
  468. // localStorage.setItem('recordedFileType', file.type);
  469. resolve(true)
  470. // console.log("录音数据已存储到全局对象:", window.recordingData);
  471. // } catch (err) {
  472. // resolve(false)
  473. // console.error("localStorage存储base64文件失败:", err);
  474. // }
  475. // };
  476. // reader.readAsDataURL(file);
  477. })
  478. },
  479. openObserveDialog(pptid, file) {
  480. // this.observeDialogUrl = `https://observe.cocorobo.cn/#/newClassroom?userid=${this.userid}&oid=${this.oid}&org=${this.org}&pptid=${pptid}`;
  481. // this.showObserveDialog = true;
  482. const url = `https://observe.cocorobo.cn/#/newClassroom?userid=${this.userid}&oid=${this.oid}&org=${this.org}&pptid=${pptid}`;
  483. const _pageWindow = window.open(url, '_blank');
  484. // if(!_pageWindow){
  485. // alert('浏览器弹窗被拦截,请允许弹窗后重试');
  486. // return;
  487. // }
  488. const sendData = {
  489. type: 'fileData',
  490. file,
  491. }
  492. const sendMessageToVue3 = () => {
  493. _pageWindow.postMessage(
  494. sendData,
  495. '*' // targetOrigin:必须是Vue3的实际域名,不要用*(安全)
  496. );
  497. };
  498. const handleVue3Ready = (e) => {
  499. // 校验消息来源(安全:只处理Vue3域名的消息)
  500. // 校验消息类型(确认是Vue3的就绪通知)
  501. if (e.data.type === 'READY') {
  502. console.log('已就绪,开始发送数据');
  503. sendMessageToVue3();
  504. }
  505. // 校验Vue3的"接收成功"确认(可选,进一步确保送达)
  506. if (e.data.type === 'DATA_RECEIVED') {
  507. console.log('数据已被接收');
  508. // 收到确认后移除监听,避免内存泄漏
  509. window.removeEventListener('message', handleVue3Ready);
  510. }
  511. };
  512. window.addEventListener('message', handleVue3Ready);
  513. const timeoutTimer = setTimeout(() => {
  514. console.log('未收到就绪通知,主动发送数据');
  515. sendMessageToVue3();
  516. // 移除监听(兜底后清理)
  517. window.removeEventListener('message', handleVue3Ready);
  518. }, 5000);
  519. const checkWinClosed = setInterval(() => {
  520. if (_pageWindow.closed) {
  521. clearTimeout(timeoutTimer);
  522. clearInterval(checkWinClosed);
  523. window.removeEventListener('message', handleVue3Ready);
  524. }
  525. }, 1000);
  526. // 优化:仅通过轮询方式检查窗口是否加载完成并发送消息,被打开页面无需做任何处理
  527. // const sendFileData = () => {
  528. // if (_pageWindow && !_pageWindow.closed) {
  529. // _pageWindow.postMessage(
  530. // {
  531. // type: 'fileData',
  532. // file,
  533. // },
  534. // '*'
  535. // );
  536. // }
  537. // };
  538. // let checkCount = 0;
  539. // const checkLoadedInterval = setInterval(() => {
  540. // if (!_pageWindow || _pageWindow.closed) {
  541. // clearInterval(checkLoadedInterval);
  542. // return;
  543. // }
  544. // try {
  545. // if (_pageWindow.document && _pageWindow.document.readyState === 'complete') {
  546. // clearInterval(checkLoadedInterval);
  547. // sendFileData();
  548. // }
  549. // } catch (err) {
  550. // // 跨域下直接尝试发送
  551. // clearInterval(checkLoadedInterval);
  552. // sendFileData();
  553. // }
  554. // if (++checkCount > 20) {
  555. // // 最多检测2秒(20次)
  556. // clearInterval(checkLoadedInterval);
  557. // sendFileData();
  558. // }
  559. // }, 100);
  560. setTimeout(() => {
  561. window.focus()
  562. }, 100)
  563. function openPageWindow() {
  564. _pageWindow.focus()
  565. }
  566. this.$refs.messageInstructionRef.pptMessage(`${this.lang.ssStoppedRecording} <p style="color:#3AB855;text-decoration: underline;cursor: pointer;float:right;margin-left:10px" target="_blank" onClick="(${openPageWindow.toString()})()">${this.lang.ssViewRecordingResult}</p>`)
  567. },
  568. addPPTClass(file) {
  569. let params = {
  570. pptid: this.id,
  571. cid: this.tcid,
  572. st: this.recordingStartTime,
  573. et: this.recordingEndTime
  574. };
  575. this.ajax
  576. .post(this.$store.state.api + "addPPTClass", [params])
  577. .then(res => {
  578. console.log("addPPTClass", res);
  579. let id = res.data[0][0].id;
  580. this.openObserveDialog(id, file);
  581. })
  582. .catch(err => {
  583. console.error(err);
  584. this.$message.error("保存录音信息失败");
  585. });
  586. },
  587. updateRecordedTime({ duration }) {
  588. // 格式化录音时间
  589. const minutes = Math.floor(duration / 60);
  590. const seconds = Math.floor(duration % 60);
  591. return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  592. },
  593. onRecordAddLine(item) {
  594. // 添加录音文本行
  595. console.log("添加录音文本行:", item);
  596. // 这里可以根据需要添加更多处理逻辑
  597. },
  598. getCourseDetail() {
  599. this.pageLoading = true;
  600. let params = {
  601. courseId: this.id
  602. };
  603. this.ajax
  604. .get(this.$store.state.api + "selectCourseDetail3", params)
  605. .then(res => {
  606. console.log("getCourseDetail", res);
  607. this.courseDetail = res.data[0][0];
  608. this.courseDetail.chapters = JSON.parse(this.courseDetail.chapters);
  609. this.tcid = this.arrayToArray(
  610. this.courseDetail.juri ? this.courseDetail.juri.split(",") : [],
  611. this.tcid2 ? this.tcid2.split(",") : []
  612. )[0] || "";
  613. console.log('tcid', this.tcid)
  614. console.log('tcid2', this.tcid2)
  615. if (this.tcid && res.data[1].length) {
  616. let _inviteA = [];
  617. for (var ik = 0; ik < res.data[1].length; ik++) {
  618. _inviteA.push({
  619. cid: res.data[1][ik].classid,
  620. ic: res.data[1][ik].code,
  621. });
  622. }
  623. for (var ik = 0; ik < _inviteA.length; ik++) {
  624. if (
  625. this.arrayToArray(
  626. _inviteA[ik].cid.split(","),
  627. this.tcid.split(",")
  628. ).length
  629. ) {
  630. this.inviteCode = _inviteA[ik].ic;
  631. break;
  632. }
  633. }
  634. }
  635. this.setPptIframe()
  636. this.classList = res.data[2]
  637. if(!this.tcid2 && this.tType == '1'){
  638. this.$refs.selectTeachingClassDialogRef.open({classList:this.classList})
  639. }
  640. this.pageLoading = false;
  641. })
  642. .catch(err => {
  643. console.log(err);
  644. this.$message.error(this.lang.ssGetCourseDataFail);
  645. this.pageLoading = false;
  646. });
  647. },
  648. setPptIframe() {
  649. this.showIframe = false;
  650. this.$nextTick(() => {
  651. let api = 'https://psyy.cocorobo.cn/'
  652. // if (this.$region == 'beta') {
  653. // api = 'https://beta.ppt.cocorobo.cn'
  654. // } else if (this.$region == 'hk') {
  655. // api = 'https://ppt.cocorobo.hk'
  656. // } else if (this.$region == 'com') {
  657. // api = 'https://ppt.cocorobo.com'
  658. // } else {
  659. // api = 'https://ppt.cocorobo.cn'
  660. // }
  661. let _url = api + `/?mode=student&courseid=${this.id}&userid=${this.userid}&oid=${this.oid}&org=${this.org}&cid=${this.tcid}&type=${this.tType}`;
  662. this.iframeSrc = _url;
  663. this.showIframe = true;
  664. });
  665. },
  666. arrayToArray(arrayo, arrayt) {
  667. let array1 = arrayo;
  668. let array2 = arrayt;
  669. let commonElements = [];
  670. for (let i = 0; i < array1.length; i++) {
  671. for (let j = 0; j < array2.length; j++) {
  672. if (array1[i] === array2[j]) {
  673. commonElements.push(array1[i]);
  674. }
  675. }
  676. }
  677. return commonElements;
  678. },
  679. async getClassName() {
  680. let courseGrade = await this.ajax.get(this.$store.state.api + "getClassById", { id: this.tcid2 });
  681. this.className = courseGrade.data[0][0].grade;
  682. },
  683. back() {
  684. // if (this.tType != 2) {
  685. // this.goTo(
  686. // '/courseDetail?userid=' +
  687. // this.userid +
  688. // '&oid=' +
  689. // this.oid +
  690. // '&org=' +
  691. // this.org +
  692. // '&cid=' +
  693. // this.classId +
  694. // '&courseId=' +
  695. // this.id +
  696. // '&tType=' +
  697. // this.tType +
  698. // '&screenType=' +
  699. // this.screenType
  700. // )
  701. // } else {
  702. this.goTo(
  703. '/index?userid=' +
  704. this.userid +
  705. '&oid=' +
  706. this.oid +
  707. '&org=' +
  708. this.org +
  709. '&cid=' +
  710. this.classId +
  711. '&tType=' +
  712. this.tType +
  713. '&screenType=' +
  714. this.screenType
  715. )
  716. // }
  717. },
  718. gotoCourseManage(){
  719. parent.setCourseUrl();
  720. },
  721. afterClass() {
  722. if (this.recordedForm.status == 1) {
  723. this.toggleRecording().then((flag) => {
  724. if (flag) {
  725. this.$refs.confirmInstructionRef.open({
  726. title: this.lang.ssPrompt,
  727. message: this.lang.ssEndClassConfirm,
  728. cancelText: this.lang.ssCancel,
  729. submitText: this.lang.ssConfirm,
  730. submitCallback: () => {
  731. this.$refs.ppt.contentWindow.PPTistStudent.forceLogout();
  732. this.$refs.messageInstructionRef.pptMessage(this.lang.ssStudentLoggedOut)
  733. setTimeout(() => {
  734. this.tcid2 = ""
  735. this.refreshCourse()
  736. }, 1000)
  737. },
  738. cancelCallback: () => {
  739. console.log("取消")
  740. }
  741. })
  742. // this.$confirm(this.lang.ssEndClassConfirm, this.lang.ssPrompt, {
  743. // confirmButtonText: this.lang.ssConfirm,
  744. // cancelButtonText: this.lang.ssCancel,
  745. // type: 'warning'
  746. // }).then(() => {
  747. // this.$refs.ppt.contentWindow.PPTistStudent.forceLogout();
  748. // this.$refs.messageInstructionRef.pptMessage(this.lang.ssStudentLoggedOut)
  749. // setTimeout(() => {
  750. // this.tcid2 = ""
  751. // this.refreshCourse()
  752. // }, 1000)
  753. // }).catch(() => { });
  754. }
  755. })
  756. } else {
  757. // this.$confirm(this.lang.ssEndClassConfirm, this.lang.ssPrompt, {
  758. // confirmButtonText: this.lang.ssConfirm,
  759. // cancelButtonText: this.lang.ssCancel,
  760. // type: 'warning'
  761. // }).then(() => {
  762. // this.$refs.ppt.contentWindow.PPTistStudent.forceLogout();
  763. // this.$refs.messageInstructionRef.pptMessage(this.lang.ssStudentLoggedOut)
  764. // setTimeout(() => {
  765. // this.tcid2 = ""
  766. // this.refreshCourse()
  767. // }, 1000)
  768. // }).catch(() => { });
  769. this.$refs.confirmInstructionRef.open({
  770. title: this.lang.ssPrompt,
  771. message: this.lang.ssEndClassConfirm,
  772. cancelText: this.lang.ssCancel,
  773. submitText: this.lang.ssConfirm,
  774. submitCallback: () => {
  775. this.$refs.ppt.contentWindow.PPTistStudent.forceLogout();
  776. this.$refs.messageInstructionRef.pptMessage(this.lang.ssStudentLoggedOut)
  777. setTimeout(() => {
  778. this.tcid2 = ""
  779. this.refreshCourse()
  780. }, 1000)
  781. },
  782. cancelCallback: () => {
  783. console.log("取消")
  784. }
  785. })
  786. }
  787. },
  788. onFreeBrowseChange(value) {
  789. this.freeBrowse = value;
  790. console.log('自由浏览模式已切换为1:', this.freeBrowse);
  791. this.$refs.ppt.contentWindow.PPTistStudent.toggleFollowMode()
  792. },
  793. setOperationTime() {
  794. let _this = this;
  795. if (_this.opertimer) {
  796. clearInterval(_this.opertimer);
  797. _this.opertimer = null;
  798. }
  799. _this.opertimer = setInterval(() => {
  800. _this.setoTime("600");
  801. }, 600000);
  802. },
  803. setoTime(time) {
  804. this.doSyncClassData();
  805. let params = [
  806. {
  807. uid: this.userid,
  808. cid: this.id + (this.tcid2 || ''),
  809. type: "2",
  810. time: time,
  811. },
  812. ];
  813. this.ajax
  814. .post(this.$store.state.api + "addOperationTimeT2", params)
  815. .then((res) => { })
  816. .catch((err) => {
  817. console.error(err);
  818. });
  819. },
  820. getAIJ() {
  821. this.ajax.get(this.$store.state.api + "getAIJ", "").then(res => {
  822. let a = res.data[4];
  823. console.log(a)
  824. let Array = [];
  825. a.forEach(i => Array.push(i.oid))
  826. this.jArray = Array;
  827. })
  828. },
  829. doSyncClassData() {
  830. if (this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840') {
  831. let endTime = new Date().toLocaleString("zh-CN", {
  832. hour12: false,
  833. timeZone: "Asia/Shanghai"
  834. }).replace(/\//g, "-")
  835. let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
  836. this.syncClassData({
  837. courseId: this.id,
  838. title: this.courseDetail.title,
  839. ctitle: this.courseDetail.copyTitle || this.courseDetail.title,
  840. courseGrade: this.tcid2 ? this.tcid2 : '',
  841. courseTime: courseTime,
  842. startTime: this.startTime,
  843. endTime: endTime,
  844. })
  845. console.log('同步数据')
  846. }
  847. },
  848. // 直接上传录制音频/视频
  849. uploadVoiceBtn() {
  850. const input = document.createElement('input');
  851. input.type = 'file';
  852. input.accept = '.m4a,.mp4,.mov,.mp3,.wav';
  853. input.click();
  854. input.onchange = (e) => {
  855. const fileList = e.target.files;
  856. const file = fileList[0]
  857. this.recordingStartTime = new Date(window.recordingStartTime ? window.recordingStartTime : new Date()).toLocaleString("zh-CN", {
  858. hour12: false,
  859. timeZone: "Asia/Shanghai"
  860. }).replace(/\//g, "-");
  861. this.recordingEndTime = new Date(window.recordingEndTime ? window.recordingEndTime : new Date()).toLocaleString("zh-CN", {
  862. hour12: false,
  863. timeZone: "Asia/Shanghai"
  864. }).replace(/\//g, "-");
  865. this.addPPTClass(file)
  866. // 判断文件类型并获取音频或视频时长
  867. // if (file && (file.type.startsWith('audio/') || file.type.startsWith('video/'))) {
  868. // const url = URL.createObjectURL(file);
  869. // let media;
  870. // if (file.type.startsWith('audio/')) {
  871. // media = new Audio();
  872. // } else {
  873. // media = document.createElement('video');
  874. // }
  875. // media.preload = 'metadata';
  876. // media.src = url;
  877. // media.onloadedmetadata = () => {
  878. // const duration = media.duration;
  879. // console.log('文件时长(秒):', duration);
  880. // // 这里可以赋值或者进一步处理时长 duration
  881. // URL.revokeObjectURL(url);
  882. // };
  883. // media.onerror = () => {
  884. // console.error('无法读取文件时长');
  885. // URL.revokeObjectURL(url);
  886. // };
  887. // }
  888. }
  889. },
  890. openShareDialog() {
  891. let code = this.userJson.oidCode || this.userJson.orgCode
  892. this.$refs.shareDialogRef.open(code, this.inviteCode)
  893. }
  894. },
  895. destroyed() {
  896. clearInterval(this.opertimer);
  897. this.opertimer = null;
  898. this.doSyncClassData();
  899. },
  900. async mounted() {
  901. this.setoTime("1");
  902. this.startTime = new Date().toLocaleString("zh-CN", {
  903. hour12: false,
  904. timeZone: "Asia/Shanghai"
  905. }).replace(/\//g, "-")
  906. this.getClassName()
  907. this.getAIJ();
  908. this.getCourseDetail();
  909. this.setOperationTime();
  910. window.onFreeBrowseChange = (value) => {
  911. this.freeBrowse = value;
  912. console.log('自由浏览模式已切换为:', this.freeBrowse);
  913. }
  914. if (!this.userJson || !this.userJson.accountNumber) {
  915. let res = await this.ajax.get(this.$store.state.api + "selectUser", {
  916. userid: this.$route.query.userid
  917. });
  918. this.userJson = res.data[0][0]
  919. }
  920. setTimeout(() => {
  921. this.doSyncClassData();
  922. }, 1000);
  923. }
  924. };
  925. </script>
  926. <style scoped>
  927. .pptEasyClass {
  928. width: 100vw;
  929. height: 100vh;
  930. display: flex;
  931. flex-direction: column;
  932. overflow: hidden;
  933. box-sizing: border-box;
  934. background-color: #f2f2f2;
  935. min-height: unset;
  936. }
  937. .pec_main {
  938. width: 100%;
  939. height: 100%;
  940. background-color: #fff;
  941. }
  942. .pec_header {
  943. width: 100%;
  944. height: 60px;
  945. background: #FCCF00;
  946. box-sizing: border-box;
  947. display: flex;
  948. align-items: center;
  949. justify-content: space-between;
  950. position: relative;
  951. box-shadow: 0px 4px 12px 0px #3648601F;
  952. padding: 0 10px;
  953. box-sizing: border-box;
  954. }
  955. .pec_h_left {
  956. width: auto;
  957. height: 100%;
  958. display: flex;
  959. align-items: center;
  960. gap: 25px;
  961. /* 保持左侧靠左 */
  962. }
  963. .pec_h_center {
  964. position: absolute;
  965. left: 50%;
  966. top: 0;
  967. height: 100%;
  968. display: flex;
  969. align-items: center;
  970. transform: translateX(-50%);
  971. z-index: 1;
  972. }
  973. .pec_h_l_title {
  974. font-weight: bold;
  975. font-size: 20px;
  976. color: #0e1e33;
  977. overflow: hidden;
  978. white-space: nowrap;
  979. max-width: 500px;
  980. text-overflow: ellipsis;
  981. }
  982. .pec_h_right {
  983. width: auto;
  984. height: 100%;
  985. display: flex;
  986. align-items: center;
  987. }
  988. .pec_h_r_btnArea {
  989. display: flex;
  990. align-items: center;
  991. justify-content: center;
  992. }
  993. .pec_h_r_btnArea>div {
  994. width: auto;
  995. height: auto;
  996. display: flex;
  997. align-items: center;
  998. justify-content: center;
  999. padding: 10px 20px;
  1000. background-color: #f0f4fa;
  1001. border-radius: 4px;
  1002. cursor: pointer;
  1003. font-size: 14px;
  1004. font-weight: 400;
  1005. color: #000;
  1006. border: 1px solid #cad1dc;
  1007. }
  1008. .pec_h_r_btnArea>div+div {
  1009. margin-left: 10px;
  1010. }
  1011. .pec_h_r_btnArea>div>img {
  1012. width: 15px;
  1013. height: 15px;
  1014. margin-right: 5px;
  1015. }
  1016. .pec_h_center>.pec_h_r_btn_refresh {
  1017. color: #fff;
  1018. /* background-color: #0061ff;
  1019. border-color: #0061ff; */
  1020. padding: 9px 10px;
  1021. margin-right: 15px;
  1022. border-radius: 26px;
  1023. display: flex;
  1024. align-items: center;
  1025. justify-content: center;
  1026. gap: 5px;
  1027. background: #FFF7F5;
  1028. color: #000000;
  1029. font-weight: 400;
  1030. cursor: pointer;
  1031. fill: #666666;
  1032. }
  1033. .pec_h_center>.pec_h_r_btn_refresh>svg {
  1034. width: 1rem;
  1035. height: 1rem;
  1036. }
  1037. .pec_h_center>.pec_h_r_btn_refresh.recording {
  1038. /* background-color: #F53F3F;
  1039. border-color: #F53F3F; */
  1040. background: #FFF7E8;
  1041. fill: #FF9300;
  1042. animation: pulse 1.5s infinite;
  1043. }
  1044. @keyframes pulse {
  1045. 0% {
  1046. box-shadow: 0 0 0 0 rgba(245, 63, 63, 0.4);
  1047. }
  1048. 70% {
  1049. box-shadow: 0 0 0 10px rgba(245, 63, 63, 0);
  1050. }
  1051. 100% {
  1052. box-shadow: 0 0 0 0 rgba(245, 63, 63, 0);
  1053. }
  1054. }
  1055. .pec_h_r_btnArea>.pec_h_r_btn_afterClass {
  1056. border-color: #F0E1DD;
  1057. background-color: #FFF7F5;
  1058. color: #F53F3F;
  1059. }
  1060. .pec_h_r_btn_uploadVoiceBtn {
  1061. border-color: #F0E1DD;
  1062. background-color: #FFF7F5;
  1063. color: #000;
  1064. }
  1065. .backBtn {
  1066. width: 15px;
  1067. height: 15px;
  1068. display: flex;
  1069. align-items: center;
  1070. justify-content: center;
  1071. cursor: pointer;
  1072. }
  1073. .backBtn img {
  1074. width: 100%;
  1075. height: 100%;
  1076. }
  1077. .shareBtn {
  1078. width: 25px;
  1079. height: 25px;
  1080. display: flex;
  1081. align-items: center;
  1082. justify-content: center;
  1083. cursor: pointer;
  1084. }
  1085. .shareBtn img {
  1086. width: 100%;
  1087. height: 100%;
  1088. }
  1089. .class-info-group {
  1090. display: flex;
  1091. align-items: center;
  1092. gap: 10px;
  1093. }
  1094. .class-label {
  1095. font-size: 18px;
  1096. font-weight: bold;
  1097. color: #222;
  1098. margin-right: 5px;
  1099. }
  1100. .class-value {
  1101. font-size: 16px;
  1102. color: #222;
  1103. background: #FFFFFF3D;
  1104. border: 1px solid #00000080;
  1105. border-radius: 5px;
  1106. padding: 5px 18px;
  1107. min-width: 60px;
  1108. text-align: center;
  1109. display: inline-block;
  1110. box-sizing: border-box;
  1111. display: flex;
  1112. align-items: center;
  1113. }
  1114. .class-value2 {
  1115. cursor: pointer;
  1116. background: #fff;
  1117. }
  1118. .class-value > svg{
  1119. width: 13px;
  1120. height: 13px;
  1121. margin-left: 8px;
  1122. }
  1123. .pec_content {
  1124. width: 100%;
  1125. height: calc(100% - 60px);
  1126. border-radius: 0 0 12px 12px;
  1127. background-color: #fff;
  1128. }
  1129. .free-browse-switch {
  1130. display: flex;
  1131. align-items: center;
  1132. padding: 9px 10px;
  1133. background: #FFF7F5;
  1134. border-radius: 26px;
  1135. margin-left: 15px;
  1136. gap: 5px;
  1137. }
  1138. .switch-label {
  1139. /* background: linear-gradient(to right, #F53F3F, #FCCF00); */
  1140. /* -webkit-background-clip: text; */
  1141. color: #000;
  1142. }
  1143. .refresh_icon {
  1144. width: 35px;
  1145. height: 35px;
  1146. display: flex;
  1147. align-items: center;
  1148. justify-content: center;
  1149. background-color: #fff7f5;
  1150. border-radius: 45%;
  1151. cursor: pointer;
  1152. margin-right: 15px;
  1153. padding: 0 3px;
  1154. }
  1155. .refresh_icon img {
  1156. width: 16px;
  1157. height: 16px;
  1158. }
  1159. .name_box {
  1160. background: unset !important;
  1161. border: none !important;
  1162. cursor: unset !important;
  1163. }
  1164. .observe-dialog>>>.el-dialog__header {
  1165. padding: 0;
  1166. }
  1167. .observe-dialog>>>.el-dialog__body {
  1168. padding: 0;
  1169. }
  1170. .observe-dialog>>>.el-dialog__headerbtn {
  1171. top: 22px;
  1172. right: 20px;
  1173. z-index: 100;
  1174. }
  1175. </style>