RepeatQuestion.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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
  22. v-model="item.content"
  23. class="repeat-richtext"
  24. placeholder="输入内容"
  25. :inline="true"
  26. @handleRichTextBlur="handleRichTextBlur"
  27. />
  28. </div>
  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-select v-model="data.property.stem_question_number">
  75. <el-option v-for="item in fontSizeList" :key="item" :label="item" :value="item" />
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="选项题号">
  79. <el-select v-model="data.property.option_question_number">
  80. <el-option v-for="item in fontSizeList" :key="item" :label="item" :value="item" />
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item label="提示">
  84. <el-radio
  85. v-for="{ value, label } in switchOption"
  86. :key="value"
  87. v-model="data.property.is_enable_description"
  88. :label="value"
  89. >
  90. {{ label }}
  91. </el-radio>
  92. </el-form-item>
  93. <el-form-item label="分值">
  94. <el-radio
  95. v-for="{ value, label } in scoreTypeList"
  96. :key="value"
  97. v-model="data.property.score_type"
  98. :label="value"
  99. >
  100. {{ label }}
  101. </el-radio>
  102. </el-form-item>
  103. <el-form-item label-width="45px">
  104. <el-input-number
  105. v-model="data.property.score"
  106. :min="0"
  107. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  108. />
  109. </el-form-item>
  110. <el-form-item label="音频">
  111. <el-radio
  112. v-for="{ value, label } in audioGenerationMethodList"
  113. :key="value"
  114. v-model="data.other.audio_generation_method"
  115. :label="value"
  116. >
  117. {{ label }}
  118. </el-radio>
  119. </el-form-item>
  120. </el-form>
  121. </template>
  122. </QuestionBase>
  123. </template>
  124. <script>
  125. import UploadAudio from '../common/UploadAudio.vue';
  126. import QuestionMixin from '../common/QuestionMixin.js';
  127. import SoundRecord from '../common/SoundRecord.vue';
  128. import { selectTypeList, changeOptionType, addTone } from '@/views/exercise_questions/data/common';
  129. import { repeatData, getOption, audioGenerationMethodList } from '@/views/exercise_questions/data/repeat';
  130. import { GetStaticResources } from '@/api/app';
  131. export default {
  132. name: 'RepeatQuestion',
  133. components: {
  134. UploadAudio,
  135. SoundRecord,
  136. },
  137. mixins: [QuestionMixin],
  138. data() {
  139. return {
  140. selectTypeList,
  141. audioGenerationMethodList,
  142. changeOptionType,
  143. data: JSON.parse(JSON.stringify(repeatData)),
  144. loading_list: [
  145. {
  146. loading: false,
  147. },
  148. {
  149. loading: false,
  150. },
  151. {
  152. loading: false,
  153. },
  154. ],
  155. matically_pinyin_obj: {},
  156. };
  157. },
  158. watch: {
  159. 'data.option_list.length': {
  160. handler(val) {
  161. this.loading_list = [];
  162. for (let i = 0; i < val; i++) {
  163. let obj = {
  164. loading: false,
  165. };
  166. this.loading_list.push(obj);
  167. }
  168. },
  169. deep: true,
  170. immediate: true,
  171. },
  172. },
  173. methods: {
  174. /**
  175. * 智能识别
  176. * @param {String} text 识别数据
  177. */
  178. recognition(text) {
  179. let arr = text
  180. .split(/[\r\n]/)
  181. .map((item) => item.trim())
  182. .filter((item) => item);
  183. if (arr.length > 0) {
  184. this.data.stem = arr[0];
  185. this.data.option_list = arr.slice(1).map((content) => getOption(content));
  186. }
  187. },
  188. addOption() {
  189. this.data.option_list.push(getOption());
  190. },
  191. uploads(file_id, index) {
  192. this.data.option_list[index].audio_file_id = file_id;
  193. this.data.file_id_list.push(file_id);
  194. },
  195. deleteFiles(file_id, itemIndex) {
  196. this.data.option_list[itemIndex].audio_file_id = '';
  197. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  198. },
  199. // 删除小题
  200. deleteOption(i, file_id) {
  201. this.$confirm('是否删除?', '提示', {
  202. confirmButtonText: '确定',
  203. cancelButtonText: '取消',
  204. type: 'warning',
  205. })
  206. .then(() => {
  207. this.data.option_list.splice(i, 1);
  208. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  209. this.loading_list.splice(i, 1);
  210. })
  211. .catch(() => {});
  212. },
  213. handleReplaceTone(value, mark) {
  214. if (!value) return;
  215. value.split(/\s+/).forEach((item) => {
  216. this.handleValue(item);
  217. });
  218. this.matically_pinyin_obj[mark] = this.res_arr
  219. .map((item) =>
  220. item.map(({ number, con }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  221. )
  222. .filter((item) => item.length > 0)
  223. .join(' ');
  224. },
  225. handleValue(valItem) {
  226. let numList = [];
  227. if (/[A-Za-zü]+\d/g.test(valItem)) {
  228. valItem.split('').forEach((item, i) => {
  229. if (/\d/.test(item)) {
  230. let con = valItem.replace(/\d/g, '');
  231. numList.push({
  232. index: i,
  233. number: item,
  234. con,
  235. isTran: true,
  236. });
  237. }
  238. });
  239. } else {
  240. numList = [];
  241. }
  242. this.res_arr.push(numList.length === 0 ? [{ con: valItem }] : numList);
  243. },
  244. handleItemPinyin(content, mark) {
  245. let content_arr = content.trim().split(' ');
  246. this.res_arr = [];
  247. this.$set(this.matically_pinyin_obj, mark, []);
  248. content_arr.forEach((items, index) => {
  249. let items_trim = items.trim();
  250. if (items_trim) {
  251. this.handleReplaceTone(items_trim, mark);
  252. }
  253. });
  254. },
  255. // 转成带声调的拼音
  256. handleRichTextBlur() {
  257. let rich_rext_arr = document.getElementsByClassName('repeat-richtext');
  258. if (rich_rext_arr) {
  259. for (let i = 0; i < rich_rext_arr.length; i++) {
  260. let content = rich_rext_arr[i].innerText;
  261. let index = content.search(/0|1|2|3|4/);
  262. if (index > -1) {
  263. this.handleItemPinyin(content, this.data.option_list[i].mark);
  264. setTimeout(() => {
  265. document.getElementsByClassName('repeat-richtext')[i].innerText =
  266. this.matically_pinyin_obj[this.data.option_list[i].mark];
  267. }, 100);
  268. }
  269. }
  270. }
  271. },
  272. // 自动生成音频
  273. handleMatically(item, i) {
  274. if (
  275. document.getElementsByClassName('repeat-richtext') &&
  276. document.getElementsByClassName('repeat-richtext')[i] &&
  277. document.getElementsByClassName('repeat-richtext')[i].innerText
  278. ) {
  279. this.loading_list[i].loading = true;
  280. let MethodName = 'tool-PinyinToVoiceFile';
  281. let data = {
  282. pinyin: document.getElementsByClassName('repeat-richtext')[i].innerText.trim().split(' ').join(','),
  283. };
  284. GetStaticResources(MethodName, data)
  285. .then((res) => {
  286. this.loading_list[i].loading = false;
  287. if (res.status === 1) {
  288. item.audio_file_id = res.file_id;
  289. this.data.file_id_list.push(res.file_id);
  290. }
  291. })
  292. .catch(() => {
  293. this.loading_list[i].loading = false;
  294. });
  295. }
  296. },
  297. },
  298. };
  299. </script>
  300. <style lang="scss" scoped>
  301. .repeat-option {
  302. :deep .upload-wrapper {
  303. margin-top: 0;
  304. }
  305. :deep .file-name {
  306. width: 205px;
  307. overflow: hidden;
  308. text-overflow: ellipsis;
  309. white-space: nowrap;
  310. }
  311. .auto-matically {
  312. display: flex;
  313. flex-shrink: 0;
  314. align-items: center;
  315. width: 233px;
  316. padding: 5px 12px;
  317. background-color: $fill-color;
  318. border-radius: 2px;
  319. .audio-wrapper {
  320. margin-right: 12px;
  321. :deep .audio-play {
  322. width: 16px;
  323. height: 16px;
  324. color: #000;
  325. background-color: initial;
  326. }
  327. :deep .audio-play.not-url {
  328. color: #a1a1a1;
  329. }
  330. :deep .voice-play {
  331. width: 16px;
  332. height: 16px;
  333. }
  334. }
  335. .auto-btn {
  336. font-size: 14px;
  337. font-weight: 400;
  338. line-height: 22px;
  339. color: #1d2129;
  340. cursor: pointer;
  341. }
  342. }
  343. .delete {
  344. flex-shrink: 0;
  345. }
  346. }
  347. </style>