BookEep.vue 32 KB

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