RepeatQuestion.vue 8.0 KB

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