@fy-/fws-vue 2.1.31 → 2.1.33
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 +32 -16
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import type { APIPaging } from '../../composables/rest'
|
|
|
5
5
|
import { getURL, hasFW } from '@fy-/fws-js'
|
|
6
6
|
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/vue/24/solid'
|
|
7
7
|
import { useHead } from '@unhead/vue'
|
|
8
|
-
import { ref, watch
|
|
8
|
+
import { computed, onMounted, ref, watch } from 'vue'
|
|
9
9
|
import { useRoute } from 'vue-router'
|
|
10
10
|
import { useEventBus } from '../../composables/event-bus'
|
|
11
11
|
import { useServerRouter } from '../../stores/serverRouter'
|
|
@@ -69,17 +69,20 @@ function page(page: number): RouteLocationRaw {
|
|
|
69
69
|
hash: props.hash !== '' ? `#${props.hash}` : undefined,
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
const isMounted = ref(false)
|
|
73
73
|
pageWatcher.value = watch(
|
|
74
74
|
() => route.query.page,
|
|
75
|
-
(v) => {
|
|
75
|
+
(v, oldValue) => {
|
|
76
|
+
if (v === oldValue || !isMounted.value) return
|
|
76
77
|
eventBus.emit(`${props.id}GoToPage`, v || 1)
|
|
77
78
|
},
|
|
78
79
|
)
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
81
|
+
// Compute pagination links for useHead
|
|
82
|
+
const paginationLinks = computed(() => {
|
|
83
|
+
const result: any[] = []
|
|
84
|
+
const page = Number(props.items.page_no)
|
|
85
|
+
const page_max = Number(props.items.page_max)
|
|
83
86
|
|
|
84
87
|
let next
|
|
85
88
|
let prev
|
|
@@ -87,32 +90,37 @@ watchEffect(() => {
|
|
|
87
90
|
if (hasFW()) {
|
|
88
91
|
const url = getURL()
|
|
89
92
|
if (url) {
|
|
90
|
-
|
|
93
|
+
// Parse the canonical URL to get the base URL and current query parameters
|
|
94
|
+
const canonicalUrl = new URL(url.Canonical)
|
|
95
|
+
|
|
96
|
+
const baseUrl = `${url.Scheme}://${url.Host}${url.Path}`
|
|
97
|
+
const currentQuery: Record<string, string> = {}
|
|
98
|
+
canonicalUrl.searchParams.forEach((value, key) => {
|
|
99
|
+
currentQuery[key] = value
|
|
100
|
+
})
|
|
91
101
|
// Remove the existing 'page' parameter to avoid duplicates
|
|
92
102
|
delete currentQuery.page
|
|
93
103
|
|
|
94
|
-
const baseURL = `${url.Scheme}://${url.Host}${url.Path}`
|
|
95
104
|
const hashPart = props.hash !== '' ? `#${props.hash}` : ''
|
|
96
105
|
|
|
97
106
|
if (page + 1 <= page_max) {
|
|
98
107
|
const nextQuery = { ...currentQuery, page: (page + 1).toString() }
|
|
99
108
|
const nextQueryString = new URLSearchParams(nextQuery).toString()
|
|
100
|
-
next = `${
|
|
109
|
+
next = `${baseUrl}?${nextQueryString}${hashPart}`
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
if (page - 1 >= 1) {
|
|
104
113
|
const prevQuery = { ...currentQuery, page: (page - 1).toString() }
|
|
105
114
|
const prevQueryString = new URLSearchParams(prevQuery).toString()
|
|
106
|
-
prev = `${
|
|
115
|
+
prev = `${baseUrl}?${prevQueryString}${hashPart}`
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
|
-
const result: any = []
|
|
111
119
|
|
|
112
120
|
if (next) {
|
|
113
121
|
result.push({
|
|
114
|
-
href: next,
|
|
115
122
|
rel: 'next',
|
|
123
|
+
href: next,
|
|
116
124
|
key: `paging-next${props.id}`,
|
|
117
125
|
hid: `paging-next${props.id}`,
|
|
118
126
|
id: `paging-next${props.id}`,
|
|
@@ -120,16 +128,24 @@ watchEffect(() => {
|
|
|
120
128
|
}
|
|
121
129
|
if (prev) {
|
|
122
130
|
result.push({
|
|
123
|
-
href: prev,
|
|
124
131
|
rel: 'prev',
|
|
132
|
+
href: prev,
|
|
125
133
|
key: `paging-prev${props.id}`,
|
|
126
134
|
hid: `paging-prev${props.id}`,
|
|
127
135
|
id: `paging-prev${props.id}`,
|
|
128
136
|
})
|
|
129
137
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
|
|
139
|
+
return result
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// Use useHead outside of any reactive context to ensure it runs during SSR
|
|
143
|
+
useHead({
|
|
144
|
+
link: paginationLinks.value,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
onMounted(() => {
|
|
148
|
+
isMounted.value = true
|
|
133
149
|
})
|
|
134
150
|
</script>
|
|
135
151
|
|