index.vue 18 KB

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