123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685 |
- <!-- -->
- <template>
- <div class="NNPE-ArticleView" v-if="curQue">
- <div class="aduioLine-box aduioLine-practice-npc" v-if="
- curQue.mp3_list &&
- curQue.mp3_list.length > 0 &&
- curQue.mp3_list[0].id
- ">
- <div class="aduioLine-content">
- <template
- v-if="
- curQue.mp3_list &&
- curQue.mp3_list.length > 0 &&
- curQue.mp3_list[0].id
- "
- >
- <AudioLine
- audioId="artPhraseAudio"
- :mp3="curQue.mp3_list[0].id"
- :getCurTime="getCurTime"
- :mp3Source="curQue.mp3_list[0].source"
- :width="590"
- ref="audioLine"
- />
- </template>
- </div>
- <div class="aduioLine-right">
- <span
- :class="['pinyin-16', config.isShowPY ? '' : 'disabled']"
- @click="changePinyin"
- ></span>
- <span
- :class="['EN-16', config.isShowEN ? '' : 'disabled']"
- @click="changeEN"
- ></span>
- </div>
- </div>
- <template v-if="resArr.length > 0">
- <div class="NPC-sentences-list">
- <div
- :class="['NNPE-detail', item.isTitle ? 'NNPE-detail-title' : '']"
- v-for="(item, index) in resArr"
- :key="'detail' + index"
- >
- <div class="wordsList-box">
- <img :src="articleImg[index]" v-if="articleImg[0] && index == 0" />
- <div>
- <div
- class="NNPE-words"
- v-for="(pItem, pIndex) in item.wordsList"
- :key="'wordsList' + pIndex"
- :class="[
- pItem.chs != '“' && pItem.wordIndex == 0
- ? 'textLeft'
- : 'textCenter',
- pItem.chs == '“' ? 'textRight' : '',
- ]"
- @click="showWordDetail($event, pItem.chs)"
- >
- <template v-if="!pItem.width">
- <template v-if="pItem.isShow">
- <template
- v-if="
- item.wordsList[pIndex + 1] &&
- item.wordsList[pIndex + 1].chs &&
- chsFhList.indexOf(item.wordsList[pIndex + 1].chs) > -1
- "
- >
- <span class="NNPE-words-box">
- <span
- v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
- :class="[
- 'NNPE-pinyin',
- pItem.className ? pItem.className : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- <span
- :class="[
- 'NNPE-chs',
- newWordList.indexOf(pItem.chs) > -1 ? 'active' : '',
- ]"
- >{{ pItem.chs }}</span
- >
- <span
- v-if="
- curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
- "
- :class="[
- 'NNPE-pinyin',
- pItem.className ? pItem.className : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </span>
- <span class="NNPE-words-box">
- <span
- v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
- :class="[
- 'NNPE-pinyin',
- noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
- -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item.wordsList[pIndex + 1].pinyin }}</span
- >
- <span class="NNPE-chs" style="text-align: left">{{
- item.wordsList[pIndex + 1].chs
- }}</span>
- <span
- v-if="
- curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
- "
- :class="[
- 'NNPE-pinyin',
- noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
- -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item.wordsList[pIndex + 1].pinyin }}</span
- >
- </span>
- <span
- class="NNPE-words-box"
- v-if="
- item.wordsList[pIndex + 2] &&
- item.wordsList[pIndex + 2].chs &&
- chsFhList.indexOf(item.wordsList[pIndex + 2].chs) > -1
- "
- >
- <span
- v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
- :class="[
- 'NNPE-pinyin',
- noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
- -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item.wordsList[pIndex + 2].pinyin }}</span
- >
- <span class="NNPE-chs" style="text-align: left">{{
- item.wordsList[pIndex + 2].chs
- }}</span>
- <span
- v-if="
- curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
- "
- :class="[
- 'NNPE-pinyin',
- noFont.indexOf(item.wordsList[pIndex + 2].pinyin) >
- -1
- ? 'noFont'
- : '',
- ]"
- style="text-align: left"
- >{{ item.wordsList[pIndex + 2].pinyin }}</span
- >
- </span>
- </template>
- <template v-else>
- <span
- v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
- class="NNPE-pinyin"
- :class="[
- pItem.chs != '“' && pItem.padding ? 'padding' : '',
- pItem.className ? pItem.className : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- <span
- class="NNPE-chs"
- :class="[
- pItem.chs != '“' && pItem.padding ? 'padding' : '',
- newWordList.indexOf(pItem.chs) > -1 ? 'active' : '',
- ]"
- >{{ pItem.chs }}</span
- >
- <span
- v-if="curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin"
- class="NNPE-pinyin"
- :class="[
- pItem.chs != '“' && pItem.padding ? 'padding' : '',
- pItem.className ? pItem.className : '',
- noFont.indexOf(pItem.pinyin) > -1 ? 'noFont' : '',
- ]"
- >{{ pItem.pinyin }}</span
- >
- </template>
- </template>
- </template>
- <template v-else>
- <span
- :style="{
- height: pItem.height + 'px',
- width: pItem.width + 'px',
- }"
- ></span>
- </template>
- </div>
- </div>
- <img :src="articleImg[index + 1]" v-if="articleImg[index + 1]" />
- </div>
- </div>
- </div>
- </template>
- <template v-if="isShow">
- <div
- ref="wordcard"
- class="NNPE-wordDetail"
- :style="{ top: top + 'px', left: left + 'px' }"
- >
- <Wordcard
- :word="word"
- :changeWordCard="changeWordCard"
- :themeColor="themeColor"
- :currentTreeID="currentTreeID"
- :TaskModel="TaskModel"
- :writeList="curQue.Bookanswer.writeModel"
- @changeCurQue="changeCurQue"
- />
- </div>
- </template>
- </div>
- </template>
- <script>
- import { timeStrToSen } from "../../../../utils/index";
- import AudioLine from "../AudioLine.vue";
- import Wordcard from "../components/Wordcard.vue"; // 卡片
- export default {
- name: "PhraseModelChs",
- props: [
- "curQue",
- "bodyLeft",
- "NNPENewWordList",
- "themeColor",
- "noFont",
- "currentTreeID",
- "config",
- "TaskModel",
- ],
- components: {
- AudioLine,
- Wordcard,
- },
- data() {
- return {
- resArr: [],
- curTime: 0, //单位s
- chsFhList: [",", "。", "”", ":", "》", "《", "?", "!", ";"],
- enFhList: [",", ".", ";", "?", "!", ":", ">", "<"],
- newWords: ["鱼", "辩礼义"],
- oldHz: "",
- hz: "",
- clientY: 0,
- top: 0,
- left: 0,
- articleImg: {}, // 文章图片
- newWordList: [],
- word: null,
- isShow: false,
- screenHeight: 0,
- cardHeight: 0,
- contentWidth: 732,
- };
- },
- computed: {},
- watch: {
- hz: {
- handler: function (val, oldVal) {
- let _this = this;
- if (val) {
- _this.handleNewWords(val);
- }
- },
- // 深度观察监听
- deep: true,
- },
- isShow: {
- handler: function (val, oldVal) {
- let _this = this;
- if (val) {
- setTimeout(() => {
- _this.cardHeight = _this.$refs.wordcard.offsetHeight;
- if (_this.screenHeight - _this.clientY > _this.cardHeight) {
- _this.top = _this.clientY + 20;
- } else {
- _this.top = _this.clientY - _this.cardHeight - 30;
- }
- }, 0);
- }
- },
- // 深度观察监听
- deep: true,
- },
- },
- //方法集合
- methods: {
- //拼音的显示和隐藏
- changePinyin() {
- if (this.config.isHasPY) {
- this.$emit("changeConfig", "isShowPY");
- }
- },
- // 英文的显示和隐藏
- changeEN() {
- if (this.config.isHasEN) {
- this.$emit("changeConfig", "isShowEN");
- }
- },
- getCurTime(curTime) {
- this.curTime = curTime;
- },
- handleData() {
- let resArr = [];
- let leg = this.curQue.detail.length;
- let curQue = JSON.parse(JSON.stringify(this.curQue));
- let dhaspinyin = false; // 每段是否有拼音
- curQue.detail.forEach((dItem, dIndex) => {
- dhaspinyin = false
- let paraArr = [
- {
- pinyin: "",
- chs: "",
- width: 20,
- height: 20,
- },
- {
- width: 20,
- height: 20,
- pinyin: "",
- chs: "",
- },
- ];
- dItem.wordsList.forEach((sItem, sIndex) => {
- sItem.forEach((wItem, wIndex) => {
- //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, //wItem.padding,
- className: wItem.className,
- isShow: wItem.isShow,
- isNewWord: this.newWords.indexOf(wItem.chs) > -1 ? true : false,
- };
- paraArr.push(obj);
- if(wItem.pinyin) dhaspinyin=true
- });
- });
- let paraObj = {
- wordsList: paraArr,
- dhaspinyin:dhaspinyin
- };
- resArr.push(paraObj);
- });
- this.resArr = resArr;
- // 循环文章图片
- if (curQue.img_list) {
- curQue.img_list.forEach((item) => {
- this.articleImg[item.imgNumber] = item.id;
- });
- }
- },
- //词和标点合一起
- mergeWordSymbol(sItem, wItem, curIndex) {
- let leg = sItem.length;
- if (curIndex < leg - 1) {
- let nextIndex = curIndex + 1;
- let chs = sItem[nextIndex].chs;
- let pinyin = sItem[nextIndex].pinyin;
- // if (this.chsFhList.indexOf(chs) > -1) {
- // wItem.chs = "<a>" + wItem.chs + "</a><a>" + chs + "</a>";
- // wItem.pinyin = "<a>" + wItem.pinyin + "</a><a>" + pinyin + "</a>";
- // }
- if (this.chsFhList.indexOf(wItem.chs) > -1) {
- wItem.isShow = false;
- } else {
- wItem.isShow = true;
- }
- }
- // if (this.enFhList.indexOf(wItem.pinyin) > -1) {
- // wItem.className = "textLeft";
- // }
- },
- //判断是否有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;
- },
- //点击播放某个句子
- handleChangeTime(time) {
- this.curTime = time;
- this.$refs.audioLine.onTimeupdateTime(time);
- },
- handleNewword() {
- let NewWordList = [];
- this.NNPENewWordList.forEach((item) => {
- item.forEach((wItem) => {
- NewWordList.push(wItem.new_word);
- });
- });
- this.newWordList = JSON.parse(JSON.stringify(NewWordList));
- },
- showWordDetail(e, word) {
- let _this = this;
- if (this.newWordList.indexOf(word) > -1) {
- if (_this.oldHz != word) {
- this.isShow = false;
- setTimeout(() => {
- _this.hz = word;
- }, 50);
- }
- _this.clientY = e.clientY;
- let left = e.clientX;
- let width = 0;
- if (word.length == 1 || word.length == 2) {
- width = 304;
- } else if (word.length == 3 || word.length == 4) {
- width = 432;
- } else if (word.length > 3) {
- width = 560;
- }
- if (left - this.bodyLeft > this.contentWidth / 2) {
- _this.left = left - width + 10;
- } else {
- _this.left = left;
- }
- }
- },
- hideWordDetail() {
- this.isShow = false;
- },
- changeWordCard(isShow) {
- this.isShow = isShow;
- this.oldHz = "";
- this.hz = "";
- },
- // 处理分词数据
- handleNewWords(val, top, left) {
- this.isShow = true;
- this.word = null;
- for (let i = 0; i < this.NNPENewWordList.length; i++) {
- let pItem = this.NNPENewWordList[i];
- for (let j = 0; j < pItem.length; j++) {
- let item = pItem[j];
- if (item.new_word.trim() == val.trim()) {
- let wordlist = val.split("");
- this.word = { list: wordlist, detail: item, top: top, left: left };
- break;
- }
- }
- }
- this.oldHz = val;
- },
- getScreenHeight() {
- this.screenHeight = window.innerHeight;
- },
- changeCurQue(answer) {
- if (answer) {
- let writeModel = this.curQue.Bookanswer.writeModel;
- let hz = answer.hz;
- if (writeModel.hasOwnProperty(hz)) {
- writeModel[hz].push(answer);
- } else {
- writeModel[hz] = [answer];
- }
- console.log(this.curQue.Bookanswer);
- }
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- if (this.curQue) {
- this.handleData();
- }
- if (this.NNPENewWordList && this.NNPENewWordList.length > 0) {
- this.handleNewword();
- }
- $(window).resize(() => {
- this.getScreenHeight();
- });
- this.getScreenHeight();
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='scss' scoped>
- //@import url(); 引入公共css类
- .NNPE-ArticleView {
- width: 100%;
- .aduioLine-practice-npc {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .aduioLine-content {
- flex: 1;
- }
- .aduioLine-right {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 69px;
- 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;
- }
- }
- }
- .NPC-sentences-list {
- padding: 24px 0;
- }
- .NNPE-detail {
- clear: both;
- overflow: hidden;
- color: rgba(0, 0, 0, 0.65);
- .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: 22px;
- &.noFont {
- font-family: initial;
- }
- height: 21px;
- &.textLeft {
- text-align: left;
- }
- }
- &.NNPE-chs {
- font-family: "FZJCGFKTK";
- font-size: 20px;
- line-height: 28px;
- &.active {
- color: #de4444;
- }
- }
- &.padding {
- padding: 0 3px;
- }
- }
- }
- &.textLeft {
- text-align: left;
- }
- &.textCenter {
- text-align: center;
- }
- &.textRight {
- text-align: right;
- }
- > span {
- display: block;
- &.NNPE-pinyin {
- font-family: "GB-PINYINOK-B";
- font-weight: normal;
- font-size: 14px;
- line-height: 22px;
- height: 21px;
- &.noFont {
- font-family: initial;
- }
- &.textLeft {
- text-align: left;
- }
- }
- &.NNPE-chs {
- font-family: "FZJCGFKTK";
- font-size: 20px;
- line-height: 28px;
- &.active {
- color: #de4444;
- }
- }
- &.padding {
- padding: 0 3px;
- }
- }
- }
- &.NNPE-detail-title {
- .wordsList-box {
- > div {
- display: flex;
- justify-content: center;
- }
- }
- }
- .index {
- width: 48px;
- box-sizing: border-box;
- padding: 8px;
- text-align: right;
- border-right: 1px solid rgba(0, 0, 0, 0.1);
- b {
- font-weight: 400;
- color: #000000;
- line-height: 1.5;
- }
- }
- .wordsList-box {
- width: 100%;
- padding: 6px 24px 12px 24px;
- > div {
- overflow: hidden;
- clear: both;
- }
- > img {
- max-width: 100%;
- display: block;
- margin: 0 auto;
- }
- }
- }
- .NNPE-wordDetail {
- position: fixed;
- z-index: 9999;
- // width: 260px;
- // height: 200px;
- // background: #cc0;
- }
- }
- </style>
|