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