BookEep.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. <template>
  2. <div class="common-preview" :class="{ 'is-mobile': isMobile }">
  3. <div class="audit-content">
  4. <div ref="previewMain" class="main-container">
  5. <main :class="['preview-main', 'no-audit']" :style="computedCommonPreviewStyle">
  6. <div
  7. v-if="!isMobile"
  8. class="preview-left"
  9. :style="{ backgroundColor: background.background?.is_global ? '' : '#fff' }"
  10. ></div>
  11. <CoursewarePreview
  12. v-if="!isMobile"
  13. ref="courseware"
  14. :is-show-group="isShowGroup"
  15. :group-show-all="groupShowAll"
  16. :group-row-list="groupRowList"
  17. :row-checked-list="rowCheckedList"
  18. :data="data"
  19. :courseware-id="curSelectId"
  20. :component-list="cList"
  21. :background="background"
  22. :can-remark="false"
  23. :show-remark="false"
  24. :component-remark-obj="{}"
  25. :project="project"
  26. :is-mobile="isMobile"
  27. @editNote="handEditNote"
  28. @saveCollect="saveCollect"
  29. @getTranslate="getTranslate"
  30. />
  31. <MobileCoursewarePreview
  32. v-else
  33. ref="mobileCourseware"
  34. :is-show-group="isShowGroup"
  35. :group-show-all="groupShowAll"
  36. :group-row-list="groupRowList"
  37. :row-checked-list="rowCheckedList"
  38. :data="data"
  39. :courseware-id="curSelectId"
  40. :component-list="cList"
  41. :background="background"
  42. :can-remark="false"
  43. :show-remark="false"
  44. :component-remark-obj="{}"
  45. :project="project"
  46. :is-mobile="isMobile"
  47. @editNote="handEditNote"
  48. @saveCollect="saveCollect"
  49. @getTranslate="getTranslate"
  50. />
  51. <div
  52. v-if="!isMobile"
  53. class="preview-right"
  54. :style="{ backgroundColor: background.background?.is_global ? '' : '#fff' }"
  55. ></div>
  56. </main>
  57. </div>
  58. </div>
  59. <ExplanatoryNoteDialog
  60. ref="explanatoryNote"
  61. :open.sync="editDialogOpen"
  62. :init-data="oldRichData"
  63. :title-text="dialogTitleText"
  64. :modal="false"
  65. @confirm="dialogSave"
  66. @cancel="dialogCancel"
  67. />
  68. <TranslateDialog
  69. :open.sync="showTranslate"
  70. :modal="false"
  71. :init-text="translateText"
  72. :book-id="id"
  73. title-text="翻译 (机器翻译)"
  74. />
  75. </div>
  76. </template>
  77. <script>
  78. import CoursewarePreview from '@/views/book/courseware/preview/CoursewarePreview.vue';
  79. import ExplanatoryNoteDialog from '@/components/ExplanatoryNoteDialog.vue';
  80. import TranslateDialog from '@/components/TranslateDialog.vue';
  81. import MobileCoursewarePreview from './MobileCoursewarePreview.vue';
  82. import { isTrue } from '@/utils/validate';
  83. import { buildCoursewareStyle } from '@/views/book/courseware/preview/common/utils/coursewareStyle';
  84. import { updateBaseURL } from '@/utils/http';
  85. import {
  86. GetMyNoteList,
  87. AddMyCollect,
  88. GetMyCollectList,
  89. DeleteMyNote,
  90. UpdateMyNote,
  91. AddMyNote,
  92. AddCoursewareFeedback,
  93. DeleteCoursewareFeedback,
  94. GetCoursewareFeedbackList,
  95. } from '@/api/book';
  96. import { ensureExtendedFonts } from '@/common/data';
  97. import { stopAllRecorders, drainUploads } from '@/utils/recordingUpload';
  98. import { MAX_INLINE_ANSWER_CHARS } from '@/utils/audioSource';
  99. const defaultBc = {
  100. background_image_url: '',
  101. background_position: {
  102. left: 0,
  103. top: 0,
  104. },
  105. background: {},
  106. };
  107. export default {
  108. name: 'BookEep',
  109. components: {
  110. CoursewarePreview,
  111. ExplanatoryNoteDialog,
  112. TranslateDialog,
  113. MobileCoursewarePreview,
  114. },
  115. provide() {
  116. return {
  117. getLang: () => this.lang,
  118. getChinese: () => this.chinese,
  119. getShowPinYin: () => this.showPinYin,
  120. getLangList: () => this.langList,
  121. convertText: this.convertText,
  122. getTitleList: () => this.title_list,
  123. getPermissionControl: () => this.permissionControl,
  124. };
  125. },
  126. props: {
  127. id: {
  128. type: String,
  129. default: '',
  130. },
  131. // 组件内容
  132. content: {
  133. type: String,
  134. default: '',
  135. },
  136. // 内容分组行列表
  137. contentGroupRowList: {
  138. type: String,
  139. default: '',
  140. },
  141. // 组件列表
  142. componentList: {
  143. type: Array,
  144. default: () => [],
  145. },
  146. // 教材背景
  147. bookBackground: {
  148. type: String,
  149. default: '',
  150. },
  151. // 权限控制对象
  152. permissControl: {
  153. type: Object,
  154. default: () => ({}),
  155. },
  156. // 外部传入组件用户答案,JSON 格式字符串
  157. componentUserAnswer: {
  158. type: String,
  159. default: '',
  160. },
  161. // 是否显示分组内容
  162. isShowGroup: {
  163. type: Boolean,
  164. default: false,
  165. },
  166. // 行选中状态,JSON 格式字符串
  167. rowChecked: {
  168. type: String,
  169. default: '{}',
  170. },
  171. // 切换章节回调函数
  172. changeChapter: {
  173. type: Function,
  174. default: () => {},
  175. },
  176. },
  177. data() {
  178. const isMobile = /android|iphone|ipad|ipod|openharmony|harmonyos/i.test(
  179. navigator.userAgent || navigator.vendor || window.opera,
  180. );
  181. return {
  182. background: this.bookBackground.length > 0 ? JSON.parse(this.bookBackground) : defaultBc,
  183. groupRowList: this.contentGroupRowList.length > 0 ? JSON.parse(this.contentGroupRowList) : [],
  184. data: this.content.length > 0 ? JSON.parse(this.content) : { row_list: [] },
  185. cList: this.handleComponentList(),
  186. curSelectId: this.id,
  187. isTrue,
  188. project: {
  189. editor: '', // 作者
  190. cover_image_file_id: null, // 封面图片ID
  191. cover_image_file_url: '', // 封面图片URL
  192. },
  193. title_list: [],
  194. node_list: [],
  195. permissionControl: {
  196. can_answer: true, // 可作答
  197. can_judge_correct: false, // 可判断对错(客观题)
  198. can_show_answer: false, // 可查看答案
  199. can_correct: false, // 可批改
  200. can_check_correct: false, // 可查看批改
  201. },
  202. popoverShow: false,
  203. is_can_edit: 'false', // 是否可以编辑
  204. allCollectList: [],
  205. newSelectedInfo: {}, // 新的选中信息
  206. allNoteList: [],
  207. oldRichData: {},
  208. editDialogOpen: false,
  209. dialogType: 0,
  210. lang: 'ZH',
  211. chinese: 'zh-Hans',
  212. showPinYin: 'false',
  213. langList: [],
  214. showTranslate: false,
  215. translateText: '',
  216. selectedInfo: null,
  217. allFeedbackList: [],
  218. drawerType: 1,
  219. isMobile,
  220. groupShowAll: false, // 是否显示全部分组内容
  221. };
  222. },
  223. computed: {
  224. computedCommonPreviewStyle() {
  225. return buildCoursewareStyle(this.background, 'commonPreview');
  226. },
  227. dialogTitleText() {
  228. if (this.dialogType === 2) return '反馈';
  229. return '笔记';
  230. },
  231. rowCheckedList() {
  232. const _rowChecked = this.rowChecked === '[]' ? '{}' : this.rowChecked;
  233. return _rowChecked ? JSON.parse(_rowChecked) : {};
  234. },
  235. },
  236. watch: {
  237. componentList: {
  238. handler(newVal) {
  239. if (newVal && newVal.length > 0) {
  240. this.cList = this.handleComponentList();
  241. this.applyComponentUserAnswer();
  242. }
  243. },
  244. deep: true,
  245. },
  246. bookBackground: {
  247. handler(newVal) {
  248. if (newVal && newVal.length > 0) {
  249. this.background = JSON.parse(newVal);
  250. } else {
  251. this.background = defaultBc;
  252. }
  253. },
  254. },
  255. content: {
  256. handler(newVal) {
  257. if (newVal && newVal.length > 0) {
  258. this.data = JSON.parse(newVal);
  259. }
  260. },
  261. },
  262. contentGroupRowList: {
  263. handler(newVal) {
  264. if (newVal && newVal.length > 0) {
  265. this.groupRowList = JSON.parse(newVal);
  266. }
  267. },
  268. },
  269. id: {
  270. handler(newVal) {
  271. if (newVal && newVal.length > 0) {
  272. this.curSelectId = newVal;
  273. }
  274. },
  275. },
  276. permissControl: {
  277. handler(newVal) {
  278. if (newVal && Object.keys(newVal).length > 0) {
  279. this.permissionControl = newVal;
  280. }
  281. },
  282. deep: true,
  283. immediate: true,
  284. },
  285. componentUserAnswer: {
  286. handler() {
  287. this.applyComponentUserAnswer();
  288. },
  289. deep: true,
  290. immediate: true,
  291. },
  292. rowCheckedList: {
  293. handler(val) {
  294. this.groupShowAll = Object.keys(val).length === 0;
  295. },
  296. deep: true,
  297. immediate: true,
  298. },
  299. },
  300. created() {
  301. const origin = window.location.origin;
  302. if (origin && origin.indexOf('localhost') === -1) {
  303. updateBaseURL(`${origin}/`);
  304. }
  305. },
  306. mounted() {
  307. this.applyComponentUserAnswer();
  308. // 自动注册扩展字体(惰性加载,与主应用共享 _extendedFontsLoaded 标记,仅首次请求)
  309. ensureExtendedFonts();
  310. },
  311. methods: {
  312. /**
  313. * 获取当前实际渲染的课件预览组件
  314. * 桌面端为 CoursewarePreview(ref=courseware),移动端为 MobileCoursewarePreview(ref=mobileCourseware)
  315. * @returns {Object|null} 课件预览组件实例
  316. */
  317. getActiveCoursewareComponent() {
  318. return this.isMobile ? this.$refs.mobileCourseware : this.$refs.courseware;
  319. },
  320. /**
  321. * 获取当前课件内全部子 preview 组件实例(桌面与移动端均为 $refs.preview)
  322. * @returns {Array} preview 组件实例列表
  323. */
  324. getActivePreviewList() {
  325. const cw = this.getActiveCoursewareComponent();
  326. return (cw && cw.$refs && cw.$refs.preview) || [];
  327. },
  328. backTop() {
  329. this.$refs.previewMain.scrollTo({
  330. top: 0,
  331. left: 0,
  332. behavior: 'smooth',
  333. });
  334. },
  335. convertText(text) {
  336. return text;
  337. },
  338. handleComponentList() {
  339. const processHtmlString = this.processHtmlString;
  340. const cList = this.componentList || [];
  341. cList.forEach((x) => {
  342. if (x.component_type === 'audio') {
  343. let _c = JSON.parse(x.content);
  344. let p = _c.property || {};
  345. if (!p.file_name_display_mode) p.file_name_display_mode = 'true';
  346. if (p.view_method === 'independent' && !p.style_mode) {
  347. p.style_mode = 'middle';
  348. }
  349. if (!p.style_mode) p.style_mode = 'big';
  350. if (p.view_method === 'icon') {
  351. p.file_name_display_mode = 'false';
  352. p.view_method = 'independent';
  353. p.style_mode = 'small';
  354. }
  355. x.content = JSON.stringify(_c);
  356. } else if (x.component_type === 'richtext') {
  357. if (!processHtmlString) return;
  358. let _c = JSON.parse(x.content);
  359. let p = _c.property || {};
  360. let lev = Number(p.title_style_level);
  361. if (p.is_title !== 'true' || lev < 1 || !_c.content) return;
  362. let style = this.title_list.find((y) => y.level === lev) || {};
  363. if (style && style.style) {
  364. style = JSON.parse(style.style);
  365. let c_text = _c.content;
  366. const parser = new DOMParser();
  367. const doc = parser.parseFromString(c_text, 'text/html');
  368. const body = doc.body;
  369. const pElements = body.querySelectorAll('p');
  370. processHtmlString(pElements, style);
  371. _c.content = body.innerHTML;
  372. x.content = JSON.stringify(_c);
  373. }
  374. }
  375. });
  376. return cList;
  377. },
  378. /**
  379. * 获取所有组件的用户答案,供 UI 包使用者通过 ref 调用
  380. * @returns {Object} 以组件 id 为键的答案映射
  381. */
  382. getAllComponentUserAnswer() {
  383. const previewList = this.getActivePreviewList();
  384. const answerMap = {};
  385. previewList.forEach((item) => {
  386. const id = item?.$el?.dataset?.id;
  387. if (!id || typeof item.getAnswer !== 'function') return;
  388. answerMap[id] = item.getAnswer();
  389. });
  390. const obj = {
  391. duration: 0,
  392. count_not_done: 0,
  393. count_right: 0,
  394. count_error: 0,
  395. content: JSON.stringify(answerMap),
  396. };
  397. return JSON.stringify(obj);
  398. },
  399. /**
  400. * 提交前调用:停止仍在录制的录音,并等待全部录音上传结束
  401. * 录音会在“停止录音”时就上传,正常做题流程下这里几乎零等待
  402. * @param {{ timeout?: number, idleGrace?: number }} options
  403. * @returns {Promise<{ ok: boolean, timedOut: boolean, failed: number }>}
  404. */
  405. async waitForPendingRecordings(options) {
  406. await stopAllRecorders();
  407. await this.$nextTick();
  408. return drainUploads(options);
  409. },
  410. /**
  411. * 提交前校验答案体积,用于识别上传失败/未上传而残留的内联录音
  412. * 只拦截“本端新产生且上传未完成”的录音:历史答案不含 upload_state 字段,
  413. * 即使体积较大也按原行为提交,避免影响老数据
  414. * @returns {{ total: number, oversize: string[] }} oversize 为组件 id 列表
  415. */
  416. validateAnswerSize() {
  417. const oversize = [];
  418. this.getActivePreviewList().forEach((item) => {
  419. const id = item?.$el?.dataset?.id;
  420. if (!id || typeof item.getAnswer !== 'function') return;
  421. let text = '';
  422. try {
  423. text = JSON.stringify(item.getAnswer() || {});
  424. } catch (err) {
  425. text = '';
  426. }
  427. if (text.length > MAX_INLINE_ANSWER_CHARS && /"upload_state":"(uploading|failed)"/.test(text)) {
  428. oversize.push(id);
  429. }
  430. });
  431. return { total: oversize.length, oversize };
  432. },
  433. /**
  434. * 将外部传入的用户答案回填到组件
  435. */
  436. applyComponentUserAnswer() {
  437. if (!this.componentUserAnswer || this.componentUserAnswer.length === 0) return;
  438. this.$nextTick(() => {
  439. const previewList = this.getActivePreviewList();
  440. if (!previewList.length) return;
  441. const answerMap = JSON.parse(this.componentUserAnswer || '{}');
  442. if (!answerMap || Object.keys(answerMap).length === 0) return;
  443. previewList.forEach((item) => {
  444. const id = item?.$el?.dataset?.id;
  445. if (!id || typeof item.showAnswer !== 'function') return;
  446. if (!Object.hasOwn(answerMap, id)) return;
  447. item.showAnswer(true, true, answerMap[id], true);
  448. });
  449. });
  450. },
  451. processHtmlString(pElements, styleConfig, isClear = false) {
  452. const _pElements = pElements || [];
  453. _pElements.forEach((pElement) => {
  454. if (pElement.innerHTML !== '<br data-mce-bogus="1">') {
  455. pElement.innerHTML = pElement.innerText;
  456. }
  457. if (isClear) {
  458. pElement.removeAttribute('style');
  459. pElement.removeAttribute('data-mce-style');
  460. } else {
  461. const style = pElement.style;
  462. if (styleConfig.font) style.fontFamily = styleConfig.font;
  463. if (styleConfig.font_size) style.fontSize = styleConfig.font_size;
  464. if (styleConfig.text_color) style.color = styleConfig.text_color;
  465. style.fontWeight = styleConfig.bold === 'true' ? 'bold' : 'normal';
  466. style.fontStyle = styleConfig.italic === 'true' ? 'italic' : 'normal';
  467. if (styleConfig.indent || styleConfig.indent === 0) style.marginLeft = `${styleConfig.indent}px`;
  468. }
  469. });
  470. },
  471. /**
  472. * 获取收藏列表
  473. * @param {Object} params - 参数对象
  474. * @param {number} params.type - 收藏类型(可选)
  475. */
  476. async getCollect(params) {
  477. if (params && params.type) this.drawerType = Number(params.type);
  478. this.allCollectList = [];
  479. await GetMyCollectList({ courseware_id: this.curSelectId }).then((res) => {
  480. if (res.status === 1) {
  481. res.collect_list.forEach((x) => {
  482. if (x.collect_desc) {
  483. let n = JSON.parse(x.collect_desc);
  484. let obj = {
  485. coursewareId: x.courseware_id,
  486. id: x.id,
  487. blockId: n.blockId,
  488. startIndex: n.startIndex,
  489. endIndex: n.endIndex,
  490. text: n.text,
  491. };
  492. this.allCollectList.push(obj);
  493. }
  494. });
  495. }
  496. });
  497. },
  498. /**
  499. * 保存收藏
  500. * @param {Object} collect - 收藏信息对象
  501. * @param {string} collect.coursewareId - 课件 ID
  502. * @param {string} collect.blockId - 区块 ID
  503. * @param {number} collect.startIndex - 起始索引
  504. * @param {number} collect.endIndex - 结束索引
  505. * @param {string} collect.text - 收藏文本
  506. */
  507. async saveCollect(collect) {
  508. if (this.allCollectList.length === 0) {
  509. await this.getCollect();
  510. }
  511. let old = this.allCollectList.find(
  512. (x) =>
  513. x.coursewareId === collect.coursewareId &&
  514. x.blockId === collect.blockId &&
  515. x.startIndex === collect.startIndex &&
  516. x.endIndex === collect.endIndex,
  517. );
  518. if (old) {
  519. this.$message({
  520. dangerouslyUseHTMLString: true,
  521. message: "<i class='el-icon-check' />已收藏",
  522. });
  523. return;
  524. }
  525. this.newSelectedInfo = collect;
  526. let collectInfo = {
  527. blockId: this.newSelectedInfo.blockId,
  528. startIndex: this.newSelectedInfo.startIndex,
  529. endIndex: this.newSelectedInfo.endIndex,
  530. text: this.newSelectedInfo.text,
  531. };
  532. let reqData = {
  533. courseware_id: this.newSelectedInfo.coursewareId, // 课件 ID
  534. component_id: 'WHOLE',
  535. collect_desc: JSON.stringify(collectInfo), // 位置描述
  536. };
  537. AddMyCollect(reqData)
  538. .then(() => {
  539. this.getCollect();
  540. })
  541. .then(() => {
  542. this.$message({
  543. dangerouslyUseHTMLString: true,
  544. message: "<i class='el-icon-check' />已收藏",
  545. });
  546. });
  547. },
  548. /**
  549. * 获取笔记列表
  550. * @param {Object} params - 参数对象
  551. */
  552. async getNote(params) {
  553. if (params && params.type) this.drawerType = Number(params.type);
  554. this.allNoteList = [];
  555. await GetMyNoteList({ courseware_id: this.curSelectId }).then((res) => {
  556. if (res.status === 1) {
  557. res.note_list.forEach((x) => {
  558. if (x.note_desc) {
  559. let n = JSON.parse(x.note_desc);
  560. let obj = {
  561. coursewareId: x.courseware_id,
  562. id: x.id,
  563. blockId: n.blockId,
  564. startIndex: n.startIndex,
  565. endIndex: n.endIndex,
  566. text: n.text,
  567. note: this.addImageMaxWidth(n.note),
  568. };
  569. this.allNoteList.push(obj);
  570. }
  571. });
  572. }
  573. });
  574. },
  575. async handEditNote(note) {
  576. this.oldRichData = {};
  577. if (this.allNoteList.length === 0) {
  578. await this.getNote();
  579. }
  580. let old = this.allNoteList.find(
  581. (x) =>
  582. x.coursewareId === note.coursewareId &&
  583. x.blockId === note.blockId &&
  584. x.startIndex === note.startIndex &&
  585. x.endIndex === note.endIndex,
  586. );
  587. if (old) {
  588. this.oldRichData = old;
  589. this.oldRichData.dataStr = old.note;
  590. }
  591. this.newSelectedInfo = note;
  592. this.editDialogOpen = true;
  593. this.dialogType = 1;
  594. },
  595. /**
  596. * 获取翻译
  597. * @param {Object} info - 翻译信息对象
  598. * @param {string} info.text - 需要翻译的文本
  599. */
  600. async getTranslate(info) {
  601. this.showTranslate = true;
  602. this.translateText = info.text;
  603. },
  604. dialogSave(obj) {
  605. if (this.dialogType === 1) return this.saveNote(obj);
  606. if (this.dialogType === 2) return this.saveFeedback(obj);
  607. },
  608. dialogCancel(id) {
  609. if (this.dialogType === 1) return this.delNote(id);
  610. if (this.dialogType === 2) return this.delFeedback(id);
  611. },
  612. /**
  613. * 保存笔记
  614. * @param {Object} note - 笔记信息对象
  615. * @param {string} note.dataStr - 笔记内容
  616. */
  617. saveNote(note) {
  618. let noteInfo = {
  619. blockId: this.newSelectedInfo.blockId,
  620. startIndex: this.newSelectedInfo.startIndex,
  621. endIndex: this.newSelectedInfo.endIndex,
  622. note: note.dataStr,
  623. text: this.newSelectedInfo.text,
  624. };
  625. let reqData = {
  626. courseware_id: this.newSelectedInfo.coursewareId, // 课件 ID
  627. component_id: 'WHOLE',
  628. note_desc: JSON.stringify(noteInfo), // 位置描述
  629. };
  630. if (note.id) {
  631. if (!noteInfo.note) {
  632. this.delNote(note.id);
  633. return;
  634. }
  635. let upDate = {
  636. id: note.id,
  637. note_desc: reqData.note_desc,
  638. };
  639. UpdateMyNote(upDate).then(() => {
  640. this.getNote();
  641. });
  642. } else {
  643. AddMyNote(reqData).then(() => {
  644. this.getNote();
  645. });
  646. }
  647. this.editDialogOpen = false;
  648. this.newSelectedInfo = null;
  649. this.selectedInfo = null;
  650. },
  651. delNote(id) {
  652. const noteId = id || (this.oldRichData && this.oldRichData.id);
  653. if (!noteId) return;
  654. DeleteMyNote({ id: noteId }).then(() => {
  655. this.allNoteList = this.allNoteList.filter((x) => x.id !== noteId);
  656. });
  657. },
  658. saveFeedback(feedBack) {
  659. if (feedBack.id) {
  660. this.delFeedback(feedBack.id);
  661. }
  662. if (feedBack.dataStr) {
  663. let feedBackInfo = {
  664. blockId: this.newSelectedInfo.blockId,
  665. startIndex: this.newSelectedInfo.startIndex,
  666. endIndex: this.newSelectedInfo.endIndex,
  667. feedBack: feedBack.dataStr,
  668. text: this.newSelectedInfo.text,
  669. };
  670. let reqData = {
  671. courseware_id: this.newSelectedInfo.coursewareId, // 课件 ID
  672. component_id: 'WHOLE',
  673. content: JSON.stringify(feedBackInfo),
  674. content_select: this.newSelectedInfo.text,
  675. };
  676. AddCoursewareFeedback(reqData).then(() => {
  677. this.getFeedback();
  678. });
  679. }
  680. this.editDialogOpen = false;
  681. this.newSelectedInfo = null;
  682. this.selectedInfo = null;
  683. },
  684. delFeedback(id) {
  685. const feedBackId = id || (this.oldRichData && this.oldRichData.id);
  686. if (!feedBackId) return;
  687. DeleteCoursewareFeedback({ id: feedBackId })
  688. .then(() => {
  689. this.allFeedbackList = this.allFeedbackList.filter((x) => x.id !== feedBackId);
  690. })
  691. .catch(() => {});
  692. },
  693. /**
  694. * 为HTML内容中的图片添加最大宽度限制
  695. * @param {string} html - HTML字符串
  696. * @returns {string} - 处理后的HTML字符串
  697. */
  698. addImageMaxWidth(html) {
  699. if (!html) return html;
  700. const regex = /<img([^>]*)>/gi;
  701. return html.replace(regex, (match, attributes) => {
  702. if (attributes.includes('style=')) {
  703. return match.replace(/style=["']([^"']*)["']/i, (styleMatch, styleValue) => {
  704. if (styleValue.includes('max-width')) {
  705. return styleMatch;
  706. }
  707. return `style="${styleValue}; max-width: 200px;"`;
  708. });
  709. }
  710. return `<img${attributes} style="max-width: 200px;">`;
  711. });
  712. },
  713. async getFeedback(params) {
  714. if (params && params.type) this.drawerType = Number(params.type);
  715. this.allFeedbackList = [];
  716. await GetCoursewareFeedbackList({ courseware_id: this.curSelectId }).then((res) => {
  717. if (res.status === 1 && res.feedback_list) {
  718. res.feedback_list.forEach((x) => {
  719. if (x.content) {
  720. let n = JSON.parse(x.content);
  721. let obj = {
  722. coursewareId: x.courseware_id,
  723. id: x.id,
  724. blockId: n.blockId,
  725. startIndex: n.startIndex,
  726. endIndex: n.endIndex,
  727. text: n.text,
  728. feedBack: this.addImageMaxWidth(n.feedBack),
  729. };
  730. this.allFeedbackList.push(obj);
  731. }
  732. });
  733. }
  734. });
  735. },
  736. submitPreviewGroupId() {
  737. const cw = this.getActiveCoursewareComponent();
  738. return JSON.stringify((cw && cw.rowCheckList) || {});
  739. },
  740. /**
  741. * @description 选择章节节点
  742. * @param {string} id - 章节节点 ID
  743. */
  744. selectChapterNode(id) {
  745. this.changeChapter(id);
  746. },
  747. },
  748. };
  749. </script>
  750. <style lang="scss" scoped>
  751. @use '@/styles/mixin.scss' as *;
  752. $total-width: $courseware-width + $courseware-left-margin + $courseware-right-margin;
  753. .common-preview {
  754. min-width: calc($total-width);
  755. // 移动端适配
  756. &.is-mobile {
  757. min-width: 100%;
  758. .main-container {
  759. min-width: 100%;
  760. }
  761. .audit-content {
  762. min-width: 100%;
  763. }
  764. main.preview-main {
  765. width: 100%;
  766. min-width: 100%;
  767. max-width: 100%;
  768. }
  769. }
  770. .main-container {
  771. position: relative;
  772. flex: 1;
  773. min-width: 1110px;
  774. padding: 15px;
  775. overflow: auto;
  776. background-color: #ececec;
  777. .catalogue-bar {
  778. position: absolute;
  779. top: 15px;
  780. left: 0;
  781. display: flex;
  782. align-items: center;
  783. justify-content: center;
  784. width: 54px;
  785. height: 54px;
  786. margin: -9px 6px 0 240px;
  787. cursor: pointer;
  788. background-color: #fff;
  789. border-radius: 2px;
  790. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  791. }
  792. .sidebar-bar {
  793. position: absolute;
  794. top: 0;
  795. right: 240px;
  796. display: flex;
  797. width: 60px;
  798. height: calc(100vh - 166px);
  799. .toolbar {
  800. display: flex;
  801. flex-direction: column;
  802. align-items: center;
  803. width: 60px;
  804. height: 100%;
  805. img {
  806. cursor: pointer;
  807. }
  808. &-special {
  809. display: flex;
  810. flex-direction: column;
  811. row-gap: 16px;
  812. align-items: center;
  813. width: 100%;
  814. margin-bottom: 24px;
  815. background-color: #fff;
  816. img {
  817. width: 36px;
  818. height: 36px;
  819. }
  820. }
  821. }
  822. }
  823. }
  824. .back-top {
  825. position: absolute;
  826. right: 240px;
  827. bottom: 0;
  828. display: flex;
  829. place-content: center center;
  830. align-items: center;
  831. width: 60px;
  832. height: 60px;
  833. cursor: pointer;
  834. background-color: #fff;
  835. }
  836. main.preview-main {
  837. display: flex;
  838. flex: 1;
  839. width: calc($total-width);
  840. min-width: calc($total-width);
  841. max-width: calc($total-width);
  842. min-height: 100%;
  843. margin: 0 auto;
  844. background-color: #fff;
  845. border-radius: 4px;
  846. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  847. .preview-left {
  848. width: $courseware-left-margin;
  849. min-width: $courseware-left-margin;
  850. max-width: $courseware-left-margin;
  851. }
  852. .preview-right {
  853. width: $courseware-right-margin;
  854. min-width: $courseware-right-margin;
  855. max-width: $courseware-right-margin;
  856. }
  857. &.no-audit {
  858. margin: 0 auto;
  859. }
  860. }
  861. .audit-content {
  862. display: flex;
  863. min-width: calc($total-width);
  864. .left-menu {
  865. display: flex;
  866. flex-direction: column;
  867. width: $catalogue-width;
  868. font-family: 'Microsoft YaHei', 'Arial', sans-serif;
  869. background-color: #fff;
  870. .courseware-info {
  871. display: flex;
  872. column-gap: 18px;
  873. width: 100%;
  874. height: 186px;
  875. padding: 6px 6px 24px;
  876. border-bottom: $border;
  877. .cover-image {
  878. display: flex;
  879. align-items: center;
  880. justify-content: center;
  881. width: 111px;
  882. height: 157px;
  883. background-color: rgba(229, 229, 229, 100%);
  884. img {
  885. max-width: 111px;
  886. max-height: 157px;
  887. }
  888. }
  889. .info-content {
  890. display: flex;
  891. flex-direction: column;
  892. justify-content: space-between;
  893. .catalogue-icon {
  894. text-align: right;
  895. .svg-icon {
  896. cursor: pointer;
  897. }
  898. }
  899. .courseware {
  900. width: 159px;
  901. height: 64px;
  902. font-size: 16px;
  903. .name {
  904. font-weight: bold;
  905. }
  906. .editor {
  907. display: -webkit-box;
  908. overflow: hidden;
  909. text-overflow: ellipsis;
  910. word-break: break-word;
  911. white-space: normal;
  912. -webkit-line-clamp: 2; /* 多行省略行数,按需调整 */
  913. -webkit-box-orient: vertical;
  914. }
  915. }
  916. }
  917. }
  918. }
  919. .sidebar {
  920. position: relative;
  921. display: flex;
  922. width: $sidebar-width;
  923. .toolbar {
  924. display: flex;
  925. flex-direction: column;
  926. align-items: center;
  927. width: 60px;
  928. height: 100%;
  929. background-color: rgba(247, 248, 250, 100%);
  930. img {
  931. cursor: pointer;
  932. }
  933. &-special {
  934. display: flex;
  935. flex-direction: column;
  936. row-gap: 16px;
  937. margin-bottom: 24px;
  938. }
  939. &-list {
  940. display: flex;
  941. flex-direction: column;
  942. row-gap: 16px;
  943. align-items: center;
  944. width: 100%;
  945. .sidebar-item {
  946. width: 100%;
  947. text-align: center;
  948. .sidebar-icon {
  949. width: 36px;
  950. height: 36px;
  951. cursor: pointer;
  952. }
  953. &.active {
  954. background-color: #4095e5;
  955. }
  956. }
  957. }
  958. }
  959. .content {
  960. flex: 1;
  961. background-color: #fff;
  962. .resource_box {
  963. height: 100%;
  964. overflow-y: auto;
  965. border: 1px solid #e5e5e5;
  966. h5 {
  967. position: fixed;
  968. z-index: 999;
  969. width: 240px;
  970. padding: 0 5px;
  971. margin: 0;
  972. font-size: 18px;
  973. line-height: 40px;
  974. background: #f2f3f5;
  975. }
  976. .scroll-container {
  977. display: flex;
  978. flex-direction: column;
  979. row-gap: 8px;
  980. margin: 6px;
  981. .list-item {
  982. display: flex;
  983. align-items: center;
  984. cursor: pointer;
  985. border: 1px solid #ccc;
  986. border-radius: 8px;
  987. :deep .el-slider {
  988. .el-slider__runway {
  989. background-color: #eee;
  990. }
  991. }
  992. .el-image {
  993. display: flex;
  994. width: 100%;
  995. min-width: 100%;
  996. height: 90px;
  997. background-color: #ccc;
  998. border-radius: 8px;
  999. }
  1000. .video-play {
  1001. width: 100%;
  1002. min-width: 100%;
  1003. }
  1004. .text-box {
  1005. word-break: break-word;
  1006. }
  1007. }
  1008. }
  1009. p {
  1010. color: #999;
  1011. text-align: center;
  1012. }
  1013. .card-box li {
  1014. padding: 10px;
  1015. border-bottom: 1px solid #ccc;
  1016. .el-icon-notebook-2 {
  1017. display: block;
  1018. margin-bottom: 4px;
  1019. font-size: 12px;
  1020. color: grey;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. .back-top {
  1026. position: absolute;
  1027. bottom: 0;
  1028. left: 0;
  1029. display: flex;
  1030. place-content: center center;
  1031. align-items: center;
  1032. width: 60px;
  1033. height: 60px;
  1034. cursor: pointer;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. :deep .scroll-container .audio-wrapper {
  1040. width: 100% !important;
  1041. .audio-middle {
  1042. width: 100% !important;
  1043. padding: 6px 8px !important;
  1044. border: none;
  1045. border-radius: 8px;
  1046. .audio-name {
  1047. text-align: left;
  1048. }
  1049. .slider-area {
  1050. column-gap: 8px !important;
  1051. }
  1052. :deep .remark-dialog {
  1053. .el-dialog__body {
  1054. padding: 5px 20px;
  1055. }
  1056. }
  1057. :deep .audit-dialog {
  1058. .el-dialog__body {
  1059. height: calc(100vh - 260px);
  1060. padding: 5px 20px;
  1061. }
  1062. .mind-map-container .mind-map {
  1063. height: calc(100vh - 310px);
  1064. }
  1065. }
  1066. }
  1067. }
  1068. .mt10 {
  1069. margin: 10px 0 0 !important;
  1070. background-color: #eee;
  1071. }
  1072. .courseware-tree {
  1073. display: flex;
  1074. flex: 1;
  1075. flex-direction: column;
  1076. row-gap: 8px;
  1077. max-height: calc(100vh - 200px);
  1078. overflow: auto;
  1079. .menu-item {
  1080. display: flex;
  1081. align-items: center;
  1082. &:not(.courseware) {
  1083. font-weight: bold;
  1084. }
  1085. &.courseware {
  1086. &:hover {
  1087. .name {
  1088. background-color: #f3f3f3;
  1089. }
  1090. }
  1091. }
  1092. .svg-icon {
  1093. margin-left: 4px;
  1094. &.my-edit-task {
  1095. color: $right-color;
  1096. }
  1097. }
  1098. .name {
  1099. flex: 1;
  1100. padding: 4px 8px 4px 4px;
  1101. border-radius: 4px;
  1102. }
  1103. &.active {
  1104. .name {
  1105. font-weight: bold;
  1106. color: #4095e5;
  1107. }
  1108. }
  1109. }
  1110. }
  1111. </style>
  1112. <style lang="scss">
  1113. .tox-tinymce-aux {
  1114. z-index: 9999 !important;
  1115. }
  1116. </style>