ChineseQuestion.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 v-for="(item, i) in data.option_list" :key="i" v-loading="loading_list[i].loadings" class="content-item">
  27. <span
  28. v-if="data.property.learn_type === 'dictation'"
  29. class="question-number"
  30. title="双击切换序号类型"
  31. @dblclick="changeOptionType(data)"
  32. >
  33. {{ computedQuestionNumber(i, data.option_number_show_mode) }}
  34. </span>
  35. <el-input
  36. v-model="item.content"
  37. :maxlength="data.property.learn_type === 'dictation' ? null : 1"
  38. :placeholder="data.property.learn_type === 'dictation' ? '输入汉字或词汇' : '输入一个汉字'"
  39. @blur="handleChineseStrokes(item, i)"
  40. />
  41. <el-input
  42. v-model="item.pinyin"
  43. :placeholder="data.property.learn_type === 'dictation' ? '拼音间用空格隔开' : '输入拼音'"
  44. @blur="handleSplitPy(item)"
  45. />
  46. <UploadAudio
  47. v-if="data.other.audio_generation_method === 'upload'"
  48. :key="item.audio_file_id || i"
  49. :file-id="item.audio_file_id"
  50. :item-index="i"
  51. :show-upload="!item.audio_file_id"
  52. @upload="uploads"
  53. @deleteFile="deleteFiles"
  54. />
  55. <div v-else-if="data.other.audio_generation_method === 'auto'" class="auto-matically">
  56. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="gray" />
  57. <span v-loading="loading_list[i].loading" class="auto-btn" @click="handleMatically(item, i)">{{
  58. item.audio_file_id ? '已生成' : '自动生成'
  59. }}</span>
  60. </div>
  61. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  62. <el-input
  63. v-if="data.property.learn_type !== 'dictation'"
  64. v-model="item.definition"
  65. placeholder="输入释义"
  66. />
  67. <el-input
  68. v-if="data.property.learn_type !== 'dictation'"
  69. v-model="item.collocation"
  70. placeholder="输入搭配"
  71. />
  72. <SvgIcon icon-class="delete" class="delete pointer" @click="deleteOption(i, item.audio_file_id)" />
  73. </li>
  74. </ul>
  75. </div>
  76. <div class="footer">
  77. <span class="add-option" @click="addOption">
  78. <SvgIcon icon-class="add-circle" size="14" /> <span>增加汉字</span>
  79. </span>
  80. </div>
  81. </template>
  82. <template #property>
  83. <el-form :model="data.property">
  84. <el-form-item label="题干">
  85. <el-radio
  86. v-for="{ value, label } in stemTypeList"
  87. :key="value"
  88. v-model="data.property.stem_type"
  89. :label="value"
  90. >
  91. {{ label }}
  92. </el-radio>
  93. </el-form-item>
  94. <el-form-item label="题号">
  95. <el-input v-model="data.property.question_number" />
  96. </el-form-item>
  97. <el-form-item label-width="45px">
  98. <el-radio
  99. v-for="{ value, label } in questionNumberTypeList"
  100. :key="value"
  101. v-model="data.other.question_number_type"
  102. :label="value"
  103. >
  104. {{ label }}
  105. </el-radio>
  106. </el-form-item>
  107. <el-form-item label="描述">
  108. <el-radio
  109. v-for="{ value, label } in switchOption"
  110. :key="value"
  111. v-model="data.property.is_enable_description"
  112. :label="value"
  113. >
  114. {{ label }}
  115. </el-radio>
  116. </el-form-item>
  117. <el-form-item label="分值">
  118. <el-radio
  119. v-for="{ value, label } in scoreTypeList"
  120. :key="value"
  121. v-model="data.property.score_type"
  122. :label="value"
  123. >
  124. {{ label }}
  125. </el-radio>
  126. </el-form-item>
  127. <el-form-item label-width="45px">
  128. <el-input-number
  129. v-model="data.property.score"
  130. :min="0"
  131. :step="data.property.score_type === scoreTypeList[0].value ? 1 : 0.1"
  132. />
  133. </el-form-item>
  134. <el-form-item label="类型">
  135. <el-radio
  136. v-for="{ value, label } in learnTypeList"
  137. :key="value"
  138. v-model="data.property.learn_type"
  139. :label="value"
  140. @change="handleChangeType"
  141. >
  142. {{ label }}
  143. </el-radio>
  144. </el-form-item>
  145. <el-form-item v-if="data.property.learn_type !== 'dictation'" label="田字格数">
  146. <el-input
  147. v-model="data.property.tian_number"
  148. type="number"
  149. @blur="data.property.tian_number = handleInputNumber(data.property.tian_number)"
  150. />
  151. </el-form-item>
  152. <el-form-item label="音频">
  153. <el-radio
  154. v-for="{ value, label } in audioGenerationMethodList"
  155. :key="value"
  156. v-model="data.other.audio_generation_method"
  157. :label="value"
  158. >
  159. {{ label }}
  160. </el-radio>
  161. </el-form-item>
  162. </el-form>
  163. </template>
  164. </QuestionBase>
  165. </template>
  166. <script>
  167. import QuestionMixin from '../common/QuestionMixin.js';
  168. import UploadAudio from '../common/UploadAudio.vue';
  169. import SoundRecord from '../common/SoundRecord.vue';
  170. import { GetStaticResources } from '@/api/app';
  171. import { changeOptionType, handleInputNumber } from '@/views/exercise_questions/data/common';
  172. import {
  173. chineseData,
  174. learnTypeList,
  175. audioGenerationMethodList,
  176. getOption,
  177. } from '@/views/exercise_questions/data/chinese';
  178. export default {
  179. name: 'ChineseQuestion',
  180. components: {
  181. UploadAudio,
  182. SoundRecord,
  183. },
  184. mixins: [QuestionMixin],
  185. data() {
  186. return {
  187. learnTypeList,
  188. audioGenerationMethodList,
  189. data: JSON.parse(JSON.stringify(chineseData)),
  190. changeOptionType,
  191. handleInputNumber,
  192. loading_list: [
  193. {
  194. loading: false,
  195. loadings: false,
  196. },
  197. {
  198. loading: false,
  199. loadings: false,
  200. },
  201. {
  202. loading: false,
  203. loadings: false,
  204. },
  205. ],
  206. };
  207. },
  208. methods: {
  209. addOption() {
  210. this.data.option_list.push(getOption());
  211. this.loading_list.push({
  212. loading: false,
  213. loadings: false,
  214. });
  215. },
  216. uploads(file_id, index) {
  217. this.data.option_list[index].audio_file_id = file_id;
  218. this.data.file_id_list.push(file_id);
  219. },
  220. deleteFiles(file_id, itemIndex) {
  221. this.data.option_list[itemIndex].audio_file_id = '';
  222. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  223. },
  224. // 删除小题
  225. deleteOption(i, file_id) {
  226. this.$confirm('是否删除?', '提示', {
  227. confirmButtonText: '确定',
  228. cancelButtonText: '取消',
  229. type: 'warning',
  230. })
  231. .then(() => {
  232. this.data.option_list.splice(i, 1);
  233. this.data.file_id_list.splice(this.data.file_id_list.indexOf(file_id), 1);
  234. this.loading_list.splice(i, 1);
  235. })
  236. .catch(() => {});
  237. },
  238. // 自动生成音频
  239. handleMatically(item, i) {
  240. if (item.pinyin.trim()) {
  241. this.loading_list[i].loading = true;
  242. let MethodName = 'tool-PinyinToVoiceFile';
  243. let data = {
  244. pinyin: item.pinyin.trim(),
  245. };
  246. GetStaticResources(MethodName, data)
  247. .then((res) => {
  248. this.loading_list[i].loading = false;
  249. if (res.status === 1) {
  250. item.audio_file_id = res.file_id;
  251. this.data.file_id_list.push(res.file_id);
  252. }
  253. })
  254. .catch(() => {
  255. this.loading_list[i].loading = false;
  256. });
  257. }
  258. },
  259. // 改变类型
  260. handleChangeType() {
  261. if (this.data.property.learn_type !== 'dictation') {
  262. this.data.option_list.forEach((item) => {
  263. if (item.content.trim()) {
  264. item.content = item.content.substring(0, 1);
  265. }
  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. };
  312. </script>
  313. <style lang="scss" scoped>
  314. .content {
  315. display: flex;
  316. flex-direction: column;
  317. .content-item {
  318. .upload-wrapper {
  319. margin-top: 0;
  320. }
  321. :deep .file-name {
  322. width: 205px;
  323. overflow: hidden;
  324. text-overflow: ellipsis;
  325. white-space: nowrap;
  326. }
  327. .auto-matically {
  328. display: flex;
  329. flex-shrink: 0;
  330. align-items: center;
  331. width: 233px;
  332. padding: 5px 12px;
  333. background-color: $fill-color;
  334. border-radius: 2px;
  335. .audio-wrapper {
  336. margin-right: 12px;
  337. :deep .audio-play {
  338. width: 16px;
  339. height: 16px;
  340. color: #000;
  341. background-color: initial;
  342. }
  343. :deep .audio-play.not-url {
  344. color: #a1a1a1;
  345. }
  346. :deep .voice-play {
  347. width: 16px;
  348. height: 16px;
  349. }
  350. }
  351. .auto-btn {
  352. font-size: 14px;
  353. font-weight: 400;
  354. line-height: 22px;
  355. color: #1d2129;
  356. cursor: pointer;
  357. }
  358. }
  359. .delete {
  360. flex-shrink: 0;
  361. width: 16px;
  362. height: 16px;
  363. }
  364. }
  365. }
  366. </style>