ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<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>