BookEep.vue 32 KB

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