diff --git a/pages/learnPath/allPath.vue b/pages/learnPath/allPath.vue index 1377212..6404a1b 100644 --- a/pages/learnPath/allPath.vue +++ b/pages/learnPath/allPath.vue @@ -189,8 +189,9 @@ return integratedDataArray; }, goSearch(){ + let positionId = this.preparedData.map(item => item.positionName).join(',') uni.navigateTo({ - url: '/pages/learnPath/pathSearch' + url: `/pages/learnPath/pathSearch?positionId=${positionId}` }) }, } diff --git a/pages/learnPath/pathSearch.vue b/pages/learnPath/pathSearch.vue index f83ec0f..be7f607 100644 --- a/pages/learnPath/pathSearch.vue +++ b/pages/learnPath/pathSearch.vue @@ -100,8 +100,20 @@ res.data.unshift(majorItem); } this.posiLists = res.data - this.posiData.push(this.posiLists[0]) - this.indexs.push(0) + const positionName = this.$route.query.positionId + const positionNames = positionName.split(','); + const matchedItemsWithIndexes = positionNames.flatMap((item, index) => { + // 先找到匹配的项 + const matches = this.posiLists + .map((listItem, listItemIndex) => listItem.positionName === item ? { listItem, listItemIndex } : null) + .filter(match => match !== null); + return matches.map(match => ({ + matchedItem: match.listItem, + indexInPosiLists: match.listItemIndex + })); + }); + this.posiData = matchedItemsWithIndexes.map(item=> item.matchedItem) + this.indexs = matchedItemsWithIndexes.map(item=> item.indexInPosiLists) if(this.posiLists.length > 9){ this.posiLists = this.posiLists.slice(0, 9) } @@ -138,23 +150,50 @@ this.bandShow = !this.bandShow }, isDisabled(index) { - if (this.bandIndexs.length >= 1) { - const firstClickIndex = Math.min(...this.bandIndexs); + if (this.bandIndexs.length == 1) { + const firstClickIndex = this.bandIndexs[0]; const allowedRangeEnd = firstClickIndex + 2; - return index < firstClickIndex || index > allowedRangeEnd; + return index < firstClickIndex - 2 || index > allowedRangeEnd; } + if (this.bandIndexs.length == 2) { + const firstClickIndex = this.bandIndexs[0]; + const allowedRangeEnd = firstClickIndex + 2; + return index < firstClickIndex - 1 || index > allowedRangeEnd; + } + if (this.bandIndexs.length == 3) { + const firstClickIndex = Math.min(...this.bandIndexs); + const allowedRangeEnd = Math.max(...this.bandIndexs); + return index < firstClickIndex || index > allowedRangeEnd; + } return false; }, isBand(item,index){ - if (this.bandIndexs.length >= 1) { - const firstClickIndex = Math.min(...this.bandIndexs); + console.log(this.bandIndexs.length) + if (this.bandIndexs.length == 1) { + const firstClickIndex = this.bandIndexs[0]; const allowedRangeEnd = firstClickIndex + 2; - if (index < firstClickIndex || index > allowedRangeEnd) { + if (index < firstClickIndex - 2 || index > allowedRangeEnd) { return; } } - if (this.bandIndexs.length === 3 && this.bandIndexs.includes(index) && this.bandIndexs.indexOf(index) === 1) { + if (this.bandIndexs.length == 2) { + const firstClickIndex = this.bandIndexs[0]; + const allowedRangeEnd = firstClickIndex + 2; + if (index < firstClickIndex - 1 || index > allowedRangeEnd) { + return; + } + } + if (this.bandIndexs.length == 3) { + const firstClickIndex = Math.min(...this.bandIndexs); + const allowedRangeEnd = Math.max(...this.bandIndexs); + if (index < firstClickIndex || index > allowedRangeEnd) { + return; + } + } + this.bandIndexs.sort((a, b) => a - b); + if (this.bandIndexs.length === 3 && this.bandIndexs.includes(index) && this.bandIndexs.indexOf(index) == 1) { // 删除最后一个元素 + this.bandIndexs.sort((a, b) => a - b); this.bandIndexs.pop(); this.bandItem = this.bandIndexs.map(index => this.bandLists[index]) this.bandItem = this.bandItem.sort((a, b) => parseInt(a.bandId, 10) - parseInt(b.bandId, 10)); @@ -169,27 +208,54 @@ if (this.bandIndexs.length === 0) { this.bandIndexs.push(currentIndex); + this.bandItem = this.bandIndexs.map(index => this.bandLists[index]) + this.bandItem = this.bandItem.sort((a, b) => parseInt(a.bandId, 10) - parseInt(b.bandId, 10)); + this.bandFirst = this.bandItem[0].bandCode return; } // 确保currentIndex和firstClickIndex按顺序排列 - if (currentIndex < firstClickIndex) { - [currentIndex, firstClickIndex] = [firstClickIndex, currentIndex]; - } - + // if (currentIndex < firstClickIndex) { + // [currentIndex, firstClickIndex] = [firstClickIndex, currentIndex]; + // } // 检查是否有连续的未选择项,并自动填充 - for (let i = firstClickIndex + 1; i < currentIndex; i++) { - if (!this.bandIndexs.includes(i)) { - this.bandIndexs.splice(this.bandIndexs.indexOf(i - 1) + 1, 0, i); - } - } - + // for (let i = firstClickIndex + 1; i < currentIndex; i++) { + // if (!this.bandIndexs.includes(i)) { + // this.bandIndexs.splice(this.bandIndexs.indexOf(i - 1) + 1, 0, i); + // } + // } + + // const start = Math.min(firstClickIndex, currentIndex); + // const end = Math.max(firstClickIndex, currentIndex); + + // this.bandIndexs = this.bandIndexs.filter(index => index < start || index > end); + + // for (let i = start; i <= end; i++) { + // if (!this.bandIndexs.includes(i)) { + // this.bandIndexs.push(i); + // } + // } + // 添加或移除当前点击的index - const indexToRemove = this.bandIndexs.indexOf(currentIndex); + // const indexToRemove = this.bandIndexs.indexOf(currentIndex); + // if (indexToRemove !== -1) { + // this.bandIndexs.splice(indexToRemove, 1); + // } else { + // this.bandIndexs.push(currentIndex); + // } + const indexToRemove = this.bandIndexs.findIndex(index => index === currentIndex); if (indexToRemove !== -1) { - this.bandIndexs.splice(indexToRemove, 1); + this.bandIndexs.splice(indexToRemove, 1); } else { - this.bandIndexs.push(currentIndex); + // 如果索引不存在于数组中,则需要检查是否需要填充连续索引 + const start = Math.min(firstClickIndex, currentIndex); + const end = Math.max(firstClickIndex, currentIndex); + console.log(start,end,'end') + for (let i = start; i <= end; i++) { + if (!this.bandIndexs.includes(i)) { + this.bandIndexs.push(i); + } + } } if(this.bandIndexs.length == 0){ this.bandFirst = '' @@ -199,7 +265,6 @@ if(this.bandIndexs.length == 1){ this.bandEnd = '' } - this.bandItem = this.bandIndexs.map(index => this.bandLists[index]) this.bandItem = this.bandItem.sort((a, b) => parseInt(a.bandId, 10) - parseInt(b.bandId, 10)); this.bandFirst = this.bandItem[0].bandCode