index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div class="exercise">
  3. <div class="list">
  4. <el-button icon="el-icon-back" @click="back">返回练习管理</el-button>
  5. <div class="list-title">课上练习</div>
  6. <div class="exercise-list">
  7. <ul>
  8. <li v-for="(item, i) in index_list" :key="i" :class="['exercise-item', { active: i === curIndex }]">
  9. <SvgIcon icon-class="child" :size="20" />
  10. <span class="item-name nowrap-ellipsis" @click="selectExerciseItem(i)">
  11. {{ i + 1 }}. {{ exerciseNames[item.type] }}
  12. </span>
  13. <SvgIcon icon-class="copy" class="pointer" :size="10" @click="copy(i, item.type)" />
  14. </li>
  15. </ul>
  16. </div>
  17. <div class="list-operate">
  18. <el-button type="primary">批量导入</el-button>
  19. <el-button type="primary" @click="addQuestionToExercise('select', 'single')">新建</el-button>
  20. </div>
  21. </div>
  22. <CreateMain
  23. ref="createMain"
  24. :cur-index="curIndex"
  25. :index-list="index_list"
  26. @selectExerciseItem="selectExerciseItem"
  27. @setUp="setUp"
  28. @setPreview="setPreview"
  29. @deleteQuestion="deleteQuestion"
  30. @addQuestionToExercise="addQuestionToExercise"
  31. />
  32. <div class="preview">
  33. <div class="preview-header">
  34. <span class="quick-preview">快捷预览:</span>
  35. <div class="preview-right">
  36. <template v-if="preview">
  37. <span class="preview-button plain" @click="getPreviewData">
  38. <SvgIcon icon-class="loop" size="14" /><span>刷新</span>
  39. </span>
  40. <span class="preview-button"><SvgIcon icon-class="eye" /><span>完整预览</span></span>
  41. <span class="preview-button plain" @click="setPreview"><SvgIcon icon-class="close" />关闭预览</span>
  42. </template>
  43. <template v-else>
  44. <span class="preview-button" @click="setPreview"><SvgIcon icon-class="eye" />预览</span>
  45. </template>
  46. </div>
  47. </div>
  48. <div class="preview-content">
  49. <component :is="curPreviewPage" v-if="preview" :data="previewData" />
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { exerciseNames } from '../data/common';
  56. import { AddQuestionToExercise, SaveQuestion, GetExerciseQuestionIndexList } from '@/api/exercise';
  57. import CreateMain from './components/create.vue';
  58. import SelectPreview from '@/views/exercise_questions/preview/SelectPreview.vue';
  59. export default {
  60. name: 'CreateExercise',
  61. components: {
  62. CreateMain,
  63. SelectPreview
  64. },
  65. provide() {
  66. return {
  67. isSetUp: () => this.isSetUp
  68. };
  69. },
  70. data() {
  71. const { id } = this.$route.query;
  72. return {
  73. id, // 练习id
  74. curIndex: 0, // 当前练习索引
  75. index_list: [], // 练习列表
  76. exerciseNames, // 练习名称
  77. isSetUp: false, // 设置
  78. preview: false, // 预览显示
  79. previewData: {}, // 预览数据
  80. previewComponents: { select: SelectPreview }
  81. };
  82. },
  83. computed: {
  84. curPreviewPage() {
  85. if (this.index_list.length === 0) return '';
  86. return this.previewComponents[this.index_list[this.curIndex].type];
  87. }
  88. },
  89. created() {
  90. this.getExerciseQuestionIndexList();
  91. },
  92. methods: {
  93. // 返回练习管理
  94. back() {
  95. this.$router.push('/personal_question');
  96. },
  97. // 新建练习
  98. createExercise() {
  99. this.index_list.push({ type: 'select' });
  100. },
  101. /**
  102. * 添加题目到练习
  103. * @param {string} type
  104. * @param {string} additional_type
  105. */
  106. addQuestionToExercise(type, additional_type) {
  107. AddQuestionToExercise({
  108. exercise_id: this.id,
  109. type,
  110. additional_type,
  111. content: '',
  112. file_id_list: [],
  113. answer: '{}'
  114. })
  115. .then(() => {
  116. this.getExerciseQuestionIndexList();
  117. })
  118. .catch((err) => {
  119. console.log(err);
  120. });
  121. },
  122. /**
  123. * 获取练习题目索引列表
  124. */
  125. getExerciseQuestionIndexList() {
  126. GetExerciseQuestionIndexList({ exercise_id: this.id })
  127. .then(({ index_list }) => {
  128. this.index_list = index_list;
  129. })
  130. .catch((err) => {
  131. console.log(err);
  132. });
  133. },
  134. /**
  135. * 复制练习
  136. * @param {Number} index 练习索引
  137. * @param {String} type 练习类型
  138. */
  139. copy(index, type) {
  140. // this.index_list.splice(index + 1, 0, { type });
  141. // TODO
  142. },
  143. /**
  144. * 选择练习
  145. * @param {Number} index 练习索引
  146. */
  147. selectExerciseItem(index, data) {
  148. if (index < 0 || index > this.index_list.length - 1) return;
  149. this.curIndex = index;
  150. this.$refs.createMain.saveQuestion(data);
  151. },
  152. // 设置
  153. setUp() {
  154. this.isSetUp = !this.isSetUp;
  155. },
  156. getPreviewData() {
  157. this.previewData = this.$refs.createMain.$refs.exercise?.[0].data || {};
  158. },
  159. // 预览
  160. setPreview() {
  161. this.preview = !this.preview;
  162. this.getPreviewData();
  163. },
  164. // 删除练习
  165. deleteQuestion() {}
  166. }
  167. };
  168. </script>
  169. <style lang="scss" scoped>
  170. .exercise {
  171. display: grid;
  172. grid-template: 1fr auto / 224px 1fr;
  173. height: 100%;
  174. .list {
  175. display: flex;
  176. flex-direction: column;
  177. grid-area: 1 / 1 / -1;
  178. row-gap: 16px;
  179. padding: 16px 8px;
  180. background-color: #fff;
  181. border-right: 1px solid $border-color;
  182. &-title {
  183. font-weight: bold;
  184. }
  185. .exercise-list {
  186. max-height: calc(100% - 130px);
  187. overflow-y: auto;
  188. .exercise-item {
  189. display: flex;
  190. column-gap: 8px;
  191. align-items: center;
  192. padding: 4px 8px;
  193. color: #333;
  194. cursor: pointer;
  195. border-radius: 2px;
  196. &.active {
  197. color: $main-color;
  198. background-color: #f4f8ff;
  199. }
  200. .item-name {
  201. flex: 1;
  202. }
  203. }
  204. }
  205. &-operate {
  206. display: flex;
  207. > .el-button {
  208. width: 50%;
  209. }
  210. }
  211. }
  212. .preview {
  213. position: relative;
  214. max-height: 450px;
  215. padding: 16px 24px;
  216. overflow: auto;
  217. background-color: #eff1f5;
  218. border-top: 1px solid $border-color;
  219. .preview-header {
  220. display: flex;
  221. justify-content: space-between;
  222. width: 100%;
  223. .quick-preview {
  224. font-weight: bold;
  225. }
  226. .preview-right {
  227. display: flex;
  228. column-gap: 18px;
  229. align-items: center;
  230. .preview-button {
  231. display: flex;
  232. column-gap: 8px;
  233. align-items: center;
  234. color: #175dff;
  235. cursor: pointer;
  236. &.plain {
  237. color: #2f3742;
  238. }
  239. }
  240. }
  241. }
  242. &-content {
  243. width: 100%;
  244. max-height: calc(100% - 24px);
  245. overflow: auto;
  246. }
  247. }
  248. }
  249. </style>