2023-02-13 20:21:29 +08:00
|
|
|
import type { CSSProperties, ExtractPropTypes } from 'vue';
|
2022-05-22 10:35:19 +08:00
|
|
|
import { computed, watchEffect, defineComponent, ref, watch, toRaw } from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { getPropsSlot } from '../_util/props-util';
|
2020-08-31 16:53:19 +08:00
|
|
|
import classNames from '../_util/classNames';
|
2019-01-12 11:33:27 +08:00
|
|
|
import List from './list';
|
|
|
|
import Operation from './operation';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2023-05-18 23:23:43 +08:00
|
|
|
|
2023-01-28 08:53:47 +08:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2023-05-18 23:23:43 +08:00
|
|
|
import type { VueNode, CustomSlotsType } from '../_util/type';
|
2023-02-13 20:21:29 +08:00
|
|
|
import {
|
|
|
|
withInstall,
|
|
|
|
stringType,
|
|
|
|
arrayType,
|
|
|
|
someType,
|
|
|
|
booleanType,
|
|
|
|
objectType,
|
|
|
|
functionType,
|
|
|
|
} from '../_util/type';
|
2023-01-27 16:00:17 +08:00
|
|
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
2023-05-18 23:23:43 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
import type { TransferListBodyProps } from './ListBody';
|
|
|
|
import type { PaginationType } from './interface';
|
2022-05-22 10:35:19 +08:00
|
|
|
import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItemContext';
|
2022-03-12 09:56:32 +08:00
|
|
|
import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
|
2022-05-22 10:35:19 +08:00
|
|
|
import type { InputStatus } from '../_util/statusUtils';
|
|
|
|
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
|
2023-02-13 20:46:02 +08:00
|
|
|
import { groupKeysMap, groupDisabledKeysMap } from '../_util/transKeys';
|
2023-02-13 20:21:29 +08:00
|
|
|
// CSSINJS
|
|
|
|
import useStyle from './style';
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export type { TransferListProps } from './list';
|
|
|
|
export type { TransferOperationProps } from './operation';
|
|
|
|
export type { TransferSearchProps } from './search';
|
2019-01-12 11:33:27 +08:00
|
|
|
|
2020-10-20 16:45:49 +08:00
|
|
|
export type TransferDirection = 'left' | 'right';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export interface RenderResultObject {
|
|
|
|
label: VueNode;
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type RenderResult = VueNode | RenderResultObject | string | null;
|
|
|
|
|
|
|
|
export interface TransferItem {
|
|
|
|
key?: string;
|
|
|
|
title?: string;
|
|
|
|
description?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
[name: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type KeyWise<T> = T & { key: string };
|
|
|
|
|
|
|
|
export type KeyWiseTransferItem = KeyWise<TransferItem>;
|
|
|
|
|
|
|
|
type TransferRender<RecordType> = (item: RecordType) => RenderResult;
|
|
|
|
|
|
|
|
export interface ListStyle {
|
|
|
|
direction: TransferDirection;
|
|
|
|
}
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export type SelectAllLabel =
|
|
|
|
| VueNode
|
|
|
|
| ((info: { selectedCount: number; totalCount: number }) => VueNode);
|
|
|
|
|
|
|
|
export interface TransferLocale {
|
2023-02-13 20:46:02 +08:00
|
|
|
titles?: VueNode[];
|
2021-09-25 16:51:32 +08:00
|
|
|
notFoundContent?: VueNode;
|
|
|
|
searchPlaceholder: string;
|
|
|
|
itemUnit: string;
|
|
|
|
itemsUnit: string;
|
2023-02-13 20:46:02 +08:00
|
|
|
remove?: string;
|
|
|
|
selectAll?: string;
|
|
|
|
selectCurrent?: string;
|
|
|
|
selectInvert?: string;
|
|
|
|
removeAll?: string;
|
|
|
|
removeCurrent?: string;
|
2021-09-25 16:51:32 +08:00
|
|
|
}
|
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
export const transferProps = () => ({
|
2021-09-25 16:51:32 +08:00
|
|
|
id: String,
|
|
|
|
prefixCls: String,
|
2023-02-13 20:21:29 +08:00
|
|
|
dataSource: arrayType<TransferItem[]>([]),
|
|
|
|
disabled: booleanType(),
|
|
|
|
targetKeys: arrayType<string[]>(),
|
|
|
|
selectedKeys: arrayType<string[]>(),
|
|
|
|
render: functionType<TransferRender<TransferItem>>(),
|
|
|
|
listStyle: someType<((style: ListStyle) => CSSProperties) | CSSProperties>(
|
|
|
|
[Function, Object],
|
|
|
|
() => ({}),
|
|
|
|
),
|
|
|
|
operationStyle: objectType<CSSProperties>(undefined as CSSProperties),
|
|
|
|
titles: arrayType<string[]>(),
|
|
|
|
operations: arrayType<string[]>(),
|
|
|
|
showSearch: booleanType(false),
|
|
|
|
filterOption: functionType<(inputValue: string, item: TransferItem) => boolean>(),
|
2021-09-25 16:51:32 +08:00
|
|
|
searchPlaceholder: String,
|
2018-04-07 00:20:45 +08:00
|
|
|
notFoundContent: PropTypes.any,
|
2023-02-13 20:21:29 +08:00
|
|
|
locale: objectType(),
|
|
|
|
rowKey: functionType<(record: TransferItem) => string>(),
|
|
|
|
showSelectAll: booleanType(),
|
|
|
|
selectAllLabels: arrayType<SelectAllLabel[]>(),
|
|
|
|
children: functionType<(props: TransferListBodyProps) => VueNode>(),
|
|
|
|
oneWay: booleanType(),
|
|
|
|
pagination: someType<PaginationType>([Object, Boolean]),
|
|
|
|
status: stringType<InputStatus>(),
|
|
|
|
onChange:
|
|
|
|
functionType<
|
|
|
|
(targetKeys: string[], direction: TransferDirection, moveKeys: string[]) => void
|
|
|
|
>(),
|
2023-02-13 20:46:02 +08:00
|
|
|
onSelectChange:
|
|
|
|
functionType<(sourceSelectedKeys: string[], targetSelectedKeys: string[]) => void>(),
|
2023-02-13 20:21:29 +08:00
|
|
|
onSearch: functionType<(direction: TransferDirection, value: string) => void>(),
|
|
|
|
onScroll: functionType<(direction: TransferDirection, e: UIEvent) => void>(),
|
|
|
|
'onUpdate:targetKeys': functionType<(keys: string[]) => void>(),
|
|
|
|
'onUpdate:selectedKeys': functionType<(keys: string[]) => void>(),
|
2022-03-26 22:52:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export type TransferProps = Partial<ExtractPropTypes<ReturnType<typeof transferProps>>>;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2020-10-20 16:45:49 +08:00
|
|
|
const Transfer = defineComponent({
|
2022-09-26 21:33:41 +08:00
|
|
|
compatConfig: { MODE: 3 },
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ATransfer',
|
2020-11-07 15:37:17 +08:00
|
|
|
inheritAttrs: false,
|
2022-03-26 22:52:54 +08:00
|
|
|
props: transferProps(),
|
2023-05-18 21:22:58 +08:00
|
|
|
slots: Object as CustomSlotsType<{
|
|
|
|
leftTitle?: any;
|
|
|
|
rightTitle?: any;
|
|
|
|
children?: any;
|
|
|
|
render?: TransferItem;
|
|
|
|
notFoundContent?: any;
|
|
|
|
leftSelectAllLabel?: any;
|
|
|
|
rightSelectAllLabel?: any;
|
|
|
|
footer?: any;
|
|
|
|
default?: any;
|
|
|
|
}>,
|
2022-03-26 22:52:54 +08:00
|
|
|
// emits: ['update:targetKeys', 'update:selectedKeys', 'change', 'search', 'scroll', 'selectChange'],
|
2021-09-25 16:51:32 +08:00
|
|
|
setup(props, { emit, attrs, slots, expose }) {
|
|
|
|
const { configProvider, prefixCls, direction } = useConfigInject('transfer', props);
|
2023-02-13 20:21:29 +08:00
|
|
|
|
|
|
|
// style
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const sourceSelectedKeys = ref([]);
|
|
|
|
const targetSelectedKeys = ref([]);
|
|
|
|
|
|
|
|
const formItemContext = useInjectFormItemContext();
|
2022-05-22 10:35:19 +08:00
|
|
|
const formItemInputContext = FormItemInputContext.useInject();
|
|
|
|
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
|
2021-09-25 16:51:32 +08:00
|
|
|
watch(
|
|
|
|
() => props.selectedKeys,
|
|
|
|
() => {
|
|
|
|
sourceSelectedKeys.value =
|
|
|
|
props.selectedKeys?.filter(key => props.targetKeys.indexOf(key) === -1) || [];
|
|
|
|
targetSelectedKeys.value =
|
|
|
|
props.selectedKeys?.filter(key => props.targetKeys.indexOf(key) > -1) || [];
|
|
|
|
},
|
|
|
|
{ immediate: true },
|
|
|
|
);
|
2020-03-07 19:45:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const getLocale = (transferLocale: TransferLocale, renderEmpty: RenderEmptyHandler) => {
|
2020-03-07 19:45:13 +08:00
|
|
|
// Keep old locale props still working.
|
2020-10-20 16:45:49 +08:00
|
|
|
const oldLocale: { notFoundContent?: any; searchPlaceholder?: string } = {
|
2020-07-18 21:40:26 +08:00
|
|
|
notFoundContent: renderEmpty('Transfer'),
|
2020-03-07 19:45:13 +08:00
|
|
|
};
|
2021-09-25 16:51:32 +08:00
|
|
|
const notFoundContent = getPropsSlot(slots, props, 'notFoundContent');
|
2020-03-07 19:45:13 +08:00
|
|
|
if (notFoundContent) {
|
|
|
|
oldLocale.notFoundContent = notFoundContent;
|
|
|
|
}
|
2021-09-25 16:51:32 +08:00
|
|
|
if (props.searchPlaceholder !== undefined) {
|
|
|
|
oldLocale.searchPlaceholder = props.searchPlaceholder;
|
2020-03-07 19:45:13 +08:00
|
|
|
}
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
return { ...transferLocale, ...oldLocale, ...props.locale };
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const moveTo = (direction: TransferDirection) => {
|
|
|
|
const { targetKeys = [], dataSource = [] } = props;
|
|
|
|
const moveKeys = direction === 'right' ? sourceSelectedKeys.value : targetSelectedKeys.value;
|
2023-02-13 20:46:02 +08:00
|
|
|
const dataSourceDisabledKeysMap = groupDisabledKeysMap(dataSource);
|
2018-04-07 00:20:45 +08:00
|
|
|
// filter the disabled options
|
2023-02-13 20:46:02 +08:00
|
|
|
const newMoveKeys = moveKeys.filter(key => !dataSourceDisabledKeysMap.has(key));
|
|
|
|
const newMoveKeysMap = groupKeysMap(newMoveKeys);
|
|
|
|
|
2018-04-07 00:20:45 +08:00
|
|
|
// move items to target box
|
2019-01-12 11:33:27 +08:00
|
|
|
const newTargetKeys =
|
|
|
|
direction === 'right'
|
|
|
|
? newMoveKeys.concat(targetKeys)
|
2023-02-13 20:46:02 +08:00
|
|
|
: targetKeys.filter(targetKey => !newMoveKeysMap.has(targetKey));
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
// empty checked keys
|
2019-01-12 11:33:27 +08:00
|
|
|
const oppositeDirection = direction === 'right' ? 'left' : 'right';
|
2021-09-25 16:51:32 +08:00
|
|
|
direction === 'right' ? (sourceSelectedKeys.value = []) : (targetSelectedKeys.value = []);
|
|
|
|
emit('update:targetKeys', newTargetKeys);
|
|
|
|
handleSelectChange(oppositeDirection, []);
|
|
|
|
emit('change', newTargetKeys, direction, newMoveKeys);
|
|
|
|
formItemContext.onFieldChange();
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const moveToLeft = () => {
|
|
|
|
moveTo('left');
|
|
|
|
};
|
|
|
|
const moveToRight = () => {
|
|
|
|
moveTo('right');
|
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const onItemSelectAll = (direction: TransferDirection, selectedKeys: string[]) => {
|
|
|
|
handleSelectChange(direction, selectedKeys);
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const onLeftItemSelectAll = (selectedKeys: string[]) => {
|
|
|
|
return onItemSelectAll('left', selectedKeys);
|
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const onRightItemSelectAll = (selectedKeys: string[]) => {
|
|
|
|
return onItemSelectAll('right', selectedKeys);
|
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const handleSelectChange = (direction: TransferDirection, holder: string[]) => {
|
|
|
|
if (direction === 'left') {
|
|
|
|
if (!props.selectedKeys) {
|
|
|
|
sourceSelectedKeys.value = holder;
|
|
|
|
}
|
2021-09-30 08:54:51 +08:00
|
|
|
emit('update:selectedKeys', [...holder, ...targetSelectedKeys.value]);
|
|
|
|
emit('selectChange', holder, toRaw(targetSelectedKeys.value));
|
2021-09-25 16:51:32 +08:00
|
|
|
} else {
|
|
|
|
if (!props.selectedKeys) {
|
|
|
|
targetSelectedKeys.value = holder;
|
|
|
|
}
|
2021-09-30 08:54:51 +08:00
|
|
|
emit('update:selectedKeys', [...holder, ...sourceSelectedKeys.value]);
|
|
|
|
emit('selectChange', toRaw(sourceSelectedKeys.value), holder);
|
2021-09-25 16:51:32 +08:00
|
|
|
}
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const handleFilter = (direction: TransferDirection, e) => {
|
2019-01-12 11:33:27 +08:00
|
|
|
const value = e.target.value;
|
2021-09-25 16:51:32 +08:00
|
|
|
emit('search', direction, value);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLeftFilter = (e: Event) => {
|
|
|
|
handleFilter('left', e);
|
|
|
|
};
|
|
|
|
const handleRightFilter = (e: Event) => {
|
|
|
|
handleFilter('right', e);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClear = (direction: TransferDirection) => {
|
|
|
|
emit('search', direction, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleLeftClear = () => {
|
|
|
|
handleClear('left');
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleRightClear = () => {
|
|
|
|
handleClear('right');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onItemSelect = (direction: TransferDirection, selectedKey: string, checked: boolean) => {
|
|
|
|
const holder =
|
|
|
|
direction === 'left' ? [...sourceSelectedKeys.value] : [...targetSelectedKeys.value];
|
2020-03-07 19:45:13 +08:00
|
|
|
const index = holder.indexOf(selectedKey);
|
2018-04-07 00:20:45 +08:00
|
|
|
if (index > -1) {
|
2019-01-12 11:33:27 +08:00
|
|
|
holder.splice(index, 1);
|
2018-04-07 00:20:45 +08:00
|
|
|
}
|
|
|
|
if (checked) {
|
2020-03-07 19:45:13 +08:00
|
|
|
holder.push(selectedKey);
|
2018-04-07 00:20:45 +08:00
|
|
|
}
|
2021-09-25 16:51:32 +08:00
|
|
|
handleSelectChange(direction, holder);
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const onLeftItemSelect = (selectedKey: string, checked: boolean) => {
|
|
|
|
return onItemSelect('left', selectedKey, checked);
|
|
|
|
};
|
|
|
|
const onRightItemSelect = (selectedKey: string, checked: boolean) => {
|
|
|
|
return onItemSelect('right', selectedKey, checked);
|
|
|
|
};
|
|
|
|
const onRightItemRemove = (targetedKeys: string[]) => {
|
|
|
|
const { targetKeys = [] } = props;
|
|
|
|
const newTargetKeys = targetKeys.filter(key => !targetedKeys.includes(key));
|
|
|
|
emit('update:targetKeys', newTargetKeys);
|
|
|
|
emit('change', newTargetKeys, 'left', [...targetedKeys]);
|
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
const handleScroll = (direction: TransferDirection, e: UIEvent) => {
|
2021-09-25 16:51:32 +08:00
|
|
|
emit('scroll', direction, e);
|
|
|
|
};
|
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
const handleLeftScroll = (e: UIEvent) => {
|
2021-09-25 16:51:32 +08:00
|
|
|
handleScroll('left', e);
|
|
|
|
};
|
2022-03-26 22:52:54 +08:00
|
|
|
const handleRightScroll = (e: UIEvent) => {
|
2021-09-25 16:51:32 +08:00
|
|
|
handleScroll('right', e);
|
|
|
|
};
|
|
|
|
const handleListStyle = (
|
|
|
|
listStyle: ((style: ListStyle) => CSSProperties) | CSSProperties,
|
|
|
|
direction: TransferDirection,
|
|
|
|
) => {
|
2020-03-07 19:45:13 +08:00
|
|
|
if (typeof listStyle === 'function') {
|
|
|
|
return listStyle({ direction });
|
|
|
|
}
|
|
|
|
return listStyle;
|
2021-09-25 16:51:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const leftDataSource = ref([]);
|
|
|
|
const rightDataSource = ref([]);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
watchEffect(() => {
|
|
|
|
const { dataSource, rowKey, targetKeys = [] } = props;
|
2018-12-05 20:00:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const ld = [];
|
|
|
|
const rd = new Array(targetKeys.length);
|
2023-02-13 20:46:02 +08:00
|
|
|
const targetKeysMap = groupKeysMap(targetKeys);
|
2020-03-07 19:45:13 +08:00
|
|
|
dataSource.forEach(record => {
|
|
|
|
if (rowKey) {
|
|
|
|
record.key = rowKey(record);
|
|
|
|
}
|
|
|
|
|
2023-02-13 20:46:02 +08:00
|
|
|
// rightData should be ordered by targetKeys
|
|
|
|
// leftData should be ordered by dataSource
|
|
|
|
if (targetKeysMap.has(record.key)) {
|
|
|
|
rd[targetKeysMap.get(record.key)!] = record;
|
2020-03-07 19:45:13 +08:00
|
|
|
} else {
|
2021-09-25 16:51:32 +08:00
|
|
|
ld.push(record);
|
2020-03-07 19:45:13 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
leftDataSource.value = ld;
|
|
|
|
rightDataSource.value = rd;
|
|
|
|
});
|
|
|
|
|
|
|
|
expose({ handleSelectChange });
|
2018-12-05 20:00:13 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
const renderTransfer = (transferLocale: TransferLocale) => {
|
2018-04-07 00:20:45 +08:00
|
|
|
const {
|
2018-12-05 20:00:13 +08:00
|
|
|
disabled,
|
2018-04-07 00:20:45 +08:00
|
|
|
operations = [],
|
|
|
|
showSearch,
|
|
|
|
listStyle,
|
2018-09-05 21:28:54 +08:00
|
|
|
operationStyle,
|
2018-04-07 00:20:45 +08:00
|
|
|
filterOption,
|
2020-03-07 19:45:13 +08:00
|
|
|
showSelectAll,
|
2021-09-25 16:51:32 +08:00
|
|
|
selectAllLabels = [],
|
|
|
|
oneWay,
|
|
|
|
pagination,
|
|
|
|
id = formItemContext.id.value,
|
2019-01-12 11:33:27 +08:00
|
|
|
} = props;
|
2021-09-25 16:51:32 +08:00
|
|
|
const { class: className, style } = attrs;
|
|
|
|
|
|
|
|
const children = slots.children;
|
|
|
|
const mergedPagination = !children && pagination;
|
|
|
|
|
|
|
|
const renderEmpty = configProvider.renderEmpty;
|
|
|
|
const locale = getLocale(transferLocale, renderEmpty);
|
|
|
|
const { footer } = slots;
|
|
|
|
const renderItem = props.render || slots.render;
|
|
|
|
const leftActive = targetSelectedKeys.value.length > 0;
|
|
|
|
const rightActive = sourceSelectedKeys.value.length > 0;
|
|
|
|
|
2022-05-22 10:35:19 +08:00
|
|
|
const cls = classNames(
|
|
|
|
prefixCls.value,
|
|
|
|
className,
|
|
|
|
{
|
|
|
|
[`${prefixCls.value}-disabled`]: disabled,
|
|
|
|
[`${prefixCls.value}-customize-list`]: !!children,
|
|
|
|
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
|
|
|
},
|
|
|
|
getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback),
|
2023-02-13 20:21:29 +08:00
|
|
|
hashId.value,
|
2022-05-22 10:35:19 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
const titles = props.titles;
|
|
|
|
const leftTitle =
|
|
|
|
(titles && titles[0]) ?? slots.leftTitle?.() ?? (locale.titles || ['', ''])[0];
|
|
|
|
const rightTitle =
|
|
|
|
(titles && titles[1]) ?? slots.rightTitle?.() ?? (locale.titles || ['', ''])[1];
|
2018-04-07 00:20:45 +08:00
|
|
|
return (
|
2023-02-13 20:21:29 +08:00
|
|
|
<div {...attrs} class={cls} style={style as CSSProperties} id={id}>
|
2018-04-07 00:20:45 +08:00
|
|
|
<List
|
2020-03-07 19:45:13 +08:00
|
|
|
key="leftList"
|
2021-09-25 16:51:32 +08:00
|
|
|
prefixCls={`${prefixCls.value}-list`}
|
|
|
|
dataSource={leftDataSource.value}
|
2018-04-07 00:20:45 +08:00
|
|
|
filterOption={filterOption}
|
2021-09-25 16:51:32 +08:00
|
|
|
style={handleListStyle(listStyle, 'left')}
|
|
|
|
checkedKeys={sourceSelectedKeys.value}
|
|
|
|
handleFilter={handleLeftFilter}
|
|
|
|
handleClear={handleLeftClear}
|
|
|
|
onItemSelect={onLeftItemSelect}
|
|
|
|
onItemSelectAll={onLeftItemSelectAll}
|
2018-04-07 00:20:45 +08:00
|
|
|
renderItem={renderItem}
|
|
|
|
showSearch={showSearch}
|
2020-03-07 19:45:13 +08:00
|
|
|
renderList={children}
|
2021-09-25 16:51:32 +08:00
|
|
|
onScroll={handleLeftScroll}
|
2018-12-05 20:00:13 +08:00
|
|
|
disabled={disabled}
|
2022-03-12 09:56:32 +08:00
|
|
|
direction={direction.value === 'rtl' ? 'right' : 'left'}
|
2020-03-07 19:45:13 +08:00
|
|
|
showSelectAll={showSelectAll}
|
2021-09-25 16:51:32 +08:00
|
|
|
selectAllLabel={selectAllLabels[0] || slots.leftSelectAllLabel}
|
|
|
|
pagination={mergedPagination}
|
|
|
|
{...locale}
|
|
|
|
v-slots={{ titleText: () => leftTitle, footer }}
|
2018-04-07 00:20:45 +08:00
|
|
|
/>
|
|
|
|
<Operation
|
2020-03-07 19:45:13 +08:00
|
|
|
key="operation"
|
2021-09-25 16:51:32 +08:00
|
|
|
class={`${prefixCls.value}-operation`}
|
2018-04-07 00:20:45 +08:00
|
|
|
rightActive={rightActive}
|
|
|
|
rightArrowText={operations[0]}
|
2021-09-25 16:51:32 +08:00
|
|
|
moveToRight={moveToRight}
|
2018-04-07 00:20:45 +08:00
|
|
|
leftActive={leftActive}
|
|
|
|
leftArrowText={operations[1]}
|
2021-09-25 16:51:32 +08:00
|
|
|
moveToLeft={moveToLeft}
|
2018-09-05 21:28:54 +08:00
|
|
|
style={operationStyle}
|
2018-12-05 20:00:13 +08:00
|
|
|
disabled={disabled}
|
2021-09-25 16:51:32 +08:00
|
|
|
direction={direction.value}
|
|
|
|
oneWay={oneWay}
|
2018-04-07 00:20:45 +08:00
|
|
|
/>
|
|
|
|
<List
|
2020-03-07 19:45:13 +08:00
|
|
|
key="rightList"
|
2021-09-25 16:51:32 +08:00
|
|
|
prefixCls={`${prefixCls.value}-list`}
|
|
|
|
dataSource={rightDataSource.value}
|
2018-04-07 00:20:45 +08:00
|
|
|
filterOption={filterOption}
|
2021-09-25 16:51:32 +08:00
|
|
|
style={handleListStyle(listStyle, 'right')}
|
|
|
|
checkedKeys={targetSelectedKeys.value}
|
|
|
|
handleFilter={handleRightFilter}
|
|
|
|
handleClear={handleRightClear}
|
|
|
|
onItemSelect={onRightItemSelect}
|
|
|
|
onItemSelectAll={onRightItemSelectAll}
|
|
|
|
onItemRemove={onRightItemRemove}
|
2018-04-07 00:20:45 +08:00
|
|
|
renderItem={renderItem}
|
|
|
|
showSearch={showSearch}
|
2020-03-07 19:45:13 +08:00
|
|
|
renderList={children}
|
2021-09-25 16:51:32 +08:00
|
|
|
onScroll={handleRightScroll}
|
2018-12-05 20:00:13 +08:00
|
|
|
disabled={disabled}
|
2022-03-12 09:56:32 +08:00
|
|
|
direction={direction.value === 'rtl' ? 'left' : 'right'}
|
2020-03-07 19:45:13 +08:00
|
|
|
showSelectAll={showSelectAll}
|
2021-09-25 16:51:32 +08:00
|
|
|
selectAllLabel={selectAllLabels[1] || slots.rightSelectAllLabel}
|
|
|
|
showRemove={oneWay}
|
|
|
|
pagination={mergedPagination}
|
|
|
|
{...locale}
|
|
|
|
v-slots={{ titleText: () => rightTitle, footer }}
|
2018-04-07 00:20:45 +08:00
|
|
|
/>
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2021-09-25 16:51:32 +08:00
|
|
|
};
|
2023-02-13 20:21:29 +08:00
|
|
|
return () =>
|
|
|
|
wrapSSR(
|
|
|
|
<LocaleReceiver
|
|
|
|
componentName="Transfer"
|
|
|
|
defaultLocale={defaultLocale.Transfer}
|
|
|
|
children={renderTransfer}
|
|
|
|
/>,
|
|
|
|
);
|
2018-04-07 00:20:45 +08:00
|
|
|
},
|
2020-10-20 16:45:49 +08:00
|
|
|
});
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2020-11-01 15:03:33 +08:00
|
|
|
export default withInstall(Transfer);
|