Character.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <ModuleBase ref="base" :type="data.type">
  3. <template #content>
  4. <!-- eslint-disable max-len -->
  5. <div class="character-wrapper">
  6. <div class="fun-type">
  7. <a
  8. v-for="{ value, label } in modelList"
  9. :key="value"
  10. :class="[data.property.model === value ? 'active' : '']"
  11. @click="data.property.model = value"
  12. >{{ label }}</a
  13. >
  14. </div>
  15. <div v-for="(item, index) in data.option_list" :key="index" class="content-box">
  16. <div class="content-item">
  17. <el-input
  18. v-model="item.content"
  19. maxlength="10"
  20. show-word-limit
  21. placeholder="输入汉字,@:代表图片,#:代表书写格"
  22. @blur="handleMindMap"
  23. />
  24. <el-button @click="identify(item, index)">识别</el-button>
  25. <SoundRecord v-if="item.audio_file_id" :wav-blob.sync="item.audio_file_id" />
  26. <el-button v-else @click="handleMatic(item.content, index)">生成音频</el-button>
  27. <el-button @click="handleDelete(index)">删除此条</el-button>
  28. </div>
  29. <div class="option-item">
  30. <template v-if="data.property.model === 'miao'">
  31. <span>显示本体:</span>
  32. <el-radio-group v-model="item.is_show_ben">
  33. <el-radio :label="true">是</el-radio>
  34. <el-radio :label="false">否</el-radio>
  35. </el-radio-group>
  36. </template>
  37. <template v-if="data.property.model === 'write'">
  38. <span>需要间距:</span>
  39. <el-radio-group v-model="item.is_margin">
  40. <el-radio :label="true">是</el-radio>
  41. <el-radio :label="false">否</el-radio>
  42. </el-radio-group>
  43. </template>
  44. <template v-if="isEnable(data.property.view_pinyin)">
  45. <!-- <span>共用拼音:</span>
  46. <el-radio-group v-model="item.is_common_pinyin">
  47. <el-radio :label="true">是</el-radio>
  48. <el-radio :label="false">否</el-radio>
  49. </el-radio-group> -->
  50. <template v-if="item.is_common_pinyin">
  51. <span>拼音</span>
  52. <el-input v-model="item.pinyin" placeholder="输入拼音" />
  53. </template>
  54. </template>
  55. <template v-if="isEnable(data.property.is_enable_shiyi)">
  56. <span>释义</span>
  57. <el-input v-model="item.shiyi" placeholder="输入释义" />
  58. </template>
  59. </div>
  60. <div v-for="(items, indexs) in item.content_list" :key="indexs" class="content-items">
  61. <template v-if="items">
  62. <label>内容:{{ items.con }} </label>
  63. <UploadFile
  64. v-if="items.type === 'img'"
  65. :type="data.type"
  66. :file-list="items.file_list"
  67. :file-id-list="items.file_id_list"
  68. :label-text="'图片'"
  69. :accept-file-type="acceptFileType"
  70. :index="index"
  71. :indexs="indexs"
  72. :limit="1"
  73. @updateFileList="updateFileList"
  74. />
  75. <div class="option-item">
  76. <template v-if="isEnable(data.property.view_pinyin) && !item.is_common_pinyin">
  77. <span>拼音</span>
  78. <el-input v-model="items.pinyin" placeholder="输入拼音" />
  79. </template>
  80. <!-- <template v-if="isEnable(data.property.is_enable_shiyi) && data.property.model === 'input'">
  81. <span>释义</span>
  82. <el-input v-model="items.shiyi" placeholder="输入释义"></el-input>
  83. </template> -->
  84. </div>
  85. </template>
  86. </div>
  87. </div>
  88. <el-button icon="el-icon-plus" style="margin: 10px 0" @click="addElement">增加一个</el-button>
  89. </div>
  90. <AnswerAnalysisList
  91. v-if="data.answer_list?.length > 0 || data.analysis_list?.length > 0"
  92. :answer-list="data.answer_list"
  93. :analysis-list="data.analysis_list"
  94. :unified-attrib="data.unified_attrib"
  95. @updateAnswerAnalysisFileList="updateAnswerAnalysisFileList"
  96. @deleteAnswerAnalysis="deleteAnswerAnalysis"
  97. />
  98. </template>
  99. </ModuleBase>
  100. </template>
  101. <script>
  102. import ModuleMixin from '../../common/ModuleMixin';
  103. import { getCharacterData, modelList, getOption } from '@/views/book/courseware/data/character';
  104. import { GetStaticResources, TextToAudioFile } from '@/api/app';
  105. import cnchar from 'cnchar';
  106. import UploadFile from '../../base/common/UploadFile.vue';
  107. import SoundRecord from '@/views/book/courseware/create/components/question/fill/components/SoundRecord.vue';
  108. export default {
  109. name: 'CharacterPage',
  110. components: { UploadFile, SoundRecord },
  111. mixins: [ModuleMixin],
  112. data() {
  113. return {
  114. data: getCharacterData(),
  115. modelList,
  116. getOption,
  117. acceptFileType: '.png,.jpg,.jpeg',
  118. };
  119. },
  120. watch: {
  121. // 'data.content': 'handleMindMap',
  122. },
  123. methods: {
  124. // 解析输入内容
  125. handleChangeContent() {
  126. if (this.data.content.trim()) {
  127. let contentArr = this.data.content.split('\n');
  128. let contentList = [];
  129. contentArr.forEach((item, index) => {
  130. if (item.trim()) {
  131. let content_arr = item.trim().split('');
  132. let content_arrs = [];
  133. let content_arr_strokes = [];
  134. content_arr.forEach((itemc) => {
  135. if (itemc.trim()) {
  136. content_arrs.push(itemc.trim());
  137. }
  138. });
  139. content_arrs.forEach((itemc, indexc) => {
  140. content_arr_strokes.push(null);
  141. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  142. let data = {
  143. hz: itemc,
  144. };
  145. GetStaticResources(MethodName, data).then((res) => {
  146. let obj = {
  147. hz: itemc.trim(),
  148. strokes: res,
  149. };
  150. content_arr_strokes[indexc] = obj;
  151. });
  152. });
  153. contentList.push({
  154. con: item.trim(),
  155. pinyin: cnchar.spell(item.trim(), 'array', 'low', 'tone').join(' '),
  156. audio_file_id: '',
  157. hz_strokes_list: content_arr_strokes,
  158. });
  159. this.handleMatic(item.trim(), contentList.length - 1);
  160. }
  161. });
  162. this.data.content_list = contentList;
  163. } else {
  164. this.data.content_list = [];
  165. }
  166. this.handleMindMap();
  167. },
  168. // 自动生成音频
  169. handleMatic(con, index) {
  170. TextToAudioFile({
  171. text: con.replace(/<[^>]+>/g, ''),
  172. voice_type: this.data.property.voice_type,
  173. emotion: this.data.property.emotion,
  174. speed_ratio: this.data.property.speed_ratio,
  175. })
  176. .then(({ status, file_id, file_url }) => {
  177. if (status === 1) {
  178. this.data.option_list[index].audio_file_id = {
  179. file_url,
  180. file_id,
  181. };
  182. }
  183. })
  184. .catch(() => {});
  185. },
  186. updateFileList({ file_list, file_id_list }, index, indexs) {
  187. this.data.option_list[index].content_list[indexs].file_list = file_list;
  188. this.data.option_list[index].content_list[indexs].file_id_list = file_id_list;
  189. },
  190. // 增加
  191. addElement() {
  192. this.data.option_list.push(getOption());
  193. },
  194. // 删除
  195. handleDelete(index) {
  196. this.data.option_list.splice(index, 1);
  197. },
  198. handleMindMap() {
  199. // 思维导图数据
  200. let node_list = [];
  201. this.data.option_list.forEach((item) => {
  202. node_list.push({
  203. name: item.content.replace(/<[^>]*>?/gm, ''),
  204. id: Math.random().toString(36).substring(2, 12),
  205. });
  206. });
  207. this.data.mind_map.node_list = node_list;
  208. },
  209. // 识别
  210. async identify(items, index) {
  211. let con = items.content.trim();
  212. if (con) {
  213. items.content_list = [];
  214. let arr = con.split('');
  215. const regex = /[\u4E00-\u9FFF]/;
  216. let str = '';
  217. arr.forEach((item) => {
  218. if (regex.test(item)) {
  219. str += item;
  220. }
  221. });
  222. let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
  223. let data = {
  224. hz_str: str,
  225. };
  226. items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
  227. await GetStaticResources(MethodName, data)
  228. .then((res) => {
  229. for (let key in res) {
  230. if (key != 'status' && key != ',' && res[key]) {
  231. res[key] = JSON.parse(res[key]);
  232. }
  233. }
  234. let hzDetailList = res;
  235. arr.forEach((item, index) => {
  236. let objs = {};
  237. if (item === '@') {
  238. // 图片
  239. objs = {
  240. con: item,
  241. type: 'img',
  242. file_list: [],
  243. file_id_list: [],
  244. pinyin: '',
  245. };
  246. } else if (item === '#') {
  247. // 书写
  248. objs = {
  249. con: item,
  250. type: 'write',
  251. img: '',
  252. base64: '',
  253. pinyin: '',
  254. };
  255. } else if (regex.test(item)) {
  256. // 汉字
  257. let hz_list = [];
  258. let res = JSON.parse(JSON.stringify(hzDetailList[item]));
  259. let obj = {
  260. con: item,
  261. hzDetail: {
  262. hz_json: res,
  263. },
  264. };
  265. hz_list.push(obj);
  266. objs = {
  267. con: item,
  268. type: 'hanzi',
  269. hz_info: hz_list,
  270. pinyin: cnchar.spell(item, 'array', 'low', 'tone').join(' '),
  271. shiyi: '',
  272. answer: '',
  273. is_example: false,
  274. answer_pinyin: '',
  275. answer_en: '',
  276. is_can_input_answer: true,
  277. high_strokes: '',
  278. };
  279. } else {
  280. // 连字符
  281. objs = {
  282. con: item,
  283. type: 'lian',
  284. pinyin: '',
  285. };
  286. }
  287. this.$set(items.content_list, index, objs);
  288. });
  289. })
  290. .catch(() => {});
  291. if (str) {
  292. this.handleMatic(str, index);
  293. }
  294. } else {
  295. this.$message.warning('请先输入内容');
  296. }
  297. },
  298. },
  299. };
  300. </script>
  301. <style lang="scss" scoped>
  302. .character-wrapper {
  303. display: flex;
  304. flex-direction: column;
  305. row-gap: 16px;
  306. align-items: flex-start;
  307. :deep .rich-wrapper {
  308. width: 100%;
  309. }
  310. .tips {
  311. font-size: 12px;
  312. color: #999;
  313. }
  314. .fun-type {
  315. display: flex;
  316. gap: 5px;
  317. width: 100%;
  318. padding-bottom: 10px;
  319. border-bottom: 1px solid #e5e6eb;
  320. a {
  321. padding: 5px 10px;
  322. font-weight: normal;
  323. color: #1d2129;
  324. cursor: pointer;
  325. background: #f2f3f5;
  326. border: 1px solid #f2f3f5;
  327. border-radius: 2px;
  328. &.active {
  329. color: #165dff;
  330. background: #e7eeff;
  331. border-color: #165dff;
  332. }
  333. }
  334. }
  335. .upload-file {
  336. // display: flex;
  337. column-gap: 12px;
  338. align-items: center;
  339. margin: 8px 0;
  340. .file-name {
  341. display: flex;
  342. column-gap: 14px;
  343. align-items: center;
  344. justify-content: space-between;
  345. max-width: 360px;
  346. padding: 8px 12px;
  347. font-size: 14px;
  348. color: #1d2129;
  349. background-color: #f7f8fa;
  350. span {
  351. display: flex;
  352. column-gap: 14px;
  353. align-items: center;
  354. }
  355. }
  356. .svg-icon {
  357. cursor: pointer;
  358. }
  359. }
  360. .fun-type {
  361. display: flex;
  362. gap: 5px;
  363. width: 100%;
  364. padding-bottom: 10px;
  365. border-bottom: 1px solid #e5e6eb;
  366. a {
  367. padding: 5px 10px;
  368. font-weight: normal;
  369. color: #1d2129;
  370. cursor: pointer;
  371. background: #f2f3f5;
  372. border: 1px solid #f2f3f5;
  373. border-radius: 2px;
  374. &.active {
  375. color: #165dff;
  376. background: #e7eeff;
  377. border-color: #165dff;
  378. }
  379. }
  380. }
  381. .content-box {
  382. width: 100%;
  383. }
  384. .content-item {
  385. display: flex;
  386. gap: 16px;
  387. .el-input {
  388. max-width: 400px;
  389. }
  390. }
  391. .content-items {
  392. margin: 10px 0;
  393. label {
  394. font-size: 14px;
  395. line-height: 34px;
  396. color: #4e5969;
  397. }
  398. }
  399. .option-item {
  400. display: flex;
  401. flex-flow: wrap;
  402. align-items: center;
  403. margin-top: 5px;
  404. span {
  405. flex-shrink: 0;
  406. width: max-content;
  407. margin-right: 10px;
  408. font-size: 14px;
  409. color: #4e5969;
  410. }
  411. .el-input {
  412. max-width: 100px;
  413. margin-right: 30px;
  414. }
  415. .el-radio-group {
  416. margin-right: 30px;
  417. }
  418. }
  419. }
  420. </style>