Character.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <ModuleBase :type="data.type">
  3. <template #content>
  4. <!-- eslint-disable max-len -->
  5. <div class="fill-wrapper">
  6. <el-input v-model="data.content" placeholder="输入" type="textarea" @change="handleChangeContent"></el-input>
  7. <span class="tips">输入字或词请一字一行</span>
  8. </div>
  9. </template>
  10. </ModuleBase>
  11. </template>
  12. <script>
  13. import ModuleMixin from '../../common/ModuleMixin';
  14. import SoundRecord from '@/views/book/courseware/create/components/question/fill/components/SoundRecord.vue';
  15. import UploadAudio from '@/views/book/courseware/create/components/question/fill/components/UploadAudio.vue';
  16. import { getCharacterData } from '@/views/book/courseware/data/character';
  17. import { GetStaticResources } from '@/api/app';
  18. import cnchar from 'cnchar';
  19. export default {
  20. name: 'CharacterPage',
  21. components: {
  22. SoundRecord,
  23. UploadAudio,
  24. },
  25. mixins: [ModuleMixin],
  26. data() {
  27. return {
  28. data: getCharacterData(),
  29. };
  30. },
  31. methods: {
  32. // 解析输入内容
  33. handleChangeContent() {
  34. if (this.data.content.trim()) {
  35. let contentArr = this.data.content.split('\n');
  36. let contentList = [];
  37. contentArr.forEach((item, index) => {
  38. if (item.trim()) {
  39. let content_arr = item.trim().split('');
  40. let content_arrs = [];
  41. let content_arr_strokes = [];
  42. content_arr.forEach((itemc) => {
  43. if (itemc.trim()) {
  44. content_arrs.push(itemc.trim());
  45. }
  46. });
  47. content_arrs.forEach((itemc, indexc) => {
  48. content_arr_strokes.push(null);
  49. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  50. let data = {
  51. hz: itemc,
  52. };
  53. GetStaticResources(MethodName, data).then((res) => {
  54. let obj = {
  55. hz: itemc.trim(),
  56. strokes: res,
  57. };
  58. content_arr_strokes[indexc] = obj;
  59. });
  60. });
  61. contentList.push({
  62. con: item.trim(),
  63. pinyin: cnchar.spell(item.trim(), 'array', 'low', 'tone').join(' '),
  64. audio_file_id: '',
  65. hz_strokes_list: content_arr_strokes,
  66. });
  67. this.handleMatic(item.trim(), contentList.length - 1);
  68. }
  69. });
  70. this.data.content_list = contentList;
  71. } else {
  72. this.data.content_list = [];
  73. }
  74. },
  75. // 自动生成音频
  76. handleMatic(con, index) {
  77. GetStaticResources('tool-TextToVoiceFile', {
  78. text: con.replace(/<[^>]+>/g, ''),
  79. })
  80. .then(({ status, file_id }) => {
  81. if (status === 1) {
  82. this.data.content_list[index].audio_file_id = file_id;
  83. }
  84. })
  85. .catch(() => {});
  86. },
  87. },
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .fill-wrapper {
  92. display: flex;
  93. flex-direction: column;
  94. row-gap: 16px;
  95. align-items: flex-start;
  96. :deep .rich-wrapper {
  97. width: 100%;
  98. }
  99. .tips {
  100. font-size: 12px;
  101. color: #999;
  102. }
  103. .auto-matic,
  104. .upload-audio-play {
  105. :deep .upload-wrapper {
  106. margin-top: 0;
  107. }
  108. .audio-wrapper {
  109. :deep .audio-play {
  110. width: 16px;
  111. height: 16px;
  112. color: #000;
  113. background-color: initial;
  114. }
  115. :deep .audio-play.not-url {
  116. color: #a1a1a1;
  117. }
  118. :deep .voice-play {
  119. width: 16px;
  120. height: 16px;
  121. }
  122. }
  123. }
  124. .auto-matic {
  125. display: flex;
  126. flex-shrink: 0;
  127. column-gap: 12px;
  128. align-items: center;
  129. width: 200px;
  130. padding: 5px 12px;
  131. background-color: $fill-color;
  132. border-radius: 2px;
  133. .auto-btn {
  134. font-size: 16px;
  135. font-weight: 400;
  136. line-height: 22px;
  137. color: #1d2129;
  138. cursor: pointer;
  139. }
  140. }
  141. .correct-answer {
  142. display: flex;
  143. flex-wrap: wrap;
  144. gap: 8px;
  145. .el-input {
  146. width: 180px;
  147. :deep &__prefix {
  148. display: flex;
  149. align-items: center;
  150. color: $text-color;
  151. }
  152. }
  153. }
  154. }
  155. </style>