ChooseToneQuestion.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <QuestionBase>
  3. <template #content>
  4. <div class="stem">
  5. <el-input
  6. v-if="data.property.stem_type === stemTypeList[0].value"
  7. v-model="data.stem"
  8. rows="3"
  9. resize="none"
  10. type="textarea"
  11. placeholder="输入题干"
  12. />
  13. <RichText v-if="data.property.stem_type === stemTypeList[1].value" v-model="data.stem" placeholder="输入题干" />
  14. <el-input
  15. v-show="isEnable(data.property.is_enable_description)"
  16. v-model="data.description"
  17. rows="3"
  18. resize="none"
  19. type="textarea"
  20. placeholder="输入描述"
  21. />
  22. </div>
  23. <div class="content">
  24. <label class="subtitle">内容</label>
  25. <ul>
  26. <li v-for="(item, i) in data.option_list" :key="i" class="content-item">
  27. <span class="question-number" @dblclick="changeOptionType(data)">
  28. {{ computedQuestionNumber(i, data.option_number_show_mode) }}.
  29. </span>
  30. <el-input v-model="item.content" placeholder="输入内容" @blur="handleItemAnswer(item)" />
  31. <UploadAudio
  32. v-if="data.other.audio_generation_method === 'upload'"
  33. :key="item.audio_file_id || i"
  34. :file-id="item.audio_file_id"
  35. :item-index="i"
  36. :show-upload="!item.audio_file_id"
  37. @upload="uploads"
  38. @deleteFile="deleteFiles"
  39. />
  40. <div v-else-if="data.other.audio_generation_method === 'auto'" class="auto-matically">
  41. <AudioPlay :file-id="item.audio_file_id" theme-color="gray" />
  42. <span class="auto-btn" @click="handleMatically">自动生成</span>
  43. </div>
  44. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  45. <SvgIcon icon-class="delete" class="delete pointer" @click="deleteOption(i, item.audio_file_id)" />
  46. </li>
  47. </ul>
  48. </div>
  49. <div class="footer">
  50. <span class="add-option" @click="addOption">
  51. <SvgIcon icon-class="add-circle" size="14" /> <span>增加选项</span>
  52. </span>
  53. </div>
  54. </template>
  55. <template #property>
  56. <el-form :model="data.property">
  57. <el-form-item label="题干">
  58. <el-radio
  59. v-for="{ value, label } in stemTypeList"
  60. :key="value"
  61. v-model="data.property.stem_type"
  62. :label="value"
  63. >
  64. {{ label }}
  65. </el-radio>
  66. </el-form-item>
  67. <el-form-item label="题号">
  68. <el-input v-model="data.property.question_number" />
  69. </el-form-item>
  70. <el-form-item label-width="45px">
  71. <el-radio
  72. v-for="{ value, label } in questionNumberTypeList"
  73. :key="value"
  74. v-model="data.other.question_number_type"
  75. :label="value"
  76. >
  77. {{ label }}
  78. </el-radio>
  79. </el-form-item>
  80. <el-form-item label="描述">
  81. <el-radio
  82. v-for="{ value, label } in switchOption"
  83. :key="value"
  84. v-model="data.property.is_enable_description"
  85. :label="value"
  86. >
  87. {{ label }}
  88. </el-radio>
  89. </el-form-item>
  90. <el-form-item label="分值">
  91. <el-radio
  92. v-for="{ value, label } in scoreTypeList"
  93. :key="value"
  94. v-model="data.property.score_type"
  95. :label="value"
  96. >
  97. {{ label }}
  98. </el-radio>
  99. </el-form-item>
  100. <el-form-item label-width="45px">
  101. <el-input v-model="data.property.score" type="number" />
  102. </el-form-item>
  103. <el-form-item label="类型">
  104. <el-radio
  105. v-for="{ value, label } in toneTypeList"
  106. :key="value"
  107. v-model="data.property.answer_mode"
  108. :label="value"
  109. @change="handleChangeType"
  110. >
  111. {{ label }}
  112. </el-radio>
  113. </el-form-item>
  114. <el-form-item label="音频">
  115. <el-radio
  116. v-for="{ value, label } in audioGenerationMethodList"
  117. :key="value"
  118. v-model="data.other.audio_generation_method"
  119. :label="value"
  120. >
  121. {{ label }}
  122. </el-radio>
  123. </el-form-item>
  124. </el-form>
  125. </template>
  126. </QuestionBase>
  127. </template>
  128. <script>
  129. import QuestionMixin from '@/views/exercise_questions/create/components/common/QuestionMixin';
  130. import UploadAudio from '../common/UploadAudio.vue';
  131. import SoundRecord from '../common/SoundRecord.vue';
  132. import { changeOptionType } from '@/views/exercise_questions/data/common';
  133. import {
  134. getOption,
  135. ChooseToneData,
  136. audioGenerationMethodList,
  137. toneList,
  138. toneTypeList,
  139. } from '@/views/exercise_questions/data/chooseTone';
  140. export default {
  141. name: 'ChooseToneQuestion',
  142. components: {
  143. UploadAudio,
  144. SoundRecord,
  145. },
  146. mixins: [QuestionMixin],
  147. data() {
  148. return {
  149. toneList,
  150. changeOptionType,
  151. audioGenerationMethodList,
  152. toneTypeList,
  153. data: JSON.parse(JSON.stringify(ChooseToneData)),
  154. };
  155. },
  156. methods: {
  157. addOption() {
  158. this.data.option_list.push(getOption());
  159. },
  160. uploads(file_id, index) {
  161. this.data.option_list[index].audio_file_id = file_id;
  162. this.data.file_id_list.push(file_id);
  163. },
  164. deleteFiles(file_id, itemIndex) {
  165. this.data.option_list[itemIndex].audio_file_id = '';
  166. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  167. },
  168. // 删除小题
  169. deleteOption(i, file_id) {
  170. this.data.option_list.splice(i, 1);
  171. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  172. },
  173. // 自动生成音频
  174. handleMatically() {},
  175. // 答案
  176. handleItemAnswer(item) {
  177. const index = this.data.answer.answer_list.findIndex((items) => items.mark === item.mark);
  178. let content = item.content.trim();
  179. let content_arr = content.split(' ');
  180. let select_item = '';
  181. let content_preview = '';
  182. content_arr.forEach((items) => {
  183. let items_trim = items.trim();
  184. if (items_trim) {
  185. let items_yuan = JSON.parse(JSON.stringify(items_trim)).replace(/0|1|2|3|4/, '');
  186. let indexs = items.search(/0|1|2|3|4/);
  187. if (this.data.property.answer_mode === 'select') {
  188. // 如果是选择声调 把声调放在拼音后面
  189. // select_item += `${items_yuan + items_trim.substring(indexs, indexs + 1)} `;
  190. select_item += `${items_trim.substring(indexs, indexs + 1)} `;
  191. } else if (this.data.property.answer_mode === 'label') {
  192. // 如果是标注声调 把声调放在对应字母后面
  193. select_item += `${items_trim} `;
  194. }
  195. content_preview += `${items_yuan} `;
  196. }
  197. });
  198. if (index === -1) {
  199. let obj = {
  200. mark: item.mark,
  201. value: select_item.trim().split(' '),
  202. };
  203. this.data.answer.answer_list.push(obj);
  204. } else {
  205. this.data.answer.answer_list[index].value = select_item.trim().split(' ');
  206. }
  207. item.content_view = content_preview.trim().split(' ');
  208. },
  209. // 改变类型
  210. handleChangeType() {
  211. this.data.option_list.forEach((item) => {
  212. this.handleItemAnswer(item);
  213. });
  214. },
  215. },
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. .content {
  220. display: flex;
  221. flex-direction: column;
  222. .subtitle {
  223. margin: 8px 0;
  224. font-size: 14px;
  225. color: #4e5969;
  226. }
  227. .content-item {
  228. .upload-wrapper {
  229. margin-top: 0;
  230. }
  231. :deep .file-name {
  232. width: 205px;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. white-space: nowrap;
  236. }
  237. .auto-matically {
  238. display: flex;
  239. align-items: center;
  240. width: 233px;
  241. padding: 5px 12px;
  242. background-color: $fill-color;
  243. border-radius: 2px;
  244. .audio-wrapper {
  245. margin-right: 12px;
  246. :deep .audio-play {
  247. width: 16px;
  248. height: 16px;
  249. color: #000;
  250. background-color: initial;
  251. }
  252. :deep .audio-play.not-url {
  253. color: #a1a1a1;
  254. }
  255. :deep .voice-play {
  256. width: 16px;
  257. height: 16px;
  258. }
  259. }
  260. .auto-btn {
  261. font-size: 14px;
  262. font-weight: 400;
  263. line-height: 22px;
  264. color: #1d2129;
  265. cursor: pointer;
  266. }
  267. }
  268. .delete {
  269. flex-shrink: 0;
  270. width: 16px;
  271. height: 16px;
  272. }
  273. }
  274. }
  275. </style>