UNPKG

react-admin-component

Version:
1,051 lines (970 loc) 789 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var React = require('react'); var React__default = _interopDefault(React); var antd = require('antd'); var CropperLib = _interopDefault(require('cropperjs')); var reactUse = require('react-use'); var classNames = _interopDefault(require('classnames')); var ReactDom = _interopDefault(require('react-dom')); var reduxAlita = require('redux-alita'); var isEqual = _interopDefault(require('react-fast-compare')); var locale = _interopDefault(require('antd/lib/date-picker/locale/zh_CN')); var debounce = _interopDefault(require('lodash.debounce')); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var OPTIONS = [ { key: '1/1', name: '1:1' }, { key: '4/3', name: '4:3' }, { key: '1/2', name: '1:2' }, { key: '16/9', name: '16:9' }, { key: '9/16', name: '9:16' }, ]; var Controller = function (_a) { var imgData = _a.imgData, IMG_SPECTRATIO = _a.IMG_SPECTRATIO, initialValue = _a.initialValue, onSelectChange = _a.onSelectChange, resetInputValue = _a.resetInputValue, cropperIns = _a.cropperIns; var _b = React.useState(initialValue), inputValue = _b[0], setInputValue = _b[1]; var _c = React.useState('1/1'), selectAspectRatio = _c[0], setSelectAspectRatio = _c[1]; var prevInitialValue = reactUse.usePrevious(initialValue); React.useEffect(function () { if (JSON.stringify(prevInitialValue) !== JSON.stringify(initialValue)) { setInputValue(initialValue); } }, [initialValue, prevInitialValue, setInputValue]); function renderCropperInput(sizeName, sizeKey) { var onChange = function (_a) { var target = _a.target; var value = target && target.value; if (!value && !value.match(/\d*/g)) return ''; value = +(value.match(/\d*/g) || [''])[0]; value = (value > imgData[sizeKey] ? imgData[sizeKey] : value) + ''; var numberValue = +value; var calculateStyle = function (value, IMG_SPECTRATIO) { return +(value / IMG_SPECTRATIO).toFixed(0); }; var aspectRatio = selectAspectRatio ? +selectAspectRatio.split('/')[0] / +selectAspectRatio.split('/')[1] : 0; var calculateResult = function (IMG_SPECTRATIO) { var calculateAnother = function (keys) { var _a, _b; return (__assign((_a = {}, _a[keys[0]] = calculateStyle(numberValue, IMG_SPECTRATIO), _a), (aspectRatio && (_b = {}, _b[keys[1]] = calculateStyle(keys[0] === 'width' ? numberValue / aspectRatio : numberValue * aspectRatio, IMG_SPECTRATIO), _b)))); }; return __assign({}, inputValue, calculateAnother(sizeKey === 'width' ? ['width', 'height'] : ['height', 'width'])); }; var finalInputStyle = calculateResult(1); setInputValue(finalInputStyle); if (cropperIns) { cropperIns.setAspectRatio(aspectRatio); cropperIns.setCropBoxData(Object.keys(finalInputStyle).reduce(function (prev, curr) { prev[curr] = calculateStyle(finalInputStyle[curr], IMG_SPECTRATIO); return prev; }, {})); } }; return (React__default.createElement(antd.Input, { placeholder: sizeName, value: inputValue[sizeKey], style: { width: 70 }, onChange: onChange })); } function onChange(value) { setSelectAspectRatio(value); if (!value && cropperIns) { var cropperBox = cropperIns.getCropBoxData(); cropperIns.setAspectRatio(0); cropperIns.setCropBoxData(cropperBox); return; } var cropperStyle = onSelectChange && onSelectChange({ width: Number(value.split('/')[0]), height: Number(value.split('/')[1]), }); setInputValue(resetInputValue(cropperStyle)); } return (React__default.createElement("div", { className: "rac_cropper_controller", style: { marginTop: 20, display: 'flex', justifyContent: 'space-around' } }, React__default.createElement("div", null, React__default.createElement("span", null, "\u88C1\u526A\uFF1A"), renderCropperInput('宽', 'width'), React__default.createElement("span", { style: { margin: '0 10px' } }, "X"), renderCropperInput('高', 'height')), React__default.createElement("div", null, React__default.createElement("span", null, "\u50CF\u7D20\u6BD4\uFF1A"), React__default.createElement(antd.Select, { onChange: onChange, style: { width: 150 }, allowClear: true, value: selectAspectRatio }, OPTIONS.map(function (op) { return (React__default.createElement(antd.Select.Option, { key: op.key }, op.name)); }))))); }; var cropperIns; var DEFAULT_CROPPERSIZE = 360; var IMG_SPECTRATIO = 0; var DEFAULT_SPECTRATIO = 450; var DEFAULT_CROPPERCSTYLE; var Cropper = function (_a, ref) { var imgData = _a.imgData, children = _a.children, onCroppered = _a.onCroppered, className = _a.className, style = _a.style, onReady = _a.onReady; var _b = React.useState({ width: 0, height: 0 }), cropperCStyle = _b[0], setCropperCStyle = _b[1]; var _c = React.useState({ width: 0, height: 0 }), cropperStyle = _c[0], setCropperStyle = _c[1]; var _d = React.useState(false), cropperLoading = _d[0], setCropperLoading = _d[1]; var modalRef = React.useRef(null); var imgRef = React.useRef(null); React.useImperativeHandle(ref, function () { return ({ showCropper: showCropper }); }); React.useEffect(function () { return function () { cropperIns && cropperIns.destroy(); }; }, []); var showCropper = function () { if (modalRef.current) { modalRef.current.open(); var setWH = function (lenKey1, lenKey2) { var smallerSide = imgData[lenKey1] < imgData[lenKey2]; IMG_SPECTRATIO = +imgData[smallerSide ? lenKey2 : lenKey1] / DEFAULT_SPECTRATIO; return smallerSide ? +imgData[lenKey1] / IMG_SPECTRATIO : DEFAULT_SPECTRATIO; }; var cropperCH = setWH('height', 'width'); var cropperCW = setWH('width', 'height'); DEFAULT_CROPPERSIZE = cropperCH > cropperCW ? cropperCW : cropperCH; DEFAULT_CROPPERCSTYLE = { width: cropperCW, height: cropperCH }; var timer_1 = setTimeout(function () { setCropperCStyle(DEFAULT_CROPPERCSTYLE); setCropperStyle({ width: DEFAULT_CROPPERSIZE, height: DEFAULT_CROPPERSIZE }); setCropperLoading(true); clearTimeout(timer_1); }, 0); } }; var initialCropper = function () { cropperIns = new CropperLib(imgRef.current, { aspectRatio: 1, viewMode: 3, zoomable: false, minContainerHeight: DEFAULT_CROPPERCSTYLE.height, minContainerWidth: DEFAULT_CROPPERCSTYLE.width, ready: function () { setCropperLoading(false); resetCropperSize({ width: DEFAULT_CROPPERSIZE, height: DEFAULT_CROPPERSIZE }); onReady && onReady(); }, cropstart: function (_event) { }, cropend: function (_event) { var _a = cropperIns.getCropBoxData(), width = _a.width, height = _a.height; setCropperStyle({ width: Number(width.toFixed(0)), height: Number(height.toFixed(0)), }); }, }); }; function destroyCropper() { if (!cropperIns) return; cropperIns.destroy(); } function resetCropperSize(_a) { var width = _a.width, height = _a.height; cropperIns.setAspectRatio(width / height); cropperIns.setCropBoxData({ width: Number(width), height: Number(height) }); } function resetInputValue(_a) { var width = _a.width, height = _a.height; var calculate = function (size) { return Number((size * IMG_SPECTRATIO).toFixed(0)); }; return { width: calculate(width), height: calculate(height), }; } function onOk() { if (modalRef.current) { modalRef.current.close(); } var canvasStyle = resetInputValue(cropperIns.getCropBoxData()); var canvasTemp = cropperIns.getCroppedCanvas(canvasStyle); var image = new Image(); image.setAttribute('crossOrigin', 'anonymous'); image.onload = function () { var canvas = document.createElement('canvas'); canvas.width = canvasStyle.width; canvas.height = canvasStyle.height; var ctx = canvas.getContext('2d'); ctx && ctx.drawImage(image, 0, 0, canvasStyle.width, canvasStyle.height); onCroppered && onCroppered(canvas); destroyCropper(); }; image.src = canvasTemp.toDataURL('image/jpeg'); } function changeAspectRatio(ratio) { function setNewCropBox(judge) { var _a; if (judge === void 0) { judge = cropperCStyle.width >= cropperCStyle.height; } var orderedKey = judge ? ['width', 'height'] : ['height', 'width']; cropperIns.setAspectRatio(ratio.width / ratio.height); return _a = {}, _a[orderedKey[1]] = cropperCStyle[orderedKey[1]], _a[orderedKey[0]] = (cropperCStyle[orderedKey[1]] * ratio[orderedKey[0]]) / ratio[orderedKey[1]], _a; } var newCropBoxData = setNewCropBox(); if (newCropBoxData.width > cropperCStyle.width || newCropBoxData.height > cropperCStyle.height) { newCropBoxData = setNewCropBox(cropperCStyle.width < cropperCStyle.height); } cropperIns.setCropBoxData(newCropBoxData); return { width: newCropBoxData.width, height: newCropBoxData.height }; } return (React__default.createElement(React__default.Fragment, null, children && React__default.createElement("div", { onClick: showCropper }, children), React__default.createElement(ModalContainer$1, { title: "\u56FE\u7247\u88C1\u526A", onOk: onOk, ref: modalRef, style: __assign({ width: '80%', maxWidth: 946 }, style), onCancel: destroyCropper, className: className, destroyOnClose: true }, React__default.createElement(antd.Spin, { spinning: cropperLoading }, React__default.createElement("div", { style: __assign({}, cropperCStyle, { margin: '0 auto', textAlign: 'center' }) }, React__default.createElement("img", { id: "cropper_img", ref: imgRef, style: __assign({}, cropperCStyle), alt: "\u88C1\u526A\u56FE\u7247", src: imgData.imgUrl, onLoad: initialCropper })), cropperStyle.width && (React__default.createElement(Controller, __assign({}, { imgData: imgData, IMG_SPECTRATIO: IMG_SPECTRATIO, resetCropperSize: resetCropperSize, resetInputValue: resetInputValue, initialValue: resetInputValue(cropperStyle), }, { onSelectChange: changeAspectRatio, cropperIns: cropperIns }))))))); }; var index = React__default.forwardRef(Cropper); var ModalContainer = function (_a, ref) { var title = _a.title, style = _a.style, className = _a.className, children = _a.children, onOk = _a.onOk, onCancel = _a.onCancel, destroyOnClose = _a.destroyOnClose, forceRender = _a.forceRender, _b = _a.autoClose, autoClose = _b === void 0 ? true : _b, _c = _a.width, width = _c === void 0 ? 946 : _c, _d = _a.maskClosable, maskClosable = _d === void 0 ? false : _d, restProps = __rest(_a, ["title", "style", "className", "children", "onOk", "onCancel", "destroyOnClose", "forceRender", "autoClose", "width", "maskClosable"]); var _e = React.useState(false), visible = _e[0], setVisible = _e[1]; React.useImperativeHandle(ref, function () { return ({ open: function () { return changeModalVisible(true); }, close: function () { return changeModalVisible(false); }, }); }); var handleOk = function () { onOk && onOk(); autoClose && changeModalVisible(false); }; var handleCancel = function () { changeModalVisible(false); onCancel && onCancel(); }; var changeModalVisible = function (flag) { if (flag === void 0) { flag = true; } setVisible(flag); }; return (React__default.createElement(antd.Modal, __assign({ onOk: handleOk, onCancel: handleCancel, maskClosable: maskClosable, className: classNames('modal-theme-header', className) }, __assign({ visible: visible, title: title, style: style, destroyOnClose: destroyOnClose, forceRender: forceRender }, (((style && !style.width) || !style) && { width: width }), restProps)), children)); }; var ModalContainer$1 = React__default.forwardRef(ModalContainer); var ModalCustom = (function () { function ModalCustom(modalId) { if (modalId === void 0) { modalId = 'react-admin_modal'; } this.modalEle = null; this.modalId = modalId; this.initDom(); } ModalCustom.prototype.initDom = function () { this.modalEle = document.getElementById(this.modalId); if (!this.modalEle) { this.modalEle = document.createElement('div'); this.modalEle.setAttribute('id', 'react-admin_modal-' + Math.random()); document.body.appendChild(this.modalEle); } }; ModalCustom.prototype.show = function (component) { if (!this.modalEle) this.initDom(); ReactDom.render(component, this.modalEle); }; ModalCustom.prototype.destroy = function () { if (this.modalEle) { ReactDom.unmountComponentAtNode(this.modalEle); this.modalEle.parentNode.removeChild(this.modalEle); this.modalEle = null; } }; return ModalCustom; }()); var alertIns = new ModalCustom(); var closedByHand = false; var AlertDefaultProps = { cancelText: '取消', confirmText: '确认', btnText: '知道了', }; var AlertType; (function (AlertType) { AlertType["SUCCESS"] = "success"; AlertType["ERROR"] = "error"; AlertType["WARN"] = "warn"; AlertType["CONFIRM"] = "confirm"; })(AlertType || (AlertType = {})); var Success = function () { return (React__default.createElement("div", { className: "alert_icon alert_icon-success" }, React__default.createElement("div", { className: "alert_icon-success_line alert_icon-success_line-long" }), React__default.createElement("div", { className: "alert_icon-success_line alert_icon-success_line-tip" }), React__default.createElement("div", { className: "alert_icon-success_ring" }), React__default.createElement("div", { className: "alert_icon-success_hide-corners" }))); }; var Warn = function () { return (React__default.createElement("div", { className: "alert_icon alert_icon-warning" }, React__default.createElement("span", { className: "alert_icon-warning_body" }, React__default.createElement("span", { className: "alert_icon-warning_dot" })))); }; var Error$1 = function () { return (React__default.createElement("div", { className: "alert_icon alert_icon-error" }, React__default.createElement("span", { className: "alert_icon-error_mark" }, React__default.createElement("span", { className: "alert_icon-error_line alert_icon-error_line-left" }), React__default.createElement("span", { className: "alert_icon-error_line alert_icon-error_line-right" })))); }; var Alert = function (props) { var header = props.header, body = props.body, icon = props.icon, alertType = props.alertType, hideBtn = props.hideBtn; var close = function () { closedByHand = true; var onCancel = props.onCancel; onCancel && onCancel(); alertIns.destroy(); }; var confirm = function () { closedByHand = true; var onOk = props.onOk; onOk && onOk(); alertIns.destroy(); }; return (React__default.createElement("div", { className: classNames('alert_overlay alert_overlay-show', props.className), style: props.style }, React__default.createElement("div", { className: "alert_modal", style: props.containerStyle }, React__default.createElement("div", { className: "alert_close", onClick: close }), header && React__default.createElement("div", { className: "alert_header" }, header), body ? (body) : (React__default.createElement(React__default.Fragment, null, icon && React__default.createElement("div", { className: "alert_icon_" + alertType }, icon), !icon && !props.hideIcon && (React__default.createElement("div", null, alertType === AlertType.SUCCESS && React__default.createElement(Success, null), (alertType === AlertType.WARN || alertType === AlertType.CONFIRM) && React__default.createElement(Warn, null), alertType === AlertType.ERROR && React__default.createElement(Error$1, null))), React__default.createElement("div", { className: "alert_title" }, props.title), props.text && React__default.createElement("div", { className: "alert_text" }, props.text))), !hideBtn && (React__default.createElement("div", { className: "alert_button_container" }, props.alertType !== AlertType.CONFIRM && (React__default.createElement("div", { className: "alert_button", onClick: confirm }, props.btnText)), props.alertType === AlertType.CONFIRM && (React__default.createElement(React__default.Fragment, null, React__default.createElement("div", { className: "alert_button-confirm", onClick: close }, props.cancelText), React__default.createElement("div", { style: { flex: 1 } }), React__default.createElement("div", { className: "alert_button-confirm", onClick: confirm }, props.confirmText)))))))); }; Alert.defaultProps = AlertDefaultProps; var renderCommon = function (params, alertType) { if (Object.prototype.toString.call(params) === '[object String]') { params = { title: params }; } alertIns.show(React__default.createElement(Alert, __assign({ alertType: alertType }, __assign({}, params)))); }; var alert = { success: function (params) { closedByHand = false; var DURATION = 2000; if (Object.prototype.toString.call(params) === '[object String]') { params = { title: params, duration: DURATION }; } else { params.duration = params.hasOwnProperty('duration') ? params.duration : DURATION; } alertIns.show(React__default.createElement(Alert, __assign({ alertType: "success" }, __assign({}, params)))); var duration = params.duration; if (duration === 0) return; var timer = setTimeout(function () { !closedByHand && alertIns && alertIns.destroy(); clearTimeout(timer); }, duration); }, error: function (params) { renderCommon(params, 'error'); }, warn: function (params) { renderCommon(params, 'warn'); }, warning: function (params) { renderCommon(params, 'warn'); }, confirm: function (params) { renderCommon(params, 'confirm'); }, destroy: function () { alertIns.destroy(); }, }; var IconOp = function (props) { return (React__default.createElement("span", { className: "op_icon" }, React__default.createElement(antd.Tooltip, { title: props.title || props.children }, React__default.createElement("i", { onClick: props.onClick, style: __assign({ color: props.color }, props.style), className: classNames('icon-666', 'karakal-icon-' + props.icon, props.className) })))); }; var imgPreviewInstance = new ModalCustom(); var ImgPreviewSource = (function (_super) { __extends(ImgPreviewSource, _super); function ImgPreviewSource(props) { var _this = _super.call(this, props) || this; _this.loadImg = function (event) { var _a = event.currentTarget, naturalHeight = _a.naturalHeight, naturalWidth = _a.naturalWidth; _this.setState({ naturalHeight: naturalHeight, naturalWidth: naturalWidth, }); }; _this.close = function () { imgPreviewInstance.destroy(); }; _this.state = { naturalHeight: 'auto', naturalWidth: 'auto', }; _this.displayName = 'ImgPreviewSource'; return _this; } ImgPreviewSource.prototype.componentWillUnmount = function () { }; ImgPreviewSource.prototype.render = function () { var _a = this.state, naturalWidth = _a.naturalWidth, naturalHeight = _a.naturalHeight; var imgSrc = this.props.imgSrc; return (React__default.createElement("div", { className: "imgps_root" }, React__default.createElement("img", { src: imgSrc, width: naturalWidth, height: naturalHeight, alt: "\u539F\u56FE", onLoad: this.loadImg, className: "imgps_img_ratio" }), React__default.createElement("div", { className: "imgps_close", onClick: this.close }, React__default.createElement("i", { className: "imgps_icon", style: { color: '#ffffff' } })))); }; return ImgPreviewSource; }(React.Component)); var index$1 = { showImgSource: function (imgSrc) { imgPreviewInstance.show(React__default.createElement(ImgPreviewSource, { imgSrc: imgSrc })); }, }; var ScrollUp = function (props) { var prevLocation = reactUse.usePrevious(props.location); React.useEffect(function () { if (prevLocation && prevLocation.pathname !== props.location.pathname) { window.scrollTo(0, 0); } }, [props.location, prevLocation]); return props.children; }; var AuthPool = function (props) { var permits = reduxAlita.useAlitaState([{ permits: [] }]).permits; return props.checkPermit(permits.data); }; function intersectionArr(arr1, arr2) { var _temp = []; arr1.forEach(function (v1) { if (arr2.indexOf(v1) !== -1) _temp.push(v1); }); return _temp; } var includePermit = function (permits, require, every) { if (!require || require.length < 1) return true; var _intersection = intersectionArr(require, permits); return every ? _intersection.length === require.length : _intersection.length > 0; }; var PrototypeCheck = (function () { function PrototypeCheck() { } PrototypeCheck.getPrototype = function (value) { return Object.prototype.toString.call(value); }; PrototypeCheck.checkProtoType = function (value, prototype) { return this.getPrototype(value) === prototype; }; PrototypeCheck.isString = function (value) { return this.checkProtoType(value, '[object String]'); }; PrototypeCheck.isNumber = function (value) { return this.checkProtoType(value, '[object Number]'); }; PrototypeCheck.isArray = function (value) { return this.checkProtoType(value, '[object Array]'); }; PrototypeCheck.isFunction = function (value) { return this.checkProtoType(value, '[object Function]'); }; return PrototypeCheck; }()); function uuid(a) { return a ? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid); } var AuthPermit = function (props) { return (React__default.createElement(AuthPool, { checkPermit: function (permits) { return includePermit(permits, props.require, props.every) ? props.children : null; } })); }; var ContentEditable = (function (_super) { __extends(ContentEditable, _super); function ContentEditable() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.emitChange = function () { var valueType = _this.props.valueType; var html = valueType === 'text' ? _this.domNode.innerText : _this.domNode.innerHTML; if (_this.props.onChange && html !== _this.lastHtml) { _this.props.onChange({ target: { value: html, }, }); } _this.lastHtml = html; }; return _this; } ContentEditable.prototype.shouldComponentUpdate = function (nextProps) { return !!this.domNode && nextProps.html !== this.domNode.innerHTML; }; ContentEditable.prototype.componentDidUpdate = function () { var domNode = this.domNode; var html = this.props.html; if (html && !!domNode && html !== domNode.innerHTML) { domNode.innerHTML = html; } }; ContentEditable.prototype.render = function () { var _this = this; var _a = this.props, className = _a.className, style = _a.style, html = _a.html; return (React__default.createElement("div", __assign({ ref: function (dom) { return (_this.domNode = dom); }, onInput: this.emitChange, onBlur: this.emitChange, contentEditable: true, dangerouslySetInnerHTML: { __html: html }, className: classNames('rac_contenteditable', className) }, { style: style }))); }; ContentEditable.defaultProps = { valueType: 'text', }; return ContentEditable; }(React__default.Component)); var FormTextareaHint = function (_a) { var value = _a.value, maxLength = _a.maxLength; var getLength = value ? value.length : 0; var max = maxLength ? maxLength : 1000; var show = maxLength ? true : false; return show ? (React__default.createElement("div", { className: "rac_form_textarea_hint-container" }, getLength + " / " + max)) : (React__default.createElement("div", null)); }; var FormInput = function (_a) { var required = _a.required, label = _a.label, field = _a.field, placeholder = _a.placeholder, max = _a.max, readOnly = _a.readOnly, initialValue = _a.initialValue, valueFilter = _a.valueFilter, form = _a.form, disabled = _a.disabled, inputProps = _a.inputProps, validator = _a.validator, valueType = _a.valueType, allowClear = _a.allowClear, labelCol = _a.labelCol, wrapperCol = _a.wrapperCol, className = _a.className, textarea = _a.textarea, autoSize = _a.autoSize, restProps = __rest(_a, ["required", "label", "field", "placeholder", "max", "readOnly", "initialValue", "valueFilter", "form", "disabled", "inputProps", "validator", "valueType", "allowClear", "labelCol", "wrapperCol", "className", "textarea", "autoSize"]); var _b = form, getFieldDecorator = _b.getFieldDecorator, getFieldValue = _b.getFieldValue; var rules = [ required && { required: required, message: label ? "\u8BF7\u8F93\u5165" + label : placeholder, transform: function (value) { if (value) { if (PrototypeCheck.isString(value)) { value.trim(); } else if (PrototypeCheck.isNumber(value)) { value = JSON.stringify(value); } } return value; }, }, ].concat([ { validator: function (rule, value, callback) { if (value && valueType === 'number' && !PrototypeCheck.isNumber(Number(value))) { callback('请输入数字'); } if (value && validator) { validator(rule, value, callback, form); } else callback(); }, } ], (max ? [{ max: max, message: "\u4E0D\u80FD\u8F93\u5165\u8D85\u8FC7" + max + "\u4E2A\u5B57\u7B26" }] : [])).filter(Boolean); var commonProps = __assign({ placeholder: placeholder || "\u8BF7\u8F93\u5165" + label }, inputProps, { disabled: disabled }); return (React__default.createElement(antd.Form.Item, __assign({}, { label: label, labelCol: labelCol, wrapperCol: wrapperCol, }, { className: classNames('rac_form_input', className) }), getFieldDecorator(field, { initialValue: initialValue, rules: rules, validateFirst: true, normalize: function (value) { if (valueFilter) return valueFilter(value); return value; }, })(readOnly ? (restProps.render ? (restProps.render(getFieldValue(field))) : (React__default.createElement("span", null, getFieldValue(field)))) : textarea ? (React__default.createElement("div", { className: "rac_form_textarea-container" }, React__default.createElement(antd.Input.TextArea, __assign({}, commonProps, { value: getFieldValue(field), autosize: autoSize })), React__default.createElement(FormTextareaHint, { value: getFieldValue(field), maxLength: inputProps && inputProps.maxLength }))) : (React__default.createElement(antd.Input, __assign({}, commonProps, { allowClear: allowClear })))))); }; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function commonjsRequire () { throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var lodash = createCommonjsModule(function (module, exports) { (function() { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined$1; /** Used as the semantic version number. */ var VERSION = '4.17.15'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; /** Error message constants. */ var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', FUNC_ERROR_TEXT = 'Expected a function'; /** Used to stand-in for `undefined` hash values. */ var HASH_UNDEFINED = '__lodash_hash_undefined__'; /** Used as the maximum memoize cache size. */ var MAX_MEMOIZE_SIZE = 500; /** Used as the internal argument placeholder. */ var PLACEHOLDER = '__lodash_placeholder__'; /** Used to compose bitmasks for cloning. */ var CLONE_DEEP_FLAG = 1, CLONE_FLAT_FLAG = 2, CLONE_SYMBOLS_FLAG = 4; /** Used to compose bitmasks for value comparisons. */ var COMPARE_PARTIAL_FLAG = 1, COMPARE_UNORDERED_FLAG = 2; /** Used to compose bitmasks for function metadata. */ var WRAP_BIND_FLAG = 1, WRAP_BIND_KEY_FLAG = 2, WRAP_CURRY_BOUND_FLAG = 4, WRAP_CURRY_FLAG = 8, WRAP_CURRY_RIGHT_FLAG = 16, WRAP_PARTIAL_FLAG = 32, WRAP_PARTIAL_RIGHT_FLAG = 64, WRAP_ARY_FLAG = 128, WRAP_REARG_FLAG = 256, WRAP_FLIP_FLAG = 512; /** Used as default options for `_.truncate`. */ var DEFAULT_TRUNC_LENGTH = 30, DEFAULT_TRUNC_OMISSION = '...'; /** Used to detect hot functions by number of calls within a span of milliseconds. */ var HOT_COUNT = 800, HOT_SPAN = 16; /** Used to indicate the type of lazy iteratees. */ var LAZY_FILTER_FLAG = 1, LAZY_MAP_FLAG = 2, LAZY_WHILE_FLAG = 3; /** Used as references for various `Number` constants. */ var INFINITY = 1 / 0, MAX_SAFE_INTEGER = 9007199254740991, MAX_INTEGER = 1.7976931348623157e+308, NAN = 0 / 0; /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; /** Used to associate wrap methods with their bit flags. */ var wrapFlags = [ ['ary', WRAP_ARY_FLAG], ['bind', WRAP_BIND_FLAG], ['bindKey', WRAP_BIND_KEY_FLAG], ['curry', WRAP_CURRY_FLAG], ['curryRight', WRAP_CURRY_RIGHT_FLAG], ['flip', WRAP_FLIP_FLAG], ['partial', WRAP_PARTIAL_FLAG], ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], ['rearg', WRAP_REARG_FLAG] ]; /** `Object#toString` result references. */ var argsTag = '[object Arguments]', arrayTag = '[object Array]', asyncTag = '[object AsyncFunction]', boolTag = '[object Boolean]', dateTag = '[object Date]', domExcTag = '[object DOMException]', errorTag = '[object Error]', funcTag = '[object Function]', genTag = '[object GeneratorFunction]', mapTag = '[object Map]', numberTag = '[object Number]', nullTag = '[object Null]', objectTag = '[object Object]', promiseTag = '[object Promise]', proxyTag = '[object Proxy]', regexpTag = '[object RegExp]', setTag = '[object Set]', stringTag = '[object String]', symbolTag = '[object Symbol]', undefinedTag = '[object Undefined]', weakMapTag = '[object WeakMap]', weakSetTag = '[object WeakSet]'; var arrayBufferTag = '[object ArrayBuffer]', dataViewTag = '[object DataView]', float32Tag = '[object Float32Array]', float64Tag = '[object Float64Array]', int8Tag = '[object Int8Array]', int16Tag = '[object Int16Array]', int32Tag = '[object Int32Array]', uint8Tag = '[object Uint8Array]', uint8ClampedTag = '[object Uint8ClampedArray]', uint16Tag = '[object Uint16Array]', uint32Tag = '[object Uint32Array]'; /** Used to match empty string literals in compiled template source. */ var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; /** Used to match HTML entities and HTML characters. */ var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, reUnescapedHtml = /[&<>"']/g, reHasEscapedHtml = RegExp(reEscapedHtml.source), reHasUnescapedHtml = RegExp(reUnescapedHtml.source); /** Used to match template delimiters. */ var reEscape = /<%-([\s\S]+?)%>/g, reEvaluate = /<%([\s\S]+?)%>/g, reInterpolate = /<%=([\s\S]+?)%>/g; /** Used to match property names within property paths. */ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; /** * Used to match `RegExp` * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). */ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, reHasRegExpChar = RegExp(reRegExpChar.source); /** Used to match leading and trailing whitespace. */ var reTrim = /^\s+|\s+$/g, reTrimStart = /^\s+/, reTrimEnd = /\s+$/; /** Used to match wrap detail comments. */ var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, reSplitDetails = /,? & /; /** Used to match words composed of alphanumeric characters. */ var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; /** Used to match backslashes in property paths. */ var reEscapeChar = /\\(\\)?/g; /** * Used to match * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). */ var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to match `RegExp` flags from their coerced string values. */ var reFlags = /\w*$/; /** Used to detect bad signed hexadecimal string values. */ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; /** Used to detect binary string values. */ var reIsBinary = /^0b[01]+$/i; /** Used to detect host constructors (Safari). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used to detect octal string values. */ var reIsOctal = /^0o[0-7]+$/i; /** Used to detect unsigned integer values. */ var reIsUint = /^(?:0|[1-9]\d*)$/; /** Used to match Latin Unicode letters (excluding mathematical operators). */ var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; /** Used to ensure capturing order of template delimiters. */ var reNoMatch = /($^)/; /** Used to match unescaped characters in compiled string literals. */ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; /** Used to compose unicode character classes. */ var rsAstralRange = '\\ud800-\\udfff', rsComboMarksRange = '\\u0300-\\u036f', reComboHalfMarksRange = '\\ufe20-\\ufe2f', rsComboSymbolsRange = '\\u20d0-\\u20ff', rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, rsDingbatRange = '\\u2700-\\u27bf', rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', rsPunctuationRange = '\\u2000-\\u206f', rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', rsVarRange = '\\ufe0e\\ufe0f', rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; /** Used to compose unicode capture groups. */ var rsApos = "['\u2019]", rsAstral = '[' + rsAstralRange + ']', rsBreak = '[' + rsBreakRange + ']', rsCombo = '[' + rsComboRange + ']', rsDigits = '\\d+', rsDingbat = '[' + rsDingbatRange + ']', rsLower = '[' + rsLowerRange + ']', rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', rsFitz = '\\ud83c[\\udffb-\\udfff]', rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', rsNonAstral = '[^' + rsAstralRange + ']', rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', rsUpper = '[' + rsUpperRange + ']', rsZWJ = '\\u200d'; /** Used to compose unicode regexes. */ var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; /** Used to match apostrophes. */ var reApos = RegExp(rsApos, 'g'); /** * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). */ var reComboMark = RegExp(rsCombo, 'g'); /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); /** Used to match complex or compound words. */ var reUnicodeWord = RegExp([ rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, rsUpper + '+' + rsOptContrUpper, rsOrdUpper, rsOrdLower, rsDigits, rsEmoji ].join('|'), 'g'); /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); /** Used to detect strings that need a more robust regexp to match words. */ var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** Used to assign default `context` object properties. */ var contextProps = [ 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' ]; /** Used to make template sourceURLs easier to identify. */ var templateCounter = -1; /** Used to identify `toStringTag` values of typed arrays. */ var typedArrayTags = {}; typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true; typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; /** Used to identify `toStringTag` values supported by `_.clone`. */ var cloneableTags = {}; cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false; /** Used to map Latin Unicode letters to basic Latin letters. */ var deburredLetters = { // Latin-1 Supplement block. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', '\xc7': 'C', '\xe7': 'c', '\xd0': 'D', '\xf0': 'd', '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', '\xd1': 'N', '\xf1': 'n', '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', '\xc6': 'Ae', '\xe6': 'ae', '\xde': 'Th', '\xfe': 'th', '\xdf': 'ss', // Latin Extended-A block. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i