From f4425543db1c8db8c47a34c53ef477e72cfe318e Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期一, 11 三月 2024 18:19:56 +0800 Subject: [PATCH] feat(答题器): 答题器 --- pages/bookServices/detail/components/tree/index.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 104 insertions(+), 2 deletions(-) diff --git a/pages/bookServices/detail/components/tree/index.js b/pages/bookServices/detail/components/tree/index.js index d3706b0..11f74cb 100644 --- a/pages/bookServices/detail/components/tree/index.js +++ b/pages/bookServices/detail/components/tree/index.js @@ -22,6 +22,14 @@ applyState: { type: String, value: '' + }, + openTeachids: { + type: Array, + value: '' + }, + openLearnids: { + type: Array, + value: "" } }, data: { @@ -48,7 +56,6 @@ } }, downloadTeach(e) { - console.log('鐐瑰嚮浜�', e); const value = e.currentTarget.dataset.value var myEventDetail = { value, @@ -58,6 +65,7 @@ composed: true } // 瑙﹀彂浜嬩欢鐨勯�夐」 this.triggerEvent('downloadTeach', myEventDetail, myEventOption) + }, // 鍒ゆ柇璧勬簮鏄惁璐拱 resourceIsBuy(data) { @@ -72,11 +80,105 @@ goPlayer(e) { const item = e.currentTarget.dataset.item const parent = e.currentTarget.dataset.parent - console.log(this.properties.bookInfo); + console.log(item.selectType); + debugger wx.navigateTo({ url: `/pages/resourceDetails/index?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parent.productLinkPath}&parentName=${parent.name}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}`, }) console.log(e); + }, + // 鎷垮埌鎵�鏈夐」 + getAllChildren(id) { + let result = []; + function findChildren(item) { + if (item.id === id) { + if (item.children && item.children.length > 0) { + item.children.forEach(child => { + findChildren(child); + }); + } + } else { + if (item.children && item.children.length > 0) { + item.children.forEach(child => { + findChildren(child); + }); + } + } + if (item.children && item.children.length > 0) { + result.push(...item.children); + } + } + this.properties.treeList.forEach(item => { + findChildren(item); + }); + return result; + }, + // 鎷垮埌褰撳墠椤瑰瓙椤� + flattenTree(tree) { + let result = []; + function flatten(node) { + result.push(node); + if (node.children && node.children.length > 0) { + node.children.forEach(child => { + flatten(child); + }); + } + } + tree.forEach(node => { + flatten(node); + }); + return result + }, + findAndUpdateItemById(tree, id) { + function findAndUpdate(node) { + if (node.id === id) { + node.check = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true + return true; // 杩斿洖 true 琛ㄧず鎵惧埌浜嗙洰鏍囬」 + } + if (node.children && node.children.length > 0) { + for (let child of node.children) { + if (findAndUpdate(child)) { + return true; // 濡傛灉鍦ㄥ瓙鑺傜偣涓壘鍒颁簡鐩爣椤癸紝鍒欑洿鎺ヨ繑鍥� true + } + } + } + return false; // 琛ㄧず鏈壘鍒扮洰鏍囬」 + } + + for (let node of tree) { + if (findAndUpdate(node)) { + break; // 濡傛灉鍦ㄩ《灞傝妭鐐逛腑鎵惧埌浜嗙洰鏍囬」锛岀洿鎺ラ��鍑哄惊鐜� + } + } + }, + // 鍙樹负true + findAndUpdateItemsByIds(tree, ids) { + function findAndUpdate(node) { + if (ids.includes(node.id)) { + node.checked = true; // 灏嗙洰鏍囬」鐨� check 灞炴�ц缃负 true + } + if (node.children && node.children.length > 0) { + for (let child of node.children) { + findAndUpdate(child); // 閫掑綊澶勭悊瀛愯妭鐐� + } + } + } + + for (let node of tree) { + findAndUpdate(node); // 瀵规瘡涓《灞傝妭鐐规墽琛屾煡鎵惧拰鏇存柊鎿嶄綔 + } + return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍 + }, + // 绔犺妭鍕鹃�� + checkResourceTitle(e) { + const item = e.currentTarget.dataset.item + let list = this.flattenTree([item]) + let ids = [] + list.forEach(item => { + ids.push(item.id) + }) + const tab = this.findAndUpdateItemsByIds([item], ids) + console.log(ids, tab); } } }) \ No newline at end of file -- Gitblit v1.9.1