feat:iframe组件

This commit is contained in:
wangzenghua 2025-03-20 07:26:13 +01:00
parent cfde330ac0
commit 5e00d9ce21
3 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,39 @@
<template>
<iframe v-if="state.url" :src="state.url" frameborder="0" width="100%" height="100%" @load="onLoad"></iframe>
</template>
<script setup name="custom-iframe">
import { reactive, watch } from 'vue';
import { isExternal } from '@/utils/validate';
const props = defineProps({
url: {
type: String,
required: true,
},
});
const emit = defineEmits(['on-load']);
const state = reactive({
url: '',
loaded: false,
});
watch(
() => props.url,
(val) => {
if (isExternal(val)) {
state.url = val;
}
},
{
immediate: true,
}
);
const onLoad = () => {
state.loaded = true;
emit('on-load', state.loaded);
};
</script>

View File

@ -1,4 +1,5 @@
import SvgIcon from './svg-icon';
import CustomIframe from './custom-iframe';
import CustomTableOperate from './custom-table-operate';
import CustomTableTree from './custom-table-tree';
import CustomCarouselPicture from './custom-carousel-picture';
@ -16,6 +17,7 @@ import CustomEchartPie3d from './custom-echart-pie-3d';
export {
SvgIcon,
CustomIframe,
CustomTableOperate,
CustomTableTree,
CustomCarouselPicture,

View File

@ -45,7 +45,7 @@ export function isHttp(url) {
* @returns {Boolean}
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path);
return /^(http?:|https?:|mailto:|tel:)/.test(path);
}
/**