11<template >
2- <iframe class =" tiny-engine-iframe" :src =" tinyEngineUrl" ></iframe >
2+ <div class =" tiny-engine-app-visit" >
3+ <div id =" loading" class =" tiny-engine-loading" ></div >
4+ <iframe class =" tiny-engine-iframe" :src =" tinyEngineUrl" ></iframe >
5+ </div >
36</template >
47<script >
58import { TINY_ENGINE_DEFAULT_URL , TINY_ENGINE_DESIGNER_URL } from ' ../controller/utils'
69import { useRoute } from ' vue-router'
7- import { onMounted , onUnmounted } from ' vue'
10+ import { onMounted , onUnmounted , ref } from ' vue'
11+ import { Loading } from ' @opentiny/vue'
812
913export default {
1014 setup () {
1115 const route = useRoute ()
1216 const tinyEngineUrl = route .name === ' applicationVisit' ? TINY_ENGINE_DEFAULT_URL : TINY_ENGINE_DESIGNER_URL
17+
18+ const loadingInstance = ref (null )
1319 // 回调函数
14- const openAppNewTab = ( event ) => {
15- if (event .data .type === ' openNewTab' ) {
20+ const openAppNewTab = (event ) => {
21+ if (event .data .type === ' openNewTab' ) {
1622 const href = window .location .href .split (' ?' )[0 ]
1723 const searchParams = event .data .url .split (' ?' )[1 ]
1824 window .open (` ${ href} ?${ searchParams} ` )
1925 }
2026 }
21- window .addEventListener (" message" , openAppNewTab, false )
27+ window .addEventListener (' message' , openAppNewTab, false )
2228
2329 onMounted (() => {
2430 const url = new URL (window .location .href )
@@ -27,6 +33,15 @@ export default {
2733 const iframe = document .querySelector (' iframe' )
2834 iframe .src = ` ${ TINY_ENGINE_DESIGNER_URL } ?${ type} `
2935 }
36+ loadingInstance .value = Loading .service ({
37+ text: ' 加载中...' ,
38+ target: document .getElementById (' loading' ),
39+ size: ' large'
40+ })
41+ document .querySelector (' iframe' ).onload = function () {
42+ document .querySelector (' iframe' ).style .display = ' block'
43+ document .getElementById (' loading' ).style .display = ' none'
44+ }
3045 })
3146
3247 onUnmounted (() => {
@@ -39,9 +54,16 @@ export default {
3954}
4055 </script >
4156<style lang="less">
57+ .tiny-engine-app-visit {
58+ height : 100vh ;
59+ }
4260.tiny-engine-iframe {
4361 width : 100% ;
4462 height : 99% ;
4563 border : none ;
4664}
65+ .tiny-engine-loading {
66+ display : block ;
67+ height : 100vh ;
68+ }
4769 </style >
0 commit comments