BookEep.vue 30 KB

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