@tmagic/editor 1.5.0-beta.9 → 1.5.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.
- package/dist/style.css +75 -16
- package/dist/tmagic-editor.js +797 -518
- package/dist/tmagic-editor.umd.cjs +802 -525
- package/package.json +12 -10
- package/src/Editor.vue +6 -1
- package/src/components/CodeBlockEditor.vue +11 -5
- package/src/components/CodeParams.vue +3 -3
- package/src/editorProps.ts +3 -1
- package/src/fields/Code.vue +1 -2
- package/src/fields/CodeSelect.vue +13 -11
- package/src/fields/CodeSelectCol.vue +32 -5
- package/src/fields/CondOpSelect.vue +5 -2
- package/src/fields/DataSourceFields.vue +31 -12
- package/src/fields/DataSourceMethods.vue +72 -14
- package/src/fields/DisplayConds.vue +8 -3
- package/src/fields/EventSelect.vue +28 -11
- package/src/fields/KeyValue.vue +15 -10
- package/src/fields/UISelect.vue +6 -3
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-code-block-edit.ts +1 -1
- package/src/hooks/use-data-source-edit.ts +3 -2
- package/src/hooks/use-filter.ts +1 -1
- package/src/hooks/use-node-status.ts +2 -2
- package/src/initService.ts +177 -74
- package/src/layouts/Framework.vue +8 -4
- package/src/layouts/PropsPanel.vue +3 -3
- package/src/layouts/page-bar/AddButton.vue +29 -9
- package/src/layouts/page-bar/PageBar.vue +78 -65
- package/src/layouts/page-bar/PageBarScrollContainer.vue +82 -96
- package/src/layouts/page-bar/PageList.vue +5 -3
- package/src/layouts/page-bar/Search.vue +67 -0
- package/src/layouts/sidebar/Sidebar.vue +3 -0
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +6 -1
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
- package/src/layouts/sidebar/data-source/DataSourceList.vue +6 -1
- package/src/layouts/sidebar/layer/use-node-status.ts +2 -3
- package/src/layouts/workspace/Workspace.vue +5 -2
- package/src/layouts/workspace/viewer/Stage.vue +23 -5
- package/src/services/dataSource.ts +12 -5
- package/src/services/dep.ts +61 -13
- package/src/services/editor.ts +46 -51
- package/src/theme/page-bar.scss +38 -16
- package/src/theme/search-input.scss +1 -0
- package/src/type.ts +2 -1
- package/src/utils/data-source/formConfigs/http.ts +2 -0
- package/src/utils/data-source/index.ts +2 -2
- package/src/utils/editor.ts +78 -22
- package/src/utils/idle-task.ts +36 -4
- package/src/utils/props.ts +3 -3
- package/types/index.d.ts +835 -1169
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.5.0
|
|
2
|
+
"version": "1.5.0",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"node": ">=18"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
|
+
"directory": "packages/editor",
|
|
35
36
|
"type": "git",
|
|
36
37
|
"url": "https://github.com/Tencent/tmagic-editor.git"
|
|
37
38
|
},
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"@element-plus/icons-vue": "^2.3.1",
|
|
49
50
|
"buffer": "^6.0.3",
|
|
50
51
|
"color": "^3.1.3",
|
|
52
|
+
"deep-object-diff": "^1.1.9",
|
|
51
53
|
"emmet-monaco-es": "^5.3.0",
|
|
52
54
|
"events": "^3.3.0",
|
|
53
55
|
"gesto": "^1.19.1",
|
|
@@ -56,11 +58,11 @@
|
|
|
56
58
|
"moveable": "^0.53.0",
|
|
57
59
|
"serialize-javascript": "^6.0.0",
|
|
58
60
|
"sortablejs": "^1.15.2",
|
|
59
|
-
"@tmagic/
|
|
60
|
-
"@tmagic/
|
|
61
|
-
"@tmagic/
|
|
62
|
-
"@tmagic/
|
|
63
|
-
"@tmagic/
|
|
61
|
+
"@tmagic/design": "1.5.0",
|
|
62
|
+
"@tmagic/form": "1.5.0",
|
|
63
|
+
"@tmagic/stage": "1.5.0",
|
|
64
|
+
"@tmagic/utils": "1.5.0",
|
|
65
|
+
"@tmagic/table": "1.5.0"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
66
68
|
"@types/events": "^3.0.0",
|
|
@@ -69,19 +71,19 @@
|
|
|
69
71
|
"@types/serialize-javascript": "^5.0.1",
|
|
70
72
|
"@types/sortablejs": "^1.15.8",
|
|
71
73
|
"@vitejs/plugin-vue": "^5.1.3",
|
|
72
|
-
"@vue/compiler-sfc": "^3.5.
|
|
74
|
+
"@vue/compiler-sfc": "^3.5.12",
|
|
73
75
|
"@vue/test-utils": "^2.4.6",
|
|
74
76
|
"rimraf": "^3.0.2",
|
|
75
77
|
"sass": "^1.78.0",
|
|
76
78
|
"tsc-alias": "^1.8.5",
|
|
77
79
|
"type-fest": "^4.10.3",
|
|
78
|
-
"vite": "^5.4.
|
|
80
|
+
"vite": "^5.4.10"
|
|
79
81
|
},
|
|
80
82
|
"peerDependencies": {
|
|
81
83
|
"monaco-editor": "^0.48.0",
|
|
82
84
|
"typescript": "*",
|
|
83
|
-
"vue": "
|
|
84
|
-
"@tmagic/core": "1.5.0
|
|
85
|
+
"vue": ">=3.5.0",
|
|
86
|
+
"@tmagic/core": "1.5.0"
|
|
85
87
|
},
|
|
86
88
|
"peerDependenciesMeta": {
|
|
87
89
|
"typescript": {
|
package/src/Editor.vue
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<Framework
|
|
2
|
+
<Framework
|
|
3
|
+
:disabled-page-fragment="disabledPageFragment"
|
|
4
|
+
:page-bar-sort-options="pageBarSortOptions"
|
|
5
|
+
:page-filter-function="pageFilterFunction"
|
|
6
|
+
>
|
|
3
7
|
<template #header>
|
|
4
8
|
<slot name="header"></slot>
|
|
5
9
|
</template>
|
|
@@ -114,6 +118,7 @@
|
|
|
114
118
|
</template>
|
|
115
119
|
|
|
116
120
|
<template #page-bar><slot name="page-bar"></slot></template>
|
|
121
|
+
<template #page-bar-add-button><slot name="page-bar-add-button"></slot></template>
|
|
117
122
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
118
123
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
119
124
|
<template #page-list-popover="{ list }"><slot name="page-list-popover" :list="list"></slot></template>
|
|
@@ -63,7 +63,13 @@ import { computed, inject, Ref, ref } from 'vue';
|
|
|
63
63
|
|
|
64
64
|
import type { CodeBlockContent } from '@tmagic/core';
|
|
65
65
|
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
|
66
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
type ContainerChangeEventData,
|
|
68
|
+
type FormConfig,
|
|
69
|
+
type FormState,
|
|
70
|
+
MFormBox,
|
|
71
|
+
type TableColumnConfig,
|
|
72
|
+
} from '@tmagic/form';
|
|
67
73
|
|
|
68
74
|
import FloatingBox from '@editor/components/FloatingBox.vue';
|
|
69
75
|
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
|
@@ -88,7 +94,7 @@ const props = defineProps<{
|
|
|
88
94
|
}>();
|
|
89
95
|
|
|
90
96
|
const emit = defineEmits<{
|
|
91
|
-
submit: [values: CodeBlockContent];
|
|
97
|
+
submit: [values: CodeBlockContent, eventData: ContainerChangeEventData];
|
|
92
98
|
}>();
|
|
93
99
|
|
|
94
100
|
const services = inject<Services>('services');
|
|
@@ -209,9 +215,9 @@ const functionConfig = computed<FormConfig>(() => [
|
|
|
209
215
|
},
|
|
210
216
|
]);
|
|
211
217
|
|
|
212
|
-
const submitForm = (values: CodeBlockContent) => {
|
|
218
|
+
const submitForm = (values: CodeBlockContent, data: ContainerChangeEventData) => {
|
|
213
219
|
changedValue.value = undefined;
|
|
214
|
-
emit('submit', values);
|
|
220
|
+
emit('submit', values, data);
|
|
215
221
|
};
|
|
216
222
|
|
|
217
223
|
const errorHandler = (error: any) => {
|
|
@@ -238,7 +244,7 @@ const beforeClose = (done: (cancel?: boolean) => void) => {
|
|
|
238
244
|
distinguishCancelAndClose: true,
|
|
239
245
|
})
|
|
240
246
|
.then(() => {
|
|
241
|
-
changedValue.value && submitForm(changedValue.value);
|
|
247
|
+
changedValue.value && submitForm(changedValue.value, { changeRecords: formBox.value?.form?.changeRecords });
|
|
242
248
|
done();
|
|
243
249
|
})
|
|
244
250
|
.catch((action: string) => {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<script lang="ts" setup>
|
|
14
14
|
import { computed, ref } from 'vue';
|
|
15
15
|
|
|
16
|
-
import { FormConfig, MForm } from '@tmagic/form';
|
|
16
|
+
import { type ContainerChangeEventData, type FormConfig, type FormValue, MForm } from '@tmagic/form';
|
|
17
17
|
|
|
18
18
|
import type { CodeParamStatement } from '@editor/type';
|
|
19
19
|
import { error } from '@editor/utils';
|
|
@@ -59,10 +59,10 @@ const codeParamsConfig = computed(() =>
|
|
|
59
59
|
/**
|
|
60
60
|
* 参数值修改更新
|
|
61
61
|
*/
|
|
62
|
-
const onParamsChangeHandler = async () => {
|
|
62
|
+
const onParamsChangeHandler = async (v: FormValue, eventData: ContainerChangeEventData) => {
|
|
63
63
|
try {
|
|
64
64
|
const value = await form.value?.submitForm(true);
|
|
65
|
-
emit('change', value);
|
|
65
|
+
emit('change', value, eventData);
|
|
66
66
|
} catch (e) {
|
|
67
67
|
error(e);
|
|
68
68
|
}
|
package/src/editorProps.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataSourceSchema, EventOption, Id, MApp, MNode } from '@tmagic/core';
|
|
1
|
+
import type { DataSourceSchema, EventOption, Id, MApp, MNode, MPage, MPageFragment } from '@tmagic/core';
|
|
2
2
|
import type { FormConfig, FormState } from '@tmagic/form';
|
|
3
3
|
import StageCore, {
|
|
4
4
|
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
@@ -97,6 +97,8 @@ export interface EditorProps {
|
|
|
97
97
|
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
98
98
|
/** 页面顺序拖拽配置参数 */
|
|
99
99
|
pageBarSortOptions?: PageBarSortOptions;
|
|
100
|
+
/** 页面搜索函数 */
|
|
101
|
+
pageFilterFunction?: (page: MPage | MPageFragment, keyword: string) => boolean;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
export const defaultEditorProps = {
|
package/src/fields/Code.vue
CHANGED
|
@@ -25,7 +25,7 @@ const emit = defineEmits<{
|
|
|
25
25
|
change: [value: string | any];
|
|
26
26
|
}>();
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
withDefaults(
|
|
29
29
|
defineProps<
|
|
30
30
|
FieldProps<
|
|
31
31
|
{
|
|
@@ -44,7 +44,6 @@ const props = withDefaults(
|
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
const save = (v: string | any) => {
|
|
47
|
-
props.model[props.name] = v;
|
|
48
47
|
emit('change', v);
|
|
49
48
|
};
|
|
50
49
|
</script>
|
|
@@ -21,8 +21,8 @@ import { isEmpty } from 'lodash-es';
|
|
|
21
21
|
|
|
22
22
|
import { HookCodeType, HookType } from '@tmagic/core';
|
|
23
23
|
import { TMagicCard } from '@tmagic/design';
|
|
24
|
-
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
25
|
-
import {
|
|
24
|
+
import type { ContainerChangeEventData, FieldProps, FormItem, GroupListConfig } from '@tmagic/form';
|
|
25
|
+
import { MContainer } from '@tmagic/form';
|
|
26
26
|
|
|
27
27
|
import type { Services } from '@editor/type';
|
|
28
28
|
|
|
@@ -30,7 +30,9 @@ defineOptions({
|
|
|
30
30
|
name: 'MFieldsCodeSelect',
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
const emit = defineEmits
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
change: [v: any, eventData: ContainerChangeEventData];
|
|
35
|
+
}>();
|
|
34
36
|
|
|
35
37
|
const services = inject<Services>('services');
|
|
36
38
|
|
|
@@ -45,12 +47,12 @@ const props = withDefaults(
|
|
|
45
47
|
{},
|
|
46
48
|
);
|
|
47
49
|
|
|
48
|
-
const codeConfig = computed(() => ({
|
|
50
|
+
const codeConfig = computed<GroupListConfig>(() => ({
|
|
49
51
|
type: 'group-list',
|
|
50
52
|
name: 'hookData',
|
|
51
53
|
enableToggleMode: false,
|
|
52
54
|
expandAll: true,
|
|
53
|
-
title: (mForm
|
|
55
|
+
title: (mForm, { model, index }: any) => {
|
|
54
56
|
if (model.codeType === HookCodeType.DATA_SOURCE_METHOD) {
|
|
55
57
|
if (Array.isArray(model.codeId)) {
|
|
56
58
|
if (model.codeId.length < 2) {
|
|
@@ -78,11 +80,13 @@ const codeConfig = computed(() => ({
|
|
|
78
80
|
{ value: HookCodeType.DATA_SOURCE_METHOD, text: '数据源方法' },
|
|
79
81
|
],
|
|
80
82
|
defaultValue: 'code',
|
|
81
|
-
onChange: (mForm
|
|
83
|
+
onChange: (mForm, v: HookCodeType, { model, prop, changeRecords }) => {
|
|
82
84
|
if (v === HookCodeType.DATA_SOURCE_METHOD) {
|
|
83
85
|
model.codeId = [];
|
|
86
|
+
changeRecords.push({ propPath: prop.replace('codeType', 'codeId'), value: [] });
|
|
84
87
|
} else {
|
|
85
88
|
model.codeId = '';
|
|
89
|
+
changeRecords.push({ propPath: prop.replace('codeType', 'codeId'), value: '' });
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
return v;
|
|
@@ -93,7 +97,7 @@ const codeConfig = computed(() => ({
|
|
|
93
97
|
name: 'codeId',
|
|
94
98
|
span: 18,
|
|
95
99
|
labelWidth: 0,
|
|
96
|
-
display: (mForm
|
|
100
|
+
display: (mForm, { model }) => model.codeType !== HookCodeType.DATA_SOURCE_METHOD,
|
|
97
101
|
notEditable: () => !services?.codeBlockService.getEditStatus(),
|
|
98
102
|
},
|
|
99
103
|
{
|
|
@@ -101,7 +105,7 @@ const codeConfig = computed(() => ({
|
|
|
101
105
|
name: 'codeId',
|
|
102
106
|
span: 18,
|
|
103
107
|
labelWidth: 0,
|
|
104
|
-
display: (mForm
|
|
108
|
+
display: (mForm, { model }) => model.codeType === HookCodeType.DATA_SOURCE_METHOD,
|
|
105
109
|
notEditable: () => !services?.dataSourceService.get('editable'),
|
|
106
110
|
},
|
|
107
111
|
],
|
|
@@ -126,7 +130,5 @@ watch(
|
|
|
126
130
|
},
|
|
127
131
|
);
|
|
128
132
|
|
|
129
|
-
const changeHandler =
|
|
130
|
-
emit('change', props.model[props.name]);
|
|
131
|
-
};
|
|
133
|
+
const changeHandler = (v: any, eventData: ContainerChangeEventData) => emit('change', v, eventData);
|
|
132
134
|
</script>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
:config="selectConfig"
|
|
8
8
|
:model="model"
|
|
9
9
|
:size="size"
|
|
10
|
-
@change="
|
|
10
|
+
@change="onCodeIdChangeHandler"
|
|
11
11
|
></MContainer>
|
|
12
12
|
|
|
13
13
|
<!-- 查看/编辑按钮 -->
|
|
@@ -41,7 +41,14 @@ import { isEmpty, map } from 'lodash-es';
|
|
|
41
41
|
|
|
42
42
|
import type { Id } from '@tmagic/core';
|
|
43
43
|
import { TMagicButton } from '@tmagic/design';
|
|
44
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
type ContainerChangeEventData,
|
|
46
|
+
createValues,
|
|
47
|
+
type FieldProps,
|
|
48
|
+
filterFunction,
|
|
49
|
+
type FormState,
|
|
50
|
+
MContainer,
|
|
51
|
+
} from '@tmagic/form';
|
|
45
52
|
|
|
46
53
|
import CodeParams from '@editor/components/CodeParams.vue';
|
|
47
54
|
import MIcon from '@editor/components/Icon.vue';
|
|
@@ -55,7 +62,9 @@ defineOptions({
|
|
|
55
62
|
const mForm = inject<FormState | undefined>('mForm');
|
|
56
63
|
const services = inject<Services>('services');
|
|
57
64
|
const eventBus = inject<EventBus>('eventBus');
|
|
58
|
-
const emit = defineEmits
|
|
65
|
+
const emit = defineEmits<{
|
|
66
|
+
change: [v: any, eventData: ContainerChangeEventData];
|
|
67
|
+
}>();
|
|
59
68
|
|
|
60
69
|
const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
|
|
61
70
|
disabled: false,
|
|
@@ -125,12 +134,30 @@ const selectConfig = {
|
|
|
125
134
|
},
|
|
126
135
|
};
|
|
127
136
|
|
|
137
|
+
const onCodeIdChangeHandler = (value: any) => {
|
|
138
|
+
props.model.params = value.params;
|
|
139
|
+
emit('change', props.model, {
|
|
140
|
+
changeRecords: [
|
|
141
|
+
{
|
|
142
|
+
propPath: props.prop,
|
|
143
|
+
value: value[props.name],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
128
149
|
/**
|
|
129
150
|
* 参数值修改更新
|
|
130
151
|
*/
|
|
131
|
-
const onParamsChangeHandler = (value: any) => {
|
|
152
|
+
const onParamsChangeHandler = (value: any, eventData: ContainerChangeEventData) => {
|
|
132
153
|
props.model.params = value.params;
|
|
133
|
-
emit('change', props.model
|
|
154
|
+
emit('change', props.model, {
|
|
155
|
+
...eventData,
|
|
156
|
+
changeRecords: (eventData.changeRecords || []).map((item) => ({
|
|
157
|
+
prop: `${props.prop.replace(props.name, '')}${item.propPath}`,
|
|
158
|
+
value: item.value,
|
|
159
|
+
})),
|
|
160
|
+
});
|
|
134
161
|
};
|
|
135
162
|
|
|
136
163
|
const editCode = (id: string) => {
|
|
@@ -39,7 +39,10 @@ defineOptions({
|
|
|
39
39
|
name: 'MFieldsCondOpSelect',
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
const emit = defineEmits
|
|
42
|
+
const emit = defineEmits<{
|
|
43
|
+
change: [value: string];
|
|
44
|
+
}>();
|
|
45
|
+
|
|
43
46
|
const { dataSourceService } = inject<Services>('services') || {};
|
|
44
47
|
|
|
45
48
|
const props = defineProps<FieldProps<CondOpSelectConfig>>();
|
|
@@ -81,7 +84,7 @@ const options = computed(() => {
|
|
|
81
84
|
return [...arrayOptions, ...eqOptions, ...numberOptions];
|
|
82
85
|
});
|
|
83
86
|
|
|
84
|
-
const fieldChangeHandler = (v: string
|
|
87
|
+
const fieldChangeHandler = (v: string) => {
|
|
85
88
|
emit('change', v);
|
|
86
89
|
};
|
|
87
90
|
</script>
|
|
@@ -51,7 +51,13 @@ import { inject, Ref, ref } from 'vue';
|
|
|
51
51
|
|
|
52
52
|
import type { DataSchema } from '@tmagic/core';
|
|
53
53
|
import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
|
|
54
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
type ContainerChangeEventData,
|
|
56
|
+
type FieldProps,
|
|
57
|
+
type FormConfig,
|
|
58
|
+
type FormState,
|
|
59
|
+
MFormBox,
|
|
60
|
+
} from '@tmagic/form';
|
|
55
61
|
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
56
62
|
import { getDefaultValueFromFields } from '@tmagic/utils';
|
|
57
63
|
|
|
@@ -75,7 +81,9 @@ const props = withDefaults(
|
|
|
75
81
|
},
|
|
76
82
|
);
|
|
77
83
|
|
|
78
|
-
const emit = defineEmits
|
|
84
|
+
const emit = defineEmits<{
|
|
85
|
+
change: [v: any, eventData?: ContainerChangeEventData];
|
|
86
|
+
}>();
|
|
79
87
|
|
|
80
88
|
const services = inject<Services>('services');
|
|
81
89
|
|
|
@@ -91,16 +99,29 @@ const newHandler = () => {
|
|
|
91
99
|
addDialogVisible.value = true;
|
|
92
100
|
};
|
|
93
101
|
|
|
94
|
-
const fieldChange = ({ index, ...value }: Record<string, any
|
|
102
|
+
const fieldChange = ({ index, ...value }: Record<string, any>, data: ContainerChangeEventData) => {
|
|
103
|
+
addDialogVisible.value = false;
|
|
104
|
+
|
|
95
105
|
if (index > -1) {
|
|
96
|
-
|
|
106
|
+
emit('change', value, {
|
|
107
|
+
modifyKey: index,
|
|
108
|
+
changeRecords: (data.changeRecords || []).map((item) => ({
|
|
109
|
+
propPath: `${props.prop}.${index}.${item.propPath}`,
|
|
110
|
+
value: item.value,
|
|
111
|
+
})),
|
|
112
|
+
});
|
|
97
113
|
} else {
|
|
98
|
-
props.model[props.name].
|
|
114
|
+
const modifyKey = props.model[props.name].length;
|
|
115
|
+
emit('change', value, {
|
|
116
|
+
modifyKey,
|
|
117
|
+
changeRecords: [
|
|
118
|
+
{
|
|
119
|
+
propPath: `${props.prop}.${modifyKey}`,
|
|
120
|
+
value,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
});
|
|
99
124
|
}
|
|
100
|
-
|
|
101
|
-
addDialogVisible.value = false;
|
|
102
|
-
|
|
103
|
-
emit('change', props.model[props.name]);
|
|
104
125
|
};
|
|
105
126
|
|
|
106
127
|
const fieldColumns: ColumnConfig[] = [
|
|
@@ -310,11 +331,9 @@ const addFromJsonFromChange = ({ data }: { data: string }) => {
|
|
|
310
331
|
try {
|
|
311
332
|
const value = JSON.parse(data);
|
|
312
333
|
|
|
313
|
-
props.model[props.name] = getFieldsConfig(value, props.model[props.name]);
|
|
314
|
-
|
|
315
334
|
addFromJsonDialogVisible.value = false;
|
|
316
335
|
|
|
317
|
-
emit('change', props.model[props.name]);
|
|
336
|
+
emit('change', getFieldsConfig(value, props.model[props.name]));
|
|
318
337
|
} catch (e: any) {
|
|
319
338
|
tMagicMessage.error(e.message);
|
|
320
339
|
}
|
|
@@ -21,14 +21,17 @@
|
|
|
21
21
|
</template>
|
|
22
22
|
|
|
23
23
|
<script setup lang="ts">
|
|
24
|
+
import { nextTick, ref } from 'vue';
|
|
25
|
+
import { cloneDeep } from 'lodash-es';
|
|
26
|
+
|
|
24
27
|
import type { CodeBlockContent } from '@tmagic/core';
|
|
25
|
-
import { TMagicButton } from '@tmagic/design';
|
|
26
|
-
import type { FieldProps } from '@tmagic/form';
|
|
28
|
+
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
|
29
|
+
import type { ContainerChangeEventData, FieldProps } from '@tmagic/form';
|
|
27
30
|
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
28
31
|
|
|
29
32
|
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
30
|
-
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
31
33
|
import type { CodeParamStatement } from '@editor/type';
|
|
34
|
+
import { getEditorConfig } from '@editor/utils/config';
|
|
32
35
|
|
|
33
36
|
defineOptions({
|
|
34
37
|
name: 'MFieldsDataSourceMethods',
|
|
@@ -47,7 +50,10 @@ const props = withDefaults(
|
|
|
47
50
|
|
|
48
51
|
const emit = defineEmits(['change']);
|
|
49
52
|
|
|
50
|
-
const
|
|
53
|
+
const codeConfig = ref<CodeBlockContent>();
|
|
54
|
+
const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
|
|
55
|
+
|
|
56
|
+
let editIndex = -1;
|
|
51
57
|
|
|
52
58
|
const methodColumns: ColumnConfig[] = [
|
|
53
59
|
{
|
|
@@ -73,16 +79,31 @@ const methodColumns: ColumnConfig[] = [
|
|
|
73
79
|
actions: [
|
|
74
80
|
{
|
|
75
81
|
text: '编辑',
|
|
76
|
-
handler: (
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
handler: (method: CodeBlockContent, index: number) => {
|
|
83
|
+
let codeContent = method.content || `({ params, dataSource, app }) => {\n // place your code here\n}`;
|
|
84
|
+
|
|
85
|
+
if (typeof codeContent !== 'string') {
|
|
86
|
+
codeContent = codeContent.toString();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
codeConfig.value = {
|
|
90
|
+
...cloneDeep(method),
|
|
91
|
+
content: codeContent,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
editIndex = index;
|
|
95
|
+
|
|
96
|
+
nextTick(() => {
|
|
97
|
+
codeBlockEditor.value?.show();
|
|
98
|
+
});
|
|
79
99
|
},
|
|
80
100
|
},
|
|
81
101
|
{
|
|
82
102
|
text: '删除',
|
|
83
103
|
buttonType: 'danger',
|
|
84
|
-
handler: (row: CodeBlockContent) => {
|
|
85
|
-
|
|
104
|
+
handler: async (row: CodeBlockContent, index: number) => {
|
|
105
|
+
await tMagicMessageBox.confirm(`确定删除${row.name}?`, '提示');
|
|
106
|
+
props.model[props.name].splice(index, 1);
|
|
86
107
|
emit('change', props.model[props.name]);
|
|
87
108
|
},
|
|
88
109
|
},
|
|
@@ -91,14 +112,51 @@ const methodColumns: ColumnConfig[] = [
|
|
|
91
112
|
];
|
|
92
113
|
|
|
93
114
|
const createCodeHandler = () => {
|
|
94
|
-
|
|
115
|
+
codeConfig.value = {
|
|
116
|
+
name: '',
|
|
117
|
+
content: `({ params, dataSource, app, flowState }) => {\n // place your code here\n}`,
|
|
118
|
+
params: [],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
editIndex = -1;
|
|
95
122
|
|
|
96
|
-
|
|
123
|
+
nextTick(() => {
|
|
124
|
+
codeBlockEditor.value?.show();
|
|
125
|
+
});
|
|
97
126
|
};
|
|
98
127
|
|
|
99
|
-
const submitCodeHandler = (
|
|
100
|
-
|
|
128
|
+
const submitCodeHandler = (value: CodeBlockContent, data: ContainerChangeEventData) => {
|
|
129
|
+
if (value.content) {
|
|
130
|
+
// 在保存的时候转换代码内容
|
|
131
|
+
const parseDSL = getEditorConfig('parseDSL');
|
|
132
|
+
if (typeof value.content === 'string') {
|
|
133
|
+
value.content = parseDSL<(...args: any[]) => any>(value.content);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (editIndex > -1) {
|
|
137
|
+
emit('change', value, {
|
|
138
|
+
modifyKey: editIndex,
|
|
139
|
+
changeRecords: (data.changeRecords || []).map((item) => ({
|
|
140
|
+
propPath: `${props.prop}.${editIndex}.${item.propPath}`,
|
|
141
|
+
value: item.value,
|
|
142
|
+
})),
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
const modifyKey = props.model[props.name].length;
|
|
146
|
+
emit('change', value, {
|
|
147
|
+
modifyKey,
|
|
148
|
+
changeRecords: [
|
|
149
|
+
{
|
|
150
|
+
propPath: `${props.prop}.${modifyKey}`,
|
|
151
|
+
value,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
editIndex = -1;
|
|
158
|
+
codeConfig.value = void 0;
|
|
101
159
|
|
|
102
|
-
|
|
160
|
+
codeBlockEditor.value?.hide();
|
|
103
161
|
};
|
|
104
162
|
</script>
|
|
@@ -17,6 +17,7 @@ import { computed, inject } from 'vue';
|
|
|
17
17
|
|
|
18
18
|
import type { DisplayCond } from '@tmagic/core';
|
|
19
19
|
import {
|
|
20
|
+
type ContainerChangeEventData,
|
|
20
21
|
type FieldProps,
|
|
21
22
|
type FilterFunction,
|
|
22
23
|
filterFunction,
|
|
@@ -33,7 +34,7 @@ defineOptions({
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
const emit = defineEmits<{
|
|
36
|
-
change: [value: DisplayCond[]];
|
|
37
|
+
change: [value: DisplayCond[], eventData?: ContainerChangeEventData];
|
|
37
38
|
}>();
|
|
38
39
|
|
|
39
40
|
const props = withDefaults(
|
|
@@ -149,7 +150,11 @@ const config = computed<GroupListConfig>(() => ({
|
|
|
149
150
|
],
|
|
150
151
|
}));
|
|
151
152
|
|
|
152
|
-
const changeHandler = (v: DisplayCond[]) => {
|
|
153
|
-
|
|
153
|
+
const changeHandler = (v: DisplayCond[], eventData?: ContainerChangeEventData) => {
|
|
154
|
+
if (!Array.isArray(props.model[props.name])) {
|
|
155
|
+
props.model[props.name] = [];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
emit('change', v, eventData);
|
|
154
159
|
};
|
|
155
160
|
</script>
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
:key="index"
|
|
21
21
|
:disabled="disabled"
|
|
22
22
|
:size="size"
|
|
23
|
+
:prop="`${prop}.${index}`"
|
|
23
24
|
:config="actionsConfig"
|
|
24
25
|
:model="cardItem"
|
|
25
26
|
:label-width="config.labelWidth || '100px'"
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
:model="cardItem"
|
|
33
34
|
:disabled="disabled"
|
|
34
35
|
:size="size"
|
|
35
|
-
|
|
36
|
+
:prop="`${prop}.${index}`"
|
|
37
|
+
@change="eventNameChangeHandler"
|
|
36
38
|
></MFormContainer>
|
|
37
39
|
<TMagicButton
|
|
38
40
|
style="color: #f56c6c"
|
|
@@ -56,12 +58,19 @@ import { has } from 'lodash-es';
|
|
|
56
58
|
import type { EventOption, MComponent, MContainer } from '@tmagic/core';
|
|
57
59
|
import { ActionType } from '@tmagic/core';
|
|
58
60
|
import { TMagicButton } from '@tmagic/design';
|
|
59
|
-
import type {
|
|
61
|
+
import type {
|
|
62
|
+
CascaderOption,
|
|
63
|
+
ChildConfig,
|
|
64
|
+
ContainerChangeEventData,
|
|
65
|
+
FieldProps,
|
|
66
|
+
FormState,
|
|
67
|
+
PanelConfig,
|
|
68
|
+
} from '@tmagic/form';
|
|
60
69
|
import { MContainer as MFormContainer, MPanel } from '@tmagic/form';
|
|
61
|
-
import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX } from '@tmagic/utils';
|
|
70
|
+
import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, traverseNode } from '@tmagic/utils';
|
|
62
71
|
|
|
63
72
|
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
|
64
|
-
import { getCascaderOptionsFromFields
|
|
73
|
+
import { getCascaderOptionsFromFields } from '@editor/utils';
|
|
65
74
|
|
|
66
75
|
defineOptions({
|
|
67
76
|
name: 'MFieldsEventSelect',
|
|
@@ -69,7 +78,9 @@ defineOptions({
|
|
|
69
78
|
|
|
70
79
|
const props = defineProps<FieldProps<EventSelectConfig>>();
|
|
71
80
|
|
|
72
|
-
const emit = defineEmits
|
|
81
|
+
const emit = defineEmits<{
|
|
82
|
+
change: [v: any, eventData?: ContainerChangeEventData];
|
|
83
|
+
}>();
|
|
73
84
|
|
|
74
85
|
const services = inject<Services>('services');
|
|
75
86
|
|
|
@@ -108,7 +119,7 @@ const eventNameConfig = computed(() => {
|
|
|
108
119
|
if (pageFragment) {
|
|
109
120
|
events = [
|
|
110
121
|
{
|
|
111
|
-
label: pageFragment.name || '
|
|
122
|
+
label: pageFragment.name || '页面片容器',
|
|
112
123
|
value: pageFragment.id,
|
|
113
124
|
children: events,
|
|
114
125
|
},
|
|
@@ -355,21 +366,27 @@ const addEvent = () => {
|
|
|
355
366
|
name: '',
|
|
356
367
|
actions: [],
|
|
357
368
|
};
|
|
369
|
+
|
|
358
370
|
if (!props.model[props.name]) {
|
|
359
371
|
props.model[props.name] = [];
|
|
360
372
|
}
|
|
361
|
-
|
|
362
|
-
|
|
373
|
+
|
|
374
|
+
emit('change', defaultEvent, {
|
|
375
|
+
modifyKey: props.model[props.name].length,
|
|
376
|
+
});
|
|
363
377
|
};
|
|
364
378
|
|
|
365
379
|
// 删除事件
|
|
366
380
|
const removeEvent = (index: number) => {
|
|
367
381
|
if (!props.name) return;
|
|
368
382
|
props.model[props.name].splice(index, 1);
|
|
369
|
-
|
|
383
|
+
emit('change', props.model[props.name]);
|
|
370
384
|
};
|
|
371
385
|
|
|
372
|
-
const
|
|
373
|
-
emit('change', props.model);
|
|
386
|
+
const eventNameChangeHandler = (v: any, eventData: ContainerChangeEventData) => {
|
|
387
|
+
emit('change', props.model[props.name], eventData);
|
|
374
388
|
};
|
|
389
|
+
|
|
390
|
+
const onChangeHandler = (v: any, eventData: ContainerChangeEventData) =>
|
|
391
|
+
emit('change', props.model[props.name], eventData);
|
|
375
392
|
</script>
|