@tmagic/editor 1.4.6 → 1.4.8

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 (158) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +636 -589
  3. package/dist/tmagic-editor.umd.cjs +634 -586
  4. package/package.json +15 -11
  5. package/types/editorProps.d.ts +0 -7
  6. package/types/layouts/PropsPanel.vue.d.ts +9 -9
  7. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  8. package/types/services/codeBlock.d.ts +2 -1
  9. package/types/services/dataSource.d.ts +2 -1
  10. package/types/services/dep.d.ts +12 -2
  11. package/types/services/editor.d.ts +22 -4
  12. package/types/services/props.d.ts +7 -6
  13. package/types/type.d.ts +6 -0
  14. package/types/utils/editor.d.ts +1 -0
  15. package/types/utils/idle-task.d.ts +14 -0
  16. package/types/utils/operator.d.ts +2 -2
  17. package/src/Editor.vue +0 -211
  18. package/src/components/CodeBlockEditor.vue +0 -268
  19. package/src/components/CodeParams.vue +0 -60
  20. package/src/components/ContentMenu.vue +0 -193
  21. package/src/components/FloatingBox.vue +0 -178
  22. package/src/components/Icon.vue +0 -27
  23. package/src/components/Resizer.vue +0 -23
  24. package/src/components/ScrollBar.vue +0 -151
  25. package/src/components/ScrollViewer.vue +0 -128
  26. package/src/components/SearchInput.vue +0 -37
  27. package/src/components/SplitView.vue +0 -186
  28. package/src/components/ToolButton.vue +0 -138
  29. package/src/components/Tree.vue +0 -71
  30. package/src/components/TreeNode.vue +0 -148
  31. package/src/editorProps.ts +0 -124
  32. package/src/fields/Code.vue +0 -50
  33. package/src/fields/CodeLink.vue +0 -80
  34. package/src/fields/CodeSelect.vue +0 -132
  35. package/src/fields/CodeSelectCol.vue +0 -139
  36. package/src/fields/DataSourceFieldSelect.vue +0 -149
  37. package/src/fields/DataSourceFields.vue +0 -323
  38. package/src/fields/DataSourceInput.vue +0 -325
  39. package/src/fields/DataSourceMethodSelect.vue +0 -153
  40. package/src/fields/DataSourceMethods.vue +0 -104
  41. package/src/fields/DataSourceMocks.vue +0 -255
  42. package/src/fields/DataSourceSelect.vue +0 -98
  43. package/src/fields/EventSelect.vue +0 -301
  44. package/src/fields/KeyValue.vue +0 -137
  45. package/src/fields/PageFragmentSelect.vue +0 -63
  46. package/src/fields/UISelect.vue +0 -135
  47. package/src/hooks/index.ts +0 -24
  48. package/src/hooks/use-code-block-edit.ts +0 -83
  49. package/src/hooks/use-data-source-edit.ts +0 -46
  50. package/src/hooks/use-data-source-method.ts +0 -100
  51. package/src/hooks/use-editor-content-height.ts +0 -26
  52. package/src/hooks/use-filter.ts +0 -55
  53. package/src/hooks/use-float-box.ts +0 -76
  54. package/src/hooks/use-getso.ts +0 -35
  55. package/src/hooks/use-next-float-box-position.ts +0 -29
  56. package/src/hooks/use-node-status.ts +0 -48
  57. package/src/hooks/use-stage.ts +0 -129
  58. package/src/hooks/use-window-rect.ts +0 -20
  59. package/src/icons/AppManageIcon.vue +0 -15
  60. package/src/icons/CenterIcon.vue +0 -13
  61. package/src/icons/CodeIcon.vue +0 -28
  62. package/src/icons/FolderMinusIcon.vue +0 -22
  63. package/src/icons/PinIcon.vue +0 -25
  64. package/src/icons/PinnedIcon.vue +0 -25
  65. package/src/index.ts +0 -118
  66. package/src/initService.ts +0 -447
  67. package/src/layouts/AddPageBox.vue +0 -55
  68. package/src/layouts/CodeEditor.vue +0 -226
  69. package/src/layouts/Framework.vue +0 -163
  70. package/src/layouts/NavMenu.vue +0 -200
  71. package/src/layouts/PropsPanel.vue +0 -130
  72. package/src/layouts/page-bar/AddButton.vue +0 -48
  73. package/src/layouts/page-bar/PageBar.vue +0 -159
  74. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  75. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  76. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  77. package/src/layouts/sidebar/Sidebar.vue +0 -278
  78. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
  79. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  80. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  81. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
  82. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  83. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  84. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  85. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  86. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  87. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  88. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  89. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  90. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  91. package/src/layouts/workspace/Workspace.vue +0 -46
  92. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  93. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  94. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  95. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  96. package/src/services/BaseService.ts +0 -230
  97. package/src/services/codeBlock.ts +0 -324
  98. package/src/services/componentList.ts +0 -58
  99. package/src/services/dataSource.ts +0 -209
  100. package/src/services/dep.ts +0 -80
  101. package/src/services/editor.ts +0 -1087
  102. package/src/services/events.ts +0 -93
  103. package/src/services/history.ts +0 -126
  104. package/src/services/keybinding.ts +0 -220
  105. package/src/services/props.ts +0 -265
  106. package/src/services/stageOverlay.ts +0 -212
  107. package/src/services/storage.ts +0 -155
  108. package/src/services/ui.ts +0 -156
  109. package/src/shims-vue.d.ts +0 -6
  110. package/src/theme/breadcrumb.scss +0 -6
  111. package/src/theme/code-block.scss +0 -6
  112. package/src/theme/code-editor.scss +0 -38
  113. package/src/theme/common/var.scss +0 -14
  114. package/src/theme/component-list-panel.scss +0 -95
  115. package/src/theme/content-menu.scss +0 -76
  116. package/src/theme/data-source-field.scss +0 -12
  117. package/src/theme/data-source-fields.scss +0 -13
  118. package/src/theme/data-source-input.scss +0 -18
  119. package/src/theme/data-source-methods.scss +0 -13
  120. package/src/theme/data-source.scss +0 -28
  121. package/src/theme/event.scss +0 -37
  122. package/src/theme/floating-box.scss +0 -32
  123. package/src/theme/framework.scss +0 -69
  124. package/src/theme/icon.scss +0 -12
  125. package/src/theme/index.scss +0 -10
  126. package/src/theme/key-value.scss +0 -20
  127. package/src/theme/layer-panel.scss +0 -26
  128. package/src/theme/layout.scss +0 -9
  129. package/src/theme/nav-menu.scss +0 -78
  130. package/src/theme/page-bar.scss +0 -89
  131. package/src/theme/page-fragment-select.scss +0 -14
  132. package/src/theme/props-panel.scss +0 -55
  133. package/src/theme/resizer.scss +0 -66
  134. package/src/theme/ruler.scss +0 -38
  135. package/src/theme/search-input.scss +0 -14
  136. package/src/theme/sidebar.scss +0 -79
  137. package/src/theme/stage.scss +0 -76
  138. package/src/theme/theme.scss +0 -27
  139. package/src/theme/tree.scss +0 -89
  140. package/src/theme/workspace.scss +0 -9
  141. package/src/type.ts +0 -746
  142. package/src/utils/compose.ts +0 -52
  143. package/src/utils/config.ts +0 -29
  144. package/src/utils/content-menu.ts +0 -95
  145. package/src/utils/data-source/formConfigs/base.ts +0 -30
  146. package/src/utils/data-source/formConfigs/http.ts +0 -60
  147. package/src/utils/data-source/index.ts +0 -236
  148. package/src/utils/editor.ts +0 -294
  149. package/src/utils/index.ts +0 -24
  150. package/src/utils/keybinding-config.ts +0 -125
  151. package/src/utils/logger.ts +0 -47
  152. package/src/utils/monaco-editor.ts +0 -8
  153. package/src/utils/operator.ts +0 -106
  154. package/src/utils/props.ts +0 -504
  155. package/src/utils/scroll-viewer.ts +0 -165
  156. package/src/utils/tree.ts +0 -15
  157. package/src/utils/undo-redo.ts +0 -76
  158. package/tsconfig.build.json +0 -16
@@ -1,255 +0,0 @@
1
- <template>
2
- <div class="m-editor-data-source-fields">
3
- <MagicTable :data="model[name]" :columns="columns"></MagicTable>
4
-
5
- <div class="m-editor-data-source-fields-footer">
6
- <TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
7
- </div>
8
-
9
- <FloatingBox
10
- v-model:visible="addDialogVisible"
11
- v-model:width="width"
12
- v-model:height="editorHeight"
13
- :title="drawerTitle"
14
- :position="boxPosition"
15
- >
16
- <template #body>
17
- <MFormBox
18
- ref="addDialog"
19
- label-width="120px"
20
- :config="formConfig"
21
- :values="formValues"
22
- :parentValues="model[name]"
23
- :disabled="disabled"
24
- @submit="formChangeHandler"
25
- ></MFormBox>
26
- </template>
27
- </FloatingBox>
28
- </div>
29
- </template>
30
-
31
- <script setup lang="ts">
32
- import { inject, Ref, ref } from 'vue';
33
-
34
- import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
35
- import { type FieldProps, type FormConfig, type FormState, MFormBox } from '@tmagic/form';
36
- import type { MockSchema } from '@tmagic/schema';
37
- import { type ColumnConfig, MagicTable } from '@tmagic/table';
38
- import { getDefaultValueFromFields } from '@tmagic/utils';
39
-
40
- import FloatingBox from '@editor/components/FloatingBox.vue';
41
- import { useNextFloatBoxPosition } from '@editor/hooks/use-next-float-box-position';
42
- import CodeEditor from '@editor/layouts/CodeEditor.vue';
43
- import { Services } from '@editor/type';
44
-
45
- import { useEditorContentHeight } from '..';
46
-
47
- defineOptions({
48
- name: 'MFieldsDataSourceMocks',
49
- });
50
-
51
- const props = withDefaults(
52
- defineProps<
53
- FieldProps<{
54
- type: 'data-source-mocks';
55
- }>
56
- >(),
57
- {
58
- disabled: false,
59
- },
60
- );
61
-
62
- const emit = defineEmits(['change']);
63
-
64
- const services = inject<Services>('services');
65
- const width = defineModel<number>('width', { default: 670 });
66
-
67
- const drawerTitle = ref('');
68
- const formValues = ref<Record<string, any>>({});
69
-
70
- const formConfig: FormConfig = [
71
- { name: 'index', type: 'hidden', filter: 'number', defaultValue: -1 },
72
- {
73
- name: 'title',
74
- text: '名称',
75
- rules: [
76
- {
77
- required: true,
78
- message: '请输入字段名称',
79
- },
80
- {
81
- required: true,
82
- message: '请输入名称',
83
- },
84
- ],
85
- },
86
- {
87
- name: 'description',
88
- text: '描述',
89
- },
90
- {
91
- name: 'enable',
92
- text: '启用',
93
- type: 'switch',
94
- },
95
- {
96
- name: 'useInEditor',
97
- text: '编辑器中使用',
98
- type: 'switch',
99
- },
100
- {
101
- name: 'data',
102
- text: 'mock数据',
103
- type: 'vs-code',
104
- language: 'json',
105
- options: inject('codeOptions', {}),
106
- defaultValue: '{}',
107
- height: '400px',
108
- onChange: (formState: FormState | undefined, v: string | any) => {
109
- if (typeof v !== 'string') return v;
110
- return JSON.parse(v);
111
- },
112
- rules: [
113
- {
114
- validator: ({ value, callback }) => {
115
- if (typeof value !== 'string') return callback();
116
-
117
- try {
118
- // 检测json是否存在语法错误
119
- JSON.parse(value);
120
-
121
- callback();
122
- } catch (error: any) {
123
- callback(error);
124
- }
125
- },
126
- },
127
- ],
128
- },
129
- ];
130
-
131
- const columns: ColumnConfig[] = [
132
- {
133
- type: 'expand',
134
- component: CodeEditor,
135
- props: (row: MockSchema) => ({
136
- initValues: row.data,
137
- language: 'json',
138
- height: '150px',
139
- options: {
140
- readOnly: true,
141
- },
142
- }),
143
- },
144
- {
145
- label: '名称',
146
- prop: 'title',
147
- },
148
- {
149
- label: '描述',
150
- prop: 'description',
151
- },
152
- {
153
- label: '是否启用',
154
- prop: 'enable',
155
- type: 'component',
156
- component: TMagicSwitch,
157
- props: (row: MockSchema) => ({
158
- modelValue: row.enable,
159
- activeValue: true,
160
- inactiveValue: false,
161
- }),
162
- listeners: (row: MockSchema, index: number) => ({
163
- 'update:modelValue': (v: boolean) => {
164
- toggleValue(row, 'enable', v, index);
165
- },
166
- }),
167
- },
168
- {
169
- label: '编辑器中使用',
170
- prop: 'useInEditor',
171
- type: 'component',
172
- component: TMagicSwitch,
173
- props: (row: MockSchema) => ({
174
- modelValue: row.useInEditor,
175
- activeValue: true,
176
- inactiveValue: false,
177
- }),
178
- listeners: (row: MockSchema, index: number) => ({
179
- 'update:modelValue': (v: boolean) => {
180
- toggleValue(row, 'useInEditor', v, index);
181
- },
182
- }),
183
- },
184
- {
185
- label: '操作',
186
- fixed: 'right',
187
- actions: [
188
- {
189
- text: '编辑',
190
- handler: (row: MockSchema, index: number) => {
191
- formValues.value = {
192
- ...row,
193
- index,
194
- };
195
- drawerTitle.value = `编辑${row.title}`;
196
- calcBoxPosition();
197
- addDialogVisible.value = true;
198
- },
199
- },
200
- {
201
- text: '删除',
202
- buttonType: 'danger',
203
- handler: async (row: MockSchema, index: number) => {
204
- await tMagicMessageBox.confirm(`确定删除${row.title}?`, '提示');
205
- props.model[props.name].splice(index, 1);
206
- emit('change', props.model[props.name]);
207
- },
208
- },
209
- ],
210
- },
211
- ];
212
-
213
- const newHandler = () => {
214
- const isFirstRow = props.model[props.name].length === 0;
215
- formValues.value = {
216
- data: getDefaultValueFromFields(props.model.fields || []),
217
- useInEditor: isFirstRow,
218
- enable: isFirstRow,
219
- };
220
- drawerTitle.value = '新增Mock';
221
- calcBoxPosition();
222
- addDialogVisible.value = true;
223
- };
224
-
225
- const formChangeHandler = ({ index, ...value }: Record<string, any>) => {
226
- if (index > -1) {
227
- props.model[props.name][index] = value;
228
- } else {
229
- props.model[props.name].push(value);
230
- }
231
-
232
- addDialogVisible.value = false;
233
-
234
- emit('change', props.model[props.name]);
235
- };
236
-
237
- const toggleValue = (row: MockSchema, key: 'enable' | 'useInEditor', value: boolean, index: number) => {
238
- if (value) {
239
- props.model[props.name].forEach((item: MockSchema) => {
240
- item[key] = false;
241
- });
242
- }
243
-
244
- formChangeHandler({
245
- ...row,
246
- [key]: value,
247
- index,
248
- });
249
- };
250
-
251
- const addDialogVisible = defineModel<boolean>('visible', { default: false });
252
- const { height: editorHeight } = useEditorContentHeight();
253
- const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
254
- const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
255
- </script>
@@ -1,98 +0,0 @@
1
- <template>
2
- <div class="m-fields-data-source-select">
3
- <MSelect
4
- :model="model"
5
- :name="name"
6
- :size="size"
7
- :prop="prop"
8
- :disabled="disabled"
9
- :config="selectConfig"
10
- :last-values="lastValues"
11
- @change="changeHandler"
12
- ></MSelect>
13
-
14
- <TMagicButton
15
- v-if="model[name] && hasDataSourceSidePanel"
16
- class="m-fields-select-action-button"
17
- :size="size"
18
- @click="editHandler"
19
- ><MIcon :icon="!notEditable ? Edit : View"></MIcon
20
- ></TMagicButton>
21
- </div>
22
- </template>
23
-
24
- <script setup lang="ts">
25
- import { computed, inject } from 'vue';
26
- import { Edit, View } from '@element-plus/icons-vue';
27
-
28
- import { TMagicButton } from '@tmagic/design';
29
- import { type FieldProps, filterFunction, type FormState, MSelect, type SelectConfig } from '@tmagic/form';
30
-
31
- import MIcon from '@editor/components/Icon.vue';
32
- import type { DataSourceSelect, EventBus, Services } from '@editor/type';
33
- import { SideItemKey } from '@editor/type';
34
-
35
- defineOptions({
36
- name: 'MFieldsDataSourceSelect',
37
- });
38
-
39
- const emit = defineEmits(['change']);
40
-
41
- const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
42
- disabled: false,
43
- });
44
-
45
- const mForm = inject<FormState | undefined>('mForm');
46
- const { dataSourceService, uiService } = inject<Services>('services') || {};
47
- const eventBus = inject<EventBus>('eventBus');
48
-
49
- const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
50
-
51
- const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
52
-
53
- const hasDataSourceSidePanel = computed(() =>
54
- (uiService?.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
55
- );
56
-
57
- const selectConfig = computed<SelectConfig>(() => {
58
- const { type, dataSourceType, value, ...config } = props.config;
59
-
60
- const valueIsId = props.config.value === 'id';
61
-
62
- return {
63
- ...config,
64
- type: 'select',
65
- valueKey: 'dataSourceId',
66
- options: dataSources.value
67
- .filter((ds) => !props.config.dataSourceType || ds.type === props.config.dataSourceType)
68
- .map((ds) => ({
69
- value: valueIsId
70
- ? ds.id
71
- : {
72
- isBindDataSource: true,
73
- dataSourceType: ds.type,
74
- dataSourceId: ds.id,
75
- },
76
- text: ds.title || ds.id,
77
- })),
78
- };
79
- });
80
-
81
- const changeHandler = (value: any) => {
82
- emit('change', value);
83
- };
84
-
85
- const editHandler = () => {
86
- const value = props.model[props.name];
87
-
88
- if (!value) return;
89
-
90
- const id = typeof value === 'string' ? value : value.dataSourceId;
91
-
92
- const dataSource = dataSourceService?.getDataSourceById(id);
93
-
94
- if (!dataSource) return;
95
-
96
- eventBus?.emit('edit-data-source', id);
97
- };
98
- </script>
@@ -1,301 +0,0 @@
1
- <template>
2
- <div class="m-fields-event-select">
3
- <m-form-table
4
- v-if="isOldVersion"
5
- ref="eventForm"
6
- name="events"
7
- :size="size"
8
- :disabled="disabled"
9
- :model="model"
10
- :config="tableConfig"
11
- @change="onChangeHandler"
12
- ></m-form-table>
13
-
14
- <div v-else class="fullWidth">
15
- <TMagicButton class="create-button" type="primary" :size="size" :disabled="disabled" @click="addEvent()"
16
- >添加事件</TMagicButton
17
- >
18
- <MPanel
19
- v-for="(cardItem, index) in model[name]"
20
- :key="index"
21
- :disabled="disabled"
22
- :size="size"
23
- :config="actionsConfig"
24
- :model="cardItem"
25
- :label-width="config.labelWidth || '100px'"
26
- @change="onChangeHandler"
27
- >
28
- <template #header>
29
- <MContainer
30
- class="fullWidth"
31
- :config="eventNameConfig"
32
- :model="cardItem"
33
- :disabled="disabled"
34
- :size="size"
35
- @change="onChangeHandler"
36
- ></MContainer>
37
- <TMagicButton
38
- style="color: #f56c6c"
39
- link
40
- :icon="Delete"
41
- :disabled="disabled"
42
- :size="size"
43
- @click="removeEvent(index)"
44
- ></TMagicButton>
45
- </template>
46
- </MPanel>
47
- </div>
48
- </div>
49
- </template>
50
-
51
- <script lang="ts" setup>
52
- import { computed, inject } from 'vue';
53
- import { Delete } from '@element-plus/icons-vue';
54
- import { has } from 'lodash-es';
55
-
56
- import type { EventOption } from '@tmagic/core';
57
- import { TMagicButton } from '@tmagic/design';
58
- import type { CascaderOption, FieldProps, FormState, PanelConfig } from '@tmagic/form';
59
- import { MContainer, MPanel } from '@tmagic/form';
60
- import { ActionType } from '@tmagic/schema';
61
- import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX } from '@tmagic/utils';
62
-
63
- import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
64
- import { getCascaderOptionsFromFields } from '@editor/utils';
65
-
66
- defineOptions({
67
- name: 'MFieldsEventSelect',
68
- });
69
-
70
- const props = defineProps<FieldProps<EventSelectConfig>>();
71
-
72
- const emit = defineEmits(['change']);
73
-
74
- const services = inject<Services>('services');
75
-
76
- const editorService = services?.editorService;
77
- const dataSourceService = services?.dataSourceService;
78
- const eventsService = services?.eventsService;
79
- const codeBlockService = services?.codeBlockService;
80
-
81
- // 事件名称下拉框表单配置
82
- const eventNameConfig = computed(() => {
83
- const fieldType = props.config.src === 'component' ? 'select' : 'cascader';
84
- const defaultEventNameConfig = {
85
- name: 'name',
86
- text: '事件',
87
- type: fieldType,
88
- labelWidth: '40px',
89
- checkStrictly: true,
90
- valueSeparator: '.',
91
- options: (mForm: FormState, { formValue }: any) => {
92
- let events: EventOption[] | CascaderOption[] = [];
93
-
94
- if (!eventsService || !dataSourceService) return events;
95
-
96
- if (props.config.src === 'component') {
97
- events = eventsService.getEvent(formValue.type);
98
- return events.map((option) => ({
99
- text: option.label,
100
- value: option.value,
101
- }));
102
- }
103
- if (props.config.src === 'datasource') {
104
- // 从数据源类型中获取到相关事件
105
- events = dataSourceService.getFormEvent(formValue.type);
106
- // 从数据源类型和实例中分别获取数据以追加数据变化的事件
107
- const dataSource = dataSourceService.getDataSourceById(formValue.id);
108
- const fields = dataSource?.fields || [];
109
- if (fields.length > 0) {
110
- return [
111
- ...events,
112
- {
113
- label: '数据变化',
114
- value: DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX,
115
- children: getCascaderOptionsFromFields(fields),
116
- },
117
- ];
118
- }
119
-
120
- return events;
121
- }
122
- },
123
- };
124
- return { ...defaultEventNameConfig, ...props.config.eventNameConfig };
125
- });
126
-
127
- // 联动类型
128
- const actionTypeConfig = computed(() => {
129
- const defaultActionTypeConfig = {
130
- name: 'actionType',
131
- text: '联动类型',
132
- type: 'select',
133
- defaultValue: ActionType.COMP,
134
- options: () => [
135
- {
136
- text: '组件',
137
- label: '组件',
138
- value: ActionType.COMP,
139
- },
140
- {
141
- text: '代码',
142
- label: '代码',
143
- disabled: !Object.keys(codeBlockService?.getCodeDsl() || {}).length,
144
- value: ActionType.CODE,
145
- },
146
- {
147
- text: '数据源',
148
- label: '数据源',
149
- disabled: !dataSourceService
150
- ?.get('dataSources')
151
- ?.filter((ds) => ds.methods?.length || dataSourceService?.getFormMethod(ds.type).length).length,
152
- value: ActionType.DATA_SOURCE,
153
- },
154
- ],
155
- };
156
- return { ...defaultActionTypeConfig, ...props.config.actionTypeConfig };
157
- });
158
-
159
- // 联动组件配置
160
- const targetCompConfig = computed(() => {
161
- const defaultTargetCompConfig = {
162
- name: 'to',
163
- text: '联动组件',
164
- type: 'ui-select',
165
- display: (mForm: FormState, { model }: { model: Record<any, any> }) => model.actionType === ActionType.COMP,
166
- };
167
- return { ...defaultTargetCompConfig, ...props.config.targetCompConfig };
168
- });
169
-
170
- // 联动组件动作配置
171
- const compActionConfig = computed(() => {
172
- const defaultCompActionConfig = {
173
- name: 'method',
174
- text: '动作',
175
- type: 'select',
176
- display: (mForm: FormState, { model }: { model: Record<any, any> }) => model.actionType === ActionType.COMP,
177
- options: (mForm: FormState, { model }: any) => {
178
- const node = editorService?.getNodeById(model.to);
179
- if (!node?.type) return [];
180
-
181
- return eventsService?.getMethod(node.type).map((option: any) => ({
182
- text: option.label,
183
- value: option.value,
184
- }));
185
- },
186
- };
187
- return { ...defaultCompActionConfig, ...props.config.compActionConfig };
188
- });
189
-
190
- // 代码联动配置
191
- const codeActionConfig = computed(() => {
192
- const defaultCodeActionConfig: CodeSelectColConfig = {
193
- type: 'code-select-col',
194
- text: '代码块',
195
- name: 'codeId',
196
- notEditable: () => !codeBlockService?.getEditStatus(),
197
- display: (mForm, { model }) => model.actionType === ActionType.CODE,
198
- };
199
- return { ...defaultCodeActionConfig, ...props.config.codeActionConfig };
200
- });
201
-
202
- // 数据源联动配置
203
- const dataSourceActionConfig = computed(() => {
204
- const defaultDataSourceActionConfig: DataSourceMethodSelectConfig = {
205
- type: 'data-source-method-select',
206
- text: '数据源方法',
207
- name: 'dataSourceMethod',
208
- notEditable: () => !services?.dataSourceService.get('editable'),
209
- display: (mForm, { model }) => model.actionType === ActionType.DATA_SOURCE,
210
- };
211
- return { ...defaultDataSourceActionConfig, ...props.config.dataSourceActionConfig };
212
- });
213
-
214
- // 兼容旧的数据格式
215
- const tableConfig = computed(() => ({
216
- type: 'table',
217
- name: 'events',
218
- items: [
219
- {
220
- name: 'name',
221
- label: '事件名',
222
- type: eventNameConfig.value.type,
223
- options: (mForm: FormState, { formValue }: any) =>
224
- eventsService?.getEvent(formValue.type).map((option: any) => ({
225
- text: option.label,
226
- value: option.value,
227
- })),
228
- },
229
- {
230
- name: 'to',
231
- label: '联动组件',
232
- type: 'ui-select',
233
- },
234
- {
235
- name: 'method',
236
- label: '动作',
237
- type: compActionConfig.value.type,
238
- options: (mForm: FormState, { model }: any) => {
239
- const node = editorService?.getNodeById(model.to);
240
- if (!node?.type) return [];
241
-
242
- return eventsService?.getMethod(node.type).map((option: any) => ({
243
- text: option.label,
244
- value: option.value,
245
- }));
246
- },
247
- },
248
- ],
249
- }));
250
-
251
- // 组件动作组表单配置
252
- const actionsConfig = computed<PanelConfig>(() => ({
253
- type: 'panel',
254
- items: [
255
- {
256
- type: 'group-list',
257
- name: 'actions',
258
- expandAll: true,
259
- enableToggleMode: false,
260
- titlePrefix: '动作',
261
- items: [
262
- actionTypeConfig.value,
263
- targetCompConfig.value,
264
- compActionConfig.value,
265
- codeActionConfig.value,
266
- dataSourceActionConfig.value,
267
- ],
268
- },
269
- ],
270
- }));
271
-
272
- // 是否为旧的数据格式
273
- const isOldVersion = computed(() => {
274
- if (props.model[props.name].length === 0) return false;
275
- return !has(props.model[props.name][0], 'actions');
276
- });
277
-
278
- // 添加事件
279
- const addEvent = () => {
280
- const defaultEvent = {
281
- name: '',
282
- actions: [],
283
- };
284
- if (!props.model[props.name]) {
285
- props.model[props.name] = [];
286
- }
287
- props.model[props.name].push(defaultEvent);
288
- onChangeHandler();
289
- };
290
-
291
- // 删除事件
292
- const removeEvent = (index: number) => {
293
- if (!props.name) return;
294
- props.model[props.name].splice(index, 1);
295
- onChangeHandler();
296
- };
297
-
298
- const onChangeHandler = () => {
299
- emit('change', props.model);
300
- };
301
- </script>