feat: update list & pagination
parent
1713581576
commit
69f5487fd1
|
@ -69,3 +69,4 @@ package-lock.json
|
||||||
|
|
||||||
# 备份文件
|
# 备份文件
|
||||||
/components/test/*
|
/components/test/*
|
||||||
|
list.txt
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Collapse should support remove expandIcon 1`] = `
|
||||||
|
<div class="ant-collapse">
|
||||||
|
<div role="tablist" class="ant-collapse-item">
|
||||||
|
<div role="button" tabindex="0" class="ant-collapse-header"><i class="anticon anticon-right ant-collapse-arrow"><svg viewBox="64 64 896 896" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true" class="">
|
||||||
|
<path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path>
|
||||||
|
</svg></i>header</div>
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
|
@ -2,8 +2,10 @@ import PropTypes from '../_util/vue-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { getSlotOptions, getComponentFromProp, isEmptyElement } from '../_util/props-util';
|
import { getSlotOptions, getComponentFromProp, isEmptyElement } from '../_util/props-util';
|
||||||
import { Col } from '../grid';
|
import { Col } from '../grid';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import { ListGridType } from './index';
|
import { ListGridType } from './index';
|
||||||
|
|
||||||
|
|
||||||
export const ListItemProps = {
|
export const ListItemProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
extra: PropTypes.any,
|
extra: PropTypes.any,
|
||||||
|
@ -22,10 +24,16 @@ export const Meta = {
|
||||||
functional: true,
|
functional: true,
|
||||||
name: 'AListItemMeta',
|
name: 'AListItemMeta',
|
||||||
__ANT_LIST_ITEM_META: true,
|
__ANT_LIST_ITEM_META: true,
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
render(h, context) {
|
render(h, context) {
|
||||||
const { props, slots, listeners } = context;
|
const { props, slots, listeners, injections } = context;
|
||||||
const slotsMap = slots();
|
const slotsMap = slots();
|
||||||
const { prefixCls = 'ant-list' } = props;
|
const getPrefixCls = injections.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const { prefixCls: customizePrefixCls } = props;
|
||||||
|
const prefixCls = getPrefixCls('list', customizePrefixCls);
|
||||||
|
|
||||||
const avatar = props.avatar || slotsMap.avatar;
|
const avatar = props.avatar || slotsMap.avatar;
|
||||||
const title = props.title || slotsMap.title;
|
const title = props.title || slotsMap.title;
|
||||||
const description = props.description || slotsMap.description;
|
const description = props.description || slotsMap.description;
|
||||||
|
@ -54,11 +62,14 @@ export default {
|
||||||
props: ListItemProps,
|
props: ListItemProps,
|
||||||
inject: {
|
inject: {
|
||||||
listContext: { default: () => ({}) },
|
listContext: { default: () => ({}) },
|
||||||
|
configProvider: { default: () =>({}) },
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { grid } = this.listContext;
|
const { grid } = this.listContext;
|
||||||
const { prefixCls = 'ant-list', $slots, $listeners } = this;
|
const { prefixCls: customizePrefixCls, $slots, $listeners } = this;
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('list', customizePrefixCls);
|
||||||
|
|
||||||
const classString = `${prefixCls}-item`;
|
const classString = `${prefixCls}-item`;
|
||||||
const extra = getComponentFromProp(this, 'extra');
|
const extra = getComponentFromProp(this, 'extra');
|
||||||
const actions = getComponentFromProp(this, 'actions');
|
const actions = getComponentFromProp(this, 'actions');
|
||||||
|
|
|
@ -3,6 +3,7 @@ import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import defaultLocale from '../locale-provider/default';
|
import defaultLocale from '../locale-provider/default';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
import Spin from '../spin';
|
import Spin from '../spin';
|
||||||
import Pagination, { PaginationConfig } from '../pagination';
|
import Pagination, { PaginationConfig } from '../pagination';
|
||||||
|
@ -55,7 +56,6 @@ const List = {
|
||||||
name: 'AList',
|
name: 'AList',
|
||||||
props: initDefaultProps(ListProps(), {
|
props: initDefaultProps(ListProps(), {
|
||||||
dataSource: [],
|
dataSource: [],
|
||||||
prefixCls: 'ant-list',
|
|
||||||
bordered: false,
|
bordered: false,
|
||||||
split: true,
|
split: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -66,6 +66,9 @@ const List = {
|
||||||
listContext: this,
|
listContext: this,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
this.keys = [];
|
this.keys = [];
|
||||||
this.defaultPaginationProps = {
|
this.defaultPaginationProps = {
|
||||||
|
@ -86,15 +89,15 @@ const List = {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderItem2(item, index) {
|
renderItem2(item, index) {
|
||||||
const { dataSource, $scopedSlots, rowKey } = this;
|
const { $scopedSlots, rowKey } = this;
|
||||||
let key;
|
let key;
|
||||||
const renderItem = this.renderItem || $scopedSlots.renderItem;
|
const renderItem = this.renderItem || $scopedSlots.renderItem;
|
||||||
if (typeof rowKey === 'function') {
|
if (typeof rowKey === 'function') {
|
||||||
key = rowKey(dataSource[index]);
|
key = rowKey(item);
|
||||||
} else if (typeof rowKey === 'string') {
|
} else if (typeof rowKey === 'string') {
|
||||||
key = dataSource[rowKey];
|
key = item[rowKey];
|
||||||
} else {
|
} else {
|
||||||
key = dataSource.key;
|
key = item.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
|
@ -113,19 +116,23 @@ const List = {
|
||||||
return !!(loadMore || pagination || footer);
|
return !!(loadMore || pagination || footer);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderEmpty(contextLocale) {
|
renderEmpty(prefixCls, renderEmpty) {
|
||||||
const locale = { ...contextLocale, ...this.locale };
|
const locale = this;
|
||||||
return <div class={`${this.prefixCls}-empty-text`}>{locale.emptyText}</div>;
|
return (
|
||||||
|
<div class={`${prefixCls}-empty-text`}>
|
||||||
|
{(locale && locale.emptyText) || renderEmpty(h, 'List')}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
prefixCls: customizePrefixCls,
|
||||||
bordered,
|
bordered,
|
||||||
split,
|
split,
|
||||||
itemLayout,
|
itemLayout,
|
||||||
pagination,
|
pagination,
|
||||||
prefixCls,
|
|
||||||
grid,
|
grid,
|
||||||
dataSource,
|
dataSource,
|
||||||
size,
|
size,
|
||||||
|
@ -134,6 +141,9 @@ const List = {
|
||||||
$slots,
|
$slots,
|
||||||
paginationCurrent,
|
paginationCurrent,
|
||||||
} = this;
|
} = this;
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('list', customizePrefixCls);
|
||||||
|
|
||||||
const loadMore = getComponentFromProp(this, 'loadMore');
|
const loadMore = getComponentFromProp(this, 'loadMore');
|
||||||
const footer = getComponentFromProp(this, 'footer');
|
const footer = getComponentFromProp(this, 'footer');
|
||||||
const header = getComponentFromProp(this, 'header');
|
const header = getComponentFromProp(this, 'header');
|
||||||
|
@ -214,13 +224,11 @@ const List = {
|
||||||
|
|
||||||
childrenContent = grid ? <Row gutter={grid.gutter}>{childrenList}</Row> : childrenList;
|
childrenContent = grid ? <Row gutter={grid.gutter}>{childrenList}</Row> : childrenList;
|
||||||
} else if (!children.length && !isLoading) {
|
} else if (!children.length && !isLoading) {
|
||||||
childrenContent = (
|
const renderEmpty = (
|
||||||
<LocaleReceiver
|
this.configProvider.renderEmpty &&
|
||||||
componentName="Table"
|
this.configProvider.renderEmpty()
|
||||||
defaultLocale={defaultLocale.Table}
|
) || ConfigConsumerProps.renderEmpty;
|
||||||
scopedSlots={{ default: this.renderEmpty }}
|
childrenContent = this.renderEmpty(prefixCls, renderEmpty);
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const paginationPosition = paginationProps.position || 'bottom';
|
const paginationPosition = paginationProps.position || 'bottom';
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import '../../style/index.less';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
|
|
||||||
// style dependencies
|
// style dependencies
|
||||||
|
import '../../empty/style';
|
||||||
import '../../spin/style';
|
import '../../spin/style';
|
||||||
import '../../pagination/style';
|
import '../../pagination/style';
|
||||||
import '../../grid/style';
|
import '../../grid/style';
|
||||||
|
|
|
@ -5,6 +5,7 @@ import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import { getOptionProps } from '../_util/props-util';
|
import { getOptionProps } from '../_util/props-util';
|
||||||
import VcPagination from '../vc-pagination';
|
import VcPagination from '../vc-pagination';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
export const PaginationProps = () => ({
|
export const PaginationProps = () => ({
|
||||||
total: PropTypes.number,
|
total: PropTypes.number,
|
||||||
|
@ -41,12 +42,12 @@ export default {
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
...PaginationProps(),
|
...PaginationProps(),
|
||||||
prefixCls: PropTypes.string.def('ant-pagination'),
|
},
|
||||||
selectPrefixCls: PropTypes.string.def('ant-select'),
|
inject: {
|
||||||
|
configProvider: { default: () => ({}) },
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getIconsProps() {
|
getIconsProps(prefixCls) {
|
||||||
const { prefixCls } = this.$props;
|
|
||||||
const prevIcon = (
|
const prevIcon = (
|
||||||
<a class={`${prefixCls}-item-link`}>
|
<a class={`${prefixCls}-item-link`}>
|
||||||
<Icon type="left" />
|
<Icon type="left" />
|
||||||
|
@ -83,12 +84,25 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
renderPagination(contextLocale) {
|
renderPagination(contextLocale) {
|
||||||
const { buildOptionText, size, locale: customLocale, ...restProps } = getOptionProps(this);
|
const {
|
||||||
|
prefixCls: customizePrefixCls,
|
||||||
|
selectPrefixCls: customizeSelectPrefixCls,
|
||||||
|
buildOptionText,
|
||||||
|
size,
|
||||||
|
locale: customLocale,
|
||||||
|
...restProps
|
||||||
|
} = getOptionProps(this);
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('pagination', customizePrefixCls);
|
||||||
|
const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls);
|
||||||
|
|
||||||
const isSmall = size === 'small';
|
const isSmall = size === 'small';
|
||||||
const paginationProps = {
|
const paginationProps = {
|
||||||
props: {
|
props: {
|
||||||
|
prefixCls,
|
||||||
|
selectPrefixCls,
|
||||||
...restProps,
|
...restProps,
|
||||||
...this.getIconsProps(),
|
...this.getIconsProps(prefixCls),
|
||||||
selectComponentClass: isSmall ? MiniSelect : VcSelect,
|
selectComponentClass: isSmall ? MiniSelect : VcSelect,
|
||||||
locale: { ...contextLocale, ...customLocale },
|
locale: { ...contextLocale, ...customLocale },
|
||||||
buildOptionText: buildOptionText || this.$scopedSlots.buildOptionText,
|
buildOptionText: buildOptionText || this.$scopedSlots.buildOptionText,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
| hideOnSinglePage | Whether to hide pager on single page | boolean | false |
|
| hideOnSinglePage | Whether to hide pager on single page | boolean | false |
|
||||||
| itemRender | to customize item innerHTML | (page, type: 'page' \| 'prev' \| 'next', originalElement) => vNode | - |
|
| itemRender | to customize item innerHTML | (page, type: 'page' \| 'prev' \| 'next', originalElement) => vNode | - |
|
||||||
| pageSize(.sync) | number of data items per page | number | - |
|
| pageSize(.sync) | number of data items per page | number | - |
|
||||||
| pageSizeOptions | specify the sizeChanger options | string\[] | ['10', '20', '30', '40'] |
|
| pageSizeOptions | specify the sizeChanger options | string\[] | \['10', '20', '30', '40'] |
|
||||||
| showQuickJumper | determine whether you can jump to pages directly | boolean | false |
|
| showQuickJumper | determine whether you can jump to pages directly | boolean | false |
|
||||||
| showSizeChanger | determine whether `pageSize` can be changed | boolean | false |
|
| showSizeChanger | determine whether `pageSize` can be changed | boolean | false |
|
||||||
| showTotal | to display the total number and range | Function(total, range) | - |
|
| showTotal | to display the total number and range | Function(total, range) | - |
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
| hideOnSinglePage | 只有一页时是否隐藏分页器 | boolean | false |
|
| hideOnSinglePage | 只有一页时是否隐藏分页器 | boolean | false |
|
||||||
| itemRender | 用于自定义页码的结构,可用于优化 SEO | (page, type: 'page' \| 'prev' \| 'next', originalElement) => vNode | - |
|
| itemRender | 用于自定义页码的结构,可用于优化 SEO | (page, type: 'page' \| 'prev' \| 'next', originalElement) => vNode | - |
|
||||||
| pageSize(.sync) | 每页条数 | number | - |
|
| pageSize(.sync) | 每页条数 | number | - |
|
||||||
| pageSizeOptions | 指定每页可以显示多少条 | string\[] | ['10', '20', '30', '40'] |
|
| pageSizeOptions | 指定每页可以显示多少条 | string\[] | \['10', '20', '30', '40'] |
|
||||||
| showQuickJumper | 是否可以快速跳转至某页 | boolean | false |
|
| showQuickJumper | 是否可以快速跳转至某页 | boolean | false |
|
||||||
| showSizeChanger | 是否可以改变 pageSize | boolean | false |
|
| showSizeChanger | 是否可以改变 pageSize | boolean | false |
|
||||||
| showTotal | 用于显示数据总量和当前数据顺序 | Function(total, range) | - |
|
| showTotal | 用于显示数据总量和当前数据顺序 | Function(total, range) | - |
|
||||||
|
|
Loading…
Reference in New Issue