UNPKG

saas-dynamic-component

Version:

saas-dynamic-component ==== saas平台动态引擎组件库,目前包括查询引擎、表格引擎,后续待增加...

555 lines (459 loc) 22.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4; var _templateObject = _taggedTemplateLiteral(['<ant-Spin size="small">'], ['<ant-Spin size="small">']); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _mobx = require('mobx'); var _mobxReact = require('mobx-react'); var _nornj = require('nornj'); var _nornj2 = _interopRequireDefault(_nornj); var _nornjReact = require('nornj-react'); var _coreDecorators = require('core-decorators'); var _form = require('flarej/lib/components/antd/form'); var _form2 = _interopRequireDefault(_form); var _message = require('flarej/lib/components/antd/message'); var _message2 = _interopRequireDefault(_message); var _searchEngine = require('./searchEngine.scss'); var _searchEngine2 = _interopRequireDefault(_searchEngine); var _searchEngineT = require('./searchEngine.t.html'); var _searchEngineT2 = _interopRequireDefault(_searchEngineT); var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment); require('../../utils/nj.configs'); var _util = require('../../utils/util'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } function _initDefineProp(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object['ke' + 'ys'](descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object['define' + 'Property'](target, property, desc); desc = null; } return desc; } function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); } var SearchEngine = (_dec = (0, _nornjReact.registerTmpl)('SearchEngine'), _dec2 = (0, _mobxReact.inject)('store'), _dec3 = _form2.default.create(), _dec(_class = _dec2(_class = _dec3(_class = (0, _mobxReact.observer)(_class = (_class2 = function (_Component) { _inherits(SearchEngine, _Component); function SearchEngine() { var _temp, _this, _ret; _classCallCheck(this, SearchEngine); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _initDefineProp(_this, 'selectLoading', _descriptor, _this), _initDefineProp(_this, 'cascaderLoading', _descriptor2, _this), _initDefineProp(_this, 'propertyId', _descriptor3, _this), _initDefineProp(_this, 'queryAllShow', _descriptor4, _this), _temp), _possibleConstructorReturn(_this, _ret); } SearchEngine.prototype.componentDidMount = function componentDidMount() { var _props = this.props, searchEngine = _props.store.searchEngine, form = _props.form, appCode = _props.appCode, menuUrl = _props.menuUrl; searchEngine.setQueryParams([]); searchEngine.setCascaderData({}); searchEngine.setPopupVisible({}); searchEngine.setResultLoading(true); searchEngine.getTemplate({ appCode: appCode, menuUrl: menuUrl }); }; // 当查询项多余6条时,展开/收起控制 SearchEngine.prototype.queryItemChange = function queryItemChange() { var searchEngine = this.props.store.searchEngine; this.queryAllShow = !this.queryAllShow; if (this.queryAllShow) { searchEngine.setQueryItem(searchEngine.searchCollection); } else { searchEngine.setQueryItem(searchEngine.searchCollection.slice(0, 6)); } }; /** * select 相关功能 * searchSelectValue => 下拉后台模糊搜索 * onFocusSelect => 下拉初始化数据 * filterOptionChange => 前端搜索,暂废弃 */ SearchEngine.prototype.searchSelectValue = function searchSelectValue(id, isMultiSelect, field) { var _this2 = this; return function (value) { var _props2 = _this2.props, searchEngine = _props2.store.searchEngine, appCode = _props2.appCode, form = _props2.form; // 增加级联逻辑 var cascadeFields = void 0, searchValue = void 0; if (field.cascadeFields) { cascadeFields = searchEngine.searchCollection.find(function (item) { return item.pkTemplateField == field.cascadeFields; }); form.validateFields(function (err, values) { if (cascadeFields.dataType == 5 || cascadeFields.dataType == 9) { searchValue = values[cascadeFields.code] != undefined ? values[cascadeFields.code][values[cascadeFields.code].length - 1] : ''; } else { searchValue = values[cascadeFields.code]; } }); } searchEngine.selectItem[field.code] = []; searchEngine.setItemSelect(_extends({}, searchEngine.selectItem)); _this2.selectLoading = (0, _nornj2.default)(_templateObject)(); searchEngine.getSelectItem({ appCode: appCode, propertyId: id, searchLabel: value, searchValue: searchValue, size: field.dataType == 6 ? 50 : '' }, isMultiSelect).then(function (res) { _this2.selectLoading = (0, _util.intlSaaS)('emptyData'); if (res && res.length > 0) { if (isMultiSelect == 0) { res.unshift({ value: '', label: (0, _util.intlSaaS)('all') }); } searchEngine.selectItem[field.code] = res; searchEngine.setItemSelect(_extends({}, searchEngine.selectItem)); } }); }; }; SearchEngine.prototype.onFocusSelect = function onFocusSelect(id, isMultiSelect, field) { var _this3 = this; return function (e) { var _props3 = _this3.props, searchEngine = _props3.store.searchEngine, appCode = _props3.appCode, form = _props3.form; // 增加级联逻辑 var cascadeFields = void 0, searchValue = void 0; if (field.cascadeFields) { cascadeFields = searchEngine.searchCollection.find(function (item) { return item.pkTemplateField == field.cascadeFields; }); form.validateFields(function (err, values) { if (cascadeFields.dataType == 5 || cascadeFields.dataType == 9) { searchValue = values[cascadeFields.code] != undefined ? values[cascadeFields.code][values[cascadeFields.code].length - 1] : ''; } else { searchValue = values[cascadeFields.code]; } }); } searchEngine.selectItem[field.code] = []; searchEngine.setItemSelect(_extends({}, searchEngine.selectItem)); _this3.selectLoading = (0, _nornj2.default)(_templateObject)(); searchEngine.getSelectItem({ appCode: appCode, propertyId: id, searchValue: searchValue, size: field.dataType == 6 ? 50 : '' }, isMultiSelect).then(function (res) { _this3.selectLoading = (0, _util.intlSaaS)('emptyData');; if (res && res.length > 0) { if (isMultiSelect == 0) { res.unshift({ value: '', label: (0, _util.intlSaaS)('all') }); } searchEngine.selectItem[field.code] = res; searchEngine.setItemSelect(_extends({}, searchEngine.selectItem)); } }); }; }; SearchEngine.prototype.filterOptionChange = function filterOptionChange(input, option) { return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0; }; SearchEngine.prototype.setChildren = function setChildren(data) { var _this4 = this; return data.map(function (item) { if (item.children) { item.children = _this4.setChildren(item.children); } item.isLeaf = false; return item; }); }; SearchEngine.prototype.formValue = function formValue(options) { return this.props.form.getFieldDecorator(options.props.propSelf, { rules: [{ required: options.props.required == 1 ? true : false, message: (0, _util.intlSaaS)('notEmpty') }], initialValue: options.props.defaultValue })(options.result()); }; SearchEngine.prototype.getReturnType = function getReturnType(type, item) { if (type == 1) { return item.value; } else if (type == 2) { return item.label; } else { return item.id; } }; SearchEngine.prototype.getShowType = function getShowType(type, item) { if (item.label == (0, _util.intlSaaS)('all')) { return item.label; } if (type == 1) { return item.label; } else { return item.value; } }; /** * cascader 相关 * onPopupVisible 显示/隐藏浮层回调 * onChangeCascader 选择完成回调 * onChangeCascaderInput 一级搜索输入回调 * onFocusCascaderInput 一级搜索聚焦回调 * loadDataCascader 动态加载数据回调 */ SearchEngine.prototype.onPopupVisible = function onPopupVisible(id, code) { var _this5 = this; return function (value) { var _props4 = _this5.props, searchEngine = _props4.store.searchEngine, appCode = _props4.appCode; _this5.propertyId = id; if (searchEngine.cascaderData[code] == undefined) { searchEngine.cascaderData[code] = []; } searchEngine.popupVisible[code] = value; searchEngine.setPopupVisible(_extends({}, searchEngine.popupVisible)); if (value && searchEngine.cascaderData[code].length == 0) { searchEngine.getCascader({ propertyId: id, appCode: appCode, parentValue: null }).then(function (res) { if (res) { _this5.cascaderLoading = (0, _util.intlSaaS)('emptyData'); res.map(function (item) { item.isLeaf = false; }); searchEngine.cascaderData[code] = res; searchEngine.setCascaderData(_extends({}, searchEngine.cascaderData)); } }); } }; }; SearchEngine.prototype.onChangeCascader = function onChangeCascader(code) { var _this6 = this; return function (value, selectedOptions) { var _props5 = _this6.props, searchEngine = _props5.store.searchEngine, appCode = _props5.appCode; if (value.length == 0 && selectedOptions.length == 0) { // 点击列表时,隐藏输入搜索 searchEngine.cascaderInputVisible[code] = false; searchEngine.setPopupVisible(_extends({}, searchEngine.cascaderInputVisible)); searchEngine.getCascader({ propertyId: _this6.propertyId, appCode: appCode, parentValue: null }).then(function (res) { if (res) { _this6.cascaderLoading = (0, _util.intlSaaS)('emptyData'); res.map(function (item) { item.isLeaf = false; }); searchEngine.cascaderData[code] = res; searchEngine.setCascaderData(_extends({}, searchEngine.cascaderData)); } }); } }; }; SearchEngine.prototype.onChangeCascaderInput = function onChangeCascaderInput(id, code) { var _this7 = this; return function (e) { var _props6 = _this7.props, searchEngine = _props6.store.searchEngine, appCode = _props6.appCode; _this7.propertyId = id; searchEngine.popupVisible[code] = true; searchEngine.setPopupVisible(_extends({}, searchEngine.popupVisible)); searchEngine.getCascader({ propertyId: id, appCode: appCode, parentValue: null, searchLabel: e.target.value }).then(function (res) { if (res) { _this7.cascaderLoading = (0, _util.intlSaaS)('emptyData'); res.map(function (item) { item.isLeaf = false; }); searchEngine.cascaderData[code] = res; searchEngine.setCascaderData(_extends({}, searchEngine.cascaderData)); } }); }; }; SearchEngine.prototype.onFocusCascaderInput = function onFocusCascaderInput(id, code) { var _this8 = this; return function (e) { var _props7 = _this8.props, searchEngine = _props7.store.searchEngine, appCode = _props7.appCode; _this8.propertyId = id; if (searchEngine.cascaderData[code] == undefined) { searchEngine.cascaderData[code] = []; } if (searchEngine.popupVisible[code] != true) { searchEngine.popupVisible[code] = true; searchEngine.setPopupVisible(_extends({}, searchEngine.popupVisible)); if (searchEngine.cascaderData[code].length == 0) { searchEngine.getCascader({ propertyId: id, appCode: appCode, parentValue: null }).then(function (res) { if (res) { res.map(function (item) { item.isLeaf = false; }); searchEngine.cascaderData[code] = res; searchEngine.setCascaderData(_extends({}, searchEngine.cascaderData)); } }); } } }; }; SearchEngine.prototype.loadDataCascader = function loadDataCascader(code) { var _this9 = this; return function (selectedOptions) { var _props8 = _this9.props, searchEngine = _props8.store.searchEngine, appCode = _props8.appCode; // 点击列表时,隐藏输入搜索 searchEngine.cascaderInputVisible[code] = true; // searchEngine.setPopupVisible({...searchEngine.cascaderInputVisible}); searchEngine.setCascaderInputVisible(_extends({}, searchEngine.cascaderInputVisible)); var targetOption = selectedOptions[selectedOptions.length - 1]; targetOption.loading = true; searchEngine.getCascader({ propertyId: _this9.propertyId, appCode: appCode, parentValue: targetOption.value }).then(function (res) { if (res && res.length != 0) { targetOption.children = res.map(function (item) { item.isLeaf = false; return item; }); } else { targetOption.isLeaf = true; } _this9.cascaderLoading = (0, _util.intlSaaS)('emptyData'); targetOption.loading = false; searchEngine.setCascaderData(_extends({}, searchEngine.cascaderData)); }); }; }; SearchEngine.prototype.onSearch = function onSearch() { var _props9 = this.props, _props9$store = _props9.store, searchEngine = _props9$store.searchEngine, tableEngine = _props9$store.tableEngine, form = _props9.form, appCode = _props9.appCode, menuUrl = _props9.menuUrl; this.props.onBuried(); form.validateFields(function (err, value) { if (!err) { searchEngine.setQueryParams(value); tableEngine.setCurrentPage(1); var sort = ''; if (tableEngine.sorter) { sort = tableEngine.sorter.field + ',' + tableEngine.sorter.order; } var params = { fieldCodes: tableEngine.fieldCodes, queryParams: searchEngine.queryParams, pageNum: 1, pageSize: tableEngine.pageSize, operationInfo: tableEngine.opsInfo.query, sort: sort }; tableEngine.setTableLoading(true); tableEngine.translateParams(params, { appCode: appCode, menuUrl: menuUrl }).then(function (result) { if (result) { tableEngine.searchTableData(result, tableEngine.operations.query + '?appCode=' + appCode + '&menuUrl=' + menuUrl).then(function () { tableEngine.setTableLoading(false); }); } }); } }); }; SearchEngine.prototype.onReset = function onReset() { var _props10 = this.props, _props10$store = _props10.store, tableEngine = _props10$store.tableEngine, searchEngine = _props10$store.searchEngine, form = _props10.form, appCode = _props10.appCode, menuUrl = _props10.menuUrl; form.resetFields(); tableEngine.setCurrentPage(1); var params = { fieldCodes: tableEngine.fieldCodes, queryParams: [], pageNum: 1, pageSize: tableEngine.pageSize, operationInfo: tableEngine.opsInfo.query }; searchEngine.setQueryParams([]); tableEngine.translateParams(params, { appCode: appCode, menuUrl: menuUrl }).then(function (result) { if (result) { tableEngine.searchTableData(result, tableEngine.operations.query + '?appCode=' + appCode + '&menuUrl=' + menuUrl); } }); }; SearchEngine.prototype.render = function render() { var _props11 = this.props, searchEngine = _props11.store.searchEngine, form = _props11.form; this.props.onChange(form); return _searchEngineT2.default.searchEngine(this.props, this, { styles: _searchEngine2.default, searchEngine: searchEngine, lang: (0, _util.getLang)().toLowerCase() }); }; return SearchEngine; }(_react.Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'selectLoading', [_mobx.observable], { enumerable: true, initializer: function initializer() { return (0, _nornj2.default)(_templateObject)(); } }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, 'cascaderLoading', [_mobx.observable], { enumerable: true, initializer: function initializer() { return (0, _nornj2.default)(_templateObject)(); } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, 'propertyId', [_mobx.observable], { enumerable: true, initializer: function initializer() { return null; } }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, 'queryAllShow', [_mobx.observable], { enumerable: true, initializer: function initializer() { return false; } }), _applyDecoratedDescriptor(_class2.prototype, 'queryItemChange', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'queryItemChange'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'searchSelectValue', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'searchSelectValue'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onFocusSelect', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onFocusSelect'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'filterOptionChange', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'filterOptionChange'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'getReturnType', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'getReturnType'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'getShowType', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'getShowType'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onPopupVisible', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onPopupVisible'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onChangeCascader', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onChangeCascader'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onChangeCascaderInput', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onChangeCascaderInput'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onFocusCascaderInput', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onFocusCascaderInput'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'loadDataCascader', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'loadDataCascader'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onSearch', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onSearch'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'onReset', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class2.prototype, 'onReset'), _class2.prototype)), _class2)) || _class) || _class) || _class) || _class); exports.default = SearchEngine; SearchEngine.defaultProps = { onChange: function onChange() {}, onBuried: function onBuried() {} };