From 44f109b881222a7beced5e2c04441a468e8ed202 Mon Sep 17 00:00:00 2001 From: lizi Date: Wed, 24 Jul 2024 11:19:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=BE=AE=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/shell-vue-app/package.json | 2 + apps/shell-vue-app/src/App.vue | 132 +--------------- apps/shell-vue-app/src/layout/index.vue | 87 +++++++++++ apps/shell-vue-app/src/main.ts | 24 ++- apps/shell-vue-app/src/pages/common/index.vue | 50 ++++++ apps/shell-vue-app/src/router/index.ts | 73 +++++++++ apps/shell-vue-app/src/utils/common.ts | 10 ++ apps/shell-vue-app/src/utils/index.ts | 1 + apps/vue-app/src/App.vue | 57 +++---- apps/vue-app/src/main.ts | 4 - apps/vue-app/src/pages/index.vue | 10 +- apps/vue-app/src/router.ts | 15 +- apps/vue2-app/src/App.vue | 50 ++---- apps/vue2-app/src/main.ts | 5 - apps/vue2-app/src/pages/bar.vue | 10 +- apps/vue2-app/src/pages/foo.vue | 2 +- apps/vue2-app/src/pages/index.vue | 4 +- apps/vue2-app/src/router.ts | 27 ++-- pnpm-lock.yaml | 147 ++++++++++++++++++ 19 files changed, 472 insertions(+), 238 deletions(-) create mode 100644 apps/shell-vue-app/src/layout/index.vue create mode 100644 apps/shell-vue-app/src/pages/common/index.vue create mode 100644 apps/shell-vue-app/src/router/index.ts create mode 100644 apps/shell-vue-app/src/utils/common.ts create mode 100644 apps/shell-vue-app/src/utils/index.ts diff --git a/apps/shell-vue-app/package.json b/apps/shell-vue-app/package.json index 263345a..ded9492 100644 --- a/apps/shell-vue-app/package.json +++ b/apps/shell-vue-app/package.json @@ -9,7 +9,9 @@ "preview": "vite preview" }, "dependencies": { + "element-plus": "^2.7.7", "vue": "^3.4.29", + "vue-router": "^4.4.0", "wujie-vue3": "^1.0.22" }, "devDependencies": { diff --git a/apps/shell-vue-app/src/App.vue b/apps/shell-vue-app/src/App.vue index d8ae8be..8864a8d 100644 --- a/apps/shell-vue-app/src/App.vue +++ b/apps/shell-vue-app/src/App.vue @@ -1,139 +1,9 @@ diff --git a/apps/shell-vue-app/src/layout/index.vue b/apps/shell-vue-app/src/layout/index.vue new file mode 100644 index 0000000..29f835d --- /dev/null +++ b/apps/shell-vue-app/src/layout/index.vue @@ -0,0 +1,87 @@ + + + diff --git a/apps/shell-vue-app/src/main.ts b/apps/shell-vue-app/src/main.ts index 10dcab6..cc9b892 100644 --- a/apps/shell-vue-app/src/main.ts +++ b/apps/shell-vue-app/src/main.ts @@ -2,7 +2,27 @@ import { createApp } from 'vue' import './style.css' import WujieVue from 'wujie-vue3' import App from './App.vue' +import router from './router/index.ts' +import ElementPlus from 'element-plus' +import 'element-plus/dist/index.css' -const { bus, setupApp, preloadApp, destroyApp } = WujieVue +const app = createApp(App) -createApp(App).use(WujieVue).mount('#app') +const { bus } = WujieVue; + +bus.$on("sub-route-change", (name: string, path: string) => { + const mainName = `${name}-sub`; + const mainPath = `/${name}-sub${path}`; + const currentName = router.currentRoute.value.name; + const currentPath = router.currentRoute.value.path; + console.log(555555555555, name, path, mainName, mainPath, currentName, currentPath) + if (mainName === currentName && mainPath !== currentPath) { + router.push({ path: mainPath }); + } +}); + +app.use(WujieVue) +app.use(ElementPlus) +app.use(router) + +app.mount('#app') diff --git a/apps/shell-vue-app/src/pages/common/index.vue b/apps/shell-vue-app/src/pages/common/index.vue new file mode 100644 index 0000000..6b649a3 --- /dev/null +++ b/apps/shell-vue-app/src/pages/common/index.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/apps/shell-vue-app/src/router/index.ts b/apps/shell-vue-app/src/router/index.ts new file mode 100644 index 0000000..af633c4 --- /dev/null +++ b/apps/shell-vue-app/src/router/index.ts @@ -0,0 +1,73 @@ +import { createRouter, createWebHistory } from "vue-router"; + +const Layout = () => import("../layout/index.vue"); +const Common = () => import("../pages/common/index.vue"); + +// 静态路由 +export const constantRoutes: any[] = [ + { + path: "/", + redirect: "/vue3-sub/index", + }, + + { + path: "/", + name: "/", + component: Layout, + children: [ + { + path: "/vue3", + name: "Vue3", + component: Common, + props: { + url: "//localhost:8001/", + alive: true, + name: "vue3" + }, + key: "vue3" + }, + { + path: "/vue2", + name: "Vue2", + component: Common, + props: { + url: "//localhost:8002/", + alive: true, + name: "vue2" + }, + key: "vue2" + }, + { + path: "/vue3-sub/:path", + name: "vue3-sub", + component: Common, + props: { + url: "//localhost:8001/", + alive: true, + name: "vue3" + }, + key: "vue3" + }, + { + path: "/vue2-sub/:path", + name: "vue2-sub", + component: Common, + props: { + url: "//localhost:8002/", + alive: true, + name: "vue2" + }, + key: "vue2" + } + ], + }, +]; + +const router = createRouter({ + history: createWebHistory(), + routes: constantRoutes, + // 刷新时,滚动条位置还原 + scrollBehavior: () => ({ left: 0, top: 0 }), +}); + +export default router; \ No newline at end of file diff --git a/apps/shell-vue-app/src/utils/common.ts b/apps/shell-vue-app/src/utils/common.ts new file mode 100644 index 0000000..4f0b456 --- /dev/null +++ b/apps/shell-vue-app/src/utils/common.ts @@ -0,0 +1,10 @@ +/** + * 判断是否是外部链接 + * + * @param {string} path + * @returns {Boolean} + */ +export function isExternal(path: string) { + const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path); + return isExternal; +} \ No newline at end of file diff --git a/apps/shell-vue-app/src/utils/index.ts b/apps/shell-vue-app/src/utils/index.ts new file mode 100644 index 0000000..a18f847 --- /dev/null +++ b/apps/shell-vue-app/src/utils/index.ts @@ -0,0 +1 @@ +export * from './common'; \ No newline at end of file diff --git a/apps/vue-app/src/App.vue b/apps/vue-app/src/App.vue index 747f39b..b7f4462 100644 --- a/apps/vue-app/src/App.vue +++ b/apps/vue-app/src/App.vue @@ -1,26 +1,24 @@ diff --git a/apps/vue-app/src/main.ts b/apps/vue-app/src/main.ts index e6f0aea..823de6b 100644 --- a/apps/vue-app/src/main.ts +++ b/apps/vue-app/src/main.ts @@ -13,10 +13,6 @@ if (window.__POWERED_BY_WUJIE__) { instance.mount('#app') window.$router = router window.$instance = instance - window.$wujie?.bus.$emit('addTab', 'vue3', '/') - router.afterEach((to) => { - window.$wujie?.bus.$emit('addTab', 'vue3', to.path) - }) } window.__WUJIE_UNMOUNT = () => { instance.unmount() diff --git a/apps/vue-app/src/pages/index.vue b/apps/vue-app/src/pages/index.vue index 2844e9b..b4f7122 100644 --- a/apps/vue-app/src/pages/index.vue +++ b/apps/vue-app/src/pages/index.vue @@ -1,10 +1,18 @@ + diff --git a/apps/vue-app/src/router.ts b/apps/vue-app/src/router.ts index 6a2ca69..19b17b2 100644 --- a/apps/vue-app/src/router.ts +++ b/apps/vue-app/src/router.ts @@ -1,9 +1,10 @@ -import Index from './pages/index.vue' -import Bar from './pages/bar.vue' -import Foo from './pages/foo.vue' +import Index from "./pages/index.vue"; +import Bar from "./pages/bar.vue"; +import Foo from "./pages/foo.vue"; export const routes = [ - { path: '/', component: Index }, - { path: '/foo', component: Foo }, - { path: '/Bar', component: Bar }, -] + { path: "/", redirect: "/index" }, + { path: "/index", component: Index }, + { path: "/foo", component: Foo }, + { path: "/Bar", component: Bar }, +]; diff --git a/apps/vue2-app/src/App.vue b/apps/vue2-app/src/App.vue index f848cd8..a5d0f60 100644 --- a/apps/vue2-app/src/App.vue +++ b/apps/vue2-app/src/App.vue @@ -1,22 +1,20 @@ - diff --git a/apps/vue2-app/src/main.ts b/apps/vue2-app/src/main.ts index 57e35bf..adf45e4 100644 --- a/apps/vue2-app/src/main.ts +++ b/apps/vue2-app/src/main.ts @@ -17,11 +17,6 @@ if (window.__POWERED_BY_WUJIE__) { instance = new Vue({ router, render: h => h(App), pinia }).$mount('#app') window.$router = router window.$instance = instance - window.$wujie?.bus.$emit('addTab', 'vue2', '/') - - router.afterEach((to) => { - window.$wujie?.bus.$emit('addTab', 'vue2', to.path) - }) } window.__WUJIE_UNMOUNT = () => { instance.$destroy() diff --git a/apps/vue2-app/src/pages/bar.vue b/apps/vue2-app/src/pages/bar.vue index 7dabfce..785762a 100644 --- a/apps/vue2-app/src/pages/bar.vue +++ b/apps/vue2-app/src/pages/bar.vue @@ -1,9 +1,17 @@ +