@fy-/fws-vue 2.1.27 → 2.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ui/DefaultPaging.vue +64 -55
- package/package.json +1 -1
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type {
|
|
3
|
-
WatchStopHandle,
|
|
4
|
-
} from 'vue'
|
|
2
|
+
import type { WatchStopHandle } from 'vue'
|
|
5
3
|
import type { RouteLocationRaw } from 'vue-router'
|
|
6
4
|
import type { APIPaging } from '../../composables/rest'
|
|
7
5
|
import { getURL, hasFW } from '@fy-/fws-js'
|
|
8
6
|
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/vue/24/solid'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
computed,
|
|
12
|
-
ref,
|
|
13
|
-
watch,
|
|
14
|
-
} from 'vue'
|
|
7
|
+
import { useHead } from '@unhead/vue'
|
|
8
|
+
import { computed, ref, watch, watchEffect } from 'vue'
|
|
15
9
|
import { useRoute } from 'vue-router'
|
|
16
10
|
import { useEventBus } from '../../composables/event-bus'
|
|
17
11
|
import { useServerRouter } from '../../stores/serverRouter'
|
|
@@ -28,14 +22,17 @@ const props = withDefaults(
|
|
|
28
22
|
hash: '',
|
|
29
23
|
},
|
|
30
24
|
)
|
|
25
|
+
|
|
31
26
|
const route = useRoute()
|
|
32
27
|
const eventBus = useEventBus()
|
|
33
28
|
const history = useServerRouter()
|
|
29
|
+
|
|
34
30
|
function isNewPage(page: number) {
|
|
35
31
|
return (
|
|
36
32
|
page >= 1 && page <= props.items.page_max && page !== props.items.page_no
|
|
37
33
|
)
|
|
38
34
|
}
|
|
35
|
+
|
|
39
36
|
const pageWatcher = ref<WatchStopHandle>()
|
|
40
37
|
|
|
41
38
|
function next() {
|
|
@@ -50,6 +47,7 @@ function next() {
|
|
|
50
47
|
hash: props.hash !== '' ? `#${props.hash}` : undefined,
|
|
51
48
|
})
|
|
52
49
|
}
|
|
50
|
+
|
|
53
51
|
function prev() {
|
|
54
52
|
const page = props.items.page_no - 1
|
|
55
53
|
if (!isNewPage(page)) return
|
|
@@ -79,46 +77,58 @@ pageWatcher.value = watch(
|
|
|
79
77
|
},
|
|
80
78
|
)
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
watchEffect(() => {
|
|
81
|
+
useHead({
|
|
82
|
+
link: computed(() => {
|
|
83
|
+
const result: any = []
|
|
84
|
+
const page = props.items.page_no
|
|
85
|
+
const page_max = props.items.page_max
|
|
86
|
+
|
|
87
|
+
let next
|
|
88
|
+
let prev
|
|
89
|
+
|
|
90
|
+
if (hasFW()) {
|
|
91
|
+
const url = getURL()
|
|
92
|
+
if (url) {
|
|
93
|
+
const currentQuery = { ...route.query }
|
|
94
|
+
// Remove the existing 'page' parameter to avoid duplicates
|
|
95
|
+
delete currentQuery.page
|
|
96
|
+
|
|
97
|
+
const baseURL = `${url.Scheme}://${url.Host}${url.Path}`
|
|
98
|
+
const hashPart = props.hash !== '' ? `#${props.hash}` : ''
|
|
99
|
+
|
|
100
|
+
if (page + 1 <= page_max) {
|
|
101
|
+
const nextQuery = { ...currentQuery, page: (page + 1).toString() }
|
|
102
|
+
const nextQueryString = new URLSearchParams(nextQuery).toString()
|
|
103
|
+
next = `${baseURL}?${nextQueryString}${hashPart}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (page - 1 >= 1) {
|
|
107
|
+
const prevQuery = { ...currentQuery, page: (page - 1).toString() }
|
|
108
|
+
const prevQueryString = new URLSearchParams(prevQuery).toString()
|
|
109
|
+
prev = `${baseURL}?${prevQueryString}${hashPart}`
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (next) {
|
|
115
|
+
result.push({
|
|
116
|
+
href: next,
|
|
117
|
+
rel: 'next',
|
|
118
|
+
key: `paging-next${props.id}`,
|
|
119
|
+
})
|
|
97
120
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
if (prev) {
|
|
122
|
+
result.push({
|
|
123
|
+
href: prev,
|
|
124
|
+
rel: 'prev',
|
|
125
|
+
key: `paging-prev${props.id}`,
|
|
126
|
+
})
|
|
102
127
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
href: next,
|
|
108
|
-
rel: 'next',
|
|
109
|
-
key: 'paging-next',
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
if (prev) {
|
|
113
|
-
result.push({
|
|
114
|
-
href: prev,
|
|
115
|
-
rel: 'prev',
|
|
116
|
-
key: 'paging-prev',
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return result
|
|
121
|
-
}),
|
|
128
|
+
|
|
129
|
+
return result
|
|
130
|
+
}),
|
|
131
|
+
})
|
|
122
132
|
})
|
|
123
133
|
</script>
|
|
124
134
|
|
|
@@ -150,8 +160,7 @@ useServerHead({
|
|
|
150
160
|
</li>
|
|
151
161
|
<li v-if="items.page_no - 2 > 2">
|
|
152
162
|
<div
|
|
153
|
-
|
|
154
|
-
class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
|
|
163
|
+
class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400"
|
|
155
164
|
>
|
|
156
165
|
...
|
|
157
166
|
</div>
|
|
@@ -159,7 +168,7 @@ useServerHead({
|
|
|
159
168
|
<template v-for="i in 2">
|
|
160
169
|
<li
|
|
161
170
|
v-if="items.page_no - (3 - i) >= 1"
|
|
162
|
-
:key="`page-${items.page_no
|
|
171
|
+
:key="`page-${items.page_no - (3 - i)}`"
|
|
163
172
|
>
|
|
164
173
|
<router-link
|
|
165
174
|
class="flex items-center justify-center px-3 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
|
|
@@ -172,7 +181,7 @@ useServerHead({
|
|
|
172
181
|
<li>
|
|
173
182
|
<div
|
|
174
183
|
aria-current="page"
|
|
175
|
-
class="z-10 flex items-center justify-center px-3 h-8 leading-tight text-primary-600 border border-primary-300 bg-primary-50
|
|
184
|
+
class="z-10 flex items-center justify-center px-3 h-8 leading-tight text-primary-600 border border-primary-300 bg-primary-50 dark:border-fv-neutral-700 dark:bg-fv-neutral-700 dark:text-white"
|
|
176
185
|
>
|
|
177
186
|
{{ items.page_no }}
|
|
178
187
|
</div>
|
|
@@ -192,7 +201,7 @@ useServerHead({
|
|
|
192
201
|
</template>
|
|
193
202
|
<li v-if="items.page_no + 2 < items.page_max - 1">
|
|
194
203
|
<div
|
|
195
|
-
class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300
|
|
204
|
+
class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400"
|
|
196
205
|
>
|
|
197
206
|
...
|
|
198
207
|
</div>
|
|
@@ -205,7 +214,7 @@ useServerHead({
|
|
|
205
214
|
{{ items.page_max }}
|
|
206
215
|
</router-link>
|
|
207
216
|
</li>
|
|
208
|
-
<li v-if="items.page_no < items.page_max
|
|
217
|
+
<li v-if="items.page_no < items.page_max">
|
|
209
218
|
<button
|
|
210
219
|
type="button"
|
|
211
220
|
class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
|
|
@@ -223,8 +232,8 @@ useServerHead({
|
|
|
223
232
|
>
|
|
224
233
|
{{
|
|
225
234
|
$t("global_paging", {
|
|
226
|
-
start: items.results_per_page * (items.page_no - 1),
|
|
227
|
-
end: items.results_per_page * items.page_no,
|
|
235
|
+
start: items.results_per_page * (items.page_no - 1) + 1,
|
|
236
|
+
end: Math.min(items.results_per_page * items.page_no, items.count),
|
|
228
237
|
total: items.count >= 10000 ? $t("paging_a_lot_of") : items.count,
|
|
229
238
|
})
|
|
230
239
|
}}
|