feat: first commit
This commit is contained in:
commit
8a85cf5b78
64 files changed
+7832
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import type { BaseFilterRequest, BaseModel, PageResult, Paging } from '@/model/base'
|
||||
import { reactive, type Ref, ref } from 'vue'
|
||||
import type { PageInfo } from 'tdesign-vue-next'
|
||||
|
||||
export const useSearchable = <T extends BaseFilterRequest, D extends BaseModel>(api: (filter: Partial<T>) => Promise<PageResult<D>>, defaultFilter = {}) => {
|
||||
const loading = ref(false)
|
||||
const data: Ref<D[]> = ref([])
|
||||
const pagination = reactive<Paging>({
|
||||
page: 1,
|
||||
size: 20,
|
||||
})
|
||||
const filter: Ref<Partial<T>> = ref(defaultFilter)
|
||||
|
||||
const fetchData = async (defaultFilter = {}) => {
|
||||
loading.value = true
|
||||
const result = await api({...filter.value, page: pagination.page, size: pagination.size, ...defaultFilter})
|
||||
data.value = result.data
|
||||
pagination.page = result.paging.page
|
||||
pagination.size = result.paging.size
|
||||
pagination.total = result.paging.total
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
const onPageChange = (pageInfo: PageInfo): void => {
|
||||
pagination.size = pageInfo.pageSize
|
||||
pagination.page = pageInfo.current
|
||||
fetchData()
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
data,
|
||||
pagination,
|
||||
filter,
|
||||
fetchData,
|
||||
onPageChange
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user