index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="preview">
  3. <div>
  4. <div v-for="{ id, name, nodes: children } in nodes" :key="id" class="catalogue">
  5. <div class="catalogue-title">{{ name }}</div>
  6. <template v-for="item in children">
  7. <div :key="item.id" :class="['catalogue-item', item.is_leaf_chapter === 'true' ? 'content' : 'subdirectory']">
  8. <span class="name">{{ item.name }}</span>
  9. </div>
  10. <div v-for="li in item.nodes" :key="li.id">
  11. <div :class="['catalogue-item', 'children', curChapterId === li.id ? 'active' : '']">
  12. <span class="name">{{ li?.name }}</span>
  13. </div>
  14. </div>
  15. </template>
  16. </div>
  17. </div>
  18. <div class="content-area">
  19. <div class="content-top">
  20. <el-button @click="goBack"><SvgIcon icon-class="quit" size="14" /> 退出预览</el-button>
  21. </div>
  22. <div
  23. class="content"
  24. :style="[
  25. {
  26. backgroundImage: data.background_image_url ? `url(${data.background_image_url})` : '',
  27. backgroundSize: data.background_image_url
  28. ? `${data.background_position.width}% ${data.background_position.height}%`
  29. : '',
  30. backgroundPosition: data.background_image_url
  31. ? `${data.background_position.left}% ${data.background_position.top}%`
  32. : '',
  33. },
  34. ]"
  35. >
  36. <div class="navigation">
  37. <span class="navigation-label"> <SvgIcon icon-class="navigation" size="14" />{{ getCatalogueName() }} </span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import {
  45. GetCoursewareContent,
  46. GetBookChapterStruct,
  47. GetCoursewareList_Chapter,
  48. GetCoursewareComponentContent_View,
  49. } from '@/api/book';
  50. export default {
  51. name: 'PreviewPage',
  52. data() {
  53. const { chapter_id } = this.$route.query;
  54. return {
  55. book_id: this.$route.params.book_id,
  56. chapter_id,
  57. curChapterId: chapter_id,
  58. data: {
  59. background_image_url: '',
  60. background_position: {
  61. width: 100,
  62. height: 100,
  63. top: 0,
  64. left: 0,
  65. },
  66. // 组件列表
  67. row_list: [],
  68. },
  69. nodes: [],
  70. curPosition: [],
  71. courseware_list: [],
  72. };
  73. },
  74. created() {
  75. GetBookChapterStruct({ book_id: this.book_id, node_deep_mode: 0 }).then(({ nodes }) => {
  76. this.nodes = nodes ?? [];
  77. this.setCurPosition(this.chapter_id);
  78. });
  79. this.getCoursewareList_Chapter(this.chapter_id);
  80. this.GetCoursewareComponentContent_View();
  81. },
  82. methods: {
  83. // 获取课件数据
  84. getCoursewareComponentContent_View() {
  85. GetCoursewareComponentContent_View({ courseware_id: this.coursewareId, component_id: this.componentId }).then(
  86. ({ content }) => {
  87. // if (content) this.file_list = JSON.parse(content).file_list;
  88. },
  89. );
  90. },
  91. goBack() {
  92. this.$router.push(`/chapter?chapter_id=${this.chapter_id}&book_id=${this.book_id}`);
  93. },
  94. /**
  95. * 根据节点id查找节点在nodes中的位置
  96. * @param {array} nodes 节点数组
  97. * @param {string} id 节点id
  98. * @param {array} position 节点位置
  99. */
  100. findNodeIndexById(nodes, id, position = []) {
  101. for (let i = 0; i < nodes.length; i++) {
  102. const node = nodes[i];
  103. if (node.id === id) {
  104. position.push(i);
  105. return position;
  106. }
  107. if (node.nodes && node.nodes.length > 0) {
  108. const childPosition = this.findNodeIndexById(node.nodes, id, [...position, i]);
  109. if (childPosition.length > 0) {
  110. return childPosition;
  111. }
  112. }
  113. }
  114. return [];
  115. },
  116. setCurPosition(id) {
  117. this.curPosition = this.findNodeIndexById(this.nodes, id);
  118. },
  119. getCoursewareList_Chapter(chapter_id) {
  120. GetCoursewareList_Chapter({ chapter_id }).then(({ courseware_list }) => {
  121. this.courseware_list = courseware_list ?? [];
  122. });
  123. },
  124. getCoursewareContent() {
  125. GetCoursewareContent({ id: this.courseware_id }).then(({ content }) => {
  126. if (content) this.data = JSON.parse(content);
  127. });
  128. },
  129. getNodeName(index) {
  130. let node = this.nodes;
  131. for (let i = 0; i <= index; i++) {
  132. node = i === 0 ? node[this.curPosition[i]] : node.nodes[this.curPosition[i]];
  133. }
  134. return node?.name;
  135. },
  136. getCatalogueName() {
  137. return this.curPosition.map((item, index) => this.getNodeName(index)).join(' / ');
  138. },
  139. },
  140. };
  141. </script>
  142. <style lang="scss" scoped>
  143. .preview {
  144. display: flex;
  145. height: calc(100vh - 66px);
  146. background-color: #ececec;
  147. .catalogue {
  148. display: flex;
  149. flex-direction: column;
  150. height: 100%;
  151. padding: 24px;
  152. background-color: #fff;
  153. &-title {
  154. padding: 8px 0;
  155. font-weight: bold;
  156. color: #000;
  157. }
  158. &-item {
  159. display: flex;
  160. column-gap: 8px;
  161. padding: 8px 32px 8px 16px;
  162. font-size: 14px;
  163. border-bottom: 1px solid #ebebeb;
  164. &:hover {
  165. background-color: #f3f3f3;
  166. }
  167. &.active {
  168. background-color: #f3f3f3;
  169. }
  170. &.subdirectory {
  171. .name {
  172. font-weight: bold;
  173. }
  174. }
  175. &.children {
  176. padding-left: 32px;
  177. }
  178. .name {
  179. flex: 1;
  180. color: #000;
  181. }
  182. .time,
  183. .edit {
  184. color: #929292;
  185. }
  186. .edit {
  187. margin-left: 24px;
  188. cursor: pointer;
  189. }
  190. }
  191. }
  192. .content-area {
  193. width: calc(100vw - 320px);
  194. margin: 18px 60px;
  195. .content-top {
  196. display: flex;
  197. justify-content: end;
  198. width: 100%;
  199. margin-bottom: 18px;
  200. font-size: 16px;
  201. }
  202. .content {
  203. display: flex;
  204. flex-direction: column;
  205. row-gap: 6px;
  206. width: 94%;
  207. min-height: calc(100% - 56px);
  208. padding: 24px;
  209. background-color: #fff;
  210. background-repeat: no-repeat;
  211. border: 3px solid #f44444;
  212. border-radius: 16px;
  213. .row {
  214. display: grid;
  215. row-gap: 16px;
  216. align-items: start;
  217. .col {
  218. display: grid;
  219. }
  220. }
  221. .navigation {
  222. margin: -10px 0 0 -24px;
  223. &-label {
  224. padding: 18px 24px;
  225. color: #fff;
  226. background-color: #f44444;
  227. border-radius: 16px 0;
  228. .svg-icon {
  229. margin: 0 22px 0 1px;
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }
  236. </style>