import { reactive } from 'vue'

const usePagination = (fn) => {
    // pagination参数
    const paginaionConfig = reactive({
        query: {
            pageindex: 1,
            rows: 15,
        },
        total: 0,
        sizeOptions: [15, 30, 50]
    })

    // 显示条数改变
    const handleSizeChange = (val) => {
        paginaionConfig.query.rows = val
        fn()
    }

    // 页码改变
    const handleCurrentChange = (val) => {
        paginaionConfig.query.pageindex = val
        fn()
    }

    return {
        paginaionConfig,
        handleSizeChange,
        handleCurrentChange
    }
}

export default usePagination;