WritePictureQuestion.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <QuestionBase>
  3. <template #content>
  4. <div class="stem">
  5. <RichText v-model="data.stem" :font-size="18" placeholder="输入题干" />
  6. </div>
  7. <div class="content">
  8. <div v-for="(item, index) in data.option_list" :key="index" class="content-item">
  9. <div v-if="pic_list[item.picture_file_id]" class="content-pic">
  10. <div class="item-left">
  11. <el-image
  12. style="width: 72px; height: 72px"
  13. :src="pic_list[item.picture_file_id]"
  14. :preview-src-list="[pic_list[item.picture_file_id]]"
  15. fit="contain"
  16. />
  17. <button class="delete-btn" @click="delectOptions(index, item.picture_file_id)">
  18. <i class="el-icon-delete"></i>删除
  19. </button>
  20. </div>
  21. <div class="item-right">
  22. <div class="item-rich">
  23. <label class="">图片标题</label>
  24. <RichText v-model="item.picture_title" placeholder="输入图片标题" />
  25. </div>
  26. <div class="item-rich">
  27. <label class="">图片信息</label>
  28. <RichText v-model="item.picture_info" placeholder="输入图片信息" />
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <UploadDrag ref="uploadDrag" :limit="999" @fileUploadSuccess="fileUploadSuccess" />
  34. <label class="title-little">阅读材料:</label>
  35. <RichText v-model="data.article" placeholder="输入阅读材料" />
  36. <template v-if="isEnable(data.property.is_enable_description)">
  37. <label class="title-little">题目要求:</label>
  38. <RichText v-model="data.description" placeholder="输入题目要求" />
  39. </template>
  40. <template v-if="isEnable(data.property.is_enable_sample_text)">
  41. <el-divider class="write-divider" />
  42. <label class="title-little">范文:</label>
  43. <RichText v-model="data.sample_text" placeholder="输入范文" :wordlimit-num="5000" />
  44. <p class="tips">多篇范文之间使用分割线(---)</p>
  45. </template>
  46. </div>
  47. </template>
  48. <template #property>
  49. <el-form :model="data.property">
  50. <el-form-item label="题号">
  51. <el-input v-model="data.property.question_number" />
  52. </el-form-item>
  53. <el-form-item label-width="45px">
  54. <el-radio
  55. v-for="{ value, label } in questionNumberTypeList"
  56. :key="value"
  57. v-model="data.other.question_number_type"
  58. :label="value"
  59. >
  60. {{ label }}
  61. </el-radio>
  62. </el-form-item>
  63. <el-form-item label="题干题号">
  64. <el-select v-model="data.property.stem_question_number_font_size">
  65. <el-option v-for="item in fontSizeList" :key="item" :label="item" :value="item" />
  66. </el-select>
  67. </el-form-item>
  68. <el-form-item label="题目要求">
  69. <el-radio
  70. v-for="{ value, label } in switchOption"
  71. :key="value"
  72. v-model="data.property.is_enable_description"
  73. :label="value"
  74. >
  75. {{ label }}
  76. </el-radio>
  77. </el-form-item>
  78. <el-form-item label="分值">
  79. <el-radio
  80. v-for="{ value, label } in scoreTypeList"
  81. :key="value"
  82. v-model="data.property.score_type"
  83. :label="value"
  84. >
  85. {{ label }}
  86. </el-radio>
  87. </el-form-item>
  88. <el-form-item label-width="45px">
  89. <el-input-number
  90. v-model="data.property.score"
  91. :min="0"
  92. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  93. />
  94. </el-form-item>
  95. <el-form-item label="字数">
  96. <el-input-number v-model="data.property.word_num" :min="1" :step="10" class="word-num-input" :precision="0" />
  97. </el-form-item>
  98. <el-form-item label="范文">
  99. <el-radio
  100. v-for="{ value, label } in switchOption"
  101. :key="value"
  102. v-model="data.property.is_enable_sample_text"
  103. :label="value"
  104. >
  105. {{ label }}
  106. </el-radio>
  107. </el-form-item>
  108. <el-form-item label="上传附件">
  109. <el-radio
  110. v-for="{ value, label } in switchOption"
  111. :key="value"
  112. v-model="data.property.is_enable_upload_accessory"
  113. :label="value"
  114. >
  115. {{ label }}
  116. </el-radio>
  117. </el-form-item>
  118. </el-form>
  119. </template>
  120. </QuestionBase>
  121. </template>
  122. <script>
  123. import QuestionMixin from '../common/QuestionMixin.js';
  124. import { writePictrueData, getOption } from '@/views/exercise_questions/data/writePicture';
  125. import { GetFileStoreInfo } from '@/api/app';
  126. import UploadDrag from '../common/UploadDrag.vue';
  127. export default {
  128. name: 'WritePictureQuestion',
  129. components: { UploadDrag },
  130. mixins: [QuestionMixin],
  131. data() {
  132. return {
  133. data: JSON.parse(JSON.stringify(writePictrueData)),
  134. pic_list: {},
  135. is_first: true,
  136. };
  137. },
  138. watch: {
  139. 'data.file_id_list': {
  140. handler() {
  141. if (this.is_first) {
  142. this.handleData();
  143. }
  144. },
  145. deep: true,
  146. },
  147. },
  148. created() {},
  149. mounted() {},
  150. methods: {
  151. // 初始化数据
  152. handleData() {
  153. this.data.file_id_list.forEach((item) => {
  154. GetFileStoreInfo({ file_id: item }).then(({ file_id, file_url }) => {
  155. this.$set(this.pic_list, file_id, file_url);
  156. });
  157. });
  158. this.is_first = false;
  159. },
  160. // 删除
  161. delectOptions(i, id) {
  162. this.$confirm('是否删除该条全部信息?', '提示', {
  163. confirmButtonText: '确定',
  164. cancelButtonText: '取消',
  165. type: 'warning',
  166. })
  167. .then(() => {
  168. delete this.pic_list[id];
  169. this.data.file_id_list.splice(this.data.file_id_list.indexOf(id), 1);
  170. this.data.option_list.splice(i, 1);
  171. this.$refs.uploadDrag.clearFiles();
  172. })
  173. .catch(() => {});
  174. },
  175. fileUploadSuccess(file_id, file_url) {
  176. this.data.file_id_list.push(file_id);
  177. this.data.option_list.push(getOption());
  178. this.data.option_list[this.data.option_list.length - 1].picture_file_id = file_id;
  179. this.$set(this.pic_list, file_id, file_url);
  180. },
  181. /**
  182. * 智能识别
  183. * @param {String} text 识别数据
  184. */
  185. recognition(text) {
  186. let arr = text
  187. .split(/[\r\n]/)
  188. .map((item) => item.trim())
  189. .filter((item) => item);
  190. if (arr.length > 0) {
  191. this.data.stem = arr[0];
  192. this.data.description = arr[2] ? arr[2] : '';
  193. this.data.article = arr[1] ? arr[1] : '';
  194. this.data.sample_text = arr[3] ? arr[3] : '';
  195. }
  196. },
  197. },
  198. };
  199. </script>
  200. <style lang="scss" scoped>
  201. .content {
  202. :deep .el-upload {
  203. width: 100%;
  204. &-dragger {
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. justify-content: center;
  209. width: 100%;
  210. height: 90px;
  211. font-size: 14px;
  212. :first-child {
  213. color: #000;
  214. }
  215. :last-child {
  216. color: $text-color;
  217. }
  218. }
  219. }
  220. .content-item {
  221. .content-pic {
  222. display: flex;
  223. column-gap: 8px;
  224. margin-bottom: 24px;
  225. }
  226. }
  227. .delete-btn {
  228. width: 100%;
  229. padding: 5px 8px;
  230. font-size: 14px;
  231. line-height: 22px;
  232. color: #f53f3f;
  233. background: #fff4f4;
  234. border: none;
  235. border-radius: 4px;
  236. .el-icon-delete {
  237. margin-right: 8px;
  238. }
  239. &:hover {
  240. color: #f53f3f;
  241. }
  242. &:focus {
  243. outline: none;
  244. }
  245. }
  246. .item-left {
  247. width: 72px;
  248. }
  249. .item-right {
  250. flex: 1;
  251. .item-rich {
  252. display: flex;
  253. > label {
  254. flex-shrink: 0;
  255. width: 64px;
  256. font-size: 14px;
  257. line-height: 32px;
  258. color: #4e5969;
  259. }
  260. }
  261. }
  262. }
  263. </style>