@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.
- package/dist/style.css +1 -1
- package/dist/tmagic-editor.js +636 -589
- package/dist/tmagic-editor.umd.cjs +634 -586
- package/package.json +15 -11
- package/types/editorProps.d.ts +0 -7
- package/types/layouts/PropsPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
- package/types/services/codeBlock.d.ts +2 -1
- package/types/services/dataSource.d.ts +2 -1
- package/types/services/dep.d.ts +12 -2
- package/types/services/editor.d.ts +22 -4
- package/types/services/props.d.ts +7 -6
- package/types/type.d.ts +6 -0
- package/types/utils/editor.d.ts +1 -0
- package/types/utils/idle-task.d.ts +14 -0
- package/types/utils/operator.d.ts +2 -2
- package/src/Editor.vue +0 -211
- package/src/components/CodeBlockEditor.vue +0 -268
- package/src/components/CodeParams.vue +0 -60
- package/src/components/ContentMenu.vue +0 -193
- package/src/components/FloatingBox.vue +0 -178
- package/src/components/Icon.vue +0 -27
- package/src/components/Resizer.vue +0 -23
- package/src/components/ScrollBar.vue +0 -151
- package/src/components/ScrollViewer.vue +0 -128
- package/src/components/SearchInput.vue +0 -37
- package/src/components/SplitView.vue +0 -186
- package/src/components/ToolButton.vue +0 -138
- package/src/components/Tree.vue +0 -71
- package/src/components/TreeNode.vue +0 -148
- package/src/editorProps.ts +0 -124
- package/src/fields/Code.vue +0 -50
- package/src/fields/CodeLink.vue +0 -80
- package/src/fields/CodeSelect.vue +0 -132
- package/src/fields/CodeSelectCol.vue +0 -139
- package/src/fields/DataSourceFieldSelect.vue +0 -149
- package/src/fields/DataSourceFields.vue +0 -323
- package/src/fields/DataSourceInput.vue +0 -325
- package/src/fields/DataSourceMethodSelect.vue +0 -153
- package/src/fields/DataSourceMethods.vue +0 -104
- package/src/fields/DataSourceMocks.vue +0 -255
- package/src/fields/DataSourceSelect.vue +0 -98
- package/src/fields/EventSelect.vue +0 -301
- package/src/fields/KeyValue.vue +0 -137
- package/src/fields/PageFragmentSelect.vue +0 -63
- package/src/fields/UISelect.vue +0 -135
- package/src/hooks/index.ts +0 -24
- package/src/hooks/use-code-block-edit.ts +0 -83
- package/src/hooks/use-data-source-edit.ts +0 -46
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/hooks/use-editor-content-height.ts +0 -26
- package/src/hooks/use-filter.ts +0 -55
- package/src/hooks/use-float-box.ts +0 -76
- package/src/hooks/use-getso.ts +0 -35
- package/src/hooks/use-next-float-box-position.ts +0 -29
- package/src/hooks/use-node-status.ts +0 -48
- package/src/hooks/use-stage.ts +0 -129
- package/src/hooks/use-window-rect.ts +0 -20
- package/src/icons/AppManageIcon.vue +0 -15
- package/src/icons/CenterIcon.vue +0 -13
- package/src/icons/CodeIcon.vue +0 -28
- package/src/icons/FolderMinusIcon.vue +0 -22
- package/src/icons/PinIcon.vue +0 -25
- package/src/icons/PinnedIcon.vue +0 -25
- package/src/index.ts +0 -118
- package/src/initService.ts +0 -447
- package/src/layouts/AddPageBox.vue +0 -55
- package/src/layouts/CodeEditor.vue +0 -226
- package/src/layouts/Framework.vue +0 -163
- package/src/layouts/NavMenu.vue +0 -200
- package/src/layouts/PropsPanel.vue +0 -130
- package/src/layouts/page-bar/AddButton.vue +0 -48
- package/src/layouts/page-bar/PageBar.vue +0 -159
- package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
- package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
- package/src/layouts/sidebar/Sidebar.vue +0 -278
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
- package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
- package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
- package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
- package/src/layouts/sidebar/layer/use-click.ts +0 -110
- package/src/layouts/sidebar/layer/use-drag.ts +0 -161
- package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
- package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
- package/src/layouts/workspace/Breadcrumb.vue +0 -35
- package/src/layouts/workspace/Workspace.vue +0 -46
- package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
- package/src/layouts/workspace/viewer/Stage.vue +0 -246
- package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
- package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
- package/src/services/BaseService.ts +0 -230
- package/src/services/codeBlock.ts +0 -324
- package/src/services/componentList.ts +0 -58
- package/src/services/dataSource.ts +0 -209
- package/src/services/dep.ts +0 -80
- package/src/services/editor.ts +0 -1087
- package/src/services/events.ts +0 -93
- package/src/services/history.ts +0 -126
- package/src/services/keybinding.ts +0 -220
- package/src/services/props.ts +0 -265
- package/src/services/stageOverlay.ts +0 -212
- package/src/services/storage.ts +0 -155
- package/src/services/ui.ts +0 -156
- package/src/shims-vue.d.ts +0 -6
- package/src/theme/breadcrumb.scss +0 -6
- package/src/theme/code-block.scss +0 -6
- package/src/theme/code-editor.scss +0 -38
- package/src/theme/common/var.scss +0 -14
- package/src/theme/component-list-panel.scss +0 -95
- package/src/theme/content-menu.scss +0 -76
- package/src/theme/data-source-field.scss +0 -12
- package/src/theme/data-source-fields.scss +0 -13
- package/src/theme/data-source-input.scss +0 -18
- package/src/theme/data-source-methods.scss +0 -13
- package/src/theme/data-source.scss +0 -28
- package/src/theme/event.scss +0 -37
- package/src/theme/floating-box.scss +0 -32
- package/src/theme/framework.scss +0 -69
- package/src/theme/icon.scss +0 -12
- package/src/theme/index.scss +0 -10
- package/src/theme/key-value.scss +0 -20
- package/src/theme/layer-panel.scss +0 -26
- package/src/theme/layout.scss +0 -9
- package/src/theme/nav-menu.scss +0 -78
- package/src/theme/page-bar.scss +0 -89
- package/src/theme/page-fragment-select.scss +0 -14
- package/src/theme/props-panel.scss +0 -55
- package/src/theme/resizer.scss +0 -66
- package/src/theme/ruler.scss +0 -38
- package/src/theme/search-input.scss +0 -14
- package/src/theme/sidebar.scss +0 -79
- package/src/theme/stage.scss +0 -76
- package/src/theme/theme.scss +0 -27
- package/src/theme/tree.scss +0 -89
- package/src/theme/workspace.scss +0 -9
- package/src/type.ts +0 -746
- package/src/utils/compose.ts +0 -52
- package/src/utils/config.ts +0 -29
- package/src/utils/content-menu.ts +0 -95
- package/src/utils/data-source/formConfigs/base.ts +0 -30
- package/src/utils/data-source/formConfigs/http.ts +0 -60
- package/src/utils/data-source/index.ts +0 -236
- package/src/utils/editor.ts +0 -294
- package/src/utils/index.ts +0 -24
- package/src/utils/keybinding-config.ts +0 -125
- package/src/utils/logger.ts +0 -47
- package/src/utils/monaco-editor.ts +0 -8
- package/src/utils/operator.ts +0 -106
- package/src/utils/props.ts +0 -504
- package/src/utils/scroll-viewer.ts +0 -165
- package/src/utils/tree.ts +0 -15
- package/src/utils/undo-redo.ts +0 -76
- package/tsconfig.build.json +0 -16
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-fields-code-select-col">
|
|
3
|
-
<div class="code-select-container">
|
|
4
|
-
<!-- 代码块下拉框 -->
|
|
5
|
-
<MContainer
|
|
6
|
-
class="select"
|
|
7
|
-
:config="selectConfig"
|
|
8
|
-
:model="model"
|
|
9
|
-
:size="size"
|
|
10
|
-
@change="onParamsChangeHandler"
|
|
11
|
-
></MContainer>
|
|
12
|
-
|
|
13
|
-
<!-- 查看/编辑按钮 -->
|
|
14
|
-
<TMagicButton
|
|
15
|
-
v-if="model[name] && hasCodeBlockSidePanel"
|
|
16
|
-
class="m-fields-select-action-button"
|
|
17
|
-
:size="size"
|
|
18
|
-
@click="editCode(model[name])"
|
|
19
|
-
>
|
|
20
|
-
<MIcon :icon="!notEditable ? Edit : View"></MIcon>
|
|
21
|
-
</TMagicButton>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<!-- 参数填写框 -->
|
|
25
|
-
<CodeParams
|
|
26
|
-
v-if="paramsConfig.length"
|
|
27
|
-
name="params"
|
|
28
|
-
:key="model[name]"
|
|
29
|
-
:model="model"
|
|
30
|
-
:size="size"
|
|
31
|
-
:params-config="paramsConfig"
|
|
32
|
-
@change="onParamsChangeHandler"
|
|
33
|
-
></CodeParams>
|
|
34
|
-
</div>
|
|
35
|
-
</template>
|
|
36
|
-
|
|
37
|
-
<script lang="ts" setup>
|
|
38
|
-
import { computed, inject, ref, watch } from 'vue';
|
|
39
|
-
import { Edit, View } from '@element-plus/icons-vue';
|
|
40
|
-
import { isEmpty, map } from 'lodash-es';
|
|
41
|
-
|
|
42
|
-
import { TMagicButton } from '@tmagic/design';
|
|
43
|
-
import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
|
|
44
|
-
import type { Id } from '@tmagic/schema';
|
|
45
|
-
|
|
46
|
-
import CodeParams from '@editor/components/CodeParams.vue';
|
|
47
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
48
|
-
import type { CodeParamStatement, CodeSelectColConfig, EventBus, Services } from '@editor/type';
|
|
49
|
-
import { SideItemKey } from '@editor/type';
|
|
50
|
-
|
|
51
|
-
defineOptions({
|
|
52
|
-
name: 'MFieldsCodeSelectCol',
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
56
|
-
const services = inject<Services>('services');
|
|
57
|
-
const eventBus = inject<EventBus>('eventBus');
|
|
58
|
-
const emit = defineEmits(['change']);
|
|
59
|
-
|
|
60
|
-
const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
|
|
61
|
-
disabled: false,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
65
|
-
|
|
66
|
-
const hasCodeBlockSidePanel = computed(() =>
|
|
67
|
-
(services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.CODE_BLOCK),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 根据代码块id获取代码块参数配置
|
|
72
|
-
* @param codeId 代码块ID
|
|
73
|
-
*/
|
|
74
|
-
const getParamItemsConfig = (codeId?: Id): CodeParamStatement[] => {
|
|
75
|
-
if (!codeDsl.value || !codeId) return [];
|
|
76
|
-
|
|
77
|
-
const paramStatements = codeDsl.value[codeId]?.params;
|
|
78
|
-
|
|
79
|
-
if (isEmpty(paramStatements)) return [];
|
|
80
|
-
|
|
81
|
-
return paramStatements.map((paramState: CodeParamStatement) => ({
|
|
82
|
-
labelWidth: '100px',
|
|
83
|
-
text: paramState.name,
|
|
84
|
-
...paramState,
|
|
85
|
-
}));
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
89
|
-
const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model[props.name]));
|
|
90
|
-
|
|
91
|
-
watch(
|
|
92
|
-
() => props.model[props.name],
|
|
93
|
-
(v, preV) => {
|
|
94
|
-
if (v !== preV) {
|
|
95
|
-
paramsConfig.value = getParamItemsConfig(v);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const selectConfig = {
|
|
101
|
-
type: 'select',
|
|
102
|
-
name: props.name,
|
|
103
|
-
disable: props.disabled,
|
|
104
|
-
options: () => {
|
|
105
|
-
if (codeDsl.value) {
|
|
106
|
-
return map(codeDsl.value, (value, key) => ({
|
|
107
|
-
text: `${value.name}(${key})`,
|
|
108
|
-
label: `${value.name}(${key})`,
|
|
109
|
-
value: key,
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
return [];
|
|
113
|
-
},
|
|
114
|
-
onChange: (formState: any, codeId: Id, { model }: any) => {
|
|
115
|
-
// 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
|
|
116
|
-
paramsConfig.value = getParamItemsConfig(codeId);
|
|
117
|
-
|
|
118
|
-
if (paramsConfig.value.length) {
|
|
119
|
-
model.params = createValues(formState, paramsConfig.value, {}, model.params);
|
|
120
|
-
} else {
|
|
121
|
-
model.params = {};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return codeId;
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 参数值修改更新
|
|
130
|
-
*/
|
|
131
|
-
const onParamsChangeHandler = (value: any) => {
|
|
132
|
-
props.model.params = value.params;
|
|
133
|
-
emit('change', props.model);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const editCode = (id: string) => {
|
|
137
|
-
eventBus?.emit('edit-code', id);
|
|
138
|
-
};
|
|
139
|
-
</script>
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-fields-data-source-field-select">
|
|
3
|
-
<component
|
|
4
|
-
:is="tagName"
|
|
5
|
-
:config="showDataSourceFieldSelect || !config.fieldConfig ? cascaderConfig : config.fieldConfig"
|
|
6
|
-
:model="model"
|
|
7
|
-
:name="name"
|
|
8
|
-
:disabled="disabled"
|
|
9
|
-
:size="size"
|
|
10
|
-
:last-values="lastValues"
|
|
11
|
-
:init-values="initValues"
|
|
12
|
-
:values="values"
|
|
13
|
-
:prop="`${prop}${prop ? '.' : ''}${name}`"
|
|
14
|
-
@change="onChangeHandler"
|
|
15
|
-
></component>
|
|
16
|
-
|
|
17
|
-
<TMagicButton
|
|
18
|
-
v-if="(showDataSourceFieldSelect || !config.fieldConfig) && selectedDataSourceId && hasDataSourceSidePanel"
|
|
19
|
-
class="m-fields-select-action-button"
|
|
20
|
-
:size="size"
|
|
21
|
-
@click="editHandler(selectedDataSourceId)"
|
|
22
|
-
><MIcon :icon="!notEditable ? Edit : View"></MIcon
|
|
23
|
-
></TMagicButton>
|
|
24
|
-
|
|
25
|
-
<TMagicButton
|
|
26
|
-
v-if="config.fieldConfig"
|
|
27
|
-
style="margin-left: 5px"
|
|
28
|
-
:type="showDataSourceFieldSelect ? 'primary' : 'default'"
|
|
29
|
-
:size="size"
|
|
30
|
-
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
|
31
|
-
><MIcon :icon="Coin"></MIcon
|
|
32
|
-
></TMagicButton>
|
|
33
|
-
</div>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
<script setup lang="ts">
|
|
37
|
-
import { computed, inject, ref, resolveComponent, watch } from 'vue';
|
|
38
|
-
import { Coin, Edit, View } from '@element-plus/icons-vue';
|
|
39
|
-
|
|
40
|
-
import { TMagicButton } from '@tmagic/design';
|
|
41
|
-
import type { CascaderConfig, FieldProps, FormState } from '@tmagic/form';
|
|
42
|
-
import { filterFunction, MCascader } from '@tmagic/form';
|
|
43
|
-
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
|
44
|
-
|
|
45
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
46
|
-
import type { DataSourceFieldSelectConfig, EventBus, Services } from '@editor/type';
|
|
47
|
-
import { SideItemKey } from '@editor/type';
|
|
48
|
-
import { getCascaderOptionsFromFields } from '@editor/utils';
|
|
49
|
-
|
|
50
|
-
defineOptions({
|
|
51
|
-
name: 'MFieldsDataSourceFieldSelect',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const services = inject<Services>('services');
|
|
55
|
-
const eventBus = inject<EventBus>('eventBus');
|
|
56
|
-
const emit = defineEmits(['change']);
|
|
57
|
-
|
|
58
|
-
const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
|
|
59
|
-
disabled: false,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
|
63
|
-
|
|
64
|
-
const hasDataSourceSidePanel = computed(() =>
|
|
65
|
-
(services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const selectedDataSourceId = computed(() => {
|
|
69
|
-
const value = props.model[props.name];
|
|
70
|
-
if (!Array.isArray(value) || !value.length) {
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return value[0].replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
78
|
-
|
|
79
|
-
const cascaderConfig = computed<CascaderConfig>(() => {
|
|
80
|
-
const valueIsKey = props.config.value === 'key';
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
type: 'cascader',
|
|
84
|
-
checkStrictly: props.config.checkStrictly ?? !valueIsKey,
|
|
85
|
-
popperClass: 'm-editor-data-source-field-select-popper',
|
|
86
|
-
options: () => {
|
|
87
|
-
const options =
|
|
88
|
-
dataSources.value?.map((ds) => ({
|
|
89
|
-
label: ds.title || ds.id,
|
|
90
|
-
value: valueIsKey ? ds.id : `${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX}${ds.id}`,
|
|
91
|
-
children: getCascaderOptionsFromFields(ds.fields, props.config.dataSourceFieldType),
|
|
92
|
-
})) || [];
|
|
93
|
-
return options.filter((option) => option.children.length);
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const showDataSourceFieldSelect = ref(false);
|
|
99
|
-
|
|
100
|
-
watch(
|
|
101
|
-
() => props.model[props.name],
|
|
102
|
-
(value) => {
|
|
103
|
-
if (
|
|
104
|
-
Array.isArray(value) &&
|
|
105
|
-
typeof value[0] === 'string' &&
|
|
106
|
-
value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
|
|
107
|
-
) {
|
|
108
|
-
showDataSourceFieldSelect.value = true;
|
|
109
|
-
} else {
|
|
110
|
-
showDataSourceFieldSelect.value = false;
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
immediate: true,
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const mForm = inject<FormState | undefined>('mForm');
|
|
119
|
-
|
|
120
|
-
const type = computed((): string => {
|
|
121
|
-
let type = props.config.fieldConfig?.type;
|
|
122
|
-
if (typeof type === 'function') {
|
|
123
|
-
type = type(mForm, {
|
|
124
|
-
model: props.model,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (type === 'form') return '';
|
|
128
|
-
if (type === 'container') return '';
|
|
129
|
-
return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (props.config.items ? '' : 'text');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const tagName = computed(() => {
|
|
133
|
-
if (showDataSourceFieldSelect.value || !props.config.fieldConfig) {
|
|
134
|
-
return MCascader;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const component = resolveComponent(`m-${props.config.items ? 'form' : 'fields'}-${type.value}`);
|
|
138
|
-
if (typeof component !== 'string') return component;
|
|
139
|
-
return 'm-fields-text';
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const onChangeHandler = (value: any) => {
|
|
143
|
-
emit('change', value);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const editHandler = (id: string) => {
|
|
147
|
-
eventBus?.emit('edit-data-source', id);
|
|
148
|
-
};
|
|
149
|
-
</script>
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-data-source-fields">
|
|
3
|
-
<MagicTable :data="model[name]" :columns="fieldColumns"></MagicTable>
|
|
4
|
-
|
|
5
|
-
<div class="m-editor-data-source-fields-footer">
|
|
6
|
-
<TMagicButton size="small" :disabled="disabled" plain @click="newFromJsonHandler()">快速添加</TMagicButton>
|
|
7
|
-
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
<FloatingBox
|
|
11
|
-
v-model:visible="addDialogVisible"
|
|
12
|
-
v-model:width="width"
|
|
13
|
-
v-model:height="editorHeight"
|
|
14
|
-
:title="fieldTitle"
|
|
15
|
-
:position="boxPosition"
|
|
16
|
-
>
|
|
17
|
-
<template #body>
|
|
18
|
-
<MFormBox
|
|
19
|
-
label-width="80px"
|
|
20
|
-
:title="fieldTitle"
|
|
21
|
-
:config="dataSourceFieldsConfig"
|
|
22
|
-
:values="fieldValues"
|
|
23
|
-
:parentValues="model[name]"
|
|
24
|
-
:disabled="disabled"
|
|
25
|
-
@submit="fieldChange"
|
|
26
|
-
></MFormBox>
|
|
27
|
-
</template>
|
|
28
|
-
</FloatingBox>
|
|
29
|
-
|
|
30
|
-
<FloatingBox
|
|
31
|
-
v-model:visible="addFromJsonDialogVisible"
|
|
32
|
-
v-model:width="width"
|
|
33
|
-
v-model:height="editorHeight"
|
|
34
|
-
title="快速添加数据定义"
|
|
35
|
-
:position="boxPosition"
|
|
36
|
-
>
|
|
37
|
-
<template #body>
|
|
38
|
-
<MFormBox
|
|
39
|
-
:config="jsonFromConfig"
|
|
40
|
-
:values="jsonFromValues"
|
|
41
|
-
:disabled="disabled"
|
|
42
|
-
@submit="addFromJsonFromChange"
|
|
43
|
-
></MFormBox>
|
|
44
|
-
</template>
|
|
45
|
-
</FloatingBox>
|
|
46
|
-
</div>
|
|
47
|
-
</template>
|
|
48
|
-
|
|
49
|
-
<script setup lang="ts">
|
|
50
|
-
import { inject, Ref, ref } from 'vue';
|
|
51
|
-
|
|
52
|
-
import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
|
|
53
|
-
import { type FieldProps, type FormConfig, type FormState, MFormBox } from '@tmagic/form';
|
|
54
|
-
import type { DataSchema } from '@tmagic/schema';
|
|
55
|
-
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
56
|
-
import { getDefaultValueFromFields } from '@tmagic/utils';
|
|
57
|
-
|
|
58
|
-
import FloatingBox from '@editor/components/FloatingBox.vue';
|
|
59
|
-
import { useEditorContentHeight } from '@editor/hooks';
|
|
60
|
-
import { useNextFloatBoxPosition } from '@editor/hooks/use-next-float-box-position';
|
|
61
|
-
import type { Services } from '@editor/type';
|
|
62
|
-
|
|
63
|
-
defineOptions({
|
|
64
|
-
name: 'MFieldsDataSourceFields',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const props = withDefaults(
|
|
68
|
-
defineProps<
|
|
69
|
-
FieldProps<{
|
|
70
|
-
type: 'data-source-fields';
|
|
71
|
-
}>
|
|
72
|
-
>(),
|
|
73
|
-
{
|
|
74
|
-
disabled: false,
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const emit = defineEmits(['change']);
|
|
79
|
-
|
|
80
|
-
const services = inject<Services>('services');
|
|
81
|
-
|
|
82
|
-
const fieldValues = ref<Record<string, any>>({});
|
|
83
|
-
const fieldTitle = ref('');
|
|
84
|
-
|
|
85
|
-
const width = defineModel<number>('width', { default: 670 });
|
|
86
|
-
|
|
87
|
-
const newHandler = () => {
|
|
88
|
-
fieldValues.value = {};
|
|
89
|
-
fieldTitle.value = '新增属性';
|
|
90
|
-
calcBoxPosition();
|
|
91
|
-
addDialogVisible.value = true;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const fieldChange = ({ index, ...value }: Record<string, any>) => {
|
|
95
|
-
if (index > -1) {
|
|
96
|
-
props.model[props.name][index] = value;
|
|
97
|
-
} else {
|
|
98
|
-
props.model[props.name].push(value);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
addDialogVisible.value = false;
|
|
102
|
-
|
|
103
|
-
emit('change', props.model[props.name]);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const fieldColumns: ColumnConfig[] = [
|
|
107
|
-
{
|
|
108
|
-
label: '属性名称',
|
|
109
|
-
prop: 'title',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
label: '属性key',
|
|
113
|
-
prop: 'name',
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
label: '属性描述',
|
|
117
|
-
prop: 'description',
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
label: '默认值',
|
|
121
|
-
prop: 'defaultValue',
|
|
122
|
-
formatter(item, row) {
|
|
123
|
-
try {
|
|
124
|
-
return JSON.stringify(row.defaultValue);
|
|
125
|
-
} catch (e) {
|
|
126
|
-
return row.defaultValue;
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
label: '操作',
|
|
132
|
-
fixed: 'right',
|
|
133
|
-
actions: [
|
|
134
|
-
{
|
|
135
|
-
text: '编辑',
|
|
136
|
-
handler: (row: Record<string, any>, index: number) => {
|
|
137
|
-
fieldValues.value = {
|
|
138
|
-
...row,
|
|
139
|
-
index,
|
|
140
|
-
};
|
|
141
|
-
fieldTitle.value = `编辑${row.title}`;
|
|
142
|
-
calcBoxPosition();
|
|
143
|
-
addDialogVisible.value = true;
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
text: '删除',
|
|
148
|
-
buttonType: 'danger',
|
|
149
|
-
handler: async (row: Record<string, any>, index: number) => {
|
|
150
|
-
await tMagicMessageBox.confirm(`确定删除${row.title}(${row.name})?`, '提示');
|
|
151
|
-
props.model[props.name].splice(index, 1);
|
|
152
|
-
emit('change', props.model[props.name]);
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
const dataSourceFieldsConfig: FormConfig = [
|
|
160
|
-
{ name: 'index', type: 'hidden', filter: 'number', defaultValue: -1 },
|
|
161
|
-
{
|
|
162
|
-
name: 'type',
|
|
163
|
-
text: '数据类型',
|
|
164
|
-
type: 'select',
|
|
165
|
-
defaultValue: 'string',
|
|
166
|
-
options: [
|
|
167
|
-
{ text: '字符串', value: 'string' },
|
|
168
|
-
{ text: '数字', value: 'number' },
|
|
169
|
-
{ text: '布尔值', value: 'boolean' },
|
|
170
|
-
{ text: '对象', value: 'object' },
|
|
171
|
-
{ text: '数组', value: 'array' },
|
|
172
|
-
{ text: 'null', value: 'null' },
|
|
173
|
-
{ text: 'any', value: 'any' },
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: 'name',
|
|
178
|
-
text: '字段名称',
|
|
179
|
-
rules: [
|
|
180
|
-
{
|
|
181
|
-
required: true,
|
|
182
|
-
message: '请输入字段名称',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
validator: ({ value, callback }, { model, parent }) => {
|
|
186
|
-
const index = parent.findIndex((item: Record<string, any>) => item.name === value);
|
|
187
|
-
if ((model.index === -1 && index > -1) || (model.index > -1 && index > -1 && index !== model.index)) {
|
|
188
|
-
return callback(`属性key(${value})已存在`);
|
|
189
|
-
}
|
|
190
|
-
callback();
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: 'title',
|
|
197
|
-
text: '展示名称',
|
|
198
|
-
rules: [
|
|
199
|
-
{
|
|
200
|
-
required: true,
|
|
201
|
-
message: '请输入展示名称',
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
name: 'description',
|
|
207
|
-
text: '描述',
|
|
208
|
-
type: 'textarea',
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
name: 'defaultValue',
|
|
212
|
-
text: '默认值',
|
|
213
|
-
height: '200px',
|
|
214
|
-
parse: true,
|
|
215
|
-
type: (mForm: FormState | undefined, { model }: any) => {
|
|
216
|
-
if (model.type === 'number') return 'number';
|
|
217
|
-
if (model.type === 'boolean') return 'select';
|
|
218
|
-
if (model.type === 'string') return 'text';
|
|
219
|
-
|
|
220
|
-
return 'vs-code';
|
|
221
|
-
},
|
|
222
|
-
options: [
|
|
223
|
-
{ text: 'true', value: true },
|
|
224
|
-
{ text: 'false', value: false },
|
|
225
|
-
],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: 'enable',
|
|
229
|
-
text: '是否可用',
|
|
230
|
-
type: 'switch',
|
|
231
|
-
defaultValue: true,
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
name: 'fields',
|
|
235
|
-
type: 'data-source-fields',
|
|
236
|
-
defaultValue: [],
|
|
237
|
-
display: (formState: FormState | undefined, { model }: any) => model.type === 'object' || model.type === 'array',
|
|
238
|
-
},
|
|
239
|
-
];
|
|
240
|
-
|
|
241
|
-
const jsonFromConfig: FormConfig = [
|
|
242
|
-
{
|
|
243
|
-
name: 'data',
|
|
244
|
-
type: 'vs-code',
|
|
245
|
-
labelWidth: '0',
|
|
246
|
-
language: 'json',
|
|
247
|
-
height: '600px',
|
|
248
|
-
options: inject('codeOptions', {}),
|
|
249
|
-
},
|
|
250
|
-
];
|
|
251
|
-
|
|
252
|
-
const jsonFromValues = ref({
|
|
253
|
-
data: {},
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const newFromJsonHandler = () => {
|
|
257
|
-
jsonFromValues.value.data = getDefaultValueFromFields(props.model[props.name]);
|
|
258
|
-
calcBoxPosition();
|
|
259
|
-
addFromJsonDialogVisible.value = true;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const getValueType = (value: any) => {
|
|
263
|
-
if (Array.isArray(value)) return 'array';
|
|
264
|
-
if (value === null) return 'null';
|
|
265
|
-
if (typeof value === 'object') return 'object';
|
|
266
|
-
if (typeof value === 'number') return 'number';
|
|
267
|
-
if (typeof value === 'boolean') return 'boolean';
|
|
268
|
-
if (typeof value === 'string') return 'string';
|
|
269
|
-
|
|
270
|
-
return 'any';
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const getFieldsConfig = (value: any, fields: DataSchema[] = []) => {
|
|
274
|
-
if (!value || typeof value !== 'object') throw new Error('数据格式错误');
|
|
275
|
-
|
|
276
|
-
const newFields: DataSchema[] = [];
|
|
277
|
-
Object.entries(value).forEach(([key, value]) => {
|
|
278
|
-
const type = getValueType(value);
|
|
279
|
-
|
|
280
|
-
const oldField = fields.find((field) => field.name === key);
|
|
281
|
-
|
|
282
|
-
let childFields: DataSchema[] = [];
|
|
283
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
284
|
-
childFields = getFieldsConfig(value[0], oldField?.fields);
|
|
285
|
-
} else if (type === 'object') {
|
|
286
|
-
childFields = getFieldsConfig(value, oldField?.fields);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
newFields.push({
|
|
290
|
-
name: key,
|
|
291
|
-
title: oldField?.title || key,
|
|
292
|
-
type,
|
|
293
|
-
description: oldField?.description || '',
|
|
294
|
-
enable: oldField?.enable ?? true,
|
|
295
|
-
defaultValue: value,
|
|
296
|
-
fields: childFields,
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
return newFields;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const addFromJsonFromChange = ({ data }: { data: string }) => {
|
|
304
|
-
try {
|
|
305
|
-
const value = JSON.parse(data);
|
|
306
|
-
|
|
307
|
-
props.model[props.name] = getFieldsConfig(value, props.model[props.name]);
|
|
308
|
-
|
|
309
|
-
addFromJsonDialogVisible.value = false;
|
|
310
|
-
|
|
311
|
-
emit('change', props.model[props.name]);
|
|
312
|
-
} catch (e: any) {
|
|
313
|
-
tMagicMessage.error(e.message);
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
const addDialogVisible = defineModel<boolean>('visible', { default: false });
|
|
318
|
-
const addFromJsonDialogVisible = defineModel<boolean>('visible1', { default: false });
|
|
319
|
-
const { height: editorHeight } = useEditorContentHeight();
|
|
320
|
-
|
|
321
|
-
const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
|
|
322
|
-
const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
|
|
323
|
-
</script>
|