tntd
Version:
tntd是基于 TNT Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。
232 lines (230 loc) • 8.78 kB
JavaScript
;
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _queryForm = _interopRequireDefault(require("../query-form"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
"default": e
};
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _possibleConstructorReturn(t, e) {
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
return _assertThisInitialized(t);
}
function _assertThisInitialized(e) {
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return e;
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
return !!t;
})();
}
function _getPrototypeOf(t) {
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
return t.__proto__ || Object.getPrototypeOf(t);
}, _getPrototypeOf(t);
}
function _inherits(t, e) {
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: !0,
configurable: !0
}
}), Object.defineProperty(t, "prototype", {
writable: !1
}), e && _setPrototypeOf(t, e);
}
function _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
var __rest = void 0 && (void 0).__rest || function (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;
};
var clsPrefix = 'tnt-querylistscene-queryform';
var QueryForm = exports["default"] = /*#__PURE__*/function (_React$PureComponent) {
function QueryForm(props) {
var _this;
_classCallCheck(this, QueryForm);
_this = _callSuper(this, QueryForm, [props]);
Object.defineProperty(_this, "onSearch", {
enumerable: true,
configurable: true,
writable: true,
value: function value(searchObj) {
var _this$props = _this.props,
onSearch = _this$props.onSearch,
actions = _this$props.actions;
var values = actions.getFormData();
var params = Object.assign(Object.assign(Object.assign({}, values), searchObj || {}), {
current: 1
});
// memory 与 url解析setForm时 监听事件异步
actions.setData('formData', values);
Promise.resolve().then(function () {
onSearch && onSearch(params);
actions.emit('search', params);
});
}
});
Object.defineProperty(_this, "onReset", {
enumerable: true,
configurable: true,
writable: true,
value: function value() {
var _this$props2 = _this.props,
initialValues = _this$props2.initialValues,
onReset = _this$props2.onReset,
actions = _this$props2.actions;
actions.setFormData(initialValues, false);
onReset === null || onReset === void 0 ? void 0 : onReset(initialValues);
_this.onSearch();
}
});
Object.defineProperty(_this, "onChange", {
enumerable: true,
configurable: true,
writable: true,
value: function value(newValues, changedInfo) {
var _this$props3 = _this.props,
onChange = _this$props3.onChange,
actions = _this$props3.actions;
actions.setFormData(newValues, false);
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
rest[_key - 2] = arguments[_key];
}
onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, [newValues, changedInfo].concat(rest));
}
});
Object.defineProperty(_this, "setFormData", {
enumerable: true,
configurable: true,
writable: true,
value: function value(data, needSearch) {
var actions = _this.props.actions;
actions.setData('formData', data);
_this.form.setValues(data);
needSearch && _this.onSearch();
}
});
Object.defineProperty(_this, "resetFormData", {
enumerable: true,
configurable: true,
writable: true,
value: function value(needSearch) {
var _this$props4 = _this.props,
initialValues = _this$props4.initialValues,
actions = _this$props4.actions;
actions.setFormData(initialValues, needSearch);
_this.form.resetValues();
}
});
var actions = props.actions,
form = props.form;
_this.form = form || _queryForm["default"].createForm();
actions.on('setFormData', _this.setFormData);
actions.on('resetFormData', _this.resetFormData);
return _this;
}
_inherits(QueryForm, _React$PureComponent);
return _createClass(QueryForm, [{
key: "render",
value: function render() {
var _a = this.props,
className = _a.className,
actions = _a.actions,
extraActions = _a.extraActions,
extralActions = _a.extralActions,
qlsProps = _a.qlsProps,
props = __rest(_a, ["className", "actions", "extraActions", "extralActions", "qlsProps"]);
return _react["default"].createElement(_queryForm["default"], Object.assign({}, props, {
form: this.form,
className: (0, _classnames["default"])(clsPrefix, className),
// 前期拼写错误,导致需要兼容错误的api
extraActions: extraActions || extralActions,
onChange: this.onChange,
onSearch: this.onSearch,
onReset: this.onReset
}));
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
var _this$props5 = this.props,
_this$props5$initialV = _this$props5.initialValues,
initialValues = _this$props5$initialV === void 0 ? {} : _this$props5$initialV,
actions = _this$props5.actions,
qlsProps = _this$props5.qlsProps,
memory = _this$props5.memory;
if (qlsProps.memory || memory) {
actions.setFormData(Object.assign(Object.assign({}, initialValues), actions.getFormData()), false);
} else {
actions.setData('formData', initialValues);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var actions = this.props.actions;
actions.removeListener('setFormData', this.setFormData);
actions.removeListener('resetFormData', this.resetFormData);
}
}]);
}(_react["default"].PureComponent);
QueryForm.Field = _queryForm["default"].Field;