ChineseQuestion.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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="data.property.learn_type === 'dictation' ? '拼音间用空格隔开' : '输入拼音'"
  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 {
  155. chineseData,
  156. learnTypeList,
  157. audioGenerationMethodList,
  158. getOption,
  159. } from '@/views/exercise_questions/data/chinese';
  160. export default {
  161. name: 'ChineseQuestion',
  162. components: {
  163. UploadAudio,
  164. SoundRecord,
  165. },
  166. mixins: [QuestionMixin],
  167. data() {
  168. return {
  169. learnTypeList,
  170. audioGenerationMethodList,
  171. data: JSON.parse(JSON.stringify(chineseData)),
  172. changeOptionType,
  173. handleInputNumber,
  174. loading_list: [
  175. {
  176. loading: false,
  177. loadings: false,
  178. },
  179. {
  180. loading: false,
  181. loadings: false,
  182. },
  183. {
  184. loading: false,
  185. loadings: false,
  186. },
  187. ],
  188. };
  189. },
  190. watch: {
  191. 'data.option_list.length': {
  192. handler(val) {
  193. this.loading_list = [];
  194. for (let i = 0; i < val; i++) {
  195. let obj = {
  196. loading: false,
  197. loadings: false,
  198. };
  199. this.loading_list.push(obj);
  200. }
  201. },
  202. deep: true,
  203. immediate: true,
  204. },
  205. },
  206. mounted() {
  207. // if (this.data.option_list.length > 3) {
  208. // let length = this.data.option_list.length - 3;
  209. // for (let i = 0; i < length; i++) {
  210. // let obj = {
  211. // loading: false,
  212. // loadings: false,
  213. // };
  214. // this.loading_list.push(obj);
  215. // }
  216. // }
  217. },
  218. methods: {
  219. addOption() {
  220. this.data.option_list.push(getOption());
  221. this.loading_list.push({
  222. loading: false,
  223. loadings: false,
  224. });
  225. },
  226. uploads(file_id, index) {
  227. this.data.option_list[index].audio_file_id = file_id;
  228. this.data.file_id_list.push(file_id);
  229. },
  230. deleteFiles(file_id, itemIndex) {
  231. this.data.option_list[itemIndex].audio_file_id = '';
  232. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  233. },
  234. // 删除小题
  235. deleteOption(i, file_id) {
  236. this.$confirm('是否删除?', '提示', {
  237. confirmButtonText: '确定',
  238. cancelButtonText: '取消',
  239. type: 'warning',
  240. })
  241. .then(() => {
  242. this.data.option_list.splice(i, 1);
  243. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  244. this.loading_list.splice(i, 1);
  245. })
  246. .catch(() => {});
  247. },
  248. // 自动生成音频
  249. handleMatically(item, i) {
  250. if (item.pinyin.trim()) {
  251. this.loading_list[i].loading = true;
  252. let MethodName = 'tool-PinyinToVoiceFile';
  253. let data = {
  254. pinyin: item.pinyin.trim().split(' ').join(','),
  255. };
  256. GetStaticResources(MethodName, data)
  257. .then((res) => {
  258. this.loading_list[i].loading = false;
  259. if (res.status === 1) {
  260. item.audio_file_id = res.file_id;
  261. this.data.file_id_list.push(res.file_id);
  262. }
  263. })
  264. .catch(() => {
  265. this.loading_list[i].loading = false;
  266. });
  267. }
  268. },
  269. // 生成汉字
  270. handleChineseStrokes(item, i) {
  271. if (item.content.trim()) {
  272. this.loading_list[i].loadings = true;
  273. let content_arr = item.content.trim().split('');
  274. let content_arrs = [];
  275. let content_arr_strokes = [];
  276. content_arr.forEach((itemc) => {
  277. if (itemc.trim()) {
  278. content_arrs.push(itemc.trim());
  279. }
  280. });
  281. content_arrs.forEach((itemc, indexc) => {
  282. content_arr_strokes.push(null);
  283. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  284. let data = {
  285. hz: itemc,
  286. };
  287. GetStaticResources(MethodName, data).then((res) => {
  288. let obj = {
  289. hz: itemc.trim(),
  290. strokes: res,
  291. };
  292. content_arr_strokes[indexc] = obj;
  293. });
  294. });
  295. this.loading_list[i].loadings = false;
  296. item.hz_strokes_list = content_arr_strokes;
  297. }
  298. },
  299. // 切割拼音
  300. handleSplitPy(item) {
  301. let pinyin_list = item.pinyin.trim().split(' ');
  302. item.pinyin_item_list = [];
  303. pinyin_list.forEach((itemp) => {
  304. let obj = {
  305. pinyin_item: itemp,
  306. };
  307. item.pinyin_item_list.push(obj);
  308. });
  309. },
  310. // 修改拼音
  311. changePinyin(item) {
  312. if (this.data.other.audio_generation_method === 'auto') {
  313. item.audio_file_id = '';
  314. }
  315. },
  316. },
  317. };
  318. </script>
  319. <style lang="scss" scoped>
  320. .content {
  321. display: flex;
  322. flex-direction: column;
  323. .content-item {
  324. .upload-wrapper {
  325. margin-top: 0;
  326. }
  327. :deep .file-name {
  328. width: 205px;
  329. overflow: hidden;
  330. text-overflow: ellipsis;
  331. white-space: nowrap;
  332. }
  333. .auto-matically {
  334. display: flex;
  335. flex-shrink: 0;
  336. align-items: center;
  337. width: 233px;
  338. padding: 5px 12px;
  339. background-color: $fill-color;
  340. border-radius: 2px;
  341. .audio-wrapper {
  342. margin-right: 12px;
  343. :deep .audio-play {
  344. width: 16px;
  345. height: 16px;
  346. color: #000;
  347. background-color: initial;
  348. }
  349. :deep .audio-play.not-url {
  350. color: #a1a1a1;
  351. }
  352. :deep .voice-play {
  353. width: 16px;
  354. height: 16px;
  355. }
  356. }
  357. .auto-btn {
  358. font-size: 14px;
  359. font-weight: 400;
  360. line-height: 22px;
  361. color: #1d2129;
  362. cursor: pointer;
  363. }
  364. }
  365. .delete {
  366. flex-shrink: 0;
  367. width: 16px;
  368. height: 16px;
  369. }
  370. }
  371. }
  372. </style>