123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801 |
- <!-- -->
- <template>
- <div
- class="NPC-Book-Article Big-Book-Maxwidth"
- v-if="curQue"
- v-loading="loading"
- >
- <div class="adult-book-input-item">
- <span class="adult-book-lable">序号:</span>
- <el-input
- class="adult-book-input"
- placeholder="请输入序号"
- v-model="curQue.number"
- @blur="onBlur(curQue, 'number')"
- ></el-input>
- </div>
- <div class="Big-Book-mp3">
- <Upload
- :changeFillId="changeImage"
- :datafileList="fileCon.img_list"
- :filleNumber="imgNumber"
- :uploadType="'image'"
- />
- </div>
- <div class="Big-Book-mp3">
- <Upload
- type="mp3"
- :changeFillId="changeMp3"
- :datafileList="fileCon.mp3_list"
- :filleNumber="mp3Number"
- :uploadType="'mp3'"
- :handleMp3Base64="handleChange"
- />
- </div>
- <div class="adult-book-input-item">
- <span class="adult-book-lable">内容类型:</span>
- <el-radio-group v-model="curQue.font">
- <el-radio label="py">拼音</el-radio>
- <el-radio label="cn">汉字</el-radio>
- </el-radio-group>
- </div>
- <div class="adult-book-input-item" v-if="type != 'option'">
- <span class="adult-book-lable">功能设置:</span>
- <el-checkbox-group
- v-model="curQue.checkList"
- @change="handleCheckedFnChange"
- >
- <el-checkbox
- v-for="(fnItem, fnIndex) in fn_list"
- :key="'dis_fn_list' + fnIndex"
- :label="fnItem.type"
- >{{ fnItem.name }}</el-checkbox
- >
- </el-checkbox-group>
- </div>
- <div class="adult-book-input-item">
- <span class="adult-book-lable">文章提示:</span>
- <el-input
- class="adult-book-input"
- type="textarea"
- :autosize="{ minRows: 2 }"
- placeholder="请输入文章提示"
- v-model="curQue.notice"
- @blur="onBlur(curQue, 'notice')"
- ></el-input>
- </div>
- <div class="NPC-Book-role" v-if="curQue.roleList">
- <ul
- class="adult-book-input-role"
- v-if="curQue.roleList && curQue.roleList.length > 0"
- >
- <li
- v-for="(rItem, rIndex) in curQue.roleList"
- :key="'roleList' + rIndex"
- >
- <div class="rItem" @click="editRole(rItem)">
- <span v-if="rItem.role" class="adult-book-input-roleText">{{
- rItem.role
- }}</span>
- <img
- v-else-if="rItem.img_list.length>0"
- :src="rItem.img_list[0] && rItem.img_list[0].url"
- class="adult-book-input-roleImg"
- />
- <img
- v-else-if="rItem.simpleHead!==''"
- :src="require('../../../../assets/NPC/simple'+(rItem.simpleHead+1)+'.png')"
- class="adult-book-input-roleImg"
- />
- <template v-if="rItem.detail.wordsList.length > 0">
- <span class="pinyin">{{
- rItem.detail.wordsList | handlePinyin
- }}</span>
- <span class="chs">{{ rItem.detail.wordsList | handleChs }}</span>
- </template>
- </div>
- <i class="el-icon-circle-close" @click="delRole(rIndex)"></i>
- </li>
- </ul>
- <el-button type="primary" @click="addRole">添加角色</el-button>
- </div>
- <div class="NPC-Book-article">
- <ArticleChs
- :curQue="curQue"
- :isPara="isPara"
- :changeIsPara="changeIsPara"
- />
- </div>
- <div class="NPC-Book-Paragraph" v-if="isPara">
- <Paragraph :curQue="curQue" :isClause="isClause" :sureSeg="sureSeg" />
- </div>
- <!---上传rlc文件-->
- <!-- <div class="NPC-Book-Paragraph" v-if="isClause">
- <el-button
- type="warning"
- size="small"
- @click="uploadLRC"
- v-if="curQue.detail[0].timeList.length == 0"
- >上传lrc文件</el-button
- >
- <div v-else class="lrc-box">
- <span>已有字幕时间节点</span>
- <el-button type="text" @click="editTimeList">去编辑</el-button>
- </div>
- </div> -->
- <!---分句-->
- <div class="NPC-Book-Paragraph" v-if="isClause">
- <Clauseresult :curQue="curQue" :segByWord="segByWord" v-if="isClause" />
- </div>
- <template v-if="curQue.font !== 'py'">
- <div class="lrc-box">
- <div
- v-if="this.curQue.wordTime && this.curQue.wordTime.length > 0"
- class="lrc-box"
- >
- <span>已有字幕时间节点</span>
- <el-button type="text" @click="againWordTime">重新生成</el-button>
- </div>
- <template v-else>
- <el-button v-if="!isWordTime" size="medium" @click="createWordTime"
- >自动生成字幕节点</el-button
- >
- <p v-else>字幕节点生成中...请等待</p>
- </template>
- </div>
- <!---分词-->
- <div class="NPC-Book-Word" v-if="isByWord">
- <Segbyword
- :curQue="curQue"
- :paraIndex="paraIndex"
- :segList="segList"
- :type="type"
- v-if="isByWord"
- />
- </div>
- </template>
- <!---答案-->
- <div
- class="adult-book-input-item"
- v-if="curQue.checkList && curQue.checkList.indexOf('input') > -1"
- >
- <span class="adult-book-lable">答案:</span>
- <el-input
- class="adult-book-input"
- type="textarea"
- :autosize="{ minRows: 2 }"
- placeholder="请输入答案"
- v-model="curQue.answer"
- @blur="onBlur(curQue, 'answer')"
- ></el-input>
- </div>
- <el-dialog title="段落分句字幕打点" :visible.sync="cTVisible" width="30%">
- <Createtimelist ref="createtimelist" :curQue="curQue" />
- <span slot="footer" class="dialog-footer">
- <el-button @click="cTVisible = false">取 消</el-button>
- <el-button type="primary" @click="saveTimeList">保 存</el-button>
- </span>
- </el-dialog>
- <el-dialog
- :title="roleStatus == 1 ? '添加角色' : '编辑角色'"
- :visible.sync="roleVisible"
- :close-on-click-modal="false"
- :modal-append-to-body="false"
- append-to-body
- width="60%"
- >
- <template v-if="curQue.roleList">
- <template v-if="roleStatus == 1">
- <RoleChs
- ref="createRolelist"
- :curRole="curQue.roleList[curQue.roleList.length - 1]"
- />
- </template>
- <template v-else>
- <RoleChs ref="createRolelist" :curRole="curRole" />
- </template>
- </template>
- <span slot="footer" class="dialog-footer">
- <el-button @click="roleVisible = false">取 消</el-button>
- <el-button type="primary" @click="saveRoleList">保 存</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import {
- segSentences,
- BatchSegContent,
- prepareTranscribe,
- getWordTime,
- } from "@/api/ajax";
- const Base64 = require("js-base64").Base64;
- import Upload from "../../common/Upload.vue";
- import UploadArt from "../../common/UploadArt.vue";
- import ArticleChs from "./components/ArticleChs.vue";
- import Paragraph from "./components/ParagraphChs.vue";
- import Clauseresult from "./components/ClauseresultChs.vue";
- import Segbyword from "./components/SegbywordChs.vue";
- import Createtimelist from "./components/CreatetimelistChs.vue";
- import RoleChs from "./components/RoleChs.vue";
- export default {
- name: "ArticleTemChs",
- components: {
- Upload,
- UploadArt,
- ArticleChs,
- Paragraph,
- Clauseresult,
- Segbyword,
- Createtimelist,
- RoleChs,
- },
- props: ["curQue", "changeCurQue", "listIndex", "segModel", "type"],
- filters: {
- handlePinyin(wordsList) {
- let str = "";
- wordsList.forEach((item, index) => {
- if (index < wordsList.length - 1) {
- str += item.pinyin + " ";
- } else {
- str += item.pinyin;
- }
- });
- return str;
- },
- handleChs(wordsList) {
- let str = "";
- wordsList.forEach((item, index) => {
- if (index < wordsList.length - 1) {
- str += item.chs + " ";
- } else {
- str += item.chs;
- }
- });
- return str;
- },
- },
- data() {
- return {
- fn_list: [
- {
- type: "input",
- name: "填空题",
- isFn: false,
- isDisable: false,
- },
- {
- type: "judge",
- name: "判断题",
- isFn: false,
- isDisable: false,
- },
- {
- type: "record",
- name: "录音题",
- isFn: false,
- isDisable: false,
- },
- ],
- imgNumber: 1,
- mp3Number: 1,
- fileCon: {
- img_list: [],
- mp3_list: [],
- },
- isPara: false,
- isClause: false,
- isByWord: false,
- paraIndex: 0, //段落索引
- cTVisible: false,
- roleVisible: false,
- roleStatus: 1, //1添加;2是编辑
- curRole: null,
- loading: false,
- segList: null,
- isWordTime: false,
- };
- },
- computed: {},
- watch: {
- listIndex: {
- handler: function (newVal, oldVal) {
- if (newVal !== oldVal) {
- this.isPara = false;
- this.isClause = false;
- this.isByWord = false;
- this.paraIndex = 0; //段落索引
- this.roleStatus = 1; //1添加;2是编辑
- this.curRole = null;
- this.loading = false;
- this.segList = null;
- this.isWordTime = false;
- console.log(this.isClause);
- this.initData();
- }
- },
- deep: true,
- },
- },
- //方法集合
- methods: {
- onBlur(item, field) {
- item[field] = item[field] ? item[field].trim() : "";
- },
- onBlurIndex(index, field) {
- let res = this.curQueItem[field][index].trim();
- this.$set(this.curQueItem[field], index, res);
- },
- // 更多配置选择
- handleCheckedFnChange(value) {
- let _this = this;
- if (_this.curQue.checkList.indexOf("input") < 0) {
- _this.curQue.answer = "";
- }
- if (_this.curQue.checkList.indexOf("judge") < 0) {
- _this.curQue.judge = [];
- } else {
- _this.curQue.judge = [];
- _this.curQue.detail.forEach(() => {
- _this.curQue.judge.push(
- JSON.parse(JSON.stringify({ isJudge: false, judge: "" }))
- );
- });
- }
- },
- changeMp3(fileList) {
- const articleImgList = JSON.parse(JSON.stringify(fileList));
- const articleImgRes = [];
- articleImgList.forEach((item) => {
- if (item.response) {
- const obj = {
- name: item.name,
- duration: item.response.file_info_list[0].media_duration,
- url: item.response.file_info_list[0].file_url,
- id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
- media_duration: item.response.file_info_list[0].media_duration, //音频时长
- };
- articleImgRes.push(obj);
- }
- });
- this.curQue.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
- },
- changeImage(fileList) {
- const articleImgList = JSON.parse(JSON.stringify(fileList));
- const articleImgRes = [];
- articleImgList.forEach((item) => {
- if (item.response) {
- const obj = {
- name: item.name,
- url: item.response.file_info_list[0].file_url,
- id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
- };
- articleImgRes.push(obj);
- }
- });
- this.curQue.img_list = JSON.parse(JSON.stringify(articleImgRes));
- },
- changeImage2(file) {
- if (file.response) {
- const obj = {
- name: file.name,
- url: file.response.file_info_list[0].file_url,
- id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
- };
- this.curQue.img_list.push(obj);
- this.$forceUpdate();
- }
- },
- forceUpdate() {
- this.$forceUpdate();
- },
- delImage(index) {
- this.curQue.img_list.splice(index, 1);
- this.fileCon.img_list.splice(index, 1);
- },
- //添加角色
- addRole() {
- this.roleVisible = true;
- this.roleStatus = 1;
- let id = Math.random().toString(36).substr(2);
- let roleCon = {
- id: id,
- role: "",
- img_list: [],
- detail: {
- fullName: "",
- seg_words: "",
- wordsList: [],
- },
- simpleHead: ""
- };
- this.curQue.roleList.push(JSON.parse(JSON.stringify(roleCon)));
- },
- //保存角色
- saveRoleList() {
- this.roleVisible = false;
- this.$message.success("保存成功!");
- },
- //删除角色
- delRole(index) {
- this.curQue.roleList.splice(index, 1);
- },
- //点击角色
- editRole(item) {
- this.roleVisible = true;
- this.roleStatus = 2;
- this.curRole = item;
- },
- changeIsPara() {
- this.isPara = true;
- },
- //生成分句
- sureSeg() {
- let detail = JSON.parse(JSON.stringify(this.curQue.detail));
- let leg = detail.length;
- let flag = false;
- for (let i = 0; i < leg; i++) {
- if (!detail[i].para) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- let textList = [];
- detail.forEach((item) => {
- let str = Base64.encode(item.para);
- textList.push(str);
- });
- this.loading = true;
- let data = {
- textList: textList,
- };
- segSentences(data).then((res) => {
- this.loading = false;
- let result = res.data.result;
- result.forEach((item, index) => {
- this.$set(this.curQue.detail[index], "sentences", item);
- for (let i = 0; i < item.length; i++) {
- this.curQue.detail[index].sentencesEn.push("");
- }
- });
- this.isClause = true;
- });
- } else {
- this.$message.warning("段落不能为空");
- }
- },
- changeIsClause(isClause) {
- this.isClause = isClause;
- },
- //生成分词
- segByWord(sentences, paraIndex) {
- if (!this.segModel || this.segModel == "words") {
- this.loading = true;
- let textList = [];
- sentences.forEach((item) => {
- let str = Base64.encode(item);
- textList.push(str);
- });
- let data = {
- textList: textList,
- };
- BatchSegContent(data).then((res) => {
- this.loading = false;
- let list = res.data.result.list;
- this.$set(this.curQue.detail[paraIndex], "segList", list);
- this.segList = list;
- this.isByWord = true;
- this.paraIndex = paraIndex;
- this.setWordsList(list, paraIndex);
- });
- } else {
- let list = [];
- let reg = /_{2,}/g;
- sentences.forEach((item) => {
- if (reg.test(item)) {
- item = item.replace(reg, "^");
- }
- let arr = item.split("");
- arr = arr.map((aItem) => {
- aItem = aItem == "^" ? "_______" : aItem;
- return aItem;
- });
- list.push(arr);
- });
- console.log(list);
- this.setWordsList(list, paraIndex);
- this.$set(this.curQue.detail[paraIndex], "segList", list);
- console.log(this.curQue);
- this.segList = list;
- this.isByWord = true;
- this.paraIndex = paraIndex;
- }
- },
- setWordsList(list, paraIndex) {
- let wordsList = [];
- list.forEach((item, index) => {
- let sentArr = [];
- item.map((sItem) => {
- let obj = {
- chs: sItem,
- pinyin: "",
- fontSize: "20px",
- fontColor: "#000",
- fontFamily: "FZJCGFKTK",
- wordPadding: [],
- underLine: false,
- };
- sentArr.push(obj);
- });
- wordsList.push(sentArr);
- });
- this.$set(this.curQue.detail[paraIndex], "wordsList", wordsList);
- },
- // 上传音频文件
- handleChange(file, fileList) {
- let _this = this;
- _this.getBase64(file.raw).then((res) => {
- let base_res = res.split("base64,");
- let data = {
- fileName: file.raw.name,
- speechBase64: base_res[1],
- language: "ch",
- };
- prepareTranscribe(data).then((reses) => {
- _this.$set(_this.curQue, "taskId", reses.data.taskId);
- });
- });
- },
- getBase64(file) {
- return new Promise(function (resolve, reject) {
- let reader = new FileReader();
- let imgResult = "";
- reader.readAsDataURL(file);
- reader.onload = function () {
- imgResult = reader.result;
- };
- reader.onerror = function (error) {
- reject(error);
- };
- reader.onloadend = function () {
- resolve(imgResult);
- };
- });
- },
- createWordTime() {
- if (this.curQue.taskId) {
- let verseList = [];
- this.curQue.detail.forEach((item) => {
- verseList = verseList.concat(item.sentences);
- });
- if (verseList.length > 0) {
- this.isWordTime = true;
- let data = {
- taskId: this.curQue.taskId,
- verseList: JSON.stringify(verseList),
- language: "ch",
- };
- getWordTime(data).then((res) => {
- this.curQue.wordTime = res.data.result;
- this.isWordTime = false;
- });
- }
- } else {
- this.$message.warning("请先上传音频");
- }
- },
- againWordTime() {
- this.isWordTime = false;
- this.$set(this.curQue, "wordTime", []);
- },
- uploadLRC() {
- this.cTVisible = true;
- },
- //保存字幕节点
- saveTimeList() {
- this.cTVisible = false;
- let detail = JSON.parse(JSON.stringify(this.$refs.createtimelist.detail));
- let detailRes = detail.map((item) => {
- let timeList = item.time_str.split("\n");
- item.timeList = this.handleTimeReg(timeList);
- return item;
- });
- this.curQue.detail = JSON.parse(JSON.stringify(detailRes));
- },
- handleTimeReg(list) {
- list = list.map((item) => {
- let regArr = item.split("]");
- let reg = regArr[0];
- item = reg.replace("[", "");
- return item;
- });
- return list;
- },
- //点击字幕节点
- editTimeList() {
- this.cTVisible = true;
- },
- initData() {
- if (this.curQue) {
- if(this.curQue.detail&&this.curQue.detail[this.paraIndex]&&this.curQue.detail[this.paraIndex].segList){
- this.segList = this.curQue.detail[this.paraIndex].segList;
- }
- if (!this.curQue.number) {
- this.curQue.number = "";
- }
- if (this.curQue.detail && this.curQue.detail.length > 0) {
- if (this.curQue.detail[0].para) {
- this.isPara = true;
- }
- if (this.curQue.detail[0].sentences.length > 0) {
- this.isClause = true;
- }
- if (this.curQue.detail[0].seg_words.length > 0) {
- this.isByWord = true;
- }
- }
- if (!this.curQue.img_list) {
- this.curQue.img_list = [];
- }
- if (!this.curQue.mp3_list) {
- this.curQue.mp3_list = [];
- }
- this.fileCon.img_list = JSON.parse(
- JSON.stringify(this.curQue.img_list)
- );
- this.fileCon.mp3_list = JSON.parse(
- JSON.stringify(this.curQue.mp3_list)
- );
- }
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- this.initData();
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='scss' scoped>
- //@import url(); 引入公共css类
- p {
- margin: 0;
- padding: 0;
- }
- .adult-book-input-item {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- > span {
- margin-right: 10px;
- width: 70px;
- }
- }
- .adult-book-input-role {
- clear: both;
- overflow: hidden;
- > li {
- float: left;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- padding: 4px 8px;
- border: 1px #a7a7a7 solid;
- border-radius: 8px;
- margin: 0 10px 10px 0px;
- .rItem {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .adult-book-input {
- &-roleText {
- width: 40px;
- height: 40px;
- background: #a7a7a7;
- border-radius: 100%;
- text-align: center;
- line-height: 40px;
- }
- &-roleImg {
- width: 40px;
- height: 40px;
- }
- }
- .pinyin {
- font-family: "GB-PINYINOK-B";
- font-size: 14px;
- line-height: 22px;
- color: rgba(0, 0, 0, 0.85);
- margin-right: 8px;
- margin-left: 8px;
- }
- .chs {
- font-family: "FZJCGFKTK";
- font-size: 16px;
- line-height: 24px;
- color: #000000;
- margin-right: 16px;
- }
- }
- > i {
- cursor: pointer;
- }
- }
- }
- .uploadArt_list {
- border: 1px #ccc solid;
- border-bottom: 0;
- margin-top: 10px;
- > li {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- border-bottom: 1px #ccc solid;
- > span {
- width: 320px;
- word-wrap: break-word;
- font-size: 14px;
- color: rgb(112, 110, 110);
- border-right: 1px #ccc solid;
- padding: 5px 10px;
- }
- > p {
- flex: 1;
- padding: 5px 10px;
- }
- .imgNumber {
- width: 80px;
- }
- .del-close {
- width: 24px;
- height: 24px;
- cursor: pointer;
- margin-right: 10px;
- }
- }
- }
- .NPC-Book-Article {
- > div {
- margin-bottom: 20px;
- }
- }
- .NPC-Book-model {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- > span {
- margin: 0;
- }
- }
- .lrc-box {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- > span {
- font-size: 14px;
- margin-right: 16px;
- }
- }
- </style>
|