mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-24 09:02:10 +08:00
feat(editor): 属性面板支持切换源码
This commit is contained in:
parent
c83e76e641
commit
de1711d713
@ -12,17 +12,42 @@
|
|||||||
@change="submit"
|
@change="submit"
|
||||||
@error="errorHandler"
|
@error="errorHandler"
|
||||||
></MForm>
|
></MForm>
|
||||||
|
|
||||||
|
<TMagicButton
|
||||||
|
class="m-editor-props-panel-src-icon"
|
||||||
|
circle
|
||||||
|
size="large"
|
||||||
|
title="源码"
|
||||||
|
:icon="DocumentIcon"
|
||||||
|
:type="showSrc ? 'primary' : ''"
|
||||||
|
@click="showSrc = !showSrc"
|
||||||
|
></TMagicButton>
|
||||||
|
|
||||||
|
<CodeEditor
|
||||||
|
v-if="showSrc"
|
||||||
|
:height="`${editorContentHeight}px`"
|
||||||
|
:init-values="values"
|
||||||
|
:options="codeOptions"
|
||||||
|
:parse="true"
|
||||||
|
@save="saveCode"
|
||||||
|
></CodeEditor>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
|
import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
|
||||||
|
import { Document as DocumentIcon } from '@element-plus/icons-vue';
|
||||||
|
|
||||||
|
import { TMagicButton } from '@tmagic/design';
|
||||||
import type { FormState, FormValue } from '@tmagic/form';
|
import type { FormState, FormValue } from '@tmagic/form';
|
||||||
import { MForm } from '@tmagic/form';
|
import { MForm } from '@tmagic/form';
|
||||||
|
import type { MNode } from '@tmagic/schema';
|
||||||
|
|
||||||
|
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
||||||
import type { PropsPanelSlots, Services } from '@editor/type';
|
import type { PropsPanelSlots, Services } from '@editor/type';
|
||||||
|
|
||||||
|
import CodeEditor from './CodeEditor.vue';
|
||||||
|
|
||||||
defineSlots<PropsPanelSlots>();
|
defineSlots<PropsPanelSlots>();
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -33,8 +58,12 @@ defineProps<{
|
|||||||
extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const codeOptions = inject('codeOptions', {});
|
||||||
|
|
||||||
const emit = defineEmits(['mounted', 'submit-error', 'form-error']);
|
const emit = defineEmits(['mounted', 'submit-error', 'form-error']);
|
||||||
|
|
||||||
|
const showSrc = ref(false);
|
||||||
|
|
||||||
const internalInstance = getCurrentInstance();
|
const internalInstance = getCurrentInstance();
|
||||||
const values = ref<FormValue>({});
|
const values = ref<FormValue>({});
|
||||||
const configForm = ref<InstanceType<typeof MForm>>();
|
const configForm = ref<InstanceType<typeof MForm>>();
|
||||||
@ -46,6 +75,8 @@ const nodes = computed(() => services?.editorService.get('nodes') || []);
|
|||||||
const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
|
const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
|
||||||
const stage = computed(() => services?.editorService.get('stage'));
|
const stage = computed(() => services?.editorService.get('stage'));
|
||||||
|
|
||||||
|
const { height: editorContentHeight } = useEditorContentHeight();
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (!node.value) {
|
if (!node.value) {
|
||||||
curFormConfig.value = [];
|
curFormConfig.value = [];
|
||||||
@ -87,5 +118,9 @@ const errorHandler = (e: any) => {
|
|||||||
emit('form-error', e);
|
emit('form-error', e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveCode = (values: MNode) => {
|
||||||
|
services?.editorService.update(values);
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({ configForm, submit });
|
defineExpose({ configForm, submit });
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
.m-editor-props-panel {
|
.m-editor-props-panel {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
||||||
|
.m-editor-props-panel-src-icon {
|
||||||
|
position: absolute;
|
||||||
|
right: 15px;
|
||||||
|
bottom: 15px;
|
||||||
|
z-index: 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.magic-code-editor {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
&.small {
|
&.small {
|
||||||
.el-form-item__label {
|
.el-form-item__label {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user