@doreamonjs/gate
Version:
gate for doreamonjs
92 lines • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const dva_1 = require("dva");
const antd_1 = require("antd");
const transfer = tslib_1.__importStar(require("@doreamonjs/plugin-transfer"));
const NAMESPACE = transfer.NAMESPACE;
const mapState = (states) => {
const { visible, attributes, datasets } = states[NAMESPACE];
const { target = {} } = attributes;
const nextEffect = `${target.namespace}/${target.effect}`;
const loading = states.loading.effects[nextEffect];
return {
...attributes,
...datasets,
//
visible,
loading,
values: datasets.values,
};
};
const mapActions = (dispatch) => ({
onValueChange: (name, value) => dispatch({
type: `${NAMESPACE}/value/change`,
payload: { [name]: value },
}),
onClose: () => dispatch({ type: `${NAMESPACE}/close` }),
onSubmit: (values, lastValues) => dispatch({
type: `${NAMESPACE}/submit`,
payload: { values, lastValues },
}),
});
let ZTransfer = class ZTransfer extends react_1.PureComponent {
constructor() {
super(...arguments);
this.state = {
targetKeys: [],
};
this.onSubmit = () => {
const { values, onSubmit } = this.props;
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit({
...values,
...this.state,
}, values);
};
this.onChange = (targetKeys) => {
// props.onValueChange?.('values', { targetKeys })
this.setState({ targetKeys });
};
}
componentWillReceiveProps(nextProps) {
var _a;
this.setState({
targetKeys: ((_a = nextProps.values) === null || _a === void 0 ? void 0 : _a.targetKeys) || [],
});
}
get modalProps() {
const props = this.props;
return {
confirmLoading: props.loading,
width: 700,
bodyStyle: { height: 500 },
title: props.title,
visible: props.visible,
onOk: this.onSubmit,
onCancel: props.onClose,
cancelText: props.cancelText,
okText: props.submitText,
};
}
render() {
const { titles, values } = this.props;
const { targetKeys } = this.state;
return (react_1.default.createElement(antd_1.Modal, { ...this.modalProps },
react_1.default.createElement(antd_1.Transfer, { style: { height: '100%', display: 'flex' }, listStyle: { flex: 1, height: '100%' }, operationStyle: {
display: 'flex',
flexFlow: 'column wrap',
justifyContent: 'center',
}, titles: titles, dataSource: values === null || values === void 0 ? void 0 : values.dataSource, targetKeys: targetKeys, onChange: this.onChange,
// onSearch={onSearch}
render: (item) => item.title, showSearch: true })));
}
};
ZTransfer.defaultProps = {
type: 'modal',
};
ZTransfer = tslib_1.__decorate([
dva_1.connect(mapState, mapActions)
], ZTransfer);
exports.default = ZTransfer;
//# sourceMappingURL=index.js.map