choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
107 lines (96 loc) • 5.47 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _ref;
import { observable, runInAction, toJS } from 'mobx';
import isObject from 'lodash/isObject';
import { categories } from 'choerodon-ui-font';
import { RecordStatus } from '../../pro/es/data-set/enum';
import { $l } from '../../pro/es/locale-context';
import { TableQueryBarType } from '../../pro/es/table/enum';
import defaultFeedback from '../../pro/es/data-set/FeedBack';
import { LabelLayout } from '../../pro/es/form/enum';
import { ButtonColor, FuncType } from '../../pro/es/button/enum';
import { defaultExcludeUseColonTag } from '../../pro/es/form/utils';
import { Size } from '../_util/enum';
var defaultRenderEmpty = function defaultRenderEmpty(componentName) {
switch (componentName) {
case 'Table':
return $l('Table', 'empty_data');
case 'Select':
return $l('Select', 'no_matching_results');
case 'Output':
return '';
default:
}
};
var defaultButtonProps = {
color: ButtonColor.primary,
funcType: FuncType.flat
};
var defaultSpinProps = {
size: Size["default"],
wrapperClassName: ''
};
var globalConfig = observable.map([['prefixCls', 'c7n'], ['proPrefixCls', 'c7n-pro'], ['iconfontPrefix', 'icon'], ['ripple', true], ['collapseExpandIconPosition', 'left'], ['collapseTrigger', 'header'], ['lookupCache', {
maxAge: 1000 * 60 * 10,
max: 100
}], ['lookupUrl', function (code) {
return "/common/code/".concat(code, "/");
}], ['lookupAxiosMethod', 'post'], // [
// 'lookupBatchAxiosConfig',
// codes => ({
// url: '/common/batch',
// params: codes.reduce((obj, code) => {
// obj[code] = code;
// return obj;
// }, {}),
// }),
// ],
['lovDefineUrl', function (code) {
return "/sys/lov/lov_define?code=".concat(code);
}], ['lovQueryUrl', function (code) {
return "/common/lov/dataset/".concat(code);
}], ['lovTableProps', {}], ['lovModalProps', {}], ['lovAutoSelectSingle', false], ['dataKey', 'rows'], ['totalKey', 'total'], ['statusKey', '__status'], ['tlsKey', '__tls'], ['status', (_ref = {}, _defineProperty(_ref, RecordStatus.add, 'add'), _defineProperty(_ref, RecordStatus.update, 'update'), _defineProperty(_ref, RecordStatus["delete"], 'delete'), _ref)], ['labelLayout', LabelLayout.horizontal], ['queryBar', TableQueryBarType.normal], ['tableBorder', true], ['tableHighLightRow', true], ['tableSelectedHighLightRow', false], ['tableRowHeight', 30], ['tableDefaultRenderer', ''], ['tableColumnResizable', true], ['tableColumnHideable', true], ['tableRowDraggable', false], ['tableColumnDraggable', false], ['tableSpinProps', defaultSpinProps], ['tableButtonProps', defaultButtonProps], ['tableCommandProps', defaultButtonProps], ['tableAlwaysShowRowBox', false], ['tableUseMouseBatchChoose', false], ['tableEditorNextKeyEnterDown', true], ['tableAutoFocus', false], ['tableKeyboard', false], ['tableFilterSearchText', 'params'], ['tableAutoHeightDiff', 80], ['tableCustomizedSave', function (code, customized) {
return localStorage.setItem("table.customized.".concat(code), JSON.stringify(customized));
}], ['tableCustomizedLoad', function (code) {
return Promise.resolve(JSON.parse(localStorage.getItem("table.customized.".concat(code)) || 'null'));
}], ['modalSectionBorder', true], ['drawerSectionBorder', true], ['drawerTransitionName', 'slide-right'], ['modalOkFirst', true], ['modalAutoCenter', false], ['drawerOkFirst', undefined], ['modalKeyboard', true], ['modalMaskClosable', false], ['buttonColor', ButtonColor["default"]], ['buttonFuncType', FuncType.raised], ['feedback', defaultFeedback], ['renderEmpty', defaultRenderEmpty], ['icons', categories], ['formatter', {
jsonDate: 'YYYY-MM-DD HH:mm:ss',
date: 'YYYY-MM-DD',
dateTime: 'YYYY-MM-DD HH:mm:ss',
time: 'HH:mm:ss',
year: 'YYYY',
month: 'YYYY-MM',
week: 'GGGG-Wo'
}], ['dropdownMatchSelectWidth', true], ['selectReverse', true], ['selectPagingOptionContent', '···'], ['selectSearchable', false], ['useColon', false], ['excludeUseColonTagList', defaultExcludeUseColonTag], ['textFieldAutoComplete', undefined], ['numberFieldNonStrictStep', false], ['numberFieldFormatter', undefined], ['numberFieldFormatterOptions', undefined]]);
export function getConfig(key) {
// FIXME: observable.map把构建map时传入的key类型和value类型分别做了union,
// 丢失了一一对应的映射关系,导致函数调用者无法使用union后的返回值类型,因此需要指定本函数返回值为any
return globalConfig.get(key);
}
export function getPrefixCls(suffixCls, customizePrefixCls) {
if (customizePrefixCls) {
return customizePrefixCls;
}
return "".concat(getConfig('prefixCls'), "-").concat(suffixCls);
}
export function getProPrefixCls(suffixCls, customizePrefixCls) {
if (customizePrefixCls) {
return customizePrefixCls;
}
return "".concat(getConfig('proPrefixCls'), "-").concat(suffixCls);
}
var mergeProps = ['transport', 'feedback', 'formatter', 'tableFilterAdapter'];
export default function configure(config) {
runInAction(function () {
Object.keys(config).forEach(function (key) {
var value = config[key];
if (mergeProps.includes(key) && isObject(value)) {
globalConfig.set(key, _objectSpread({}, toJS(globalConfig.get(key)), {}, value));
} else {
globalConfig.set(key, config[key]);
}
});
});
}
//# sourceMappingURL=index.js.map