BookEep.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <div class="common-preview">
  3. <div class="audit-content">
  4. <div ref="previewMain" class="main-container" :style="{ paddingLeft: '0', paddingRight: '0' }">
  5. <main :class="['preview-main', 'no-audit']" :style="computedCommonPreviewStyle">
  6. <div class="preview-left" :style="{ backgroundColor: background.background?.is_global ? '' : '#fff' }"></div>
  7. <CoursewarePreview
  8. ref="courseware"
  9. :is-show-group="false"
  10. :group-show-all="true"
  11. :group-row-list="groupRowList"
  12. :data="data"
  13. :courseware-id="curSelectId"
  14. :component-list="cList"
  15. :background="background"
  16. :can-remark="false"
  17. :show-remark="false"
  18. :component-remark-obj="{}"
  19. :project="project"
  20. />
  21. <div class="preview-right" :style="{ backgroundColor: background.background?.is_global ? '' : '#fff' }"></div>
  22. </main>
  23. </div>
  24. <div v-if="!sidebarShow" class="back-top" @click="backTop">
  25. <img :src="require(`@/assets/icon/back-top.png`)" alt="返回顶部" />
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import CoursewarePreview from '@/views/book/courseware/preview/CoursewarePreview.vue';
  32. import { isTrue } from '@/utils/validate';
  33. import { buildCoursewareStyle } from '@/views/book/courseware/preview/common/utils/coursewareStyle';
  34. export default {
  35. name: 'BookEep',
  36. components: {
  37. CoursewarePreview,
  38. },
  39. provide() {
  40. return {
  41. getLang: () => this.lang,
  42. getChinese: () => this.chinese,
  43. getShowPinYin: () => this.showPinYin,
  44. getLangList: () => this.langList,
  45. convertText: this.convertText,
  46. getTitleList: () => this.title_list,
  47. getPermissionControl: () => this.permissionControl,
  48. };
  49. },
  50. props: {
  51. id: {
  52. type: String,
  53. default: '',
  54. },
  55. // 组件内容
  56. content: {
  57. type: String,
  58. default: '',
  59. },
  60. // 内容分组行列表
  61. contentGroupRowList: {
  62. type: String,
  63. default: '',
  64. },
  65. // 组件列表
  66. componentList: {
  67. type: Array,
  68. default: () => [],
  69. },
  70. // 教材背景
  71. bookBackground: {
  72. type: String,
  73. default: '',
  74. },
  75. },
  76. data() {
  77. return {
  78. background: this.bookBackground.length > 0 ? JSON.parse(this.bookBackground) : {},
  79. groupRowList: this.contentGroupRowList.length > 0 ? JSON.parse(this.contentGroupRowList) : [],
  80. data: this.content.length > 0 ? JSON.parse(this.content) : { row_list: [] },
  81. cList: this.handleComponentList(),
  82. curSelectId: this.id,
  83. isTrue,
  84. sidebarShow: true,
  85. project: {
  86. editor: '', // 作者
  87. cover_image_file_id: null, // 封面图片ID
  88. cover_image_file_url: '', // 封面图片URL
  89. },
  90. title_list: [],
  91. node_list: [],
  92. permissionControl: {
  93. can_answer: true, // 可作答
  94. can_judge_correct: false, // 可判断对错(客观题)
  95. can_show_answer: false, // 可查看答案
  96. can_correct: false, // 可批改
  97. can_check_correct: false, // 可查看批改
  98. },
  99. popoverShow: false,
  100. is_can_edit: 'false', // 是否可以编辑
  101. };
  102. },
  103. computed: {
  104. computedCommonPreviewStyle() {
  105. return buildCoursewareStyle(this.background, 'commonPreview');
  106. },
  107. },
  108. watch: {
  109. componentList: {
  110. handler(newVal) {
  111. if (newVal && newVal.length > 0) {
  112. this.cList = this.handleComponentList();
  113. }
  114. },
  115. deep: true,
  116. },
  117. bookBackground: {
  118. handler(newVal) {
  119. if (newVal && newVal.length > 0) {
  120. this.background = JSON.parse(newVal);
  121. }
  122. },
  123. },
  124. content: {
  125. handler(newVal) {
  126. if (newVal && newVal.length > 0) {
  127. this.data = JSON.parse(newVal);
  128. }
  129. },
  130. },
  131. contentGroupRowList: {
  132. handler(newVal) {
  133. if (newVal && newVal.length > 0) {
  134. this.groupRowList = JSON.parse(newVal);
  135. }
  136. },
  137. },
  138. id: {
  139. handler(newVal) {
  140. if (newVal && newVal.length > 0) {
  141. this.curSelectId = newVal;
  142. }
  143. },
  144. },
  145. },
  146. methods: {
  147. backTop() {
  148. this.$refs.previewMain.scrollTo({
  149. top: 0,
  150. left: 0,
  151. behavior: 'smooth',
  152. });
  153. },
  154. convertText(text) {
  155. return text;
  156. },
  157. handleComponentList() {
  158. const processHtmlString = this.processHtmlString;
  159. const cList = this.componentList || [];
  160. cList.forEach((x) => {
  161. if (x.component_type === 'audio') {
  162. let _c = JSON.parse(x.content);
  163. let p = _c.property || {};
  164. if (!p.file_name_display_mode) p.file_name_display_mode = 'true';
  165. if (p.view_method === 'independent' && !p.style_mode) {
  166. p.style_mode = 'middle';
  167. }
  168. if (!p.style_mode) p.style_mode = 'big';
  169. if (p.view_method === 'icon') {
  170. p.file_name_display_mode = 'false';
  171. p.view_method = 'independent';
  172. p.style_mode = 'small';
  173. }
  174. x.content = JSON.stringify(_c);
  175. } else if (x.component_type === 'richtext') {
  176. if (!processHtmlString) return;
  177. let _c = JSON.parse(x.content);
  178. let p = _c.property || {};
  179. let lev = Number(p.title_style_level);
  180. if (p.is_title !== 'true' || lev < 1 || !_c.content) return;
  181. let style = this.title_list.find((y) => y.level === lev) || {};
  182. if (style && style.style) {
  183. style = JSON.parse(style.style);
  184. let c_text = _c.content;
  185. const parser = new DOMParser();
  186. const doc = parser.parseFromString(c_text, 'text/html');
  187. const body = doc.body;
  188. const pElements = body.querySelectorAll('p');
  189. processHtmlString(pElements, style);
  190. _c.content = body.innerHTML;
  191. x.content = JSON.stringify(_c);
  192. }
  193. }
  194. });
  195. return cList;
  196. },
  197. processHtmlString(pElements, styleConfig, isClear = false) {
  198. const _pElements = pElements || [];
  199. _pElements.forEach((pElement) => {
  200. if (pElement.innerHTML !== '<br data-mce-bogus="1">') {
  201. pElement.innerHTML = pElement.innerText;
  202. }
  203. if (isClear) {
  204. pElement.removeAttribute('style');
  205. pElement.removeAttribute('data-mce-style');
  206. } else {
  207. const style = pElement.style;
  208. if (styleConfig.font) style.fontFamily = styleConfig.font;
  209. if (styleConfig.font_size) style.fontSize = styleConfig.font_size;
  210. if (styleConfig.text_color) style.color = styleConfig.text_color;
  211. style.fontWeight = styleConfig.bold === 'true' ? 'bold' : 'normal';
  212. style.fontStyle = styleConfig.italic === 'true' ? 'italic' : 'normal';
  213. if (styleConfig.indent || styleConfig.indent === 0) style.marginLeft = `${styleConfig.indent}px`;
  214. }
  215. });
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. @use '@/styles/mixin.scss' as *;
  222. $total-width: $courseware-width + $courseware-left-margin + $courseware-right-margin;
  223. .common-preview {
  224. .main-container {
  225. position: relative;
  226. flex: 1;
  227. min-width: 1110px;
  228. padding: 15px 0;
  229. overflow: auto;
  230. background-color: #ececec;
  231. .catalogue-bar {
  232. position: absolute;
  233. top: 15px;
  234. left: 0;
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. width: 54px;
  239. height: 54px;
  240. margin: -9px 6px 0 240px;
  241. cursor: pointer;
  242. background-color: #fff;
  243. border-radius: 2px;
  244. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  245. }
  246. .sidebar-bar {
  247. position: absolute;
  248. top: 0;
  249. right: 240px;
  250. display: flex;
  251. width: 60px;
  252. height: calc(100vh - 166px);
  253. .toolbar {
  254. display: flex;
  255. flex-direction: column;
  256. align-items: center;
  257. width: 60px;
  258. height: 100%;
  259. img {
  260. cursor: pointer;
  261. }
  262. &-special {
  263. display: flex;
  264. flex-direction: column;
  265. row-gap: 16px;
  266. align-items: center;
  267. width: 100%;
  268. margin-bottom: 24px;
  269. background-color: #fff;
  270. img {
  271. width: 36px;
  272. height: 36px;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. .back-top {
  279. position: absolute;
  280. right: 240px;
  281. bottom: 0;
  282. display: flex;
  283. place-content: center center;
  284. align-items: center;
  285. width: 60px;
  286. height: 60px;
  287. cursor: pointer;
  288. background-color: #fff;
  289. }
  290. main.preview-main {
  291. display: flex;
  292. flex: 1;
  293. width: calc($total-width);
  294. min-width: calc($total-width);
  295. max-width: calc($total-width);
  296. min-height: 100%;
  297. margin: 0 auto;
  298. background-color: #fff;
  299. border-radius: 4px;
  300. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  301. .preview-left {
  302. width: $courseware-left-margin;
  303. min-width: $courseware-left-margin;
  304. max-width: $courseware-left-margin;
  305. background-color: $courseware-bgColor;
  306. }
  307. .preview-right {
  308. width: $courseware-right-margin;
  309. min-width: $courseware-right-margin;
  310. max-width: $courseware-right-margin;
  311. background-color: $courseware-bgColor;
  312. }
  313. &.no-audit {
  314. margin: 0 auto;
  315. }
  316. }
  317. .audit-content {
  318. display: flex;
  319. min-width: 1810px;
  320. height: calc(100vh - 166px);
  321. &_org {
  322. height: calc(100vh - 126px);
  323. }
  324. .left-menu {
  325. display: flex;
  326. flex-direction: column;
  327. width: $catalogue-width;
  328. font-family: 'Microsoft YaHei', 'Arial', sans-serif;
  329. background-color: #fff;
  330. .courseware-info {
  331. display: flex;
  332. column-gap: 18px;
  333. width: 100%;
  334. height: 186px;
  335. padding: 6px 6px 24px;
  336. border-bottom: $border;
  337. .cover-image {
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. width: 111px;
  342. height: 157px;
  343. background-color: rgba(229, 229, 229, 100%);
  344. img {
  345. max-width: 111px;
  346. max-height: 157px;
  347. }
  348. }
  349. .info-content {
  350. display: flex;
  351. flex-direction: column;
  352. justify-content: space-between;
  353. .catalogue-icon {
  354. text-align: right;
  355. .svg-icon {
  356. cursor: pointer;
  357. }
  358. }
  359. .courseware {
  360. width: 159px;
  361. height: 64px;
  362. font-size: 16px;
  363. .name {
  364. font-weight: bold;
  365. }
  366. .editor {
  367. display: -webkit-box;
  368. overflow: hidden;
  369. text-overflow: ellipsis;
  370. word-break: break-word;
  371. white-space: normal;
  372. -webkit-line-clamp: 2; /* 多行省略行数,按需调整 */
  373. -webkit-box-orient: vertical;
  374. }
  375. }
  376. }
  377. }
  378. }
  379. .sidebar {
  380. position: relative;
  381. display: flex;
  382. width: $sidebar-width;
  383. .toolbar {
  384. display: flex;
  385. flex-direction: column;
  386. align-items: center;
  387. width: 60px;
  388. height: 100%;
  389. background-color: rgba(247, 248, 250, 100%);
  390. img {
  391. cursor: pointer;
  392. }
  393. &-special {
  394. display: flex;
  395. flex-direction: column;
  396. row-gap: 16px;
  397. margin-bottom: 24px;
  398. }
  399. &-list {
  400. display: flex;
  401. flex-direction: column;
  402. row-gap: 16px;
  403. align-items: center;
  404. width: 100%;
  405. .sidebar-item {
  406. width: 100%;
  407. text-align: center;
  408. .sidebar-icon {
  409. width: 36px;
  410. height: 36px;
  411. cursor: pointer;
  412. }
  413. &.active {
  414. background-color: #4095e5;
  415. }
  416. }
  417. }
  418. }
  419. .content {
  420. flex: 1;
  421. background-color: #fff;
  422. .resource_box {
  423. height: 100%;
  424. overflow-y: auto;
  425. border: 1px solid #e5e5e5;
  426. h5 {
  427. position: fixed;
  428. z-index: 999;
  429. width: 240px;
  430. padding: 0 5px;
  431. margin: 0;
  432. font-size: 18px;
  433. line-height: 40px;
  434. background: #f2f3f5;
  435. }
  436. .scroll-container {
  437. display: flex;
  438. flex-direction: column;
  439. row-gap: 8px;
  440. margin: 6px;
  441. .list-item {
  442. display: flex;
  443. align-items: center;
  444. cursor: pointer;
  445. border: 1px solid #ccc;
  446. border-radius: 8px;
  447. :deep .el-slider {
  448. .el-slider__runway {
  449. background-color: #eee;
  450. }
  451. }
  452. .el-image {
  453. display: flex;
  454. width: 100%;
  455. min-width: 100%;
  456. height: 90px;
  457. background-color: #ccc;
  458. border-radius: 8px;
  459. }
  460. .video-play {
  461. width: 100%;
  462. min-width: 100%;
  463. }
  464. .text-box {
  465. word-break: break-word;
  466. }
  467. }
  468. }
  469. p {
  470. color: #999;
  471. text-align: center;
  472. }
  473. .card-box li {
  474. padding: 10px;
  475. border-bottom: 1px solid #ccc;
  476. .el-icon-notebook-2 {
  477. display: block;
  478. margin-bottom: 4px;
  479. font-size: 12px;
  480. color: grey;
  481. }
  482. }
  483. }
  484. }
  485. .back-top {
  486. position: absolute;
  487. bottom: 0;
  488. left: 0;
  489. display: flex;
  490. place-content: center center;
  491. align-items: center;
  492. width: 60px;
  493. height: 60px;
  494. cursor: pointer;
  495. }
  496. }
  497. }
  498. }
  499. :deep .scroll-container .audio-wrapper {
  500. width: 100% !important;
  501. .audio-middle {
  502. width: 100% !important;
  503. padding: 6px 8px !important;
  504. border: none;
  505. border-radius: 8px;
  506. .audio-name {
  507. text-align: left;
  508. }
  509. .slider-area {
  510. column-gap: 8px !important;
  511. }
  512. :deep .remark-dialog {
  513. .el-dialog__body {
  514. padding: 5px 20px;
  515. }
  516. }
  517. :deep .audit-dialog {
  518. .el-dialog__body {
  519. height: calc(100vh - 260px);
  520. padding: 5px 20px;
  521. }
  522. .mind-map-container .mind-map {
  523. height: calc(100vh - 310px);
  524. }
  525. }
  526. }
  527. }
  528. .mt10 {
  529. margin: 10px 0 0 !important;
  530. background-color: #eee;
  531. }
  532. .courseware-tree {
  533. display: flex;
  534. flex: 1;
  535. flex-direction: column;
  536. row-gap: 8px;
  537. max-height: calc(100vh - 200px);
  538. overflow: auto;
  539. .menu-item {
  540. display: flex;
  541. align-items: center;
  542. &:not(.courseware) {
  543. font-weight: bold;
  544. }
  545. &.courseware {
  546. &:hover {
  547. .name {
  548. background-color: #f3f3f3;
  549. }
  550. }
  551. }
  552. .svg-icon {
  553. margin-left: 4px;
  554. &.my-edit-task {
  555. color: $right-color;
  556. }
  557. }
  558. .name {
  559. flex: 1;
  560. padding: 4px 8px 4px 4px;
  561. border-radius: 4px;
  562. }
  563. &.active {
  564. .name {
  565. font-weight: bold;
  566. color: #4095e5;
  567. }
  568. }
  569. }
  570. }
  571. </style>
  572. <style lang="scss">
  573. .tox-tinymce-aux {
  574. z-index: 9999 !important;
  575. }
  576. </style>