PhraseModelChs.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <!-- -->
  2. <template>
  3. <div class="NNPE-ArticleView" v-if="curQue">
  4. <AudioLine
  5. :mp3="curQue.mp3_list[0].url"
  6. :getCurTime="getCurTime"
  7. ref="audioLine"
  8. />
  9. <template v-if="resArr.length > 0">
  10. <div class="NPC-sentences-list">
  11. <div
  12. :class="['NNPE-detail', item.isTitle ? 'NNPE-detail-title' : '']"
  13. v-for="(item, index) in resArr"
  14. :key="'detail' + index"
  15. >
  16. <div class="wordsList-box">
  17. <img :src="articleImg[index]" v-if="articleImg[0] && index == 0" />
  18. <div>
  19. <div
  20. class="NNPE-words"
  21. v-for="(pItem, pIndex) in item.wordsList"
  22. :key="'wordsList' + pIndex"
  23. :class="[pItem.wordIndex == 0 ? 'textLeft' : 'textCenter']"
  24. @click="showWordDetail($event, pItem.chs)"
  25. >
  26. <template v-if="!pItem.width">
  27. <template v-if="pItem.isShow">
  28. <template
  29. v-if="
  30. item.wordsList[pIndex + 1].chs &&
  31. chsFhList.indexOf(item.wordsList[pIndex + 1].chs) > -1
  32. "
  33. >
  34. <span class="NNPE-words-box">
  35. <span
  36. class="NNPE-pinyin"
  37. :class="[pItem.className ? pItem.className : '']"
  38. >{{ pItem.pinyin }}</span
  39. >
  40. <span
  41. :class="[
  42. 'NNPE-chs',
  43. newWordList.indexOf(pItem.chs) > -1 ? 'active' : '',
  44. ]"
  45. >{{ pItem.chs }}</span
  46. >
  47. </span>
  48. <span class="NNPE-words-box">
  49. <span class="NNPE-pinyin" style="text-align: left">{{
  50. item.wordsList[pIndex + 1].pinyin
  51. }}</span>
  52. <span class="NNPE-chs" style="text-align: left">{{
  53. item.wordsList[pIndex + 1].chs
  54. }}</span>
  55. </span>
  56. </template>
  57. <template v-else>
  58. <span
  59. class="NNPE-pinyin"
  60. :class="[
  61. pItem.padding ? 'padding' : '',
  62. pItem.className ? pItem.className : '',
  63. ]"
  64. >{{ pItem.pinyin }}</span
  65. >
  66. <span
  67. class="NNPE-chs"
  68. :class="[
  69. pItem.padding ? 'padding' : '',
  70. newWordList.indexOf(pItem.chs) > -1 ? 'active' : '',
  71. ]"
  72. >{{ pItem.chs }}</span
  73. >
  74. </template>
  75. </template>
  76. </template>
  77. <template v-else>
  78. <span
  79. :style="{
  80. height: pItem.height + 'px',
  81. width: pItem.width + 'px',
  82. }"
  83. ></span>
  84. </template>
  85. </div>
  86. </div>
  87. <img :src="articleImg[index + 1]" v-if="articleImg[index + 1]" />
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <template v-if="isShow">
  93. <div
  94. class="NNPE-wordDetail"
  95. :style="{ top: top + 'px', left: left + 'px' }"
  96. >
  97. <Wordcard :word="word" :changeWordCard="changeWordCard" />
  98. </div>
  99. </template>
  100. </div>
  101. </template>
  102. <script>
  103. import { timeStrToSen } from "@/utils/index";
  104. import AudioLine from "../AudioLine.vue";
  105. import Wordcard from "../components/Wordcard.vue"; // 卡片
  106. export default {
  107. name: "PhraseModelChs",
  108. props: ["curQue", "bodyLeft", "NNPENewWordList"],
  109. components: {
  110. AudioLine,
  111. Wordcard,
  112. },
  113. data() {
  114. return {
  115. resArr: [],
  116. curTime: 0, //单位s
  117. chsFhList: [",", "。", "“", ":", "》", "《", "?", "!", ";"],
  118. enFhList: [",", ".", ";", "?", "!", ":", ">", "<"],
  119. newWords: ["鱼", "辩礼义"],
  120. oldHz: "",
  121. hz: "",
  122. top: 0,
  123. left: 0,
  124. articleImg: {}, // 文章图片
  125. newWordList: [],
  126. word: null,
  127. isShow: false,
  128. };
  129. },
  130. computed: {},
  131. watch: {
  132. hz: {
  133. handler: function (val, oldVal) {
  134. let _this = this;
  135. if (val) {
  136. _this.handleNewWords(val, _this.top, _this.left);
  137. }
  138. },
  139. // 深度观察监听
  140. deep: true,
  141. },
  142. },
  143. //方法集合
  144. methods: {
  145. getCurTime(curTime) {
  146. this.curTime = curTime;
  147. },
  148. handleData() {
  149. let resArr = [];
  150. let leg = this.curQue.detail.length;
  151. let curQue = JSON.parse(JSON.stringify(this.curQue));
  152. curQue.detail.forEach((dItem, dIndex) => {
  153. let paraArr = [
  154. {
  155. pinyin: "",
  156. chs: "",
  157. width: 20,
  158. height: 20,
  159. },
  160. {
  161. width: 20,
  162. height: 20,
  163. pinyin: "",
  164. chs: "",
  165. },
  166. ];
  167. dItem.wordsList.forEach((sItem, sIndex) => {
  168. sItem.forEach((wItem, wIndex) => {
  169. //this.judgePad(sItem, wItem, wIndex);
  170. this.mergeWordSymbol(sItem, wItem, wIndex);
  171. let obj = {
  172. paraIndex: dIndex, //段落索引
  173. sentIndex: sIndex, //在段落中句子索引
  174. wordIndex: wIndex, //单词的索引
  175. pinyin: wItem.pinyin,
  176. chs: wItem.chs,
  177. padding: true, //wItem.padding,
  178. className: wItem.className,
  179. isShow: wItem.isShow,
  180. isNewWord: this.newWords.indexOf(wItem.chs) > -1 ? true : false,
  181. };
  182. paraArr.push(obj);
  183. });
  184. });
  185. let paraObj = {
  186. wordsList: paraArr,
  187. };
  188. resArr.push(paraObj);
  189. });
  190. this.resArr = resArr;
  191. console.log(this.resArr);
  192. // 循环文章图片
  193. if (curQue.img_list) {
  194. curQue.img_list.forEach((item) => {
  195. this.articleImg[item.imgNumber] = item.url;
  196. });
  197. }
  198. },
  199. //词和标点合一起
  200. mergeWordSymbol(sItem, wItem, curIndex) {
  201. let leg = sItem.length;
  202. if (curIndex < leg - 1) {
  203. let nextIndex = curIndex + 1;
  204. let chs = sItem[nextIndex].chs;
  205. let pinyin = sItem[nextIndex].pinyin;
  206. // if (this.chsFhList.indexOf(chs) > -1) {
  207. // wItem.chs = "<a>" + wItem.chs + "</a><a>" + chs + "</a>";
  208. // wItem.pinyin = "<a>" + wItem.pinyin + "</a><a>" + pinyin + "</a>";
  209. // }
  210. if (this.chsFhList.indexOf(wItem.chs) > -1) {
  211. wItem.isShow = false;
  212. } else {
  213. wItem.isShow = true;
  214. }
  215. }
  216. // if (this.enFhList.indexOf(wItem.pinyin) > -1) {
  217. // wItem.className = "textLeft";
  218. // }
  219. },
  220. //判断是否有padding
  221. judgePad(sItem, wItem, curIndex) {
  222. let leg = sItem.length;
  223. if (curIndex < leg - 1) {
  224. let nextIndex = curIndex + 1;
  225. let chs = sItem[nextIndex].chs;
  226. if (
  227. this.chsFhList.indexOf(chs) > -1 ||
  228. this.chsFhList.indexOf(wItem.chs) > -1
  229. ) {
  230. wItem.padding = false;
  231. } else {
  232. wItem.padding = true;
  233. }
  234. if (this.enFhList.indexOf(wItem.pinyin) > -1) {
  235. wItem.className = "textLeft";
  236. }
  237. }
  238. },
  239. //转化时间
  240. handleTimeList(list) {
  241. let listRes = [];
  242. list.forEach((item) => {
  243. let res = timeStrToSen(item);
  244. listRes.push(res);
  245. });
  246. return listRes;
  247. },
  248. //点击播放某个句子
  249. handleChangeTime(time) {
  250. this.curTime = time;
  251. this.$refs.audioLine.onTimeupdateTime(time);
  252. },
  253. handleNewword() {
  254. let NewWordList = [];
  255. this.NNPENewWordList.forEach((item) => {
  256. NewWordList.push(item.new_word);
  257. });
  258. this.newWordList = JSON.parse(JSON.stringify(NewWordList));
  259. },
  260. showWordDetail(e, word) {
  261. let _this = this;
  262. if (_this.oldHz != word) {
  263. this.isShow = false;
  264. setTimeout(() => {
  265. _this.hz = word;
  266. }, 50);
  267. }
  268. _this.top = e.clientY + 20;
  269. let left = e.clientX;
  270. let width = 0;
  271. if (word.length == 1 || word.length == 2) {
  272. width = 304;
  273. } else if (word.length == 3 || word.length == 4) {
  274. width = 432;
  275. } else if (word.length > 3) {
  276. width = 560;
  277. }
  278. if (left - this.bodyLeft > this.contentWidth / 2) {
  279. _this.left = left - width;
  280. } else {
  281. _this.left = left;
  282. }
  283. },
  284. hideWordDetail() {
  285. this.isShow = false;
  286. },
  287. changeWordCard(isShow) {
  288. this.isShow = isShow;
  289. this.oldHz = "";
  290. this.hz = "";
  291. },
  292. // 处理分词数据
  293. handleNewWords(val, top, left) {
  294. debugger;
  295. this.isShow = true;
  296. this.word = null;
  297. for (let i = 0; i < this.NNPENewWordList.length; i++) {
  298. let item = this.NNPENewWordList[i];
  299. if (item.new_word.trim() == val.trim()) {
  300. let wordlist = val.split("");
  301. this.word = { list: wordlist, detail: item, top: top, left: left };
  302. break;
  303. }
  304. }
  305. this.oldHz = val;
  306. },
  307. },
  308. //生命周期 - 创建完成(可以访问当前this实例)
  309. created() {},
  310. //生命周期 - 挂载完成(可以访问DOM元素)
  311. mounted() {
  312. console.log(this.curQue);
  313. if (this.curQue) {
  314. this.handleData();
  315. }
  316. console.log("生词");
  317. console.log(this.NNPENewWordList);
  318. if (this.NNPENewWordList && this.NNPENewWordList.length > 0) {
  319. this.handleNewword();
  320. }
  321. },
  322. beforeCreate() {}, //生命周期 - 创建之前
  323. beforeMount() {}, //生命周期 - 挂载之前
  324. beforeUpdate() {}, //生命周期 - 更新之前
  325. updated() {}, //生命周期 - 更新之后
  326. beforeDestroy() {}, //生命周期 - 销毁之前
  327. destroyed() {}, //生命周期 - 销毁完成
  328. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  329. };
  330. </script>
  331. <style lang='scss' scoped>
  332. //@import url(); 引入公共css类
  333. .NNPE-ArticleView {
  334. width: 100%;
  335. .NPC-sentences-list {
  336. padding: 24px 0;
  337. }
  338. .NNPE-detail {
  339. clear: both;
  340. overflow: hidden;
  341. .NNPE-words {
  342. float: left;
  343. padding: 0 0px 8px 0px;
  344. &-box {
  345. float: left;
  346. > span {
  347. display: block;
  348. &.NNPE-pinyin {
  349. font-family: "GB-PINYINOK-B";
  350. font-weight: normal;
  351. font-size: 14px;
  352. line-height: 150%;
  353. color: #000000;
  354. height: 21px;
  355. &.textLeft {
  356. text-align: left;
  357. }
  358. }
  359. &.NNPE-chs {
  360. font-family: "FZJCGFKTK";
  361. font-size: 24px;
  362. line-height: 150%;
  363. color: #000000;
  364. &.active {
  365. color: #e35454;
  366. }
  367. }
  368. &.padding {
  369. padding: 0 3px;
  370. }
  371. }
  372. }
  373. &.textLeft {
  374. text-align: left;
  375. }
  376. &.textCenter {
  377. text-align: center;
  378. }
  379. > span {
  380. display: block;
  381. &.NNPE-pinyin {
  382. font-family: "GB-PINYINOK-B";
  383. font-weight: normal;
  384. font-size: 14px;
  385. line-height: 150%;
  386. color: #000000;
  387. height: 21px;
  388. &.textLeft {
  389. text-align: left;
  390. }
  391. }
  392. &.NNPE-chs {
  393. font-family: "FZJCGFKTK";
  394. font-size: 24px;
  395. line-height: 150%;
  396. color: #000000;
  397. &.active {
  398. color: #e35454;
  399. }
  400. }
  401. &.padding {
  402. padding: 0 3px;
  403. }
  404. }
  405. }
  406. &.NNPE-detail-title {
  407. .wordsList-box {
  408. > div {
  409. display: flex;
  410. justify-content: center;
  411. }
  412. }
  413. }
  414. .index {
  415. width: 48px;
  416. box-sizing: border-box;
  417. padding: 8px;
  418. text-align: right;
  419. border-right: 1px solid rgba(0, 0, 0, 0.1);
  420. b {
  421. font-weight: 400;
  422. color: #000000;
  423. line-height: 1.5;
  424. }
  425. }
  426. .wordsList-box {
  427. width: 100%;
  428. padding: 6px 24px 12px 24px;
  429. > div {
  430. overflow: hidden;
  431. clear: both;
  432. }
  433. > img {
  434. width: 100%;
  435. display: block;
  436. }
  437. }
  438. }
  439. .NNPE-wordDetail {
  440. position: fixed;
  441. // width: 260px;
  442. // height: 200px;
  443. // background: #cc0;
  444. }
  445. }
  446. </style>