feat: 文档库/问题库的分页功能 #91
@ -101,19 +101,19 @@
|
|||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
productTypeOptions: {
|
productTypeOptions: {
|
||||||
type: Array as () => Array<{ id: number; name: string }>,
|
type: Array as () => Array<{ id: string; name: string }>,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
productOptions: {
|
productOptions: {
|
||||||
type: Array as () => Array<{ id: number; name: string }>,
|
type: Array as () => Array<{ id: string; name: string }>,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const model = defineModel<{
|
const model = defineModel<{
|
||||||
keyword: string;
|
keyword: string;
|
||||||
selectedType: number | null;
|
selectedType: string | null;
|
||||||
selectedProduct: number | null;
|
selectedProduct: string | null;
|
||||||
}>();
|
}>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,16 @@
|
|||||||
:product-type-options="productTypeOptions"
|
:product-type-options="productTypeOptions"
|
||||||
:product-options="productOptions"
|
:product-options="productOptions"
|
||||||
/>
|
/>
|
||||||
<document-list :documents="filteredDocuments" />
|
<!-- <document-list :documents="filteredDocuments" /> -->
|
||||||
|
<document-list :documents="paginatedDocuments" />
|
||||||
|
<el-pagination
|
||||||
|
v-model:current-page="page"
|
||||||
|
class="justify-center pagination-container"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
hide-on-single-page
|
||||||
|
:page-size="documentsPerPage"
|
||||||
|
:total="filteredDocuments.length"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -30,11 +39,14 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
const filters = reactive({
|
const filters = reactive({
|
||||||
selectedType: null as number | null,
|
selectedType: null as string | null,
|
||||||
selectedProduct: null as number | null,
|
selectedProduct: null as string | null,
|
||||||
keyword: '',
|
keyword: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const page = ref(1);
|
||||||
|
const documentsPerPage = 10;
|
||||||
|
|
||||||
const { data: documents, pending, error } = await useDocumentList();
|
const { data: documents, pending, error } = await useDocumentList();
|
||||||
|
|
||||||
const productTypeOptions = computed(() => {
|
const productTypeOptions = computed(() => {
|
||||||
@ -92,6 +104,13 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const paginatedDocuments = computed(() => {
|
||||||
|
return filteredDocuments.value.slice(
|
||||||
|
(page.value - 1) * documentsPerPage,
|
||||||
|
page.value * documentsPerPage
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => filters.selectedType,
|
() => filters.selectedType,
|
||||||
() => {
|
() => {
|
||||||
@ -153,4 +172,35 @@
|
|||||||
height: 40px;
|
height: 40px;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pagination-container {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-pagination) {
|
||||||
|
.btn-prev,
|
||||||
|
.btn-next {
|
||||||
|
.el-icon {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-pager {
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
.el-pager li {
|
||||||
|
font-size: 1rem;
|
||||||
|
/* border: 1px solid #409eff; */
|
||||||
|
border-radius: 50%;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #ecf5ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-active {
|
||||||
|
background-color: var(--el-color-primary);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -17,7 +17,16 @@
|
|||||||
:product-options="productOptions"
|
:product-options="productOptions"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<question-list :questions="filteredQuestions" />
|
<question-list :questions="paginatedQuestions" />
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
v-model:current-page="page"
|
||||||
|
class="justify-center pagination-container"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
hide-on-single-page
|
||||||
|
:page-size="questionsPerPage"
|
||||||
|
:total="filteredQuestions.length"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -25,13 +34,21 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const localePath = useLocalePath();
|
const localePath = useLocalePath();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
const filters = reactive({
|
const filters = reactive({
|
||||||
selectedType: null as number | null,
|
selectedType: null as string | null,
|
||||||
selectedProduct: null as number | null,
|
selectedProduct: null as string | null,
|
||||||
keyword: '',
|
keyword: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const page = ref(1);
|
||||||
|
const questionsPerPage = 10;
|
||||||
|
|
||||||
|
const focusQuestionId = ref<string | null>(
|
||||||
|
route.query.focus as string | null
|
||||||
|
);
|
||||||
|
|
||||||
const breadcrumbItems = [
|
const breadcrumbItems = [
|
||||||
{ label: $t('navigation.home'), to: localePath('/') },
|
{ label: $t('navigation.home'), to: localePath('/') },
|
||||||
{ label: $t('navigation.support'), to: localePath('/support') },
|
{ label: $t('navigation.support'), to: localePath('/support') },
|
||||||
@ -92,6 +109,34 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const paginatedQuestions = computed(() => {
|
||||||
|
const start = (page.value - 1) * questionsPerPage;
|
||||||
|
const end = page.value * questionsPerPage;
|
||||||
|
return filteredQuestions.value.slice(start, end);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
focusQuestionId,
|
||||||
|
async (focusId) => {
|
||||||
|
if (!focusId) return;
|
||||||
|
if (!import.meta.client) return;
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
const question = filteredQuestions.value.find((q) => q.id === focusId);
|
||||||
|
if (!question) return;
|
||||||
|
|
||||||
|
const targetIndex = filteredQuestions.value.indexOf(question);
|
||||||
|
const targetPage = Math.floor(targetIndex / questionsPerPage) + 1;
|
||||||
|
onMounted(() => {
|
||||||
|
if (page.value !== targetPage) {
|
||||||
|
page.value = targetPage;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => filters.selectedType,
|
() => filters.selectedType,
|
||||||
() => {
|
() => {
|
||||||
@ -136,4 +181,34 @@
|
|||||||
.page-content {
|
.page-content {
|
||||||
padding: 1rem 2rem 2rem;
|
padding: 1rem 2rem 2rem;
|
||||||
}
|
}
|
||||||
|
.pagination-container {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-pagination) {
|
||||||
|
.btn-prev,
|
||||||
|
.btn-next {
|
||||||
|
.el-icon {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-pager {
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
.el-pager li {
|
||||||
|
font-size: 1rem;
|
||||||
|
/* border: 1px solid #409eff; */
|
||||||
|
border-radius: 50%;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #ecf5ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-active {
|
||||||
|
background-color: var(--el-color-primary);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user