ExercisePreview.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="Exercise-preview" v-loading="loading">
  3. <div class="type-content">
  4. <div class="type-content-inner">
  5. <div class="rich-text" v-html="sanitizeHTML(title)"></div>
  6. <component :is="getViewCom" :content="content" ref="preview" />
  7. </div>
  8. </div>
  9. <footer style="text-align: right">
  10. <el-button @click="handleCancle">取 消</el-button>
  11. <el-button :loading="loading" type="primary" @click="submitAdd">确 定</el-button>
  12. </footer>
  13. </div>
  14. </template>
  15. <script>
  16. import SelectPreview from '@/views/book/courseware/preview/components/select/SelectPreview.vue';
  17. import JudgePreview from '@/views/book/courseware/preview/components/judge/JudgePreview.vue';
  18. import { GetCoursewareExerciseView } from '@/api/book';
  19. import { sanitizeHTML } from '@/utils/common';
  20. export default {
  21. name: 'ExercisePreview',
  22. components: { SelectPreview, JudgePreview },
  23. props: ['exercise_id'],
  24. data() {
  25. return {
  26. sanitizeHTML,
  27. typeValue: '',
  28. title: '',
  29. content: null,
  30. loading: false,
  31. };
  32. },
  33. computed: {
  34. getViewCom() {
  35. switch (this.typeValue) {
  36. case 'select':
  37. return SelectPreview;
  38. case 'judge':
  39. return JudgePreview;
  40. }
  41. },
  42. },
  43. // 生命周期 - 创建完成(可以访问当前this实例)
  44. created() {
  45. this.handleData();
  46. },
  47. methods: {
  48. componentMove() {},
  49. handleCancle() {
  50. this.$emit('handleCancle');
  51. },
  52. submitAdd() {
  53. this.$emit('submitAdd', this.exercise_id, this.$refs.preview.answer);
  54. },
  55. handleData() {
  56. this.loading = true;
  57. let data = {
  58. exercise_id: this.exercise_id,
  59. courseware_id: this.$route.params.id,
  60. };
  61. GetCoursewareExerciseView(data)
  62. .then((res) => {
  63. this.loading = false;
  64. if (res.status === 1) {
  65. this.content = res.content_exercise;
  66. this.title = res.content_title;
  67. this.typeValue = res.content_exercise ? JSON.parse(res.content_exercise).type : '';
  68. }
  69. })
  70. .catch(() => {
  71. this.loading = false;
  72. });
  73. },
  74. },
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .type-content {
  79. margin: 5px 0;
  80. }
  81. .type-content-inner {
  82. width: 100%;
  83. }
  84. </style>