ChineseQuestion.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <QuestionBase>
  3. <template #content>
  4. <div class="stem">
  5. <RichText v-model="data.stem" placeholder="输入题干" />
  6. <RichText
  7. v-if="isEnable(data.property.is_enable_description)"
  8. v-model="data.description"
  9. placeholder="输入提示"
  10. />
  11. </div>
  12. <div class="content">
  13. <label class="title-little">题目:</label>
  14. <ul>
  15. <li
  16. v-for="(item, i) in data.option_list"
  17. :key="i"
  18. v-loading="loading_list[i] ? loading_list[i].loadings : false"
  19. class="content-item"
  20. >
  21. <span
  22. v-if="data.property.learn_type === 'dictation'"
  23. class="question-number"
  24. title="双击切换序号类型"
  25. @dblclick="changeOptionType(data)"
  26. >
  27. {{ computedQuestionNumber(i, data.option_number_show_mode) }}
  28. </span>
  29. <el-input v-model="item.content" :placeholder="'输入汉字或词汇'" @blur="handleChineseStrokes(item, i)" />
  30. <el-input
  31. v-model="item.pinyin"
  32. :placeholder="'拼音间用空格隔开'"
  33. @blur="handleSplitPy(item)"
  34. @change="changePinyin(item)"
  35. />
  36. <UploadAudio
  37. v-if="data.other.audio_generation_method === 'upload'"
  38. :key="item.audio_file_id || i"
  39. :file-id="item.audio_file_id"
  40. :item-index="i"
  41. :show-upload="!item.audio_file_id"
  42. @upload="uploads"
  43. @deleteFile="deleteFiles"
  44. />
  45. <div v-else-if="data.other.audio_generation_method === 'auto'" class="auto-matically">
  46. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="gray" />
  47. <span
  48. v-loading="loading_list[i] ? loading_list[i].loading : false"
  49. class="auto-btn"
  50. @click="handleMatically(item, i)"
  51. >{{ item.audio_file_id ? '已生成' : '自动生成' }}</span
  52. >
  53. </div>
  54. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  55. <el-input
  56. v-if="data.property.learn_type !== 'dictation'"
  57. v-model="item.definition"
  58. placeholder="输入释义"
  59. />
  60. <el-input
  61. v-if="data.property.learn_type !== 'dictation'"
  62. v-model="item.collocation"
  63. placeholder="输入搭配"
  64. />
  65. <SvgIcon icon-class="delete" class="delete pointer" @click="deleteOption(i, item.audio_file_id)" />
  66. </li>
  67. </ul>
  68. </div>
  69. <div class="footer">
  70. <span class="add-option" @click="addOption">
  71. <SvgIcon icon-class="add-circle" size="14" /> <span>增加汉字</span>
  72. </span>
  73. </div>
  74. </template>
  75. <template #property>
  76. <el-form :model="data.property">
  77. <el-form-item label="题号">
  78. <el-input v-model="data.property.question_number" />
  79. </el-form-item>
  80. <el-form-item label-width="45px">
  81. <el-radio
  82. v-for="{ value, label } in questionNumberTypeList"
  83. :key="value"
  84. v-model="data.other.question_number_type"
  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 switchOption"
  93. :key="value"
  94. v-model="data.property.is_enable_description"
  95. :label="value"
  96. >
  97. {{ label }}
  98. </el-radio>
  99. </el-form-item>
  100. <el-form-item label="分值">
  101. <el-radio
  102. v-for="{ value, label } in scoreTypeList"
  103. :key="value"
  104. v-model="data.property.score_type"
  105. :label="value"
  106. >
  107. {{ label }}
  108. </el-radio>
  109. </el-form-item>
  110. <el-form-item label-width="45px">
  111. <el-input-number
  112. v-model="data.property.score"
  113. :min="0"
  114. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  115. />
  116. </el-form-item>
  117. <el-form-item label="类型">
  118. <el-radio
  119. v-for="{ value, label } in learnTypeList"
  120. :key="value"
  121. v-model="data.property.learn_type"
  122. :label="value"
  123. >
  124. {{ label }}
  125. </el-radio>
  126. </el-form-item>
  127. <el-form-item v-if="data.property.learn_type !== 'dictation'" label="田字格组">
  128. <el-input
  129. v-model="data.property.tian_number"
  130. type="number"
  131. @blur="data.property.tian_number = handleInputNumber(data.property.tian_number)"
  132. />
  133. </el-form-item>
  134. <el-form-item label="音频">
  135. <el-radio
  136. v-for="{ value, label } in audioGenerationMethodList"
  137. :key="value"
  138. v-model="data.other.audio_generation_method"
  139. :label="value"
  140. >
  141. {{ label }}
  142. </el-radio>
  143. </el-form-item>
  144. </el-form>
  145. </template>
  146. </QuestionBase>
  147. </template>
  148. <script>
  149. import QuestionMixin from '../common/QuestionMixin.js';
  150. import UploadAudio from '../common/UploadAudio.vue';
  151. import SoundRecord from '../common/SoundRecord.vue';
  152. import { GetStaticResources } from '@/api/app';
  153. import { changeOptionType, handleInputNumber } from '@/views/exercise_questions/data/common';
  154. import { getRandomNumber } from '@/utils/index';
  155. import {
  156. chineseData,
  157. learnTypeList,
  158. audioGenerationMethodList,
  159. getOption,
  160. } from '@/views/exercise_questions/data/chinese';
  161. export default {
  162. name: 'ChineseQuestion',
  163. components: {
  164. UploadAudio,
  165. SoundRecord,
  166. },
  167. mixins: [QuestionMixin],
  168. data() {
  169. return {
  170. learnTypeList,
  171. audioGenerationMethodList,
  172. data: JSON.parse(JSON.stringify(chineseData)),
  173. changeOptionType,
  174. handleInputNumber,
  175. loading_list: [
  176. {
  177. loading: false,
  178. loadings: false,
  179. },
  180. {
  181. loading: false,
  182. loadings: false,
  183. },
  184. {
  185. loading: false,
  186. loadings: false,
  187. },
  188. ],
  189. };
  190. },
  191. watch: {
  192. 'data.option_list.length': {
  193. handler(val) {
  194. this.loading_list = [];
  195. for (let i = 0; i < val; i++) {
  196. let obj = {
  197. loading: false,
  198. loadings: false,
  199. };
  200. this.loading_list.push(obj);
  201. }
  202. },
  203. deep: true,
  204. immediate: true,
  205. },
  206. },
  207. mounted() {
  208. // if (this.data.option_list.length > 3) {
  209. // let length = this.data.option_list.length - 3;
  210. // for (let i = 0; i < length; i++) {
  211. // let obj = {
  212. // loading: false,
  213. // loadings: false,
  214. // };
  215. // this.loading_list.push(obj);
  216. // }
  217. // }
  218. },
  219. methods: {
  220. addOption() {
  221. this.data.option_list.push(getOption());
  222. this.loading_list.push({
  223. loading: false,
  224. loadings: false,
  225. });
  226. },
  227. uploads(file_id, index) {
  228. this.data.option_list[index].audio_file_id = file_id;
  229. this.data.file_id_list.push(file_id);
  230. },
  231. deleteFiles(file_id, itemIndex) {
  232. this.data.option_list[itemIndex].audio_file_id = '';
  233. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  234. },
  235. // 删除小题
  236. deleteOption(i, file_id) {
  237. this.$confirm('是否删除?', '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning',
  241. })
  242. .then(() => {
  243. this.data.option_list.splice(i, 1);
  244. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  245. this.loading_list.splice(i, 1);
  246. })
  247. .catch(() => {});
  248. },
  249. // 自动生成音频
  250. handleMatically(item, i) {
  251. if (item.pinyin.trim()) {
  252. this.loading_list[i].loading = true;
  253. let MethodName = 'tool-PinyinToVoiceFile';
  254. let data = {
  255. pinyin: item.pinyin.trim().split(' ').join(','),
  256. };
  257. GetStaticResources(MethodName, data)
  258. .then((res) => {
  259. this.loading_list[i].loading = false;
  260. if (res.status === 1) {
  261. item.audio_file_id = res.file_id;
  262. this.data.file_id_list.push(res.file_id);
  263. }
  264. })
  265. .catch(() => {
  266. this.loading_list[i].loading = false;
  267. });
  268. }
  269. },
  270. // 生成汉字
  271. handleChineseStrokes(item, i) {
  272. if (item.content.trim()) {
  273. this.loading_list[i].loadings = true;
  274. let content_arr = item.content.trim().split('');
  275. let content_arrs = [];
  276. let content_arr_strokes = [];
  277. content_arr.forEach((itemc) => {
  278. if (itemc.trim()) {
  279. content_arrs.push(itemc.trim());
  280. }
  281. });
  282. content_arrs.forEach((itemc, indexc) => {
  283. content_arr_strokes.push(null);
  284. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  285. let data = {
  286. hz: itemc,
  287. };
  288. GetStaticResources(MethodName, data).then((res) => {
  289. let obj = {
  290. hz: itemc.trim(),
  291. strokes: res,
  292. };
  293. content_arr_strokes[indexc] = obj;
  294. });
  295. });
  296. this.loading_list[i].loadings = false;
  297. item.hz_strokes_list = content_arr_strokes;
  298. }
  299. },
  300. // 切割拼音
  301. handleSplitPy(item) {
  302. let pinyin_list = item.pinyin.trim().split(' ');
  303. item.pinyin_item_list = [];
  304. pinyin_list.forEach((itemp) => {
  305. let obj = {
  306. pinyin_item: itemp,
  307. };
  308. item.pinyin_item_list.push(obj);
  309. });
  310. },
  311. // 修改拼音
  312. changePinyin(item) {
  313. if (this.data.other.audio_generation_method === 'auto') {
  314. item.audio_file_id = '';
  315. }
  316. },
  317. /**
  318. * 智能识别
  319. * @param {String} text 识别数据
  320. */
  321. recognition(text) {
  322. let arr = text
  323. .split(/[\r\n]/)
  324. .map((item) => item.trim())
  325. .filter((item) => item);
  326. if (arr.length > 0) {
  327. this.data.stem = arr[0];
  328. this.data.option_list = [];
  329. arr.slice(1).map((content, index) => {
  330. let content_item = content.split('&&');
  331. this.data.option_list.push({
  332. content: content_item[0] ? content_item[0] : '',
  333. mark: getRandomNumber(),
  334. audio_file_id: '',
  335. pinyin: content_item[1] ? content_item[1] : '',
  336. pinyin_item_list: [],
  337. definition: content_item[2] ? content_item[2] : '',
  338. collocation: content_item[3] ? content_item[3] : '',
  339. hz_strokes_list: [],
  340. });
  341. this.handleSplitPy(this.data.option_list[index]);
  342. this.handleChineseStrokes(this.data.option_list[index], index);
  343. });
  344. }
  345. },
  346. },
  347. };
  348. </script>
  349. <style lang="scss" scoped>
  350. .content {
  351. display: flex;
  352. flex-direction: column;
  353. .content-item {
  354. .upload-wrapper {
  355. margin-top: 0;
  356. }
  357. :deep .file-name {
  358. width: 205px;
  359. overflow: hidden;
  360. text-overflow: ellipsis;
  361. white-space: nowrap;
  362. }
  363. .auto-matically {
  364. display: flex;
  365. flex-shrink: 0;
  366. align-items: center;
  367. width: 233px;
  368. padding: 5px 12px;
  369. background-color: $fill-color;
  370. border-radius: 2px;
  371. .audio-wrapper {
  372. margin-right: 12px;
  373. :deep .audio-play {
  374. width: 16px;
  375. height: 16px;
  376. color: #000;
  377. background-color: initial;
  378. }
  379. :deep .audio-play.not-url {
  380. color: #a1a1a1;
  381. }
  382. :deep .voice-play {
  383. width: 16px;
  384. height: 16px;
  385. }
  386. }
  387. .auto-btn {
  388. font-size: 14px;
  389. font-weight: 400;
  390. line-height: 22px;
  391. color: #1d2129;
  392. cursor: pointer;
  393. }
  394. }
  395. .delete {
  396. flex-shrink: 0;
  397. width: 16px;
  398. height: 16px;
  399. }
  400. }
  401. }
  402. </style>