index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <!-- -->
  2. <template>
  3. <div
  4. class="NPC-Book-Article Big-Book-Maxwidth"
  5. v-if="curQue"
  6. v-loading="loading"
  7. >
  8. <div class="adult-book-input-item">
  9. <span class="adult-book-lable">序号:</span>
  10. <el-input
  11. class="adult-book-input"
  12. placeholder="请输入文章提示"
  13. v-model="curQue.number"
  14. @blur="onBlur(curQue, 'number')"
  15. maxlength="200"
  16. show-word-limit
  17. ></el-input>
  18. </div>
  19. <div class="Big-Book-mp3">
  20. <Upload
  21. :changeFillId="changeImage"
  22. :datafileList="fileCon.img_list"
  23. :filleNumber="imgNumber"
  24. :uploadType="'image'"
  25. />
  26. </div>
  27. <div class="Big-Book-mp3">
  28. <Upload
  29. type="mp3"
  30. :changeFillId="changeMp3"
  31. :datafileList="fileCon.mp3_list"
  32. :filleNumber="mp3Number"
  33. :uploadType="'mp3'"
  34. :handleMp3Base64="handleChange"
  35. />
  36. </div>
  37. <div class="adult-book-input-item">
  38. <span class="adult-book-lable">内容类型:</span>
  39. <el-radio-group v-model="curQue.font">
  40. <el-radio label="py">拼音</el-radio>
  41. <el-radio label="cn">汉字</el-radio>
  42. </el-radio-group>
  43. </div>
  44. <div class="adult-book-input-item">
  45. <span class="adult-book-lable">功能设置:</span>
  46. <el-checkbox-group v-model="checkList" @change="handleCheckedFnChange">
  47. <el-checkbox
  48. v-for="(fnItem, fnIndex) in curQue.fn_list"
  49. :key="'dis_fn_list' + fnIndex"
  50. :label="fnItem.name"
  51. ></el-checkbox>
  52. </el-checkbox-group>
  53. </div>
  54. <div class="adult-book-input-item">
  55. <span class="adult-book-lable">文章提示:</span>
  56. <el-input
  57. class="adult-book-input"
  58. type="textarea"
  59. :autosize="{ minRows: 2 }"
  60. placeholder="请输入文章提示"
  61. v-model="curQue.notice"
  62. @blur="onBlur(curQue, 'notice')"
  63. maxlength="200"
  64. show-word-limit
  65. ></el-input>
  66. </div>
  67. <div class="NPC-Book-role">
  68. <ul class="adult-book-input-role" v-if="curQue.roleList.length > 0">
  69. <li
  70. v-for="(rItem, rIndex) in curQue.roleList"
  71. :key="'roleList' + rIndex"
  72. >
  73. <div class="rItem" @click="editRole(rItem)">
  74. <span v-if="rItem.role" class="adult-book-input-roleText">{{
  75. rItem.role
  76. }}</span>
  77. <img
  78. v-else
  79. :src="rItem.img_list[0] && rItem.img_list[0].url"
  80. class="adult-book-input-roleImg"
  81. />
  82. <template v-if="rItem.detail.wordsList.length > 0">
  83. <span class="pinyin">{{
  84. rItem.detail.wordsList | handlePinyin
  85. }}</span>
  86. <span class="chs">{{ rItem.detail.wordsList | handleChs }}</span>
  87. </template>
  88. </div>
  89. <i class="el-icon-circle-close" @click="delRole(rIndex)"></i>
  90. </li>
  91. </ul>
  92. <el-button type="primary" @click="addRole">添加角色</el-button>
  93. </div>
  94. <div class="NPC-Book-article">
  95. <ArticleChs
  96. :curQue="curQue"
  97. :isPara="isPara"
  98. :changeIsPara="changeIsPara"
  99. />
  100. </div>
  101. <div class="NPC-Book-Paragraph" v-if="isPara">
  102. <Paragraph :curQue="curQue" :isClause="isClause" :sureSeg="sureSeg" />
  103. </div>
  104. <!---上传rlc文件-->
  105. <!-- <div class="NPC-Book-Paragraph" v-if="isClause">
  106. <el-button
  107. type="warning"
  108. size="small"
  109. @click="uploadLRC"
  110. v-if="curQue.detail[0].timeList.length == 0"
  111. >上传lrc文件</el-button
  112. >
  113. <div v-else class="lrc-box">
  114. <span>已有字幕时间节点</span>
  115. <el-button type="text" @click="editTimeList">去编辑</el-button>
  116. </div>
  117. </div> -->
  118. <!---分句-->
  119. <div class="NPC-Book-Paragraph" v-if="isClause">
  120. <Clauseresult :curQue="curQue" :segByWord="segByWord" />
  121. </div>
  122. <template v-if="curQue.font !== 'py'">
  123. <div class="lrc-box">
  124. <div
  125. v-if="this.curQue.wordTime && this.curQue.wordTime.length > 0"
  126. class="lrc-box"
  127. >
  128. <span>已有字幕时间节点</span>
  129. <el-button type="text" @click="againWordTime">重新生成</el-button>
  130. </div>
  131. <template v-else>
  132. <el-button v-if="!isWordTime" size="medium" @click="createWordTime"
  133. >自动生成字幕节点</el-button
  134. >
  135. <p v-else>字幕节点生成中...请等待</p>
  136. </template>
  137. </div>
  138. <!---分词-->
  139. <div class="NPC-Book-Word" v-if="isByWord">
  140. <Segbyword :curQue="curQue" :paraIndex="paraIndex" :segList="segList" />
  141. </div>
  142. </template>
  143. <!---答案-->
  144. <div class="adult-book-input-item">
  145. <span class="adult-book-lable">答案:</span>
  146. <el-input
  147. class="adult-book-input"
  148. type="textarea"
  149. :autosize="{ minRows: 2 }"
  150. placeholder="请输入答案"
  151. v-model="curQue.answer"
  152. @blur="onBlur(curQue, 'answer')"
  153. maxlength="200"
  154. show-word-limit
  155. ></el-input>
  156. </div>
  157. <el-dialog title="段落分句字幕打点" :visible.sync="cTVisible" width="30%">
  158. <Createtimelist ref="createtimelist" :curQue="curQue" />
  159. <span slot="footer" class="dialog-footer">
  160. <el-button @click="cTVisible = false">取 消</el-button>
  161. <el-button type="primary" @click="saveTimeList">保 存</el-button>
  162. </span>
  163. </el-dialog>
  164. <el-dialog
  165. :title="roleStatus == 1 ? '添加角色' : '编辑角色'"
  166. :visible.sync="roleVisible"
  167. :modal="false"
  168. width="60%"
  169. >
  170. <template v-if="roleStatus == 1">
  171. <RoleChs
  172. ref="createRolelist"
  173. :curRole="curQue.roleList[curQue.roleList.length - 1]"
  174. />
  175. </template>
  176. <template v-else>
  177. <RoleChs ref="createRolelist" :curRole="curRole" />
  178. </template>
  179. <span slot="footer" class="dialog-footer">
  180. <el-button @click="roleVisible = false">取 消</el-button>
  181. <el-button type="primary" @click="saveRoleList">保 存</el-button>
  182. </span>
  183. </el-dialog>
  184. </div>
  185. </template>
  186. <script>
  187. import {
  188. segSentences,
  189. BatchSegContent,
  190. createPinyin,
  191. prepareTranscribe,
  192. getWordTime,
  193. } from "@/api/ajax";
  194. const Base64 = require("js-base64").Base64;
  195. import Upload from "../../common/Upload.vue";
  196. import UploadArt from "../../common/UploadArt.vue";
  197. import ArticleChs from "./components/ArticleChs.vue";
  198. import Paragraph from "./components/ParagraphChs.vue";
  199. import Clauseresult from "./components/ClauseresultChs.vue";
  200. import Segbyword from "./components/SegbywordChs.vue";
  201. import Createtimelist from "./components/CreatetimelistChs.vue";
  202. import RoleChs from "./components/RoleChs.vue";
  203. export default {
  204. name: "ArticleTemChs",
  205. components: {
  206. Upload,
  207. UploadArt,
  208. ArticleChs,
  209. Paragraph,
  210. Clauseresult,
  211. Segbyword,
  212. Createtimelist,
  213. RoleChs,
  214. },
  215. props: ["curQue", "changeCurQue", "listIndex"],
  216. filters: {
  217. handlePinyin(wordsList) {
  218. let str = "";
  219. wordsList.forEach((item, index) => {
  220. if (index < wordsList.length - 1) {
  221. str += item.pinyin + " ";
  222. } else {
  223. str += item.pinyin;
  224. }
  225. });
  226. return str;
  227. },
  228. handleChs(wordsList) {
  229. let str = "";
  230. wordsList.forEach((item, index) => {
  231. if (index < wordsList.length - 1) {
  232. str += item.chs + " ";
  233. } else {
  234. str += item.chs;
  235. }
  236. });
  237. return str;
  238. },
  239. },
  240. data() {
  241. return {
  242. checkList: [],
  243. imgNumber: 1,
  244. mp3Number: 1,
  245. fileCon: {
  246. img_list: [],
  247. mp3_list: [],
  248. },
  249. isPara: false,
  250. isClause: false,
  251. isByWord: false,
  252. paraIndex: 0, //段落索引
  253. cTVisible: false,
  254. roleVisible: false,
  255. roleStatus: 1, //1添加;2是编辑
  256. curRole: null,
  257. loading: false,
  258. segList: null,
  259. isWordTime: false,
  260. };
  261. },
  262. computed: {},
  263. watch: {
  264. listIndex: {
  265. handler: function (newVal, oldVal) {
  266. if (newVal !== oldVal) {
  267. this.isPara = false;
  268. this.isClause = false;
  269. this.isByWord = false;
  270. this.paraIndex = 0; //段落索引
  271. this.roleStatus = 1; //1添加;2是编辑
  272. this.curRole = null;
  273. this.loading = false;
  274. this.segList = null;
  275. this.isWordTime = false;
  276. this.initData();
  277. }
  278. },
  279. deep: true,
  280. },
  281. },
  282. //方法集合
  283. methods: {
  284. onBlur(item, field) {
  285. item[field] = item[field] ? item[field].trim() : "";
  286. },
  287. onBlurIndex(index, field) {
  288. let res = this.curQueItem[field][index].trim();
  289. this.$set(this.curQueItem[field], index, res);
  290. },
  291. // 更多配置选择
  292. handleCheckedFnChange(value) {
  293. let fn_list = JSON.parse(JSON.stringify(this.curQue.fn_list));
  294. this.curQue.fn_list = fn_list.map((item) => {
  295. if (value.indexOf(item.name) > -1) {
  296. item.isFn = true;
  297. } else {
  298. item.isFn = false;
  299. if (item.type == "dialogue_answer_input_chs") {
  300. this.curQue.answer = "";
  301. } else if (item.type == "dialogue_answer_judge_chs") {
  302. this.curQue.judge = "";
  303. }
  304. }
  305. return item;
  306. });
  307. },
  308. changeMp3(fileList) {
  309. const articleImgList = JSON.parse(JSON.stringify(fileList));
  310. const articleImgRes = [];
  311. articleImgList.forEach((item) => {
  312. if (item.response) {
  313. const obj = {
  314. name: item.name,
  315. duration: item.response.file_info_list[0].media_duration,
  316. url: item.response.file_info_list[0].file_url,
  317. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  318. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  319. };
  320. articleImgRes.push(obj);
  321. }
  322. });
  323. this.curQue.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
  324. },
  325. changeImage(fileList) {
  326. const articleImgList = JSON.parse(JSON.stringify(fileList));
  327. const articleImgRes = [];
  328. articleImgList.forEach((item) => {
  329. if (item.response) {
  330. const obj = {
  331. name: item.name,
  332. url: item.response.file_info_list[0].file_url,
  333. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  334. };
  335. articleImgRes.push(obj);
  336. }
  337. });
  338. this.curQue.img_list = JSON.parse(JSON.stringify(articleImgRes));
  339. },
  340. changeImage2(file) {
  341. if (file.response) {
  342. const obj = {
  343. name: file.name,
  344. url: file.response.file_info_list[0].file_url,
  345. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  346. };
  347. this.curQue.img_list.push(obj);
  348. this.$forceUpdate();
  349. }
  350. },
  351. forceUpdate() {
  352. this.$forceUpdate();
  353. },
  354. delImage(index) {
  355. this.curQue.img_list.splice(index, 1);
  356. this.fileCon.img_list.splice(index, 1);
  357. },
  358. //添加角色
  359. addRole() {
  360. this.roleVisible = true;
  361. this.roleStatus = 1;
  362. let id = Math.random().toString(36).substr(2);
  363. let roleCon = {
  364. id: id,
  365. role: "",
  366. img_list: [],
  367. detail: {
  368. fullName: "",
  369. seg_words: "",
  370. wordsList: [],
  371. },
  372. };
  373. this.curQue.roleList.push(JSON.parse(JSON.stringify(roleCon)));
  374. },
  375. //保存角色
  376. saveRoleList() {
  377. this.roleVisible = false;
  378. this.$message.success("保存成功!");
  379. },
  380. //删除角色
  381. delRole(index) {
  382. this.curQue.roleList.splice(index, 1);
  383. },
  384. //点击角色
  385. editRole(item) {
  386. this.roleVisible = true;
  387. this.roleStatus = 2;
  388. this.curRole = item;
  389. },
  390. changeIsPara() {
  391. this.isPara = true;
  392. },
  393. //生成分句
  394. sureSeg() {
  395. let detail = JSON.parse(JSON.stringify(this.curQue.detail));
  396. let leg = detail.length;
  397. let flag = false;
  398. for (let i = 0; i < leg; i++) {
  399. if (!detail[i].para) {
  400. flag = true;
  401. break;
  402. }
  403. }
  404. if (!flag) {
  405. let textList = [];
  406. detail.forEach((item) => {
  407. let str = Base64.encode(item.para);
  408. textList.push(str);
  409. });
  410. this.loading = true;
  411. let data = {
  412. textList: textList,
  413. };
  414. segSentences(data).then((res) => {
  415. this.loading = false;
  416. let result = res.data.result;
  417. result.forEach((item, index) => {
  418. this.$set(this.curQue.detail[index], "sentences", item);
  419. for (let i = 0; i < item.length; i++) {
  420. this.curQue.detail[index].sentencesEn.push("");
  421. }
  422. });
  423. this.isClause = true;
  424. });
  425. } else {
  426. this.$message.warning("段落不能为空");
  427. }
  428. },
  429. changeIsClause(isClause) {
  430. this.isClause = isClause;
  431. },
  432. //生成分词
  433. segByWord(sentences, paraIndex) {
  434. this.loading = true;
  435. let textList = [];
  436. sentences.forEach((item) => {
  437. let str = Base64.encode(item);
  438. textList.push(str);
  439. });
  440. let data = {
  441. textList: textList,
  442. };
  443. BatchSegContent(data).then((res) => {
  444. this.loading = false;
  445. let list = res.data.result.list;
  446. this.$set(this.curQue.detail[paraIndex], "segList", list);
  447. this.segList = list;
  448. this.isByWord = true;
  449. this.paraIndex = paraIndex;
  450. });
  451. },
  452. // 上传音频文件
  453. handleChange(file, fileList) {
  454. let _this = this;
  455. _this.getBase64(file.raw).then((res) => {
  456. let base_res = res.split("base64,");
  457. let data = {
  458. fileName: file.raw.name,
  459. speechBase64: base_res[1],
  460. language: "ch",
  461. };
  462. prepareTranscribe(data).then((res) => {
  463. _this.$set(_this.curQue, "taskId", res.data.taskId);
  464. });
  465. });
  466. },
  467. getBase64(file) {
  468. return new Promise(function (resolve, reject) {
  469. let reader = new FileReader();
  470. let imgResult = "";
  471. reader.readAsDataURL(file);
  472. reader.onload = function () {
  473. imgResult = reader.result;
  474. };
  475. reader.onerror = function (error) {
  476. reject(error);
  477. };
  478. reader.onloadend = function () {
  479. resolve(imgResult);
  480. };
  481. });
  482. },
  483. createWordTime() {
  484. if (this.curQue.taskId) {
  485. let verseList = [];
  486. this.curQue.detail.forEach((item) => {
  487. verseList = verseList.concat(item.sentences);
  488. });
  489. if (verseList.length > 0) {
  490. this.isWordTime = true;
  491. let data = {
  492. taskId: this.curQue.taskId,
  493. verseList: JSON.stringify(verseList),
  494. language: "ch",
  495. };
  496. getWordTime(data).then((res) => {
  497. this.curQue.wordTime = res.data.result;
  498. this.isWordTime = false;
  499. });
  500. }
  501. } else {
  502. this.$message.warning("请先上传音频");
  503. }
  504. },
  505. againWordTime() {
  506. this.isWordTime = false;
  507. this.$set(this.curQue, "wordTime", []);
  508. },
  509. uploadLRC() {
  510. this.cTVisible = true;
  511. },
  512. //保存字幕节点
  513. saveTimeList() {
  514. this.cTVisible = false;
  515. let detail = JSON.parse(JSON.stringify(this.$refs.createtimelist.detail));
  516. let detailRes = detail.map((item) => {
  517. let timeList = item.time_str.split("\n");
  518. item.timeList = this.handleTimeReg(timeList);
  519. return item;
  520. });
  521. this.curQue.detail = JSON.parse(JSON.stringify(detailRes));
  522. },
  523. handleTimeReg(list) {
  524. list = list.map((item) => {
  525. let regArr = item.split("]");
  526. let reg = regArr[0];
  527. item = reg.replace("[", "");
  528. return item;
  529. });
  530. return list;
  531. },
  532. //点击字幕节点
  533. editTimeList() {
  534. this.cTVisible = true;
  535. },
  536. initData() {
  537. if (this.curQue) {
  538. if (!this.curQue.number) {
  539. this.curQue.number = "";
  540. }
  541. if (this.curQue.detail && this.curQue.detail.length > 0) {
  542. if (this.curQue.detail[0].para) {
  543. this.isPara = true;
  544. }
  545. if (this.curQue.detail[0].sentences.length > 0) {
  546. this.isClause = true;
  547. }
  548. if (this.curQue.detail[0].seg_words.length > 0) {
  549. this.isByWord = true;
  550. }
  551. }
  552. if (!this.curQue.img_list) {
  553. this.curQue.img_list = [];
  554. }
  555. if (!this.curQue.mp3_list) {
  556. this.curQue.mp3_list = [];
  557. }
  558. this.fileCon.img_list = JSON.parse(
  559. JSON.stringify(this.curQue.img_list)
  560. );
  561. this.fileCon.mp3_list = JSON.parse(
  562. JSON.stringify(this.curQue.mp3_list)
  563. );
  564. }
  565. },
  566. },
  567. //生命周期 - 创建完成(可以访问当前this实例)
  568. created() {},
  569. //生命周期 - 挂载完成(可以访问DOM元素)
  570. mounted() {
  571. this.initData();
  572. },
  573. beforeCreate() {}, //生命周期 - 创建之前
  574. beforeMount() {}, //生命周期 - 挂载之前
  575. beforeUpdate() {}, //生命周期 - 更新之前
  576. updated() {}, //生命周期 - 更新之后
  577. beforeDestroy() {}, //生命周期 - 销毁之前
  578. destroyed() {}, //生命周期 - 销毁完成
  579. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  580. };
  581. </script>
  582. <style lang='scss' scoped>
  583. //@import url(); 引入公共css类
  584. p {
  585. margin: 0;
  586. padding: 0;
  587. }
  588. .adult-book-input-role {
  589. clear: both;
  590. overflow: hidden;
  591. > li {
  592. float: left;
  593. display: flex;
  594. justify-content: flex-start;
  595. align-items: center;
  596. padding: 4px 8px;
  597. border: 1px #a7a7a7 solid;
  598. border-radius: 8px;
  599. margin: 0 10px 10px 0px;
  600. .rItem {
  601. display: flex;
  602. justify-content: flex-start;
  603. align-items: center;
  604. .adult-book-input {
  605. &-roleText {
  606. width: 40px;
  607. height: 40px;
  608. background: #a7a7a7;
  609. border-radius: 100%;
  610. text-align: center;
  611. line-height: 40px;
  612. }
  613. &-roleImg {
  614. width: 40px;
  615. height: 40px;
  616. }
  617. }
  618. .pinyin {
  619. font-family: "GB-PINYINOK-B";
  620. font-size: 14px;
  621. line-height: 22px;
  622. color: rgba(0, 0, 0, 0.85);
  623. margin-right: 8px;
  624. margin-left: 8px;
  625. }
  626. .chs {
  627. font-family: "FZJCGFKTK";
  628. font-size: 16px;
  629. line-height: 24px;
  630. color: #000000;
  631. margin-right: 16px;
  632. }
  633. }
  634. > i {
  635. cursor: pointer;
  636. }
  637. }
  638. }
  639. .uploadArt_list {
  640. border: 1px #ccc solid;
  641. border-bottom: 0;
  642. margin-top: 10px;
  643. > li {
  644. display: flex;
  645. justify-content: flex-start;
  646. align-items: center;
  647. border-bottom: 1px #ccc solid;
  648. > span {
  649. width: 320px;
  650. word-wrap: break-word;
  651. font-size: 14px;
  652. color: rgb(112, 110, 110);
  653. border-right: 1px #ccc solid;
  654. padding: 5px 10px;
  655. }
  656. > p {
  657. flex: 1;
  658. padding: 5px 10px;
  659. }
  660. .imgNumber {
  661. width: 80px;
  662. }
  663. .del-close {
  664. width: 24px;
  665. height: 24px;
  666. cursor: pointer;
  667. margin-right: 10px;
  668. }
  669. }
  670. }
  671. .NPC-Book-Article {
  672. > div {
  673. margin-bottom: 20px;
  674. }
  675. }
  676. .NPC-Book-model {
  677. display: flex;
  678. justify-content: flex-start;
  679. align-items: center;
  680. > span {
  681. margin: 0;
  682. }
  683. }
  684. .lrc-box {
  685. display: flex;
  686. justify-content: flex-start;
  687. align-items: center;
  688. > span {
  689. font-size: 14px;
  690. margin-right: 16px;
  691. }
  692. }
  693. </style>