<script lang="ts" setup>
|
import { computed, nextTick, ref, unref } from 'vue';
|
|
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
|
|
import Parser from '#/components/FormGenerator/src/components/Parser.vue';
|
import { $t } from '#/locales';
|
|
const props = defineProps(['formConf']);
|
defineEmits(['register']);
|
const [registerModal, { changeOkLoading }] = useModalInner(init);
|
const parserRef = ref<any>(null);
|
const loading = ref(true);
|
const key = ref(Date.now());
|
|
const getOkText = computed(() => {
|
const text = props.formConf.confirmButtonTextI18nCode
|
? $t(props.formConf.confirmButtonTextI18nCode, props.formConf.confirmButtonText)
|
: props.formConf.confirmButtonText;
|
return text || $t('common.okText');
|
});
|
const getCancelText = computed(() => {
|
const text = props.formConf.cancelButtonTextI18nCode
|
? $t(props.formConf.cancelButtonTextI18nCode, props.formConf.cancelButtonText)
|
: props.formConf.cancelButtonText;
|
return text || $t('common.cancelText');
|
});
|
|
function init() {
|
loading.value = true;
|
key.value = Date.now();
|
nextTick(() => {
|
loading.value = false;
|
});
|
}
|
function getParser() {
|
const parser = unref(parserRef);
|
if (!parser) {
|
throw new Error('parser is null!');
|
}
|
return parser;
|
}
|
|
function handleConfirm() {
|
getParser().handleSubmit();
|
}
|
function submitForm(data, callback) {
|
changeOkLoading(true);
|
// eslint-disable-next-line no-console
|
console.log('提交数据:', data);
|
if (callback && typeof callback === 'function') callback();
|
changeOkLoading(false);
|
}
|
</script>
|
<template>
|
<BasicModal
|
v-bind="$attrs"
|
@register="registerModal"
|
:title="$t('common.previewText')"
|
@ok="handleConfirm"
|
can-fullscreen
|
destroy-on-close
|
:ok-text="getOkText"
|
:cancel-text="getCancelText">
|
<Parser ref="parserRef" :form-conf="formConf" @submit="submitForm" :key="key" v-if="!loading" />
|
</BasicModal>
|
</template>
|