index.vue 19 KB

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