Skip to content

Commit

Permalink
🎉 version(architecture): v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ting-Code committed Aug 21, 2024
1 parent ec295f8 commit d4d3e39
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 32 deletions.
34 changes: 21 additions & 13 deletions .github/workflows/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ http {
# alias 或root 都是替换路径
# location /micro 则最后不加/
# location /micro/ 则最后加/
location /micro {
if ($request_filename ~* .*\.(?:htm|html)$) ## 配置页面不缓存html和htm结尾的文件
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
# 把匹配到的路径重写, 注意要以/结尾
alias /usr/share/nginx/html/micro;
# 默认首页
index index.html;
try_files $uri $uri/ /micro/index.html;
}
location /docs {
# location /micro {
# if ($request_filename ~* .*\.(?:htm|html)$) ## 配置页面不缓存html和htm结尾的文件
# {
# add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
# }
# # 把匹配到的路径重写, 注意要以/结尾
# alias /usr/share/nginx/html/micro;
# # 默认首页
# index index.html;
# try_files $uri $uri/ /micro/index.html;
# }
location /micro/docs {
if ($request_filename ~* .*\.(?:htm|html)$) ## 配置页面不缓存html和htm结尾的文件
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
Expand Down Expand Up @@ -118,10 +118,18 @@ http {
expires -1; # 首页一般没有强制缓存
add_header Cache-Control no-cache;

add_header "Access-Control-Allow-Origin" "*"; # 全局变量获得当前请求origin,带cookie的请求不支持*
add_header "Access-Control-Allow-Origin" $http_origin; # 全局变量获得当前请求origin,带cookie的请求不支持*
add_header "Access-Control-Allow-Methods" "*"; # 允许请求方法
add_header "Access-Control-Allow-Headers" "*"; # 允许请求的 header
}
location ~*\.(js|css|png|jpg|jpeg|gif|ico)$ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

root /usr/share/nginx/html/docs;
expires 30d;
}
}
}

20 changes: 10 additions & 10 deletions packages/apps/admin/mock/module/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const menu = {
icon: 'Box',
module: 'docs'
},
component: 'LAYOUT',
path: '/system',
// component: 'LAYOUT',
path: '/docs/system',
children: [
{
name: 'system_home',
path: '/system/home',
path: '/docs/system/home',
meta: {
title: 'Ting Library 介绍',
module: 'docs'
Expand All @@ -28,7 +28,7 @@ const menu = {
},
{
name: 'system_markdown',
path: '/system/markdown',
path: '/docs/system/markdown',
meta: {
title: '🔥文档的设计',
module: 'docs'
Expand All @@ -37,7 +37,7 @@ const menu = {
},
{
name: 'system_micro',
path: '/system/micro',
path: '/docs/system/micro',
meta: {
title: '🔥微前端',
module: 'docs'
Expand All @@ -46,7 +46,7 @@ const menu = {
},
{
name: 'system_404',
path: '/system/404',
path: '/docs/system/404',
meta: {
title: '404页面',
transition: true
Expand All @@ -62,12 +62,12 @@ const menu = {
icon: 'Coin',
module: 'docs'
},
component: 'LAYOUT',
path: '/performance',
// component: 'LAYOUT',
path: '/docs/performance',
children: [
{
name: 'performance_virtual_scroll',
path: '/performance/virtual-scroll',
path: '/docs/performance/virtual-scroll',
meta: {
title: '虚拟列表',
module: 'docs'
Expand All @@ -84,7 +84,7 @@ const menu = {
module: 'docs'
},
component: 'LAYOUT',
path: '/repackage',
path: '/docs/repackage',
children: [
{
name: 'repackage_home',
Expand Down
3 changes: 1 addition & 2 deletions packages/apps/admin/src/router/routerGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function createRouterGuards(router: Router) {
* @description 路由跳转前执行守卫
*/
router.beforeEach(async (to, from, next) => {
console.log('======== beforeEach =========', to)
NProgress.start()
// 登录后如果重定向失败即重定向到首页
if (from.path === LOGIN_PATH && to.name === ERROR_PAGE_NAME) {
Expand Down Expand Up @@ -64,7 +63,7 @@ export function createRouterGuards(router: Router) {
try {
const userStore = useUserStoreWidthOut()
const { auth, menu } = await getUserInfo()
const addRouters = generateRoutes(menu)
const addRouters = generateRoutes(transRouter(menu))
console.log('addRouters', addRouters, auth)
userStore.setAuth(auth)
userStore.setMenu(menu)
Expand Down
8 changes: 7 additions & 1 deletion packages/apps/admin/src/views/layouts/micro/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<template>
<micro-app :name="name" :url="url" :iframe="isIframe" router-mode="state" />
<micro-app
:name="name"
:url="url"
:baseroute="`/${name}/`"
:iframe="isIframe"
router-mode="native"
/>
</template>

<script setup lang="ts">
Expand Down
1 change: 1 addition & 0 deletions packages/apps/micro-docs/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ declare interface Window {
unmount: () => void
mount: () => void
__MICRO_APP_ENVIRONMENT__: boolean
__MICRO_APP_BASE_ROUTE__: string | undefined
}
3 changes: 2 additions & 1 deletion packages/apps/micro-docs/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export const asyncRoutes = [...routeModuleList]
//普通路由 无需验证权限
export const constantRouter: any[] = [...routeModuleList, ErrorPageRoute]

console.log('window.__MICRO_APP_BASE_ROUTE__', window.__MICRO_APP_BASE_ROUTE__)
// 创建路由
const router = createRouter({
// history: process.env.NODE_ENV === 'production' ? createWebHistory() : createWebHashHistory(),
history: createWebHistory(import.meta.env.PROD ? '/docs' : '/docs'),
history: createWebHistory(window.__MICRO_APP_BASE_ROUTE__ || '/docs/'),
routes: constantRouter as unknown as RouteRecordRaw[],
scrollBehavior() {
return { left: 0, top: 0 }
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/micro-docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd())
console.log(env, command)
return {
base: command === 'build' ? '/docs/' : '/docs/',
base: command === 'build' ? '/micro/docs/' : '/micro/docs/',
plugins: [
vue({
include: [/\.vue$/, /\.md$/] // markdown 兼容
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/system/src/hooks/micro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { error } from '@tingcode/utils'

// 'development' | 'production'
export const devMicroUrlMap = {
docs: 'http://localhost:8680/docs/',
docs: 'http://localhost:8680/micro/docs/',
micro: 'http://139.199.173.241/'
}
export const proMicroUrlMap = {
docs: 'http://139.199.173.241/docs/',
docs: 'http://139.199.173.241/micro/docs/',
micro: 'http://139.199.173.241/micro/'
}
const IFRAME = ['docs']
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/system/src/hooks/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum PageEnum {
REDIRECT = '/redirect',
REDIRECT_NAME = 'Redirect',
// 首页
BASE_HOME = '/system/home',
BASE_HOME = '/',
BASE_HOME_NAME = 'system_home',
// 错误
ERROR_PAGE_NAME = 'ErrorPage'
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/system/src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function checkWindow() {
*/
export function initMicroApp() {
microApp.start({
'router-mode': 'state'
'router-mode': 'native'
})
}
/**
Expand Down

0 comments on commit d4d3e39

Please sign in to comment.