WritePreview.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="write-preview">
  4. <div class="stem">
  5. <span class="question-number" :style="{ fontSize: data.property.stem_question_number_font_size }">
  6. {{ questionNumberEndIsBracket(data.property.question_number) }}
  7. </span>
  8. <span v-html="sanitizeHTML(data.stem)"></span>
  9. </div>
  10. <div
  11. v-if="isEnable(data.property.is_enable_description)"
  12. class="description rich-text"
  13. v-html="sanitizeHTML(data.description)"
  14. ></div>
  15. <el-input
  16. class="write-input"
  17. v-model="answer.answer_list[0].text"
  18. rows="3"
  19. type="textarea"
  20. placeholder="请输入内容"
  21. :maxlength="data.property.word_num"
  22. show-word-limit
  23. :readonly="disabled"
  24. @input="handleInput"
  25. :autosize="{ minRows: 3 }"
  26. />
  27. <template v-if="isEnable(data.property.is_enable_upload_accessory)">
  28. <!-- 上传附件 -->
  29. <UploadFiles
  30. :fille-number="999"
  31. file-type-name="文件"
  32. :upload-type="'*'"
  33. :file-id-list="answer.answer_list[0].accessory_file_id_list"
  34. :disabled="disabled"
  35. @upload="handleUpload"
  36. @deleteFile="handleDelete"
  37. />
  38. </template>
  39. <template v-if="isEnable(data.property.is_enable_sample_text) && isShowRightAnswer">
  40. <el-divider content-position="center"
  41. ><span
  42. :class="['sample-text', show_sample_text ? 'sample-show' : 'sample-hide']"
  43. @click="show_sample_text = !show_sample_text"
  44. >{{ show_sample_text ? '隐藏范文' : '查看范文' }}</span
  45. ></el-divider
  46. >
  47. <div v-if="show_sample_text" class="article-content rich-text" v-html="sanitizeHTML(data.sample_text)"></div>
  48. </template>
  49. </div>
  50. </template>
  51. <script>
  52. import PreviewMixin from './components/PreviewMixin';
  53. import UploadFiles from './components/common/UploadFiles.vue';
  54. export default {
  55. name: 'WritePreview',
  56. components: {
  57. UploadFiles,
  58. },
  59. mixins: [PreviewMixin],
  60. data() {
  61. return {
  62. show_sample_text: false,
  63. };
  64. },
  65. watch: {
  66. isJudgingRightWrong: {
  67. handler(val) {
  68. if (!val) {
  69. this.answer.answer_list.push({
  70. text: '', // 用户文章
  71. accessory_file_id_list: [], // 上传文件列表
  72. });
  73. }
  74. },
  75. immediate: true,
  76. },
  77. data: {
  78. handler(val) {
  79. if (!val || this.data.type !== 'write') return;
  80. },
  81. deep: true,
  82. immediate: true,
  83. },
  84. },
  85. created() {},
  86. methods: {
  87. // 文件上传成功
  88. handleUpload(fileId) {
  89. this.answer.answer_list[0].accessory_file_id_list.push(fileId);
  90. },
  91. // 删除文件
  92. handleDelete(fileId) {
  93. this.answer.answer_list[0].accessory_file_id_list.splice(
  94. this.answer.answer_list[0].accessory_file_id_list.indexOf(fileId),
  95. 1,
  96. );
  97. },
  98. handleInput(value) {
  99. if (value.length >= this.data.property.word_num) {
  100. this.$message.warning(`字数达到${value.length}字!`);
  101. }
  102. },
  103. },
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. @use '@/styles/mixin.scss' as *;
  108. .write-preview {
  109. @include preview;
  110. .el-divider--horizontal {
  111. margin: 12px 0;
  112. }
  113. .sample-text {
  114. font-size: 14px;
  115. font-weight: 400;
  116. line-height: 30px;
  117. color: #000;
  118. cursor: pointer;
  119. &.sample-show {
  120. color: $light-main-color;
  121. }
  122. }
  123. .article-content,
  124. .description {
  125. :deep p {
  126. margin: 0;
  127. }
  128. }
  129. .write-input {
  130. font-size: 16px;
  131. }
  132. :deep .el-textarea .el-input__count {
  133. font-size: 14px;
  134. background-color: #f2f3f5;
  135. }
  136. }
  137. </style>