Upgraded dependencies, bumped to Node 24.
This commit is contained in:
@@ -1,3 +1,119 @@
|
||||
<script setup>
|
||||
import { parse } from 'path-to-regexp';
|
||||
import { computed, inject } from 'vue';
|
||||
|
||||
import Campaign from '#/components/campaigns/campaign.vue';
|
||||
|
||||
const props = defineProps({
|
||||
page: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
total: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
redirect: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
query: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
includeQuery: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
useMaxMatches: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['navigation']);
|
||||
const pageContext = inject('pageContext');
|
||||
|
||||
const {
|
||||
routeParams,
|
||||
urlParsed,
|
||||
pageProps,
|
||||
env,
|
||||
campaigns,
|
||||
} = pageContext;
|
||||
|
||||
const currentPage = computed(() => props.page || Number(routeParams?.page));
|
||||
|
||||
const limit = computed(() => props.limit || Number(pageProps.limit) || 30);
|
||||
const total = computed(() => props.total || Number(pageProps.total));
|
||||
const pageTotal = computed(() => Math.ceil((props.useMaxMatches ? Math.min(total.value, env.maxMatches) : total.value) / limit.value));
|
||||
|
||||
const hasNextPage = computed(() => currentPage.value + 1 <= pageTotal.value);
|
||||
const hasPrevPage = computed(() => currentPage.value - 1 >= 1);
|
||||
|
||||
const prevPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
||||
const page = currentPage.value - index - 1;
|
||||
|
||||
if (page < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return page;
|
||||
}).filter(Boolean));
|
||||
|
||||
const nextPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
||||
const page = currentPage.value + index + 1;
|
||||
|
||||
if (page > pageTotal.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return page;
|
||||
}).filter(Boolean));
|
||||
|
||||
function go(page, event) {
|
||||
if (!props.redirect) {
|
||||
event.preventDefault();
|
||||
history.pushState({}, '', event.target.href);
|
||||
}
|
||||
|
||||
emit('navigation', {
|
||||
href: event.target.href,
|
||||
page,
|
||||
});
|
||||
}
|
||||
|
||||
function getPath(page) {
|
||||
const query = typeof window === 'undefined'
|
||||
? urlParsed.searchOriginal
|
||||
: window.location.search;
|
||||
|
||||
if (!routeParams.path && props.includeQuery && query) {
|
||||
return `${pageContext.urlParsed.pathname}${page}${query}`;
|
||||
}
|
||||
|
||||
if (!routeParams.path) {
|
||||
return `${pageContext.urlParsed.pathname}${page}`;
|
||||
}
|
||||
|
||||
const path = parse(routeParams.path)
|
||||
.map((segment) => {
|
||||
if (segment.name === 'page') {
|
||||
return `/${page}`;
|
||||
}
|
||||
|
||||
return `${segment.prefix || ''}${routeParams[segment.name] || segment}`;
|
||||
})
|
||||
.join('');
|
||||
|
||||
if (props.includeQuery && query) {
|
||||
return `${path}${query}`;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pagination-container">
|
||||
<Campaign
|
||||
@@ -91,122 +207,6 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, inject } from 'vue';
|
||||
import { parse } from 'path-to-regexp';
|
||||
|
||||
import Campaign from '#/components/campaigns/campaign.vue';
|
||||
|
||||
const props = defineProps({
|
||||
page: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
total: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
redirect: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
query: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
includeQuery: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
useMaxMatches: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['navigation']);
|
||||
const pageContext = inject('pageContext');
|
||||
|
||||
const {
|
||||
routeParams,
|
||||
urlParsed,
|
||||
pageProps,
|
||||
env,
|
||||
campaigns,
|
||||
} = pageContext;
|
||||
|
||||
const currentPage = computed(() => props.page || Number(routeParams?.page));
|
||||
|
||||
const limit = computed(() => props.limit || Number(pageProps.limit) || 30);
|
||||
const total = computed(() => props.total || Number(pageProps.total));
|
||||
const pageTotal = computed(() => Math.ceil((props.useMaxMatches ? Math.min(total.value, env.maxMatches) : total.value) / limit.value));
|
||||
|
||||
const hasNextPage = computed(() => currentPage.value + 1 <= pageTotal.value);
|
||||
const hasPrevPage = computed(() => currentPage.value - 1 >= 1);
|
||||
|
||||
const prevPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
||||
const page = currentPage.value - index - 1;
|
||||
|
||||
if (page < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return page;
|
||||
}).filter(Boolean));
|
||||
|
||||
const nextPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
||||
const page = currentPage.value + index + 1;
|
||||
|
||||
if (page > pageTotal.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return page;
|
||||
}).filter(Boolean));
|
||||
|
||||
function go(page, event) {
|
||||
if (!props.redirect) {
|
||||
event.preventDefault();
|
||||
history.pushState({}, '', event.target.href); // eslint-disable-line no-restricted-globals
|
||||
}
|
||||
|
||||
emit('navigation', {
|
||||
href: event.target.href,
|
||||
page,
|
||||
});
|
||||
}
|
||||
|
||||
function getPath(page) {
|
||||
const query = typeof window === 'undefined'
|
||||
? urlParsed.searchOriginal
|
||||
: window.location.search;
|
||||
|
||||
if (!routeParams.path && props.includeQuery && query) {
|
||||
return `${pageContext.urlParsed.pathname}${page}${query}`;
|
||||
}
|
||||
|
||||
if (!routeParams.path) {
|
||||
return `${pageContext.urlParsed.pathname}${page}`;
|
||||
}
|
||||
|
||||
const path = parse(routeParams.path)
|
||||
.map((segment) => {
|
||||
if (segment.name === 'page') {
|
||||
return `/${page}`;
|
||||
}
|
||||
|
||||
return `${segment.prefix || ''}${routeParams[segment.name] || segment}`;
|
||||
})
|
||||
.join('');
|
||||
|
||||
if (props.includeQuery && query) {
|
||||
return `${path}${query}`;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user