@fy-/fws-vue 2.1.25 → 2.1.26
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 +28 -20
- package/package.json +1 -1
|
@@ -30,15 +30,19 @@ const props = withDefaults(
|
|
|
30
30
|
hash: '',
|
|
31
31
|
},
|
|
32
32
|
)
|
|
33
|
+
|
|
33
34
|
const route = useRoute()
|
|
34
35
|
const eventBus = useEventBus()
|
|
35
36
|
const history = useServerRouter()
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
const prevNextSeo = ref<{ prev?: string, next?: string }>({})
|
|
39
|
+
|
|
37
40
|
function isNewPage(page: number) {
|
|
38
41
|
return (
|
|
39
42
|
page >= 1 && page <= props.items.page_max && page !== props.items.page_no
|
|
40
43
|
)
|
|
41
44
|
}
|
|
45
|
+
|
|
42
46
|
const pageWatcher = ref<WatchStopHandle>()
|
|
43
47
|
|
|
44
48
|
function next() {
|
|
@@ -53,6 +57,7 @@ function next() {
|
|
|
53
57
|
hash: props.hash !== '' ? `#${props.hash}` : undefined,
|
|
54
58
|
})
|
|
55
59
|
}
|
|
60
|
+
|
|
56
61
|
function prev() {
|
|
57
62
|
const page = props.items.page_no - 1
|
|
58
63
|
if (!isNewPage(page)) return
|
|
@@ -76,60 +81,63 @@ function page(page: number): RouteLocationRaw {
|
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
function checkPageNumber(page: number = 1) {
|
|
84
|
+
// Reset prev and next
|
|
79
85
|
prevNextSeo.value.next = undefined
|
|
80
86
|
prevNextSeo.value.prev = undefined
|
|
81
87
|
|
|
82
88
|
if (hasFW()) {
|
|
83
89
|
const url = getURL()
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
= `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
= `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${
|
|
92
|
-
props.hash !== '' ? `#${props.hash}` : ''}`
|
|
90
|
+
if (url) {
|
|
91
|
+
if (page + 1 <= props.items.page_max) {
|
|
92
|
+
prevNextSeo.value.next = `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${props.hash !== '' ? `#${props.hash}` : ''}`
|
|
93
|
+
}
|
|
94
|
+
if (page - 1 >= 1) {
|
|
95
|
+
prevNextSeo.value.prev = `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${props.hash !== '' ? `#${props.hash}` : ''}`
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
// Watch for changes in the current page number
|
|
97
102
|
pageWatcher.value = watch(
|
|
98
|
-
() =>
|
|
99
|
-
(
|
|
100
|
-
|
|
103
|
+
() => props.items.page_no,
|
|
104
|
+
(newPage) => {
|
|
105
|
+
checkPageNumber(newPage)
|
|
101
106
|
},
|
|
107
|
+
{ immediate: true }, // Ensure it's called initially
|
|
102
108
|
)
|
|
109
|
+
|
|
103
110
|
onMounted(() => {
|
|
104
111
|
eventBus.on(`${props.id}GoToPage`, checkPageNumber)
|
|
105
112
|
})
|
|
106
113
|
onUnmounted(() => {
|
|
107
114
|
eventBus.off(`${props.id}GoToPage`, checkPageNumber)
|
|
108
|
-
|
|
115
|
+
if (pageWatcher.value) pageWatcher.value()
|
|
109
116
|
})
|
|
110
117
|
|
|
118
|
+
// Initial check
|
|
111
119
|
checkPageNumber(props.items.page_no)
|
|
112
120
|
|
|
121
|
+
// Setup SEO head
|
|
113
122
|
useServerHead({
|
|
114
123
|
link: computed(() => {
|
|
115
|
-
const
|
|
116
|
-
|
|
124
|
+
const links: any[] = []
|
|
125
|
+
|
|
117
126
|
if (prevNextSeo.value.next) {
|
|
118
|
-
|
|
127
|
+
links.push({
|
|
119
128
|
href: prevNextSeo.value.next,
|
|
120
129
|
rel: 'next',
|
|
121
130
|
key: 'paging-next',
|
|
122
131
|
})
|
|
123
132
|
}
|
|
124
133
|
if (prevNextSeo.value.prev) {
|
|
125
|
-
|
|
134
|
+
links.push({
|
|
126
135
|
href: prevNextSeo.value.prev,
|
|
127
136
|
rel: 'prev',
|
|
128
137
|
key: 'paging-prev',
|
|
129
138
|
})
|
|
130
139
|
}
|
|
131
|
-
|
|
132
|
-
return result
|
|
140
|
+
return links
|
|
133
141
|
}),
|
|
134
142
|
})
|
|
135
143
|
</script>
|