BookEep.vue 30 KB

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