2019-01-12 11:33:27 +08:00
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
|
import {
|
|
|
|
|
hasProp,
|
|
|
|
|
initDefaultProps,
|
|
|
|
|
getOptionProps,
|
|
|
|
|
getComponentFromProp,
|
|
|
|
|
} from '../_util/props-util';
|
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import List from './list';
|
|
|
|
|
import Operation from './operation';
|
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
|
import defaultLocale from '../locale-provider/default';
|
2019-03-28 20:56:06 +08:00
|
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2019-01-12 11:33:27 +08:00
|
|
|
|
import warning from '../_util/warning';
|
2019-08-28 10:50:19 +08:00
|
|
|
|
import Base from '../base';
|
2019-01-12 11:33:27 +08:00
|
|
|
|
|
|
|
|
|
export const TransferDirection = 'left' | 'right';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2018-04-07 10:32:13 +08:00
|
|
|
|
export const TransferItem = {
|
|
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
|
title: PropTypes.string.isRequired,
|
2018-04-07 00:20:45 +08:00
|
|
|
|
description: PropTypes.string,
|
|
|
|
|
disabled: PropTypes.bool,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
|
|
export const TransferProps = {
|
|
|
|
|
prefixCls: PropTypes.string,
|
2018-04-07 10:41:09 +08:00
|
|
|
|
dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose),
|
2018-12-05 20:00:13 +08:00
|
|
|
|
disabled: PropTypes.boolean,
|
2018-04-07 00:20:45 +08:00
|
|
|
|
targetKeys: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
selectedKeys: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
render: PropTypes.func,
|
|
|
|
|
listStyle: PropTypes.object,
|
2018-09-05 21:28:54 +08:00
|
|
|
|
operationStyle: PropTypes.object,
|
2018-04-07 10:32:13 +08:00
|
|
|
|
titles: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
operations: PropTypes.arrayOf(PropTypes.string),
|
2018-04-07 00:20:45 +08:00
|
|
|
|
showSearch: PropTypes.bool,
|
|
|
|
|
filterOption: PropTypes.func,
|
|
|
|
|
searchPlaceholder: PropTypes.string,
|
|
|
|
|
notFoundContent: PropTypes.any,
|
2018-12-05 20:00:13 +08:00
|
|
|
|
locale: PropTypes.object,
|
2018-04-07 10:41:09 +08:00
|
|
|
|
rowKey: PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
lazy: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
|
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
|
|
export const TransferLocale = {
|
|
|
|
|
titles: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
notFoundContent: PropTypes.string,
|
|
|
|
|
itemUnit: PropTypes.string,
|
|
|
|
|
itemsUnit: PropTypes.string,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
|
const Transfer = {
|
2018-04-08 21:17:20 +08:00
|
|
|
|
name: 'ATransfer',
|
2018-04-07 00:20:45 +08:00
|
|
|
|
mixins: [BaseMixin],
|
2018-04-07 10:41:09 +08:00
|
|
|
|
props: initDefaultProps(TransferProps, {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
dataSource: [],
|
2018-12-05 20:00:13 +08:00
|
|
|
|
locale: {},
|
2018-04-07 00:20:45 +08:00
|
|
|
|
showSearch: false,
|
|
|
|
|
}),
|
2019-03-28 20:56:06 +08:00
|
|
|
|
inject: {
|
2019-09-11 22:35:25 +08:00
|
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-03-28 20:56:06 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
data() {
|
2018-12-13 21:26:21 +08:00
|
|
|
|
// vue 中 通过slot,不方便传递,保留notFoundContent及searchPlaceholder
|
|
|
|
|
// warning(
|
|
|
|
|
// !(getComponentFromProp(this, 'notFoundContent') || hasProp(this, 'searchPlaceholder')),
|
|
|
|
|
// 'Transfer[notFoundContent] and Transfer[searchPlaceholder] will be removed, ' +
|
|
|
|
|
// 'please use Transfer[locale] instead.',
|
|
|
|
|
// )
|
2018-12-05 20:00:13 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.separatedDataSource =
|
|
|
|
|
{
|
|
|
|
|
leftDataSource: [],
|
|
|
|
|
rightDataSource: [],
|
|
|
|
|
} | null;
|
|
|
|
|
const { selectedKeys = [], targetKeys = [] } = this;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
return {
|
|
|
|
|
leftFilter: '',
|
|
|
|
|
rightFilter: '',
|
|
|
|
|
sourceSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) === -1),
|
|
|
|
|
targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
mounted() {
|
2018-05-18 21:57:40 +08:00
|
|
|
|
// this.currentProps = { ...this.$props }
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
watch: {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
targetKeys() {
|
|
|
|
|
this.updateState();
|
2018-05-18 21:57:40 +08:00
|
|
|
|
if (this.selectedKeys) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const targetKeys = this.targetKeys || [];
|
2018-05-18 21:57:40 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
sourceSelectedKeys: this.selectedKeys.filter(key => !targetKeys.includes(key)),
|
|
|
|
|
targetSelectedKeys: this.selectedKeys.filter(key => targetKeys.includes(key)),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-05-18 21:57:40 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
dataSource() {
|
|
|
|
|
this.updateState();
|
2018-05-18 21:57:40 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
selectedKeys() {
|
2018-05-18 21:57:40 +08:00
|
|
|
|
if (this.selectedKeys) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const targetKeys = this.targetKeys || [];
|
2018-05-18 21:57:40 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
sourceSelectedKeys: this.selectedKeys.filter(key => !targetKeys.includes(key)),
|
|
|
|
|
targetSelectedKeys: this.selectedKeys.filter(key => targetKeys.includes(key)),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-05-18 21:57:40 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
updateState() {
|
|
|
|
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
|
|
|
|
this.separatedDataSource = null;
|
2018-05-18 21:57:40 +08:00
|
|
|
|
if (!this.selectedKeys) {
|
|
|
|
|
// clear key nolonger existed
|
|
|
|
|
// clear checkedKeys according to targetKeys
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { dataSource, targetKeys = [] } = this;
|
2018-05-18 21:57:40 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const newSourceSelectedKeys = [];
|
|
|
|
|
const newTargetSelectedKeys = [];
|
2018-05-18 21:57:40 +08:00
|
|
|
|
dataSource.forEach(({ key }) => {
|
|
|
|
|
if (sourceSelectedKeys.includes(key) && !targetKeys.includes(key)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
newSourceSelectedKeys.push(key);
|
2018-05-18 21:57:40 +08:00
|
|
|
|
}
|
|
|
|
|
if (targetSelectedKeys.includes(key) && targetKeys.includes(key)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
newTargetSelectedKeys.push(key);
|
2018-05-18 21:57:40 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-05-18 21:57:40 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
sourceSelectedKeys: newSourceSelectedKeys,
|
|
|
|
|
targetSelectedKeys: newTargetSelectedKeys,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-05-18 21:57:40 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
separateDataSource(props) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.separatedDataSource) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.separatedDataSource;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { dataSource, rowKey, targetKeys = [] } = props;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const leftDataSource = [];
|
|
|
|
|
const rightDataSource = new Array(targetKeys.length);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
dataSource.forEach(record => {
|
|
|
|
|
if (rowKey) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
record.key = rowKey(record);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rightDataSource should be ordered by targetKeys
|
|
|
|
|
// leftDataSource should be ordered by dataSource
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const indexOfKey = targetKeys.indexOf(record.key);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
if (indexOfKey !== -1) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
rightDataSource[indexOfKey] = record;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
leftDataSource.push(record);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
|
this.separatedDataSource = {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
leftDataSource,
|
|
|
|
|
rightDataSource,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.separatedDataSource;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
moveTo(direction) {
|
|
|
|
|
const { targetKeys = [], dataSource = [] } = this.$props;
|
|
|
|
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
|
|
|
|
const moveKeys = direction === 'right' ? sourceSelectedKeys : targetSelectedKeys;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
// filter the disabled options
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const newMoveKeys = moveKeys.filter(
|
|
|
|
|
key => !dataSource.some(data => !!(key === data.key && data.disabled)),
|
|
|
|
|
);
|
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)
|
|
|
|
|
: targetKeys.filter(targetKey => newMoveKeys.indexOf(targetKey) === -1);
|
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';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
[this.getSelectedKeysName(oppositeDirection)]: [],
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
this.handleSelectChange(oppositeDirection, []);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('change', newTargetKeys, direction, newMoveKeys);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
moveToLeft() {
|
|
|
|
|
this.moveTo('left');
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
moveToRight() {
|
|
|
|
|
this.moveTo('right');
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleSelectChange(direction, holder) {
|
|
|
|
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
|
|
if (direction === 'left') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('selectChange', holder, targetSelectedKeys);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('selectChange', sourceSelectedKeys, holder);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleSelectAll(direction, filteredDataSource, checkAll) {
|
|
|
|
|
const originalSelectedKeys = this[this.getSelectedKeysName(direction)] || [];
|
|
|
|
|
const currentKeys = filteredDataSource.map(item => item.key);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
// Only operate current keys from original selected keys
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const newKeys1 = originalSelectedKeys.filter(key => currentKeys.indexOf(key) === -1);
|
|
|
|
|
const newKeys2 = [...originalSelectedKeys];
|
|
|
|
|
currentKeys.forEach(key => {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
if (newKeys2.indexOf(key) === -1) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
newKeys2.push(key);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
const holder = checkAll ? newKeys1 : newKeys2;
|
|
|
|
|
this.handleSelectChange(direction, holder);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
|
|
if (!this.selectedKeys) {
|
|
|
|
|
this.setState({
|
|
|
|
|
[this.getSelectedKeysName(direction)]: holder,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleLeftSelectAll(filteredDataSource, checkAll) {
|
|
|
|
|
this.handleSelectAll('left', filteredDataSource, checkAll);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleRightSelectAll(filteredDataSource, checkAll) {
|
|
|
|
|
this.handleSelectAll('right', filteredDataSource, checkAll);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleFilter(direction, e) {
|
|
|
|
|
const value = e.target.value;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
// add filter
|
2019-01-07 20:58:18 +08:00
|
|
|
|
[`${direction}Filter`]: value,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2019-01-07 20:58:18 +08:00
|
|
|
|
if (this.$listeners.searchChange) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
warning(false, '`searchChange` in Transfer is deprecated. Please use `search` instead.');
|
|
|
|
|
this.$emit('searchChange', direction, e);
|
2019-01-07 20:58:18 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('search', direction, value);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleLeftFilter(e) {
|
|
|
|
|
this.handleFilter('left', e);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleRightFilter(e) {
|
|
|
|
|
this.handleFilter('right', e);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleClear(direction) {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
[`${direction}Filter`]: '',
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
this.$emit('search', direction, '');
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleLeftClear() {
|
|
|
|
|
this.handleClear('left');
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleRightClear() {
|
|
|
|
|
this.handleClear('right');
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleSelect(direction, selectedItem, checked) {
|
|
|
|
|
const { sourceSelectedKeys, targetSelectedKeys } = this;
|
|
|
|
|
const holder = direction === 'left' ? [...sourceSelectedKeys] : [...targetSelectedKeys];
|
|
|
|
|
const index = holder.indexOf(selectedItem.key);
|
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) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
holder.push(selectedItem.key);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.handleSelectChange(direction, holder);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
|
|
|
|
|
if (!this.selectedKeys) {
|
|
|
|
|
this.setState({
|
|
|
|
|
[this.getSelectedKeysName(direction)]: holder,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleLeftSelect(selectedItem, checked) {
|
|
|
|
|
return this.handleSelect('left', selectedItem, checked);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleRightSelect(selectedItem, checked) {
|
|
|
|
|
return this.handleSelect('right', selectedItem, checked);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleScroll(direction, e) {
|
|
|
|
|
this.$emit('scroll', direction, e);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleLeftScroll(e) {
|
|
|
|
|
this.handleScroll('left', e);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleRightScroll(e) {
|
|
|
|
|
this.handleScroll('right', e);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getTitles(transferLocale) {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
if (this.titles) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.titles;
|
2018-04-07 00:20:45 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return transferLocale.titles || ['', ''];
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getSelectedKeysName(direction) {
|
|
|
|
|
return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys';
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-03-28 20:56:06 +08:00
|
|
|
|
getLocale(transferLocale, renderEmpty) {
|
|
|
|
|
const h = this.$createElement;
|
2018-12-05 20:00:13 +08:00
|
|
|
|
// Keep old locale props still working.
|
2019-03-28 20:56:06 +08:00
|
|
|
|
const oldLocale = {
|
|
|
|
|
notFoundContent: renderEmpty(h, 'Transfer'),
|
|
|
|
|
};
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const notFoundContent = getComponentFromProp(this, 'notFoundContent');
|
2018-12-05 20:00:13 +08:00
|
|
|
|
if (notFoundContent) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
oldLocale.notFoundContent = notFoundContent;
|
2018-12-05 20:00:13 +08:00
|
|
|
|
}
|
|
|
|
|
if (hasProp(this, 'searchPlaceholder')) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
oldLocale.searchPlaceholder = this.$props.searchPlaceholder;
|
2018-12-05 20:00:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return { ...transferLocale, ...oldLocale, ...this.$props.locale };
|
2018-12-05 20:00:13 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
renderTransfer(transferLocale) {
|
|
|
|
|
const props = getOptionProps(this);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
const {
|
2019-03-28 20:56:06 +08:00
|
|
|
|
prefixCls: customizePrefixCls,
|
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,
|
|
|
|
|
lazy,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
} = props;
|
2019-09-11 22:35:25 +08:00
|
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-28 20:56:06 +08:00
|
|
|
|
const prefixCls = getPrefixCls('transfer', customizePrefixCls);
|
|
|
|
|
|
2019-09-11 22:35:25 +08:00
|
|
|
|
const renderEmpty = this.configProvider.renderEmpty;
|
2019-03-28 20:56:06 +08:00
|
|
|
|
const locale = this.getLocale(transferLocale, renderEmpty);
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const {
|
|
|
|
|
leftFilter,
|
|
|
|
|
rightFilter,
|
|
|
|
|
sourceSelectedKeys,
|
|
|
|
|
targetSelectedKeys,
|
|
|
|
|
$scopedSlots,
|
|
|
|
|
} = this;
|
|
|
|
|
const { body, footer } = $scopedSlots;
|
|
|
|
|
const renderItem = props.render;
|
|
|
|
|
const { leftDataSource, rightDataSource } = this.separateDataSource(this.$props);
|
|
|
|
|
const leftActive = targetSelectedKeys.length > 0;
|
|
|
|
|
const rightActive = sourceSelectedKeys.length > 0;
|
|
|
|
|
|
|
|
|
|
const cls = classNames(prefixCls, disabled && `${prefixCls}-disabled`);
|
|
|
|
|
|
|
|
|
|
const titles = this.getTitles(locale);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
return (
|
|
|
|
|
<div class={cls}>
|
|
|
|
|
<List
|
|
|
|
|
prefixCls={`${prefixCls}-list`}
|
|
|
|
|
titleText={titles[0]}
|
|
|
|
|
dataSource={leftDataSource}
|
|
|
|
|
filter={leftFilter}
|
|
|
|
|
filterOption={filterOption}
|
|
|
|
|
style={listStyle}
|
|
|
|
|
checkedKeys={sourceSelectedKeys}
|
|
|
|
|
handleFilter={this.handleLeftFilter}
|
|
|
|
|
handleClear={this.handleLeftClear}
|
|
|
|
|
handleSelect={this.handleLeftSelect}
|
|
|
|
|
handleSelectAll={this.handleLeftSelectAll}
|
|
|
|
|
renderItem={renderItem}
|
|
|
|
|
showSearch={showSearch}
|
|
|
|
|
body={body}
|
|
|
|
|
footer={footer}
|
|
|
|
|
lazy={lazy}
|
|
|
|
|
onScroll={this.handleLeftScroll}
|
2018-12-05 20:00:13 +08:00
|
|
|
|
disabled={disabled}
|
|
|
|
|
itemUnit={locale.itemUnit}
|
|
|
|
|
itemsUnit={locale.itemsUnit}
|
|
|
|
|
notFoundContent={locale.notFoundContent}
|
|
|
|
|
searchPlaceholder={locale.searchPlaceholder}
|
2018-04-07 00:20:45 +08:00
|
|
|
|
/>
|
|
|
|
|
<Operation
|
|
|
|
|
class={`${prefixCls}-operation`}
|
|
|
|
|
rightActive={rightActive}
|
|
|
|
|
rightArrowText={operations[0]}
|
|
|
|
|
moveToRight={this.moveToRight}
|
|
|
|
|
leftActive={leftActive}
|
|
|
|
|
leftArrowText={operations[1]}
|
|
|
|
|
moveToLeft={this.moveToLeft}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
style={operationStyle}
|
2018-12-05 20:00:13 +08:00
|
|
|
|
disabled={disabled}
|
2018-04-07 00:20:45 +08:00
|
|
|
|
/>
|
|
|
|
|
<List
|
|
|
|
|
prefixCls={`${prefixCls}-list`}
|
|
|
|
|
titleText={titles[1]}
|
|
|
|
|
dataSource={rightDataSource}
|
|
|
|
|
filter={rightFilter}
|
|
|
|
|
filterOption={filterOption}
|
|
|
|
|
style={listStyle}
|
|
|
|
|
checkedKeys={targetSelectedKeys}
|
|
|
|
|
handleFilter={this.handleRightFilter}
|
|
|
|
|
handleClear={this.handleRightClear}
|
|
|
|
|
handleSelect={this.handleRightSelect}
|
|
|
|
|
handleSelectAll={this.handleRightSelectAll}
|
|
|
|
|
renderItem={renderItem}
|
|
|
|
|
showSearch={showSearch}
|
|
|
|
|
body={body}
|
|
|
|
|
footer={footer}
|
|
|
|
|
lazy={lazy}
|
|
|
|
|
onScroll={this.handleRightScroll}
|
2018-12-05 20:00:13 +08:00
|
|
|
|
disabled={disabled}
|
|
|
|
|
itemUnit={locale.itemUnit}
|
|
|
|
|
itemsUnit={locale.itemsUnit}
|
|
|
|
|
notFoundContent={locale.notFoundContent}
|
|
|
|
|
searchPlaceholder={locale.searchPlaceholder}
|
2018-04-07 00:20:45 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-04-07 00:20:45 +08:00
|
|
|
|
return (
|
|
|
|
|
<LocaleReceiver
|
2019-01-12 11:33:27 +08:00
|
|
|
|
componentName="Transfer"
|
2018-04-07 00:20:45 +08:00
|
|
|
|
defaultLocale={defaultLocale.Transfer}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
scopedSlots={{ default: this.renderTransfer }}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-04-07 00:20:45 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
|
Transfer.install = function(Vue) {
|
2019-08-28 10:50:19 +08:00
|
|
|
|
Vue.use(Base);
|
2019-01-12 11:33:27 +08:00
|
|
|
|
Vue.component(Transfer.name, Transfer);
|
|
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
export default Transfer;
|