@cniot/mdd-editor 0.2.0-beta.9 → 0.3.0

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 (75) hide show
  1. package/README.MD +308 -11
  2. package/build/index.cjs.js +27 -19
  3. package/build/index.es.js +3539 -342
  4. package/build/style.css +1 -1
  5. package/package.json +1 -1
  6. package/src/ai/LocalAIDrawer.jsx +211 -0
  7. package/src/ai/bridgeClient.js +76 -0
  8. package/src/ai/pageIR.js +148 -0
  9. package/src/components/address-select/formily.jsx +1 -1
  10. package/src/components/ajax-schema-form/formily-table-form-proxy.jsx +1 -1
  11. package/src/components/ajax-schema-form/formily.jsx +1 -1
  12. package/src/components/ajax-schema-form/table-form-proxy.jsx +1 -1
  13. package/src/components/ajax-schema-form/table-form.jsx +1 -1
  14. package/src/components/data-source-select/formily.jsx +1 -1
  15. package/src/components/dynamic-value/base/formily.jsx +1 -1
  16. package/src/components/dynamic-value/date/formily.jsx +1 -1
  17. package/src/components/formily-select/index.tsx +1 -1
  18. package/src/components/params-select/formily.jsx +1 -1
  19. package/src/components/time-range/formily.jsx +1 -1
  20. package/src/hooks/useSchema.jsx +5 -5
  21. package/src/hooks/useSwagger.jsx +2 -2
  22. package/src/schema/base-schema/AjaxSchema.js +1 -1
  23. package/src/schema/base-schema/AjaxSchemaQueue.js +1 -1
  24. package/src/schema/blocks/edit-table.js +57 -0
  25. package/src/schema/blocks/filter.js +49 -0
  26. package/src/schema/blocks/form.js +49 -0
  27. package/src/schema/blocks/index.js +32 -10
  28. package/src/schema/blocks/table.js +3 -4
  29. package/src/schema/detail/detail-item.js +5 -5
  30. package/src/schema/detail/index.js +26 -18
  31. package/src/schema/edit-table/header-toolbar.js +1 -1
  32. package/src/schema/edit-table/index.js +10 -5
  33. package/src/schema/edit-table/table.js +10 -2
  34. package/src/schema/formily-form/data-source.js +1 -1
  35. package/src/schema/formily-form/form-schema.js +1 -1
  36. package/src/schema/formily-form/index.js +8 -8
  37. package/src/schema/formily-form-v2/form-info.js +2 -2
  38. package/src/schema/formily-form-v2/form-items.js +1 -1
  39. package/src/schema/formily-form-v2/index.js +3 -3
  40. package/src/schema/ftp/data-source.js +1 -1
  41. package/src/schema/ftp/filter.js +2 -2
  42. package/src/schema/ftp/header-toolbar.js +1 -1
  43. package/src/schema/ftp/index.js +4 -4
  44. package/src/schema/ftp/middle-item.js +1 -1
  45. package/src/schema/ftp/table.js +9 -3
  46. package/src/schema/util.js +3 -3
  47. package/src/services/index.js +1 -1
  48. package/src/template/blocks/EditTable.jsx +62 -0
  49. package/src/template/blocks/Filter.jsx +137 -0
  50. package/src/template/blocks/Form.jsx +136 -0
  51. package/src/template/blocks/Table.jsx +4 -4
  52. package/src/template/const.js +18 -4
  53. package/src/template/detail/DetailItems.jsx +6 -1
  54. package/src/template/detail/components/Actions.jsx +1 -1
  55. package/src/template/detail/components/DetailCard.jsx +8 -5
  56. package/src/template/detail/components/DetailColumns.jsx +193 -113
  57. package/src/template/detail/components/DetailCustom.jsx +2 -2
  58. package/src/template/detail/components/DetailTable.jsx +13 -8
  59. package/src/template/detail/components/MultiAjaxSchemaForm.jsx +1 -1
  60. package/src/template/edit-table/HeaderToolbar.jsx +3 -2
  61. package/src/template/edit-table/Table.jsx +56 -3
  62. package/src/template/formily-form-v2/FormInfo.jsx +1 -1
  63. package/src/template/formily-form-v2/FormItems.jsx +4 -8
  64. package/src/template/formilyform/components/AsyncDataSourceSetter/index.tsx +1 -1
  65. package/src/template/formilyform/components/SubmitActionSetter/index.tsx +1 -1
  66. package/src/template/ftp/DataSource.jsx +1 -1
  67. package/src/template/ftp/Filter.jsx +14 -7
  68. package/src/template/ftp/HeaderToolbar.jsx +8 -4
  69. package/src/template/ftp/Middle.jsx +11 -7
  70. package/src/template/ftp/Table.jsx +143 -12
  71. package/src/template/simple-ftp/Table.jsx +2 -2
  72. package/src/toolbar.jsx +76 -14
  73. package/src/utils/buildFieldsToCompJson.js +3 -3
  74. package/src/utils/persistentStorage.js +1 -1
  75. package/src/utils/swagger/api2SchemaFromSwagger.js +7 -7
@@ -1,14 +1,18 @@
1
1
  import React from 'react';
2
- import MddTableForm from '@src/components/mdd-table-form';
2
+ import MddTableForm from '$src/components/mdd-table-form';
3
3
 
4
4
  export default function HeaderToolbarPanel({ schema, moduleMap }) {
5
5
  const mddFormRef = React.useRef();
6
6
  const [_, forceUpdate] = React.useState({});
7
7
  React.useEffect(() => {
8
- schema.on('$updated', (changeData, ignoreUpdate) => {
8
+ const handleUpdated = (changeData, ignoreUpdate) => {
9
9
  !ignoreUpdate && forceUpdate({});
10
- });
11
- }, []);
10
+ };
11
+ schema.on('$updated', handleUpdated);
12
+ return () => {
13
+ schema.off('$updated', handleUpdated);
14
+ };
15
+ }, [schema]);
12
16
 
13
17
  const operationFields = schema.getData();
14
18
 
@@ -2,11 +2,11 @@
2
2
  * 中间模块区
3
3
  */
4
4
  import React from 'react';
5
- import MddTableSimpleArray from '@src/components/mdd-table-simple-array';
6
- import TableFromProxy from '@src/components/ajax-schema-form/table-form-proxy';
5
+ import MddTableSimpleArray from '$src/components/mdd-table-simple-array';
6
+ import TableFromProxy from '$src/components/ajax-schema-form/table-form-proxy';
7
7
  import { Select, Input, Icon } from '@cainiaofe/cn-ui';
8
- import AjaxSchemaForm from '@src/components/ajax-schema-form';
9
- import DynamicValueBase from '@src/components/dynamic-value/base';
8
+ import AjaxSchemaForm from '$src/components/ajax-schema-form';
9
+ import DynamicValueBase from '$src/components/dynamic-value/base';
10
10
 
11
11
  import styles from './index.module.scss';
12
12
 
@@ -23,10 +23,14 @@ export default function Middle(props) {
23
23
  const [_, forceUpdate] = React.useState({});
24
24
 
25
25
  React.useEffect(() => {
26
- schema.on('$updated', (changeData, ignoreUpdate) => {
26
+ const handleUpdated = (changeData, ignoreUpdate) => {
27
27
  !ignoreUpdate && forceUpdate({});
28
- });
29
- }, []);
28
+ };
29
+ schema.on('$updated', handleUpdated);
30
+ return () => {
31
+ schema.off('$updated', handleUpdated);
32
+ };
33
+ }, [schema]);
30
34
 
31
35
  const onAddHandle = () => {
32
36
  schema.addMiddle();
@@ -1,25 +1,30 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { Input, Switch, Icon, NumberPicker } from '@cainiaofe/cn-ui';
3
- import MddTableForm from '@src/components/mdd-table-form';
4
- import MddForm from '@src/components/mdd-form';
5
- import AjaxSchemaForm from '@src/components/ajax-schema-form';
2
+ import { Input, Switch, Icon, NumberPicker, CnSwitch, CnTooltip } from '@cainiaofe/cn-ui';
3
+ import MddTableForm from '$src/components/mdd-table-form';
4
+ import MddForm from '$src/components/mdd-form';
5
+ import AjaxSchemaForm from '$src/components/ajax-schema-form';
6
6
  import { columnsTypeOptionsWithCnTable } from '../const';
7
7
 
8
8
  export default function TablePanel({ schema, swaggerFields = [] }) {
9
9
  const columnMddFormRef = React.useRef();
10
10
  const bulkMddFormRef = React.useRef();
11
11
  const operateMddFormRef = React.useRef();
12
+ const rowDoubleClickRef = React.useRef();
12
13
 
13
14
  const [_, forceUpdate] = useState({});
14
15
  const [visibleRowDetail, setVisibleRowDetail] = useState(!!schema.get('rowDetailModule')?.path);
15
16
  useEffect(() => {
16
- schema.on('$updated', (changeData, ignoreUpdate) => {
17
+ const handleUpdated = (changeData, ignoreUpdate) => {
17
18
  !ignoreUpdate && forceUpdate({});
18
- });
19
+ };
20
+ schema.on('$updated', handleUpdated);
19
21
 
20
22
  // hack处理
21
23
  hackRowDetail(schema);
22
- }, []);
24
+ return () => {
25
+ schema.off('$updated', handleUpdated);
26
+ };
27
+ }, [schema]);
23
28
  // 主键
24
29
  const primaryKey = schema.get('primaryKey');
25
30
  // 批量操作
@@ -27,13 +32,17 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
27
32
  const columns = schema.get('columns');
28
33
  // 操作列
29
34
  const actionColumns = schema.get('actionColumns');
35
+ // 行双击配置
36
+ const rowDoubleClick = schema.get('rowDoubleClick');
30
37
  const pagination = schema.get('pagination');
31
38
  // 树形
32
39
  const tree = schema.get('tree');
33
40
  // 显示序号
34
41
  const showIndex = schema.get('showIndex');
35
- // 影藏底部操作区
42
+ // 隐藏底部操作区
36
43
  const hideCommonToolbar = schema.get('hideCommonToolbar');
44
+ // 操作列按钮最长字符数
45
+ const actionMaxCharNum = schema.get('actionMaxCharNum');
37
46
  // 操作列宽度
38
47
  const actionWidth = schema.get('actionWidth');
39
48
  // 是否显示多选
@@ -42,6 +51,8 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
42
51
  const rowDetailModule = schema.get('rowDetailModule');
43
52
  // 远程排序
44
53
  const remoteSort = schema.get('remoteSort');
54
+ // 父子节点级联勾选
55
+ const treeLinkageCheck = schema.get('treeLinkageCheck');
45
56
 
46
57
  // 加载子节点数据源面板
47
58
  const loadChildrenDataApiPanel = schema.getLoadChildrenDataApiPanel();
@@ -98,6 +109,23 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
98
109
  );
99
110
  operateMddFormRef.current?.updateData(schema.get('actionColumns'));
100
111
  break;
112
+ case 'rowDoubleClick':
113
+ // 操作列,默认带上当前行对象
114
+ schema.add(
115
+ {
116
+ type: 'button',
117
+ action: {
118
+ type: 'url',
119
+ params: {
120
+ record: '$TABLE.RECORD_DATA',
121
+ },
122
+ },
123
+ },
124
+ 'rowDoubleClick',
125
+ true,
126
+ );
127
+ rowDoubleClickRef.current?.updateData(schema.get('rowDoubleClick'));
128
+ break;
101
129
  default:
102
130
  break;
103
131
  }
@@ -111,6 +139,8 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
111
139
  columnMddFormRef.current?.updateData(schema.get('columns'));
112
140
  } else if (key === 'actionColumns') {
113
141
  operateMddFormRef.current?.updateData(schema.get('actionColumns'));
142
+ } else if (key === 'rowDoubleClick') {
143
+ rowDoubleClickRef.current?.updateData(schema.get('rowDoubleClick'));
114
144
  }
115
145
  };
116
146
 
@@ -118,6 +148,10 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
118
148
  schema.update(index, record, key, true);
119
149
  };
120
150
 
151
+ const onActionMaxCharNum = (value) => {
152
+ schema.update('', value ? Number(value) : '', 'actionMaxCharNum');
153
+ };
154
+
121
155
  const onActionWidthChange = (value) => {
122
156
  schema.update('', value ? Number(value) : '', 'actionWidth');
123
157
  };
@@ -132,6 +166,7 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
132
166
  if (!value) {
133
167
  // 关闭直接初始化rowDetailModule字段
134
168
  onChangeHandle({}, 'rowDetailModule');
169
+ onBaseInfoChange('rowDetailDefaultOpenAll', false);
135
170
  }
136
171
  };
137
172
 
@@ -178,6 +213,39 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
178
213
  schema.setItemAll(newList, 'actionColumns', true);
179
214
  }}
180
215
  />
216
+ <MddTableForm
217
+ ref={rowDoubleClickRef}
218
+ data={rowDoubleClick}
219
+ title={() => (
220
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
221
+ 配置行双击事件
222
+ <CnSwitch
223
+ size="small"
224
+ checked={schema.get('rowDoubleClick')?.length > 0}
225
+ onChange={(checked) => {
226
+ if (checked) onAddHandle('rowDoubleClick');
227
+ else onRemoveHandle(0, 'rowDoubleClick');
228
+ }}
229
+ />
230
+ <CnTooltip trigger={<Icon type="prompt" />}>
231
+ 行双击事件 和 操作列按钮 配置保持一致,下面 关于按钮的配置 均会失效,请只关注 双击 要执行的事件本身
232
+ </CnTooltip>
233
+ </div>
234
+ )}
235
+ titleType={[]}
236
+ draggable={false}
237
+ titleRender={() => '行双击 事件配置'}
238
+ onRemove={() => {}}
239
+ onChange={({ index, record }) => onChangeHandle({ index, record }, 'rowDoubleClick')}
240
+ />
241
+ <div style={{ marginLeft: '10px', marginBottom: 8 }}>
242
+ <label>操作列按钮最长字符数:</label>
243
+ <NumberPicker value={actionMaxCharNum} size="small" onChange={onActionMaxCharNum} min={1} max={10} />
244
+ <span className="mdd-tip">
245
+ <Icon type="prompt" /> 超长部分会显示为“...”[注意:需全局开启配置后 此项生效;在低版本 CN-UI 上不生效,如
246
+ 实施工作台;可能会对一码多端效果造成影响,慎用]
247
+ </span>
248
+ </div>
181
249
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
182
250
  <label>操作列宽度:</label>
183
251
  <Input value={actionWidth} size="small" onChange={onActionWidthChange} />
@@ -187,7 +255,12 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
187
255
  </div>
188
256
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
189
257
  <label>最大高度:</label>
190
- <Input value={schema.get('maxHeight')} size="small" onChange={(v) => onBaseInfoChange('maxHeight', v)} />
258
+ <NumberPicker
259
+ value={schema.get('maxHeight')}
260
+ size="small"
261
+ onChange={(v) => onBaseInfoChange('maxHeight', v)}
262
+ min={0}
263
+ />
191
264
  <span className="mdd-tip">
192
265
  <Icon type="prompt" /> 该属性可以实现一屏展示,支持calc函数,eg: calc(100vh - 100px)
193
266
  </span>
@@ -217,6 +290,17 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
217
290
  onChange={({ index, record }) => onChangeHandle({ index, record }, 'rowDetailModule')}
218
291
  />
219
292
  )}
293
+ {visibleRowDetail && (
294
+ <div style={{ marginLeft: '10px', marginBottom: 8 }}>
295
+ <label>行详情是否默认展开全部:</label>
296
+ <Switch
297
+ autoWidth
298
+ checked={schema.get('rowDetailDefaultOpenAll')}
299
+ size="small"
300
+ onChange={(v) => onBaseInfoChange('rowDetailDefaultOpenAll', v)}
301
+ />
302
+ </div>
303
+ )}
220
304
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
221
305
  <label>树形:</label>
222
306
  <Switch autoWidth checked={tree} size="small" onChange={(v) => onBaseInfoChange('tree', v)} />
@@ -225,8 +309,25 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
225
309
  开启后也可通过下面的懒加载设置改成懒加载模式,不配置则需要一次性返回树形数据
226
310
  </span>
227
311
  </div>
312
+
228
313
  {tree && (
229
- <div style={{ marginLeft: '10px', marginBottom: 8, display: 'flex' }}>
314
+ <div style={{ marginLeft: '20px', marginBottom: 8, display: 'flex' }}>
315
+ <label>父子节点级联勾选:</label>
316
+ <Switch
317
+ autoWidth
318
+ checked={treeLinkageCheck}
319
+ size="small"
320
+ onChange={(v) => onBaseInfoChange('treeLinkageCheck', v)}
321
+ />
322
+
323
+ <span className="mdd-tip">
324
+ <Icon type="prompt" />{' '}
325
+ 父节点勾选默认会勾选所有子节点,子节点勾选默认会勾上父节点【必须配置唯一主键,不支持异步数据】
326
+ </span>
327
+ </div>
328
+ )}
329
+ {tree && (
330
+ <div style={{ marginLeft: '20px', marginBottom: 8, display: 'flex' }}>
230
331
  <label>子节点懒加载配置:</label>
231
332
  <div>
232
333
  <AjaxSchemaForm schema={loadChildrenDataApiPanel} isSelectType={false} />
@@ -236,6 +337,7 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
236
337
  </div>
237
338
  </div>
238
339
  )}
340
+
239
341
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
240
342
  <label>是否显示序号:</label>
241
343
  <Switch autoWidth checked={showIndex} size="small" onChange={(v) => onBaseInfoChange('showIndex', v)} />
@@ -244,7 +346,7 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
244
346
  </span>
245
347
  </div>
246
348
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
247
- <label>是否影藏通用顶部操作区:</label>
349
+ <label>是否隐藏通用顶部操作区:</label>
248
350
  <Switch
249
351
  autoWidth
250
352
  checked={hideCommonToolbar}
@@ -252,7 +354,7 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
252
354
  onChange={(v) => onBaseInfoChange('hideCommonToolbar', v)}
253
355
  />
254
356
  <span className="mdd-tip">
255
- <Icon type="prompt" /> 是否影藏table顶部操作区的通用操作按钮,比如全屏、斑马线、列设置、尺寸等
357
+ <Icon type="prompt" /> 是否隐藏table顶部操作区的通用操作按钮,比如全屏、斑马线、列设置、尺寸等
256
358
  </span>
257
359
  </div>
258
360
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
@@ -283,6 +385,35 @@ export default function TablePanel({ schema, swaggerFields = [] }) {
283
385
  <Icon type="prompt" /> 纯前端筛选
284
386
  </span>
285
387
  </div>
388
+
389
+ <div style={{ marginLeft: '10px', marginBottom: 8 }}>
390
+ <label>是否开启多维指标排序:</label>
391
+ <Switch
392
+ autoWidth
393
+ checked={schema.get('customSort')}
394
+ size="small"
395
+ onChange={(v) => {
396
+ onBaseInfoChange('customSort', v);
397
+ !v && onBaseInfoChange('customSortStorage', '');
398
+ }}
399
+ />
400
+ <span className="mdd-tip">
401
+ <Icon type="prompt" /> 纯前端排序
402
+ </span>
403
+
404
+ {schema.get('customSort') && (
405
+ <Input
406
+ style={{ marginLeft: 8 }}
407
+ value={schema.get('customSortStorage')}
408
+ size="small"
409
+ placeholder="跟随页面缓存"
410
+ onChange={(v) => {
411
+ onBaseInfoChange('customSortStorage', v);
412
+ }}
413
+ />
414
+ )}
415
+ </div>
416
+
286
417
  <div style={{ marginLeft: '10px', marginBottom: 8 }}>
287
418
  <label>是否开启列头复制:</label>
288
419
  <Switch autoWidth checked={schema.get('copy')} size="small" onChange={(v) => onBaseInfoChange('copy', v)} />
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { Input, Switch, Icon, NumberPicker } from '@cainiaofe/cn-ui';
3
- import MddTableForm from '@src/components/mdd-table-form';
4
- import MddForm from '@src/components/mdd-form';
3
+ import MddTableForm from '$src/components/mdd-table-form';
4
+ import MddForm from '$src/components/mdd-form';
5
5
  import { columnsTypeOptionsWithCnTable } from '../const';
6
6
 
7
7
  export default function TablePanel({ schema }) {
package/src/toolbar.jsx CHANGED
@@ -1,13 +1,17 @@
1
1
  import React from 'react';
2
2
  import { Dialog, CnIcon, CnButton, CnTooltip, CnDrawer, CnTab, CnTabItem, CnCard } from '@cainiaofe/cn-ui';
3
3
  import MDDRenderEngine, { JSONWatch } from '@cniot/mdd-render-engine';
4
- import Monaco from '@src/components/ajax-schema-form/monaco';
4
+ import Monaco from '$src/components/ajax-schema-form/monaco';
5
+ import LocalAIDrawer from '$src/ai/LocalAIDrawer';
5
6
 
6
- import { EVENT_KEY } from '@src/common/const';
7
+ import { EVENT_KEY } from '$src/common/const';
7
8
 
8
9
  import './index.less';
9
10
 
10
- const isDebug = window?.location?.search?.indexOf('debug') >= 0;
11
+ // window.localStorage.__l4_location_search_debug__ = true; // 调试使用
12
+ // window.localStorage.__l4_ftp_filter_expand__ = true; // 调试使用
13
+ const isDebug =
14
+ window?.location?.search?.indexOf('debug') >= 0 || window.localStorage?.__l4_location_search_debug__ === 'true';
11
15
 
12
16
  /**
13
17
  * 顶部操作区
@@ -21,18 +25,36 @@ const isDebug = window?.location?.search?.indexOf('debug') >= 0;
21
25
  * }
22
26
  */
23
27
  export default function Toolbar(props) {
24
- const { schema, scriptInfo = { script: '', style: '' }, showScript, scriptTopButtons } = props;
28
+ const {
29
+ schema,
30
+ scriptInfo = { script: '', style: '' },
31
+ showScript,
32
+ scriptTopButtons,
33
+ aiBridge = true,
34
+ pageMeta,
35
+ onSchemaApplied,
36
+ } = props;
25
37
  const [fullscreen, setFullscreen] = React.useState(false);
26
38
  const [codeVisible, setCodeVisible] = React.useState(false);
27
39
  const [schemaVisible, setSchemaVisible] = React.useState(false);
40
+ const [aiVisible, setAiVisible] = React.useState(false);
41
+ const [scriptEditorInfo, setScriptEditorInfo] = React.useState(scriptInfo);
42
+ const [schemaEditorCode, setSchemaEditorCode] = React.useState(
43
+ JSON.stringify(schema?.getAllJSON() || {}, null, 2),
44
+ );
28
45
 
29
- const scriptRef = React.useRef(scriptInfo);
30
- const schemaRef = React.useRef(JSON.stringify(schema?.getAllJSON() || {}, null, 2));
46
+ const scriptRef = React.useRef(scriptEditorInfo);
47
+ const schemaRef = React.useRef(schemaEditorCode);
31
48
 
32
49
  const editorHeight = 'calc(100vh - 146px)';
33
50
 
34
51
  const scriptChange = (scriptChangeCode) => {
35
- scriptRef.current.script = scriptChangeCode; // 缓存脚本
52
+ const nextScriptInfo = {
53
+ script: scriptChangeCode,
54
+ style: scriptRef.current.style,
55
+ };
56
+ scriptRef.current = nextScriptInfo; // 缓存脚本
57
+ setScriptEditorInfo(nextScriptInfo);
36
58
  schema.emit(EVENT_KEY.SCRIPT_UPDATE, {
37
59
  script: scriptChangeCode,
38
60
  style: scriptRef.current.style,
@@ -40,11 +62,13 @@ export default function Toolbar(props) {
40
62
  };
41
63
 
42
64
  const styleChange = (styleChangeCode) => {
43
- scriptRef.current.style = styleChangeCode; // 缓存样式
44
- schema.emit(EVENT_KEY.SCRIPT_UPDATE, {
65
+ const nextScriptInfo = {
45
66
  script: scriptRef.current.script,
46
67
  style: styleChangeCode,
47
- });
68
+ };
69
+ scriptRef.current = nextScriptInfo; // 缓存样式
70
+ setScriptEditorInfo(nextScriptInfo);
71
+ schema.emit(EVENT_KEY.SCRIPT_UPDATE, nextScriptInfo);
48
72
  };
49
73
 
50
74
  // schema change
@@ -52,6 +76,15 @@ export default function Toolbar(props) {
52
76
  schema.emit(EVENT_KEY.SCHEMA_UPDATE_FORCE, newSchemaCode);
53
77
  };
54
78
 
79
+ const onLocalAIApply = ({ schemaJson, scriptInfo: nextScriptInfo }) => {
80
+ scriptRef.current = nextScriptInfo;
81
+ setScriptEditorInfo(nextScriptInfo);
82
+ const nextSchemaCode = JSON.stringify(schemaJson || schema?.getAllJSON() || {}, null, 2);
83
+ schemaRef.current = nextSchemaCode;
84
+ setSchemaEditorCode(nextSchemaCode);
85
+ onSchemaApplied?.();
86
+ };
87
+
55
88
  return (
56
89
  <div>
57
90
  <div className="mdd-editor-toolbar">
@@ -77,7 +110,6 @@ export default function Toolbar(props) {
77
110
  脚本
78
111
  </CnTooltip>
79
112
  )}
80
-
81
113
  <CnTooltip
82
114
  trigger={
83
115
  <CnButton text onClick={() => setFullscreen(true)}>
@@ -87,6 +119,17 @@ export default function Toolbar(props) {
87
119
  >
88
120
  预览
89
121
  </CnTooltip>
122
+ {aiBridge !== false && (
123
+ <CnTooltip
124
+ trigger={
125
+ <CnButton type="primary" size="small" className="mdd-editor-ai-button" onClick={() => setAiVisible(true)}>
126
+ 本地 AI
127
+ </CnButton>
128
+ }
129
+ >
130
+ 本地 AI
131
+ </CnTooltip>
132
+ )}
90
133
  </div>
91
134
  <Dialog v2 title="预览" width="90vw" visible={fullscreen} onClose={() => setFullscreen(false)} footer={false}>
92
135
  <MDDRenderEngine
@@ -99,6 +142,24 @@ export default function Toolbar(props) {
99
142
  }
100
143
  />
101
144
  </Dialog>
145
+ {aiVisible && (
146
+ <CnDrawer
147
+ title="本地 AI 工作区"
148
+ width="720px"
149
+ footer={false}
150
+ visible={aiVisible}
151
+ onClose={() => setAiVisible(false)}
152
+ >
153
+ <LocalAIDrawer
154
+ schema={schema}
155
+ scriptInfo={scriptEditorInfo}
156
+ pageMeta={pageMeta}
157
+ bridgeConfig={aiBridge}
158
+ onApply={onLocalAIApply}
159
+ />
160
+ </CnDrawer>
161
+ )}
162
+
102
163
  {/* 代码编辑 */}
103
164
  <CnDrawer
104
165
  title="脚本编辑"
@@ -121,7 +182,7 @@ export default function Toolbar(props) {
121
182
  <Monaco
122
183
  defaultLanguage="javascript"
123
184
  height={editorHeight}
124
- defaultValue={scriptInfo.script}
185
+ value={scriptEditorInfo.script}
125
186
  onChange={scriptChange}
126
187
  />
127
188
  </CnTabItem>
@@ -129,7 +190,7 @@ export default function Toolbar(props) {
129
190
  <Monaco
130
191
  defaultLanguage="less"
131
192
  height={editorHeight}
132
- defaultValue={scriptInfo.style}
193
+ value={scriptEditorInfo.style}
133
194
  onChange={styleChange}
134
195
  />
135
196
  </CnTabItem>
@@ -164,9 +225,10 @@ export default function Toolbar(props) {
164
225
  <Monaco
165
226
  defaultLanguage="json"
166
227
  height={editorHeight}
167
- defaultValue={schemaRef.current}
228
+ value={schemaEditorCode}
168
229
  onChange={(v) => {
169
230
  schemaRef.current = v;
231
+ setSchemaEditorCode(v);
170
232
  }}
171
233
  />
172
234
  </CnCard>
@@ -1,6 +1,6 @@
1
- import { SWAGGER_DT } from '@src/common/const';
2
- import { calcWordWidth } from '@src/utils';
3
- import { propFields } from '@src/common/comp-schema/fields/propFields';
1
+ import { SWAGGER_DT } from '$src/common/const';
2
+ import { calcWordWidth } from '$src/utils';
3
+ import { propFields } from '$src/common/comp-schema/fields/propFields';
4
4
 
5
5
  // 不生成字段 黑名单
6
6
  const REMOVE_FIELDS_NAME = ['page', 'pageSize', 'pageNo', 'currentPage', 'userContext'];
@@ -1,5 +1,5 @@
1
1
  // 用于LS储存
2
- import { PERSISTENT_STORE_LS_KEY } from '@src/common/const';
2
+ import { PERSISTENT_STORE_LS_KEY } from '$src/common/const';
3
3
 
4
4
  class PersistentStorage {
5
5
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import merge from 'lodash/merge';
2
- import buildSwaggerApiJson from '@src/utils/buildSwaggerApiJson';
3
- import buildFieldsToCompJson from '@src/utils/buildFieldsToCompJson';
4
- import jsonSchemaRefParser from '@src/utils/jsonSchemaRefParser';
5
- import { getDefaultFomrLabelAlign } from '@src/utils';
2
+ import buildSwaggerApiJson from '$src/utils/buildSwaggerApiJson';
3
+ import buildFieldsToCompJson from '$src/utils/buildFieldsToCompJson';
4
+ import jsonSchemaRefParser from '$src/utils/jsonSchemaRefParser';
5
+ import { getDefaultFomrLabelAlign } from '$src/utils';
6
6
 
7
7
  /** 将swaggerjson 转换成前端能用的swagger对象 */
8
8
  export function getSwaggerInfoFromJson(swaggerJson) {
@@ -186,14 +186,14 @@ export function api2SchemaFromSwaggerApiInfo(api, schemaType, apiInfo, extraSche
186
186
  },
187
187
  tree: false,
188
188
  showIndex: false,
189
- hideCommonToolbar: false,
189
+ hideCommonToolbar: true,
190
190
  },
191
191
  headerToolbar: [],
192
192
  };
193
- } else if (schemaType === 'blocks-table') {
193
+ } else if (schemaType?.startsWith('blocks-')) {
194
194
  result.type = 'blocks';
195
195
  result.body = {
196
- type: 'blocks-table',
196
+ type: schemaType,
197
197
  blocks: [],
198
198
  };
199
199
  }