ChineseQuestion.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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="title-little">题目:</label>
  25. <ul>
  26. <li
  27. v-for="(item, i) in data.option_list"
  28. :key="i"
  29. v-loading="loading_list[i] ? loading_list[i].loadings : false"
  30. class="content-item"
  31. >
  32. <span
  33. v-if="data.property.learn_type === 'dictation'"
  34. class="question-number"
  35. title="双击切换序号类型"
  36. @dblclick="changeOptionType(data)"
  37. >
  38. {{ computedQuestionNumber(i, data.option_number_show_mode) }}
  39. </span>
  40. <el-input
  41. v-model="item.content"
  42. :maxlength="data.property.learn_type === 'dictation' ? null : 1"
  43. :placeholder="data.property.learn_type === 'dictation' ? '输入汉字或词汇' : '输入一个汉字'"
  44. @blur="handleChineseStrokes(item, i)"
  45. />
  46. <el-input
  47. v-model="item.pinyin"
  48. :placeholder="data.property.learn_type === 'dictation' ? '拼音间用空格隔开' : '输入拼音'"
  49. @blur="handleSplitPy(item)"
  50. />
  51. <UploadAudio
  52. v-if="data.other.audio_generation_method === 'upload'"
  53. :key="item.audio_file_id || i"
  54. :file-id="item.audio_file_id"
  55. :item-index="i"
  56. :show-upload="!item.audio_file_id"
  57. @upload="uploads"
  58. @deleteFile="deleteFiles"
  59. />
  60. <div v-else-if="data.other.audio_generation_method === 'auto'" class="auto-matically">
  61. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="gray" />
  62. <span
  63. v-loading="loading_list[i] ? loading_list[i].loading : false"
  64. class="auto-btn"
  65. @click="handleMatically(item, i)"
  66. >{{ item.audio_file_id ? '已生成' : '自动生成' }}</span
  67. >
  68. </div>
  69. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  70. <el-input
  71. v-if="data.property.learn_type !== 'dictation'"
  72. v-model="item.definition"
  73. placeholder="输入释义"
  74. />
  75. <el-input
  76. v-if="data.property.learn_type !== 'dictation'"
  77. v-model="item.collocation"
  78. placeholder="输入搭配"
  79. />
  80. <SvgIcon icon-class="delete" class="delete pointer" @click="deleteOption(i, item.audio_file_id)" />
  81. </li>
  82. </ul>
  83. </div>
  84. <div class="footer">
  85. <span class="add-option" @click="addOption">
  86. <SvgIcon icon-class="add-circle" size="14" /> <span>增加汉字</span>
  87. </span>
  88. </div>
  89. </template>
  90. <template #property>
  91. <el-form :model="data.property">
  92. <el-form-item label="题干">
  93. <el-radio
  94. v-for="{ value, label } in stemTypeList"
  95. :key="value"
  96. v-model="data.property.stem_type"
  97. :label="value"
  98. >
  99. {{ label }}
  100. </el-radio>
  101. </el-form-item>
  102. <el-form-item label="题号">
  103. <el-input v-model="data.property.question_number" />
  104. </el-form-item>
  105. <el-form-item label-width="45px">
  106. <el-radio
  107. v-for="{ value, label } in questionNumberTypeList"
  108. :key="value"
  109. v-model="data.other.question_number_type"
  110. :label="value"
  111. >
  112. {{ label }}
  113. </el-radio>
  114. </el-form-item>
  115. <el-form-item label="描述">
  116. <el-radio
  117. v-for="{ value, label } in switchOption"
  118. :key="value"
  119. v-model="data.property.is_enable_description"
  120. :label="value"
  121. >
  122. {{ label }}
  123. </el-radio>
  124. </el-form-item>
  125. <el-form-item label="分值">
  126. <el-radio
  127. v-for="{ value, label } in scoreTypeList"
  128. :key="value"
  129. v-model="data.property.score_type"
  130. :label="value"
  131. >
  132. {{ label }}
  133. </el-radio>
  134. </el-form-item>
  135. <el-form-item label-width="45px">
  136. <el-input-number
  137. v-model="data.property.score"
  138. :min="0"
  139. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  140. />
  141. </el-form-item>
  142. <el-form-item label="类型">
  143. <el-radio
  144. v-for="{ value, label } in learnTypeList"
  145. :key="value"
  146. v-model="data.property.learn_type"
  147. :label="value"
  148. @change="handleChangeType"
  149. >
  150. {{ label }}
  151. </el-radio>
  152. </el-form-item>
  153. <el-form-item v-if="data.property.learn_type !== 'dictation'" label="田字格数">
  154. <el-input
  155. v-model="data.property.tian_number"
  156. type="number"
  157. @blur="data.property.tian_number = handleInputNumber(data.property.tian_number)"
  158. />
  159. </el-form-item>
  160. <el-form-item label="音频">
  161. <el-radio
  162. v-for="{ value, label } in audioGenerationMethodList"
  163. :key="value"
  164. v-model="data.other.audio_generation_method"
  165. :label="value"
  166. >
  167. {{ label }}
  168. </el-radio>
  169. </el-form-item>
  170. </el-form>
  171. </template>
  172. </QuestionBase>
  173. </template>
  174. <script>
  175. import QuestionMixin from '../common/QuestionMixin.js';
  176. import UploadAudio from '../common/UploadAudio.vue';
  177. import SoundRecord from '../common/SoundRecord.vue';
  178. import { GetStaticResources } from '@/api/app';
  179. import { changeOptionType, handleInputNumber } from '@/views/exercise_questions/data/common';
  180. import {
  181. chineseData,
  182. learnTypeList,
  183. audioGenerationMethodList,
  184. getOption,
  185. } from '@/views/exercise_questions/data/chinese';
  186. export default {
  187. name: 'ChineseQuestion',
  188. components: {
  189. UploadAudio,
  190. SoundRecord,
  191. },
  192. mixins: [QuestionMixin],
  193. data() {
  194. return {
  195. learnTypeList,
  196. audioGenerationMethodList,
  197. data: JSON.parse(JSON.stringify(chineseData)),
  198. changeOptionType,
  199. handleInputNumber,
  200. loading_list: [
  201. {
  202. loading: false,
  203. loadings: false,
  204. },
  205. {
  206. loading: false,
  207. loadings: false,
  208. },
  209. {
  210. loading: false,
  211. loadings: false,
  212. },
  213. ],
  214. };
  215. },
  216. watch: {
  217. 'data.option_list.length': {
  218. handler(val) {
  219. this.loading_list = [];
  220. for (let i = 0; i < val; i++) {
  221. let obj = {
  222. loading: false,
  223. loadings: false,
  224. };
  225. this.loading_list.push(obj);
  226. }
  227. },
  228. deep: true,
  229. immediate: true,
  230. },
  231. },
  232. mounted() {
  233. // if (this.data.option_list.length > 3) {
  234. // let length = this.data.option_list.length - 3;
  235. // for (let i = 0; i < length; i++) {
  236. // let obj = {
  237. // loading: false,
  238. // loadings: false,
  239. // };
  240. // this.loading_list.push(obj);
  241. // }
  242. // }
  243. },
  244. methods: {
  245. addOption() {
  246. this.data.option_list.push(getOption());
  247. this.loading_list.push({
  248. loading: false,
  249. loadings: false,
  250. });
  251. },
  252. uploads(file_id, index) {
  253. this.data.option_list[index].audio_file_id = file_id;
  254. this.data.file_id_list.push(file_id);
  255. },
  256. deleteFiles(file_id, itemIndex) {
  257. this.data.option_list[itemIndex].audio_file_id = '';
  258. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  259. },
  260. // 删除小题
  261. deleteOption(i, file_id) {
  262. this.$confirm('是否删除?', '提示', {
  263. confirmButtonText: '确定',
  264. cancelButtonText: '取消',
  265. type: 'warning',
  266. })
  267. .then(() => {
  268. this.data.option_list.splice(i, 1);
  269. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  270. this.loading_list.splice(i, 1);
  271. })
  272. .catch(() => {});
  273. },
  274. // 自动生成音频
  275. handleMatically(item, i) {
  276. if (item.pinyin.trim()) {
  277. this.loading_list[i].loading = true;
  278. let MethodName = 'tool-PinyinToVoiceFile';
  279. let data = {
  280. pinyin: item.pinyin.trim(),
  281. };
  282. GetStaticResources(MethodName, data)
  283. .then((res) => {
  284. this.loading_list[i].loading = false;
  285. if (res.status === 1) {
  286. item.audio_file_id = res.file_id;
  287. this.data.file_id_list.push(res.file_id);
  288. }
  289. })
  290. .catch(() => {
  291. this.loading_list[i].loading = false;
  292. });
  293. }
  294. },
  295. // 改变类型
  296. handleChangeType() {
  297. if (this.data.property.learn_type !== 'dictation') {
  298. this.data.option_list.forEach((item) => {
  299. if (item.content.trim()) {
  300. item.content = item.content.substring(0, 1);
  301. }
  302. });
  303. }
  304. },
  305. // 生成汉字
  306. handleChineseStrokes(item, i) {
  307. if (item.content.trim()) {
  308. this.loading_list[i].loadings = true;
  309. let content_arr = item.content.trim().split('');
  310. let content_arrs = [];
  311. let content_arr_strokes = [];
  312. content_arr.forEach((itemc) => {
  313. if (itemc.trim()) {
  314. content_arrs.push(itemc.trim());
  315. }
  316. });
  317. content_arrs.forEach((itemc, indexc) => {
  318. content_arr_strokes.push(null);
  319. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  320. let data = {
  321. hz: itemc,
  322. };
  323. GetStaticResources(MethodName, data).then((res) => {
  324. let obj = {
  325. hz: itemc.trim(),
  326. strokes: res,
  327. };
  328. content_arr_strokes[indexc] = obj;
  329. });
  330. });
  331. this.loading_list[i].loadings = false;
  332. item.hz_strokes_list = content_arr_strokes;
  333. }
  334. },
  335. // 切割拼音
  336. handleSplitPy(item) {
  337. let pinyin_list = item.pinyin.trim().split(' ');
  338. item.pinyin_item_list = [];
  339. pinyin_list.forEach((itemp) => {
  340. let obj = {
  341. pinyin_item: itemp,
  342. };
  343. item.pinyin_item_list.push(obj);
  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>