@bit-sun/business-component 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/BsLayouts/Components/AllFunc/drawContent.d.ts +1 -1
  9. package/dist/components/Business/BsLayouts/Components/AllFunc/index.d.ts +1 -1
  10. package/dist/components/Business/BsLayouts/Components/RightContent/index.d.ts +2 -2
  11. package/dist/components/Business/BsLayouts/Components/SearchFunc/index.d.ts +2 -2
  12. package/dist/components/Business/BsLayouts/index.d.ts +2 -2
  13. package/dist/components/Business/BsSulaQueryTable/utils.d.ts +2 -2
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.esm.js +7804 -9105
  16. package/dist/index.js +7803 -9103
  17. package/dist/plugin/TableColumnSetting/index.d.ts +64 -0
  18. package/dist/plugin/TableColumnSetting/utils.d.ts +1 -0
  19. package/dist/utils/LocalstorageUtils.d.ts +2 -0
  20. package/dist/utils/TableUtils.d.ts +2 -2
  21. package/dist/utils/utils.d.ts +1 -1
  22. package/docs/index.md +21 -21
  23. package/lib/assets/drag.svg +17 -17
  24. package/lib/assets/exportFail.svg +37 -37
  25. package/lib/assets/exportProcessing.svg +28 -28
  26. package/lib/assets/exportSuccess.svg +34 -34
  27. package/lib/assets/label_icon_bottom.svg +25 -25
  28. package/lib/assets/upExport.svg +22 -22
  29. package/package.json +77 -77
  30. package/src/assets/32.svg +27 -27
  31. package/src/assets/addIcon.svg +17 -17
  32. package/src/assets/allfunc.svg +27 -27
  33. package/src/assets/arrowRight.svg +24 -24
  34. package/src/assets/btn-delete.svg +29 -29
  35. package/src/assets/btn-edit.svg +19 -19
  36. package/src/assets/btn-more.svg +17 -17
  37. package/src/assets/btn-submit.svg +19 -19
  38. package/src/assets/caidan.svg +11 -11
  39. package/src/assets/close.svg +26 -26
  40. package/src/assets/drag.svg +17 -17
  41. package/src/assets/exportFail.svg +37 -37
  42. package/src/assets/exportProcessing.svg +28 -28
  43. package/src/assets/exportSuccess.svg +34 -34
  44. package/src/assets/fixed-left-active.svg +11 -11
  45. package/src/assets/fixed-left.svg +15 -15
  46. package/src/assets/fixed-right-active.svg +11 -11
  47. package/src/assets/fixed-right.svg +15 -15
  48. package/src/assets/guanbi.svg +15 -15
  49. package/src/assets/icon-quanping.svg +15 -15
  50. package/src/assets/icon-shezhi.svg +17 -17
  51. package/src/assets/label_icon_bottom.svg +25 -25
  52. package/src/assets/list-no-img.svg +21 -21
  53. package/src/assets/morentouxiang-32.svg +23 -23
  54. package/src/assets/scanning.svg +24 -24
  55. package/src/assets/upExport.svg +22 -22
  56. package/src/components/Business/AddSelectBusiness/index.md +63 -42
  57. package/src/components/Business/AddSelectBusiness/index.tsx +344 -341
  58. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  59. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  60. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  61. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  62. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  63. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  64. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  65. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  66. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  67. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  68. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  69. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  70. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  71. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  72. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  73. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  74. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +156 -156
  75. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  76. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  77. package/src/components/Business/BsLayouts/index.less +79 -79
  78. package/src/components/Business/BsLayouts/index.tsx +1479 -1479
  79. package/src/components/Business/BsLayouts/service.ts +10 -10
  80. package/src/components/Business/BsLayouts/utils.tsx +230 -230
  81. package/src/components/Business/BsSulaQueryTable/index.less +219 -219
  82. package/src/components/Business/BsSulaQueryTable/index.tsx +480 -476
  83. package/src/components/Business/BsSulaQueryTable/setting.tsx +802 -802
  84. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  85. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  86. package/src/components/Business/CommodityEntry/index.md +70 -70
  87. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  88. package/src/components/Business/CommonAlert/index.tsx +23 -23
  89. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  90. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  91. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  92. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  93. package/src/components/Business/DetailPageWrapper/index.tsx +335 -335
  94. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  95. package/src/components/Business/HomePageWrapper/index.less +33 -33
  96. package/src/components/Business/HomePageWrapper/index.md +45 -45
  97. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  98. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  99. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +201 -201
  100. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  101. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  102. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  103. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  104. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  105. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  106. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  107. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  108. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  109. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  110. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  111. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  112. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  113. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  114. package/src/components/Business/JsonQueryTable/index.less +16 -16
  115. package/src/components/Business/JsonQueryTable/index.md +328 -328
  116. package/src/components/Business/JsonQueryTable/index.tsx +320 -320
  117. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  118. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  119. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  120. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  121. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  122. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  123. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  124. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  125. package/src/components/Business/JsonQueryTable/static.ts +356 -356
  126. package/src/components/Business/SearchSelect/BusinessUtils.ts +1586 -1586
  127. package/src/components/Business/SearchSelect/common.ts +53 -53
  128. package/src/components/Business/SearchSelect/index.md +1254 -1254
  129. package/src/components/Business/SearchSelect/index.tsx +51 -51
  130. package/src/components/Business/SearchSelect/utils.ts +100 -100
  131. package/src/components/Business/StateFlow/index.less +130 -130
  132. package/src/components/Business/StateFlow/index.md +60 -60
  133. package/src/components/Business/StateFlow/index.tsx +29 -29
  134. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  135. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  136. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  137. package/src/components/Business/columnSettingTable/columnSetting.tsx +764 -764
  138. package/src/components/Business/columnSettingTable/index.less +247 -247
  139. package/src/components/Business/columnSettingTable/index.md +357 -357
  140. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  141. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  142. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  143. package/src/components/Business/moreTreeTable/index.less +99 -99
  144. package/src/components/Business/moreTreeTable/index.md +508 -508
  145. package/src/components/Business/moreTreeTable/index.tsx +315 -315
  146. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  147. package/src/components/Functional/AddSelect/index.less +367 -367
  148. package/src/components/Functional/AddSelect/index.md +155 -154
  149. package/src/components/Functional/AddSelect/index.tsx +1072 -994
  150. package/src/components/Functional/BillEntry/index.less +371 -371
  151. package/src/components/Functional/BillEntry/index.md +39 -39
  152. package/src/components/Functional/BillEntry/index.tsx +766 -670
  153. package/src/components/Functional/DataImport/index.less +63 -63
  154. package/src/components/Functional/DataImport/index.md +44 -44
  155. package/src/components/Functional/DataImport/index.tsx +695 -695
  156. package/src/components/Functional/DataValidation/index.less +63 -63
  157. package/src/components/Functional/DataValidation/index.md +39 -39
  158. package/src/components/Functional/DataValidation/index.tsx +687 -687
  159. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  160. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  161. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  162. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  163. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  164. package/src/components/Functional/SearchSelect/index.less +115 -115
  165. package/src/components/Functional/SearchSelect/index.md +141 -141
  166. package/src/components/Functional/SearchSelect/index.tsx +813 -813
  167. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  168. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  169. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  170. package/src/index.ts +34 -34
  171. package/src/plugin/TableColumnSetting/index.less +247 -0
  172. package/src/plugin/TableColumnSetting/index.md +50 -0
  173. package/src/plugin/TableColumnSetting/index.tsx +724 -0
  174. package/src/plugin/TableColumnSetting/utils.ts +19 -0
  175. package/src/styles/bsDefault.less +1906 -1906
  176. package/src/utils/CheckOneUser/index.md +39 -39
  177. package/src/utils/CheckOneUser/index.ts +51 -51
  178. package/src/utils/LocalstorageUtils.ts +33 -0
  179. package/src/utils/TableUtils.tsx +18 -18
  180. package/src/utils/checkUtils.ts +39 -39
  181. package/src/utils/enumConfig.ts +10 -10
  182. package/src/utils/getFormMode.js +12 -12
  183. package/src/utils/index.ts +2 -2
  184. package/src/utils/requestUtils.ts +33 -33
  185. package/src/utils/serialize.js +7 -7
  186. package/src/utils/utils.ts +183 -183
  187. package/tsconfig.json +29 -29
  188. package/typings.d.ts +4 -4
@@ -1,346 +1,346 @@
1
- import React, { useEffect } from 'react';
2
- import {
3
- Typography,
4
- Button,
5
- message,
6
- Popconfirm,
7
- Tooltip,
8
- Row,
9
- Col,
10
- Space,
11
- } from 'antd';
12
- import Editor, { monaco } from '@monaco-editor/react';
13
- import serialize, { deserialize } from '@/utils/serialize';
14
- import {
15
- BulbOutlined,
16
- PlayCircleOutlined,
17
- DeleteOutlined,
18
- CopyOutlined,
19
- SaveOutlined,
20
- FullscreenOutlined,
21
- FullscreenExitOutlined,
22
- } from '@ant-design/icons';
23
- import validateSulaConfig from './lint';
24
- import * as acorn from 'acorn';
25
- import * as walk from 'acorn-walk';
26
- import ConfigTree, { iconRender, nameRender } from '../configTree';
27
- import registerSuggestions from './suggestions';
28
- import style from './index.less';
29
-
30
- const { Title } = Typography;
31
- const STRTEMP = 'const config = ';
32
-
33
- const getEditorValue = data => {
34
- return `${STRTEMP}${serialize(data, { space: 2, unsafe: true })}`;
35
- };
36
-
37
- let isRegister;
38
- let decorations = [];
39
-
40
- export default props => {
41
- const monacoRef = React.useRef(null);
42
- const {
43
- onRun,
44
- value,
45
- type,
46
- onFullScreen = () => {},
47
- shallowHeight = 0,
48
- } = props;
49
-
50
- const editorRef = React.useRef(null);
51
- const [highLightLine, setHighLightLine] = React.useState();
52
- const [isFull, setFull] = React.useState(false);
53
-
54
- const isTableAllValue = !!value?.columns;
55
-
56
- const finalValue = getEditorValue(isTableAllValue ? {columns: value?.columns, fields: value?.fields} : value);
57
- const [treeData, setTreeData] = React.useState(finalValue);
58
-
59
- const handleCopy = () => {
60
- const value1 = editorRef.current.getValue().slice(STRTEMP.length);
61
-
62
- try {
63
- const res = deserialize(value1);
64
- onRun(isTableAllValue ? {...value, columns: res.columns, fields: res.fields}: res, true);
65
- formatDocument();
66
- setFull(false);
67
- } catch (e) {
68
- message.error(`JSON 格式错误`);
69
- }
70
- };
71
-
72
- const formatDocument = () => {
73
- setTimeout(() => {
74
- editorRef.current &&
75
- editorRef.current.getAction('editor.action.formatDocument').run();
76
- }, 300);
77
- };
78
-
79
- monaco.init().then(ref => {
80
- monacoRef.current = ref;
81
- if (!isRegister) {
82
- registerSuggestions(ref);
83
- isRegister = true;
84
- }
85
- });
86
-
87
- const onEditorDidMount = (_monaco, editor) => {
88
- editorRef.current = editor;
89
- const model = editor.getModel();
90
-
91
- formatDocument();
92
-
93
- editor.onKeyDown(e => {
94
- if (e.shiftKey) {
95
- editorRef.current &&
96
- editorRef.current.trigger(
97
- 'auto completion',
98
- 'editor.action.triggerSuggest',
99
- );
100
- }
101
- });
102
-
103
- editor.onDidChangeCursorPosition(e => {
104
- const lineCount = editor.getModel().getLineCount();
105
- if (e.position.lineNumber === 1) {
106
- editor.setPosition({
107
- lineNumber: 2,
108
- column: 1,
109
- });
110
- } else if (e.position.lineNumber === lineCount) {
111
- editor.setPosition({
112
- lineNumber: lineCount - 1,
113
- column: 1,
114
- });
115
- }
116
- });
117
-
118
- editor.onMouseDown(event => {
119
- clearDecorations();
120
- onEditorLineChange(event.target.position);
121
- });
122
-
123
- editor.onKeyDown(event => {
124
- setTimeout(() => {
125
- const position = editor.getPosition();
126
- onEditorLineChange(position);
127
- setTreeData(editor.getValue());
128
- });
129
- });
130
-
131
- editor.onDidChangeModelContent(() => {
132
- const content = editor.getValue();
133
- const markers = monacoRef.current.editor.getModelMarkers();
134
-
135
- if (markers.length > 0) {
136
- markers.forEach(marker => {
137
- monacoRef.current.editor.setModelMarkers(
138
- editor.getModel(),
139
- marker.owner,
140
- [],
141
- );
142
- });
143
- }
144
- const ast = acorn.parse(content, { locations: true });
145
- walk.full(ast, node => {
146
- // if (node?.loc?.start?.column < 5) {
147
- validateSulaConfig(node, monacoRef.current, editor);
148
- // }
149
- });
150
- });
151
- };
152
-
153
- function onEditorLineChange(position) {
154
- const { lineNumber } = position || {};
155
- setHighLightLine(lineNumber);
156
- }
157
-
158
- // console.log(`点击字段: ${clickType}, 点击字段所属字段: ${type}, 提示: ${suggestionType}`);
159
-
160
- const onClickRun = () => {
161
- const value1 = editorRef.current.getValue().slice(STRTEMP.length);
162
-
163
- try {
164
- const res = deserialize(value1);
165
- onRun(isTableAllValue ? {...value, columns: res.columns, fields: res.fields}: res);
166
- formatDocument();
167
- setFull(false);
168
- message.success(`Run Success 🎉`);
169
- } catch (e) {
170
- message.error(`JSON 格式错误`);
171
- }
172
- };
173
-
174
- const onClickDelete = () => {
175
- editorRef.current.setValue(`${STRTEMP}{\n\n}`);
176
- };
177
-
178
- function clearDecorations() {
179
- if (decorations.length) {
180
- decorations = editorRef.current.deltaDecorations(decorations, []);
181
- }
182
- }
183
-
184
- function setDecorations(range) {
185
- const [startLineNumber, startColumn, endLineNumber, endColumn] = range;
186
- const newDecorations = editorRef.current.deltaDecorations(
187
- [],
188
- [
189
- {
190
- range: {
191
- endColumn,
192
- endLineNumber,
193
- startColumn,
194
- startLineNumber,
195
- },
196
- options: {
197
- className: 'si-editor-highlight',
198
- },
199
- },
200
- ],
201
- );
202
- decorations = decorations.concat(newDecorations);
203
- }
204
-
205
- const handleSelect = (node, hasChildren) => {
206
- const { loc, name } = node;
207
- clearDecorations();
208
- // 高亮
209
- if (hasChildren) {
210
- const [line, startColumn] = loc;
211
- const keyPosition = [line, startColumn, line, 100];
212
- setDecorations(keyPosition);
213
- } else {
214
- setDecorations(loc);
215
- }
216
- editorRef.current.revealLine(loc[0]); // 行跳转
217
- };
218
-
219
- const handleFullScreen = () => {
220
- setFull(true);
221
- };
222
-
223
- const handleExitFullScreen = () => {
224
- setFull(false);
225
- };
226
-
227
- useEffect(() => {
228
- editorRef?.current?.layout();
229
- onFullScreen && onFullScreen(isFull);
230
- }, [isFull]);
231
-
232
- useEffect(() => {
233
- editorRef?.current?.layout();
234
- }, [shallowHeight]);
235
-
236
- const hasConfigTree = type !== 'editor';
237
-
238
- return (
239
- <div className={isFull ? style.editorWrapper : ''}>
240
- <div style={{ overflow: 'hidden' }}>
241
- <Title style={{ float: 'left' }} level={4}>
242
- 代码展示
243
- </Title>
244
- <Tooltip title="按 shift 键快速呼出提示">
245
- <BulbOutlined
246
- style={{ marginLeft: 8, lineHeight: '32px', cursor: 'pointer' }}
247
- />
248
- </Tooltip>
249
- <Space style={{ float: 'right' }}>
250
- <Tooltip title="运行代码">
251
- <Button
252
- shape="circle"
253
- size="small"
254
- type="primary"
255
- icon={<PlayCircleOutlined />}
256
- onClick={onClickRun}
257
- shape="circle"
258
- />
259
- </Tooltip>
260
- {/* <Popconfirm title="确定要清空吗?" onConfirm={onClickDelete}>
261
- <Tooltip title="清空代码">
262
- <Button
263
- type="primary"
264
- icon={<DeleteOutlined />}
265
- size="small"
266
- shape="circle"
267
- />
268
- </Tooltip>
269
- </Popconfirm> */}
270
- <Tooltip title="保存">
271
- <Button
272
- type="primary"
273
- icon={<SaveOutlined />}
274
- onClick={handleCopy}
275
- style={{
276
- border: 'none',
277
- }}
278
- shape="circle"
279
- size="small"
280
- />
281
- </Tooltip>
282
- <div>
283
- <Tooltip title="退出全屏">
284
- <Button
285
- type="primary"
286
- icon={<FullscreenExitOutlined />}
287
- onClick={handleExitFullScreen}
288
- style={{
289
- border: 'none',
290
- display: !isFull ? 'none' : '',
291
- }}
292
- shape="circle"
293
- size="small"
294
- />
295
- </Tooltip>
296
- {/* <Tooltip title="全屏编辑">
297
- <Button
298
- type="primary"
299
- icon={<FullscreenOutlined />}
300
- onClick={handleFullScreen}
301
- style={{
302
- border: 'none',
303
- display: isFull ? 'none' : '',
304
- }}
305
- shape="circle"
306
- size="small"
307
- />
308
- </Tooltip> */}
309
- </div>
310
- </Space>
311
- </div>
312
- <Row>
313
- <Col span={hasConfigTree ? 16 : 24}>
314
- <Editor
315
- height={`calc(100vh - ${shallowHeight + 100}px)`}
316
- language="javascript"
317
- editorDidMount={onEditorDidMount}
318
- options={{
319
- selectOnLineNumbers: true,
320
- renderSideBySide: false,
321
- }}
322
- value={finalValue}
323
- // value={{columns: finalValue.columns, fields: finalValue.fields}}
324
- />
325
- </Col>
326
- {hasConfigTree && (
327
- <Col span={8}>
328
- <div className={style.title}>属性节点树</div>
329
- <ConfigTree
330
- style={{
331
- height: 'calc(100vh - 300px)',
332
- overflowY: 'scroll',
333
- }}
334
- level={1}
335
- data={treeData}
336
- onSelect={handleSelect}
337
- currentLine={highLightLine}
338
- iconRender={iconRender}
339
- nameRender={nameRender}
340
- />
341
- </Col>
342
- )}
343
- </Row>
344
- </div>
345
- );
346
- };
1
+ import React, { useEffect } from 'react';
2
+ import {
3
+ Typography,
4
+ Button,
5
+ message,
6
+ Popconfirm,
7
+ Tooltip,
8
+ Row,
9
+ Col,
10
+ Space,
11
+ } from 'antd';
12
+ import Editor, { monaco } from '@monaco-editor/react';
13
+ import serialize, { deserialize } from '@/utils/serialize';
14
+ import {
15
+ BulbOutlined,
16
+ PlayCircleOutlined,
17
+ DeleteOutlined,
18
+ CopyOutlined,
19
+ SaveOutlined,
20
+ FullscreenOutlined,
21
+ FullscreenExitOutlined,
22
+ } from '@ant-design/icons';
23
+ import validateSulaConfig from './lint';
24
+ import * as acorn from 'acorn';
25
+ import * as walk from 'acorn-walk';
26
+ import ConfigTree, { iconRender, nameRender } from '../configTree';
27
+ import registerSuggestions from './suggestions';
28
+ import style from './index.less';
29
+
30
+ const { Title } = Typography;
31
+ const STRTEMP = 'const config = ';
32
+
33
+ const getEditorValue = data => {
34
+ return `${STRTEMP}${serialize(data, { space: 2, unsafe: true })}`;
35
+ };
36
+
37
+ let isRegister;
38
+ let decorations = [];
39
+
40
+ export default props => {
41
+ const monacoRef = React.useRef(null);
42
+ const {
43
+ onRun,
44
+ value,
45
+ type,
46
+ onFullScreen = () => {},
47
+ shallowHeight = 0,
48
+ } = props;
49
+
50
+ const editorRef = React.useRef(null);
51
+ const [highLightLine, setHighLightLine] = React.useState();
52
+ const [isFull, setFull] = React.useState(false);
53
+
54
+ const isTableAllValue = !!value?.columns;
55
+
56
+ const finalValue = getEditorValue(isTableAllValue ? {columns: value?.columns, fields: value?.fields} : value);
57
+ const [treeData, setTreeData] = React.useState(finalValue);
58
+
59
+ const handleCopy = () => {
60
+ const value1 = editorRef.current.getValue().slice(STRTEMP.length);
61
+
62
+ try {
63
+ const res = deserialize(value1);
64
+ onRun(isTableAllValue ? {...value, columns: res.columns, fields: res.fields}: res, true);
65
+ formatDocument();
66
+ setFull(false);
67
+ } catch (e) {
68
+ message.error(`JSON 格式错误`);
69
+ }
70
+ };
71
+
72
+ const formatDocument = () => {
73
+ setTimeout(() => {
74
+ editorRef.current &&
75
+ editorRef.current.getAction('editor.action.formatDocument').run();
76
+ }, 300);
77
+ };
78
+
79
+ monaco.init().then(ref => {
80
+ monacoRef.current = ref;
81
+ if (!isRegister) {
82
+ registerSuggestions(ref);
83
+ isRegister = true;
84
+ }
85
+ });
86
+
87
+ const onEditorDidMount = (_monaco, editor) => {
88
+ editorRef.current = editor;
89
+ const model = editor.getModel();
90
+
91
+ formatDocument();
92
+
93
+ editor.onKeyDown(e => {
94
+ if (e.shiftKey) {
95
+ editorRef.current &&
96
+ editorRef.current.trigger(
97
+ 'auto completion',
98
+ 'editor.action.triggerSuggest',
99
+ );
100
+ }
101
+ });
102
+
103
+ editor.onDidChangeCursorPosition(e => {
104
+ const lineCount = editor.getModel().getLineCount();
105
+ if (e.position.lineNumber === 1) {
106
+ editor.setPosition({
107
+ lineNumber: 2,
108
+ column: 1,
109
+ });
110
+ } else if (e.position.lineNumber === lineCount) {
111
+ editor.setPosition({
112
+ lineNumber: lineCount - 1,
113
+ column: 1,
114
+ });
115
+ }
116
+ });
117
+
118
+ editor.onMouseDown(event => {
119
+ clearDecorations();
120
+ onEditorLineChange(event.target.position);
121
+ });
122
+
123
+ editor.onKeyDown(event => {
124
+ setTimeout(() => {
125
+ const position = editor.getPosition();
126
+ onEditorLineChange(position);
127
+ setTreeData(editor.getValue());
128
+ });
129
+ });
130
+
131
+ editor.onDidChangeModelContent(() => {
132
+ const content = editor.getValue();
133
+ const markers = monacoRef.current.editor.getModelMarkers();
134
+
135
+ if (markers.length > 0) {
136
+ markers.forEach(marker => {
137
+ monacoRef.current.editor.setModelMarkers(
138
+ editor.getModel(),
139
+ marker.owner,
140
+ [],
141
+ );
142
+ });
143
+ }
144
+ const ast = acorn.parse(content, { locations: true });
145
+ walk.full(ast, node => {
146
+ // if (node?.loc?.start?.column < 5) {
147
+ validateSulaConfig(node, monacoRef.current, editor);
148
+ // }
149
+ });
150
+ });
151
+ };
152
+
153
+ function onEditorLineChange(position) {
154
+ const { lineNumber } = position || {};
155
+ setHighLightLine(lineNumber);
156
+ }
157
+
158
+ // console.log(`点击字段: ${clickType}, 点击字段所属字段: ${type}, 提示: ${suggestionType}`);
159
+
160
+ const onClickRun = () => {
161
+ const value1 = editorRef.current.getValue().slice(STRTEMP.length);
162
+
163
+ try {
164
+ const res = deserialize(value1);
165
+ onRun(isTableAllValue ? {...value, columns: res.columns, fields: res.fields}: res);
166
+ formatDocument();
167
+ setFull(false);
168
+ message.success(`Run Success 🎉`);
169
+ } catch (e) {
170
+ message.error(`JSON 格式错误`);
171
+ }
172
+ };
173
+
174
+ const onClickDelete = () => {
175
+ editorRef.current.setValue(`${STRTEMP}{\n\n}`);
176
+ };
177
+
178
+ function clearDecorations() {
179
+ if (decorations.length) {
180
+ decorations = editorRef.current.deltaDecorations(decorations, []);
181
+ }
182
+ }
183
+
184
+ function setDecorations(range) {
185
+ const [startLineNumber, startColumn, endLineNumber, endColumn] = range;
186
+ const newDecorations = editorRef.current.deltaDecorations(
187
+ [],
188
+ [
189
+ {
190
+ range: {
191
+ endColumn,
192
+ endLineNumber,
193
+ startColumn,
194
+ startLineNumber,
195
+ },
196
+ options: {
197
+ className: 'si-editor-highlight',
198
+ },
199
+ },
200
+ ],
201
+ );
202
+ decorations = decorations.concat(newDecorations);
203
+ }
204
+
205
+ const handleSelect = (node, hasChildren) => {
206
+ const { loc, name } = node;
207
+ clearDecorations();
208
+ // 高亮
209
+ if (hasChildren) {
210
+ const [line, startColumn] = loc;
211
+ const keyPosition = [line, startColumn, line, 100];
212
+ setDecorations(keyPosition);
213
+ } else {
214
+ setDecorations(loc);
215
+ }
216
+ editorRef.current.revealLine(loc[0]); // 行跳转
217
+ };
218
+
219
+ const handleFullScreen = () => {
220
+ setFull(true);
221
+ };
222
+
223
+ const handleExitFullScreen = () => {
224
+ setFull(false);
225
+ };
226
+
227
+ useEffect(() => {
228
+ editorRef?.current?.layout();
229
+ onFullScreen && onFullScreen(isFull);
230
+ }, [isFull]);
231
+
232
+ useEffect(() => {
233
+ editorRef?.current?.layout();
234
+ }, [shallowHeight]);
235
+
236
+ const hasConfigTree = type !== 'editor';
237
+
238
+ return (
239
+ <div className={isFull ? style.editorWrapper : ''}>
240
+ <div style={{ overflow: 'hidden' }}>
241
+ <Title style={{ float: 'left' }} level={4}>
242
+ 代码展示
243
+ </Title>
244
+ <Tooltip title="按 shift 键快速呼出提示">
245
+ <BulbOutlined
246
+ style={{ marginLeft: 8, lineHeight: '32px', cursor: 'pointer' }}
247
+ />
248
+ </Tooltip>
249
+ <Space style={{ float: 'right' }}>
250
+ <Tooltip title="运行代码">
251
+ <Button
252
+ shape="circle"
253
+ size="small"
254
+ type="primary"
255
+ icon={<PlayCircleOutlined />}
256
+ onClick={onClickRun}
257
+ shape="circle"
258
+ />
259
+ </Tooltip>
260
+ {/* <Popconfirm title="确定要清空吗?" onConfirm={onClickDelete}>
261
+ <Tooltip title="清空代码">
262
+ <Button
263
+ type="primary"
264
+ icon={<DeleteOutlined />}
265
+ size="small"
266
+ shape="circle"
267
+ />
268
+ </Tooltip>
269
+ </Popconfirm> */}
270
+ <Tooltip title="保存">
271
+ <Button
272
+ type="primary"
273
+ icon={<SaveOutlined />}
274
+ onClick={handleCopy}
275
+ style={{
276
+ border: 'none',
277
+ }}
278
+ shape="circle"
279
+ size="small"
280
+ />
281
+ </Tooltip>
282
+ <div>
283
+ <Tooltip title="退出全屏">
284
+ <Button
285
+ type="primary"
286
+ icon={<FullscreenExitOutlined />}
287
+ onClick={handleExitFullScreen}
288
+ style={{
289
+ border: 'none',
290
+ display: !isFull ? 'none' : '',
291
+ }}
292
+ shape="circle"
293
+ size="small"
294
+ />
295
+ </Tooltip>
296
+ {/* <Tooltip title="全屏编辑">
297
+ <Button
298
+ type="primary"
299
+ icon={<FullscreenOutlined />}
300
+ onClick={handleFullScreen}
301
+ style={{
302
+ border: 'none',
303
+ display: isFull ? 'none' : '',
304
+ }}
305
+ shape="circle"
306
+ size="small"
307
+ />
308
+ </Tooltip> */}
309
+ </div>
310
+ </Space>
311
+ </div>
312
+ <Row>
313
+ <Col span={hasConfigTree ? 16 : 24}>
314
+ <Editor
315
+ height={`calc(100vh - ${shallowHeight + 100}px)`}
316
+ language="javascript"
317
+ editorDidMount={onEditorDidMount}
318
+ options={{
319
+ selectOnLineNumbers: true,
320
+ renderSideBySide: false,
321
+ }}
322
+ value={finalValue}
323
+ // value={{columns: finalValue.columns, fields: finalValue.fields}}
324
+ />
325
+ </Col>
326
+ {hasConfigTree && (
327
+ <Col span={8}>
328
+ <div className={style.title}>属性节点树</div>
329
+ <ConfigTree
330
+ style={{
331
+ height: 'calc(100vh - 300px)',
332
+ overflowY: 'scroll',
333
+ }}
334
+ level={1}
335
+ data={treeData}
336
+ onSelect={handleSelect}
337
+ currentLine={highLightLine}
338
+ iconRender={iconRender}
339
+ nameRender={nameRender}
340
+ />
341
+ </Col>
342
+ )}
343
+ </Row>
344
+ </div>
345
+ );
346
+ };