RepeatQuestion.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <!-- 听读训练 -->
  2. <template>
  3. <QuestionBase>
  4. <template #content>
  5. <div class="stem">
  6. <RichText v-model="data.stem" placeholder="输入题干" />
  7. <el-input
  8. v-show="isEnable(data.property.is_enable_description)"
  9. v-model="data.description"
  10. rows="3"
  11. resize="none"
  12. type="textarea"
  13. placeholder="输入描述"
  14. />
  15. </div>
  16. <div class="content">
  17. <label class="title-little">内容</label>
  18. <ul>
  19. <li v-for="(item, i) in data.option_list" :key="i" class="content-item repeat-option">
  20. <span class="question-number" title="双击切换序号类型" @dblclick="changeOptionType(data)">
  21. {{ computedQuestionNumber(i, data.option_number_show_mode) }}
  22. </span>
  23. <el-input
  24. v-if="data.other.audio_generation_method === 'auto'"
  25. v-model="item.content"
  26. placeholder="拼音间用空格隔开"
  27. @change="item.audio_file_id = ''"
  28. />
  29. <UploadAudio
  30. v-if="data.other.audio_generation_method === 'upload'"
  31. :key="item.audio_file_id || i"
  32. :file-id="item.audio_file_id"
  33. :item-index="i"
  34. :show-upload="!item.audio_file_id"
  35. @upload="uploads"
  36. @deleteFile="deleteFiles"
  37. />
  38. <div v-else-if="data.other.audio_generation_method === 'auto'" class="auto-matically">
  39. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="gray" />
  40. <span
  41. v-loading="loading_list[i] ? loading_list[i].loading : false"
  42. class="auto-btn"
  43. @click="handleMatically(item, i)"
  44. >{{ item.audio_file_id ? '已生成' : '自动生成' }}</span
  45. >
  46. </div>
  47. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  48. <SvgIcon icon-class="delete" class="delete pointer" @click="deleteOption(i, item.audio_file_id)" />
  49. </li>
  50. </ul>
  51. </div>
  52. <div class="footer">
  53. <span class="add-option" @click="addOption">
  54. <SvgIcon icon-class="add-circle" size="14" /> <span>增加选项</span>
  55. </span>
  56. </div>
  57. </template>
  58. <template #property>
  59. <el-form :model="data.property">
  60. <el-form-item label="题号">
  61. <el-input v-model="data.property.question_number" />
  62. </el-form-item>
  63. <el-form-item label-width="45px">
  64. <el-radio
  65. v-for="{ value, label } in questionNumberTypeList"
  66. :key="value"
  67. v-model="data.other.question_number_type"
  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 switchOption"
  76. :key="value"
  77. v-model="data.property.is_enable_description"
  78. :label="value"
  79. >
  80. {{ label }}
  81. </el-radio>
  82. </el-form-item>
  83. <el-form-item label="分值">
  84. <el-radio
  85. v-for="{ value, label } in scoreTypeList"
  86. :key="value"
  87. v-model="data.property.score_type"
  88. :label="value"
  89. >
  90. {{ label }}
  91. </el-radio>
  92. </el-form-item>
  93. <el-form-item label-width="45px">
  94. <el-input-number
  95. v-model="data.property.score"
  96. :min="0"
  97. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  98. />
  99. </el-form-item>
  100. <el-form-item label="音频">
  101. <el-radio
  102. v-for="{ value, label } in audioGenerationMethodList"
  103. :key="value"
  104. v-model="data.other.audio_generation_method"
  105. :label="value"
  106. >
  107. {{ label }}
  108. </el-radio>
  109. </el-form-item>
  110. </el-form>
  111. </template>
  112. </QuestionBase>
  113. </template>
  114. <script>
  115. import UploadAudio from '../common/UploadAudio.vue';
  116. import QuestionMixin from '../common/QuestionMixin.js';
  117. import SoundRecord from '../common/SoundRecord.vue';
  118. import { selectTypeList, changeOptionType } from '@/views/exercise_questions/data/common';
  119. import { repeatData, getOption, audioGenerationMethodList } from '@/views/exercise_questions/data/repeat';
  120. import { GetStaticResources } from '@/api/app';
  121. export default {
  122. name: 'RepeatQuestion',
  123. components: {
  124. UploadAudio,
  125. SoundRecord,
  126. },
  127. mixins: [QuestionMixin],
  128. data() {
  129. return {
  130. selectTypeList,
  131. audioGenerationMethodList,
  132. changeOptionType,
  133. data: JSON.parse(JSON.stringify(repeatData)),
  134. loading_list: [
  135. {
  136. loading: false,
  137. },
  138. {
  139. loading: false,
  140. },
  141. {
  142. loading: false,
  143. },
  144. ],
  145. };
  146. },
  147. watch: {
  148. 'data.option_list.length': {
  149. handler(val) {
  150. this.loading_list = [];
  151. for (let i = 0; i < val; i++) {
  152. let obj = {
  153. loading: false,
  154. };
  155. this.loading_list.push(obj);
  156. }
  157. },
  158. deep: true,
  159. immediate: true,
  160. },
  161. },
  162. methods: {
  163. /**
  164. * 智能识别
  165. * @param {String} text 识别数据
  166. */
  167. recognition(text) {
  168. let arr = text
  169. .split(/[\r\n]/)
  170. .map((item) => item.trim())
  171. .filter((item) => item);
  172. if (arr.length > 0) {
  173. this.data.stem = arr[0];
  174. this.data.option_list = arr.slice(1).map((content) => getOption(content));
  175. }
  176. },
  177. addOption() {
  178. this.data.option_list.push(getOption());
  179. },
  180. uploads(file_id, index) {
  181. this.data.option_list[index].audio_file_id = file_id;
  182. this.data.file_id_list.push(file_id);
  183. },
  184. deleteFiles(file_id, itemIndex) {
  185. this.data.option_list[itemIndex].audio_file_id = '';
  186. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  187. },
  188. // 删除小题
  189. deleteOption(i, file_id) {
  190. this.$confirm('是否删除?', '提示', {
  191. confirmButtonText: '确定',
  192. cancelButtonText: '取消',
  193. type: 'warning',
  194. })
  195. .then(() => {
  196. this.data.option_list.splice(i, 1);
  197. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  198. this.loading_list.splice(i, 1);
  199. })
  200. .catch(() => {});
  201. },
  202. // 自动生成音频
  203. handleMatically(item, i) {
  204. if (item.content.trim()) {
  205. this.loading_list[i].loading = true;
  206. let MethodName = 'tool-PinyinToVoiceFile';
  207. let data = {
  208. pinyin: item.content.trim().split(' ').join(','),
  209. };
  210. GetStaticResources(MethodName, data)
  211. .then((res) => {
  212. this.loading_list[i].loading = false;
  213. if (res.status === 1) {
  214. item.audio_file_id = res.file_id;
  215. this.data.file_id_list.push(res.file_id);
  216. }
  217. })
  218. .catch(() => {
  219. this.loading_list[i].loading = false;
  220. });
  221. }
  222. },
  223. },
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .repeat-option {
  228. :deep .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. flex-shrink: 0;
  240. align-items: center;
  241. width: 233px;
  242. padding: 5px 12px;
  243. background-color: $fill-color;
  244. border-radius: 2px;
  245. .audio-wrapper {
  246. margin-right: 12px;
  247. :deep .audio-play {
  248. width: 16px;
  249. height: 16px;
  250. color: #000;
  251. background-color: initial;
  252. }
  253. :deep .audio-play.not-url {
  254. color: #a1a1a1;
  255. }
  256. :deep .voice-play {
  257. width: 16px;
  258. height: 16px;
  259. }
  260. }
  261. .auto-btn {
  262. font-size: 14px;
  263. font-weight: 400;
  264. line-height: 22px;
  265. color: #1d2129;
  266. cursor: pointer;
  267. }
  268. }
  269. .delete {
  270. flex-shrink: 0;
  271. }
  272. }
  273. </style>