123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- <!-- -->
- <template>
- <div class="NNPE-ArticleView" v-if="curQue">
- <div class="aduioLine-box aduioLine-practice">
- <div
- class="aduioLine-content"
- v-if="
- curQue.mp3_list &&
- curQue.mp3_list.length > 0 &&
- curQue.mp3_list[0].url
- "
- >
- <AudioLine
- audioId="artPraAudio"
- :mp3="curQue.mp3_list[0].url"
- :getCurTime="getCurTime"
- ref="audioLine"
- :stopAudio="stopAudio"
- :width="555"
- @handleChangeStopAudio="handleChangeStopAudio"
- />
- </div>
- <div class="aduioLine-right">
- <span
- :class="['Repeat-16', isRepeat ? '' : 'disabled']"
- @click="changeRepeat"
- ></span>
- <span
- :class="['pinyin-16', isShowPY ? '' : 'disabled']"
- @click="changePinyin"
- ></span>
- </div>
- </div>
- <template v-if="resObj">
- <!-- -->
- <div class="NPC-sentences-list">
- <div
- :class="['NNPE-detail-box', sentIndex == index ? 'active' : '']"
- v-for="(item, index) in resObj.sentList"
- :key="'detail' + index"
- >
- <div
- :class="['NNPE-detail']"
- @click="
- handleChangeTime(
- curQue.wordTime &&
- curQue.wordTime[index] &&
- curQue.wordTime[index].bg,
- index
- )
- "
- >
- <div
- class="NNPE-words"
- v-for="(pItem, pIndex) in item"
- :key="'wordsList' + pIndex"
- :class="[pItem.wordIndex == 0 ? 'textLeft' : 'textCenter']"
- >
- <template v-if="!pItem.width">
- <template v-if="pItem.isShow">
- <template
- v-if="
- item[pIndex + 1].chs &&
- chsFhList.indexOf(item[pIndex + 1].chs) > -1
- "
- >
- <span class="NNPE-words-box">
- <template v-if="curQue.pyPosition == 'top'">
- <span
- v-if="isShowPY"
- class="NNPE-pinyin"
- :class="[
- pItem.className ? pItem.className : '',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </template>
- <span
- class="NNPE-chs"
- :class="[
- pItem.padding && isShowPY ? 'padding' : '',
- sentIndex == index ? 'wordBlank' : '',
- ]"
- >
- <template>
- <span
- v-for="(wItem, wIndex) in pItem.leg"
- :key="'ci' + wIndex + pIndex + index"
- :class="[
- pItem.timeList[wIndex] &&
- curTime >= pItem.timeList[wIndex].wordBg &&
- curTime <= curQue.wordTime[index].ed
- ? 'active'
- : '',
- sentIndex == index ? 'wordBlank' : '',
- ]"
- >{{ pItem.chs[wIndex] }}</span
- >
- </template>
- </span>
- <template v-if="curQue.pyPosition == 'bottom'">
- <span
- v-if="isShowPY"
- class="NNPE-pinyin"
- :class="[
- pItem.className ? pItem.className : '',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </template>
- </span>
- <span class="NNPE-words-box">
- <template v-if="curQue.pyPosition == 'top'">
- <span
- v-if="isShowPY"
- :class="[
- 'NNPE-pinyin',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(item[pIndex + 1].pinyin) > -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item[pIndex + 1].pinyin }}</span
- >
- </template>
- <span class="NNPE-chs" style="text-align: left">
- <span
- :class="[
- pItem.timeList[pItem.leg - 1] &&
- curQue.wordTime &&
- curTime >= pItem.timeList[pItem.leg - 1].wordBg &&
- curTime <= curQue.wordTime[index].ed
- ? 'active'
- : '',
- sentIndex == index ? 'wordBlank' : '',
- ]"
- >
- {{ item[pIndex + 1].chs }}</span
- >
- </span>
- <template v-if="curQue.pyPosition == 'bottom'">
- <span
- v-if="isShowPY"
- :class="[
- 'NNPE-pinyin',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(item[pIndex + 1].pinyin) > -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item[pIndex + 1].pinyin }}</span
- >
- </template>
- </span>
- </template>
- <template v-else>
- <template v-if="curQue.pyPosition == 'top'">
- <span
- v-if="isShowPY"
- class="NNPE-pinyin"
- :class="[
- pItem.padding ? 'padding' : '',
- pItem.className ? pItem.className : '',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </template>
- <span
- class="NNPE-chs"
- :class="[
- pItem.padding && isShowPY ? 'padding' : '',
- sentIndex == index ? 'wordBlank' : '',
- ]"
- >
- <template>
- <span
- v-for="(wItem, wIndex) in pItem.leg"
- :key="'ci' + wIndex + pIndex + index"
- :class="[
- pItem.timeList[wIndex] &&
- curQue.wordTime &&
- curQue.wordTime[index] &&
- curTime >= pItem.timeList[wIndex].wordBg &&
- curTime <= curQue.wordTime[index].ed
- ? 'active'
- : '',
- sentIndex == index ? 'wordBlank' : '',
- ]"
- >{{ pItem.chs[wIndex] }}</span
- >
- </template>
- </span>
- <template v-if="curQue.pyPosition == 'bottom'">
- <span
- v-if="isShowPY"
- class="NNPE-pinyin"
- :class="[
- pItem.padding ? 'padding' : '',
- pItem.className ? pItem.className : '',
- sentIndex == index ? 'wordBlank' : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </template>
- </template>
- </template>
- </template>
- <template v-else>
- <span
- :style="{
- height: pItem.height + 'px',
- width: pItem.width + 'px',
- }"
- ></span>
- </template>
- </div>
- </div>
- <div
- v-show="
- (curQue.wordTime &&
- curQue.wordTime[index] &&
- curTime >= curQue.wordTime[index].bg &&
- curTime <= curQue.wordTime[index].ed) ||
- sentIndex == index
- "
- class="Soundrecord-content"
- >
- <Soundrecord
- @handleWav="handleWav"
- type="promax"
- class="luyin-box"
- @handleParentPlay="handleParentPlay"
- />
- <div>
- <AudioLine
- :mp3="curQue.mp3_list[0].url"
- :getCurTime="getCurTime"
- :ref="'audioLine' + index"
- :audioId="'artPraAudioId' + index"
- :stopAudio="stopAudio"
- :width="555"
- :hideSlider="true"
- :bg="curQue.wordTime[index].bg"
- :ed="curQue.wordTime[index].ed"
- @handleChangeStopAudio="handleChangeStopAudio"
- />
- </div>
- </div>
- </div>
- </div>
- </template>
- </div>
- </template>
- <script>
- import { timeStrToSen } from "@/utils/index";
- import AudioLine from "../AudioLine.vue";
- import Soundrecord from "../../preview/Soundrecord.vue"; // 录音模板
- export default {
- name: "ArticleView",
- props: ["curQue", "noFont"],
- components: {
- AudioLine,
- Soundrecord,
- },
- data() {
- return {
- resObj: null,
- curTime: 0, //单位s
- chsFhList: [",", "。", "“", ":", "》", "《", "?", "!", ";"],
- enFhList: [",", ".", ";", "?", "!", ":", ">", "<"],
- stopAudio: false,
- sentIndex: 0,
- isShowPY: true,
- isRepeat: false,
- currSent: null, //当前句子的时间
- };
- },
- computed: {
- isPlaying: function () {
- let playing = false;
- if (this.$refs.audioLine) {
- playing = this.$refs.audioLine.audio.isPlaying;
- }
- return playing;
- },
- },
- watch: {},
- //方法集合
- methods: {
- pauseOther() {},
- getCurTime(curTime) {
- let _this = this;
- if (_this.isRepeat) {
- let time = curTime * 1000;
- console.log(time, _this.currSent.ed);
- if (time > _this.currSent.ed || time < _this.currSent.bg) {
- _this.curTime = _this.currSent.bg;
- this.$refs.audioLine.onTimeupdateTime(_this.currSent.bg / 1000);
- } else {
- _this.curTime = curTime * 1000;
- }
- } else {
- _this.curTime = curTime * 1000;
- _this.getSentIndex(_this.curTime);
- }
- },
- getSentIndex(curTime) {
- for (let i = 0; i < this.curQue.wordTime.length; i++) {
- let bg = this.curQue.wordTime[i].bg;
- let ed = this.curQue.wordTime[i].ed;
- if (curTime >= bg && curTime <= ed) {
- this.sentIndex = i;
- break;
- }
- }
- },
- handleData() {
- let resArr = [],
- timeArr = [];
- let curQue = JSON.parse(JSON.stringify(this.curQue));
- let wordTimeList = curQue.wordTime;
- curQue.detail.forEach((dItem, dIndex) => {
- dItem.wordsList.forEach((sItem, sIndex) => {
- let sentArr = [];
- sItem.forEach((wItem, wIndex) => {
- let startIndex =
- wIndex == 0
- ? 0
- : sentArr[wIndex - 1].startIndex +
- sentArr[wIndex - 1].chs.length;
- let endIndex =
- wIndex == 0
- ? wItem.chs.length
- : sentArr[wIndex - 1].endIndex + wItem.chs.length;
- // this.judgePad(sItem, wItem, wIndex);
- this.mergeWordSymbol(sItem, wItem, wIndex);
- let obj = {
- paraIndex: dIndex, //段落索引
- sentIndex: sIndex, //在段落中句子索引
- wordIndex: wIndex, //单词的索引
- pinyin: wItem.pinyin,
- chs: wItem.chs,
- padding: true,
- className: wItem.className,
- isShow: wItem.isShow,
- startIndex: startIndex,
- endIndex: endIndex,
- leg: wItem.chs.length,
- timeList: [],
- };
- sentArr.push(obj);
- });
- resArr.push(sentArr);
- });
- timeArr.push(dItem.timeList);
- });
- if (wordTimeList && wordTimeList.length > 0) {
- this.mergeWordTime(resArr, wordTimeList);
- }
- let timeList = [];
- timeArr.forEach((item) => {
- item.forEach((aItem) => {
- if (timeList.indexOf(aItem) < 0) {
- timeList.push(aItem);
- }
- });
- });
- this.resObj = { sentList: resArr, timeList: timeList };
- console.log(this.resObj);
- },
- mergeWordTime(resArr, wordTimeList) {
- resArr.forEach((item, index) => {
- let wordsResultList = wordTimeList[index].wordsResultList;
- item.forEach((wItem) => {
- let startIndex = wItem.startIndex;
- let endIndex = wItem.endIndex;
- wItem.timeList = wordsResultList.slice(startIndex, endIndex);
- });
- });
- },
- //词和标点合一起
- mergeWordSymbol(sItem, wItem, curIndex) {
- let leg = sItem.length;
- if (curIndex < leg - 1) {
- let nextIndex = curIndex + 1;
- if (this.chsFhList.indexOf(wItem.chs) > -1) {
- wItem.isShow = false;
- } else {
- wItem.isShow = true;
- }
- }
- },
- //判断是否有padding
- judgePad(sItem, wItem, curIndex) {
- let leg = sItem.length;
- if (curIndex < leg - 1) {
- let nextIndex = curIndex + 1;
- let chs = sItem[nextIndex].chs;
- if (
- this.chsFhList.indexOf(chs) > -1 ||
- this.chsFhList.indexOf(wItem.chs) > -1
- ) {
- wItem.padding = false;
- } else {
- wItem.padding = true;
- }
- if (this.enFhList.indexOf(wItem.pinyin) > -1) {
- wItem.className = "textLeft";
- }
- }
- },
- //转化时间
- handleTimeList(list) {
- let listRes = [];
- list.forEach((item) => {
- let res = timeStrToSen(item);
- listRes.push(res);
- });
- return listRes;
- },
- //计算总时间
- countWordTime(sentArr) {
- let total = 0;
- sentArr.forEach((item) => {
- total += item.endTime;
- });
- return total;
- },
- //点击播放某个句子
- handleChangeTime(time, index) {
- let _this = this;
- if (this.isRepeat) {
- _this.currSent = _this.curQue.wordTime[index];
- }
- _this.sentIndex = index;
- if (time) {
- _this.curTime = time;
- _this.$refs.audioLine.onTimeupdateTime(time / 1000, true);
- }
- },
- handleWav(data) {},
- // 录音时暂停音频播放
- handleParentPlay() {
- this.stopAudio = true;
- },
- // 音频播放时改变布尔值
- handleChangeStopAudio() {
- this.stopAudio = false;
- },
- //拼音的显示隐藏
- changePinyin() {
- this.isShowPY = !this.isShowPY;
- },
- // 单句是否重复播放
- changeRepeat() {
- let _this = this;
- _this.isRepeat = !_this.isRepeat;
- this.currSent = _this.curQue.wordTime[_this.sentIndex];
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- console.log(this.curQue);
- if (this.curQue) {
- this.handleData();
- }
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='scss' scoped>
- //@import url(); 引入公共css类
- .NNPE-ArticleView {
- width: 100%;
- .NPC-sentences-list {
- padding: 16px 0;
- }
- .aduioLine-content {
- flex: 1;
- }
- .NNPE-detail-box {
- width: 100%;
- box-sizing: border-box;
- margin-bottom: 8px;
- box-sizing: border-box;
- padding: 8px 24px 8px;
- &.active {
- background: rgba(222, 68, 68, 0.15);
- }
- }
- .aduioLine-practice {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .aduioLine-right {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 72px;
- height: 40px;
- box-sizing: border-box;
- padding: 0 12px;
- border-left: 1px solid rgba(0, 0, 0, 0.1);
- > span {
- width: 16px;
- height: 16px;
- cursor: pointer;
- }
- }
- }
- .NNPE-detail {
- clear: both;
- overflow: hidden;
- .NNPE-words {
- float: left;
- &-box {
- float: left;
- > span {
- display: block;
- &.NNPE-pinyin {
- font-family: "GB-PINYINOK-B";
- font-weight: normal;
- font-size: 14px;
- line-height: 20px;
- color: rgba(0, 0, 0, 0.45);
- height: 20px;
- &.noFont {
- font-family: initial;
- }
- &.textLeft {
- text-align: left;
- }
- &.wordBlank {
- color: rgba(0, 0, 0, 0.85);
- }
- }
- &.NNPE-chs {
- font-family: "FZJCGFKTK";
- font-size: 20px;
- line-height: 28px;
- color: rgba(0, 0, 0, 0.45);
- .active {
- color: #de4444;
- }
- &.wordBlank {
- color: rgba(0, 0, 0, 0.85);
- }
- }
- // &.padding {
- // padding-right: 6px;
- // }
- }
- }
- &.textLeft {
- text-align: left;
- }
- &.textCenter {
- text-align: center;
- }
- > span {
- display: block;
- &.NNPE-pinyin {
- font-family: "GB-PINYINOK-B";
- font-weight: normal;
- font-size: 14px;
- line-height: 20px;
- color: rgba(0, 0, 0, 0.45);
- height: 20px;
- &.noFont {
- font-family: initial;
- }
- &.textLeft {
- text-align: left;
- }
- &.wordBlank {
- color: rgba(0, 0, 0, 0.85);
- }
- }
- &.NNPE-chs {
- font-family: "FZJCGFKTK";
- font-size: 20px;
- line-height: 28px;
- color: rgba(0, 0, 0, 0.45);
- .active {
- color: #de4444;
- }
- &.wordBlank {
- color: rgba(0, 0, 0, 0.85);
- }
- }
- &.padding {
- padding: 0 3px;
- }
- }
- }
- }
- .Soundrecord-content {
- margin-top: 8px;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- }
- .luyin-box {
- width: 280px;
- box-sizing: border-box;
- padding: 8px 12px;
- background: #ffffff;
- border: 1px solid rgba(0, 0, 0, 0.1);
- box-sizing: border-box;
- border-radius: 8px;
- height: auto;
- margin-right: 16px;
- }
- }
- </style>
|