index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <div class="common-preview">
  3. <div class="common-preview__header">
  4. <div class="courseware">
  5. <span class="flow-nodename">{{ courseware_info.cur_audit_flow_node_name }}</span>
  6. <slot name="middle" :courseware="courseware_info"></slot>
  7. <div class="group">
  8. <el-checkbox v-model="isShowGroup">显示分组</el-checkbox>
  9. <el-checkbox v-model="groupShowAll">分组显示全部</el-checkbox>
  10. <el-checkbox v-model="isJudgeCorrect">判断对错</el-checkbox>
  11. <el-checkbox v-model="isShowAnswer" :disabled="!isJudgeCorrect">显示答案</el-checkbox>
  12. </div>
  13. <span class="link">
  14. <el-select v-model="lang" placeholder="请选择语言" size="mini" class="lang-select">
  15. <el-option v-for="item in langList" :key="item.type" :label="item.name" :value="item.type" />
  16. </el-select>
  17. </span>
  18. <div class="operator">
  19. <slot name="operator" :courseware="courseware_info"></slot>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="audit-content">
  24. <!-- 左侧菜单栏 - 收缩 -->
  25. <aside v-if="navigationShow" class="left-menu">
  26. <div class="courseware-info">
  27. <div class="cover-image"></div>
  28. <div class="info-content">
  29. <div class="catalogue-icon">
  30. <SvgIcon icon-class="catalogue" size="54" />
  31. </div>
  32. <div class="courseware">
  33. <div class="name nowrap-ellipsis" :title="courseware_info.book_name">
  34. {{ courseware_info.book_name }}
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. <!-- 教材章节树 -->
  40. <div class="courseware-tree">
  41. <div
  42. v-for="{ id: nodeId, name, deep, is_leaf_chapter } in node_list"
  43. :key="nodeId"
  44. :class="['menu-item', { active: curSelectId === nodeId }, { courseware: isTrue(is_leaf_chapter) }]"
  45. :style="computedNameStyle(deep, isTrue(is_leaf_chapter))"
  46. @click="selectChapterNode(nodeId, isTrue(is_leaf_chapter))"
  47. >
  48. <span class="name nowrap-ellipsis" :title="name">
  49. {{ name }}
  50. </span>
  51. </div>
  52. </div>
  53. </aside>
  54. <div ref="previewMain" class="main-container">
  55. <div v-if="!navigationShow" class="catalogue-bar">
  56. <SvgIcon icon-class="catalogue" size="54" />
  57. </div>
  58. <main :class="['preview-main']">
  59. <div class="preview-left"></div>
  60. <CoursewarePreview
  61. v-if="courseware_info.book_name"
  62. ref="courserware"
  63. :is-show-group="isShowGroup"
  64. :group-show-all="groupShowAll"
  65. :group-row-list="content_group_row_list"
  66. :data="data"
  67. :component-list="component_list"
  68. :background="background"
  69. :can-remark="isTrue(courseware_info.is_my_audit_task) && isTrue(courseware_info.is_can_add_audit_remark)"
  70. :show-remark="false"
  71. :component-remark-obj="remark_list_obj"
  72. @computeScroll="computeScroll"
  73. />
  74. <div class="preview-right"></div>
  75. </main>
  76. </div>
  77. <div class="back-top" @click="backTop">
  78. <img :src="require(`@/assets/icon/back-top.png`)" alt="返回顶部" />
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import CoursewarePreview from '@/views/book/courseware/preview/CoursewarePreview.vue';
  85. import { isTrue } from '@/utils/validate';
  86. import * as OpenCC from 'opencc-js';
  87. import { GetBookCoursewareInfo, GetCoursewareAuditRemarkList } from '@/api/project';
  88. import {
  89. ContentGetCoursewareContent_View,
  90. ChapterGetBookChapterStructExpandList,
  91. GetBookBaseInfo,
  92. GetLanguageTypeList,
  93. GetBookUnifiedAttrib,
  94. } from '@/api/book';
  95. export default {
  96. name: 'CommonPreview',
  97. components: {
  98. CoursewarePreview,
  99. },
  100. provide() {
  101. return {
  102. getLang: () => this.lang,
  103. getChinese: () => this.chinese,
  104. getLangList: () => this.langList,
  105. convertText: this.convertText,
  106. };
  107. },
  108. data() {
  109. return {
  110. book_id: this.$route.query.book_id || '',
  111. select_node: '',
  112. courseware_info: {
  113. book_name: '',
  114. is_can_start_edit: 'false',
  115. is_can_submit_audit: 'false',
  116. is_can_audit_pass: 'false',
  117. is_can_audit_reject: 'false',
  118. is_can_add_audit_remark: 'false',
  119. is_can_finish_audit: 'false',
  120. is_can_request_shangjia_book: 'false',
  121. is_can_request_rollback_project: 'false',
  122. is_can_shangjia_book: 'false',
  123. is_can_rollback_project: 'false',
  124. },
  125. background: {
  126. background_image_url: '',
  127. background_position: {
  128. left: 0,
  129. top: 0,
  130. },
  131. },
  132. node_list: [],
  133. data: { row_list: [] },
  134. component_list: [],
  135. content_group_row_list: [],
  136. remark_list: [],
  137. remark_list_obj: {}, // 存放以组件为对象的数组
  138. visible: false,
  139. remark_content: '',
  140. submit_loading: false,
  141. isTrue,
  142. isShowGroup: false,
  143. groupShowAll: true,
  144. opencc: OpenCC.Converter({ from: 'cn', to: 'tw' }),
  145. langList: [],
  146. lang: 'ZH',
  147. chinese: 'zh-Hans',
  148. isJudgeCorrect: false,
  149. isShowAnswer: false,
  150. unified_attrib: {},
  151. curSelectId: this.id,
  152. navigationShow: true,
  153. };
  154. },
  155. watch: {
  156. isJudgeCorrect(newVal) {
  157. if (!newVal) {
  158. this.isShowAnswer = false;
  159. }
  160. this.simulateAnswer(newVal);
  161. },
  162. isShowAnswer() {
  163. this.simulateAnswer();
  164. },
  165. },
  166. created() {
  167. this.getBookBaseInfo();
  168. this.getBookChapterStructExpandList();
  169. this.getBookUnifiedAttr();
  170. },
  171. methods: {
  172. getBookBaseInfo() {
  173. GetBookBaseInfo({ id: this.book_id }).then(({ book_info }) => {
  174. this.courseware_info = { ...this.courseware_info, ...book_info, book_name: book_info.name };
  175. });
  176. },
  177. /**
  178. * 得到教材课件信息
  179. * @param {string} id - 课件ID
  180. */
  181. getBookCoursewareInfo(id) {
  182. GetBookCoursewareInfo({ id, is_contain_producer: 'true', is_contain_auditor: 'true' }).then(
  183. ({ courseware_info }) => {
  184. this.courseware_info = { ...this.courseware_info, ...courseware_info };
  185. this.getLangList();
  186. },
  187. );
  188. },
  189. /**
  190. * 得到课件内容(展示内容)
  191. * @param {string} id - 课件ID
  192. */
  193. getCoursewareComponentContent_View(id) {
  194. ContentGetCoursewareContent_View({ id }).then(({ content, component_list, content_group_row_list }) => {
  195. if (content) {
  196. const _content = JSON.parse(content);
  197. this.data = _content;
  198. this.background = {
  199. background_image_url: _content.background_image_url,
  200. background_position: _content.background_position,
  201. };
  202. } else {
  203. this.data = { row_list: [] };
  204. }
  205. if (component_list) this.component_list = component_list;
  206. if (content_group_row_list) this.content_group_row_list = JSON.parse(content_group_row_list) || [];
  207. });
  208. },
  209. getLangList() {
  210. GetLanguageTypeList({ book_id: this.courseware_info.book_id, is_contain_zh: 'true' }).then(
  211. ({ language_type_list }) => {
  212. this.langList = language_type_list;
  213. },
  214. );
  215. },
  216. /**
  217. * 得到教材章节结构展开列表
  218. */
  219. getBookChapterStructExpandList() {
  220. ChapterGetBookChapterStructExpandList({
  221. book_id: this.book_id,
  222. node_deep_mode: 0,
  223. is_contain_producer: 'true',
  224. is_contain_auditor: 'true',
  225. }).then(({ node_list }) => {
  226. this.node_list = node_list;
  227. });
  228. },
  229. getBookUnifiedAttr() {
  230. GetBookUnifiedAttrib({ book_id: this.book_id }).then(({ content }) => {
  231. if (content) {
  232. this.unified_attrib = JSON.parse(content);
  233. }
  234. });
  235. },
  236. /**
  237. * 选择节点
  238. * @param {string} nodeId - 节点ID
  239. */
  240. selectNode(nodeId) {
  241. this.getCoursewareComponentContent_View(nodeId);
  242. this.getBookCoursewareInfo(nodeId);
  243. this.getCoursewareAuditRemarkList(nodeId);
  244. this.select_node = nodeId;
  245. },
  246. // 审校批注列表
  247. getCoursewareAuditRemarkList(id) {
  248. this.remark_list = [];
  249. let remarkListObj = {};
  250. GetCoursewareAuditRemarkList({
  251. courseware_id: id,
  252. }).then(({ remark_list }) => {
  253. this.remark_list = remark_list;
  254. if (!remark_list) return;
  255. remarkListObj = remark_list.reduce((acc, item) => {
  256. if (!acc[item.component_id]) {
  257. acc[item.component_id] = [];
  258. }
  259. acc[item.component_id].push(item);
  260. return acc;
  261. }, {});
  262. this.remark_list_obj = remarkListObj;
  263. });
  264. },
  265. dialogClose(type) {
  266. this[`visible${type}`] = false;
  267. },
  268. // 计算previewMain滑动距离
  269. computeScroll() {
  270. this.$refs.courserware.handleResult(
  271. this.$refs.previewMain.scrollTop,
  272. this.$refs.previewMain.scrollLeft,
  273. this.select_node,
  274. );
  275. },
  276. /**
  277. * 文本转换
  278. * @param {string} text - 要转换的文本
  279. * @returns {string} - 转换后的文本
  280. */
  281. convertText(text) {
  282. if (this.chinese === 'zh-Hant' && this.opencc) {
  283. return this.opencc(text);
  284. }
  285. return text;
  286. },
  287. simulateAnswer(disabled = true) {
  288. this.$refs.courserware.simulateAnswer(this.isJudgeCorrect, this.isShowAnswer, disabled);
  289. },
  290. /**
  291. * 选择节点
  292. * @param {string} nodeId - 节点ID
  293. * @param {boolean} isLeaf - 是否是叶子节点
  294. */
  295. selectChapterNode(nodeId, isLeaf) {
  296. if (!isLeaf) return;
  297. if (this.curSelectId === nodeId) return;
  298. this.curSelectId = nodeId;
  299. this.selectNode(nodeId);
  300. },
  301. /**
  302. * 计算章节名称样式
  303. * @param {number} deep - 节点深度
  304. * @param {boolean} isLeaf - 是否是叶子节点
  305. * @returns {Object} - 样式对象
  306. */
  307. computedNameStyle(deep, isLeaf) {
  308. return {
  309. 'padding-left': `${(deep - 1) * 8}px`,
  310. cursor: isLeaf ? 'pointer' : 'auto',
  311. };
  312. },
  313. /**
  314. * 切换左侧导航栏显示与隐藏
  315. */
  316. toggleNavigationShow() {
  317. this.navigationShow = !this.navigationShow;
  318. },
  319. backTop() {
  320. this.$refs.previewMain.scrollTo({
  321. top: 0,
  322. left: 0,
  323. behavior: 'smooth',
  324. });
  325. },
  326. },
  327. };
  328. </script>
  329. <style lang="scss" scoped>
  330. @use '@/styles/mixin.scss' as *;
  331. $total-width: $courseware-width + $courseware-left-margin + $courseware-right-margin;
  332. .common-preview {
  333. &__header {
  334. position: sticky;
  335. top: 0;
  336. left: 0;
  337. z-index: 9;
  338. display: flex;
  339. align-items: center;
  340. height: 40px;
  341. padding: 6px 4px;
  342. margin-bottom: 5px;
  343. background-color: #fff;
  344. border-top: $border;
  345. border-bottom: $border;
  346. > .courseware {
  347. display: flex;
  348. flex-grow: 1;
  349. column-gap: 16px;
  350. align-items: center;
  351. justify-content: space-between;
  352. height: 40px;
  353. .lang-select {
  354. :deep .el-input {
  355. width: 100px;
  356. }
  357. :deep .el-input__inner {
  358. height: 24px;
  359. line-height: 24px;
  360. background-color: #fff;
  361. }
  362. :deep .el-input__icon {
  363. line-height: 24px;
  364. }
  365. }
  366. .flow-nodename {
  367. flex: 1;
  368. }
  369. .group {
  370. display: flex;
  371. align-items: center;
  372. }
  373. .operator {
  374. display: flex;
  375. column-gap: 8px;
  376. align-items: center;
  377. .link {
  378. + .link {
  379. margin-left: 0;
  380. &::before {
  381. margin-right: 8px;
  382. color: #999;
  383. content: '|';
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. .main-container {
  391. position: relative;
  392. flex: 1;
  393. min-width: 1110px;
  394. padding: 15px 0;
  395. overflow: auto;
  396. background: url('@/assets/preview-bg.png') repeat;
  397. .catalogue-bar {
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. width: 54px;
  402. height: 54px;
  403. margin: -9px 6px 0 240px;
  404. cursor: pointer;
  405. background-color: #fff;
  406. border-radius: 2px;
  407. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  408. }
  409. }
  410. .back-top {
  411. position: absolute;
  412. right: 24px;
  413. bottom: 0;
  414. display: flex;
  415. place-content: center center;
  416. align-items: center;
  417. width: 60px;
  418. height: 60px;
  419. cursor: pointer;
  420. background-color: #fff;
  421. }
  422. main.preview-main {
  423. display: flex;
  424. flex: 1;
  425. width: calc($total-width);
  426. min-width: calc($total-width);
  427. max-width: calc($total-width);
  428. min-height: 100%;
  429. margin: 0 auto;
  430. background-color: #fff;
  431. border-radius: 4px;
  432. box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 40%);
  433. .preview-left {
  434. width: $courseware-left-margin;
  435. min-width: $courseware-left-margin;
  436. max-width: $courseware-left-margin;
  437. background-color: #f9f9f9;
  438. }
  439. .preview-right {
  440. width: $courseware-right-margin;
  441. min-width: $courseware-right-margin;
  442. max-width: $courseware-right-margin;
  443. background-color: #f9f9f9;
  444. }
  445. &.no-audit {
  446. margin: 0 auto;
  447. }
  448. }
  449. .audit-content {
  450. display: flex;
  451. min-width: 1400px;
  452. height: calc(100vh - 46px);
  453. .left-menu {
  454. display: flex;
  455. flex-direction: column;
  456. width: $catalogue-width;
  457. font-family: 'Microsoft YaHei', 'Arial', sans-serif;
  458. background-color: #fff;
  459. .courseware-info {
  460. display: flex;
  461. column-gap: 18px;
  462. width: 100%;
  463. height: 186px;
  464. padding: 6px 6px 24px;
  465. border-bottom: $border;
  466. .cover-image {
  467. width: 111px;
  468. height: 157px;
  469. background-color: rgba(229, 229, 229, 100%);
  470. }
  471. .info-content {
  472. display: flex;
  473. flex-direction: column;
  474. justify-content: space-between;
  475. .catalogue-icon {
  476. text-align: right;
  477. .svg-icon {
  478. cursor: pointer;
  479. }
  480. }
  481. .courseware {
  482. width: 159px;
  483. height: 64px;
  484. font-size: 16px;
  485. .name {
  486. font-weight: bold;
  487. }
  488. }
  489. }
  490. }
  491. .courseware-tree {
  492. display: flex;
  493. flex: 1;
  494. flex-direction: column;
  495. row-gap: 8px;
  496. padding: 12px;
  497. margin-top: 12px;
  498. overflow: auto;
  499. .menu-item {
  500. display: flex;
  501. align-items: center;
  502. &:not(.courseware) {
  503. font-weight: bold;
  504. }
  505. &.courseware {
  506. &:hover {
  507. .name {
  508. background-color: #f3f3f3;
  509. }
  510. }
  511. }
  512. .svg-icon {
  513. margin-left: 4px;
  514. &.my-edit-task {
  515. color: $right-color;
  516. }
  517. }
  518. .name {
  519. flex: 1;
  520. padding: 4px 8px 4px 4px;
  521. border-radius: 4px;
  522. }
  523. &.active {
  524. .name {
  525. font-weight: bold;
  526. color: #4095e5;
  527. }
  528. }
  529. }
  530. }
  531. }
  532. }
  533. }
  534. </style>
  535. <style lang="scss">
  536. .tox-tinymce-aux {
  537. z-index: 9999 !important;
  538. }
  539. </style>