<template>
    <div class="pagination">
        <a-pagination
            v-bind="props"
            :show-total="total => `共 ${total} 条`"
            v-model:current="pager.page"
            v-model:pageSize="pager.size"
            :total="pager.count"
            @showSizeChange="sizeChange"
            @change="pageChange"
        ></a-pagination>
    </div>
</template>

<script lang="ts" setup>
import {computed} from "vue";

interface Props {
    modelValue?: Record<string, any>,
}
const props = withDefaults(defineProps<Props>(), {
    modelValue: () => ({}),
    
})

const emit = defineEmits<{
    (event: 'change'): void
    (event: 'update:modelValue', value: any): void
}>()

const pager = computed({
    get() {
        return props.modelValue
    },
    set(value) {
        emit('update:modelValue', value)
    }
})
const sizeChange = () => {
    pager.value.page = 1
    emit('change')
}
const pageChange = () => {
    emit('change')
}
</script>
