tdesign-vue
Version:
509 lines (505 loc) • 18.3 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-323b993c.js';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { PageFirstIcon, PageLastIcon, ChevronLeftIcon, ChevronRightIcon, ChevronLeftDoubleIcon, ChevronRightDoubleIcon, EllipsisIcon } from 'tdesign-icons-vue';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js';
import { InputNumber } from '../input-number/index.js';
import { Select, Option } from '../select/index.js';
import { InputAdornment } from '../input-adornment/index.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import props from './props.js';
import { emitEvent } from '../utils/event.js';
import { getIEVersion } from '../_common/js/utils/helper.js';
import 'vue';
import 'lodash-es';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-c44a474d.js';
import '../_chunks/dep-d639fbd7.js';
import 'dayjs';
import '../_chunks/dep-3c66615e.js';
import '../config-provider/type.js';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
import '@vue/composition-api';
import '../input-number/input-number.js';
import '../button/index.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/setStyle.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../config.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/readOnlyError';
import '../utils/withInstall.js';
import './style/index.js';
import '../loading/type.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import '../input/index.js';
import '../input/input.js';
import '../utils/helper.js';
import '../input/props.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../hooks/useCommonClassName.js';
import '../config-provider/useConfig.js';
import '../hooks/useVModel.js';
import '../_common/js/input-number/number.js';
import '../_common/js/input-number/large-number.js';
import '../hooks/useFormDisabled.js';
import '../hooks/useGlobalIcon.js';
import '../hooks/useConfig.js';
import '../input-number/type.js';
import '../select/select.js';
import '../hooks/useDefaultValue.js';
import '../hooks/tnode.js';
import '../hooks/render-tnode.js';
import '../select/props.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/utils.js';
import '../popup/type.js';
import '../popup/plugin.js';
import '../tag/index.js';
import '../tag/tag.js';
import 'tinycolor2';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../_common/js/common.js';
import '../hooks/index.js';
import '../hooks/slots.js';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useElementLazyRender.js';
import '../_common/js/utils/observe.js';
import '../hooks/useLazyLoad.js';
import '../hooks/useResizeObserver.js';
import '../hooks/useVirtualScrollNew.js';
import '../hooks/useImagePreviewUrl.js';
import '../_common/js/upload/utils.js';
import '../tag/check-tag-group.js';
import '../tag/check-tag-group-props.js';
import '../tag/type.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/type.js';
import '../tag-input/interface.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../checkbox/hooks/useKeyboardEvent.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../select/util.js';
import '../select/select-panel.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../hooks/useVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../select/type.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../input-adornment/type.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var min = 1;
var PaginationBase = mixins(getConfigReceiverMixins("pagination"), getGlobalIconMixins()).extend({
name: "TPagination",
components: {
TInputNumber: InputNumber,
TInputAdornment: InputAdornment,
TSelect: Select,
TOption: Option
},
props: _objectSpread(_objectSpread({}, props), {}, {
current: {
type: Number,
"default": 1,
validator: function validator(v) {
return v > 0;
}
},
pageSize: {
type: Number,
"default": 10,
validator: function validator(v) {
return v > 0;
}
}
}),
data: function data() {
return {
prevMore: false,
nextMore: false,
jumpIndex: this.current
};
},
watch: {
current: function current(val) {
this.jumpIndex = val;
}
},
computed: {
paginationClass: function paginationClass() {
return ["".concat(this.componentName), this.commonSizeClassName[this.size], _defineProperty(_defineProperty({}, this.commonStatusClassName.disabled, this.disabled), "".concat(this.componentName, "-ie"), getIEVersion() < 11)];
},
totalClass: function totalClass() {
return ["".concat(this.componentName, "__total")];
},
sizerClass: function sizerClass() {
return ["".concat(this.componentName, "__select")];
},
preBtnClass: function preBtnClass() {
return ["".concat(this.componentName, "__btn"), "".concat(this.componentName, "__btn-prev"), _defineProperty({}, this.commonStatusClassName.disabled, this.disabled || this.current === 1)];
},
nextBtnClass: function nextBtnClass() {
return ["".concat(this.componentName, "__btn"), "".concat(this.componentName, "__btn-next"), _defineProperty({}, this.commonStatusClassName.disabled, this.disabled || this.current === this.pageCount)];
},
btnWrapClass: function btnWrapClass() {
return ["".concat(this.componentName, "__pager")];
},
btnMoreClass: function btnMoreClass() {
return ["".concat(this.componentName, "__number"), "".concat(this.componentName, "__number--more"), _defineProperty({}, this.commonStatusClassName.disabled, this.disabled)];
},
jumperClass: function jumperClass() {
return ["".concat(this.componentName, "__jump")];
},
jumperInputClass: function jumperInputClass() {
return ["".concat(this.componentName, "__input")];
},
pageCount: function pageCount() {
var c = Math.ceil(this.total / this.pageSize);
return c > 0 ? c : 1;
},
sizeOptions: function sizeOptions() {
var _this = this;
var options = this.pageSizeOptions.map(function (option) {
return _typeof(option) === "object" ? option : {
label: _this.t(_this.global.itemsPerPage, {
size: option
}),
value: Number(option)
};
});
return options.sort(function (a, b) {
return a.value - b.value;
});
},
curPageLeftCount: function curPageLeftCount() {
return Math.ceil((this.foldedMaxPageBtn - 1) / 2);
},
curPageRightCount: function curPageRightCount() {
return Math.ceil((this.foldedMaxPageBtn - 1) / 2);
},
isPrevMoreShow: function isPrevMoreShow() {
return 2 + this.curPageLeftCount < this.current;
},
isNextMoreShow: function isNextMoreShow() {
return this.pageCount - 1 - this.curPageRightCount > this.current;
},
pages: function pages() {
var array = [];
var start;
var end;
if (this.isFolded) {
if (this.isPrevMoreShow && this.isNextMoreShow) {
start = this.current - this.curPageLeftCount;
end = this.current + this.curPageRightCount;
} else {
var foldedStart = this.isMidEllipsis ? 2 : 1;
var foldedEnd = this.isMidEllipsis ? this.pageCount - 1 : this.pageCount;
start = this.isPrevMoreShow ? this.pageCount - this.foldedMaxPageBtn + 1 : foldedStart;
end = this.isPrevMoreShow ? foldedEnd : this.foldedMaxPageBtn;
}
} else {
start = 1;
end = this.pageCount;
}
for (var i = start; i <= end; i++) {
array.push(i);
}
return array;
},
isFolded: function isFolded() {
return this.pageCount > this.maxPageBtn;
},
isMidEllipsis: function isMidEllipsis() {
return this.pageEllipsisMode === "mid";
}
},
methods: {
toPage: function toPage(pageIndex, isTriggerChange) {
if (this.disabled) {
return;
}
var current = pageIndex;
if (pageIndex < min) {
current = min;
} else if (pageIndex > this.pageCount) {
current = this.pageCount;
}
if (this.current !== current) {
var prev = this.current;
var pageInfo = {
current: current,
previous: prev,
pageSize: this.pageSize
};
emitEvent(this, "current-change", current, pageInfo);
if (isTriggerChange !== false) {
emitEvent(this, "change", pageInfo);
}
}
},
prevPage: function prevPage() {
this.toPage(this.current - 1);
},
nextPage: function nextPage() {
this.toPage(this.current + 1);
},
prevMorePage: function prevMorePage() {
this.toPage(this.current - this.foldedMaxPageBtn);
},
nextMorePage: function nextMorePage() {
this.toPage(this.current + this.foldedMaxPageBtn);
},
getButtonClass: function getButtonClass(index) {
return ["".concat(this.componentName, "__number"), _defineProperty(_defineProperty({}, this.commonStatusClassName.disabled, this.disabled), this.commonStatusClassName.current, this.current === index)];
},
onSelectorChange: function onSelectorChange(e) {
if (this.disabled) {
return;
}
var pageSize = parseInt(e, 10);
var pageCount = 1;
if (pageSize > 0 && this.total > 0) {
pageCount = Math.ceil(this.total / pageSize);
}
var isIndexChange = false;
if (this.current > pageCount) {
isIndexChange = true;
}
var pageInfo = {
current: isIndexChange ? pageCount : this.current,
previous: this.current,
pageSize: pageSize
};
this.$emit("update:pageSize", pageSize, pageInfo);
emitEvent(this, "page-size-change", pageSize, pageInfo);
emitEvent(this, "change", pageInfo);
if (isIndexChange) {
this.toPage(pageCount, false);
}
},
onJumperChange: function onJumperChange(val) {
var currentIndex = Number(val);
if (isNaN(currentIndex)) return;
this.toPage(currentIndex);
}
},
render: function render() {
var _this2 = this;
var h = arguments[0];
var _this$useGlobalIcon = this.useGlobalIcon({
PageFirstIcon: PageFirstIcon,
PageLastIcon: PageLastIcon,
ChevronLeftIcon: ChevronLeftIcon,
ChevronRightIcon: ChevronRightIcon,
ChevronLeftDoubleIcon: ChevronLeftDoubleIcon,
ChevronRightDoubleIcon: ChevronRightDoubleIcon,
EllipsisIcon: EllipsisIcon
}),
PageFirstIcon$1 = _this$useGlobalIcon.PageFirstIcon,
PageLastIcon$1 = _this$useGlobalIcon.PageLastIcon,
ChevronLeftIcon$1 = _this$useGlobalIcon.ChevronLeftIcon,
ChevronRightIcon$1 = _this$useGlobalIcon.ChevronRightIcon,
ChevronLeftDoubleIcon$1 = _this$useGlobalIcon.ChevronLeftDoubleIcon,
ChevronRightDoubleIcon$1 = _this$useGlobalIcon.ChevronRightDoubleIcon,
EllipsisIcon$1 = _this$useGlobalIcon.EllipsisIcon;
var Jumper = h("div", {
"class": this.jumperClass
}, [this.t(this.global.jumpTo), h("t-input-adornment", {
"attrs": {
"append": "/ ".concat(this.pageCount, " ").concat(this.t(this.global.page))
}
}, [h("t-input-number", {
"class": this.jumperInputClass,
"on": {
"blur": this.onJumperChange,
"enter": this.onJumperChange
},
"attrs": {
"max": this.pageCount,
"min": min,
"size": this.size,
"theme": "normal",
"placeholder": ""
},
"model": {
value: _this2.jumpIndex,
callback: function callback($$v) {
_this2.jumpIndex = $$v;
}
}
})])]);
return h("div", {
"class": this.paginationClass
}, [renderTNodeJSX(this, "totalContent", h("div", {
"class": this.totalClass
}, [this.t(this.global.total, this.total)])), this.showPageSize && this.pageSizeOptions.length ? h("t-select", helper([{
"attrs": {
"size": this.size,
"value": this.pageSize,
"disabled": this.disabled,
"autoWidth": true
},
"class": this.sizerClass,
"on": {
"change": this.onSelectorChange
}
}, {
"props": this.selectProps || {}
}]), [this.sizeOptions.map(function (item, index) {
return h("t-option", {
"attrs": {
"value": item.value,
"label": item.label
},
"key": index
});
})]) : null, this.showFirstAndLastPageBtn ? h("div", {
"class": this.preBtnClass,
"on": {
"click": function click() {
return _this2.toPage(1);
}
},
"attrs": {
"disabled": this.disabled || this.current === min
}
}, [h(PageFirstIcon$1)]) : null, this.showPreviousAndNextBtn ? h("div", {
"class": this.preBtnClass,
"on": {
"click": this.prevPage
},
"attrs": {
"disabled": this.disabled || this.current === min
}
}, [h(ChevronLeftIcon$1)]) : null, this.showPageNumber && this.theme === "default" ? h("ul", {
"class": this.btnWrapClass
}, [this.isFolded && this.isMidEllipsis ? h("li", {
"class": this.getButtonClass(1),
"on": {
"click": function click() {
return _this2.toPage(min);
}
}
}, [min]) : null, this.isFolded && this.isPrevMoreShow && this.isMidEllipsis ? h("li", {
"class": this.btnMoreClass,
"on": {
"click": this.prevMorePage,
"mouseenter": function mouseenter() {
return _this2.prevMore = true;
},
"mouseleave": function mouseleave() {
return _this2.prevMore = false;
}
}
}, [this.prevMore ? h(ChevronLeftDoubleIcon$1) : h(EllipsisIcon$1)]) : null, this.pages.map(function (i) {
return h("li", {
"class": _this2.getButtonClass(i),
"key": i,
"on": {
"click": function click() {
return _this2.toPage(i);
}
}
}, [i]);
}), this.isFolded && this.isNextMoreShow && this.isMidEllipsis ? h("li", {
"class": this.btnMoreClass,
"on": {
"click": this.nextMorePage,
"mouseenter": function mouseenter() {
return _this2.nextMore = true;
},
"mouseleave": function mouseleave() {
return _this2.nextMore = false;
}
}
}, [this.nextMore ? h(ChevronRightDoubleIcon$1) : h(EllipsisIcon$1)]) : null, this.isFolded && this.isMidEllipsis ? h("li", {
"class": this.getButtonClass(this.pageCount),
"on": {
"click": function click() {
return _this2.toPage(_this2.pageCount);
}
}
}, [this.pageCount]) : null]) : null, this.theme === "simple" && Jumper, this.showPreviousAndNextBtn ? h("div", {
"class": this.nextBtnClass,
"on": {
"click": this.nextPage
},
"attrs": {
"disabled": this.disabled || this.current === this.pageCount
}
}, [h(ChevronRightIcon$1)]) : null, this.showFirstAndLastPageBtn ? h("div", {
"class": this.nextBtnClass,
"on": {
"click": function click() {
return _this2.toPage(_this2.pageCount);
}
},
"attrs": {
"disabled": this.disabled || this.current === this.pageCount
}
}, [h(PageLastIcon$1)]) : null, this.theme === "default" && this.showJumper && Jumper]);
}
});
export { PaginationBase as default };
//# sourceMappingURL=pagination.js.map