Character.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. data.property.model === 'write'
  23. ? '可输入汉字与符号→、+等,@:代表图片,#:代表书写格,例如好→女+子'
  24. : '输入汉字,@:代表图片,#:代表书写格'
  25. "
  26. @blur="handleMindMap"
  27. />
  28. <el-button @click="identify(item, index)">识别</el-button>
  29. <!-- <SoundRecord v-if="item.audio_file_id" :wav-blob.sync="item.audio_file_id" />
  30. <el-button v-else @click="handleMatic(item.content, index)">生成音频</el-button> -->
  31. <el-button @click="handleDelete(index)">删除此条</el-button>
  32. </div>
  33. <template v-if="data.property.is_enable_voice === 'true'">
  34. <div v-if="item.audio_file_id" style="margin-top: 8px">
  35. <SoundRecord :wav-blob.sync="item.audio_file_id" />
  36. </div>
  37. <template v-else>
  38. <div :class="['upload-audio-play']">
  39. <UploadAudio
  40. v-if="data.property.audio_generation_method === 'upload'"
  41. :file-id="item.audio_file_id"
  42. :show-upload="!item.audio_file_id"
  43. :item-index="index"
  44. @upload="uploads"
  45. @deleteFile="deleteFiles"
  46. />
  47. <div
  48. v-else-if="data.property.audio_generation_method === 'auto'"
  49. class="auto-matic"
  50. @click="handleMatic(item.content, index)"
  51. >
  52. <SvgIcon icon-class="voiceprint-line" class="record" />
  53. <span class="auto-btn">{{ item.audio_file_id ? '已生成' : '生成音频' }}</span
  54. >{{ item.audio_file_id ? '成功' : '' }}
  55. </div>
  56. <SoundRecord v-else :wav-blob.sync="item.audio_file_id" />
  57. </div>
  58. </template>
  59. </template>
  60. <div class="option-item">
  61. <template v-if="data.property.model === 'miao'">
  62. <span>书写示范:</span>
  63. <el-radio-group v-model="item.is_show_ben">
  64. <el-radio :label="true">是</el-radio>
  65. <el-radio :label="false">否</el-radio>
  66. </el-radio-group>
  67. </template>
  68. <template v-if="data.property.model === 'write'">
  69. <span>字格分开:</span>
  70. <el-radio-group v-model="item.is_margin">
  71. <el-radio :label="true">是</el-radio>
  72. <el-radio :label="false">否</el-radio>
  73. </el-radio-group>
  74. </template>
  75. <template v-if="isEnable(data.property.view_pinyin)">
  76. <!-- <span>共用拼音:</span>
  77. <el-radio-group v-model="item.is_common_pinyin">
  78. <el-radio :label="true">是</el-radio>
  79. <el-radio :label="false">否</el-radio>
  80. </el-radio-group> -->
  81. <template v-if="item.is_common_pinyin">
  82. <span>拼音</span>
  83. <el-input v-model="item.pinyin" placeholder="输入拼音" />
  84. </template>
  85. </template>
  86. <template v-if="isEnable(data.property.is_enable_shiyi)">
  87. <span>释义</span>
  88. <el-input v-model="item.shiyi" placeholder="输入释义" />
  89. </template>
  90. </div>
  91. <div v-for="(items, indexs) in item.content_list" :key="indexs" class="content-items">
  92. <template v-if="items">
  93. <label>内容:{{ items.con }} </label>
  94. <UploadFile
  95. v-if="items.type === 'img'"
  96. :type="data.type"
  97. :file-list="items.file_list"
  98. :file-id-list="items.file_id_list"
  99. :label-text="'图片'"
  100. :accept-file-type="acceptFileType"
  101. :index="index"
  102. :indexs="indexs"
  103. :limit="1"
  104. @updateFileList="updateFileList"
  105. />
  106. <div class="option-item">
  107. <template v-if="isEnable(data.property.view_pinyin) && !item.is_common_pinyin">
  108. <span>拼音</span>
  109. <el-input v-model="items.pinyin" placeholder="输入拼音" />
  110. </template>
  111. <!-- <template v-if="isEnable(data.property.is_enable_shiyi) && data.property.model === 'input'">
  112. <span>释义</span>
  113. <el-input v-model="items.shiyi" placeholder="输入释义"></el-input>
  114. </template> -->
  115. </div>
  116. </template>
  117. </div>
  118. </div>
  119. <el-button icon="el-icon-plus" style="margin: 10px 0" @click="addElement">增加一个</el-button>
  120. </div>
  121. <AnswerAnalysisList
  122. v-if="data.answer_list?.length > 0 || data.analysis_list?.length > 0"
  123. :answer-list="data.answer_list"
  124. :analysis-list="data.analysis_list"
  125. :unified-attrib="data.unified_attrib"
  126. @updateAnswerAnalysisFileList="updateAnswerAnalysisFileList"
  127. @deleteAnswerAnalysis="deleteAnswerAnalysis"
  128. />
  129. </template>
  130. </ModuleBase>
  131. </template>
  132. <script>
  133. import ModuleMixin from '../../common/ModuleMixin';
  134. import { getCharacterData, modelList, getOption } from '@/views/book/courseware/data/character';
  135. import { GetStaticResources, TextToAudioFile } from '@/api/app';
  136. import { PinyinBuild_OldFormat } from '@/api/book';
  137. import cnchar from 'cnchar';
  138. import UploadFile from '../../base/common/UploadFile.vue';
  139. import SoundRecord from '@/views/book/courseware/create/components/question/fill/components/SoundRecord.vue';
  140. import UploadAudio from '@/views/book/courseware/create/components/question/fill/components/UploadAudio.vue';
  141. export default {
  142. name: 'CharacterPage',
  143. components: { UploadFile, SoundRecord, UploadAudio },
  144. mixins: [ModuleMixin],
  145. data() {
  146. return {
  147. data: getCharacterData(),
  148. modelList,
  149. getOption,
  150. acceptFileType: '.png,.jpg,.jpeg',
  151. };
  152. },
  153. watch: {
  154. // 'data.content': 'handleMindMap',
  155. },
  156. methods: {
  157. // 解析输入内容
  158. handleChangeContent() {
  159. if (this.data.content.trim()) {
  160. let contentArr = this.data.content.split('\n');
  161. let contentList = [];
  162. contentArr.forEach((item, index) => {
  163. if (item.trim()) {
  164. let content_arr = item.trim().split('');
  165. let content_arrs = [];
  166. let content_arr_strokes = [];
  167. content_arr.forEach((itemc) => {
  168. if (itemc.trim()) {
  169. content_arrs.push(itemc.trim());
  170. }
  171. });
  172. content_arrs.forEach((itemc, indexc) => {
  173. content_arr_strokes.push(null);
  174. let MethodName = 'hz_resource_manager-GetHZStrokesContent';
  175. let data = {
  176. hz: itemc,
  177. };
  178. GetStaticResources(MethodName, data).then((res) => {
  179. let obj = {
  180. hz: itemc.trim(),
  181. strokes: res,
  182. };
  183. content_arr_strokes[indexc] = obj;
  184. });
  185. });
  186. contentList.push({
  187. con: item.trim(),
  188. pinyin: cnchar.spell(item.trim(), 'array', 'low', 'tone').join(' '),
  189. audio_file_id: '',
  190. hz_strokes_list: content_arr_strokes,
  191. });
  192. this.handleMatic(item.trim(), contentList.length - 1);
  193. }
  194. });
  195. this.data.content_list = contentList;
  196. } else {
  197. this.data.content_list = [];
  198. }
  199. this.handleMindMap();
  200. },
  201. // 自动生成音频
  202. handleMatic(con, index) {
  203. TextToAudioFile({
  204. text: con.replace(/<[^>]+>/g, ''),
  205. voice_type: this.data.property.voice_type,
  206. emotion: this.data.property.emotion,
  207. speed_ratio: this.data.property.speed_ratio,
  208. })
  209. .then(({ status, file_id, file_url }) => {
  210. if (status === 1) {
  211. this.data.option_list[index].audio_file_id = {
  212. file_url,
  213. file_id,
  214. };
  215. }
  216. })
  217. .catch(() => {});
  218. },
  219. updateFileList({ file_list, file_id_list }, index, indexs) {
  220. this.data.option_list[index].content_list[indexs].file_list = file_list;
  221. this.data.option_list[index].content_list[indexs].file_id_list = file_id_list;
  222. },
  223. // 增加
  224. addElement() {
  225. this.data.option_list.push(getOption());
  226. },
  227. // 删除
  228. handleDelete(index) {
  229. this.data.option_list.splice(index, 1);
  230. },
  231. handleMindMap() {
  232. // 思维导图数据
  233. let node_list = [];
  234. this.data.option_list.forEach((item) => {
  235. node_list.push({
  236. name: item.content.replace(/<[^>]*>?/gm, ''),
  237. id: Math.random().toString(36).substring(2, 12),
  238. });
  239. });
  240. this.data.mind_map.node_list = node_list;
  241. },
  242. // 识别
  243. async identify(items, index) {
  244. let con = items.content.trim();
  245. if (con) {
  246. items.content_list = [];
  247. let arr = con.split('');
  248. const regex = /[\u4E00-\u9FFF]/;
  249. let str = '';
  250. arr.forEach((item) => {
  251. if (regex.test(item)) {
  252. str += item;
  253. }
  254. });
  255. let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
  256. let data = {
  257. hz_str: str,
  258. };
  259. // items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
  260. if (str) {
  261. items.pinyin = await this.handlePinyin(str);
  262. }
  263. await GetStaticResources(MethodName, data)
  264. .then((res) => {
  265. for (let key in res) {
  266. if (key != 'status' && key != ',' && res[key]) {
  267. res[key] = JSON.parse(res[key]);
  268. }
  269. }
  270. let hzDetailList = res;
  271. arr.forEach((item, index) => {
  272. let objs = {};
  273. if (item === '@') {
  274. // 图片
  275. objs = {
  276. con: item,
  277. type: 'img',
  278. file_list: [],
  279. file_id_list: [],
  280. pinyin: '',
  281. };
  282. } else if (item === '#') {
  283. // 书写
  284. objs = {
  285. con: item,
  286. type: 'write',
  287. img: '',
  288. base64: '',
  289. pinyin: '',
  290. };
  291. } else if (regex.test(item)) {
  292. // 汉字
  293. let hz_list = [];
  294. let res = JSON.parse(JSON.stringify(hzDetailList[item]));
  295. let obj = {
  296. con: item,
  297. hzDetail: {
  298. hz_json: res,
  299. },
  300. };
  301. hz_list.push(obj);
  302. objs = {
  303. con: item,
  304. type: 'hanzi',
  305. hz_info: hz_list,
  306. pinyin: cnchar.spell(item, 'array', 'low', 'tone').join(' '),
  307. shiyi: '',
  308. answer: '',
  309. is_example: false,
  310. answer_pinyin: '',
  311. answer_en: '',
  312. is_can_input_answer: true,
  313. high_strokes: '',
  314. };
  315. } else {
  316. // 连字符
  317. objs = {
  318. con: item,
  319. type: 'lian',
  320. pinyin: '',
  321. };
  322. }
  323. this.$set(items.content_list, index, objs);
  324. });
  325. })
  326. .catch(() => {});
  327. for (let index = 0; index < arr.length; index++) {
  328. if (regex.test(arr[index])) {
  329. // 汉字
  330. items.content_list[index].pinyin = await this.handlePinyin(arr[index]);
  331. }
  332. }
  333. } else {
  334. this.$message.warning('请先输入内容');
  335. }
  336. },
  337. // 自动生成拼音
  338. handlePinyin(text) {
  339. let data = {
  340. text,
  341. is_rich_text: 'false',
  342. is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
  343. is_fill_space: 'false',
  344. is_custom_fc: 'false',
  345. };
  346. return new Promise((resolve, reject) => {
  347. PinyinBuild_OldFormat(data).then((res) => {
  348. if (res.parsed_text) {
  349. let mergedData = '';
  350. res.parsed_text.paragraph_list.map((outerArr, i) =>
  351. outerArr.map((innerArr, j) =>
  352. innerArr.map((newItem, k) => {
  353. mergedData += `${newItem.pinyin} `;
  354. }),
  355. ),
  356. );
  357. resolve(mergedData);
  358. }
  359. });
  360. });
  361. },
  362. uploads(file_id, index, file_url) {
  363. this.data.option_list[index].audio_file_id = {
  364. file_url,
  365. file_id,
  366. };
  367. },
  368. deleteFiles(index) {
  369. this.data.option_list[index].audio_file_id = '';
  370. },
  371. },
  372. };
  373. </script>
  374. <style lang="scss" scoped>
  375. .character-wrapper {
  376. display: flex;
  377. flex-direction: column;
  378. row-gap: 16px;
  379. align-items: flex-start;
  380. :deep .rich-wrapper {
  381. width: 100%;
  382. }
  383. .tips {
  384. font-size: 12px;
  385. color: #999;
  386. }
  387. .fun-type {
  388. display: flex;
  389. gap: 5px;
  390. width: 100%;
  391. padding-bottom: 10px;
  392. border-bottom: 1px solid #e5e6eb;
  393. a {
  394. padding: 5px 10px;
  395. font-weight: normal;
  396. color: #1d2129;
  397. cursor: pointer;
  398. background: #f2f3f5;
  399. border: 1px solid #f2f3f5;
  400. border-radius: 2px;
  401. &.active {
  402. color: #165dff;
  403. background: #e7eeff;
  404. border-color: #165dff;
  405. }
  406. }
  407. }
  408. .upload-file {
  409. // display: flex;
  410. column-gap: 12px;
  411. align-items: center;
  412. margin: 8px 0;
  413. .file-name {
  414. display: flex;
  415. column-gap: 14px;
  416. align-items: center;
  417. justify-content: space-between;
  418. max-width: 360px;
  419. padding: 8px 12px;
  420. font-size: 14px;
  421. color: #1d2129;
  422. background-color: #f7f8fa;
  423. span {
  424. display: flex;
  425. column-gap: 14px;
  426. align-items: center;
  427. }
  428. }
  429. .svg-icon {
  430. cursor: pointer;
  431. }
  432. }
  433. .fun-type {
  434. display: flex;
  435. gap: 5px;
  436. width: 100%;
  437. padding-bottom: 10px;
  438. border-bottom: 1px solid #e5e6eb;
  439. a {
  440. padding: 5px 10px;
  441. font-weight: normal;
  442. color: #1d2129;
  443. cursor: pointer;
  444. background: #f2f3f5;
  445. border: 1px solid #f2f3f5;
  446. border-radius: 2px;
  447. &.active {
  448. color: #165dff;
  449. background: #e7eeff;
  450. border-color: #165dff;
  451. }
  452. }
  453. }
  454. .content-box {
  455. width: 100%;
  456. }
  457. .content-item {
  458. display: flex;
  459. gap: 16px;
  460. .el-input {
  461. max-width: 600px;
  462. }
  463. }
  464. .content-items {
  465. margin: 10px 0;
  466. label {
  467. font-size: 14px;
  468. line-height: 34px;
  469. color: #4e5969;
  470. }
  471. }
  472. .option-item {
  473. display: flex;
  474. flex-flow: wrap;
  475. align-items: center;
  476. margin-top: 5px;
  477. span {
  478. flex-shrink: 0;
  479. width: max-content;
  480. margin-right: 10px;
  481. font-size: 14px;
  482. color: #4e5969;
  483. }
  484. .el-input {
  485. max-width: 100px;
  486. margin-right: 30px;
  487. }
  488. .el-radio-group {
  489. margin-right: 30px;
  490. }
  491. }
  492. }
  493. .auto-matic,
  494. .upload-audio-play {
  495. margin-top: 8px;
  496. :deep .upload-wrapper {
  497. margin-top: 0;
  498. }
  499. .audio-wrapper {
  500. :deep .audio-play {
  501. width: 16px;
  502. height: 16px;
  503. color: #000;
  504. background-color: initial;
  505. }
  506. :deep .audio-play.not-url {
  507. color: #a1a1a1;
  508. }
  509. :deep .voice-play {
  510. width: 16px;
  511. height: 16px;
  512. }
  513. }
  514. }
  515. .auto-matic {
  516. display: flex;
  517. flex-shrink: 0;
  518. column-gap: 12px;
  519. align-items: center;
  520. width: 200px;
  521. padding: 5px 12px;
  522. background-color: $fill-color;
  523. border-radius: 2px;
  524. .auto-btn {
  525. font-size: 16px;
  526. font-weight: 400;
  527. line-height: 22px;
  528. color: #1d2129;
  529. cursor: pointer;
  530. }
  531. }
  532. </style>