更新:增加课程首页分类跳转列表页;优化全站列表分页加载;
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
<template>
|
||||
<view class="search-page">
|
||||
<!-- 导航栏 -->
|
||||
<nav-bar>
|
||||
<template #title>
|
||||
<view class="search-box">
|
||||
<wd-search
|
||||
v-model="keyword"
|
||||
hide-cancel
|
||||
clearable
|
||||
:placeholder="$t('courseSearch.placeholder')"
|
||||
@search="handleSearch"
|
||||
@clear="handleClear"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
</nav-bar>
|
||||
|
||||
<z-paging ref="paging" v-model="courseList" auto-show-back-to-top :auto="false" class="search-page" @query="getSearchCourseList">
|
||||
<template #top>
|
||||
<!-- 导航栏 -->
|
||||
<nav-bar>
|
||||
<template #title>
|
||||
<view class="search-box">
|
||||
<wd-search
|
||||
v-model="keyword"
|
||||
hide-cancel
|
||||
clearable
|
||||
:placeholder="$t('courseSearch.placeholder')"
|
||||
@search="handleSearch"
|
||||
@clear="handleClear"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
</nav-bar>
|
||||
</template>
|
||||
|
||||
<!-- 历史搜索区域 -->
|
||||
<view v-if="!showResults" class="history-section">
|
||||
<view class="history-title">{{ $t('courseSearch.historyTitle') }}</view>
|
||||
@@ -32,15 +34,10 @@
|
||||
|
||||
<!-- 搜索结果区域 -->
|
||||
<view v-if="showResults" class="search-results">
|
||||
<!-- 加载状态 -->
|
||||
<view v-if="loading" class="loading-wrapper">
|
||||
<wd-loading />
|
||||
</view>
|
||||
|
||||
<!-- 课程列表 -->
|
||||
<view v-if="!loading && courseList.length > 0" class="course-section">
|
||||
<view class="course-list">
|
||||
<list-item
|
||||
<listItem
|
||||
v-for="(item, index) in courseList"
|
||||
:key="index"
|
||||
:data="item"
|
||||
@@ -55,7 +52,7 @@
|
||||
<wd-divider :text="$t('courseSearch.noData')" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</z-paging>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -64,9 +61,10 @@ import { onShow } from '@dcloudio/uni-app'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { courseApi } from '@/api/modules/course'
|
||||
import type { ICourse } from '@/types/search'
|
||||
import listItem from './list/components/list-item.vue'
|
||||
import ListItem from '@/components/course/ListItem.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
const paging = ref<any>(null)
|
||||
|
||||
// 状态定义
|
||||
const keyword = ref<string>('') // 搜索关键词
|
||||
@@ -123,29 +121,29 @@ const handleSearch = async () => {
|
||||
showResults.value = true
|
||||
isEmpty.value = false
|
||||
|
||||
await paging.value.reload()
|
||||
loading.value = false
|
||||
isEmpty.value = courseList.value.length === 0
|
||||
showResults.value = !isEmpty.value
|
||||
|
||||
// 保存搜索历史
|
||||
saveHistory(keyword.value.trim())
|
||||
}
|
||||
/**
|
||||
* 获取搜索课程列表
|
||||
*/
|
||||
const getSearchCourseList = async (pageNo: number, pageSize: number) => {
|
||||
try {
|
||||
const res = await courseApi.searchData({
|
||||
title: keyword.value.trim()
|
||||
title: keyword.value.trim(),
|
||||
page: pageNo,
|
||||
size: pageSize
|
||||
})
|
||||
|
||||
if (res.code === 0) {
|
||||
courseList.value = res.courseEntities || []
|
||||
isEmpty.value = courseList.value.length === 0
|
||||
|
||||
// 保存搜索历史
|
||||
saveHistory(keyword.value.trim())
|
||||
} else {
|
||||
courseList.value = []
|
||||
isEmpty.value = true
|
||||
}
|
||||
paging.value.setLocalPaging(res.courseEntities)
|
||||
|
||||
} catch (error) {
|
||||
paging.value.complete(false)
|
||||
console.error('搜索失败:', error)
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: t('global.networkConnectionError')
|
||||
})
|
||||
courseList.value = []
|
||||
isEmpty.value = true
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -187,7 +185,6 @@ onShow(() => {
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.search-page {
|
||||
min-height: 100vh;
|
||||
background: #f7faf9;
|
||||
}
|
||||
|
||||
@@ -225,6 +222,7 @@ onShow(() => {
|
||||
// 搜索结果样式
|
||||
.search-results {
|
||||
padding: 20rpx;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.loading-wrapper {
|
||||
@@ -251,13 +249,8 @@ onShow(() => {
|
||||
}
|
||||
|
||||
// 课程列表样式
|
||||
.course-section {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.course-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user