1 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2 | import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
3 | import _extends from "@babel/runtime/helpers/extends";
|
4 | import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
5 |
|
6 | var _defaultStatus;
|
7 |
|
8 | import { observable, runInAction, toJS } from 'mobx';
|
9 | import React from 'react';
|
10 | import noop from 'lodash/noop';
|
11 | import isObject from 'lodash/isObject';
|
12 | import isBoolean from 'lodash/isBoolean';
|
13 | import { categories } from 'choerodon-ui-font';
|
14 | import { FieldType, RecordStatus } from '../../pro/es/data-set/enum';
|
15 | import { $l } from '../../pro/es/locale-context';
|
16 | import { ColumnAlign, TableQueryBarType } from '../../pro/es/table/enum';
|
17 | import defaultFeedback from '../../pro/es/data-set/FeedBack';
|
18 | import { LabelLayout, ShowValidation } from '../../pro/es/form/enum';
|
19 | import { ButtonColor, FuncType } from '../../pro/es/button/enum';
|
20 | import { defaultExcludeUseColonTag } from '../../pro/es/form/utils';
|
21 | import { Action } from '../trigger/enum';
|
22 | import { Size } from '../_util/enum';
|
23 | import Popover from '../popover';
|
24 |
|
25 | function isCustomizable(target) {
|
26 | return isObject(target);
|
27 | }
|
28 |
|
29 | var defaultTooltipTheme = function defaultTooltipTheme(target) {
|
30 | return target === 'validation' ? 'light' : 'dark';
|
31 | };
|
32 |
|
33 | var defaultRenderEmpty = function defaultRenderEmpty(componentName) {
|
34 | switch (componentName) {
|
35 | case 'Attachment':
|
36 | return $l('Attachment', 'no_attachments');
|
37 |
|
38 | case 'Table':
|
39 | return $l('Table', 'empty_data');
|
40 |
|
41 | case 'Select':
|
42 | return $l('Select', 'no_matching_results');
|
43 |
|
44 | case 'Output':
|
45 | return '';
|
46 |
|
47 | default:
|
48 | }
|
49 | };
|
50 |
|
51 | var defaultFormFieldHighlightRenderer = function defaultFormFieldHighlightRenderer(_ref, element) {
|
52 | var content = _ref.content,
|
53 | hidden = _ref.hidden,
|
54 | rest = _objectWithoutProperties(_ref, ["content", "hidden"]);
|
55 |
|
56 | return content ? React.createElement(Popover, _extends({}, hidden ? _objectSpread({}, rest, {
|
57 | visible: false
|
58 | }) : rest, {
|
59 | content: content
|
60 | }), element) : element;
|
61 | };
|
62 |
|
63 | var defaultButtonProps = {
|
64 | color: ButtonColor.primary,
|
65 | funcType: FuncType.flat
|
66 | };
|
67 | var defaultSpinProps = {
|
68 | size: Size["default"],
|
69 | wrapperClassName: ''
|
70 | };
|
71 |
|
72 | var defaultTableColumnAlign = function defaultTableColumnAlign(_column, field) {
|
73 | if (field) {
|
74 | var type = field.type;
|
75 |
|
76 | switch (type) {
|
77 | case FieldType.number:
|
78 | case FieldType.currency:
|
79 | return ColumnAlign.right;
|
80 |
|
81 | case FieldType["boolean"]:
|
82 | return ColumnAlign.center;
|
83 |
|
84 | default:
|
85 | }
|
86 | }
|
87 | };
|
88 |
|
89 | function getComponentKey(component) {
|
90 | switch (component) {
|
91 | case 'Tabs':
|
92 | return 'tabs';
|
93 |
|
94 | default:
|
95 | return 'table';
|
96 | }
|
97 | }
|
98 |
|
99 | var defaultLookupCache = {
|
100 | maxAge: 1000 * 60 * 10,
|
101 | max: 100
|
102 | };
|
103 | var defaultStatus = (_defaultStatus = {}, _defineProperty(_defaultStatus, RecordStatus.add, 'add'), _defineProperty(_defaultStatus, RecordStatus.update, 'update'), _defineProperty(_defaultStatus, RecordStatus["delete"], 'delete'), _defaultStatus);
|
104 |
|
105 | var defaultCustomizedSave = function defaultCustomizedSave(code, customized, component) {
|
106 | return localStorage.setItem("".concat(getComponentKey(component), ".customized.").concat(code), JSON.stringify(customized));
|
107 | };
|
108 |
|
109 | var defaultCustomizedLoad = function defaultCustomizedLoad(code, component) {
|
110 | return Promise.resolve(JSON.parse(localStorage.getItem("".concat(getComponentKey(component), ".customized.").concat(code)) || 'null'));
|
111 | };
|
112 |
|
113 | var defaultFormatter = {
|
114 | jsonDate: 'YYYY-MM-DD HH:mm:ss',
|
115 | date: 'YYYY-MM-DD',
|
116 | dateTime: 'YYYY-MM-DD HH:mm:ss',
|
117 | time: 'HH:mm:ss',
|
118 | year: 'YYYY',
|
119 | month: 'YYYY-MM',
|
120 | week: 'GGGG-Wo'
|
121 | };
|
122 | var defaultAttachment = {
|
123 | defaultFileKey: 'file',
|
124 | defaultFileSize: 0
|
125 | };
|
126 | var defaultConfig = {
|
127 | prefixCls: 'c7n',
|
128 | proPrefixCls: 'c7n-pro',
|
129 | iconfontPrefix: 'icon',
|
130 | ripple: true,
|
131 | collapseExpandIconPosition: 'left',
|
132 | collapseTrigger: 'header',
|
133 | lookupCache: defaultLookupCache,
|
134 | lookupUrl: function lookupUrl(code) {
|
135 | return "/common/code/".concat(code, "/");
|
136 | },
|
137 | lookupAxiosMethod: 'post',
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | lovDefineUrl: function lovDefineUrl(code) {
|
147 | return "/sys/lov/lov_define?code=".concat(code);
|
148 | },
|
149 | lovQueryUrl: function lovQueryUrl(code) {
|
150 | return "/common/lov/dataset/".concat(code);
|
151 | },
|
152 | lovTableProps: {},
|
153 | lovModalProps: {},
|
154 | lovAutoSelectSingle: false,
|
155 | dataKey: 'rows',
|
156 | totalKey: 'total',
|
157 | statusKey: '__status',
|
158 | tlsKey: '__tls',
|
159 | status: defaultStatus,
|
160 | labelLayout: LabelLayout.horizontal,
|
161 | queryBar: TableQueryBarType.normal,
|
162 | tableBorder: true,
|
163 | tableHighLightRow: true,
|
164 | tableSelectedHighLightRow: false,
|
165 | tableRowHeight: 30,
|
166 | tableDefaultRenderer: '',
|
167 | tableColumnResizable: true,
|
168 | tableColumnHideable: true,
|
169 | performanceTableColumnHideable: true,
|
170 | tableRowDraggable: false,
|
171 | tableColumnDraggable: false,
|
172 | performanceTableColumnDraggable: false,
|
173 | tableColumnAlign: defaultTableColumnAlign,
|
174 | tableSpinProps: defaultSpinProps,
|
175 | tableButtonProps: defaultButtonProps,
|
176 | tableCommandProps: defaultButtonProps,
|
177 | tableAlwaysShowRowBox: false,
|
178 | tableUseMouseBatchChoose: false,
|
179 | tableEditorNextKeyEnterDown: true,
|
180 | tableAutoFocus: false,
|
181 | tableKeyboard: false,
|
182 | tableFilterSearchText: 'params',
|
183 | tableAutoHeightDiff: 80,
|
184 | customizedSave: defaultCustomizedSave,
|
185 | customizedLoad: defaultCustomizedLoad,
|
186 | tableShowRemovedRow: true,
|
187 | modalSectionBorder: true,
|
188 | drawerSectionBorder: true,
|
189 | drawerTransitionName: 'slide-right',
|
190 | modalOkFirst: true,
|
191 | modalAutoCenter: false,
|
192 | modalKeyboard: true,
|
193 | modalMaskClosable: false,
|
194 | buttonColor: ButtonColor["default"],
|
195 | buttonFuncType: FuncType.raised,
|
196 | feedback: defaultFeedback,
|
197 | renderEmpty: defaultRenderEmpty,
|
198 | icons: categories,
|
199 | formatter: defaultFormatter,
|
200 | dropdownMatchSelectWidth: true,
|
201 | selectReverse: true,
|
202 | selectPagingOptionContent: '···',
|
203 | selectSearchable: false,
|
204 | selectTrigger: [Action.focus, Action.click],
|
205 | useColon: false,
|
206 | excludeUseColonTagList: defaultExcludeUseColonTag,
|
207 | numberFieldNonStrictStep: false,
|
208 | showInvalidDate: true,
|
209 | highlightRenderer: defaultFormFieldHighlightRenderer,
|
210 | onPerformance: noop,
|
211 | performanceEnabled: {
|
212 | Table: false
|
213 | },
|
214 | tooltipTheme: defaultTooltipTheme,
|
215 | showValidation: ShowValidation.tooltip,
|
216 | attachment: defaultAttachment
|
217 | };
|
218 | var globalConfig = observable.map(defaultConfig);
|
219 | export function getConfig(key) {
|
220 | return globalConfig.get(key);
|
221 | }
|
222 | export function getPrefixCls(suffixCls, customizePrefixCls) {
|
223 | if (customizePrefixCls) {
|
224 | return customizePrefixCls;
|
225 | }
|
226 |
|
227 | return "".concat(getConfig('prefixCls'), "-").concat(suffixCls);
|
228 | }
|
229 | export function getProPrefixCls(suffixCls, customizePrefixCls) {
|
230 | if (customizePrefixCls) {
|
231 | return customizePrefixCls;
|
232 | }
|
233 |
|
234 | return "".concat(getConfig('proPrefixCls'), "-").concat(suffixCls);
|
235 | }
|
236 | export function getCustomizable(component) {
|
237 | var customizable = getConfig('customizable');
|
238 |
|
239 | if (isBoolean(customizable)) {
|
240 | return customizable;
|
241 | }
|
242 |
|
243 | if (isCustomizable(customizable)) {
|
244 | return customizable[component];
|
245 | }
|
246 | }
|
247 | var mergeProps = ['transport', 'feedback', 'formatter', 'attachment', 'pagination'];
|
248 | export default function configure(config) {
|
249 | var merge = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
250 | runInAction(function () {
|
251 | Object.keys(config).forEach(function (key) {
|
252 | var value = config[key];
|
253 |
|
254 | if (merge && mergeProps.includes(key) && isObject(value)) {
|
255 | globalConfig.set(key, _objectSpread({}, toJS(globalConfig.get(key)), {}, value));
|
256 | } else {
|
257 | globalConfig.set(key, config[key]);
|
258 | }
|
259 | });
|
260 | });
|
261 | }
|
262 |
|