UNPKG

tdesign-vue

Version:
582 lines (578 loc) 21.2 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import { h as helper } from '../../_chunks/dep-323b993c.js'; import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _typeof from '@babel/runtime/helpers/typeof'; import mixins from '../../utils/mixins.js'; import { Pagination } from '../../pagination/index.js'; import { Checkbox, CheckboxGroup } from '../../checkbox/index.js'; import { filterTreeData, getDataValues, getLeafCount, findTopNode, TARGET } from '../utils.js'; import Ripple from '../../utils/ripple.js'; import Search from './transfer-search.js'; import { renderTNodeJSXDefault } from '../../utils/render-tnode.js'; import { getClassPrefixMixins, getKeepAnimationMixins } from '../../config-provider/config-receiver.js'; import props from '../props.js'; import 'vue'; import '../../pagination/pagination.js'; import 'tdesign-icons-vue'; import '../../input-number/index.js'; 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 'lodash-es'; 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 '../../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../../utils/dom.js'; import 'raf'; import '../../utils/easing.js'; import '../../utils/transfer-dom.js'; import '../../loading/props.js'; import '@babel/runtime/helpers/readOnlyError'; 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 '../../config.js'; import '../../utils/withInstall.js'; import './style/css.js'; import '../../loading/type.js'; import '../../button/props.js'; import '../../button/type.js'; import '../../input/index.js'; import '../../input/input.js'; import '../../utils/helper.js'; import '../../utils/event.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/index.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 '../../select/util.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/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/index.js'; import '../../input-adornment/input-adornment.js'; import '../../input-adornment/props.js'; import '../../input-adornment/type.js'; import '../../pagination/props.js'; import '../../pagination/pagination-mini.js'; import '../../pagination/pagination-mini-props.js'; import '../../pagination/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 classPrefixMixins = getClassPrefixMixins("transfer"); var keepAnimationMixins = getKeepAnimationMixins(); var TransferList = mixins(keepAnimationMixins, classPrefixMixins).extend({ name: "TTransferList", components: { Search: Search, TCheckbox: Checkbox, TCheckboxGroup: CheckboxGroup }, directives: { ripple: Ripple }, props: { checkboxProps: { type: Object, "default": function _default() { return {}; } }, dataSource: { type: Array, "default": function _default() { return []; } }, listType: { type: String, "default": "target" }, title: { type: [String, Function] }, checkedValue: { type: Array, "default": function _default() { return []; } }, disabled: { type: Boolean, "default": false }, search: { type: [Boolean, Object], "default": false }, transferItem: Function, empty: { type: [Function, String] }, pagination: [Boolean, Object], footer: [Function, String], checkAll: Boolean, t: Function, global: Object, tree: props.tree, isTreeMode: { type: Boolean, "default": false }, draggable: Boolean, currentValue: { type: Array } }, data: function data() { return { filterValue: "", defaultCurrent: null, defaultPageSize: null, draggingIndex: null, dragoverIndex: null, dragoverPos: "" }; }, computed: { currentPage: function currentPage() { var _ref, _ref2, _this$pagination$curr, _this$pagination, _this$pagination2; return (_ref = (_ref2 = (_this$pagination$curr = (_this$pagination = this.pagination) === null || _this$pagination === void 0 ? void 0 : _this$pagination.current) !== null && _this$pagination$curr !== void 0 ? _this$pagination$curr : this.defaultCurrent) !== null && _ref2 !== void 0 ? _ref2 : (_this$pagination2 = this.pagination) === null || _this$pagination2 === void 0 ? void 0 : _this$pagination2.defaultCurrent) !== null && _ref !== void 0 ? _ref : 1; }, pageSize: function pageSize() { var _ref3, _ref4, _this$pagination$page, _this$pagination3, _this$pagination4; return (_ref3 = (_ref4 = (_this$pagination$page = (_this$pagination3 = this.pagination) === null || _this$pagination3 === void 0 ? void 0 : _this$pagination3.pageSize) !== null && _this$pagination$page !== void 0 ? _this$pagination$page : this.defaultPageSize) !== null && _ref4 !== void 0 ? _ref4 : (_this$pagination4 = this.pagination) === null || _this$pagination4 === void 0 ? void 0 : _this$pagination4.defaultPageSize) !== null && _ref3 !== void 0 ? _ref3 : 10; }, pageTotal: function pageTotal() { return this.filteredData && this.filteredData.length || 0; }, filteredData: function filteredData() { var _this = this; if (!this.isTreeMode) { return this.dataSource.filter(function (item) { var label = item && item.label.toString(); return label.toLowerCase().indexOf(_this.filterValue.toLowerCase()) > -1; }); } return filterTreeData(this.dataSource, this.filterValue); }, curPageData: function curPageData() { var pageData = this.filteredData; if (!this.pagination) return pageData; if (this.pageSize === 0) return pageData; var startIndex = (this.currentPage - 1) * this.pageSize; var endIndex = this.currentPage * this.pageSize; pageData = pageData.slice(startIndex, endIndex); return pageData; }, paginationProps: function paginationProps() { var defaultPaginationProps = { totalContent: false, pageSizeOptions: [] }; return _typeof(this.pagination) === "object" ? _objectSpread(_objectSpread(_objectSpread({}, defaultPaginationProps), this.pagination), {}, { size: "small", theme: "simple", current: this.currentPage, total: this.pageTotal, pageSize: this.pageSize }) : {}; }, hasFooter: function hasFooter() { return !!this.$slots["default"]; }, indeterminate: function indeterminate() { return !this.isAllChecked && this.checkedValue.length > 0; }, isAllChecked: function isAllChecked() { var _this2 = this; var allValue = getDataValues(this.dataSource, [], { isTreeMode: this.isTreeMode, include: false }); return this.checkedValue.length > 0 && (this.isTreeMode ? allValue.every(function (item) { return _this2.checkedValue.includes(item); }) : (this.search ? this.filteredData : this.dataSource).every(function (item) { return item.disabled || _this2.checkedValue.includes(item.value); })); }, totalCount: function totalCount() { return getLeafCount(this.dataSource); } }, watch: { totalCount: function totalCount(val) { if (val <= (this.currentPage - 1) * this.pageSize && val !== 0) { var lastPage = Math.ceil(val / this.pageSize); this.defaultCurrent = lastPage; } } }, methods: { handlePaginationChange: function handlePaginationChange(pageInfo) { this.$emit("pageChange", pageInfo); this.defaultCurrent = pageInfo.current; this.defaultPageSize = pageInfo.pageSize; }, handleCheckedChange: function handleCheckedChange(val) { this.$emit("checkedChange", val); }, handleCheckedAllChange: function handleCheckedAllChange(checked) { if (checked) { var allValue = getDataValues(this.search ? this.filteredData : this.dataSource, [], { isTreeMode: this.isTreeMode, include: false }); this.handleCheckedChange(allValue); } else { this.handleCheckedChange([]); } }, scroll: function scroll(e) { this.$emit("scroll", e); }, handleSearch: function handleSearch(e) { var event = { query: e.value, type: this.listType, e: e.e, trigger: e.trigger }; this.$emit("search", event); }, onDragStart: function onDragStart(e) { var index = Number(e.target.dataset.index); this.draggingIndex = index; }, onDragOver: function onDragOver(e) { e.preventDefault(); if (e.currentTarget) { var currentElement = e.currentTarget; var index = Number(currentElement.dataset.index); var elemHeight = currentElement.offsetHeight; var dragY = e.clientY - currentElement.getBoundingClientRect().top; var insertAreaPercent = 0.3; var insertAreaHeight = elemHeight * insertAreaPercent; this.dragoverIndex = index; if (this.dragoverIndex === this.draggingIndex) { this.dragoverPos = ""; return; } if (dragY < insertAreaHeight) { this.dragoverPos = "top"; } else if (dragY > elemHeight - insertAreaHeight) { this.dragoverPos = "bottom"; } else { this.dragoverPos = "center"; } } }, onDragLeave: function onDragLeave() { this.dragoverPos = ""; this.dragoverIndex = null; }, onDragEnd: function onDragEnd() { this.draggingIndex = null; this.dragoverIndex = null; this.dragoverPos = ""; }, onDrop: function onDrop(e) { e.preventDefault(); var draggingIndex = this.draggingIndex, dragoverIndex = this.dragoverIndex, dragoverPos = this.dragoverPos; this.draggingIndex = null; this.dragoverIndex = null; this.dragoverPos = ""; if (draggingIndex === dragoverIndex) { return; } var newData = _toConsumableArray(this.currentValue); var sourceItem = this.curPageData[draggingIndex].value; var targetItem = this.curPageData[dragoverIndex].value; var sourceIndex = newData.indexOf(sourceItem); var targetIndex = newData.indexOf(targetItem); newData.splice(sourceIndex, 1); if (dragoverPos === "bottom") { targetIndex += 1; } newData.splice(targetIndex, 0, sourceItem); this.$emit("dataChange", newData); }, renderTitle: function renderTitle() { var h = this.$createElement; var defaultNode = this.title && typeof this.title === "string" ? h("template", [this.title]) : null; var titleNode = renderTNodeJSXDefault(this, "title", { defaultNode: defaultNode, params: { type: this.listType } }); return h("span", [titleNode]); }, renderContent: function renderContent() { var _this3 = this; var h = this.$createElement; var rootNode = findTopNode(this); var isDraggable = this.draggable && this.listType === TARGET; var defaultNode; if (!isDraggable) { defaultNode = h(CheckboxGroup, { "attrs": { "value": this.checkedValue }, "on": { "change": this.handleCheckedChange } }, [this.curPageData.map(function (item, index) { return h(Checkbox, { "attrs": { "disabled": _this3.disabled || item.disabled, "value": item.value }, "class": ["".concat(_this3.componentName, "__list-item")], "key": item.key, "directives": [{ name: "ripple", value: _this3.keepAnimation.ripple && !_this3.draggable }], "props": _objectSpread({}, _this3.checkboxProps) }, [renderTNodeJSXDefault(_this3, "transferItem", { defaultNode: h("span", [item.label]), params: { data: item.data, index: index, type: _this3.listType } })]); })]); } else { defaultNode = h(CheckboxGroup, { "attrs": { "value": this.checkedValue }, "on": { "change": this.handleCheckedChange }, "key": JSON.stringify(this.currentValue) }, [this.curPageData.map(function (item, index) { return h("div", { "attrs": { "draggable": isDraggable, "data-index": index }, "on": { "dragend": _this3.onDragEnd, "dragstart": _this3.onDragStart, "dragover": _this3.onDragOver, "dragleave": _this3.onDragLeave, "drop": _this3.onDrop } }, [h(Checkbox, { "attrs": { "disabled": _this3.disabled || item.disabled, "value": item.value }, "class": ["".concat(_this3.componentName, "__list-item")], "key": item.key, "directives": [{ name: "ripple", value: _this3.keepAnimation.ripple && !_this3.draggable }], "props": _objectSpread({}, _this3.checkboxProps) }, [renderTNodeJSXDefault(_this3, "transferItem", { defaultNode: h("span", [item.label]), params: { data: item.data, index: index, type: _this3.listType } })])]); })]); } return h("div", { "class": "".concat(this.componentName, "__list-content narrow-scrollbar"), "on": { "scroll": this.scroll } }, [renderTNodeJSXDefault(rootNode, "tree", { defaultNode: defaultNode, params: { data: this.curPageData, value: this.checkedValue, onChange: this.handleCheckedChange } })]); }, renderEmpty: function renderEmpty() { var h = this.$createElement; var empty = this.empty || this.t(this.global.empty); var defaultNode = typeof empty === "string" ? h("span", [empty]) : null; return h("div", { "class": "".concat(this.componentName, "__empty") }, [renderTNodeJSXDefault(this, "empty", { defaultNode: defaultNode, params: { type: this.listType } })]); }, renderFooter: function renderFooter() { var h = this.$createElement; var defaultNode = typeof this.footer === "string" ? h("div", { "class": "".concat(this.componentName, "__footer") }, [this.footer]) : null; return renderTNodeJSXDefault(this, "footer", { defaultNode: defaultNode, params: { type: this.listType } }); } }, render: function render() { var _this4 = this; var h = arguments[0]; return h("div", { "class": "".concat(this.componentName, "__list ").concat(this.componentName, "__list-").concat(this.listType) }, [h("div", { "class": "".concat(this.componentName, "__list-header") }, [h("div", [this.checkAll && h(Checkbox, { "attrs": { "disabled": this.disabled || !this.dataSource.length, "checked": this.isAllChecked, "indeterminate": this.indeterminate }, "on": { "change": this.handleCheckedAllChange } }), h("span", [this.t(this.global.title, { checked: this.checkedValue.length, total: this.totalCount })])]), this.renderTitle()]), h("div", { "class": ["".concat(this.componentName, "__list-body"), this.search ? "".concat(this.componentName, "__list--with-search") : ""] }, [this.search && h("search", { "attrs": { "searchValue": this.filterValue, "placeholder": this.t(this.global.placeholder), "disabled": this.disabled, "search": this.search, "classPrefix": this.classPrefix }, "on": { "change": function change(e) { return _this4.filterValue = e; }, "search": this.handleSearch } }), this.curPageData.length > 0 ? this.renderContent() : this.renderEmpty()]), this.pagination && this.pageSize > 0 && this.pageTotal > 0 && h("div", { "class": "".concat(this.componentName, "__list-pagination") }, [h(Pagination, helper([{}, { "props": this.paginationProps }, { "on": { "change": this.handlePaginationChange } }]))]), this.renderFooter()]); } }); export { TransferList as default }; //# sourceMappingURL=transfer-list.js.map