2026-07-21 21:18:29 +08:00

56 lines
1.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="m-editor-view-form-wrapper" :style="wrapperStyle">
<MForm
v-if="config.length"
ref="form"
class="m-editor-view-form"
:config="config"
:init-values="currentValues"
:disabled="disabled"
:label-width="labelWidth"
:extend-state="mergedExtendState"
:size="size"
></MForm>
</div>
</template>
<script lang="ts" setup>
import { type Ref, type ShallowRef } from 'vue';
import { type FormConfig, MForm } from '@tmagic/form';
import { useCompareForm } from '@editor/hooks/use-compare-form';
import type { CompareFormBaseProps } from '@editor/type';
defineOptions({
name: 'MEditorViewForm',
});
const props = withDefaults(
defineProps<
CompareFormBaseProps & {
/** 是否禁用表单(默认只读展示)。 */
disabled?: boolean;
}
>(),
{
category: 'node',
labelWidth: '120px',
disabled: true,
// extendState 的默认值由 useCompareForm 内部兜底props.extendState ?? ...),此处无需重复提供
},
);
const { config, currentValues, wrapperStyle, mergedExtendState, loadConfig, formRef } = useCompareForm(props);
defineExpose<{
form: ShallowRef<InstanceType<typeof MForm> | null>;
config: Ref<FormConfig>;
reload: () => Promise<void>;
}>({
form: formRef,
config,
reload: loadConfig,
});
</script>