Neword.vue 12 KB

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