From c2cd778fd3f40a75df483758bb2f1fe1dedc7eef Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期五, 26 四月 2024 09:49:25 +0800 Subject: [PATCH] 资源购买页请求慢优化 --- packageBookService/pages/bookServices/detail/buyResource/index.js | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ packageBookService/pages/bookServices/detail/buyResource/index.wxml | 36 +++++++-- 2 files changed, 224 insertions(+), 11 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/buyResource/index.js b/packageBookService/pages/bookServices/detail/buyResource/index.js index 8c61ce1..92e8ef6 100644 --- a/packageBookService/pages/bookServices/detail/buyResource/index.js +++ b/packageBookService/pages/bookServices/detail/buyResource/index.js @@ -84,6 +84,195 @@ goBack() { wx.navigateBack(); }, + + // 鎵佸钩鍖栨暟鎹浆鎹ree + getTreeList(rootList, pathLength, newArr, path) { + for (const item of rootList) { + if (item.productLinkPath.length == pathLength && item.productLinkPath.includes(path)) { + item.checked = false; + if (item.sysType == 'CmsItem') { + if (item.selectType == 'webpage') { + item.disabled = true + } else { + if (item.isDownload != 1) { + item.disabled = true + } + } + if (item.file && item.fileMap && item.fileMap[item.file]) { + if (item.fileMap[item.file].protectType == 'Private') item.disabled = true + } + + item.isbuy = this.isShowNeedBuy(item); + item.isShopCar = this.isShoppingCart(item); + } + // newArr.push(item) + // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴� + newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) + } + } + //缁欐暟缁勯噷闈㈠啀娣诲姞涓�涓猚hildren鐨勭┖鏁扮粍 + for (const i of newArr) { + i.children = [] + this.getTreeList(rootList, pathLength + 6, i.children, i.productLinkPath) + if (i.children.length == 0) { + delete i.children + } + } + return newArr + }, + + // 鍘婚櫎鏍戠粨鏋勫浣欓」 + ensureTreeConsistency(tree) { + for (let index = 0; index < tree.length; index++) { + const item = tree[index]; + if (item.children && item.children.length) { + const isFloder = item.children.findIndex(citem => citem.sysType == 'CmsFolder') + const isItem = item.children.findIndex(citem => citem.sysType == 'CmsItem') + if (isFloder > -1 && isItem > -1) { + item.children = item.children.filter(ditem => ditem.sysType == 'CmsItem') + } + this.ensureTreeConsistency(item.children) + } + } + return tree + }, + + // 鎺掑簭鏁扮粍 鎸夌収productLinkPath + insertAndSortObjectsByProductLinkPath(array, newObj) { + // 鏌ユ壘鏂板璞″簲璇ユ彃鍏ョ殑浣嶇疆 + let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - 6, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - 6, obj.productLinkPath.length))); + + // 濡傛灉娌℃湁鎵惧埌鍚堥�傜殑浣嶇疆锛屽垯鏀惧湪鏁扮粍鏈熬 + if (insertIndex === -1) { + insertIndex = array.length; + } + // 鎻掑叆鏂板璞″埌鏁扮粍 + array.splice(insertIndex, 0, newObj); + // 娴嬭瘯6 姝e紡5 + // 瀵规暟缁勮繘琛屾帓搴� + array.sort((a, b) => { + if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) { + return -1; + } + if (Number(a.productLinkPath.substring(a.productLinkPath.length - 5, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - 5, b.productLinkPath.length))) { + return 1; + } + // a must be equal to b + return 0; + }); + + // 杩斿洖鏇存柊鍚庣殑鏁扮粍 + return array; + }, + + // 閬嶅巻鏍戠粨鏋勮浆鎹负鏁扮粍鏂规硶 + handleTreeData(array) { + const flattenedArray = []; + array.forEach((node) => { + // 灏嗗綋鍓嶈妭鐐规坊鍔犲埌灞曞紑鐨勬暟缁勪腑 + flattenedArray.push(node); + // 閫掑綊澶勭悊瀛愯妭鐐� + if (node.children && node.children.length > 0) { + const childrenArray = this.handleTreeData(node.children); + flattenedArray.push(...childrenArray); + } + }); + return flattenedArray.filter((item) => item.sysType == "CmsItem"); + }, + + // 鏁欏璧勬簮 浜戝涔� 鑾峰彇 + getResourceDataList(type) { + this.setData({ + loading: true, + noResources: false, + }); + let query = { + path: '*', + queryType: '*', + productId: this.data.bookDetail.id, + cmsPath: type.productLinkPath, + cmsType: '*', + itemFields: { + SysType: 'CmsFolder', + // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁� + selectType: [], + freeFile: [], + file: [], + protectedFile: [], + resourcesClassification: [], + isDownload: [], + jsek_resourceBrief: [], + jsek_link: [], + jsek_questionBank: [] + }, + pading: { + start: 0, + size: 999 + }, + } + app.MG.store.getProductDetail(query).then((res) => { + if (!res.datas.cmsDatas[0].datas.length) { + return this.setData({ + noResources: true, + loading: false, + haider: true, + }); + } + let list = [] + // 娴嬭瘯 6浣�// 姝e紡 5浣�// 娴嬭瘯璋冪敤浼�20锛屽唴閮�7 姝e紡璋冪敤浼�17 鍐呴儴浼�6 + //鏁欏璧勬簮 浜戝涔� + if ( + type.refCode == "jsek_teachingResources" || + type.refCode == "jsek_cloudLearning" + ) { + res.datas.cmsDatas[0].datas.forEach((item) => { + item.checked = false; + if (item.sysType == 'CmsItem') { + // 鏁欏璧勬簮 绫诲瀷鍚嶇О璧嬪�� + this.data.resourceClassList.forEach((type) => { + if (type.value == item.resourcesClassification) + item.resourceClass = type.name; + }); + if (this.data.tabValue == "jsek_teachingResources") {} else if (this.data.tabValue == "jsek_cloudLearning") { + item.isbuy = this.isShowNeedBuy(item); + item.isShopCar = this.isShoppingCart(item); + } + } + }); + this.getTreeList(res.datas.cmsDatas[0].datas, 17, list, '\\') + list = this.ensureTreeConsistency(list) + console.log('淇敼鍚庝簯', list); + let result = []; + if (type.refCode == "jsek_teachingResources") { + this.findChildIds(list, result); + this.setData({ + teach: list, + loading: false, + openTeachids: result, + }); + } else if (type.refCode == "jsek_cloudLearning") { + let arr = this.handleTreeData(list).filter( + (item) => item.saleMethod[0] + ); + let freeIds = arr.filter((item) => { + return item.saleMethod[0].Price == 0; + }); + if (!freeIds.length) + this.setData({ + isshowDrawBtn: false, + }); + this.findChildIds(list, result); + this.setData({ + learn: list, + loading: false, + openLearnids: result, + haider: true, + }); + } + } + }) + }, + // 鑾峰彇鏁欏璧勬簮 浜戝涔� 浜戞祴璇� getResourceData(type) { this.setData({ @@ -119,7 +308,7 @@ return this.setData({ noResources: true, loading: false, - haider: true + haider: true, }); } //鏁欏璧勬簮 浜戝涔� @@ -281,10 +470,14 @@ bookDetail: res.datas, buyIdList: res.datas.purchasedSaleMethodIdList, }); - this.getResourceData({ + // this.getResourceData({ + // productLinkPath: this.data.productLinkPath, + // refCode: this.data.refCode, + // }); + this.getResourceDataList({ productLinkPath: this.data.productLinkPath, refCode: this.data.refCode, - }); + }) }); }, diff --git a/packageBookService/pages/bookServices/detail/buyResource/index.wxml b/packageBookService/pages/bookServices/detail/buyResource/index.wxml index ab8280c..8a28b44 100644 --- a/packageBookService/pages/bookServices/detail/buyResource/index.wxml +++ b/packageBookService/pages/bookServices/detail/buyResource/index.wxml @@ -4,13 +4,17 @@ <template is="skeleton" wx:if="{{loading}}" /> <view wx:if="{{haider}}"> - <!--瀵艰埅鍖哄煙 --> <view style="width: 100%; height: {{barHeight}}px; "></view> <view class="nacigationBar" style="width: 70%; height: {{navBarHeight}}px;"> <view class="flex"> <view> - <t-icon name="chevron-left" size="30" data-name="{{item}}" bind:click="goBack" /> + <t-icon + name="chevron-left" + size="30" + data-name="{{item}}" + bind:click="goBack" + /> </view> <view class="navbar-title">璧勬簮璐拱</view> </view> @@ -20,7 +24,20 @@ <!-- 鍐呭 --> <view class="buy-resource" wx:if="{{!loading}}"> - <tree id="tree" paymentPage="{{paymentPage}}" superior="{{superior}}" treeList="{{learn}}" learnList="{{learn}}" tab="{{'jsek_cloudLearning'}}" isShowCheck="{{true}}" openIds="{{openLearnids}}" checkAllState="{{checkAllState}}" bind:changeCheckAll="changeCheckAll" bind:changeListChecked="changeListChecked" bind:changeResourceChecked="changeResourceChecked" /> + <tree + id="tree" + paymentPage="{{paymentPage}}" + superior="{{superior}}" + treeList="{{learn}}" + learnList="{{learn}}" + tab="{{'jsek_cloudLearning'}}" + isShowCheck="{{true}}" + openIds="{{openLearnids}}" + checkAllState="{{checkAllState}}" + bind:changeCheckAll="changeCheckAll" + bind:changeListChecked="changeListChecked" + bind:changeResourceChecked="changeResourceChecked" + /> </view> <!-- <view class="noData" wx:if="{{loading}}"> @@ -28,9 +45,12 @@ </view> --> <view class="page-bottom"> - <t-button theme="primary" size="large" class="btn-buy" bindtap="batchPurchase">鎵归噺璐拱</t-button> + <t-button + theme="primary" + size="large" + class="btn-buy" + bindtap="batchPurchase" + >鎵归噺璐拱</t-button + > </view> - - - -</view> \ No newline at end of file +</view> -- Gitblit v1.9.1