ChineseQuestion.vue 10 KB

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