WritePictruePreview.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div v-if="show_preview" class="writepicture-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. <div class="content">
  16. <div v-for="(item, index) in data.option_list" :key="index" class="content-item">
  17. <el-image
  18. v-if="pic_list[item.picture_file_id]"
  19. style="width: 370px; height: 238px"
  20. :src="pic_list[item.picture_file_id]"
  21. fit="contain"
  22. />
  23. <p class="pic-info rich-text" v-html="sanitizeHTML(item.picture_info)"></p>
  24. </div>
  25. </div>
  26. <div v-if="answer.answer_list[active_index]" class="content-right">
  27. <el-input
  28. class="write-input"
  29. v-model="answer.answer_list[active_index].text"
  30. rows="12"
  31. resize="none"
  32. type="textarea"
  33. placeholder="请输入"
  34. :maxlength="data.property.word_num"
  35. show-word-limit
  36. :readonly="disabled"
  37. @input="handleInput"
  38. :autosize="{ minRows: 5 }"
  39. />
  40. </div>
  41. <template v-if="isEnable(data.property.is_enable_upload_accessory)">
  42. <!-- 上传附件 -->
  43. <UploadFiles
  44. v-if="answer.answer_list[active_index]"
  45. :disabled="disabled"
  46. :fille-number="999"
  47. file-type-name="文件"
  48. :upload-type="'*'"
  49. :file-id-list="answer.answer_list[active_index].accessory_file_id"
  50. @upload="handleUpload"
  51. @deleteFile="handleDelete"
  52. />
  53. </template>
  54. <template v-if="isEnable(data.property.is_enable_sample_text) && isShowRightAnswer">
  55. <el-divider content-position="center"
  56. ><span
  57. :class="['sample-text', show_sample_text ? 'sample-show' : 'sample-hide']"
  58. @click="show_sample_text = !show_sample_text"
  59. >{{ show_sample_text ? '隐藏范文' : '查看范文' }}</span
  60. ></el-divider
  61. >
  62. <div v-if="show_sample_text" class="article-content rich-text" v-html="sanitizeHTML(data.sample_text)"></div>
  63. </template>
  64. </div>
  65. </template>
  66. <script>
  67. import PreviewMixin from './components/PreviewMixin';
  68. import { GetFileStoreInfo } from '@/api/app';
  69. import UploadFiles from './components/common/UploadFiles.vue';
  70. export default {
  71. name: 'WritePicturePreview',
  72. components: {
  73. UploadFiles,
  74. },
  75. mixins: [PreviewMixin],
  76. data() {
  77. return {
  78. show_sample_text: false,
  79. pic_list: {},
  80. active_index: 0,
  81. show_preview: false,
  82. };
  83. },
  84. watch: {
  85. data: {
  86. handler(val) {
  87. if (!val || this.data.type !== 'write_picture') return;
  88. this.handleData();
  89. },
  90. deep: true,
  91. immediate: true,
  92. },
  93. },
  94. created() {
  95. console.log(this.data);
  96. // this.handleData();
  97. },
  98. methods: {
  99. // 初始化数据
  100. handleData() {
  101. this.show_preview = true;
  102. this.pic_list = {};
  103. this.active_index = 0;
  104. this.data.file_id_list.forEach((item) => {
  105. GetFileStoreInfo({ file_id: item }).then(({ file_id, file_url }) => {
  106. this.$set(this.pic_list, file_id, file_url);
  107. });
  108. });
  109. if (!this.isJudgingRightWrong) {
  110. let obj = {
  111. text: '',
  112. accessory_file_id: [], // 上传文件列表
  113. };
  114. this.answer.answer_list.push(obj);
  115. }
  116. },
  117. changeImg(index) {
  118. this.active_index = index;
  119. },
  120. // 文件上传成功
  121. handleUpload(fileId) {
  122. this.answer.answer_list[this.active_index].accessory_file_id.push(fileId);
  123. },
  124. // 删除文件
  125. handleDelete(fileId) {
  126. this.answer.answer_list[this.active_index].accessory_file_id.splice(
  127. this.answer.answer_list[this.active_index].accessory_file_id.indexOf(fileId),
  128. 1,
  129. );
  130. },
  131. handleInput(value) {
  132. if (value.length >= this.data.property.word_num) {
  133. this.$message.warning(`字数达到${value.length}字!`);
  134. }
  135. },
  136. },
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. @use '@/styles/mixin.scss' as *;
  141. .writepicture-preview {
  142. @include preview;
  143. :deep p {
  144. margin: 0;
  145. }
  146. .content {
  147. display: flex;
  148. column-gap: 8px;
  149. width: 100%;
  150. overflow: auto;
  151. .pic-title {
  152. margin: 8px 0 4px;
  153. font-size: 12px;
  154. font-weight: 600;
  155. line-height: 20px;
  156. color: #000;
  157. word-break: break-word;
  158. }
  159. .pic-info {
  160. margin: 0;
  161. font-size: 12px;
  162. font-weight: 400;
  163. line-height: 20px;
  164. color: #000;
  165. word-break: break-word;
  166. }
  167. }
  168. .reference-box {
  169. padding: 12px;
  170. background: #f9f8f9;
  171. .reference-title {
  172. margin: 0 0 10px;
  173. font-size: 14px;
  174. font-weight: 400;
  175. line-height: 32px;
  176. color: #4e5969;
  177. }
  178. }
  179. .el-divider--horizontal {
  180. margin: 12px 0;
  181. }
  182. .sample-text {
  183. font-size: 14px;
  184. font-weight: 400;
  185. line-height: 30px;
  186. color: #000;
  187. cursor: pointer;
  188. &.sample-show {
  189. color: $light-main-color;
  190. }
  191. }
  192. .article-content,
  193. .description {
  194. :deep p {
  195. margin: 0;
  196. }
  197. }
  198. .write-input {
  199. font-size: 16px;
  200. }
  201. :deep .el-textarea .el-textarea__inner {
  202. padding-bottom: 25px;
  203. }
  204. :deep .el-textarea .el-input__count {
  205. bottom: 5px;
  206. font-size: 14px;
  207. background-color: #f2f3f5;
  208. }
  209. }
  210. </style>