提交 b3793255 authored 作者: matian's avatar matian

updates

上级 845adde8
...@@ -2,87 +2,66 @@ ...@@ -2,87 +2,66 @@
import CourseListItem from './CourseListItem.vue' import CourseListItem from './CourseListItem.vue'
import { useDevice } from '@/composables/useDevice' import { useDevice } from '@/composables/useDevice'
const { mobile } = useDevice() const { mobile } = useDevice()
const props = defineProps({ const props = defineProps({
courseList: { courseList: { type: Array, default: () => [] },
type: Array type: { type: String }
},
type: {
type: String
}
}) })
const page = reactive({
size: 10, const page = reactive({ size: 10, currentPage: 1 })
currentPage: 1
}) // 筛选之后的数据
const courseListAll = $computed<any>(() => { const courseFilterList = $computed(() => {
if (props.type) { return props.courseList.filter(
return props.courseList?.filter((item: any) => item.category === props.type) (item: any) => item.category === props.type || props.type === ''
} else { )
return props.courseList
}
}) })
watch(
() => courseListAll, // 当前页的数据
() => { const currentCourseList = $computed<any[]>(() => {
return queryByPage
}
)
const courseListAllNew = ref([])
const queryByPage = $computed<any>(() => {
// 起始位置 = (当前页 - 1) x 每页的大小 // 起始位置 = (当前页 - 1) x 每页的大小
const start = (page.currentPage - 1) * page.size const start = (page.currentPage - 1) * page.size
// 结束位置 = 当前页 x 每页的大小 // 结束位置 = 当前页 x 每页的大小
const end = page.currentPage * page.size const end = page.currentPage * page.size
const pageList = courseFilterList.slice(start, end)
// 返回切割数组后的数据 return pageList
return courseListAll.slice(start, end)
}) })
courseListAllNew.value = queryByPage
// 改变每页大小的方法
const handleSizeChange = (val: number) => {
page.size = val
// courseListAllNew.value = queryByPage
console.log(courseListAllNew)
courseListAllNew.value = queryByPage
}
// 改变当前页的方法 const paginationLayout = $computed(() => {
const handleCurrentChange = (val: number) => { return mobile.value ? 'prev, pager, next' : 'prev, pager, next, jumper'
page.currentPage = val })
// courseListAllNew.value = queryByPage
console.log(courseListAllNew)
courseListAllNew.value = queryByPage
}
</script> </script>
<template> <template>
<div <div class="course_list">
class="course_list" <CourseListItem
v-for="(item, index) in courseListAllNew" :courseItem="item"
:key="index" v-for="(item, index) in currentCourseList"
> :key="index"
<CourseListItem :courseItem="item" :key="type"></CourseListItem> ></CourseListItem>
</div>
<div class="pagination" v-if="courseFilterList.length > page.size">
<el-pagination
:layout="paginationLayout"
:page-size="page.size"
:total="courseFilterList.length"
v-model:currentPage="page.currentPage"
></el-pagination>
</div> </div>
<el-pagination
class="pagination"
layout="total, sizes, prev, pager, next, jumper"
:page-sizes="[10, 15, 20, 30, 50]"
:page-size="page.size"
:total="courseListAll.length"
v-model:currentPage="page.currentPage"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
v-if="courseListAll.length > 10 && !mobile"
>
</el-pagination>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.pagination { .pagination {
margin: 46px 204px 40px 0; padding: 40px;
display: flex; display: flex;
justify-content: flex-end; align-items: center;
justify-content: center;
:deep(ul) {
margin: 0 8px;
}
:deep(li) {
margin: 0 8px;
}
} }
.is-h5 { .is-h5 {
.course_list { .course_list {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论