干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { computed, reactive, h } from 'vue';
import { JVxeTableMethods, JVxeTableProps } from '/@/components/jeecg/JVxeTable/src/types';
import { isEmpty } from '/@/utils/is';
import { Pagination } from 'ant-design-vue';
 
export function usePagination(props: JVxeTableProps, methods: JVxeTableMethods) {
  const innerPagination = reactive({
    current: 1,
    pageSize: 10,
    pageSizeOptions: ['10', '20', '30'],
    showTotal: (total, range) => {
      return range[0] + '-' + range[1] + ' 共 ' + total + ' 条';
    },
    showQuickJumper: true,
    showSizeChanger: true,
    total: 100,
  });
 
  const bindProps = computed(() => {
    return {
      ...innerPagination,
      ...props.pagination,
      size: props.size === 'tiny' ? 'small' : '',
    };
  });
 
  const boxClass = computed(() => {
    return {
      'j-vxe-pagination': true,
      'show-quick-jumper': !!bindProps.value.showQuickJumper,
    };
  });
 
  function handleChange(current, pageSize) {
    innerPagination.current = current;
    methods.trigger('pageChange', { current, pageSize });
  }
 
  function handleShowSizeChange(current, pageSize) {
    innerPagination.pageSize = pageSize;
    methods.trigger('pageChange', { current, pageSize });
  }
 
  /** 渲染分页器 */
  function renderPagination() {
    if (props.pagination && !isEmpty(props.pagination)) {
      return h(
        'div',
        {
          class: boxClass.value,
        },
        [
          h(Pagination, {
            ...bindProps.value,
            disabled: props.disabled,
            onChange: handleChange,
            onShowSizeChange: handleShowSizeChange,
          }),
        ]
      );
    }
    return null;
  }
 
  return { renderPagination };
}