Neword.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-Single" v-if="curQue">
  4. <div class="Big-Book-Single-content" style="margin-top: 20px">
  5. <div class="adult-book-input-item">
  6. <span class="adult-book-lable">标题:</span>           
  7. <el-input
  8. style="width: 300px"
  9. placeholder="请输入标题"
  10. v-model="curQue.title"
  11. @blur="onBlur(curQue, 'title')"
  12. class="adult-book-input"
  13. :autosize="{ minRows: 2 }"
  14. maxlength="500"
  15. show-word-limit
  16. ></el-input>
  17. </div>
  18. <div class="adult-book-input-item">
  19. <span class="adult-book-lable">标题颜色:</span>  
  20. <div class="adult-book-main">
  21. <el-radio-group v-model="curQue.titleBg">
  22. <el-radio label="white">白色</el-radio>
  23. <el-radio label="themeColor">书的主题色</el-radio> </el-radio-group
  24. >  
  25. </div>
  26. </div>
  27. <div class="adult-book-input-item">
  28. <span class="adult-book-lable">详细信息:</span>  
  29. <div class="adult-book-main">
  30. <el-radio-group v-model="curQue.isInfor">
  31. <el-radio :label="true">有</el-radio>
  32. <el-radio :label="false">没有</el-radio> </el-radio-group
  33. >  
  34. </div>
  35.       
  36. </div>
  37. <div class="adult-book-input-item">
  38. <span class="adult-book-lable">预览展开:</span>  
  39. <div class="adult-book-main">
  40. <el-radio-group v-model="curQue.isWordShow">
  41. <el-radio :label="true">是</el-radio>
  42. <el-radio :label="false">否</el-radio> </el-radio-group
  43. >  
  44. </div>
  45.       
  46. </div>
  47. <div class="adult-book-input-item">
  48. <span class="adult-book-lable">题目音频:</span>
  49. <Upload
  50. :changeFillId="changeMp3"
  51. :datafileList="curQue.mp3_list"
  52. :filleNumber="mp3Number"
  53. :uploadType="'mp3'"
  54. :handleMp3Base64="handleChange"
  55. />
  56. </div>
  57. <div class="adult-book-input-item">
  58. <span class="adult-book-lable">题目lrc:</span>
  59. <Upload
  60. :changeFillId="changeLrc"
  61. :datafileList="curQue.lrc_list"
  62. :filleNumber="mp3Number"
  63. :uploadType="'lrc'"
  64. />
  65. </div>
  66. <div class="lrc-box">
  67. <div
  68. v-if="this.curQue.wordTime && this.curQue.wordTime.length > 0"
  69. class="lrc-box"
  70. >
  71. <span>已有字幕时间节点</span>
  72. <el-button type="text" @click="againWordTime">重新生成</el-button>
  73. </div>
  74. <template v-else>
  75. <el-button v-if="!isWordTime" size="medium" @click="createWordTime"
  76. >自动生成字幕节点</el-button
  77. >
  78. <p v-else>字幕节点生成中...请等待</p>
  79. </template>
  80. </div>
  81. <div class="adult-book-input-item">
  82. <span class="adult-book-lable"></span>
  83. <el-button
  84. type="primary"
  85. size="small"
  86. class="distribution"
  87. @click="parseLrcFile"
  88. >
  89. 分配时间
  90. </el-button>
  91. </div>
  92. <div
  93. class="Big-Book-main"
  94. v-for="(item, index) in curQue.option"
  95. :key="'newWord' + index"
  96. style="border-bottom: 1px #ccc solid; margin-bottom: 20px"
  97. >
  98. <div class="Big-Book-mian-op">
  99. <span>{{'第'+(index+1)+'组'}} </span>
  100. <el-button
  101. type="primary"
  102. size="small"
  103. icon="el-icon-top"
  104. @click="moveElement(item, index, 'up')"
  105. >上移</el-button
  106. >
  107. <el-button
  108. type="primary"
  109. size="small"
  110. icon="el-icon-bottom"
  111. @click="moveElement(item, index, 'down')"
  112. >下移</el-button
  113. >
  114. <el-button size="mini" type="danger" @click="delsItem(index)">
  115. 删除本组
  116. </el-button>
  117. </div>
  118. <div
  119. class="Big-Book-main-inner"
  120. v-for="(sItem, sIndex) in item"
  121. :key="'newWord_' + sIndex"
  122. >
  123. <NewordPhraseModule
  124. :curQue="curQue"
  125. :curQueItem="sItem"
  126. :index="index"
  127. :sIndex="sIndex"
  128. :type="curQue.type"
  129. :deleteGroup="deleteGroup"
  130. :moveElement2="moveElement2"
  131. />
  132. </div>
  133. <div class="addoption addoption2" @click="saddoption(item)">
  134. 添加字词
  135. </div>
  136. </div>
  137. <div class="addoption" @click="addoption">添加一组</div>
  138. </div>
  139. </div>
  140. </template>
  141. <script>
  142. import Inputmodule from "../common/Inputmodule.vue";
  143. import NewordPhraseModule from "../common/NewordPhraseModule.vue";
  144. import { getWordTime, getContentFile, prepareTranscribe } from "@/api/ajax";
  145. import Upload from "../common/Upload";
  146. export default {
  147. name: "Single",
  148. props: ["curQue", "changeCurQue"],
  149. components: {
  150. Inputmodule,
  151. NewordPhraseModule,
  152. Upload,
  153. },
  154. data() {
  155. return {
  156. mp3Number: 1,
  157. isWordTime: false,
  158. data_structure: {
  159. type: "NewWord_chs",
  160. name: "生词",
  161. title: "",
  162. isInfor: true,
  163. isWordShow: true,
  164. titleBg: "themeColor", //标题背景颜色
  165. mp3_list: [],
  166. lrc_list: [],
  167. taskId: [],
  168. wordTime: null,
  169. option: [
  170. [
  171. {
  172. new_word: "",
  173. cixing: "", //词性
  174. definition_list: [""], //需要增加词性
  175. pinyin: "",
  176. img_list: [],
  177. mp3_list: [],
  178. pinyin_site: "first", //拼音位置
  179. motif_color: false, //主题色
  180. },
  181. ],
  182. ],
  183. },
  184. };
  185. },
  186. computed: {},
  187. watch: {},
  188. //方法集合
  189. methods: {
  190. onBlur(item, field) {
  191. item[field] = item[field] ? item[field].trim() : "";
  192. },
  193. addoption() {
  194. let res_data = JSON.parse(JSON.stringify(this.data_structure));
  195. let obj = res_data.option[0];
  196. obj.index = this.curQue.option.push(obj);
  197. },
  198. deleteGroup(index, sIndex) {
  199. this.$confirm("确定要删除吗?", "提示", {
  200. confirmButtonText: "确定",
  201. cancelButtonText: "取消",
  202. type: "warning",
  203. }).then(() => {
  204. if (this.curQue.option[index].length == 1) {
  205. this.$message.warning("至少剩余1个,不能全部删除");
  206. return;
  207. }
  208. this.curQue.option[index].splice(sIndex, 1);
  209. });
  210. },
  211. saddoption(item) {
  212. let con = {
  213. new_word: "",
  214. cixing: "", //词性
  215. definition_list: [""], //需要增加词性
  216. pinyin: "",
  217. img_list: [],
  218. mp3_list: [],
  219. };
  220. item.push(con);
  221. },
  222. delsItem(index) {
  223. this.$confirm("确定要删除吗?", "提示", {
  224. confirmButtonText: "确定",
  225. cancelButtonText: "取消",
  226. type: "warning",
  227. }).then(() => {
  228. this.curQue.option.splice(index, 1);
  229. });
  230. },
  231. changeMp3(fileList) {
  232. const articleImgList = JSON.parse(JSON.stringify(fileList));
  233. const articleImgRes = [];
  234. articleImgList.forEach((item) => {
  235. if (item.response) {
  236. const obj = {
  237. name: item.name,
  238. url: item.response.file_info_list[0].file_url,
  239. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  240. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  241. };
  242. articleImgRes.push(obj);
  243. }
  244. });
  245. this.curQue.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
  246. },
  247. parseLrcFile() {
  248. let lrcList = this.curQue.lrc_list;
  249. if (lrcList.length === 0) {
  250. if (this.curQue.wordTime.length > 0) {
  251. this.handleNewwordList();
  252. } else {
  253. this.$message.warning("请先上传lrc文件或自动生成字幕节点");
  254. }
  255. } else {
  256. getContentFile("tool-ParseLRCFile", {
  257. content_type: "FILE",
  258. file_id: this.curQue.lrc_list[0].file_id,
  259. }).then(({ lrc_list }) => {
  260. let lrc_list_res = [];
  261. lrc_list.forEach((item) => {
  262. let obj = {
  263. bg: item.begin_time,
  264. ed: item.end_time,
  265. };
  266. lrc_list_res.push(obj);
  267. });
  268. this.handleNewwordList();
  269. this.curQue.wordTime = lrc_list_res;
  270. });
  271. }
  272. },
  273. handleNewwordList() {
  274. let index = 0;
  275. // let option = JSO
  276. this.curQue.option.map((item) => {
  277. item.map((sItem) => {
  278. this.$set(sItem, "index", index);
  279. index++;
  280. return sItem;
  281. });
  282. return item;
  283. });
  284. console.log(this.curQue.option);
  285. },
  286. getBase64(file) {
  287. return new Promise(function (resolve, reject) {
  288. let reader = new FileReader();
  289. let imgResult = "";
  290. reader.readAsDataURL(file);
  291. reader.onload = function () {
  292. imgResult = reader.result;
  293. };
  294. reader.onerror = function (error) {
  295. reject(error);
  296. };
  297. reader.onloadend = function () {
  298. resolve(imgResult);
  299. };
  300. });
  301. },
  302. createWordTime() {
  303. if (this.curQue.taskId) {
  304. let verseList = [];
  305. this.curQue.option.forEach((item, index) => {
  306. item.forEach((sItem, sIndex) => {
  307. verseList.push(sItem.new_word);
  308. });
  309. });
  310. if (verseList.length > 0) {
  311. this.isWordTime = true;
  312. let data = {
  313. taskId: this.curQue.taskId,
  314. verseList: JSON.stringify(verseList),
  315. matchType: "chinese",
  316. language: "ch",
  317. };
  318. getWordTime(data).then((res) => {
  319. this.curQue.wordTime = res.data.result;
  320. this.isWordTime = false;
  321. });
  322. }
  323. } else {
  324. this.$message.warning("请先上传音频");
  325. }
  326. },
  327. againWordTime() {
  328. this.isWordTime = false;
  329. this.$set(this.curQue, "wordTime", []);
  330. },
  331. // 上传音频文件
  332. handleChange(file, fileList) {
  333. let _this = this;
  334. _this.getBase64(file.raw).then((res) => {
  335. let base_res = res.split("base64,");
  336. let data = {
  337. fileName: file.raw.name,
  338. speechBase64: base_res[1],
  339. language: "ch",
  340. };
  341. prepareTranscribe(data).then((reses) => {
  342. _this.$set(_this.curQue, "taskId", reses.data.taskId);
  343. });
  344. });
  345. },
  346. changeLrc(fileList) {
  347. let lrc_list = [];
  348. fileList.forEach(({ response, name }) => {
  349. if (response) {
  350. let fileLists = response.file_info_list[0];
  351. lrc_list.push({
  352. name,
  353. duration: fileLists.media_duration,
  354. url: fileLists.file_url,
  355. id: "[FID##" + fileLists.file_id + "##FID]",
  356. file_id: fileLists.file_id,
  357. });
  358. }
  359. });
  360. this.curQue.lrc_list = lrc_list;
  361. },
  362. moveElement(dItem, index, type) {
  363. let obj = JSON.parse(JSON.stringify(dItem));
  364. if (type == "up" && index > 0) {
  365. this.curQue.option.splice(index - 1, 0, obj);
  366. this.curQue.option.splice(index + 1, 1);
  367. }
  368. if (type == "down" && index < this.curQue.option.length - 1) {
  369. this.curQue.option[index] = this.curQue.option.splice(index + 1, 1, this.curQue.option[index])[0]
  370. }
  371. },
  372. moveElement2(dItem, type, index, index2) {
  373. let obj = JSON.parse(JSON.stringify(dItem));
  374. if (type == "up" && index2 > 0) {
  375. this.curQue.option[index].splice(index2 - 1, 0, obj);
  376. this.curQue.option[index].splice(index2 + 1, 1);
  377. }
  378. if (type == "down" && index2 < this.curQue.option[index].length - 1) {
  379. this.curQue.option[index][index2] = this.curQue.option[index].splice(index2 + 1, 1, this.curQue.option[index][index2])[0]
  380. }
  381. },
  382. },
  383. //生命周期 - 创建完成(可以访问当前this实例)
  384. created() {},
  385. //生命周期 - 挂载完成(可以访问DOM元素)
  386. mounted() {
  387. if (!this.curQue) {
  388. let res_data = JSON.parse(JSON.stringify(this.data_structure));
  389. this.changeCurQue(res_data);
  390. } else {
  391. if (!this.curQue.hasOwnProperty("isInfor")) {
  392. this.$set(this.curQue, "isInfor", true);
  393. }
  394. if (!this.curQue.hasOwnProperty("isWordShow")) {
  395. this.$set(this.curQue, "isWordShow", true);
  396. }
  397. if (!this.curQue.hasOwnProperty("titleBg")) {
  398. this.$set(this.curQue, "titleBg", "themeColor");
  399. }
  400. if (!this.curQue.hasOwnProperty("mp3_list")) {
  401. this.$set(this.curQue, "mp3_list", []);
  402. }
  403. if (!this.curQue.hasOwnProperty("lrc_list")) {
  404. this.$set(this.curQue, "lrc_list", []);
  405. }
  406. if (!this.curQue.hasOwnProperty("taskId")) {
  407. this.$set(this.curQue, "taskId", "");
  408. }
  409. if (!this.curQue.hasOwnProperty("wordTime")) {
  410. this.$set(this.curQue, "wordTime", null);
  411. }
  412. // let data = JSON.parse(JSON.stringify(this.curQue));
  413. this.curQue.option.forEach((item) => {
  414. if (!item[0].pinyin_site) {
  415. item[0].pinyin_site = "first"; //拼音位置
  416. }
  417. if (!item[0].motif_color) {
  418. item[0].motif_color = false; //主题色
  419. }
  420. });
  421. // this.curQue = JSON.parse(JSON.stringify(data));
  422. }
  423. },
  424. beforeCreate() {}, //生命周期 - 创建之前
  425. beforeMount() {}, //生命周期 - 挂载之前
  426. beforeUpdate() {}, //生命周期 - 更新之前
  427. updated() {}, //生命周期 - 更新之后
  428. beforeDestroy() {}, //生命周期 - 销毁之前
  429. destroyed() {}, //生命周期 - 销毁完成
  430. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  431. };
  432. </script>
  433. <style lang='scss' scope>
  434. //@import url(); 引入公共css类
  435. .Big-Book-Single {
  436. &-content {
  437. &.m {
  438. display: flex;
  439. justify-content: flex-start;
  440. align-items: flex-start;
  441. }
  442. .Big-Book-title {
  443. font-size: 16px;
  444. line-height: 40px;
  445. color: #000;
  446. margin-right: 15px;
  447. }
  448. .Big-Book-main {
  449. background: rgba(230, 229, 229, 0.3);
  450. border: 1px #999 solid;
  451. border-radius: 8px;
  452. padding: 20px;
  453. > div {
  454. margin-bottom: 10px;
  455. &.Big-Book-pinyin {
  456. display: flex;
  457. justify-content: flex-start;
  458. align-items: center;
  459. }
  460. }
  461. .Big-Book-main-inner {
  462. }
  463. }
  464. }
  465. .addoption {
  466. width: 565px;
  467. height: 40px;
  468. left: 40px;
  469. top: 304px;
  470. background: #f3f3f3;
  471. border: 1px dashed rgba(0, 0, 0, 0.15);
  472. box-sizing: border-box;
  473. border-radius: 4px;
  474. text-align: center;
  475. line-height: 40px;
  476. cursor: pointer;
  477. &.addoption2 {
  478. width: 200px;
  479. }
  480. }
  481. .Big-Book-con {
  482. padding-bottom: 6px;
  483. border-bottom: 1px dashed rgba(0, 0, 0, 0.15);
  484. }
  485. }
  486. </style>
  487. <style lang="scss">
  488. </style>