@@ -29,6 +29,7 @@ const { t, locale: i18nLocale } = useI18n()
2929const   app =  getCurrentInstance ()?.appContext .app ;
3030
3131import  { setAsDarkTheme , getThemes , setTheme , getTheme  } from  ' ./theme' 
32+ import  { resolve  } from  ' path' 
3233
3334const   allThemes =  ref (getThemes ())
3435const   asDarkMode =  ref (Cache .GetPreference ().darkTheme )
@@ -109,9 +110,49 @@ const theme = ref(getTheme())
109110watch (theme , (e ) =>  {
110111    setTheme (e ) 
111112}) 
113+ 
114+ 
115+     const   loadPlugin =  async  ():  Promise <void > =>  { 
116+       try  { 
117+         //  动态加载CSS 
118+         const   css =  document .createElement (' link'  ); 
119+         css .rel  =  ' stylesheet'  ; 
120+         css .href  =  ' http://localhost:6060/atest-store-orm-ui.css'  ; 
121+         document .head .appendChild (css ); 
122+ 
123+         //  动态加载JS 
124+         await  new  Promise <void >((resolve , reject ) =>  { 
125+           const   script =  document .createElement (' script'  ); 
126+           script .src  =  ' http://localhost:6060/my-plugin.umd.js'  ; 
127+           script .onload  =  () =>  resolve (); 
128+           script .onerror  =  (err ) =>  reject (err ); 
129+           document .head .appendChild (script ); 
130+         }); 
131+ 
132+         //  类型安全的插件访问 
133+         const   plugin =  window .ATestPlugin ; 
134+          
135+         if  (plugin  &&  plugin .mount ) { 
136+           console .log (' 插件加载成功'  ); 
137+           plugin .mount (' #plugin-container'  , {  
138+             message: ' 来自宿主的消息'  
139+           }); 
140+         } 
141+       } catch  (error ) { 
142+         console .log (` 加载失败: ${(error  as  Error ).message } ` ) 
143+       } finally  { 
144+         console .log (' 插件加载完成'  ); 
145+       } 
146+     }; 
147+     try  { 
148+         loadPlugin (); 
149+     } catch  (error ) { 
150+         console .error (' 插件加载失败:'  , error ); 
151+     } 
112152 </script >
113153
114154<template >
155+     <div  id =" plugin-container"  ></div >
115156  <el-container  class =" full-height"  >
116157    <el-aside  width =" auto"   style =" display  : flex ; flex-direction  : column ;"  >
117158      <el-radio-group  v-model =" isCollapse"   class =" el-menu"  >
0 commit comments