UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

112 lines (111 loc) 7.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var antd_1 = require("antd"); var react_1 = tslib_1.__importStar(require("react")); var utils_1 = require("../../renderers/Lion/utils/utils"); var icons_1 = require("../icons"); var TextareaPop = function (props) { var _a; var visible = props.visible, onVisibleChange = props.onVisibleChange, translate = props.translate, values = props.values, onValuesChange = props.onValuesChange, onReset = props.onReset, ns = props.classPrefix, icon = props.icon, handleText = props.handleText, cx = props.classnames, placement = props.placement; var _b = (0, react_1.useState)(values), tempValue = _b[0], setTempValue = _b[1]; (0, react_1.useEffect)(function () { setTempValue(values); }, [values]); var _c = (0, react_1.useState)(visible), tempVisible = _c[0], setTempVisible = _c[1]; var valuesLength = (0, react_1.useMemo)(function () { var _a; return (_a = tempValue === null || tempValue === void 0 ? void 0 : tempValue.split('\n')) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return item !== ''; }).reduce(function (cxd, item) { if (item.includes(",")) { cxd = tslib_1.__spreadArray(tslib_1.__spreadArray([], item.split(','), true), cxd, true); } else { cxd = tslib_1.__spreadArray([item], cxd, true); } return cxd; }, []); }, [tempValue]); var handleConfirm = function () { var _a, _b, _c; var temp = (_a = tempValue === null || tempValue === void 0 ? void 0 : tempValue.split('\n')) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return item !== ''; }); // 最大支持9999行 if (temp && temp.length >= 9999) { temp = temp.slice(0, 9999); } var val = temp === null || temp === void 0 ? void 0 : temp.join(','); if ((val === null || val === void 0 ? void 0 : val[(val === null || val === void 0 ? void 0 : val.length) - 1]) === ',') { val = val.slice(0, val.length - 1); } val = Array.from(new Set((_c = (_b = val === null || val === void 0 ? void 0 : val.split(',')) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.call(_b, function (item) { return item.trim(); }))).join(','); handleText(val); setTempVisible(false); }; var handleReset = function () { setTempValue(undefined); onReset(); }; var popoverIconRef = react_1.default.createRef(); // Jay return react_1.default.createElement(antd_1.Popover, { arrowPointAtCenter: true, placement: placement || "bottom", overlayClassName: "textarea-popover", visible: tempVisible, onVisibleChange: function (visible) { onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(visible); setTempVisible(visible); }, getPopupContainer: function () { return document.getElementById('amis-modal-container') || popoverIconRef.current; }, trigger: "click", content: react_1.default.createElement("div", { onContextMenu: function (e) { return e.stopPropagation(); } }, react_1.default.createElement(antd_1.Input.TextArea, { style: { width: 300 }, rows: 6, placeholder: translate('multipleValuesMax'), value: tempValue, onPaste: function (e) { var _a, _b; e.preventDefault(); var inpTarget = e.target; var inpVal = inpTarget.value; var start = (_a = inpTarget.selectionStart) !== null && _a !== void 0 ? _a : 0; var end = (_b = inpTarget.selectionEnd) !== null && _b !== void 0 ? _b : 0; var pastedText = e.clipboardData.getData('text').trim(); var prefix = inpVal.slice(0, start); var suffix = inpVal.slice(end - start > 0 ? end : start); var newVal = prefix + pastedText + suffix; onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(newVal); setTempValue(newVal); }, onChange: function (e) { var newVal = e.target.value; onValuesChange === null || onValuesChange === void 0 ? void 0 : onValuesChange(newVal); setTempValue(newVal); }, onKeyDown: function (e) { return e.stopPropagation(); } }), react_1.default.createElement("div", { className: "button-group", style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: '10px', } }, react_1.default.createElement("div", null, react_1.default.createElement(antd_1.Button, { size: "small", style: { marginRight: 10, fontSize: 12 }, onClick: handleReset }, translate('reset')), react_1.default.createElement(antd_1.Button, { size: "small", style: { marginRight: 10, fontSize: 12 }, onClick: function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var val; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (!tempValue) return [3 /*break*/, 2]; val = tempValue === null || tempValue === void 0 ? void 0 : tempValue.replace(/\s+/g, ','); return [4 /*yield*/, (0, utils_1.copy)(val)]; case 1: _a.sent(); antd_1.message.success(translate('System.copy')); _a.label = 2; case 2: return [2 /*return*/]; } }); }); } }, translate('Alert.copy'))), translate("rowInTotal", { total: (_a = valuesLength === null || valuesLength === void 0 ? void 0 : valuesLength.length) !== null && _a !== void 0 ? _a : 0 }), react_1.default.createElement("div", null, react_1.default.createElement(antd_1.Button, { size: "small", style: { marginRight: 10 }, onClick: function () { onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(false); setTempVisible(false); } }, translate('Dialog.close')), react_1.default.createElement(antd_1.Button, { size: "small", type: "primary", onClick: handleConfirm }, translate('confirm'))))) }, react_1.default.createElement("div", { ref: popoverIconRef, className: "".concat(ns, "TextControl-addOn ").concat(icon ? ns + "TextControl-addOn-icon" : ""), onClick: function () { onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(!tempVisible); setTempVisible(!tempVisible); } }, icon !== undefined ? react_1.default.createElement("span", { className: cx('TransferPicker-icon') }, react_1.default.createElement(icons_1.Icon, { symbol: true, icon: icon, className: "icon" })) : react_1.default.createElement("i", { className: "icon fa fa-ellipsis-v" }))); }; exports.default = TextareaPop; //# sourceMappingURL=./components/common/TextareaPop.js.map