UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

1,357 lines (1,136 loc) 37.5 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import { __decorate } from "tslib"; import { action, computed, get as _get, isArrayLike, isObservableObject, observable, remove, runInAction, set as _set, toJS } from 'mobx'; import raf from 'raf'; import omit from 'lodash/omit'; import isEqual from 'lodash/isEqual'; import isObject from 'lodash/isObject'; import merge from 'lodash/merge'; import { getConfig } from '../../../es/configure'; import warning from '../../../es/_util/warning'; import DataSet from './DataSet'; import Validator from '../validator/Validator'; import { DataSetEvents, DataSetSelection, FieldTrim, FieldType } from './enum'; import lookupStore from '../stores/LookupCodeStore'; import lovCodeStore from '../stores/LovCodeStore'; import attachmentStore from '../stores/AttachmentStore'; import localeContext from '../locale-context'; import { defaultTextField, defaultValueField, getBaseType, getChainFieldName, getIf, getLimit, processValue } from './utils'; import isSame from '../_util/isSame'; import isSameLike from '../_util/isSameLike'; import { buildURLWithAxiosConfig } from '../axios/utils'; import { getDateFormatByField } from '../field/utils'; import { getLovPara } from '../stores/utils'; import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from '../number-field/utils'; import AttachmentFile from './AttachmentFile'; function isEqualDynamicProps(oldProps, newProps) { if (newProps === oldProps) { return true; } if (isObject(newProps) && isObject(oldProps)) { var newKeys = Object.keys(newProps); var length = newKeys.length; if (length) { if (length !== Object.keys(oldProps).length) { return false; } return newKeys.every(function (key) { var value = newProps[key]; var oldValue = oldProps[key]; if (oldValue === value) { return true; } if (typeof value === 'function' && typeof oldValue === 'function') { return value.toString() === oldValue.toString(); } return isEqual(oldValue, value); }); } } return isEqual(newProps, oldProps); } function getPropsFromLovConfig(lovCode, propsName) { var props = {}; if (lovCode) { var config = lovCodeStore.getConfig(lovCode); if (config) { propsName.forEach(function (name) { var value = config[name]; if (value) { props[name] = value; } }); } } return props; } var LOOKUP_SIDE_EFFECT_KEYS = ['type', 'lookupUrl', 'lookupCode', 'lookupAxiosConfig', 'lovCode', 'lovQueryAxiosConfig', 'lovPara', 'cascadeMap', 'lovQueryUrl', 'optionsProps']; var LOV_SIDE_EFFECT_KEYS = ['lovCode', 'lovDefineAxiosConfig', 'lovDefineUrl', 'optionsProps']; var LOOKUP_TOKEN = '__lookup_token__'; var Field = /*#__PURE__*/ function () { function Field() { var _this = this; var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var dataSet = arguments.length > 1 ? arguments[1] : undefined; var record = arguments.length > 2 ? arguments[2] : undefined; _classCallCheck(this, Field); runInAction(function () { _this.dataSet = dataSet; _this.record = record; _this.props = observable.map(props); // 优化性能,没有动态属性时不用处理, 直接引用dsField; 有options时,也不处理 if (!_this.getProp('options')) { var dynamicProps = _this.getProp('dynamicProps'); if (!record || typeof dynamicProps === 'function') { raf(function () { _this.fetchLookup(); _this.fetchLovConfig(); }); } else { var computedProps = _this.getProp('computedProps'); if (computedProps || dynamicProps) { var keys = Object.keys(_objectSpread({}, computedProps, {}, dynamicProps)); if (keys.length) { var fetches = []; if (keys.some(function (key) { return LOOKUP_SIDE_EFFECT_KEYS.includes(key); })) { fetches.push(_this.fetchLookup); } if (keys.some(function (key) { return LOV_SIDE_EFFECT_KEYS.includes(key); })) { fetches.push(_this.fetchLovConfig); } if (fetches.length) { raf(function () { return fetches.forEach(function (one) { return one.call(_this); }); }); } } } } } }); } _createClass(Field, [{ key: "getProps", /** * 获取所有属性 * @return 属性对象 */ value: function getProps() { var dsField = this.findDataSetField(); var lovCode = this.get('lovCode'); return merge({ lookupUrl: getConfig('lookupUrl') }, Field.defaultProps, getPropsFromLovConfig(lovCode, ['textField', 'valueField']), dsField && dsField.props.toPOJO(), this.props.toPOJO()); } /** * 根据属性名获取属性值 * @param propsName 属性名 * @return {any} */ }, { key: "get", value: function get(propsName) { var prop = this.getProp(propsName); if (prop !== undefined) { return prop; } return Field.defaultProps[propsName]; } }, { key: "getProp", value: function getProp(propsName) { var _this2 = this; if (!['computedProps', 'dynamicProps'].includes(propsName)) { var computedPropsMap = getIf(this, 'computedProps', function () { return new Map(); }); var computedProp = computedPropsMap.get(propsName); if (computedProp) { var computedValue = computedProp.get(); if (computedValue !== undefined) { return computedValue; } } else { var computedProps = this.get('computedProps'); if (computedProps) { var newComputedProp = computed(function () { var computProp = computedProps[propsName]; if (typeof computProp === 'function') { var prop = _this2.executeDynamicProps(computProp, propsName); if (prop !== undefined) { _this2.checkDynamicProp(propsName, prop); return prop; } } }, { name: propsName, context: this }); computedPropsMap.set(propsName, newComputedProp); var _computedValue = newComputedProp.get(); if (_computedValue !== undefined) { return _computedValue; } } } var dynamicProps = this.get('dynamicProps'); if (dynamicProps) { if (typeof dynamicProps === 'function') { warning(false, " The dynamicProps hook will be deprecated. Please use dynamicProps map.\n For e.g,\n Bad case:\n dynamicProps({ record }) {\n return {\n bind: record.get('xx'),\n label: record.get('yy'),\n }\n }\n Good case:\n dynamicProps = {\n bind({ record }) {\n return record.get('xx')\n },\n label({ record }) {\n return record.get('yy'),\n }\n }"); var props = this.executeDynamicProps(dynamicProps, propsName); if (props && propsName in props) { var prop = props[propsName]; this.checkDynamicProp(propsName, prop); return prop; } } else { var dynamicProp = dynamicProps[propsName]; if (typeof dynamicProp === 'function') { var _prop = this.executeDynamicProps(dynamicProp, propsName); if (_prop !== undefined) { this.checkDynamicProp(propsName, _prop); return _prop; } } } this.checkDynamicProp(propsName, undefined); } } var value = this.props.get(propsName); if (value !== undefined) { return value; } var dsField = this.findDataSetField(); if (dsField) { var dsValue = dsField.getProp(propsName); if (dsValue !== undefined) { return dsValue; } } if (propsName === 'lookup') { var dataSet = this.dataSet; if (dataSet) { var lookupToken = this.get(LOOKUP_TOKEN); var lookupCaches = dataSet.lookupCaches; if (lookupToken && lookupCaches) { return lookupCaches.get(lookupToken); } } } if (propsName === 'textField' || propsName === 'valueField') { var lovCode = this.get('lovCode'); var lovProp = getPropsFromLovConfig(lovCode, [propsName])[propsName]; if (lovProp) { return lovProp; } } if (propsName === 'lookupUrl') { return getConfig(propsName); } if (['min', 'max'].includes(propsName)) { if (this.type === FieldType.number) { if (propsName === 'max') { return MAX_SAFE_INTEGER; } return MIN_SAFE_INTEGER; } } return undefined; } /** * 设置属性值 * @param propsName 属性名 * @param value 属性值 * @return {any} */ }, { key: "set", value: function set(propsName, value) { var oldValue = this.get(propsName); if (!isEqualDynamicProps(toJS(oldValue), value)) { var dirtyProps = getIf(this, 'dirtyProps', {}); if (!(propsName in dirtyProps)) { _set(dirtyProps, propsName, oldValue); } else if (isSame(toJS(dirtyProps[propsName]), value)) { remove(dirtyProps, propsName); } this.props.set(propsName, value); var record = this.record, dataSet = this.dataSet, name = this.name; if (record && propsName === 'type') { record.set(name, processValue(record.get(name), this)); } if (dataSet) { dataSet.fireEvent(DataSetEvents.fieldChange, { dataSet: dataSet, record: record, name: name, field: this, propsName: propsName, value: value, oldValue: oldValue }); } this.handlePropChange(propsName, value, oldValue); } } /** * 根据lookup值获取lookup对象 * @param value lookup值 * @return {object} */ }, { key: "getLookupData", value: function getLookupData() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getValue(); var valueField = this.get('valueField'); var data = {}; if (this.lookup) { return this.lookup.find(function (obj) { return isSameLike(_get(obj, valueField), value); }) || data; } return data; } }, { key: "getValue", value: function getValue() { var dataSet = this.dataSet, name = this.name; var record = this.record || dataSet && dataSet.current; if (record) { return record.get(name); } } /** * 可以根据lookup值获取含义 * @param value lookup值 * @param boolean showValueIfNotFound * @return {string} */ }, { key: "getLookupText", value: function getLookupText() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getValue(); var showValueIfNotFound = arguments.length > 1 ? arguments[1] : undefined; var textField = this.get('textField'); var valueField = this.get('valueField'); var lookup = this.lookup; if (lookup) { var found = lookup.find(function (obj) { return isSameLike(_get(obj, valueField), value); }); if (found) { return _get(found, textField); } if (showValueIfNotFound) { return value; } return undefined; } } /** * 可以根据options值获取含义 * @param value opions值 * @param boolean showValueIfNotFound * @return {string} */ }, { key: "getOptionsText", value: function getOptionsText() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getValue(); var showValueIfNotFound = arguments.length > 1 ? arguments[1] : undefined; var textField = this.get('textField'); var valueField = this.get('valueField'); var options = this.options; if (options) { var found = options.find(function (record) { return isSameLike(record.get(valueField), value); }); if (found) { return found.get(textField); } if (showValueIfNotFound) { return value; } return undefined; } } /** * 根据lookup值获取lookup含义 * @param value lookup值 * @param boolean showValueIfNotFound * @return {string} */ }, { key: "getText", value: function getText() { var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getValue(); var showValueIfNotFound = arguments.length > 1 ? arguments[1] : undefined; var lookup = this.lookup; if (lookup && !isObject(value)) { return this.getLookupText(value, showValueIfNotFound); } var options = this.get('options'); var textField = this.get('textField'); if (options) { var valueField = this.get('valueField'); var found = options.find(function (record) { return isSameLike(record.get(valueField), value); }); if (found) { return found.get(textField); } } if (textField && isObject(value)) { if (isObservableObject(value)) { return _get(value, textField); } return value[textField]; } return value; } }, { key: "setOptions", value: function setOptions(options) { this.set('options', options); } }, { key: "getOptions", value: function getOptions() { return this.options; } /** * 重置设置的属性 */ }, { key: "reset", value: function reset() { var dirtyProps = this.dirtyProps; if (dirtyProps) { this.props.merge(dirtyProps); this.dirtyProps = undefined; } } }, { key: "commit", value: function commit() { var validator = this.validator; if (validator) { validator.reset(); } } /** * 是否必选 * @return true | false */ }, { key: "setLovPara", /** * 设置Lov的查询参数 * @param {String} name * @param {Object} value */ value: function setLovPara(name, value) { var p = toJS(this.get('lovPara')) || {}; if (value === null) { delete p[name]; } else { p[name] = value; } this.set('lovPara', p); } }, { key: "getValidatorProps", value: function getValidatorProps() { var record = this.record; if (record) { var dataSet = this.dataSet, name = this.name, type = this.type, required = this.required, attachmentCount = this.attachmentCount; var baseType = getBaseType(type); var customValidator = this.get('validator'); var max = this.get('max'); var min = this.get('min'); var format = this.get('format') || getDateFormatByField(this, this.type); var pattern = this.get('pattern'); var step = this.get('step'); var nonStrictStep = this.get('nonStrictStep') === undefined ? getConfig('numberFieldNonStrictStep') : this.get('nonStrictStep'); var minLength = baseType !== FieldType.string ? undefined : this.get('minLength'); var maxLength = baseType !== FieldType.string ? undefined : this.get('maxLength'); var label = this.get('label'); var range = this.get('range'); var multiple = this.get('multiple'); var unique = this.get('unique'); var defaultValidationMessages = this.get('defaultValidationMessages'); var validatorProps = { type: type, required: required, record: record, dataSet: dataSet, name: name, unique: unique, customValidator: customValidator, pattern: pattern, max: getLimit(max, record), min: getLimit(min, record), step: step, nonStrictStep: nonStrictStep, minLength: minLength, maxLength: maxLength, label: label, range: range, multiple: multiple, format: format, attachmentCount: attachmentCount, defaultValidationMessages: defaultValidationMessages }; if (!this.validatorPropKeys) { this.validatorPropKeys = Object.keys(omit(validatorProps, ['label', 'defaultValidationMessages'])); } return validatorProps; } } /** * 校验字段值 * 只有通过record.getField()获取的field才能校验 * @return true | false */ }, { key: "checkValidity", value: function () { var _checkValidity = _asyncToGenerator( /*#__PURE__*/ _regeneratorRuntime.mark(function _callee() { var report, valid, record, validator, value, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: report = _args.length > 0 && _args[0] !== undefined ? _args[0] : true; valid = true; record = this.record; if (!record) { _context.next = 11; break; } validator = this.validator; if (validator) { validator.reset(); } else { validator = new Validator(this); this.validator = validator; } value = record.get(this.name); _context.next = 9; return validator.checkValidity(value); case 9: valid = _context.sent; if (report && !record.validating) { record.reportValidity(valid); } case 11: return _context.abrupt("return", valid); case 12: case "end": return _context.stop(); } } }, _callee, this); })); function checkValidity() { return _checkValidity.apply(this, arguments); } return checkValidity; }() /** * 请求lookup值, 如有缓存值直接获得。 * @param noCache default: undefined * @return Promise<object[]> */ }, { key: "fetchLookup", value: function fetchLookup() { var _this3 = this; var noCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var dataSet = this.dataSet; if (dataSet) { var lookup = this.lookup; var lookupCaches = getIf(dataSet, 'lookupCaches', function () { return observable.map(); }); var oldToken = this.get(LOOKUP_TOKEN); var batch = this.get('lookupBatchAxiosConfig') || getConfig('lookupBatchAxiosConfig'); var lookupCode = this.get('lookupCode'); var promise; if (batch && lookupCode && Object.keys(getLovPara(this, this.record)).length === 0) { var cachedLookup = lookupCaches.get(lookupCode); if (lookupCode !== oldToken) { this.set(LOOKUP_TOKEN, lookupCode); } if (cachedLookup) { if (isArrayLike(cachedLookup)) { promise = Promise.resolve(cachedLookup); } else { this.pending = true; promise = cachedLookup; } } if (!promise) { this.pending = true; promise = lookupStore.fetchLookupDataInBatch(lookupCode, batch).then(action(function (result) { if (result) { lookupCaches.set(lookupCode, result); } return result; })); lookupCaches.set(lookupCode, promise); } } else { var axiosConfig = lookupStore.getAxiosConfig(this, noCache); if (axiosConfig.url) { var lookupToken = buildURLWithAxiosConfig(axiosConfig); if (lookupToken !== oldToken) { this.set(LOOKUP_TOKEN, lookupToken); } if (!noCache) { var _cachedLookup = lookupCaches.get(lookupToken); if (_cachedLookup) { if (isArrayLike(_cachedLookup)) { promise = Promise.resolve(_cachedLookup); } else { this.pending = true; promise = _cachedLookup; } } } if (!promise) { this.pending = true; promise = lookupStore.fetchLookupData(axiosConfig).then(action(function (result) { if (result) { lookupCaches.set(lookupToken, result); } return result; })); lookupCaches.set(lookupToken, promise); } } } if (promise) { return promise.then(action(function (result) { _this3.pending = false; if (lookup && oldToken !== _this3.get(LOOKUP_TOKEN)) { var value = _this3.getValue(); var valueField = _this3.get('valueField'); if (value && valueField) { var _ref; var values = _this3.get('multiple') ? (_ref = []).concat.apply(_ref, _toConsumableArray(value)) : [].concat(value); _this3.set('lookupData', values.reduce(function (lookupData, v) { var found = lookup.find(function (item) { return isSameLike(item[valueField], v); }); if (found) { lookupData.push(found); } return lookupData; }, [])); } } return toJS(result); }))["catch"](function (e) { _this3.pending = false; throw e; }); } } return Promise.resolve(undefined); } }, { key: "fetchLovConfig", value: function fetchLovConfig() { var lovCode = this.get('lovCode'); if (lovCode) { lovCodeStore.fetchConfig(lovCode, this); } } }, { key: "fetchAttachments", value: function fetchAttachments(props) { var _this4 = this; var bucketName = props.bucketName, bucketDirectory = props.bucketDirectory, attachmentUUID = props.attachmentUUID, storageCode = props.storageCode; var _getConfig = getConfig('attachment'), fetchList = _getConfig.fetchList; if (fetchList) { fetchList({ bucketName: bucketName, bucketDirectory: bucketDirectory, attachmentUUID: attachmentUUID, storageCode: storageCode }).then(action(function (results) { _this4.attachments = results.map(function (file) { return new AttachmentFile(file); }); })); } } }, { key: "fetchAttachmentCount", value: function fetchAttachmentCount(uuid) { var _this5 = this; var _getConfig2 = getConfig('attachment'), batchFetchCount = _getConfig2.batchFetchCount; if (batchFetchCount && !this.attachments) { attachmentStore.fetchCountInBatch(uuid).then(function (count) { _this5.attachmentCount = count; }); } } }, { key: "isValid", value: function isValid() { return this.valid; } }, { key: "getValidationMessage", value: function getValidationMessage() { var validator = this.validator; return validator ? validator.validationMessage : undefined; } }, { key: "getValidityState", value: function getValidityState() { var validator = this.validator; return validator ? validator.validity : undefined; } }, { key: "getValidationErrorValues", value: function getValidationErrorValues() { var validator = this.validator; return validator ? validator.validationResults : []; } }, { key: "ready", value: function ready() { return Promise.resolve(true); } }, { key: "findDataSetField", value: function findDataSetField() { var dataSet = this.dataSet, name = this.name, record = this.record; if (record && dataSet && name) { return dataSet.getField(name); } } }, { key: "checkDynamicProp", value: function checkDynamicProp(propsName, newProp) { var _this6 = this; var lastDynamicProps = getIf(this, 'lastDynamicProps', {}); var oldProp = lastDynamicProps[propsName]; if (!isEqualDynamicProps(oldProp, newProp)) { raf(action(function () { var validator = _this6.validator, validatorPropKeys = _this6.validatorPropKeys; if (validator && (propsName === 'validator' || validatorPropKeys && validatorPropKeys.includes(propsName))) { validator.reset(); } _this6.handlePropChange(propsName, newProp, oldProp); })); } lastDynamicProps[propsName] = newProp; } }, { key: "handlePropChange", value: function handlePropChange(propsName, newProp, oldProp) { if (propsName === 'bind' && this.type !== FieldType.intl) { var record = this.record; if (record && !this.dirty) { if (newProp && oldProp) { record.init(newProp, record.get(oldProp)); } if (oldProp) { record.init(oldProp, undefined); } } return; } if (LOOKUP_SIDE_EFFECT_KEYS.includes(propsName)) { this.set('lookupData', undefined); this.fetchLookup(); } if (LOV_SIDE_EFFECT_KEYS.includes(propsName)) { this.fetchLovConfig(); } } }, { key: "executeDynamicProps", value: function executeDynamicProps(dynamicProps, propsName) { var dataSet = this.dataSet, name = this.name, record = this.record; var dynamicPropsComputingChains = getIf(this, 'dynamicPropsComputingChains', []); if (dynamicPropsComputingChains.includes(propsName)) { warning(false, "Cycle dynamicProps execution of field<".concat(name, ">. [").concat(dynamicPropsComputingChains.join(' -> '), " -> ").concat(propsName, "]")); } else if (dataSet) { dynamicPropsComputingChains.push(propsName); try { return dynamicProps({ dataSet: dataSet, record: record, name: name }); } catch (e) { if (process.env.NODE_ENV !== 'production') { console.warn(e); } } finally { dynamicPropsComputingChains.pop(); } } } }, { key: "attachments", get: function get() { var dataSet = this.dataSet, record = this.record; if (dataSet && record) { var attachmentCaches = dataSet.attachmentCaches; var uuid = record.get(this.name); if (uuid && attachmentCaches) { var cache = attachmentCaches.get(uuid); if (cache) { return _get(cache, 'attachments'); } } } return this.get('attachments'); }, set: function set(attachments) { var _this7 = this; runInAction(function () { var record = _this7.record; if (record) { var uuid = record.get(_this7.name); var dataSet = _this7.dataSet; if (dataSet && uuid) { var attachmentCaches = getIf(dataSet, 'attachmentCaches', function () { return observable.map(); }); if (attachmentCaches) { var cache = attachmentCaches.get(uuid); if (cache) { _set(cache, 'attachments', attachments); } else { attachmentCaches.set(uuid, { attachments: attachments }); } return; } } } _this7.set('attachments', attachments); }); } }, { key: "attachmentCount", get: function get() { var attachments = this.attachments; if (attachments) { return attachments.length; } var dataSet = this.dataSet, record = this.record; if (dataSet && record) { var attachmentCaches = dataSet.attachmentCaches; var uuid = record.get(this.name); if (uuid && attachmentCaches) { var cache = attachmentCaches.get(uuid); if (cache) { return _get(cache, 'count'); } } } return this.get('attachmentCount'); }, set: function set(count) { var _this8 = this; runInAction(function () { var record = _this8.record; if (record) { var uuid = record.get(_this8.name); var dataSet = _this8.dataSet; if (dataSet && uuid) { var attachmentCaches = getIf(dataSet, 'attachmentCaches', function () { return observable.map(); }); if (attachmentCaches) { var cache = attachmentCaches.get(uuid); if (cache) { _set(cache, 'count', count); } else { attachmentCaches.set(uuid, { count: count }); } return; } } } _this8.set('attachmentCount', count); }); } }, { key: "pristineProps", get: function get() { return _objectSpread({}, this.props.toPOJO(), {}, this.dirtyProps); }, set: function set(props) { var _this9 = this; runInAction(function () { var dirtyProps = _this9.dirtyProps; if (dirtyProps) { var newProps = {}; var dirtyKeys = Object.keys(dirtyProps); if (dirtyKeys.length) { dirtyKeys.forEach(function (key) { var item = _this9.props.get(key); newProps[key] = item; if (isSame(item, props[key])) { delete dirtyProps[key]; } else { dirtyProps[key] = props[key]; } }); } _this9.props.replace(_objectSpread({}, props, {}, newProps)); } else { _this9.props.replace(props); } }); } }, { key: "lookup", get: function get() { var dataSet = this.dataSet; if (dataSet) { var lookupToken = this.get(LOOKUP_TOKEN); var lookupCaches = dataSet.lookupCaches; if (lookupToken && lookupCaches) { var lookup = lookupCaches.get(lookupToken); if (isArrayLike(lookup)) { var valueField = this.get('valueField'); var lookupData = this.get('lookupData'); if (lookupData) { var others = lookupData.filter(function (data) { return lookup.every(function (item) { return item[valueField] !== data[valueField]; }); }); if (others.length) { return others.concat(lookup.slice()); } } return lookup; } } } return undefined; } }, { key: "options", get: function get() { var options = this.get('options'); if (options) { return options; } // 确保 lookup 相关配置介入观察 lookupStore.getAxiosConfig(this); var optionsProps = this.get('optionsProps'); var lookup = this.lookup, type = this.type; if (lookup) { var parentField = this.get('parentField'); var idField = this.get('idField') || this.get('valueField'); var selection = this.get('multiple') ? DataSetSelection.multiple : DataSetSelection.single; return new DataSet(_objectSpread({ data: lookup, paging: false, selection: selection, idField: idField, parentField: parentField }, optionsProps)); } var lovCode = this.get('lovCode'); if (lovCode) { if (type === FieldType.object || type === FieldType.auto) { return lovCodeStore.getLovDataSet(lovCode, this, optionsProps); } } return undefined; } }, { key: "dirty", get: function get() { var record = this.record, name = this.name; if (record) { var dirtyData = record.dirtyData; if (dirtyData) { var dirtyNames = _toConsumableArray(dirtyData.keys()); if (dirtyNames.length) { if (dirtyNames.includes(getChainFieldName(record, name))) { return true; } if (this.type === FieldType.intl) { var tlsKey = getConfig('tlsKey'); if (record.get(tlsKey) && Object.keys(localeContext.supports).some(function (lang) { return dirtyNames.includes(getChainFieldName(record, "".concat(tlsKey, ".").concat(name, ".").concat(lang))); })) { return true; } } } } } return false; } }, { key: "name", get: function get() { return this.props.get('name'); } }, { key: "order", get: function get() { return this.get('order'); }, set: function set(order) { this.set('order', order); } }, { key: "valid", get: function get() { var validator = this.validator; return validator ? validator.validity.valid : true; } }, { key: "validationMessage", get: function get() { return this.getValidationMessage(); } }, { key: "required", get: function get() { return this.get('required'); } /** * 设置是否必选 * @param required 是否必选 */ , set: function set(required) { this.set('required', required); } /** * 是否只读 * @return true | false */ }, { key: "readOnly", get: function get() { return this.get('readOnly'); } /** * 是否禁用 * @return true | false */ , /** * 设置是否只读 * @param readOnly 是否只读 */ set: function set(readOnly) { this.set('readOnly', readOnly); } /** * 设置是否禁用 * @param disabled 是否禁用 */ }, { key: "disabled", get: function get() { return this.get('disabled'); }, set: function set(disabled) { this.set('disabled', disabled); } /** * 获取字段类型 * @return 获取字段类型 */ }, { key: "type", get: function get() { return this.get('type'); } /** * 设置字段类型 * @param type 字段类型 */ , set: function set(type) { this.set('type', type); } }]); return Field; }(); export { Field as default }; Field.defaultProps = { type: FieldType.auto, required: false, readOnly: false, disabled: false, group: false, textField: defaultTextField, valueField: defaultValueField, trueValue: true, falseValue: false, trim: FieldTrim.both }; __decorate([observable], Field.prototype, "validator", void 0); __decorate([observable], Field.prototype, "pending", void 0); __decorate([observable], Field.prototype, "props", void 0); __decorate([observable], Field.prototype, "dirtyProps", void 0); __decorate([computed], Field.prototype, "options", null); __decorate([action], Field.prototype, "set", null); __decorate([action], Field.prototype, "reset", null); __decorate([action], Field.prototype, "commit", null); __decorate([action], Field.prototype, "setLovPara", null); __decorate([action], Field.prototype, "checkValidity", null); __decorate([action], Field.prototype, "fetchLookup", null); //# sourceMappingURL=Field.js.map