feat(pagination): upgrade to v3 (#2541)
* feat(pagination): upgrade to v3 * feat(pagination): code reviewpull/2682/head
parent
c469853733
commit
a760a10676
|
@ -41,6 +41,6 @@ export default {
|
||||||
const { $slots } = this;
|
const { $slots } = this;
|
||||||
const children = this.children || $slots.default;
|
const children = this.children || $slots.default;
|
||||||
const { antLocale } = this.localeData;
|
const { antLocale } = this.localeData;
|
||||||
return children(this.getLocale(), this.getLocaleCode(), antLocale);
|
return children?.(this.getLocale(), this.getLocaleCode(), antLocale);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import VcSelect, { SelectProps } from '../select';
|
import VcSelect, { SelectProps } from '../select';
|
||||||
import { getOptionProps, filterEmpty, getListeners } from '../_util/props-util';
|
import { getOptionProps, getSlot } from '../_util/props-util';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
...SelectProps,
|
...SelectProps,
|
||||||
},
|
},
|
||||||
|
@ -9,12 +10,10 @@ export default {
|
||||||
render() {
|
render() {
|
||||||
const selectOptionsProps = getOptionProps(this);
|
const selectOptionsProps = getOptionProps(this);
|
||||||
const selelctProps = {
|
const selelctProps = {
|
||||||
props: {
|
...selectOptionsProps,
|
||||||
...selectOptionsProps,
|
size: 'small',
|
||||||
size: 'small',
|
...this.$attrs,
|
||||||
},
|
|
||||||
on: getListeners(this),
|
|
||||||
};
|
};
|
||||||
return <VcSelect {...selelctProps}>{filterEmpty(this.$slots.default)}</VcSelect>;
|
return <VcSelect {...selelctProps}>{getSlot(this)}</VcSelect>;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import PropTypes from '../_util/vue-types';
|
||||||
import VcSelect from '../select';
|
import VcSelect from '../select';
|
||||||
import MiniSelect from './MiniSelect';
|
import MiniSelect from './MiniSelect';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import { getOptionProps, getListeners } from '../_util/props-util';
|
import { getOptionProps } from '../_util/props-util';
|
||||||
import VcPagination from '../vc-pagination';
|
import VcPagination from '../vc-pagination';
|
||||||
import enUS from '../vc-pagination/locale/en_US';
|
import enUS from '../vc-pagination/locale/en_US';
|
||||||
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
||||||
|
@ -10,6 +10,8 @@ import RightOutlined from '@ant-design/icons-vue/RightOutlined';
|
||||||
import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined';
|
import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined';
|
||||||
import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined';
|
import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
import { inject } from 'vue';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
export const PaginationProps = () => ({
|
export const PaginationProps = () => ({
|
||||||
total: PropTypes.number,
|
total: PropTypes.number,
|
||||||
|
@ -42,26 +44,27 @@ export const PaginationConfig = () => ({
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'APagination',
|
name: 'APagination',
|
||||||
model: {
|
inheritAttrs: false,
|
||||||
prop: 'current',
|
|
||||||
event: 'change.current',
|
|
||||||
},
|
|
||||||
props: {
|
props: {
|
||||||
...PaginationProps(),
|
...PaginationProps(),
|
||||||
},
|
},
|
||||||
inject: {
|
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
setup() {
|
||||||
|
return {
|
||||||
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getIconsProps(prefixCls) {
|
getIconsProps(prefixCls) {
|
||||||
const prevIcon = (
|
const prevIcon = (
|
||||||
<a class={`${prefixCls}-item-link`}>
|
<a class={`${prefixCls}-item-link`}>
|
||||||
<LeftOutlined/>
|
<LeftOutlined />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
const nextIcon = (
|
const nextIcon = (
|
||||||
<a class={`${prefixCls}-item-link`}>
|
<a class={`${prefixCls}-item-link`}>
|
||||||
<RightOutlined/>
|
<RightOutlined />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
const jumpPrevIcon = (
|
const jumpPrevIcon = (
|
||||||
|
@ -104,19 +107,15 @@ export default {
|
||||||
|
|
||||||
const isSmall = size === 'small';
|
const isSmall = size === 'small';
|
||||||
const paginationProps = {
|
const paginationProps = {
|
||||||
props: {
|
prefixCls,
|
||||||
prefixCls,
|
selectPrefixCls,
|
||||||
selectPrefixCls,
|
...restProps,
|
||||||
...restProps,
|
...this.getIconsProps(prefixCls),
|
||||||
...this.getIconsProps(prefixCls),
|
selectComponentClass: isSmall ? MiniSelect : VcSelect,
|
||||||
selectComponentClass: isSmall ? MiniSelect : VcSelect,
|
locale: { ...contextLocale, ...customLocale },
|
||||||
locale: { ...contextLocale, ...customLocale },
|
buildOptionText: buildOptionText || this.$slots.buildOptionText?.(),
|
||||||
buildOptionText: buildOptionText || this.$scopedSlots.buildOptionText,
|
...this.$attrs,
|
||||||
},
|
class: classNames({ mini: isSmall }, this.$attrs.class),
|
||||||
class: {
|
|
||||||
mini: isSmall,
|
|
||||||
},
|
|
||||||
on: getListeners(this),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return <VcPagination {...paginationProps} />;
|
return <VcPagination {...paginationProps} />;
|
||||||
|
@ -127,8 +126,8 @@ export default {
|
||||||
<LocaleReceiver
|
<LocaleReceiver
|
||||||
componentName="Pagination"
|
componentName="Pagination"
|
||||||
defaultLocale={enUS}
|
defaultLocale={enUS}
|
||||||
scopedSlots={{ default: this.renderPagination }}
|
slots={{ default: this.renderPagination }}
|
||||||
/>
|
></LocaleReceiver>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,9 +4,9 @@ import Base from '../base';
|
||||||
export { PaginationProps, PaginationConfig } from './Pagination';
|
export { PaginationProps, PaginationConfig } from './Pagination';
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Pagination.install = function(Vue) {
|
Pagination.install = function(app) {
|
||||||
Vue.use(Base);
|
app.use(Base);
|
||||||
Vue.component(Pagination.name, Pagination);
|
app.component(Pagination.name, Pagination);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Pagination;
|
export default Pagination;
|
||||||
|
|
|
@ -3,6 +3,7 @@ import classNames from 'classnames';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Pager',
|
name: 'Pager',
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
rootPrefixCls: PropTypes.string,
|
rootPrefixCls: PropTypes.string,
|
||||||
page: PropTypes.number,
|
page: PropTypes.number,
|
||||||
|
@ -24,20 +25,27 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
const { class: _cls, style } = this.$attrs;
|
||||||
const props = this.$props;
|
const props = this.$props;
|
||||||
const prefixCls = `${props.rootPrefixCls}-item`;
|
const prefixCls = `${props.rootPrefixCls}-item`;
|
||||||
const cls = classNames(prefixCls, `${prefixCls}-${props.page}`, {
|
const cls = classNames(
|
||||||
[`${prefixCls}-active`]: props.active,
|
prefixCls,
|
||||||
[`${prefixCls}-disabled`]: !props.page,
|
`${prefixCls}-${props.page}`,
|
||||||
});
|
{
|
||||||
|
[`${prefixCls}-active`]: props.active,
|
||||||
|
[`${prefixCls}-disabled`]: !props.page,
|
||||||
|
},
|
||||||
|
_cls,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
class={cls}
|
|
||||||
onClick={this.handleClick}
|
onClick={this.handleClick}
|
||||||
onKeypress={this.handleKeyPress}
|
onKeypress={this.handleKeyPress}
|
||||||
title={this.showTitle ? this.page : null}
|
title={this.showTitle ? this.page : null}
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
|
class={cls}
|
||||||
|
style={style}
|
||||||
>
|
>
|
||||||
{this.itemRender(this.page, 'page', <a>{this.page}</a>)}
|
{this.itemRender(this.page, 'page', <a>{this.page}</a>)}
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { hasProp, getComponentFromProp, getOptionProps } from '../_util/props-util';
|
import { hasProp, getOptionProps, getComponent } from '../_util/props-util';
|
||||||
import Pager from './Pager';
|
import Pager from './Pager';
|
||||||
import Options from './Options';
|
import Options from './Options';
|
||||||
import LOCALE from './locale/zh_CN';
|
import LOCALE from './locale/zh_CN';
|
||||||
import KEYCODE from './KeyCode';
|
import KEYCODE from './KeyCode';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ function calculatePage(p, state, props) {
|
||||||
export default {
|
export default {
|
||||||
name: 'Pagination',
|
name: 'Pagination',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
inheritAttrs: false,
|
||||||
model: {
|
model: {
|
||||||
prop: 'current',
|
prop: 'current',
|
||||||
event: 'change.current',
|
event: 'change.current',
|
||||||
|
@ -151,7 +153,7 @@ export default {
|
||||||
},
|
},
|
||||||
getItemIcon(icon) {
|
getItemIcon(icon) {
|
||||||
const { prefixCls } = this.$props;
|
const { prefixCls } = this.$props;
|
||||||
const iconNode = getComponentFromProp(this, icon, this.$props) || (
|
const iconNode = getComponent(this, icon, this.$props) || (
|
||||||
<a class={`${prefixCls}-item-link`} />
|
<a class={`${prefixCls}-item-link`} />
|
||||||
);
|
);
|
||||||
return iconNode;
|
return iconNode;
|
||||||
|
@ -359,8 +361,9 @@ export default {
|
||||||
}
|
}
|
||||||
const hasPrev = this.hasPrev();
|
const hasPrev = this.hasPrev();
|
||||||
const hasNext = this.hasNext();
|
const hasNext = this.hasNext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul class={`${prefixCls} ${prefixCls}-simple`}>
|
<ul class={classNames(`${prefixCls} ${prefixCls}-simple`, this.$attrs.class)}>
|
||||||
<li
|
<li
|
||||||
title={this.showTitle ? locale.prev_page : null}
|
title={this.showTitle ? locale.prev_page : null}
|
||||||
onClick={this.prev}
|
onClick={this.prev}
|
||||||
|
@ -409,16 +412,12 @@ export default {
|
||||||
}
|
}
|
||||||
if (allPages <= 5 + pageBufferSize * 2) {
|
if (allPages <= 5 + pageBufferSize * 2) {
|
||||||
const pagerProps = {
|
const pagerProps = {
|
||||||
props: {
|
locale,
|
||||||
locale,
|
rootPrefixCls: prefixCls,
|
||||||
rootPrefixCls: prefixCls,
|
showTitle: props.showTitle,
|
||||||
showTitle: props.showTitle,
|
itemRender: props.itemRender,
|
||||||
itemRender: props.itemRender,
|
onClick: this.handleChange,
|
||||||
},
|
onKeypress: this.runIfEnter,
|
||||||
on: {
|
|
||||||
click: this.handleChange,
|
|
||||||
keypress: this.runIfEnter,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
if (!allPages) {
|
if (!allPages) {
|
||||||
pagerList.push(
|
pagerList.push(
|
||||||
|
@ -580,12 +579,14 @@ export default {
|
||||||
}
|
}
|
||||||
const prevDisabled = !this.hasPrev() || !allPages;
|
const prevDisabled = !this.hasPrev() || !allPages;
|
||||||
const nextDisabled = !this.hasNext() || !allPages;
|
const nextDisabled = !this.hasNext() || !allPages;
|
||||||
const buildOptionText = this.buildOptionText || this.$scopedSlots.buildOptionText;
|
const buildOptionText = this.buildOptionText || this.$slots.buildOptionText?.();
|
||||||
|
const { class: _cls, style } = this.$attrs;
|
||||||
return (
|
return (
|
||||||
<ul
|
<ul
|
||||||
class={{ [`${prefixCls}`]: true, [`${prefixCls}-disabled`]: disabled }}
|
|
||||||
unselectable="unselectable"
|
unselectable="unselectable"
|
||||||
ref="paginationNode"
|
ref="paginationNode"
|
||||||
|
style={style}
|
||||||
|
class={classNames({ [`${prefixCls}`]: true, [`${prefixCls}-disabled`]: disabled }, _cls)}
|
||||||
>
|
>
|
||||||
{totalText}
|
{totalText}
|
||||||
<li
|
<li
|
||||||
|
|
Loading…
Reference in New Issue