mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-06-04 10:58:33 +08:00
refactor(editor): 抽取 serializeConfig 工具统一序列化配置
将分散在 CodeLink、CodeEditor 及 playground 中重复的 serialize-javascript 序列化逻辑收敛为 @editor/utils/editor 的 serializeConfig 并对外导出复用。
This commit is contained in:
parent
64d35d5363
commit
1b66ab1b88
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, reactive, watch } from 'vue';
|
import { computed, reactive, watch } from 'vue';
|
||||||
import serialize from 'serialize-javascript';
|
|
||||||
|
|
||||||
import type { CodeLinkConfig, FieldProps, MLink } from '@tmagic/form';
|
import type { CodeLinkConfig, FieldProps, MLink } from '@tmagic/form';
|
||||||
|
|
||||||
import { getEditorConfig } from '@editor/utils/config';
|
import { getEditorConfig } from '@editor/utils/config';
|
||||||
|
import { serializeConfig } from '@editor/utils/editor';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'MFieldsCodeLink',
|
name: 'MFieldsCodeLink',
|
||||||
@ -47,10 +47,7 @@ watch(
|
|||||||
() => props.model[props.name],
|
() => props.model[props.name],
|
||||||
(value) => {
|
(value) => {
|
||||||
modelValue.form = {
|
modelValue.form = {
|
||||||
[props.name]: serialize(value, {
|
[props.name]: serializeConfig(value),
|
||||||
space: 2,
|
|
||||||
unsafe: true,
|
|
||||||
}).replace(/"(\w+)":\s/g, '$1: '),
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,12 +21,12 @@ import { computed, nextTick, onBeforeUnmount, onMounted, onUnmounted, ref, useTe
|
|||||||
import { FullScreen } from '@element-plus/icons-vue';
|
import { FullScreen } from '@element-plus/icons-vue';
|
||||||
import { throttle } from 'lodash-es';
|
import { throttle } from 'lodash-es';
|
||||||
import type * as Monaco from 'monaco-editor';
|
import type * as Monaco from 'monaco-editor';
|
||||||
import serialize from 'serialize-javascript';
|
|
||||||
|
|
||||||
import { TMagicButton } from '@tmagic/design';
|
import { TMagicButton } from '@tmagic/design';
|
||||||
|
|
||||||
import MIcon from '@editor/components/Icon.vue';
|
import MIcon from '@editor/components/Icon.vue';
|
||||||
import { getEditorConfig } from '@editor/utils/config';
|
import { getEditorConfig } from '@editor/utils/config';
|
||||||
|
import { serializeConfig } from '@editor/utils/editor';
|
||||||
import loadMonaco from '@editor/utils/monaco-editor';
|
import loadMonaco from '@editor/utils/monaco-editor';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -163,10 +163,7 @@ const toString = (v: string | any, language: string): string => {
|
|||||||
if (language === 'json') {
|
if (language === 'json') {
|
||||||
value = JSON.stringify(v, null, 2);
|
value = JSON.stringify(v, null, 2);
|
||||||
} else {
|
} else {
|
||||||
value = serialize(v, {
|
value = serializeConfig(v);
|
||||||
space: 2,
|
|
||||||
unsafe: true,
|
|
||||||
}).replace(/"(\w+)":\s/g, '$1: ');
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = v;
|
value = v;
|
||||||
|
|||||||
@ -48,11 +48,17 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, onBeforeUnmount, ref, shallowRef, toRaw } from 'vue';
|
import { computed, onBeforeUnmount, ref, shallowRef, toRaw } from 'vue';
|
||||||
import serialize from 'serialize-javascript';
|
|
||||||
|
|
||||||
import type { MApp, MContainer, MNode } from '@tmagic/core';
|
import type { MApp, MContainer, MNode } from '@tmagic/core';
|
||||||
import type { DatasourceTypeOption } from '@tmagic/editor';
|
import type { DatasourceTypeOption } from '@tmagic/editor';
|
||||||
import { editorService, propsService, TMagicDialog, TMagicEditor, tMagicMessage } from '@tmagic/editor';
|
import {
|
||||||
|
editorService,
|
||||||
|
propsService,
|
||||||
|
serializeConfig,
|
||||||
|
TMagicDialog,
|
||||||
|
TMagicEditor,
|
||||||
|
tMagicMessage,
|
||||||
|
} from '@tmagic/editor';
|
||||||
|
|
||||||
import DeviceGroup from '../components/DeviceGroup.vue';
|
import DeviceGroup from '../components/DeviceGroup.vue';
|
||||||
import componentGroupList from '../configs/componentGroupList';
|
import componentGroupList from '../configs/componentGroupList';
|
||||||
@ -88,13 +94,7 @@ const previewUrl = computed(
|
|||||||
const { moveableOptions } = useEditorMoveableOptions(editor);
|
const { moveableOptions } = useEditorMoveableOptions(editor);
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
localStorage.setItem(
|
localStorage.setItem('magicDSL', serializeConfig(toRaw(value.value)));
|
||||||
'magicDSL',
|
|
||||||
serialize(toRaw(value.value), {
|
|
||||||
space: 2,
|
|
||||||
unsafe: true,
|
|
||||||
}).replace(/"(\w+)":\s/g, '$1: '),
|
|
||||||
);
|
|
||||||
editor.value?.editorService.resetModifiedNodeId();
|
editor.value?.editorService.resetModifiedNodeId();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user