@lvxiaowu/antd4
Version:
antd4-components
98 lines (70 loc) • 3.86 kB
JavaScript
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import { makeObservable, action } from 'mobx';
import { overrideStore, SEARCHBAR_STORE, resetStore } from '../utils';
import { Utils } from '@lvxiaowu/utils';
var SearchStore = /*#__PURE__*/_createClass(function SearchStore(_overrides) {
var _this = this;
_classCallCheck(this, SearchStore);
this.$storeName = SEARCHBAR_STORE;
this.form = null;
this.extraParams = {};
this.searchParams = {};
this.setFormInstance = function (form) {
_this.form = form;
};
this.getFormInstance = function () {
return _this.form;
};
this.setExtraParams = function (params) {
_this.extraParams = params || {};
};
this.getExtraParams = function () {
return _this.extraParams;
};
this.getParams = function (overrides) {
return Utils.omitValues(_objectSpread(_objectSpread(_objectSpread({}, _this.extraParams), _this.searchParams), overrides));
};
this.initParams = function (params) {
_this.searchParams = _objectSpread(_objectSpread({}, params), _this.searchParams);
};
this.clearParams = function (name) {
if (name) {
delete _this.searchParams[name];
} else {
_this.searchParams = {};
}
};
this.setParams = function (params) {
var shouldSetFormValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (params) {
_this.searchParams = _objectSpread(_objectSpread({}, _this.searchParams), params);
if (shouldSetFormValues) {
_this.form.setFieldsValue(params);
}
}
};
this.reset = function () {
_this.clearParams();
_this.form.resetFields();
_this.setParams(_this.form.getFieldsValue());
};
this.search = function (params) {
var finalParams = _this.getParams(params);
_this.onSearch(finalParams);
};
this.onSearch = function () {};
this.resetStore = function () {
resetStore(_this, SearchStore);
};
overrideStore(this, _overrides);
makeObservable(this, {
search: action,
onSearch: action
});
});
export { SearchStore as default };