@tmagic/editor 1.3.0-alpha.9 → 1.3.0-beta.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 +77 -218
- package/dist/tmagic-editor.js +4143 -3302
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +5289 -4434
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +15 -15
- package/src/Editor.vue +4 -5
- package/src/components/CodeBlockEditor.vue +257 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +11 -3
- package/src/editorProps.ts +30 -5
- package/src/fields/Code.vue +23 -19
- package/src/fields/CodeLink.vue +6 -7
- package/src/fields/CodeSelect.vue +12 -9
- package/src/fields/CodeSelectCol.vue +70 -81
- package/src/fields/DataSourceFieldSelect.vue +47 -0
- package/src/fields/DataSourceFields.vue +28 -22
- package/src/fields/DataSourceInput.vue +21 -58
- package/src/fields/DataSourceMethodSelect.vue +136 -0
- package/src/fields/DataSourceMethods.vue +103 -0
- package/src/fields/DataSourceSelect.vue +5 -12
- package/src/fields/EventSelect.vue +53 -19
- package/src/fields/KeyValue.vue +9 -11
- package/src/fields/UISelect.vue +54 -14
- package/src/hooks/index.ts +21 -0
- package/src/hooks/use-code-block-edit.ts +84 -0
- package/src/hooks/use-data-source-method.ts +100 -0
- package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +0 -2
- package/src/icons/FolderMinusIcon.vue +22 -0
- package/src/index.ts +12 -0
- package/src/initService.ts +69 -16
- package/src/layouts/CodeEditor.vue +35 -3
- package/src/layouts/Framework.vue +7 -3
- package/src/layouts/PropsPanel.vue +8 -3
- package/src/layouts/sidebar/ComponentListPanel.vue +4 -6
- package/src/layouts/sidebar/LayerMenu.vue +20 -21
- package/src/layouts/sidebar/LayerPanel.vue +12 -2
- package/src/layouts/sidebar/Sidebar.vue +22 -36
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +81 -119
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +64 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +27 -47
- package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +58 -85
- package/src/layouts/workspace/Stage.vue +3 -2
- package/src/layouts/workspace/ViewerMenu.vue +10 -35
- package/src/services/codeBlock.ts +18 -71
- package/src/services/dataSource.ts +16 -1
- package/src/services/dep.ts +22 -20
- package/src/services/editor.ts +46 -18
- package/src/services/props.ts +2 -2
- package/src/theme/code-block.scss +5 -117
- package/src/theme/code-editor.scss +27 -2
- package/src/theme/content-menu.scss +1 -1
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/data-source.scss +11 -0
- package/src/theme/event.scss +15 -12
- package/src/theme/framework.scss +0 -3
- package/src/theme/layout.scss +4 -0
- package/src/theme/sidebar.scss +18 -60
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +47 -7
- package/src/utils/content-menu.ts +92 -0
- package/src/utils/data-source/formConfigs/base.ts +28 -30
- package/src/utils/data-source/index.ts +65 -2
- package/src/utils/dep.ts +33 -7
- package/src/utils/index.ts +1 -1
- package/src/utils/props.ts +298 -189
- package/src/utils/undo-redo.ts +1 -1
- package/types/Editor.vue.d.ts +30 -6
- package/types/components/CodeBlockEditor.vue.d.ts +23 -0
- package/types/components/CodeParams.vue.d.ts +26 -0
- package/types/components/ContentMenu.vue.d.ts +2 -2
- package/types/components/ToolButton.vue.d.ts +3 -3
- package/types/editorProps.d.ts +19 -5
- package/types/fields/Code.vue.d.ts +24 -19
- package/types/fields/CodeLink.vue.d.ts +12 -21
- package/types/fields/CodeSelect.vue.d.ts +6 -17
- package/types/fields/CodeSelectCol.vue.d.ts +10 -14
- package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceFields.vue.d.ts +7 -18
- package/types/fields/DataSourceInput.vue.d.ts +10 -30
- package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
- package/types/fields/DataSourceMethods.vue.d.ts +32 -0
- package/types/fields/DataSourceSelect.vue.d.ts +13 -29
- package/types/fields/EventSelect.vue.d.ts +2 -13
- package/types/fields/KeyValue.vue.d.ts +9 -24
- package/types/fields/UISelect.vue.d.ts +2 -11
- package/types/hooks/index.d.ts +3 -0
- package/types/{components/FunctionEditor.vue.d.ts → hooks/use-code-block-edit.d.ts} +31 -121
- package/types/hooks/use-data-source-method.d.ts +123 -0
- package/types/icons/CenterIcon.vue.d.ts +2 -0
- package/types/icons/FolderMinusIcon.vue.d.ts +2 -0
- package/types/index.d.ts +6 -0
- package/types/initService.d.ts +2 -2
- package/types/layouts/CodeEditor.vue.d.ts +7 -4
- package/types/layouts/PropsPanel.vue.d.ts +274 -2
- 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} +9 -5
- 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 +6 -37
- package/types/services/dataSource.d.ts +7 -1
- package/types/services/dep.d.ts +12 -21
- package/types/services/editor.d.ts +1 -1
- package/types/services/props.d.ts +10 -115
- package/types/type.d.ts +42 -7
- package/types/utils/content-menu.d.ts +7 -0
- package/types/utils/data-source/formConfigs/base.d.ts +1 -2
- package/types/utils/data-source/index.d.ts +5 -0
- package/types/utils/dep.d.ts +4 -2
- package/types/utils/index.d.ts +1 -1
- package/types/utils/props.d.ts +13 -102
- 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/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
|
@@ -1,75 +1,56 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
:data="
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<div class="
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
<TMagicTooltip effect="dark" :content="editable ? '编辑' : '查看'" placement="bottom">
|
|
37
|
-
<Icon :icon="editable ? Edit : View" class="edit-icon" @click.stop="editCode(`${data.id}`)"></Icon>
|
|
38
|
-
</TMagicTooltip>
|
|
39
|
-
<TMagicTooltip effect="dark" content="删除" placement="bottom" v-if="editable">
|
|
40
|
-
<Icon :icon="Close" class="edit-icon" @click.stop="deleteCode(`${data.id}`)"></Icon>
|
|
41
|
-
</TMagicTooltip>
|
|
42
|
-
<slot name="code-block-panel-tool" :id="data.id" :data="data.codeBlockContent"></slot>
|
|
43
|
-
</div>
|
|
2
|
+
<TMagicTree
|
|
3
|
+
ref="tree"
|
|
4
|
+
class="magic-editor-layer-tree"
|
|
5
|
+
node-key="id"
|
|
6
|
+
empty-text="暂无代码块"
|
|
7
|
+
:default-expanded-keys="expandedKeys"
|
|
8
|
+
:expand-on-click-node="false"
|
|
9
|
+
:data="codeList"
|
|
10
|
+
:props="{
|
|
11
|
+
children: 'children',
|
|
12
|
+
label: 'name',
|
|
13
|
+
value: 'id',
|
|
14
|
+
}"
|
|
15
|
+
:highlight-current="true"
|
|
16
|
+
:filter-node-method="filterNode"
|
|
17
|
+
@node-click="clickHandler"
|
|
18
|
+
>
|
|
19
|
+
<template #default="{ data }">
|
|
20
|
+
<div :id="data.id" class="list-container">
|
|
21
|
+
<div class="list-item">
|
|
22
|
+
<CodeIcon v-if="data.type === 'code'" class="codeIcon"></CodeIcon>
|
|
23
|
+
<AppManageIcon v-if="data.type === 'node'" class="compIcon"></AppManageIcon>
|
|
24
|
+
<span class="name" :class="{ code: data.type === 'code', hook: data.type === 'key' }"
|
|
25
|
+
>{{ data.name }} ({{ data.id }})</span
|
|
26
|
+
>
|
|
27
|
+
<!-- 右侧工具栏 -->
|
|
28
|
+
<div class="right-tool" v-if="data.type === 'code'">
|
|
29
|
+
<TMagicTooltip effect="dark" :content="editable ? '编辑' : '查看'" placement="bottom">
|
|
30
|
+
<Icon :icon="editable ? Edit : View" class="edit-icon" @click.stop="editCode(data.id)"></Icon>
|
|
31
|
+
</TMagicTooltip>
|
|
32
|
+
<TMagicTooltip v-if="editable" effect="dark" content="删除" placement="bottom">
|
|
33
|
+
<Icon :icon="Close" class="edit-icon" @click.stop="deleteCode(`${data.id}`)"></Icon>
|
|
34
|
+
</TMagicTooltip>
|
|
35
|
+
<slot name="code-block-panel-tool" :id="data.id" :data="data.codeBlockContent"></slot>
|
|
44
36
|
</div>
|
|
45
37
|
</div>
|
|
46
|
-
</
|
|
47
|
-
</
|
|
48
|
-
|
|
49
|
-
<!-- 代码块编辑区 -->
|
|
50
|
-
<CodeBlockEditor v-if="isShowCodeBlockEditor" :paramsColConfig="paramsColConfig">
|
|
51
|
-
<template #code-block-edit-panel-header="{ id }">
|
|
52
|
-
<slot name="code-block-edit-panel-header" :id="id"></slot>
|
|
53
|
-
</template>
|
|
54
|
-
</CodeBlockEditor>
|
|
55
|
-
</TMagicScrollbar>
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
40
|
+
</TMagicTree>
|
|
56
41
|
</template>
|
|
57
42
|
|
|
58
|
-
<script
|
|
43
|
+
<script lang="ts" setup>
|
|
59
44
|
import { computed, inject, ref } from 'vue';
|
|
60
45
|
import { Close, Edit, View } from '@element-plus/icons-vue';
|
|
61
46
|
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
import { CodeBlockContent, Id } from '@tmagic/schema';
|
|
47
|
+
import { tMagicMessage, tMagicMessageBox, TMagicTooltip, TMagicTree } from '@tmagic/design';
|
|
48
|
+
import type { Id } from '@tmagic/schema';
|
|
65
49
|
|
|
66
50
|
import Icon from '@editor/components/Icon.vue';
|
|
67
|
-
import SearchInput from '@editor/components/SearchInput.vue';
|
|
68
51
|
import AppManageIcon from '@editor/icons/AppManageIcon.vue';
|
|
69
52
|
import CodeIcon from '@editor/icons/CodeIcon.vue';
|
|
70
|
-
import { CodeDeleteErrorType, CodeDslItem, Services } from '@editor/type';
|
|
71
|
-
|
|
72
|
-
import CodeBlockEditor from './CodeBlockEditor.vue';
|
|
53
|
+
import { CodeDeleteErrorType, CodeDslItem, DepTargetType, Services } from '@editor/type';
|
|
73
54
|
|
|
74
55
|
defineOptions({
|
|
75
56
|
name: 'MEditorCodeBlockList',
|
|
@@ -77,20 +58,18 @@ defineOptions({
|
|
|
77
58
|
|
|
78
59
|
const props = defineProps<{
|
|
79
60
|
customError?: (id: Id, errorType: CodeDeleteErrorType) => any;
|
|
80
|
-
paramsColConfig?: ColumnConfig;
|
|
81
61
|
}>();
|
|
82
62
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
63
|
+
const emit = defineEmits<{
|
|
64
|
+
edit: [id: string];
|
|
65
|
+
remove: [id: string];
|
|
66
|
+
}>();
|
|
88
67
|
|
|
89
68
|
const { codeBlockService, depService, editorService } = inject<Services>('services') || {};
|
|
90
69
|
|
|
91
70
|
// 代码块列表
|
|
92
71
|
const codeList = computed(() =>
|
|
93
|
-
Object.values(depService?.
|
|
72
|
+
Object.values(depService?.getTargets(DepTargetType.CODE_BLOCK) || {}).map((target) => {
|
|
94
73
|
// 组件节点
|
|
95
74
|
const compNodes = Object.entries(target.deps).map(([id, dep]) => ({
|
|
96
75
|
name: dep.name,
|
|
@@ -107,58 +86,10 @@ const codeList = computed(() =>
|
|
|
107
86
|
};
|
|
108
87
|
}),
|
|
109
88
|
);
|
|
110
|
-
|
|
111
89
|
// 默认展开组件层级的节点
|
|
112
90
|
const expandedKeys = computed(() => codeList.value.map((item) => item.id));
|
|
113
|
-
|
|
114
91
|
const editable = computed(() => codeBlockService?.getEditStatus());
|
|
115
92
|
|
|
116
|
-
// 是否展示代码编辑区
|
|
117
|
-
const isShowCodeBlockEditor = computed(() => codeBlockService?.getCodeEditorShowStatus() || false);
|
|
118
|
-
|
|
119
|
-
// 新增代码块
|
|
120
|
-
const createCodeBlock = async () => {
|
|
121
|
-
if (!codeBlockService) {
|
|
122
|
-
tMagicMessage.error('新增代码块失败');
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const codeConfig: CodeBlockContent = {
|
|
127
|
-
name: '代码块',
|
|
128
|
-
content: `({app, params}) => {\n // place your code here\n}`,
|
|
129
|
-
params: [],
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const id = await codeBlockService.getUniqueId();
|
|
133
|
-
|
|
134
|
-
await codeBlockService.setCodeDslById(id, codeConfig);
|
|
135
|
-
codeBlockService.setCodeEditorContent(true, id);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// 编辑代码块
|
|
139
|
-
const editCode = async (key: Id) => {
|
|
140
|
-
codeBlockService?.setCodeEditorContent(true, key);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// 删除代码块
|
|
144
|
-
const deleteCode = (key: Id) => {
|
|
145
|
-
const currentCode = codeList.value.find((codeItem) => codeItem.id === key);
|
|
146
|
-
const existBinds = Boolean(currentCode?.children.length);
|
|
147
|
-
const undeleteableList = codeBlockService?.getUndeletableList() || [];
|
|
148
|
-
if (!existBinds && !undeleteableList.includes(key)) {
|
|
149
|
-
// 无绑定关系,且不在不可删除列表中
|
|
150
|
-
codeBlockService?.deleteCodeDslByIds([key]);
|
|
151
|
-
} else {
|
|
152
|
-
if (typeof props.customError === 'function') {
|
|
153
|
-
props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
|
|
154
|
-
} else {
|
|
155
|
-
tMagicMessage.error('代码块删除失败');
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const tree = ref<InstanceType<typeof TMagicTree>>();
|
|
161
|
-
|
|
162
93
|
const filterNode = (value: string, data: CodeDslItem): boolean => {
|
|
163
94
|
if (!value) {
|
|
164
95
|
return true;
|
|
@@ -166,10 +97,6 @@ const filterNode = (value: string, data: CodeDslItem): boolean => {
|
|
|
166
97
|
return `${data.name}${data.id}`.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) !== -1;
|
|
167
98
|
};
|
|
168
99
|
|
|
169
|
-
const filterTextChangeHandler = (val: string) => {
|
|
170
|
-
tree.value?.filter(val);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
100
|
// 选中组件
|
|
174
101
|
const selectComp = (compId: Id) => {
|
|
175
102
|
const stage = editorService?.get('stage');
|
|
@@ -184,4 +111,39 @@ const clickHandler = (data: any, node: any) => {
|
|
|
184
111
|
selectComp(node.parent.data.id);
|
|
185
112
|
}
|
|
186
113
|
};
|
|
114
|
+
|
|
115
|
+
// 编辑代码块
|
|
116
|
+
const editCode = (id: string) => {
|
|
117
|
+
emit('edit', id);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const deleteCode = async (id: string) => {
|
|
121
|
+
const currentCode = codeList.value.find((codeItem) => codeItem.id === id);
|
|
122
|
+
const existBinds = Boolean(currentCode?.children.length);
|
|
123
|
+
const undeleteableList = codeBlockService?.getUndeletableList() || [];
|
|
124
|
+
if (!existBinds && !undeleteableList.includes(id)) {
|
|
125
|
+
await tMagicMessageBox.confirm('确定删除该代码块吗?', '提示', {
|
|
126
|
+
confirmButtonText: '确定',
|
|
127
|
+
cancelButtonText: '取消',
|
|
128
|
+
type: 'warning',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// 无绑定关系,且不在不可删除列表中
|
|
132
|
+
emit('remove', id);
|
|
133
|
+
} else {
|
|
134
|
+
if (typeof props.customError === 'function') {
|
|
135
|
+
props.customError(id, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
|
|
136
|
+
} else {
|
|
137
|
+
tMagicMessage.error('代码块删除失败');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const tree = ref<InstanceType<typeof TMagicTree>>();
|
|
143
|
+
|
|
144
|
+
defineExpose({
|
|
145
|
+
filter(val: string) {
|
|
146
|
+
tree.value?.filter(val);
|
|
147
|
+
},
|
|
148
|
+
});
|
|
187
149
|
</script>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<TMagicScrollbar class="m-editor-code-block-list m-editor-dep-list-panel">
|
|
3
|
+
<slot name="code-block-panel-header">
|
|
4
|
+
<div class="search-wrapper">
|
|
5
|
+
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
|
6
|
+
<TMagicButton v-if="editable" class="create-code-button" type="primary" size="small" @click="createCodeBlock"
|
|
7
|
+
>新增</TMagicButton
|
|
8
|
+
>
|
|
9
|
+
<slot name="code-block-panel-search"></slot>
|
|
10
|
+
</div>
|
|
11
|
+
</slot>
|
|
12
|
+
|
|
13
|
+
<!-- 代码块列表 -->
|
|
14
|
+
<CodeBlockList ref="codeBlockList" :custom-error="customError" @edit="editCode" @remove="deleteCode">
|
|
15
|
+
<template #code-block-panel-tool="{ id, data }">
|
|
16
|
+
<slot name="code-block-panel-tool" :id="id" :data="data"></slot>
|
|
17
|
+
</template>
|
|
18
|
+
</CodeBlockList>
|
|
19
|
+
|
|
20
|
+
<!-- 代码块编辑区 -->
|
|
21
|
+
<CodeBlockEditor
|
|
22
|
+
v-if="codeConfig"
|
|
23
|
+
ref="codeBlockEditor"
|
|
24
|
+
:disabled="!editable"
|
|
25
|
+
:content="codeConfig"
|
|
26
|
+
@submit="submitCodeBlockHandler"
|
|
27
|
+
></CodeBlockEditor>
|
|
28
|
+
</TMagicScrollbar>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup lang="ts">
|
|
32
|
+
import { computed, inject, ref } from 'vue';
|
|
33
|
+
|
|
34
|
+
import { TMagicButton, TMagicScrollbar } from '@tmagic/design';
|
|
35
|
+
import type { Id } from '@tmagic/schema';
|
|
36
|
+
|
|
37
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
38
|
+
import SearchInput from '@editor/components/SearchInput.vue';
|
|
39
|
+
import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
|
40
|
+
import type { CodeDeleteErrorType, Services } from '@editor/type';
|
|
41
|
+
|
|
42
|
+
import CodeBlockList from './CodeBlockList.vue';
|
|
43
|
+
|
|
44
|
+
defineOptions({
|
|
45
|
+
name: 'MEditorCodeBlockListPanel',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
defineProps<{
|
|
49
|
+
customError?: (id: Id, errorType: CodeDeleteErrorType) => any;
|
|
50
|
+
}>();
|
|
51
|
+
|
|
52
|
+
const { codeBlockService } = inject<Services>('services') || {};
|
|
53
|
+
|
|
54
|
+
const editable = computed(() => codeBlockService?.getEditStatus());
|
|
55
|
+
|
|
56
|
+
const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
|
|
57
|
+
useCodeBlockEdit(codeBlockService);
|
|
58
|
+
|
|
59
|
+
const codeBlockList = ref<InstanceType<typeof CodeBlockList>>();
|
|
60
|
+
|
|
61
|
+
const filterTextChangeHandler = (val: string) => {
|
|
62
|
+
codeBlockList.value?.filter(val);
|
|
63
|
+
};
|
|
64
|
+
</script>
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
2
|
+
<MFormDrawer
|
|
3
|
+
ref="fomDrawer"
|
|
4
|
+
label-width="80px"
|
|
5
|
+
:close-on-press-escape="false"
|
|
4
6
|
:title="title"
|
|
5
|
-
:
|
|
6
|
-
:
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<template #footer>
|
|
14
|
-
<div>
|
|
15
|
-
<TMagicButton type="primary" @click="submitHandler">确定</TMagicButton>
|
|
16
|
-
<TMagicButton @click="hide">关闭</TMagicButton>
|
|
17
|
-
</div>
|
|
18
|
-
</template>
|
|
19
|
-
</TMagicDrawer>
|
|
7
|
+
:width="size"
|
|
8
|
+
:config="dataSourceConfig"
|
|
9
|
+
:values="initValues"
|
|
10
|
+
:disabled="disabled"
|
|
11
|
+
@submit="submitHandler"
|
|
12
|
+
@error="errorHandler"
|
|
13
|
+
></MFormDrawer>
|
|
20
14
|
</template>
|
|
21
15
|
|
|
22
16
|
<script setup lang="ts">
|
|
23
17
|
import { computed, inject, ref, watchEffect } from 'vue';
|
|
24
18
|
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
19
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
20
|
+
import { FormConfig, MFormDrawer } from '@tmagic/form';
|
|
21
|
+
import { DataSourceSchema } from '@tmagic/schema';
|
|
27
22
|
|
|
28
23
|
import type { Services } from '@editor/type';
|
|
29
24
|
|
|
@@ -34,55 +29,40 @@ defineOptions({
|
|
|
34
29
|
const props = defineProps<{
|
|
35
30
|
title?: string;
|
|
36
31
|
values: any;
|
|
32
|
+
disabled: boolean;
|
|
37
33
|
}>();
|
|
38
34
|
|
|
39
|
-
const type = ref('base');
|
|
40
|
-
|
|
41
35
|
const emit = defineEmits(['submit']);
|
|
42
36
|
|
|
43
37
|
const services = inject<Services>('services');
|
|
44
38
|
|
|
45
39
|
const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
|
|
46
40
|
|
|
47
|
-
const
|
|
41
|
+
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
|
48
42
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const initValues = ref({});
|
|
43
|
+
const initValues = ref<Partial<DataSourceSchema>>({});
|
|
44
|
+
const dataSourceConfig = ref<FormConfig>([]);
|
|
52
45
|
|
|
53
46
|
watchEffect(() => {
|
|
54
47
|
initValues.value = props.values;
|
|
55
|
-
|
|
48
|
+
dataSourceConfig.value = services?.dataSourceService.getFormConfig(initValues.value.type) || [];
|
|
56
49
|
});
|
|
57
50
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
type.value = value.type || 'base';
|
|
63
|
-
initValues.value = value;
|
|
51
|
+
const submitHandler = (values: any) => {
|
|
52
|
+
emit('submit', values);
|
|
64
53
|
};
|
|
65
54
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const values = await form.value?.submitForm();
|
|
69
|
-
emit('submit', values);
|
|
70
|
-
} catch (error: any) {
|
|
71
|
-
tMagicMessage.error(error.message);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const visible = ref(false);
|
|
76
|
-
|
|
77
|
-
const hide = () => {
|
|
78
|
-
visible.value = false;
|
|
55
|
+
const errorHandler = (error: any) => {
|
|
56
|
+
tMagicMessage.error(error.message);
|
|
79
57
|
};
|
|
80
58
|
|
|
81
59
|
defineExpose({
|
|
82
60
|
show() {
|
|
83
|
-
|
|
61
|
+
fomDrawer.value?.show();
|
|
84
62
|
},
|
|
85
63
|
|
|
86
|
-
hide
|
|
64
|
+
hide() {
|
|
65
|
+
fomDrawer.value?.hide();
|
|
66
|
+
},
|
|
87
67
|
});
|
|
88
68
|
</script>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<TMagicTree
|
|
3
|
+
ref="tree"
|
|
4
|
+
class="magic-editor-layer-tree"
|
|
5
|
+
node-key="id"
|
|
6
|
+
empty-text="暂无代码块"
|
|
7
|
+
default-expand-all
|
|
8
|
+
:expand-on-click-node="false"
|
|
9
|
+
:data="list"
|
|
10
|
+
:highlight-current="true"
|
|
11
|
+
@node-click="clickHandler"
|
|
12
|
+
>
|
|
13
|
+
<template #default="{ data }">
|
|
14
|
+
<div :id="data.id" class="list-container">
|
|
15
|
+
<div class="list-item">
|
|
16
|
+
<Icon v-if="data.type === 'code'" class="codeIcon" :icon="Coin"></Icon>
|
|
17
|
+
<Icon v-if="data.type === 'node'" class="compIcon" :icon="Aim"></Icon>
|
|
18
|
+
<span class="name" :class="{ code: data.type === 'ds', hook: data.type === 'key' }">{{
|
|
19
|
+
data.type === 'key' ? data.name : `${data.name}(${data.id})`
|
|
20
|
+
}}</span>
|
|
21
|
+
<!-- 右侧工具栏 -->
|
|
22
|
+
<div class="right-tool" v-if="data.type === 'ds'">
|
|
23
|
+
<TMagicTooltip effect="dark" :content="editable ? '编辑' : '查看'" placement="bottom">
|
|
24
|
+
<Icon :icon="editable ? Edit : View" class="edit-icon" @click.stop="editHandler(`${data.id}`)"></Icon>
|
|
25
|
+
</TMagicTooltip>
|
|
26
|
+
<TMagicTooltip v-if="editable" effect="dark" content="删除" placement="bottom">
|
|
27
|
+
<Icon :icon="Close" class="edit-icon" @click.stop="removeHandler(`${data.id}`)"></Icon>
|
|
28
|
+
</TMagicTooltip>
|
|
29
|
+
<slot name="data-source-panel-tool" :id="data.id" :data="data.codeBlockContent"></slot>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
</TMagicTree>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script lang="ts" setup>
|
|
38
|
+
import { computed, inject, ref } from 'vue';
|
|
39
|
+
import { Aim, Close, Coin, Edit, View } from '@element-plus/icons-vue';
|
|
40
|
+
|
|
41
|
+
import { tMagicMessageBox, TMagicTooltip, TMagicTree } from '@tmagic/design';
|
|
42
|
+
import { Dep, Id } from '@tmagic/schema';
|
|
43
|
+
|
|
44
|
+
import Icon from '@editor/components/Icon.vue';
|
|
45
|
+
import { DepTargetType, Services } from '@editor/type';
|
|
46
|
+
|
|
47
|
+
defineOptions({
|
|
48
|
+
name: 'MEditorDataSourceList',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const emit = defineEmits<{
|
|
52
|
+
edit: [id: string];
|
|
53
|
+
remove: [id: string];
|
|
54
|
+
}>();
|
|
55
|
+
|
|
56
|
+
const { depService, editorService, dataSourceService } = inject<Services>('services') || {};
|
|
57
|
+
|
|
58
|
+
const editable = computed(() => dataSourceService?.get('editable') ?? true);
|
|
59
|
+
|
|
60
|
+
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
61
|
+
|
|
62
|
+
const dsDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE) || {});
|
|
63
|
+
const dsMethodDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_METHOD) || {});
|
|
64
|
+
const dsCondDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_COND) || {});
|
|
65
|
+
|
|
66
|
+
const getKeyTreeConfig = (dep: Dep[string], type?: string) =>
|
|
67
|
+
dep.keys.map((key) => ({ name: key, id: key, type: 'key', isMethod: type === 'method', isCond: type === 'cond' }));
|
|
68
|
+
|
|
69
|
+
const getNodeTreeConfig = (id: string, dep: Dep[string], type?: string) => ({
|
|
70
|
+
name: dep.name,
|
|
71
|
+
type: 'node',
|
|
72
|
+
id,
|
|
73
|
+
children: getKeyTreeConfig(dep, type),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const list = computed(() =>
|
|
77
|
+
dataSources.value.map((ds) => {
|
|
78
|
+
const dsDeps = dsDep.value[ds.id].deps;
|
|
79
|
+
const dsMethodDeps = dsMethodDep.value[ds.id].deps;
|
|
80
|
+
const dsCondDeps = dsCondDep.value[ds.id].deps;
|
|
81
|
+
|
|
82
|
+
const children: any[] = [];
|
|
83
|
+
|
|
84
|
+
const mergeChildren = (deps: Dep, type?: string) => {
|
|
85
|
+
Object.entries(deps).forEach(([id, dep]) => {
|
|
86
|
+
const nodeItem = children.find((item) => item.id === id);
|
|
87
|
+
if (nodeItem) {
|
|
88
|
+
nodeItem.children = nodeItem.children.concat(getKeyTreeConfig(dep, type));
|
|
89
|
+
} else {
|
|
90
|
+
children.push(getNodeTreeConfig(id, dep, type));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
mergeChildren(dsDeps);
|
|
96
|
+
mergeChildren(dsMethodDeps, 'method');
|
|
97
|
+
mergeChildren(dsCondDeps, 'cond');
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
id: ds.id,
|
|
101
|
+
name: ds.title,
|
|
102
|
+
type: 'ds',
|
|
103
|
+
children,
|
|
104
|
+
};
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const editHandler = (id: string) => {
|
|
109
|
+
emit('edit', id);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const removeHandler = async (id: string) => {
|
|
113
|
+
await tMagicMessageBox.confirm('确定删除?', '提示', {
|
|
114
|
+
confirmButtonText: '确定',
|
|
115
|
+
cancelButtonText: '取消',
|
|
116
|
+
type: 'warning',
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
emit('remove', id);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// 选中组件
|
|
123
|
+
const selectComp = (compId: Id) => {
|
|
124
|
+
const stage = editorService?.get('stage');
|
|
125
|
+
editorService?.select(compId);
|
|
126
|
+
stage?.select(compId);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const clickHandler = (data: any, node: any) => {
|
|
130
|
+
if (data.type === 'node') {
|
|
131
|
+
selectComp(data.id);
|
|
132
|
+
} else if (data.type === 'key') {
|
|
133
|
+
selectComp(node.parent.data.id);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const tree = ref<InstanceType<typeof TMagicTree>>();
|
|
138
|
+
|
|
139
|
+
defineExpose({
|
|
140
|
+
filter(val: string) {
|
|
141
|
+
debugger;
|
|
142
|
+
tree.value?.filter(val);
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
</script>
|