|
@@ -1,15 +1,14 @@
|
|
import { useRealtime } from './useRealtime'
|
|
import { useRealtime } from './useRealtime'
|
|
-import { reactive, watch, isProxy } from 'vue'
|
|
|
|
|
|
+import { reactive, watch, isProxy, Ref, isRef } from 'vue'
|
|
import { useActive } from './useActive'
|
|
import { useActive } from './useActive'
|
|
|
|
|
|
import type { PageRequest, PageResult } from '@/api'
|
|
import type { PageRequest, PageResult } from '@/api'
|
|
|
|
|
|
export function usePaging<P extends {}, A>(
|
|
export function usePaging<P extends {}, A>(
|
|
fetch: (p: PageRequest<P>) => Promise<PageResult<A>>,
|
|
fetch: (p: PageRequest<P>) => Promise<PageResult<A>>,
|
|
- initial: P,
|
|
|
|
|
|
+ initial: P | Ref<P>,
|
|
setting?: { pageSize?: number; auto?: boolean }
|
|
setting?: { pageSize?: number; auto?: boolean }
|
|
) {
|
|
) {
|
|
- console.log(setting)
|
|
|
|
const pagination = reactive({
|
|
const pagination = reactive({
|
|
current: 1,
|
|
current: 1,
|
|
total: 0,
|
|
total: 0,
|
|
@@ -23,7 +22,7 @@ export function usePaging<P extends {}, A>(
|
|
|
|
|
|
const [list, updateList] = useRealtime(async () => {
|
|
const [list, updateList] = useRealtime(async () => {
|
|
const result = await fetch({
|
|
const result = await fetch({
|
|
- ...initial,
|
|
|
|
|
|
+ ...(isRef(initial) ? initial.value : initial),
|
|
pageNum: pagination.current,
|
|
pageNum: pagination.current,
|
|
pageSize: pagination.pageSize
|
|
pageSize: pagination.pageSize
|
|
})
|
|
})
|
|
@@ -33,7 +32,9 @@ export function usePaging<P extends {}, A>(
|
|
|
|
|
|
if (!setting || !('auto' in setting) || setting?.auto) {
|
|
if (!setting || !('auto' in setting) || setting?.auto) {
|
|
const active = useActive()
|
|
const active = useActive()
|
|
- isProxy(initial) && watch(initial, () => active.value && updateList())
|
|
|
|
|
|
+ if (isRef(initial) || isProxy(initial)) {
|
|
|
|
+ watch(initial, () => active.value && updateList())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return { list, pagination, updateList }
|
|
return { list, pagination, updateList }
|