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..a2764c4 --- /dev/null +++ b/apps/shell-vue-app/src/layout/index.vue @@ -0,0 +1,77 @@ + + + diff --git a/apps/shell-vue-app/src/main.ts b/apps/shell-vue-app/src/main.ts index 10dcab6..5612377 100644 --- a/apps/shell-vue-app/src/main.ts +++ b/apps/shell-vue-app/src/main.ts @@ -2,7 +2,28 @@ 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 +import { WUJIE_MESSAGE_CODE } from "../../../shared/constants/index.ts"; -createApp(App).use(WujieVue).mount('#app') +const app = createApp(App) + +const { bus } = WujieVue; + +bus.$on(WUJIE_MESSAGE_CODE.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; + 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/style.css b/apps/shell-vue-app/src/style.css index b0895f8..a8f385a 100644 --- a/apps/shell-vue-app/src/style.css +++ b/apps/shell-vue-app/src/style.css @@ -2,6 +2,14 @@ @tailwind components; @tailwind utilities; +:root { + --el-menu-text-color: #d7bbbb !important; + --el-menu-hover-text-color: #d7bbbb !important; + --el-menu-bg-color: #000 !important; + --el-menu-hover-bg-color: #378ae7 !important; + --el-menu-active-color: #ffffff !important; +} + html { @apply bg-slate-900 text-white; } 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/shell-vue-app/tsconfig.app.json b/apps/shell-vue-app/tsconfig.app.json index b8e9723..1bb6e5b 100644 --- a/apps/shell-vue-app/tsconfig.app.json +++ b/apps/shell-vue-app/tsconfig.app.json @@ -23,5 +23,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"] + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "../../shared/constants/**/*.ts"] } diff --git a/apps/vue-app/src/App.vue b/apps/vue-app/src/App.vue index 747f39b..d019d40 100644 --- a/apps/vue-app/src/App.vue +++ b/apps/vue-app/src/App.vue @@ -1,26 +1,25 @@ 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..5c497e5 100644 --- a/apps/vue-app/src/pages/index.vue +++ b/apps/vue-app/src/pages/index.vue @@ -4,7 +4,7 @@ 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/vue-app/tsconfig.app.json b/apps/vue-app/tsconfig.app.json index b8e9723..1bb6e5b 100644 --- a/apps/vue-app/tsconfig.app.json +++ b/apps/vue-app/tsconfig.app.json @@ -23,5 +23,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"] + "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "../../shared/constants/**/*.ts"] } diff --git a/apps/vue2-app/src/App.vue b/apps/vue2-app/src/App.vue index f848cd8..0943dc6 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..cb52d8a 100644 --- a/apps/vue2-app/src/pages/bar.vue +++ b/apps/vue2-app/src/pages/bar.vue @@ -3,7 +3,7 @@