fastlion-amis
Version:
一种MIS页面生成工具
72 lines (71 loc) • 3.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var index_1 = tslib_1.__importDefault(require("antd/lib/popover/index"));
var index_2 = tslib_1.__importDefault(require("antd/lib/menu/index"));
require("./index.scss");
var clipboard_1 = tslib_1.__importDefault(require("clipboard"));
var msgsub_1 = tslib_1.__importDefault(require("../../utils/msgsub"));
exports.default = (function (props) {
var _a = (0, react_1.useState)(false), visible = _a[0], setVisible = _a[1];
(0, react_1.useEffect)(function () {
if (document.querySelector(".lion-copybtn"))
return;
var lionBtn = document.createElement('button');
lionBtn.setAttribute("class", "lion-copybtn");
lionBtn.setAttribute("data-clipboard-action", "cut");
lionBtn.setAttribute("data-clipboard-text", "");
lionBtn.style.cssText = "display:none";
document.body.appendChild(lionBtn);
}, []);
(0, react_1.useEffect)(function () {
if (window.clipboard)
return;
window.clipboard = new clipboard_1.default('.lion-copybtn');
window.clipboard.on('success', function (e) {
var _a;
msgsub_1.default._success('复制成功', (_a = props.env) === null || _a === void 0 ? void 0 : _a.getModalContainer);
});
window.clipboard.on('error', function (e) {
var _a;
msgsub_1.default._error('复制失败', (_a = props.env) === null || _a === void 0 ? void 0 : _a.getModalContainer);
});
}, []);
var handleClick = function (e, value) {
e === null || e === void 0 ? void 0 : e.domEvent.preventDefault();
var copyBtn = document.querySelector('.lion-copybtn');
copyBtn === null || copyBtn === void 0 ? void 0 : copyBtn.setAttribute('data-clipboard-text', value ? value : '');
copyBtn.click();
setVisible(false);
};
var showItems = props.showItems, env = props.env, children = props.children, canOpenWin = props.canOpenWin;
var appShell = window['AppShell'];
var hasOpenWin = !!(appShell === null || appShell === void 0 ? void 0 : appShell.openNewWin);
var _showItems = tslib_1.__spreadArray([], showItems, true);
if (canOpenWin && hasOpenWin) {
_showItems.push({
click: function () {
var _a;
// 打开新窗口
(_a = props.openWin) === null || _a === void 0 ? void 0 : _a.call(props);
},
label: "新窗口打开",
icon: "fa fa-sticky-note-o"
});
}
var onPropsClick = function (item) {
item.click(item.value);
setVisible(false);
};
return (react_1.default.createElement(index_1.default, { visible: visible, overlayClassName: "lion-copy-item", destroyTooltipOnHide: true, placement: "bottom", arrowPointAtCenter: true, getPopupContainer: env === null || env === void 0 ? void 0 : env.getTopModalContainer, trigger: ["contextMenu"], onVisibleChange: function (visible) {
setVisible(visible);
}, content: react_1.default.createElement(index_2.default, null, _showItems.map(function (item, index) {
return react_1.default.createElement(index_2.default.Item, { onClick: function (e) {
item.click ? onPropsClick(item) : handleClick(e, item.value);
}, key: index },
react_1.default.createElement("span", { className: item.icon, style: { marginRight: '10px' } }),
item.label);
})) }, children));
});
//# sourceMappingURL=./renderers/Lion/components/LionCopyItem/index.js.map