Skip to content

Commit

Permalink
refactor(core): 抽离qiankun
Browse files Browse the repository at this point in the history
  • Loading branch information
szmxx committed Nov 16, 2023
1 parent c508ea1 commit dd465dc
Show file tree
Hide file tree
Showing 22 changed files with 5 additions and 250 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"mitt": "^3.0.1",
"nprogress": "^0.2.0",
"pinia": "^2.1.4",
"qiankun": "^2.10.11",
"universal-cookie": "^6.1.1",
"vue": "^3.3.4",
"vue-request": "^2.0.3",
Expand Down
32 changes: 2 additions & 30 deletions public/static/appConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,13 @@
"host": "192.168.55.197",
"port": 3000,
"path": "public"
},
"APP_LIST": [
{
"name": "star-map",
"entry": "//localhost:9528",
"container": "#subapp-viewport",
"activeRule": ["/star"]
},
{
"name": "ghss-demo",
"entry": "//localhost:8081",
"container": "#subapp-viewport",
"activeRule": ["/ghss"]
}
]
}
},
"production": {
"BASEURL": {
"host": "192.168.55.197",
"port": 3000,
"path": "public"
},
"APP_LIST": [
{
"name": "star-map",
"entry": "//localhost:9528",
"container": "#subapp-viewport",
"activeRule": ["/star"]
},
{
"name": "ghss-demo",
"entry": "//localhost:8081",
"container": "#subapp-viewport",
"activeRule": ["/ghss"]
}
]
}
}
}
15 changes: 1 addition & 14 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
<!--
* @Author: cola
* @Date: 2022-07-04 16:13:38
* @LastEditors: cola
* @Description:
-->

<template>
<router-view v-if="isSelfRoute"></router-view>
<LayoutPage v-else></LayoutPage>
<router-view></router-view>
</template>

<script lang="ts" setup>
import LayoutPage from '@/layout'
import { isSelfRouteFn } from '@/layout/utils'
// 是否是自身路由
const isSelfRoute = isSelfRouteFn()
console.log(import.meta.env.VITE_APP_NAME)
</script>
2 changes: 0 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getRefreshToken, getToken, setToken } from '@/utils/auth'
import Http from '@/utils/Http'
import { AxiosError, AxiosInstance } from 'axios'
import { refreshToken } from './auth'
import { RegistrableApp } from 'qiankun'
const REFRESH_WHITELIST = ['/auth/refreshToken', '/auth/sso']
const AUTH_WHITELIST = [
'/auth/login',
Expand Down Expand Up @@ -46,7 +45,6 @@ export interface AxiosConfig {
port: number
path?: string
}
APP_LIST: Array<RegistrableApp<Record<string, unknown>>>
}
const instanceMap: InstanceMap = {
base: null, // 当前系统ip下的请求
Expand Down
6 changes: 0 additions & 6 deletions src/components/DarkToggle.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
* @Author: cola
* @Date: 2023-09-09 00:59:50
* @LastEditors: cola
* @Description:
-->
<script setup lang="ts">
const theme = computed(() => currentTheme.value)
function toggleDark() {
Expand Down
7 changes: 0 additions & 7 deletions src/composables/theme.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-19 14:14:09
* @LastEditors: cola
* @Description:
*/

const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
darkModeMediaQuery.addListener((e) => {
useTheme(e.matches ? 'dark' : 'light')
Expand Down
8 changes: 0 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/*
* @Author: cola
* @Date: 2022-07-05 17:41:15
* @LastEditors: cola
* @Description:
*/
import {
initAxiosInstance,
initBusinessInstance,
AxiosConfig,
} from './api/index'
import { getAppConfig, AppConfig } from './api/public'
import useStore from '@/store/app'
import { initMicroApp } from './qiankun'
const envList = ['development', 'production']
function getRestConfig(config: AppConfig): AppConfig {
const res = Object.keys(config).reduce(
Expand All @@ -30,7 +23,6 @@ export default async () => {
const store = useStore()
const config = await getAppConfig()
const envConfig = config[import.meta.env.MODE] as AxiosConfig
initMicroApp(envConfig.APP_LIST)
initAxiosInstance(envConfig)
initBusinessInstance(envConfig)
const restConfig = getRestConfig(config)
Expand Down
16 changes: 1 addition & 15 deletions src/layout/LayoutPage.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
* @Author: cola
* @Date: 2022-07-05 16:16:23
* @LastEditors: cola
* @Description:
-->
<template>
<div class="flex flex-nowrap h-full w-full">
<div class="min-w-[220px] <sm:(absolute hidden)">
Expand All @@ -14,20 +8,12 @@
<slot>DEMO 系统</slot>
</div>
<div class="flex-1">
<router-view v-if="isSelfRoute"></router-view>
<section
v-else
id="subapp-viewport"
class="relative w-full h-full"
></section>
<router-view></router-view>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import LeftMenu from './components/LeftMenu.vue'
import { isSelfRouteFn } from '@/layout/utils'
// 是否是自身路由
const isSelfRoute = isSelfRouteFn()
</script>
6 changes: 0 additions & 6 deletions src/layout/components/LeftMenu.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
* @Author: cola
* @Date: 2022-07-24 12:31:32
* @LastEditors: cola
* @Description:
-->
<template>
<div class="h-full flex flex-col">
<MenuHeader></MenuHeader>
Expand Down
6 changes: 0 additions & 6 deletions src/layout/components/MenuHeader.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
* @Author: cola
* @Date: 2022-07-24 12:52:40
* @LastEditors: cola
* @Description:
-->
<template>
<div class="h-[60px] flex items-center p-4 border-b">
<div>{{ title }}</div>
Expand Down
6 changes: 0 additions & 6 deletions src/layout/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
/*
* @Author: cola
* @Date: 2022-07-04 19:03:36
* @LastEditors: cola
* @Description:
*/
import LayoutPage from './LayoutPage.vue'
export default LayoutPage
24 changes: 0 additions & 24 deletions src/layout/utils/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-04 16:13:38
* @LastEditors: cola
* @Description:
*/
import { createApp } from 'vue'
import App from './App.vue'
import install from '@/register'
Expand Down
6 changes: 0 additions & 6 deletions src/permission.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-10-31 11:08:30
* @LastEditors: cola
* @Description:
*/
import router from './route'
import NProgress from 'nprogress'
import { isEmpty, assign } from 'lodash-es'
Expand Down
55 changes: 0 additions & 55 deletions src/qiankun.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/register/directives/focus.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2023-09-09 11:41:50
* @LastEditors: cola
* @Description:
*/
export default {
mounted(el: HTMLElement, binding: Record<string, unknown>) {
if (binding.value) {
Expand Down
6 changes: 0 additions & 6 deletions src/register/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-05 10:22:47
* @LastEditors: cola
* @Description:
*/
import { App } from 'vue'
import './registerStyle'
import { install as installRouter } from '@/route'
Expand Down
6 changes: 0 additions & 6 deletions src/register/registerProperty.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-05 15:19:23
* @LastEditors: cola
* @Description:
*/
import Http from '@/utils/Http'
import { App } from 'vue'

Expand Down
6 changes: 0 additions & 6 deletions src/register/registerStyle.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-23 15:21:05
* @LastEditors: cola
* @Description:
*/
import '@unocss/reset/tailwind.css'
import 'nprogress/nprogress.css'
import 'uno.css'
Expand Down
25 changes: 1 addition & 24 deletions src/route/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2022-07-04 19:10:01
* @LastEditors: cola
* @Description:
*/
import {
createRouter,
RouteRecordRaw,
Expand All @@ -14,7 +8,6 @@ import HomePage from '@/views/home'
import ErrorPage from '@/views/error'
import routes from './routes'
import { App } from 'vue'
import useAppStore from '@/store/app'

export const ConstantRoutes: RouteRecordRaw[] = [
{
Expand Down Expand Up @@ -55,24 +48,8 @@ export function isNotFoundRoute(route: RouteLocationNormalized) {
? location.pathname.split('/')[1]
: location.pathname.split('/')[0]
pathname = '/' + pathname
const store = useAppStore()

const appRoutes = store.appList.reduce(
(acc: Record<string, unknown>[], cur) => {
let rules = cur.activeRule as string[]
if (!Array.isArray(rules)) {
rules = [rules]
}
rules.forEach((rule) => {
acc.push({
path: rule,
})
})
return acc
},
[],
)
const routes = [...router.getRoutes(), ...appRoutes]
const routes = [...router.getRoutes()]
for (let i = 0; i < routes.length; i++) {
// 路由表路径和本地一致,则是本地路由
if (routes[i].path === pathname) {
Expand Down
2 changes: 0 additions & 2 deletions src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default defineStore('app', {
},
getters: {
config: (state) => state._config,
appList: (state) =>
(state?._config?.APP_LIST || []) as Record<string, unknown>[],
},
actions: {
setConfig(config: AppConfig) {
Expand Down
Loading

0 comments on commit dd465dc

Please sign in to comment.