1.代码如下:
import { getPageList } from "@/api/cloudExhibitionHall"
import { ref, watch } from "vue"
const role = JSON.parse(localStorage.getItem('current-role') || '{}')
const tenantId = role.tenantId ? role.tenantId : 6
const defaultParams = {
pageNum: 1,
pageSize: 10,
tenantId
}
export function useGetTableList(params = {}) {
defaultParams.pageSize = params.pageSize
const searchParams = ref({ ...defaultParams, ...params })
const pageTotal = ref(0)
const tableData = ref([])
watch([searchParams], () => {
initData()
}, { immediate: true, deep: true })
function handleSearch(data, type) {
if (type == 'reset') {
searchParams.value = defaultParams
} else {
searchParams.value = { ...searchParams.value, ...data }
}
}
async function initData() {
const { data = {}, code } = await getPageList({ ...searchParams.value })
if (code == 200) {
tableData.value = data?.list || []
pageTotal.value = data?.total
}
}
return {
searchParams,
pageTotal,
tableData,
handleSearch,
initData
}
}