mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-21 09:19:28 +08:00
style(editor): 代码块编辑中代码编辑器高度自动设置保持表单不出现滚动条
This commit is contained in:
parent
2a0680c707
commit
e577628852
@ -9,6 +9,7 @@
|
|||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
@submit="submitForm"
|
@submit="submitForm"
|
||||||
@error="errorHandler"
|
@error="errorHandler"
|
||||||
|
@open="openHandler"
|
||||||
></MFormDrawer>
|
></MFormDrawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -37,7 +38,10 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
|
||||||
const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
|
const columnWidth = computed(() => services?.uiService.get('columnWidth'));
|
||||||
|
const size = computed(() => (columnWidth.value ? columnWidth.value.center + columnWidth.value.right : 600));
|
||||||
|
|
||||||
|
const codeEditorHeight = ref('600px');
|
||||||
|
|
||||||
const defaultParamColConfig: ColumnConfig = {
|
const defaultParamColConfig: ColumnConfig = {
|
||||||
type: 'row',
|
type: 'row',
|
||||||
@ -104,6 +108,7 @@ const functionConfig = computed(() => [
|
|||||||
name: 'content',
|
name: 'content',
|
||||||
type: 'vs-code',
|
type: 'vs-code',
|
||||||
options: inject('codeOptions', {}),
|
options: inject('codeOptions', {}),
|
||||||
|
height: codeEditorHeight.value,
|
||||||
onChange: (formState: FormState | undefined, code: string) => {
|
onChange: (formState: FormState | undefined, code: string) => {
|
||||||
try {
|
try {
|
||||||
// 检测js代码是否存在语法错误
|
// 检测js代码是否存在语法错误
|
||||||
@ -129,6 +134,15 @@ const errorHandler = (error: any) => {
|
|||||||
|
|
||||||
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
|
||||||
|
|
||||||
|
const openHandler = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (fomDrawer.value) {
|
||||||
|
const height = fomDrawer.value?.bodyHeight - 468;
|
||||||
|
codeEditorHeight.value = `${height > 100 ? height : 600}px`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
show() {
|
show() {
|
||||||
fomDrawer.value?.show();
|
fomDrawer.value?.show();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<MagicCodeEditor
|
<MagicCodeEditor
|
||||||
:height="height"
|
:height="config.height"
|
||||||
:init-values="model[name]"
|
:init-values="model[name]"
|
||||||
:language="language"
|
:language="config.language"
|
||||||
:options="{
|
:options="{
|
||||||
...config.options,
|
...config.options,
|
||||||
readOnly: disabled,
|
readOnly: disabled,
|
||||||
@ -12,8 +12,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue';
|
|
||||||
|
|
||||||
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -41,9 +39,6 @@ const props = withDefaults(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const language = computed(() => props.config.language || 'javascript');
|
|
||||||
const height = computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
|
|
||||||
|
|
||||||
const save = (v: string) => {
|
const save = (v: string) => {
|
||||||
props.model[props.name] = v;
|
props.model[props.name] = v;
|
||||||
emit('change', v);
|
emit('change', v);
|
||||||
|
@ -62,6 +62,7 @@ export { default as DataSourceMethodSelect } from './fields/DataSourceMethodSele
|
|||||||
export { default as EventSelect } from './fields/EventSelect.vue';
|
export { default as EventSelect } from './fields/EventSelect.vue';
|
||||||
export { default as KeyValue } from './fields/KeyValue.vue';
|
export { default as KeyValue } from './fields/KeyValue.vue';
|
||||||
export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
|
export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
|
||||||
|
export { default as CodeBlockListPanel } from './layouts/sidebar/code-block/CodeBlockListPanel.vue';
|
||||||
export { default as PropsPanel } from './layouts/PropsPanel.vue';
|
export { default as PropsPanel } from './layouts/PropsPanel.vue';
|
||||||
export { default as ToolButton } from './components/ToolButton.vue';
|
export { default as ToolButton } from './components/ToolButton.vue';
|
||||||
export { default as ContentMenu } from './components/ContentMenu.vue';
|
export { default as ContentMenu } from './components/ContentMenu.vue';
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<Teleport to="body" :disabled="!fullScreen">
|
<Teleport to="body" :disabled="!fullScreen">
|
||||||
<div
|
<div
|
||||||
:class="`magic-code-editor-wrapper${fullScreen ? ' full-screen' : ''}`"
|
:class="`magic-code-editor-wrapper${fullScreen ? ' full-screen' : ''}`"
|
||||||
:style="!fullScreen && height ? `height: ${height}` : ''"
|
:style="!fullScreen && height ? `height: ${height}` : '100%'"
|
||||||
>
|
>
|
||||||
<TMagicButton
|
<TMagicButton
|
||||||
class="magic-code-editor-full-screen-icon"
|
class="magic-code-editor-full-screen-icon"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="m-editor">
|
<div class="m-editor" ref="content">
|
||||||
<slot name="header"></slot>
|
<slot name="header"></slot>
|
||||||
|
|
||||||
<slot name="nav"></slot>
|
<slot name="nav"></slot>
|
||||||
@ -67,6 +67,8 @@ const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
|
|||||||
const codeOptions = inject('codeOptions', {});
|
const codeOptions = inject('codeOptions', {});
|
||||||
const { editorService, uiService } = inject<Services>('services') || {};
|
const { editorService, uiService } = inject<Services>('services') || {};
|
||||||
|
|
||||||
|
const content = ref<HTMLDivElement>();
|
||||||
|
|
||||||
const root = computed(() => editorService?.get('root'));
|
const root = computed(() => editorService?.get('root'));
|
||||||
|
|
||||||
const pageLength = computed(() => editorService?.get('pageLength') || 0);
|
const pageLength = computed(() => editorService?.get('pageLength') || 0);
|
||||||
@ -91,13 +93,15 @@ watch(
|
|||||||
|
|
||||||
columnWidth.value.left = left;
|
columnWidth.value.left = left;
|
||||||
|
|
||||||
|
const container = content.value || document.body;
|
||||||
|
|
||||||
if (length <= 0) {
|
if (length <= 0) {
|
||||||
columnWidth.value.right = undefined;
|
columnWidth.value.right = undefined;
|
||||||
columnWidth.value.center = globalThis.document.body.clientWidth - left;
|
columnWidth.value.center = container.clientWidth - left;
|
||||||
} else {
|
} else {
|
||||||
const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
|
const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
|
||||||
columnWidth.value.right = right;
|
columnWidth.value.right = right;
|
||||||
columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
|
columnWidth.value.center = container.clientWidth - left - right;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiService?.set('columnWidth', columnWidth.value as GetColumnWidth);
|
uiService?.set('columnWidth', columnWidth.value as GetColumnWidth);
|
||||||
|
@ -9,12 +9,10 @@
|
|||||||
:close-on-click-modal="true"
|
:close-on-click-modal="true"
|
||||||
:size="width"
|
:size="width"
|
||||||
:zIndex="zIndex"
|
:zIndex="zIndex"
|
||||||
|
@open="openHandler"
|
||||||
|
@opened="openedHandler"
|
||||||
>
|
>
|
||||||
<div
|
<div v-if="visible" ref="drawerBody" class="m-drawer-body">
|
||||||
v-if="visible"
|
|
||||||
class="m-drawer-body"
|
|
||||||
:style="`max-height: ${bodyHeight}; overflow-y: auto; overflow-x: hidden;`"
|
|
||||||
>
|
|
||||||
<Form
|
<Form
|
||||||
ref="form"
|
ref="form"
|
||||||
:size="size"
|
:size="size"
|
||||||
@ -47,7 +45,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { ref, watchEffect } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, TMagicCol, TMagicDrawer, TMagicRow } from '@tmagic/design';
|
import { TMagicButton, TMagicCol, TMagicDrawer, TMagicRow } from '@tmagic/design';
|
||||||
|
|
||||||
@ -78,12 +76,19 @@ withDefaults(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const emit = defineEmits(['close', 'submit', 'error', 'change']);
|
const emit = defineEmits(['close', 'submit', 'error', 'change', 'open', 'opened']);
|
||||||
|
|
||||||
const form = ref<InstanceType<typeof Form>>();
|
const form = ref<InstanceType<typeof Form>>();
|
||||||
|
const drawerBody = ref<HTMLDivElement>();
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const saveFetch = ref(false);
|
const saveFetch = ref(false);
|
||||||
const bodyHeight = ref(`${document.body.clientHeight - 194}px`);
|
const bodyHeight = ref(0);
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if (drawerBody.value) {
|
||||||
|
bodyHeight.value = drawerBody.value.clientHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const submitHandler = async () => {
|
const submitHandler = async () => {
|
||||||
try {
|
try {
|
||||||
@ -98,6 +103,14 @@ const changeHandler = (value: any) => {
|
|||||||
emit('change', value);
|
emit('change', value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openHandler = (value: any) => {
|
||||||
|
emit('open', value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openedHandler = (value: any) => {
|
||||||
|
emit('opened', value);
|
||||||
|
};
|
||||||
|
|
||||||
const show = () => {
|
const show = () => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
};
|
};
|
||||||
@ -109,6 +122,7 @@ const hide = () => {
|
|||||||
defineExpose({
|
defineExpose({
|
||||||
form,
|
form,
|
||||||
saveFetch,
|
saveFetch,
|
||||||
|
bodyHeight,
|
||||||
|
|
||||||
show,
|
show,
|
||||||
hide,
|
hide,
|
||||||
|
@ -2,4 +2,10 @@
|
|||||||
.el-drawer__header {
|
.el-drawer__header {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.m-drawer-body {
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user