@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,325 +0,0 @@
1
- <template>
2
- <component
3
- v-if="disabled || isFocused"
4
- :is="getConfig('components')?.autocomplete.component || 'el-autocomplete'"
5
- class="tmagic-design-auto-complete"
6
- ref="autocomplete"
7
- v-model="state"
8
- v-bind="
9
- getConfig('components')?.autocomplete.props({
10
- disabled,
11
- size,
12
- fetchSuggestions: querySearch,
13
- triggerOnFocus: false,
14
- clearable: true,
15
- }) || {}
16
- "
17
- style="width: 100%"
18
- @blur="blurHandler"
19
- @input="inputHandler"
20
- @select="selectHandler"
21
- >
22
- <template #suffix>
23
- <Icon :icon="Coin" />
24
- </template>
25
- <template #default="{ item }">
26
- <div style="display: flex; flex-direction: column; line-height: 1.2em">
27
- <div>{{ item.text }}</div>
28
- <span style="font-size: 10px; color: rgba(0, 0, 0, 0.6)">{{ item.value }}</span>
29
- </div>
30
- </template>
31
- </component>
32
- <div
33
- :class="`tmagic-data-source-input-text el-input t-input t-size-${size?.[0]} el-input--${size}`"
34
- @mouseup="mouseupHandler"
35
- v-else
36
- >
37
- <div :class="`tmagic-data-source-input-text-wrapper el-input__wrapper ${isFocused ? ' is-focus' : ''}`">
38
- <div class="el-input__inner t-input__inner">
39
- <template v-for="(item, index) in displayState">
40
- <span :key="index" v-if="item.type === 'text'" style="margin-right: 2px">{{ item.value }}</span>
41
- <TMagicTag :key="index" :size="size" v-if="item.type === 'var'">{{ item.value }}</TMagicTag>
42
- </template>
43
-
44
- <Icon class="tmagic-data-source-input-icon" :icon="Coin" />
45
- </div>
46
- </div>
47
- </div>
48
- </template>
49
-
50
- <script setup lang="ts">
51
- import { computed, inject, nextTick, ref, watch } from 'vue';
52
- import { Coin } from '@element-plus/icons-vue';
53
-
54
- import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
55
- import type { FieldProps, FormItem } from '@tmagic/form';
56
- import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
57
-
58
- import Icon from '@editor/components/Icon.vue';
59
- import type { Services } from '@editor/type';
60
- import { getDisplayField } from '@editor/utils/data-source';
61
-
62
- defineOptions({
63
- name: 'MFieldsDataSourceInput',
64
- });
65
-
66
- const props = withDefaults(
67
- defineProps<
68
- FieldProps<
69
- {
70
- type: 'data-source-input';
71
- } & FormItem
72
- >
73
- >(),
74
- {
75
- disabled: false,
76
- },
77
- );
78
-
79
- const emit = defineEmits<{
80
- change: [value: string];
81
- }>();
82
-
83
- const { dataSourceService } = inject<Services>('services') || {};
84
-
85
- const autocomplete = ref<InstanceType<typeof TMagicAutocomplete>>();
86
- const isFocused = ref(false);
87
- const state = ref('');
88
- const displayState = ref<{ value: string; type: 'var' | 'text' }[]>([]);
89
-
90
- const input = computed<HTMLInputElement>(() => autocomplete.value?.inputRef?.input);
91
- const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
92
-
93
- const setDisplayState = () => {
94
- displayState.value = getDisplayField(dataSources.value, state.value);
95
- };
96
-
97
- watch(
98
- () => props.model[props.name],
99
- (value = '') => {
100
- state.value = value;
101
-
102
- setDisplayState();
103
- },
104
- { immediate: true },
105
- );
106
-
107
- const mouseupHandler = async () => {
108
- isFocused.value = true;
109
- await nextTick();
110
- autocomplete.value?.focus();
111
- };
112
-
113
- const blurHandler = () => {
114
- isFocused.value = false;
115
-
116
- setDisplayState();
117
-
118
- emit('change', state.value);
119
- };
120
-
121
- const changeHandler = (v: string) => {
122
- emit('change', v);
123
- };
124
-
125
- let inputText = '';
126
-
127
- const inputHandler = (v: string) => {
128
- if (!v) {
129
- inputText = v;
130
- }
131
- };
132
-
133
- /**
134
- * 光标位置是不是}
135
- * @param selectionStart 光标位置
136
- */
137
- const isRightCurlyBracket = (selectionStart = 0) => {
138
- const lastChar = inputText.substring(selectionStart - 1, selectionStart);
139
- return lastChar === '}';
140
- };
141
-
142
- /**
143
- * 获取光标位置
144
- */
145
- const getSelectionStart = () => {
146
- let selectionStart = input.value?.selectionStart || 0;
147
-
148
- // 输入法可能会自动补全},如果当前光标前面一个字符是},则光标前移一位
149
- if (isRightCurlyBracket(selectionStart)) {
150
- selectionStart -= 1;
151
- }
152
-
153
- return selectionStart;
154
- };
155
-
156
- /**
157
- * 当前输入的是{
158
- * @param leftCurlyBracketIndex {字符索引
159
- */
160
- const curCharIsLeftCurlyBracket = (leftCurlyBracketIndex: number) =>
161
- leftCurlyBracketIndex > 0 && leftCurlyBracketIndex === getSelectionStart() - 1;
162
-
163
- /**
164
- * 当前输入的是.
165
- * @param leftCurlyBracketIndex .字符索引
166
- */
167
- const curCharIsDot = (dotIndex: number) => dotIndex > -1 && dotIndex === getSelectionStart() - 1;
168
-
169
- /**
170
- * @param leftCurlyBracketIndex 左大括号字符索引
171
- * @param cb 建议的方法
172
- */
173
- const dsQuerySearch = (queryString: string, leftCurlyBracketIndex: number, cb: (data: { value: string }[]) => void) => {
174
- let result: DataSourceSchema[] = [];
175
-
176
- if (curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
177
- // 当前输入的是{
178
- result = dataSources.value;
179
- } else if (leftCurlyBracketIndex > 0) {
180
- // 当前输入的是{xx
181
- const queryName = queryString.substring(leftCurlyBracketIndex + 1).toLowerCase();
182
- result = dataSources.value.filter((ds) => ds.title?.toLowerCase().includes(queryName) || ds.id.includes(queryName));
183
- }
184
-
185
- cb(
186
- result.map((ds) => ({
187
- value: ds.id,
188
- text: ds.title,
189
- type: 'dataSource',
190
- })),
191
- );
192
- };
193
-
194
- /**
195
- * 字段提示
196
- * @param queryString 当前输入框内的字符串
197
- * @param leftAngleIndex {字符索引
198
- * @param dotIndex .字符索引
199
- * @param cb 建议回调
200
- */
201
- const fieldQuerySearch = (
202
- queryString: string,
203
- leftAngleIndex: number,
204
- dotIndex: number,
205
- cb: (data: { value: string }[]) => void,
206
- ) => {
207
- let result: DataSchema[] = [];
208
-
209
- const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
210
-
211
- // 可能是xx.xx.xx,存在链式调用
212
- const keys = dsKey.split('.');
213
-
214
- // 最前的是数据源id
215
- const dsId = keys.shift();
216
- const ds = dataSources.value.find((ds) => ds.id === dsId);
217
- if (!ds) {
218
- cb([]);
219
- return;
220
- }
221
-
222
- let fields = ds.fields || [];
223
-
224
- // 后面这些是字段
225
- let key = keys.shift();
226
- while (key) {
227
- for (const field of fields) {
228
- if (field.name === key) {
229
- fields = field.fields || [];
230
- key = keys.shift();
231
- break;
232
- }
233
- }
234
- }
235
-
236
- if (curCharIsDot(dotIndex)) {
237
- // 当前输入的是.
238
- result = fields || [];
239
- } else if (dotIndex > -1) {
240
- const queryName = queryString.substring(dotIndex + 1).toLowerCase();
241
- result =
242
- fields.filter(
243
- (field) => field.name?.toLowerCase().includes(queryName) || field.title?.toLowerCase().includes(queryName),
244
- ) || [];
245
- }
246
-
247
- cb(
248
- result.map((field) => ({
249
- value: field.name,
250
- text: field.title,
251
- type: 'field',
252
- })),
253
- );
254
- };
255
-
256
- /**
257
- * 数据源提示
258
- * @param queryString 当前输入框内的字符串
259
- * @param cb 建议回调
260
- */
261
- const querySearch = (queryString: string, cb: (data: { value: string }[]) => void) => {
262
- inputText = queryString;
263
-
264
- const selectionStart = getSelectionStart();
265
-
266
- const curQueryString = queryString.substring(0, selectionStart);
267
-
268
- const fieldKeyStringLastIndex = curQueryString.lastIndexOf('.');
269
- const dsKeyStringLastIndex = curQueryString.lastIndexOf('${') + 1;
270
-
271
- const isFieldTip = fieldKeyStringLastIndex > dsKeyStringLastIndex;
272
-
273
- if (isFieldTip) {
274
- fieldQuerySearch(curQueryString, dsKeyStringLastIndex, fieldKeyStringLastIndex, cb);
275
- } else {
276
- dsQuerySearch(curQueryString, dsKeyStringLastIndex, cb);
277
- }
278
- };
279
-
280
- /**
281
- * 选择建议
282
- * @param value 建议值
283
- * @param type 建议类型,是数据源还是字段
284
- */
285
- const selectHandler = async ({ value, type }: { value: string; type: 'dataSource' | 'field' }) => {
286
- const isDataSource = type === 'dataSource';
287
- const selectionStart = input.value?.selectionStart || 0;
288
- let startText = inputText.substring(0, selectionStart);
289
-
290
- const dotIndex = startText.lastIndexOf('.');
291
- const leftCurlyBracketIndex = startText.lastIndexOf('${') + 1;
292
-
293
- const endText = inputText.substring(selectionStart);
294
-
295
- let suggestText = value;
296
-
297
- if (isDataSource) {
298
- if (!curCharIsLeftCurlyBracket(leftCurlyBracketIndex)) {
299
- startText = startText.substring(0, leftCurlyBracketIndex + 1);
300
- }
301
-
302
- // 当前光标后一位是否为},不是的话需要补上
303
- if (!isRightCurlyBracket(selectionStart + 1)) {
304
- suggestText = `${suggestText}}`;
305
- }
306
- } else if (!curCharIsDot(dotIndex)) {
307
- startText = startText.substring(0, dotIndex + 1);
308
- }
309
-
310
- state.value = `${startText}${suggestText}${endText}`;
311
-
312
- await nextTick();
313
-
314
- // 由于选择数据源时会在后面补全}, 所以光标要前移2位
315
- let newSelectionStart = 0;
316
- if (isDataSource) {
317
- newSelectionStart = leftCurlyBracketIndex + suggestText.length;
318
- } else {
319
- newSelectionStart = dotIndex + suggestText.length + 1;
320
- }
321
- input.value?.setSelectionRange(newSelectionStart, newSelectionStart);
322
-
323
- changeHandler(state.value);
324
- };
325
- </script>
@@ -1,153 +0,0 @@
1
- <template>
2
- <div class="m-fields-data-source-method-select">
3
- <div class="data-source-method-select-container">
4
- <MContainer
5
- class="select"
6
- :config="cascaderConfig"
7
- :model="model"
8
- :size="size"
9
- @change="onChangeHandler"
10
- ></MContainer>
11
-
12
- <TMagicButton
13
- v-if="model[name] && isCustomMethod && hasDataSourceSidePanel"
14
- class="m-fields-select-action-button"
15
- :size="size"
16
- @click="editCodeHandler"
17
- >
18
- <MIcon :icon="!notEditable ? Edit : View"></MIcon>
19
- </TMagicButton>
20
- </div>
21
-
22
- <CodeParams
23
- v-if="paramsConfig.length"
24
- name="params"
25
- :model="model"
26
- :size="size"
27
- :disabled="disabled"
28
- :params-config="paramsConfig"
29
- @change="onChangeHandler"
30
- ></CodeParams>
31
- </div>
32
- </template>
33
-
34
- <script lang="ts" setup name="">
35
- import { computed, inject, ref } from 'vue';
36
- import { Edit, View } from '@element-plus/icons-vue';
37
-
38
- import { TMagicButton } from '@tmagic/design';
39
- import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
40
- import type { Id } from '@tmagic/schema';
41
-
42
- import CodeParams from '@editor/components/CodeParams.vue';
43
- import MIcon from '@editor/components/Icon.vue';
44
- import type { CodeParamStatement, DataSourceMethodSelectConfig, EventBus, Services } from '@editor/type';
45
- import { SideItemKey } from '@editor/type';
46
-
47
- defineOptions({
48
- name: 'MFieldsDataSourceMethodSelect',
49
- });
50
-
51
- const mForm = inject<FormState | undefined>('mForm');
52
- const services = inject<Services>('services');
53
- const eventBus = inject<EventBus>('eventBus');
54
-
55
- const emit = defineEmits(['change']);
56
-
57
- const dataSourceService = services?.dataSourceService;
58
-
59
- const props = withDefaults(defineProps<FieldProps<DataSourceMethodSelectConfig>>(), {
60
- disabled: false,
61
- });
62
-
63
- const hasDataSourceSidePanel = computed(() =>
64
- (services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
65
- );
66
-
67
- const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
68
-
69
- const dataSources = computed(() => dataSourceService?.get('dataSources'));
70
-
71
- const isCustomMethod = computed(() => {
72
- const [id, name] = props.model[props.name];
73
-
74
- const dataSource = dataSourceService?.getDataSourceById(id);
75
-
76
- return Boolean(dataSource?.methods.find((method) => method.name === name));
77
- });
78
-
79
- const getParamItemsConfig = ([dataSourceId, methodName]: [Id, string] = ['', '']): CodeParamStatement[] => {
80
- if (!dataSourceId) return [];
81
-
82
- const paramStatements = dataSources.value
83
- ?.find((item) => item.id === dataSourceId)
84
- ?.methods?.find((item) => item.name === methodName)?.params;
85
-
86
- if (!paramStatements) return [];
87
-
88
- return paramStatements.map((paramState: CodeParamStatement) => ({
89
- text: paramState.name,
90
- ...paramState,
91
- }));
92
- };
93
-
94
- const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model.dataSourceMethod));
95
-
96
- const setParamsConfig = (dataSourceMethod: [Id, string], formState: any = {}) => {
97
- // 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
98
- paramsConfig.value = dataSourceMethod ? getParamItemsConfig(dataSourceMethod) : [];
99
-
100
- if (paramsConfig.value.length) {
101
- props.model.params = createValues(formState, paramsConfig.value, {}, props.model.params);
102
- } else {
103
- props.model.params = {};
104
- }
105
- };
106
-
107
- const methodsOptions = computed(
108
- () =>
109
- dataSources.value
110
- ?.filter((ds) => ds.methods?.length || dataSourceService?.getFormMethod(ds.type).length)
111
- ?.map((ds) => ({
112
- label: ds.title || ds.id,
113
- value: ds.id,
114
- children: [
115
- ...(dataSourceService?.getFormMethod(ds.type) || []),
116
- ...(ds.methods || []).map((method) => ({
117
- label: method.name,
118
- value: method.name,
119
- })),
120
- ],
121
- })) || [],
122
- );
123
-
124
- const cascaderConfig = computed(() => ({
125
- type: 'cascader',
126
- name: props.name,
127
- options: methodsOptions.value,
128
- disable: props.disabled,
129
- onChange: (formState: any, dataSourceMethod: [Id, string]) => {
130
- setParamsConfig(dataSourceMethod, formState);
131
-
132
- return dataSourceMethod;
133
- },
134
- }));
135
-
136
- /**
137
- * 参数值修改更新
138
- */
139
- const onChangeHandler = (value: any) => {
140
- props.model.params = value.params;
141
- emit('change', props.model);
142
- };
143
-
144
- const editCodeHandler = () => {
145
- const [id] = props.model[props.name];
146
-
147
- const dataSource = dataSourceService?.getDataSourceById(id);
148
-
149
- if (!dataSource) return;
150
-
151
- eventBus?.emit('edit-data-source', id);
152
- };
153
- </script>
@@ -1,104 +0,0 @@
1
- <template>
2
- <div class="m-editor-data-source-methods">
3
- <MagicTable :data="model[name]" :columns="methodColumns"></MagicTable>
4
-
5
- <div class="m-editor-data-source-methods-footer">
6
- <TMagicButton size="small" type="primary" :disabled="disabled" plain @click="createCodeHandler"
7
- >添加</TMagicButton
8
- >
9
- </div>
10
-
11
- <CodeBlockEditor
12
- v-if="codeConfig"
13
- ref="codeBlockEditor"
14
- :disabled="disabled"
15
- :content="codeConfig"
16
- :is-data-source="true"
17
- :data-source-type="model.type"
18
- @submit="submitCodeHandler"
19
- ></CodeBlockEditor>
20
- </div>
21
- </template>
22
-
23
- <script setup lang="ts">
24
- import { TMagicButton } from '@tmagic/design';
25
- import type { FieldProps } from '@tmagic/form';
26
- import type { CodeBlockContent } from '@tmagic/schema';
27
- import { type ColumnConfig, MagicTable } from '@tmagic/table';
28
-
29
- import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
30
- import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
31
- import type { CodeParamStatement } from '@editor/type';
32
-
33
- defineOptions({
34
- name: 'MFieldsDataSourceMethods',
35
- });
36
-
37
- const props = withDefaults(
38
- defineProps<
39
- FieldProps<{
40
- type: 'data-source-methods';
41
- }>
42
- >(),
43
- {
44
- disabled: false,
45
- },
46
- );
47
-
48
- const emit = defineEmits(['change']);
49
-
50
- const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
51
-
52
- const methodColumns: ColumnConfig[] = [
53
- {
54
- label: '名称',
55
- prop: 'name',
56
- },
57
- {
58
- label: '描述',
59
- prop: 'desc',
60
- },
61
- {
62
- label: '执行时机',
63
- prop: 'timing',
64
- },
65
- {
66
- label: '参数',
67
- prop: 'params',
68
- formatter: (params: CodeParamStatement[]) => params.map((item) => item.name).join(', '),
69
- },
70
- {
71
- label: '操作',
72
- fixed: 'right',
73
- actions: [
74
- {
75
- text: '编辑',
76
- handler: (row: CodeBlockContent) => {
77
- editCode(props.model, row.name);
78
- emit('change', props.model[props.name]);
79
- },
80
- },
81
- {
82
- text: '删除',
83
- buttonType: 'danger',
84
- handler: (row: CodeBlockContent) => {
85
- deleteCode(props.model, row.name);
86
- emit('change', props.model[props.name]);
87
- },
88
- },
89
- ],
90
- },
91
- ];
92
-
93
- const createCodeHandler = () => {
94
- createCode(props.model);
95
-
96
- emit('change', props.model[props.name]);
97
- };
98
-
99
- const submitCodeHandler = (values: CodeBlockContent) => {
100
- submitCode(values);
101
-
102
- emit('change', props.model[props.name]);
103
- };
104
- </script>