gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!-- 网页 iframe 组件 (Ant Design Vue 版本) -->
<script lang="ts" setup>
import { computed } from 'vue';
 
import { isUrl } from '#/utils';
 
defineOptions({ name: 'IframeComponent' });
 
const props = withDefaults(defineProps<Props>(), {
  modelValue: '',
  value: '',
  url: '',
  height: '500px',
  width: '100%',
  frameborder: '0',
  allowfullscreen: true,
  loading: 'lazy',
  sandbox: '',
});
 
// 接受父组件参数
interface Props {
  modelValue?: string;
  value?: string;
  url?: string;
  height?: string;
  width?: string;
  frameborder?: string;
  allowfullscreen?: boolean;
  loading?: 'eager' | 'lazy';
  sandbox?: string;
  // eslint-disable-next-line vue/require-default-prop
  formCreateInject?: any;
}
 
// 显示的 URL(优先使用 url prop,其次使用 value 或 modelValue)
const displayUrl = computed(
  () => props.url || props.value || props.modelValue || '',
);
 
// 是否显示预览
const showPreview = computed(() => {
  return displayUrl.value && isUrl(displayUrl.value);
});
</script>
 
<template>
  <div class="iframe-component">
    <!-- iframe 预览 -->
    <div v-if="showPreview" class="iframe-preview">
      <iframe
        :src="displayUrl"
        :width="width"
        :height="height"
        :frameborder="frameborder"
        :allowfullscreen="allowfullscreen"
        :loading="loading"
        :sandbox="sandbox || undefined"
        class="iframe-content"
      ></iframe>
    </div>
 
    <!-- 无 URL 或无效 URL 提示 -->
    <div v-else class="iframe-placeholder">
      <a-empty description="请在右侧属性面板配置 URL 地址" />
    </div>
  </div>
</template>
 
<style scoped>
.iframe-component {
  width: 100%;
}
 
.iframe-preview {
  overflow: hidden;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
}
 
.iframe-content {
  display: block;
  border: none;
}
 
.iframe-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background-color: #fafafa;
  border: 1px dashed #d9d9d9;
  border-radius: 4px;
}
</style>