@tmagic/editor 1.3.0-alpha.13 → 1.3.0-alpha.14
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 +41 -113
- package/dist/tmagic-editor.js +1307 -1197
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1318 -1204
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +11 -11
- package/src/Editor.vue +0 -4
- package/src/components/CodeBlockEditor.vue +155 -0
- package/src/components/CodeParams.vue +59 -0
- package/src/fields/Code.vue +27 -19
- package/src/fields/CodeSelect.vue +7 -1
- package/src/fields/CodeSelectCol.vue +65 -74
- package/src/fields/DataSourceFields.vue +7 -9
- package/src/fields/DataSourceMethodSelect.vue +147 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/EventSelect.vue +33 -7
- package/src/icons/CodeIcon.vue +0 -2
- package/src/index.ts +8 -0
- package/src/layouts/CodeEditor.vue +32 -1
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/sidebar/Sidebar.vue +2 -10
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +73 -124
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +23 -33
- package/src/layouts/sidebar/data-source/DataSourceList.vue +111 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +13 -81
- package/src/services/codeBlock.ts +17 -70
- package/src/services/dataSource.ts +2 -0
- package/src/theme/code-block.scss +0 -122
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +21 -6
- package/src/utils/data-source/index.ts +11 -0
- package/src/utils/use-code-block-edit.ts +84 -0
- package/src/utils/use-data-source-method.ts +101 -0
- package/types/components/CodeBlockEditor.vue.d.ts +21 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/fields/Code.vue.d.ts +26 -6
- package/types/fields/CodeSelectCol.vue.d.ts +16 -5
- package/types/fields/DataSourceFields.vue.d.ts +2 -0
- package/types/fields/DataSourceMethodSelect.vue.d.ts +44 -0
- package/types/fields/DataSourceMethods.vue.d.ts +45 -0
- package/types/index.d.ts +4 -0
- package/types/layouts/CodeEditor.vue.d.ts +2 -0
- package/types/layouts/PropsPanel.vue.d.ts +8 -8
- package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -3
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +4 -9
- package/types/layouts/sidebar/code-block/{CodeBlockEditor.vue.d.ts → CodeBlockListPanel.vue.d.ts} +5 -6
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -1
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
- package/types/services/codeBlock.d.ts +5 -36
- package/types/services/dataSource.d.ts +1 -0
- package/types/type.d.ts +19 -6
- package/types/{components/FunctionEditor.vue.d.ts → utils/use-code-block-edit.d.ts} +26 -123
- package/types/utils/use-data-source-method.d.ts +116 -0
- package/src/components/CodeDraftEditor.vue +0 -148
- package/src/components/FunctionEditor.vue +0 -197
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -100
- package/types/components/CodeDraftEditor.vue.d.ts +0 -61
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-alpha.
|
|
2
|
+
"version": "1.3.0-alpha.14",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/core": "^7.18.0",
|
|
48
48
|
"@element-plus/icons-vue": "^2.0.9",
|
|
49
|
-
"@tmagic/core": "1.3.0-alpha.
|
|
50
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
51
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
52
|
-
"@tmagic/schema": "1.3.0-alpha.
|
|
53
|
-
"@tmagic/stage": "1.3.0-alpha.
|
|
54
|
-
"@tmagic/table": "1.3.0-alpha.
|
|
55
|
-
"@tmagic/utils": "1.3.0-alpha.
|
|
49
|
+
"@tmagic/core": "1.3.0-alpha.14",
|
|
50
|
+
"@tmagic/design": "1.3.0-alpha.14",
|
|
51
|
+
"@tmagic/form": "1.3.0-alpha.14",
|
|
52
|
+
"@tmagic/schema": "1.3.0-alpha.14",
|
|
53
|
+
"@tmagic/stage": "1.3.0-alpha.14",
|
|
54
|
+
"@tmagic/table": "1.3.0-alpha.14",
|
|
55
|
+
"@tmagic/utils": "1.3.0-alpha.14",
|
|
56
56
|
"buffer": "^6.0.3",
|
|
57
57
|
"color": "^3.1.3",
|
|
58
58
|
"events": "^3.3.0",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"vue": "^3.3.4"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@tmagic/design": "1.3.0-alpha.
|
|
68
|
-
"@tmagic/form": "1.3.0-alpha.
|
|
67
|
+
"@tmagic/design": "1.3.0-alpha.14",
|
|
68
|
+
"@tmagic/form": "1.3.0-alpha.14",
|
|
69
69
|
"monaco-editor": "^0.39.0",
|
|
70
70
|
"vue": "^3.3.4"
|
|
71
71
|
},
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"sass": "^1.35.1",
|
|
82
82
|
"tsc-alias": "^1.8.5",
|
|
83
83
|
"typescript": "^5.0.4",
|
|
84
|
-
"vite": "^4.
|
|
84
|
+
"vite": "^4.4.4",
|
|
85
85
|
"vue-tsc": "^1.6.5"
|
|
86
86
|
}
|
|
87
87
|
}
|
package/src/Editor.vue
CHANGED
|
@@ -40,10 +40,6 @@
|
|
|
40
40
|
<template #code-block-panel-tool="{ id, data }">
|
|
41
41
|
<slot name="code-block-panel-tool" :id="id" :data="data"></slot>
|
|
42
42
|
</template>
|
|
43
|
-
|
|
44
|
-
<template #code-block-edit-panel-header="{ id }">
|
|
45
|
-
<slot name="code-block-edit-panel-header" :id="id"></slot>
|
|
46
|
-
</template>
|
|
47
43
|
</Sidebar>
|
|
48
44
|
</slot>
|
|
49
45
|
</template>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MFormDrawer
|
|
3
|
+
ref="fomDrawer"
|
|
4
|
+
label-width="80px"
|
|
5
|
+
:title="content.name"
|
|
6
|
+
:width="size"
|
|
7
|
+
:config="functionConfig"
|
|
8
|
+
:values="content"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
@submit="submitForm"
|
|
11
|
+
@error="errorHandler"
|
|
12
|
+
@open="openHandler"
|
|
13
|
+
></MFormDrawer>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script lang="ts" setup>
|
|
17
|
+
import { computed, inject, ref } from 'vue';
|
|
18
|
+
|
|
19
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
20
|
+
import { ColumnConfig, FormState, MFormDrawer } from '@tmagic/form';
|
|
21
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
22
|
+
|
|
23
|
+
import type { Services } from '@editor/type';
|
|
24
|
+
import { getConfig } from '@editor/utils/config';
|
|
25
|
+
|
|
26
|
+
defineOptions({
|
|
27
|
+
name: 'MEditorCodeBlockEditor',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
defineProps<{
|
|
31
|
+
content: CodeBlockContent;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
const emit = defineEmits<{
|
|
36
|
+
submit: [values: CodeBlockContent];
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const services = inject<Services>('services');
|
|
40
|
+
|
|
41
|
+
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
|
42
|
+
const size = computed(() => (columnWidth.value ? columnWidth.value.center + columnWidth.value.right : 600));
|
|
43
|
+
|
|
44
|
+
const codeEditorHeight = ref('600px');
|
|
45
|
+
|
|
46
|
+
const defaultParamColConfig: ColumnConfig = {
|
|
47
|
+
type: 'row',
|
|
48
|
+
label: '参数类型',
|
|
49
|
+
items: [
|
|
50
|
+
{
|
|
51
|
+
text: '参数类型',
|
|
52
|
+
labelWidth: '70px',
|
|
53
|
+
type: 'select',
|
|
54
|
+
name: 'type',
|
|
55
|
+
options: [
|
|
56
|
+
{
|
|
57
|
+
text: '数字',
|
|
58
|
+
label: '数字',
|
|
59
|
+
value: 'number',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
text: '字符串',
|
|
63
|
+
label: '字符串',
|
|
64
|
+
value: 'text',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: '组件',
|
|
68
|
+
label: '组件',
|
|
69
|
+
value: 'ui-select',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const functionConfig = computed(() => [
|
|
77
|
+
{
|
|
78
|
+
text: '名称',
|
|
79
|
+
name: 'name',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
text: '注释',
|
|
83
|
+
name: 'desc',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'table',
|
|
87
|
+
border: true,
|
|
88
|
+
text: '参数',
|
|
89
|
+
enableFullscreen: false,
|
|
90
|
+
name: 'params',
|
|
91
|
+
maxHeight: '300px',
|
|
92
|
+
dropSort: false,
|
|
93
|
+
items: [
|
|
94
|
+
{
|
|
95
|
+
type: 'text',
|
|
96
|
+
label: '参数名',
|
|
97
|
+
name: 'name',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'text',
|
|
101
|
+
label: '注释',
|
|
102
|
+
name: 'extra',
|
|
103
|
+
},
|
|
104
|
+
services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'content',
|
|
109
|
+
type: 'vs-code',
|
|
110
|
+
options: inject('codeOptions', {}),
|
|
111
|
+
height: codeEditorHeight.value,
|
|
112
|
+
onChange: (formState: FormState | undefined, code: string) => {
|
|
113
|
+
try {
|
|
114
|
+
// 检测js代码是否存在语法错误
|
|
115
|
+
getConfig('parseDSL')(code);
|
|
116
|
+
|
|
117
|
+
return code;
|
|
118
|
+
} catch (error: any) {
|
|
119
|
+
tMagicMessage.error(error.message);
|
|
120
|
+
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
const submitForm = async (values: CodeBlockContent) => {
|
|
128
|
+
emit('submit', values);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const errorHandler = (error: any) => {
|
|
132
|
+
tMagicMessage.error(error.message);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
|
136
|
+
|
|
137
|
+
const openHandler = () => {
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
if (fomDrawer.value) {
|
|
140
|
+
const height = fomDrawer.value?.bodyHeight - 468;
|
|
141
|
+
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
defineExpose({
|
|
147
|
+
show() {
|
|
148
|
+
fomDrawer.value?.show();
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
hide() {
|
|
152
|
+
fomDrawer.value?.hide();
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
</script>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<MForm
|
|
3
|
+
ref="form"
|
|
4
|
+
:config="codeParamsConfig"
|
|
5
|
+
:init-values="model"
|
|
6
|
+
:disabled="disabled"
|
|
7
|
+
:size="size"
|
|
8
|
+
:watch-props="false"
|
|
9
|
+
@change="onParamsChangeHandler"
|
|
10
|
+
></MForm>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts" setup>
|
|
14
|
+
import { computed, ref } from 'vue';
|
|
15
|
+
|
|
16
|
+
import { FormConfig, MForm } from '@tmagic/form';
|
|
17
|
+
|
|
18
|
+
import type { CodeParamStatement } from '@editor/type';
|
|
19
|
+
|
|
20
|
+
defineOptions({
|
|
21
|
+
name: 'MEditorCodeParams',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
model: any;
|
|
26
|
+
size?: 'small' | 'default' | 'large';
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
name: string;
|
|
29
|
+
paramsConfig: CodeParamStatement[];
|
|
30
|
+
}>();
|
|
31
|
+
|
|
32
|
+
const emit = defineEmits(['change']);
|
|
33
|
+
|
|
34
|
+
const form = ref<InstanceType<typeof MForm>>();
|
|
35
|
+
|
|
36
|
+
const getFormConfig = (items: FormConfig = []) => [
|
|
37
|
+
{
|
|
38
|
+
type: 'fieldset',
|
|
39
|
+
items,
|
|
40
|
+
legend: '参数',
|
|
41
|
+
labelWidth: '70px',
|
|
42
|
+
name: props.name,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const codeParamsConfig = computed(() => getFormConfig(props.paramsConfig));
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 参数值修改更新
|
|
50
|
+
*/
|
|
51
|
+
const onParamsChangeHandler = async () => {
|
|
52
|
+
try {
|
|
53
|
+
const value = await form.value?.submitForm(true);
|
|
54
|
+
emit('change', value);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.log(e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
</script>
|
package/src/fields/Code.vue
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
:
|
|
2
|
+
<MagicCodeEditor
|
|
3
|
+
:height="config.height"
|
|
4
4
|
:init-values="model[name]"
|
|
5
|
-
:language="language"
|
|
6
|
-
:options="
|
|
5
|
+
:language="config.language"
|
|
6
|
+
:options="{
|
|
7
|
+
...config.options,
|
|
8
|
+
readOnly: disabled,
|
|
9
|
+
}"
|
|
7
10
|
@save="save"
|
|
8
|
-
></
|
|
11
|
+
></MagicCodeEditor>
|
|
9
12
|
</template>
|
|
10
13
|
|
|
11
14
|
<script lang="ts" setup>
|
|
12
|
-
import
|
|
15
|
+
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
13
16
|
|
|
14
17
|
defineOptions({
|
|
15
18
|
name: 'MEditorCode',
|
|
@@ -17,19 +20,24 @@ defineOptions({
|
|
|
17
20
|
|
|
18
21
|
const emit = defineEmits(['change']);
|
|
19
22
|
|
|
20
|
-
const props =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const props = withDefaults(
|
|
24
|
+
defineProps<{
|
|
25
|
+
config: {
|
|
26
|
+
language?: string;
|
|
27
|
+
options?: Object;
|
|
28
|
+
height?: string;
|
|
29
|
+
};
|
|
30
|
+
model: any;
|
|
31
|
+
name: string;
|
|
32
|
+
prop: string;
|
|
33
|
+
lastValues?: any;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
size?: 'small' | 'default' | 'large';
|
|
36
|
+
}>(),
|
|
37
|
+
{
|
|
38
|
+
disabled: false,
|
|
39
|
+
},
|
|
40
|
+
);
|
|
33
41
|
|
|
34
42
|
const save = (v: string) => {
|
|
35
43
|
props.model[props.name] = v;
|
|
@@ -7,18 +7,22 @@
|
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts" setup>
|
|
10
|
-
import { computed, watch } from 'vue';
|
|
10
|
+
import { computed, inject, watch } from 'vue';
|
|
11
11
|
import { isEmpty } from 'lodash-es';
|
|
12
12
|
|
|
13
13
|
import { TMagicCard } from '@tmagic/design';
|
|
14
14
|
import { HookType } from '@tmagic/schema';
|
|
15
15
|
|
|
16
|
+
import type { Services } from '@editor/type';
|
|
17
|
+
|
|
16
18
|
defineOptions({
|
|
17
19
|
name: 'MEditorCodeSelect',
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
const emit = defineEmits(['change']);
|
|
21
23
|
|
|
24
|
+
const services = inject<Services>('services');
|
|
25
|
+
|
|
22
26
|
const props = withDefaults(
|
|
23
27
|
defineProps<{
|
|
24
28
|
config: {
|
|
@@ -41,7 +45,9 @@ const codeConfig = computed(() => ({
|
|
|
41
45
|
items: [
|
|
42
46
|
{
|
|
43
47
|
type: 'code-select-col',
|
|
48
|
+
name: 'codeId',
|
|
44
49
|
labelWidth: 0,
|
|
50
|
+
disabled: () => !services?.codeBlockService.getEditStatus(),
|
|
45
51
|
},
|
|
46
52
|
],
|
|
47
53
|
}));
|
|
@@ -9,57 +9,91 @@
|
|
|
9
9
|
@change="onParamsChangeHandler"
|
|
10
10
|
></m-form-container>
|
|
11
11
|
<!-- 查看/编辑按钮 -->
|
|
12
|
-
<Icon class="icon" :icon="
|
|
12
|
+
<Icon v-if="model[name]" class="icon" :icon="!disabled ? Edit : View" @click="editCode(model[name])"></Icon>
|
|
13
13
|
</div>
|
|
14
|
+
|
|
14
15
|
<!-- 参数填写框 -->
|
|
15
|
-
<
|
|
16
|
+
<CodeParams
|
|
17
|
+
v-if="paramsConfig.length"
|
|
18
|
+
name="params"
|
|
19
|
+
:model="model"
|
|
20
|
+
:size="size"
|
|
21
|
+
:params-config="paramsConfig"
|
|
22
|
+
@change="onParamsChangeHandler"
|
|
23
|
+
></CodeParams>
|
|
24
|
+
|
|
25
|
+
<CodeBlockEditor
|
|
26
|
+
ref="codeBlockEditor"
|
|
27
|
+
v-if="codeConfig"
|
|
28
|
+
:disabled="disabled"
|
|
29
|
+
:content="codeConfig"
|
|
30
|
+
@submit="submitCodeBlockHandler"
|
|
31
|
+
></CodeBlockEditor>
|
|
16
32
|
</div>
|
|
17
33
|
</template>
|
|
18
34
|
|
|
19
35
|
<script lang="ts" setup name="">
|
|
20
|
-
import { computed, inject, ref
|
|
36
|
+
import { computed, inject, ref } from 'vue';
|
|
21
37
|
import { Edit, View } from '@element-plus/icons-vue';
|
|
22
38
|
import { isEmpty, map } from 'lodash-es';
|
|
23
39
|
|
|
24
|
-
import { createValues
|
|
25
|
-
import { Id } from '@tmagic/schema';
|
|
40
|
+
import { createValues } from '@tmagic/form';
|
|
41
|
+
import type { Id } from '@tmagic/schema';
|
|
26
42
|
|
|
43
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
44
|
+
import CodeParams from '@editor/components/CodeParams.vue';
|
|
27
45
|
import Icon from '@editor/components/Icon.vue';
|
|
28
|
-
import type { CodeParamStatement, Services } from '@editor/type';
|
|
46
|
+
import type { CodeParamStatement, CodeSelectColConfig, Services } from '@editor/type';
|
|
47
|
+
import { useCodeBlockEdit } from '@editor/utils/use-code-block-edit';
|
|
29
48
|
|
|
30
49
|
defineOptions({
|
|
31
50
|
name: 'MEditorCodeSelectCol',
|
|
32
51
|
});
|
|
33
52
|
|
|
34
53
|
const services = inject<Services>('services');
|
|
35
|
-
const mForm = inject<FormState>('mForm');
|
|
36
54
|
const emit = defineEmits(['change']);
|
|
37
55
|
|
|
38
56
|
const props = withDefaults(
|
|
39
57
|
defineProps<{
|
|
40
|
-
config:
|
|
58
|
+
config: CodeSelectColConfig;
|
|
41
59
|
model: any;
|
|
42
60
|
prop: string;
|
|
43
61
|
name: string;
|
|
62
|
+
lastValues?: any;
|
|
63
|
+
disabled?: boolean;
|
|
44
64
|
size: 'small' | 'default' | 'large';
|
|
45
65
|
}>(),
|
|
46
|
-
{
|
|
66
|
+
{
|
|
67
|
+
disabled: false,
|
|
68
|
+
},
|
|
47
69
|
);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 根据代码块id获取代码块参数配置
|
|
73
|
+
* @param codeId 代码块ID
|
|
74
|
+
*/
|
|
75
|
+
const getParamItemsConfig = (codeId?: Id): CodeParamStatement[] => {
|
|
76
|
+
if (!codeDsl.value || !codeId) return [];
|
|
77
|
+
|
|
78
|
+
const paramStatements = codeDsl.value[codeId]?.params;
|
|
79
|
+
|
|
80
|
+
if (isEmpty(paramStatements)) return [];
|
|
81
|
+
|
|
82
|
+
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
83
|
+
labelWidth: '100px',
|
|
84
|
+
text: paramState.name,
|
|
85
|
+
...paramState,
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
|
|
48
89
|
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
type: 'fieldset',
|
|
52
|
-
items: [],
|
|
53
|
-
legend: '参数',
|
|
54
|
-
labelWidth: '70px',
|
|
55
|
-
name: 'params',
|
|
56
|
-
display: false,
|
|
57
|
-
});
|
|
90
|
+
const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model[props.name]));
|
|
91
|
+
|
|
58
92
|
const selectConfig = {
|
|
59
93
|
type: 'select',
|
|
60
94
|
text: '代码块',
|
|
61
|
-
name:
|
|
62
|
-
labelWidth: '
|
|
95
|
+
name: props.name,
|
|
96
|
+
labelWidth: '80px',
|
|
63
97
|
options: () => {
|
|
64
98
|
if (codeDsl.value) {
|
|
65
99
|
return map(codeDsl.value, (value, key) => ({
|
|
@@ -72,68 +106,25 @@ const selectConfig = {
|
|
|
72
106
|
},
|
|
73
107
|
onChange: (formState: any, codeId: Id, { model }: any) => {
|
|
74
108
|
// 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
};
|
|
109
|
+
paramsConfig.value = getParamItemsConfig(codeId);
|
|
78
110
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!codeDsl.value) return [];
|
|
85
|
-
const paramStatements = codeDsl.value[codeId]?.params;
|
|
86
|
-
if (isEmpty(paramStatements)) return [];
|
|
87
|
-
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
88
|
-
labelWidth: '100px',
|
|
89
|
-
text: paramState.name,
|
|
90
|
-
...paramState,
|
|
91
|
-
}));
|
|
92
|
-
};
|
|
111
|
+
if (paramsConfig.value.length) {
|
|
112
|
+
model.params = createValues(formState, paramsConfig.value, {}, model.params);
|
|
113
|
+
} else {
|
|
114
|
+
model.params = {};
|
|
115
|
+
}
|
|
93
116
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* @param codeId 代码块ID
|
|
97
|
-
*/
|
|
98
|
-
const getCodeParamsConfig = (codeId: Id) => {
|
|
99
|
-
const paramsConfig = getParamItemsConfig(codeId);
|
|
100
|
-
// 如果参数没有填值,则使用createValues补全空值
|
|
101
|
-
if (!props.model.params || isEmpty(props.model.params)) {
|
|
102
|
-
props.model.params = {};
|
|
103
|
-
createValues(mForm, paramsConfig, {}, props.model.params);
|
|
104
|
-
}
|
|
105
|
-
codeParamsConfig.value = {
|
|
106
|
-
type: 'fieldset',
|
|
107
|
-
items: paramsConfig,
|
|
108
|
-
legend: '参数',
|
|
109
|
-
labelWidth: '70px',
|
|
110
|
-
name: 'params',
|
|
111
|
-
display: !isEmpty(paramsConfig),
|
|
112
|
-
};
|
|
117
|
+
return codeId;
|
|
118
|
+
},
|
|
113
119
|
};
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
122
|
* 参数值修改更新
|
|
117
123
|
*/
|
|
118
|
-
const onParamsChangeHandler = () => {
|
|
124
|
+
const onParamsChangeHandler = (value: any) => {
|
|
125
|
+
props.model.params = value.params;
|
|
119
126
|
emit('change', props.model);
|
|
120
127
|
};
|
|
121
128
|
|
|
122
|
-
|
|
123
|
-
// TODO onchange在watch之前触发
|
|
124
|
-
watch(
|
|
125
|
-
() => props.model.codeId,
|
|
126
|
-
(codeId: Id) => {
|
|
127
|
-
if (!codeId) return;
|
|
128
|
-
getCodeParamsConfig(codeId);
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
immediate: true,
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
// 打开代码编辑框
|
|
136
|
-
const editCode = () => {
|
|
137
|
-
services?.codeBlockService.setCodeEditorContent(true, props.model.codeId);
|
|
138
|
-
};
|
|
129
|
+
const { codeBlockEditor, codeConfig, editCode, submitCodeBlockHandler } = useCodeBlockEdit(services?.codeBlockService);
|
|
139
130
|
</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-editor-data-source-fields">
|
|
3
|
-
<MagicTable :data="model[name]" :columns="
|
|
3
|
+
<MagicTable :data="model[name]" :columns="fieldColumns"></MagicTable>
|
|
4
4
|
|
|
5
5
|
<div class="m-editor-data-source-fields-footer">
|
|
6
6
|
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
:config="dataSourceFieldsConfig"
|
|
13
13
|
:values="fieldValues"
|
|
14
14
|
:parentValues="model[name]"
|
|
15
|
+
:disabled="disabled"
|
|
15
16
|
@submit="fieldChange"
|
|
16
17
|
></MFormDialog>
|
|
17
18
|
</div>
|
|
@@ -35,6 +36,7 @@ const props = withDefaults(
|
|
|
35
36
|
};
|
|
36
37
|
model: any;
|
|
37
38
|
prop: string;
|
|
39
|
+
lastValues?: any;
|
|
38
40
|
disabled: boolean;
|
|
39
41
|
name: string;
|
|
40
42
|
}>(),
|
|
@@ -50,27 +52,24 @@ const fieldValues = ref<Record<string, any>>({});
|
|
|
50
52
|
const filedTitle = ref('');
|
|
51
53
|
|
|
52
54
|
const newHandler = () => {
|
|
53
|
-
if (!addDialog.value) return;
|
|
54
55
|
fieldValues.value = {};
|
|
55
56
|
filedTitle.value = '新增属性';
|
|
56
|
-
addDialog.value
|
|
57
|
+
addDialog.value?.show();
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
const fieldChange = ({ index, ...value }: Record<string, any>) => {
|
|
60
|
-
if (!addDialog.value) return;
|
|
61
|
-
|
|
62
61
|
if (index > -1) {
|
|
63
62
|
props.model[props.name][index] = value;
|
|
64
63
|
} else {
|
|
65
64
|
props.model[props.name].push(value);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
addDialog.value
|
|
67
|
+
addDialog.value?.hide();
|
|
69
68
|
|
|
70
69
|
emit('change', props.model[props.name]);
|
|
71
70
|
};
|
|
72
71
|
|
|
73
|
-
const
|
|
72
|
+
const fieldColumns = [
|
|
74
73
|
{
|
|
75
74
|
label: '属性名称',
|
|
76
75
|
prop: 'title',
|
|
@@ -90,13 +89,12 @@ const filedColumns = [
|
|
|
90
89
|
{
|
|
91
90
|
text: '编辑',
|
|
92
91
|
handler: (row: Record<string, any>, index: number) => {
|
|
93
|
-
if (!addDialog.value) return;
|
|
94
92
|
fieldValues.value = {
|
|
95
93
|
...row,
|
|
96
94
|
index,
|
|
97
95
|
};
|
|
98
96
|
filedTitle.value = `编辑${row.title}`;
|
|
99
|
-
addDialog.value
|
|
97
|
+
addDialog.value?.show();
|
|
100
98
|
},
|
|
101
99
|
},
|
|
102
100
|
{
|