Explorar el Código

minor: 验证功能-qiankun

tuonian hace 2 meses
padre
commit
1edf882491

+ 4 - 0
frontend/README.md

@@ -155,3 +155,7 @@ wails build -webview2=embed
 ## 带debug
 wails build -webview2=embed -debug
 ```
+
+## 微应用支持
+### vite支持qiankun
+- 参考: https://github.com/lishaobos/vite-plugin-legacy-qiankun?tab=readme-ov-file

+ 8 - 6
frontend/package.json

@@ -1,7 +1,7 @@
 {
-  "name": "nginx-ui-react",
+  "name": "nginx-ui",
   "private": false,
-  "version": "0.1.1",
+  "version": "0.1.2",
   "license": "MIT",
   "author": {
     "email": "976056042@qq.com",
@@ -21,8 +21,9 @@
     "@mdx-js/mdx": "^2.0.0-rc.2",
     "@mdx-js/react": "^2.3.0",
     "@mdx-js/rollup": "^2.3.0",
-    "@micro-zoe/micro-app": "^1.0.0-rc.13",
     "@reduxjs/toolkit": "^1.9.5",
+    "@vitejs/plugin-legacy": "^6.0.0",
+    "@vitejs/plugin-react": "^4.3.4",
     "antd": "4.x",
     "artt-template": "^4.13.6",
     "auto-antd": "^0.1.11",
@@ -36,6 +37,7 @@
     "less": "^4.1.3",
     "lodash": "^4.17.21",
     "npm": "^9.8.0",
+    "qiankun": "^2.10.16",
     "query-string": "^8.1.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
@@ -45,7 +47,7 @@
     "redux-persist": "^6.0.0",
     "sass": "^1.80.3",
     "vite-plugin-cdn-import": "^1.0.1",
-    "wujie-react": "^1.0.22"
+    "vite-plugin-legacy-qiankun": "^0.0.12"
   },
   "devDependencies": {
     "@types/events": "^3.0.0",
@@ -55,13 +57,13 @@
     "@types/react-dom": "^18.0.11",
     "@typescript-eslint/eslint-plugin": "^5.59.0",
     "@typescript-eslint/parser": "^5.59.0",
-    "@vitejs/plugin-react-swc": "^3.0.0",
+    "@vitejs/plugin-react-swc": "^3.7.2",
     "consola": "^3.1.0",
     "eslint": "^8.38.0",
     "eslint-plugin-react-hooks": "^4.6.0",
     "eslint-plugin-react-refresh": "^0.3.4",
     "typescript": "^5.0.2",
-    "vite": "^4.3.9",
+    "vite": "5.4.6",
     "vite-plugin-md": "^0.21.5",
     "vite-plugin-mdx": "^3.5.11",
     "vite-plugin-qiankun": "^1.0.15",

+ 1 - 4
frontend/src/main.tsx

@@ -4,11 +4,8 @@ import './adapter/index.js'
 import App from './App.tsx'
 import './index.css'
 import './styles/index.less'
-import renderWithQiankun from "vite-plugin-qiankun/es/helper";
+import renderWithQiankun from "vite-plugin-qiankun/dist/helper";
 import './components/form/index.ts'
-import microApp from '@micro-zoe/micro-app'
-
-microApp.start()
 
 let root: Root | null
 

+ 2 - 6
frontend/src/pages/ldap/user/list/index.tsx

@@ -4,7 +4,6 @@ import {LDAP, LDAPApis} from "../../../../api/ldap.ts";
 import {ICurdConfig} from "../../../../components/curd/types.ts";
 import {Alert, Button} from "antd";
 import './index.less'
-import {Link} from "react-router-dom";
 import {useRouteLoaderData} from "react-router";
 import {SyncOutlined} from "@ant-design/icons";
 import {isNull, Message} from "auto-antd";
@@ -258,12 +257,9 @@ export const List = () => {
         })
     }
 
-    const operationRender = (record: LDAP.User, _: number) => {
-
+    const operationRender = () => {
         return (<>
-            <Button size="small">
-                <Link to={`server/${record.id}/user`}>重置密码</Link>
-            </Button>
+
         </>)
     }
 

+ 49 - 42
frontend/src/pages/microApp/index.tsx

@@ -5,15 +5,20 @@ import {ErrorComponent} from "../../components/error/Error.tsx";
 import {useAppDispatch, useAppSelector} from "../../store";
 import {LoadingText} from "../../components/loading";
 import {settingsActions} from "../../store/slice/settings.ts";
-// import {startApp} from "wujie";
+import {loadMicroApp, addGlobalUncaughtErrorHandler, removeGlobalUncaughtErrorHandler} from 'qiankun'
+import type {MicroApp} from "qiankun";
 
 // 腾讯无界: https://wujie-micro.github.io/doc/guide/start.html
+// https://qiankun.umijs.org/zh/guide/tutorial#%E4%B8%BB%E5%BA%94%E7%94%A8
 export const MicroAppPage = () => {
 
+    const isMounted = useRef(false)
     const params = useParams<{ id: string }>()
     const [error, setError] = useState<any>()
     const [loading, setLoading] = useState(true)
 
+    const microApp = useRef<MicroApp>()
+
     const routeMap = useAppSelector(state => state.user.routeMap)
     const dispatch = useAppDispatch();
     const domRef = useRef<HTMLDivElement>(null);
@@ -26,47 +31,48 @@ export const MicroAppPage = () => {
         dispatch(settingsActions.setFullScreen(full))
     }
 
-    // const destroyRef = useRef<any>()
-    // const onActivated = (e: any) => {
-    //     console.log('activated', e)
-    // }
-    //
-    // const onLoadFail = (url: any, e: any) => {
-    //     setLoading(false)
-    //     console.log('load fail', url)
-    //     setError(e)
-    // }
-    // const afterMounted = () => {
-    //     console.log('afterMounted', app)
-    // }
-
-    // const handleStartApp = () => {
-    //     if (!domRef.current || !app) {
-    //         return
-    //     }
-    //     console.log('startApp', app.path)
-    //     startApp({
-    //         name: app.id,
-    //         url: app.path,
-    //         alive: true,
-    //         el: domRef.current,
-    //         beforeMount: () => setLoading(true),
-    //         afterMount: afterMounted,
-    //         loadError: onLoadFail,
-    //         activated: onActivated,
-    //         degrade: true,
-    //         sync: true,
-    //     }).then(func=>{
-    //         destroyRef.current = func
-    //     }).catch(err=>{
-    //         console.log('startApp error ',err)
-    //     })
-    // }
+    useEffect(() => {
+        if (!domRef.current || !app) return;
+        console.log('app',app)
+        if (microApp.current){
+            console.log('MicroApp has init')
+            // return;
+        }
+        microApp.current = loadMicroApp({
+            name: app.id,
+            entry: app.path,
+            container: domRef.current,
+            props: {
+                root: `#micro-app-${app?.id}`
+            },
+        }, {
+            sandbox: false,
+            autoStart: true,
+        })
+        microApp.current.mountPromise.then(()=>{
+            console.log('MicroApp mounted')
+        }).catch(error=>{
+            setError(error)
+            console.log('mount error',error)
+        }).finally(()=>{
+            setLoading(false)
+        })
+    }, [app]);
 
     useEffect(() => {
+        isMounted.current = true;
         setFullScreen(true)
+        const errorHandler = (error: any) => {
+            console.log('load micro app fail',error)
+        }
+        addGlobalUncaughtErrorHandler(errorHandler)
         return ()=>{
+            isMounted.current = false
+            console.log('unload micro app',app?.id)
             setFullScreen(false)
+            removeGlobalUncaughtErrorHandler(errorHandler)
+            microApp.current?.unmount()
+            microApp.current = undefined
         }
     }, []);
 
@@ -74,13 +80,14 @@ export const MicroAppPage = () => {
     //     handleStartApp()
     // }, [domRef.current,app]);
 
-    return (<div id={'micro_app_'+app?.id} className="micro-app">
+    return (<div className="micro-app">
         <LoadingText loading={loading} text="加载中,请稍后..."/>
         {error ?<ErrorComponent noRedirect={true} error={error}/>: null}
-        <div className="micro-app-container" ref={domRef}>
-            <iframe src={app?.path} style={{width:'100%',height:'100%'}}
-                    onLoad={() => setLoading(false)}
-                    onError={e=>setError(e)}/>
+        <div id={`micro-app-${app?.id}`} className="micro-app-container" ref={domRef}>
+            {/*<iframe src={app?.path} style={{width:'100%',height:'100%'}}*/}
+            {/*        onLoad={() => setLoading(false)}*/}
+            {/*        onError={e=>setError(e)}/>*/}
+            {/*<micro-app name='my-app' url='http://localhost:3000/'></micro-app>*/}
         </div>
     </div>)
 }

+ 16 - 8
frontend/vite.config.ts

@@ -1,12 +1,12 @@
 import { defineConfig, loadEnv } from 'vite'
-import react from '@vitejs/plugin-react-swc'
+import react from '@vitejs/plugin-react'
 import {AntdResolve, createStyleImportPlugin} from "vite-plugin-style-import";
 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-// @ts-ignore
-import qiankun from 'vite-plugin-qiankun'
 import mdx from '@mdx-js/rollup'
 import * as path from 'path'
 import fse from 'fs-extra'
+import legacy from '@vitejs/plugin-legacy' // need this
+import { legacyQiankun } from 'vite-plugin-legacy-qiankun'
 
 
 const readDepInfo = (module: string) => {
@@ -37,10 +37,11 @@ export default defineConfig(({command, mode})=>{
       createStyleImportPlugin({
         resolves: [AntdResolve()]
       }),
-      qiankun('nginx-ui',{
-        useDevMode: mode != 'production'
-      }),
-
+        legacy(),
+        legacyQiankun({
+          name: 'nginx-ui',
+          devSandbox: true,
+        })
     ],
     css: {
       preprocessorOptions: {
@@ -64,11 +65,18 @@ export default defineConfig(({command, mode})=>{
             rewrite: path => path.replace(/^\/api/,"")
           }
         } : {
+          "/api/rdm/":{
+            // target: 'http://10.10.0.1:8080',
+            // target: 'http://10.10.0.1:38085',
+            target: 'http://127.0.0.1:38085',
+            rewrite: path => path.replace(/^\/api/,""),
+            ws: true
+          },
           "/api":{
             // target: 'http://10.10.0.1:8080',
             target: 'http://127.0.0.1:8080',
             rewrite: path => path.replace(/^\/api/,"")
-          }
+          },
         }
       }
     },

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 882 - 89
frontend/yarn.lock


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio