WritePictureQuestion.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <QuestionBase>
  3. <template #content>
  4. <div class="stem">
  5. <RichText v-model="data.stem" 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-radio
  65. v-for="{ value, label } in switchOption"
  66. :key="value"
  67. v-model="data.property.is_enable_description"
  68. :label="value"
  69. >
  70. {{ label }}
  71. </el-radio>
  72. </el-form-item>
  73. <el-form-item label="分值">
  74. <el-radio
  75. v-for="{ value, label } in scoreTypeList"
  76. :key="value"
  77. v-model="data.property.score_type"
  78. :label="value"
  79. >
  80. {{ label }}
  81. </el-radio>
  82. </el-form-item>
  83. <el-form-item label-width="45px">
  84. <el-input-number
  85. v-model="data.property.score"
  86. :min="0"
  87. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  88. />
  89. </el-form-item>
  90. <el-form-item label="字数">
  91. <el-input-number v-model="data.property.word_num" :min="1" :step="10" class="word-num-input" :precision="0" />
  92. </el-form-item>
  93. <el-form-item label="范文">
  94. <el-radio
  95. v-for="{ value, label } in switchOption"
  96. :key="value"
  97. v-model="data.property.is_enable_sample_text"
  98. :label="value"
  99. >
  100. {{ label }}
  101. </el-radio>
  102. </el-form-item>
  103. <el-form-item label="上传附件">
  104. <el-radio
  105. v-for="{ value, label } in switchOption"
  106. :key="value"
  107. v-model="data.property.is_enable_upload_accessory"
  108. :label="value"
  109. >
  110. {{ label }}
  111. </el-radio>
  112. </el-form-item>
  113. </el-form>
  114. </template>
  115. </QuestionBase>
  116. </template>
  117. <script>
  118. import QuestionMixin from '../common/QuestionMixin.js';
  119. import { writePictrueData, getOption } from '@/views/exercise_questions/data/writePicture';
  120. import { GetFileStoreInfo } from '@/api/app';
  121. import UploadDrag from '../common/UploadDrag.vue';
  122. export default {
  123. name: 'WritePictureQuestion',
  124. components: { UploadDrag },
  125. mixins: [QuestionMixin],
  126. data() {
  127. return {
  128. data: JSON.parse(JSON.stringify(writePictrueData)),
  129. pic_list: {},
  130. is_first: true,
  131. };
  132. },
  133. watch: {
  134. 'data.file_id_list': {
  135. handler() {
  136. if (this.is_first) {
  137. this.handleData();
  138. }
  139. },
  140. deep: true,
  141. },
  142. },
  143. created() {},
  144. mounted() {},
  145. methods: {
  146. // 初始化数据
  147. handleData() {
  148. this.data.file_id_list.forEach((item) => {
  149. GetFileStoreInfo({ file_id: item }).then(({ file_id, file_url }) => {
  150. this.$set(this.pic_list, file_id, file_url);
  151. });
  152. });
  153. this.is_first = false;
  154. },
  155. // 删除
  156. delectOptions(i, id) {
  157. this.$confirm('是否删除该条全部信息?', '提示', {
  158. confirmButtonText: '确定',
  159. cancelButtonText: '取消',
  160. type: 'warning',
  161. })
  162. .then(() => {
  163. delete this.pic_list[id];
  164. this.data.file_id_list.splice(this.data.file_id_list.indexOf(id), 1);
  165. this.data.option_list.splice(i, 1);
  166. this.$refs.uploadDrag.clearFiles();
  167. })
  168. .catch(() => {});
  169. },
  170. fileUploadSuccess(file_id, file_url) {
  171. this.data.file_id_list.push(file_id);
  172. this.data.option_list.push(getOption());
  173. this.data.option_list[this.data.option_list.length - 1].picture_file_id = file_id;
  174. this.$set(this.pic_list, file_id, file_url);
  175. },
  176. /**
  177. * 智能识别
  178. * @param {String} text 识别数据
  179. */
  180. recognition(text) {
  181. let arr = text
  182. .split(/[\r\n]/)
  183. .map((item) => item.trim())
  184. .filter((item) => item);
  185. if (arr.length > 0) {
  186. this.data.stem = arr[0];
  187. this.data.description = arr[2] ? arr[2] : '';
  188. this.data.article = arr[1] ? arr[1] : '';
  189. this.data.sample_text = arr[3] ? arr[3] : '';
  190. }
  191. },
  192. },
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. .content {
  197. :deep .el-upload {
  198. width: 100%;
  199. &-dragger {
  200. display: flex;
  201. flex-direction: column;
  202. align-items: center;
  203. justify-content: center;
  204. width: 100%;
  205. height: 90px;
  206. font-size: 14px;
  207. :first-child {
  208. color: #000;
  209. }
  210. :last-child {
  211. color: $text-color;
  212. }
  213. }
  214. }
  215. .content-item {
  216. .content-pic {
  217. display: flex;
  218. column-gap: 8px;
  219. margin-bottom: 24px;
  220. }
  221. }
  222. .delete-btn {
  223. width: 100%;
  224. padding: 5px 8px;
  225. font-size: 14px;
  226. line-height: 22px;
  227. color: #f53f3f;
  228. background: #fff4f4;
  229. border: none;
  230. border-radius: 4px;
  231. .el-icon-delete {
  232. margin-right: 8px;
  233. }
  234. &:hover {
  235. color: #f53f3f;
  236. }
  237. &:focus {
  238. outline: none;
  239. }
  240. }
  241. .item-left {
  242. width: 72px;
  243. }
  244. .item-right {
  245. flex: 1;
  246. .item-rich {
  247. display: flex;
  248. > label {
  249. flex-shrink: 0;
  250. width: 64px;
  251. font-size: 14px;
  252. line-height: 32px;
  253. color: #4e5969;
  254. }
  255. }
  256. }
  257. }
  258. </style>