From 1c389a5a5c22c8d57ee79cc9ac8ed6db6c8dbadc Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 04 六月 2024 18:01:59 +0800 Subject: [PATCH] 搜素优化 --- src/books/childHealth/view/index.vue | 416 ++++++----------------------------------------------------- 1 files changed, 45 insertions(+), 371 deletions(-) diff --git a/src/books/childHealth/view/index.vue b/src/books/childHealth/view/index.vue index 03fd85d..d96b1af 100644 --- a/src/books/childHealth/view/index.vue +++ b/src/books/childHealth/view/index.vue @@ -1,373 +1,21 @@ <template> <div class="temp-book" @mouseup="handleMouseUp"> - <pageHeader></pageHeader> <pageContent></pageContent> </div> </template> <script> -import examinations from "./components/examinations/index.vue"; -import { getPublicImage } from "@/assets/js/middleGround/tool"; -import pageHeader from "./header/index.vue"; import pageContent from "./content/index.vue"; export default { - name: "temp-book", components: { - pageHeader, pageContent, - examinations, }, data() { - return { - type: "option", - idPathList: [], - cardList: [], - }; + return {}; }, - mounted() { - this.getBookInfo(); - }, - methods: { - getBookInfo() { - let query = { - path: "*", - queryType: "*", - productId: this.config.bookId, - favoriteTypes: "FavoriteBookCity", - itemFields: { - "SysType=": "CmsFolder", - }, - coverSize: { - height: 300, - }, - fields: { - seriesName: [], - author: [], - isbn: [], - publicationDate: [], - bookClassification: [], - paperPrice: [], - JDLink: [], - tmallLink: [], - dangdangLink: [], - weidianLink: [], - content: [], - authorIntroduction: [], - // isApplyPaperBook: [], - // isApplyEBook: [], - isApplyBook: [], - isSell: [], - pdf: [], - protectedEpub: [], - probationPage: [], //pdf璇曡椤垫暟 - freeEpubPage: [], //epub璇曡鐧惧垎姣� - }, - }; - this.MG.store.getProductDetail(query).then((res) => { - console.log("鍥句功淇℃伅", res.datas.cmsDatas[0].datas); - const testData = res.datas.cmsDatas[0].datas.find( - (item) => item.refCode == "questionBank" - ); - this.getResourceData(testData); - }); - }, - getResourceData(type) { - let query = { - path: "*", - queryType: "*", - productId: this.config.bookId, - cmsPath: type.productLinkPath, - itemFields: { - SysType: "CmsFolder", - // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁� - selectType: [], - freeFile: [], - file: [], - protectedFile: [], - resourcesClassification: [], - isDownload: [], - jsek_resourceBrief: [], - jsek_link: [], - jsek_questionBank: [], - }, - pading: { - start: 0, - size: 999, - }, - }; - this.MG.store - .getProductDetail(query) - .then(async (res) => { - if (type.refCode == "questionBank") { - const data = res.datas.cmsDatas[0].datas.filter( - (item) => item.refCode == "jsek_questionBank" - ); - if (data.length) return this.getResourceData(data[0]); - } - if (type.refCode == "jsek_questionBank") { - const testDataList = res.datas.cmsDatas[0].datas; - if (testDataList.length > 0) { - // console.log("棰樼洰鍒楄〃", testDataList); - this.$store.commit("setTestList", testDataList); - // this.getIdPathList(testDataList[1]) - } else { - console.log("鏆傛棤璧勬簮"); - } - } - }) - .catch((e) => { - console.log(e); - }); - }, - getIdPathList(data) { - let query = { - path: "*", - queryType: "*", - productId: this.config.bookId, - cmsPath: data.productLinkPath, - pading: { - start: 0, - size: 999, - }, - }; - this.MG.store.getProductDetail(query).then((res) => { - console.log("棰樼洰", res.datas.cmsDatas[0].datas); - this.$data.idPathList = res.datas.cmsDatas[0].datas; - this.getQuestionList(); - }); - }, - // 鑾峰彇棰樺簱棰樼洰 - getQuestionList(oldData) { - // 娓呯┖姝g‘棰樻暟璁板綍 - let flag = 0; - for (let index = 0; index < this.$data.idPathList.length; index++) { - const pathitem = this.$data.idPathList[index]; - const pathList = this.$data.cardList; - pathList.push({ - path: pathitem.productLinkPath, - catalogName: pathitem.name, - infoList: [], - }); - this.$data.cardList = pathList; - // 鑾峰彇棰樼洰 - let query = { - path: "*", - queryType: "*", - productId: this.config.bookId, - cmsPath: pathitem.productLinkPath, - itemFields: { - Embedded_QuestionBank_Stem: [], - Embedded_QuestionBank_AnalysisCon: [], - Embedded_QuestionBank_Answer: [], - Embedded_QuestionBank_Option: [], - Embedded_QuestionBank_QuestionType: [], - Embedded_QuestionBank_StemStyle: [], - Embedded_QuestionBank_OptionStyle: [], - Embedded_QuestionBank_KnowledgePoint: [], - Embedded_QuestionBank_Difficulty: [], - }, - pading: { - start: 0, - size: 999, - }, - }; - this.MG.store.getProductDetail(query).then((res) => { - let oldList; - if (oldData) { - // 鎻愪氦杩囷紝瀛樺湪绛旈璁板綍 - oldList = oldData.find( - (item) => item.path == pathitem.productLinkPath - ).infoList; - this.setData({ - submitStatus: true, - }); - } - res.datas.cmsDatas[0].datas.forEach((item, index) => { - let oldObj = ""; - if (oldList) - oldObj = oldList.find((oldItem) => oldItem.id == item.id); - let questionObj = { - // num: index, // 棰樺彿 - id: item.id, - type: pathitem.name, - stem: - item.Embedded_QuestionBank_QuestionType == "completion" - ? JSON.parse(item.Embedded_QuestionBank_Stem) - .stemTxt.replaceAll("<vacancy>", ",input,") - .split(",") - : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共 - answer: item.Embedded_QuestionBank_Answer, // 绛旀 - option: item.Embedded_QuestionBank_Option - ? JSON.parse(item.Embedded_QuestionBank_Option) - : "", // 閫夋嫨棰橀�夐」 - analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽 - questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷 - optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷 - stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷 - difficulty: item.Embedded_QuestionBank_Difficulty - ? 4 - item.Embedded_QuestionBank_Difficulty - : 0, // 闅惧害绛夌骇 - userAnswer: oldObj - ? oldObj.userAnswer - : item.Embedded_QuestionBank_QuestionType == "completion" || - item.Embedded_QuestionBank_QuestionType == "multipleChoice" - ? [] - : "", - isUserAnswer: oldObj - ? this.isHaveAnswer(oldObj.userAnswer) - : false, - isRight: oldObj ? oldObj.isRight : null, - isComplete: oldObj ? oldObj.isComplete : false, - isCollect: false, - isUnfold: "", // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮� - }; - // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 - if ( - questionObj.questionType == "completion" || - questionObj.questionType == "multipleChoice" - ) { - try { - questionObj.answer = JSON.parse(questionObj.answer).toString(); - } catch (error) { - questionObj.answer = item.Embedded_QuestionBank_Answer; - } - } - // 濉┖棰樻敼閫� - if (questionObj.questionType == "completion") { - let index = 0; - for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i]; - if (item == "input") { - questionObj.stem[i] = { - num: index, - data: "input", - }; - if (!oldObj) questionObj.userAnswer[index] = ""; - index++; - } - } - } - // 棰樺共瀵屾枃鏈鐞� - if (questionObj.stemStyle == "RichText") { - // questionObj.option.txt = '' - questionObj.stem.stemTxt = questionObj.stem.stemTxt - .replace( - /\<img/gi, - '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' - ) - .replace(/\<p/gi, '<p class="stem-rich-p"') - .replace("../file", app.config.requestCtx + "/file"); - } - // 閫夐」瀵屾枃鏈鐞� - if ( - questionObj.optionStyle == "RichText" && - (questionObj.questionType == "singleChoice" || - questionObj.questionType == "judge" || - questionObj.questionType == "multipleChoice") - ) { - questionObj.option.forEach((item) => { - if (item.txt) - item.txt = item.txt - .replace(/\<img/gi, '<img class="option-rich-img"') - .replace(/\<p/gi, '<p class="stem-rich-p"') - .replace("../file", app.config.requestCtx + "/file"); - }); - } - // 瑙f瀽瀵屾枃鏈鐞� - if ( - questionObj.analysisCon && - typeof questionObj.analysisCon == "string" - ) { - questionObj.analysisCon = questionObj.analysisCon.replace( - /\<img/gi, - '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' - ); - } - // 鍚姏棰樹慨鏀� - // if (questionObj.questionType == 'singleChoice') { - // const src = this.extractSourceSrc(questionObj.stem.stemTxt) - // if (src) { - // questionObj.src = src - // questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) - // } - // } - // 鑾峰彇鍥剧墖 - if ( - questionObj.stemStyle == "Image" || - questionObj.stemStyle == "TxtAndImage" - ) { - questionObj.stem.stemImage = getPublicImage( - questionObj.stem.stemImage, - 150 - ); - } - if ( - questionObj.optionStyle == "Image" || - questionObj.optionStyle == "TxtAndImage" - ) { - questionObj.option.forEach((optionItem) => { - if (optionItem.img) - optionItem.img = getPublicImage(optionItem.img, 150); - }); - } - // 瀹㈣棰樻�诲垎璧嬪�� - if (questionObj.questionType !== "shortAnswer") { - // this.setData({ - // subjectiveGrade: this.data.subjectiveGrade + 2, - // }); - } - // 鏃ф暟鎹噷 棰樼洰姝g‘ 璁板綍姝g‘鏁伴噺 - if (questionObj.isRight) { - // this.setData({ - // correctNum: this.data.correctNum + 1, - // }); - } - if ( - pathitem.name == "鍒ゆ柇棰�" || - pathitem.name == "濉┖棰�" || - pathitem.name == "澶氶�夐" || - pathitem.name == "鍗曢�夐" || - pathitem.name == "鍚姏棰�" - ) { - if (oldObj) { - // this.setData({ - // subjectiveTotal: this.data.subjectiveTotal + 1, - // }); - } - } - // cardList璧嬪�� - let cardIndex = this.$data.cardList.findIndex( - (item) => item.path == pathitem.productLinkPath - ); - let infoList = this.$data.cardList[cardIndex].infoList; - infoList.push(questionObj); - // this.setData({ - // [`cardList[${cardIndex}].infoList`]: infoList, - // }); - this.$data.cardList[cardIndex].infoList = infoList; - flag++; - let questionList = []; - let grade = 0; - const cardUpdatedList = this.$data.cardList; - // if (flag == this.data.idPathList.length) { - cardUpdatedList.forEach((aitem) => { - aitem.infoList.forEach((bitem, bindex) => { - questionList.push(bitem); - bitem.number = bindex + 1; - bitem.score = 2; - }); - }); - // this.setData({ - // questionDataList: questionList, - // cardList: cardUpdatedList, - // }); - this.$data.cardList = cardUpdatedList; - console.log("棰樼洰鍛�", this.$data.cardList); - }); - }); - } - }, + mounted() {}, + methods: { getParentWithClass(element, className) { while (element.parentElement) { element = element.parentElement; @@ -377,25 +25,51 @@ } }, handleMouseUp(e) { - const txt = window.getSelection()?.toString(); - const node = window.getSelection(); - let html = node.anchorNode.parentNode.parentNode.parentNode; - let nextHtml = html.firstChild.innerHTML; - let pageHtml = this.getParentWithClass(node.anchorNode,'page-box') - if (txt) { - console.log(pageHtml); - } - if (html) { - const page = html.getAttribute("page"); - console.log("page", page,this.$actions); - this.$actions.setGlobalState({ - aa:page - }) - + const selection = ( + this.container ? this.container : window + ).getSelection(); + const txt = selection.toString(); + if (selection.type != "none" && txt) { + let node = selection.anchorNode.parentNode; + let pageHtml = this.getParentWithClass( + selection.anchorNode, + "page-box" + ); + let chapterDom = this.getParentWithClass( + selection.anchorNode, + "chapter" + ); + let chapterNum; + if (chapterDom) chapterNum = chapterDom.getAttribute("num"); + if (pageHtml) { + const page = pageHtml.getAttribute("page"); + // 鐩戝惉閫変腑鏂囨湰浜嬩欢锛屽苟瑙﹀彂鐖跺眰鏂规硶 + if (this.$store.state.qiankun.windowSelection) { + this.$store.state.qiankun.windowSelection({ + chapterNum, + txt, + page, + x: e.x, + y: e.y, + }); + } + } + } else { + if (this.$store.state.qiankun.windowSelection) { + this.$store.state.qiankun.windowSelection({ + chapterNum: "", + txt: "", + page: "", + x: e.x, + y: e.y, + }); + } } }, }, }; </script> -<style lang="less" scoped></style> +<style lang="less"> +@import "../assets/main.less"; +</style> -- Gitblit v1.9.1