diff --git a/pages/index/components/index-refactor.vue b/pages/index/components/index-refactor.vue index 9bd0d5e..cffebc6 100644 --- a/pages/index/components/index-refactor.vue +++ b/pages/index/components/index-refactor.vue @@ -534,6 +534,67 @@ function findJob(job) { conditionSearch.value[nameAttr] = val; } } + if (state.tabIndex === 'all') { + // 调用推荐接口 + getJobRecommendWithNewSearch(job.index); + } else { + // 调用普通列表接口 + getJobListWithNewSearch(job.index); + } + } +} +// 立即查询新的数据替换现有数据 +function getJobRecommendWithNewSearch(index) { + const params = { + pageSize: pageState.pageSize, + sessionId: useUserStore().seesionId, + ...pageState.search, + ...conditionSearch.value, + }; + + $api.createRequest('/app/job/recommend', params).then((resData) => { + const { data } = resData; + const newData = dataToImg(data); + //替换点击项以后的数据 + list.value.splice(index, list.value?.length - 1, newData) + // 更新加载状态 + updateLoadmoreStatus(newData); + }); +} + +// 立即查询新的数据替换现有数据 +function getJobListWithPreservedData(preservedData) { + // 重置分页参数 + pageState.page = 1; + pageState.maxPage = 2; + + const params = { + current: pageState.page, + pageSize: pageState.pageSize, + ...pageState.search, + ...conditionSearch.value, + }; + + $api.createRequest('/app/job/list', params).then((resData) => { + const { rows, total } = resData; + // 将新数据转换为图片格式 + const newData = dataToImg(rows); + //替换点击项以后的数据 + list.value.splice(index, list.value?.length - 1, newData) + // 更新分页和加载状态 + pageState.total = total; + pageState.maxPage = Math.ceil(total / pageState.pageSize); + updateLoadmoreStatus(newData); + }); +} + +function updateLoadmoreStatus(newData) { + if (loadmoreRef.value && typeof loadmoreRef.value.change === 'function') { + if (newData.length < pageState.pageSize) { + loadmoreRef.value.change('noMore'); + } else { + loadmoreRef.value.change('more'); + } } }