2021-06-26 09:35:40 +08:00
|
|
|
import type { ExtractPropTypes } from 'vue';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { computed, toRef, defineComponent } from 'vue';
|
2020-10-19 22:11:45 +08:00
|
|
|
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
|
|
|
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
|
|
|
|
import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined';
|
|
|
|
import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined';
|
|
|
|
import { tuple } from '../_util/type';
|
2020-10-11 21:31:57 +08:00
|
|
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcSelect from '../select';
|
|
|
|
import MiniSelect from './MiniSelect';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcPagination from '../vc-pagination';
|
2019-09-11 22:35:25 +08:00
|
|
|
import enUS from '../vc-pagination/locale/en_US';
|
2020-08-31 16:53:19 +08:00
|
|
|
import classNames from '../_util/classNames';
|
2021-09-25 16:51:32 +08:00
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2018-03-05 19:06:44 +08:00
|
|
|
|
2021-06-23 14:44:21 +08:00
|
|
|
export const paginationProps = () => ({
|
2018-03-05 19:06:44 +08:00
|
|
|
total: PropTypes.number,
|
|
|
|
defaultCurrent: PropTypes.number,
|
2020-10-10 18:16:28 +08:00
|
|
|
disabled: PropTypes.looseBool,
|
2018-03-05 19:06:44 +08:00
|
|
|
current: PropTypes.number,
|
|
|
|
defaultPageSize: PropTypes.number,
|
|
|
|
pageSize: PropTypes.number,
|
2020-10-10 18:16:28 +08:00
|
|
|
hideOnSinglePage: PropTypes.looseBool,
|
|
|
|
showSizeChanger: PropTypes.looseBool,
|
2019-01-12 11:33:27 +08:00
|
|
|
pageSizeOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
|
2018-03-06 15:40:42 +08:00
|
|
|
buildOptionText: PropTypes.func,
|
2018-03-05 19:06:44 +08:00
|
|
|
showSizeChange: PropTypes.func,
|
2020-10-11 21:31:57 +08:00
|
|
|
showQuickJumper: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object])),
|
2018-03-05 19:06:44 +08:00
|
|
|
showTotal: PropTypes.any,
|
|
|
|
size: PropTypes.string,
|
2020-10-10 18:16:28 +08:00
|
|
|
simple: PropTypes.looseBool,
|
2018-03-05 19:06:44 +08:00
|
|
|
locale: PropTypes.object,
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
selectPrefixCls: PropTypes.string,
|
2020-08-17 18:02:28 +08:00
|
|
|
itemRender: PropTypes.func,
|
2018-09-05 21:28:54 +08:00
|
|
|
role: PropTypes.string,
|
2020-10-10 18:16:28 +08:00
|
|
|
showLessItems: PropTypes.looseBool,
|
2021-01-23 17:09:13 +08:00
|
|
|
onChange: PropTypes.func,
|
|
|
|
onShowSizeChange: PropTypes.func,
|
|
|
|
'onUpdate:current': PropTypes.func,
|
|
|
|
'onUpdate:pageSize': PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2021-06-23 14:44:21 +08:00
|
|
|
export const paginationConfig = () => ({
|
|
|
|
...paginationProps(),
|
2020-10-19 22:19:33 +08:00
|
|
|
position: PropTypes.oneOf(tuple('top', 'bottom', 'both')),
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-01-22 21:27:37 +08:00
|
|
|
|
2021-06-23 14:44:21 +08:00
|
|
|
export type PaginationProps = Partial<ExtractPropTypes<ReturnType<typeof paginationProps>>>;
|
|
|
|
export type PaginationConfig = Partial<ExtractPropTypes<ReturnType<typeof paginationConfig>>>;
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export type PaginationLocale = any;
|
2020-10-19 22:19:33 +08:00
|
|
|
export default defineComponent({
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'APagination',
|
2020-07-14 21:51:48 +08:00
|
|
|
inheritAttrs: false,
|
2021-09-25 16:51:32 +08:00
|
|
|
props: paginationProps(),
|
2021-01-23 17:09:13 +08:00
|
|
|
emits: ['change', 'showSizeChange', 'update:current', 'update:pageSize'],
|
2021-09-25 16:51:32 +08:00
|
|
|
setup(props, { slots, attrs }) {
|
|
|
|
const { prefixCls, configProvider, direction } = useConfigInject('pagination', props);
|
|
|
|
const selectPrefixCls = computed(() =>
|
|
|
|
configProvider.getPrefixCls('select', props.selectPrefixCls),
|
|
|
|
);
|
|
|
|
const [locale] = useLocaleReceiver('Pagination', enUS, toRef(props, 'locale'));
|
|
|
|
const getIconsProps = (pre: string) => {
|
|
|
|
const ellipsis = <span class={`${pre}-item-ellipsis`}>•••</span>;
|
|
|
|
let prevIcon = (
|
|
|
|
<button class={`${pre}-item-link`} type="button" tabindex={-1}>
|
2020-07-14 21:51:48 +08:00
|
|
|
<LeftOutlined />
|
2021-09-25 16:51:32 +08:00
|
|
|
</button>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
let nextIcon = (
|
|
|
|
<button class={`${pre}-item-link`} type="button" tabindex={-1}>
|
2020-07-14 21:51:48 +08:00
|
|
|
<RightOutlined />
|
2021-09-25 16:51:32 +08:00
|
|
|
</button>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
let jumpPrevIcon = (
|
2021-11-02 16:17:20 +08:00
|
|
|
<a rel='nofollow' class={`${pre}-item-link`}>
|
2018-12-10 21:06:42 +08:00
|
|
|
{/* You can use transition effects in the container :) */}
|
2021-09-25 16:51:32 +08:00
|
|
|
<div class={`${pre}-item-container`}>
|
|
|
|
<DoubleLeftOutlined class={`${pre}-item-link-icon`} />
|
|
|
|
{ellipsis}
|
2018-12-10 21:06:42 +08:00
|
|
|
</div>
|
|
|
|
</a>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
let jumpNextIcon = (
|
2021-11-02 16:17:20 +08:00
|
|
|
<a rel='nofollow' class={`${pre}-item-link`}>
|
2018-12-10 21:06:42 +08:00
|
|
|
{/* You can use transition effects in the container :) */}
|
2021-09-25 16:51:32 +08:00
|
|
|
<div class={`${pre}-item-container`}>
|
|
|
|
<DoubleRightOutlined class={`${pre}-item-link-icon`} />
|
|
|
|
{ellipsis}
|
2018-12-10 21:06:42 +08:00
|
|
|
</div>
|
|
|
|
</a>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
// change arrows direction in right-to-left direction
|
|
|
|
if (direction.value === 'rtl') {
|
|
|
|
[prevIcon, nextIcon] = [nextIcon, prevIcon];
|
|
|
|
[jumpPrevIcon, jumpNextIcon] = [jumpNextIcon, jumpPrevIcon];
|
|
|
|
}
|
2018-12-10 21:06:42 +08:00
|
|
|
return {
|
|
|
|
prevIcon,
|
|
|
|
nextIcon,
|
|
|
|
jumpPrevIcon,
|
|
|
|
jumpNextIcon,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2021-09-25 16:51:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return () => {
|
2019-03-19 10:02:14 +08:00
|
|
|
const {
|
|
|
|
size,
|
2021-09-25 16:51:32 +08:00
|
|
|
itemRender = slots.itemRender,
|
|
|
|
buildOptionText = slots.buildOptionText,
|
2019-03-19 10:02:14 +08:00
|
|
|
...restProps
|
2021-09-25 16:51:32 +08:00
|
|
|
} = props;
|
2019-03-19 10:02:14 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const isSmall = size === 'small';
|
2018-03-05 19:06:44 +08:00
|
|
|
const paginationProps = {
|
2020-07-14 21:51:48 +08:00
|
|
|
...restProps,
|
2021-09-25 16:51:32 +08:00
|
|
|
...getIconsProps(prefixCls.value),
|
|
|
|
prefixCls: prefixCls.value,
|
|
|
|
selectPrefixCls: selectPrefixCls.value,
|
2020-07-14 21:51:48 +08:00
|
|
|
selectComponentClass: isSmall ? MiniSelect : VcSelect,
|
2021-09-25 16:51:32 +08:00
|
|
|
locale: locale.value,
|
|
|
|
buildOptionText,
|
|
|
|
...attrs,
|
|
|
|
class: classNames(
|
|
|
|
{ mini: isSmall, [`${prefixCls.value}-rtl`]: direction.value === 'rtl' },
|
|
|
|
attrs.class,
|
|
|
|
),
|
|
|
|
itemRender,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-01-22 21:27:37 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
return <VcPagination {...paginationProps} />;
|
2021-09-25 16:51:32 +08:00
|
|
|
};
|
2018-01-22 21:27:37 +08:00
|
|
|
},
|
2020-10-19 22:19:33 +08:00
|
|
|
});
|