Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 52fe1c52
authored
Nov 21, 2025
by
Lin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:模版构建/依赖循环控制/
1 parent
5aaa7c62
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
2610 additions
and
110 deletions
apps/frontend-micro/venus-agent-assisent/.env.development
apps/frontend-micro/venus-agent-assisent/.env.production
apps/frontend-micro/venus-agent-assisent/.gitignore
apps/frontend-micro/venus-agent-assisent/README copy.md
apps/frontend-micro/venus-agent-assisent/Readme.md
apps/frontend-micro/venus-agent-assisent/env.d.ts
apps/frontend-micro/venus-agent-assisent/index.html
apps/frontend-micro/venus-agent-assisent/package.json
apps/frontend-micro/venus-agent-assisent/public/vite.svg
apps/frontend-micro/venus-agent-assisent/src/App.vue
apps/frontend-micro/venus-agent-assisent/src/main.ts
apps/frontend-micro/venus-agent-assisent/src/router/index.ts
apps/frontend-micro/venus-agent-assisent/src/style.css
apps/frontend-micro/venus-agent-assisent/src/utils/communication.ts
apps/frontend-micro/venus-agent-assisent/src/views/About.vue
apps/frontend-micro/venus-agent-assisent/src/views/Communication.vue
apps/frontend-micro/venus-agent-assisent/src/views/Home.vue
apps/frontend-micro/venus-agent-assisent/src/views/NotFound.vue
apps/frontend-micro/venus-agent-assisent/src/views/Settings.vue
apps/frontend-micro/venus-agent-assisent/src/views/User.vue
apps/frontend-micro/venus-agent-assisent/tsconfig.json
apps/frontend-micro/venus-agent-assisent/tsconfig.node.json
apps/frontend-micro/venus-agent-assisent/vite.config.ts
apps/frontend-micro/venus-base/env.d.ts
apps/frontend-micro/venus-base/src/api/index.ts
apps/frontend-micro/venus-base/src/api/test.ts
apps/frontend-micro/venus-base/src/config/center.ts
apps/frontend-micro/venus-base/src/config/gscrequest.ts
apps/frontend-micro/venus-base/src/layouts/BasicLayout.vue
apps/frontend-micro/venus-base/src/main.ts
apps/frontend-micro/venus-base/src/utils/request.ts
apps/frontend-micro/venus-base/src/views/Home.vue
apps/frontend-micro/venus-base/src/views/Login.vue
apps/frontend-micro/venus-base/tsconfig.json
apps/frontend-micro/venus-micro-app/src/views/Home.vue
packages/cli/src/index.ts
packages/cli/templates/vue/package.json
pnpm-lock.yaml
pnpm-workspace.yaml
apps/frontend-micro/venus-agent-assisent/.env.development
0 → 100644
View file @
52fe1c5
# 寮€鍙戠幆澧冮厤缃?
# 搴旂敤鍩烘湰淇℃伅
VITE_APP_NAME=寰簲鐢ㄦā鏉?VITE_APP_VERSION=1.0.0
# 寰簲鐢ㄥ悕绉帮紙涓庡熀搴ч厤缃繚鎸佷竴鑷达級
VITE_MICRO_APP_NAME=subapp-vue
# 鏈嶅姟绔彛
VITE_PORT=8081
# API 鍩虹璺緞
VITE_API_BASE_URL=http://localhost:3000/api
VITE_API_TIMEOUT=30000
# 璺敱鍩虹璺緞
VITE_BASE_URL=/subapp-vue
VITE_ROUTER_BASE=/subapp-vue
# 寰簲鐢ㄨ闂矾寰?VITE_PUBLIC_PATH=http://localhost:8081/
# 鏄惁涓哄紑鍙戞ā寮?VITE_USE_DEV_MODE=true
# 鏄惁鍚敤Mock鏁版嵁
VITE_USE_MOCK=false
# 鏄惁鍚敤璋冭瘯妯″紡
VITE_DEBUG=true
# 鍩哄骇搴旂敤鍦板潃
VITE_MAIN_APP_URL=http://localhost:8080
# 鏂囦欢涓婁紶鍦板潃
VITE_UPLOAD_URL=http://localhost:3000/api/upload
# 寮€鍙戠幆澧冩爣璇?NODE_ENV=development
apps/frontend-micro/venus-agent-assisent/.env.production
0 → 100644
View file @
52fe1c5
# 鐢熶骇鐜閰嶇疆
# 鐢熶骇鐜鍩虹璺緞
VITE_BASE_URL=/subapp-vue/
apps/frontend-micro/venus-agent-assisent/.gitignore
0 → 100644
View file @
52fe1c5
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Auto-generated files
src/auto-imports.d.ts
src/components.d.ts
apps/frontend-micro/venus-agent-assisent/README copy.md
0 → 100644
View file @
52fe1c5
# Vue3 微前端子应用模板
> 基于 qiankun + Vue3 + Vite + TypeScript 构建的微前端子应用模板
## 📋 目录
-
[
功能特性
](
#功能特性
)
-
[
技术栈
](
#技术栈
)
-
[
快速开始
](
#快速开始
)
-
[
项目结构
](
#项目结构
)
-
[
与基座联调
](
#与基座联调
)
-
[
配置说明
](
#配置说明
)
-
[
开发指南
](
#开发指南
)
## ✨ 功能特性
-
🚀
**快速启动**
- 使用 Vite 构建,HMR 响应迅速
-
🎯
**独立运行**
- 支持独立开发和集成运行两种模式
-
🔧
**开箱即用**
- 集成路由、状态管理、自动导入等功能
-
💡
**TypeScript**
- 完整的类型支持,开发更安全
-
🎨
**现代化 UI**
- 精心设计的用户界面和交互体验
-
🔌
**qiankun 集成**
- 完整实现 qiankun 生命周期钩子
## 🛠️ 技术栈
-
**Vue 3**
- 渐进式 JavaScript 框架
-
**TypeScript**
- 类型安全的 JavaScript 超集
-
**Vite**
- 新一代前端构建工具
-
**Vue Router**
- 官方路由管理器
-
**Pinia**
- 新一代状态管理库
-
**qiankun**
- 微前端框架
-
**vite-plugin-qiankun**
- Vite 的 qiankun 插件
## 🚀 快速开始
### 安装依赖
```
bash
pnpm install
```
### 启动开发服务器
```
bash
pnpm dev
```
访问
`http://localhost:8081`
即可查看应用(独立运行模式)
### 构建生产版本
```
bash
pnpm build
```
### 预览生产构建
```
bash
pnpm preview
```
## 📁 项目结构
```
micro-app-template/
├── src/
│ ├── views/ # 页面组件
│ │ ├── Home.vue # 首页
│ │ ├── About.vue # 关于页
│ │ ├── User.vue # 用户管理
│ │ ├── Settings.vue # 系统设置
│ │ └── NotFound.vue # 404 页面
│ ├── router/ # 路由配置
│ │ └── index.ts # 路由定义
│ ├── App.vue # 根组件
│ ├── main.ts # 入口文件(包含 qiankun 生命周期)
│ └── style.css # 全局样式
├── index.html # HTML 模板
├── vite.config.ts # Vite 配置(qiankun 集成)
├── tsconfig.json # TypeScript 配置
├── package.json # 项目配置
└── README.md # 项目文档
```
## 🔗 与基座联调
### ⚠️ 重要提示
在启动前,请确保配置正确(已在本次更新中修复):
**子应用配置检查:**
-
✅
`vite.config.ts`
- base 配置为
`http://localhost:8081/`
-
✅
`src/router/index.ts`
- 导出
`createRouter`
函数
-
✅
`src/main.ts`
- 动态创建路由实例
**基座配置检查:**
-
✅
`src/qiankun/apps.ts`
- entry 配置为
`http://localhost:8081`
-
✅
`src/views/MicroApp.vue`
- 包含
`<div id="subapp-container"></div>`
### 1. 启动子应用
```
bash
cd
apps/frontend-micro/micro-app-template
pnpm dev
```
子应用会在
`http://localhost:8081`
启动
**验证:**
-
访问
`http://localhost:8081`
应显示子应用
-
控制台显示 "独立运行模式"
### 2. 启动基座应用
```
bash
cd
apps/frontend-micro/scrm-base
pnpm dev
```
基座会在
`http://localhost:8080`
启动
**验证:**
-
控制台显示 "
[
qiankun
]
微前端框架已启动"
### 3. 在基座中访问子应用
访问
`http://localhost:8080/subapp-vue`
,基座会自动加载并挂载子应用
**预期结果:**
-
看到子应用内容(紫色渐变背景)
-
控制台显示生命周期日志
-
运行模式显示 "🔗 基座模式"
**详细测试步骤:**
请查看
[
`INTEGRATION_GUIDE.md`
](
./INTEGRATION_GUIDE.md
)
## ⚙️ 配置说明
### 修改子应用端口
在
`vite.config.ts`
中修改
`PORT`
常量:
```
typescript
const
PORT
=
8081
;
// 修改为你想要的端口
```
### 修改子应用名称
1.
在
`vite.config.ts`
中修改
`APP_NAME`
:
```
typescript
const
APP_NAME
=
'your-app-name'
;
```
2.
在基座的
`src/micro-apps.ts`
中添加或修改对应配置:
```
typescript
{
name
:
'your-app-name'
,
entry
:
'//localhost:8081'
,
container
:
'#subapp-container'
,
activeRule
:
'/your-app-name'
,
props
:
{
routerBase
:
'/your-app-name'
,
},
}
```
### 路由配置
子应用路由会自动添加基座传递的
`routerBase`
前缀。在独立运行时,路由base为
`/`
;在基座中运行时,路由base为基座配置的
`routerBase`
(如
`/subapp-vue`
)。
## 📝 开发指南
### 独立开发模式
子应用支持完全独立开发,无需启动基座:
```
bash
pnpm dev
```
访问
`http://localhost:8081`
进行开发调试
### 集成开发模式
需要测试与基座的集成时:
1.
启动子应用:
`pnpm dev`
2.
启动基座:在 scrm-base 目录执行
`pnpm dev`
3.
通过基座访问:
`http://localhost:8080/subapp-vue`
### qiankun 生命周期说明
子应用实现了以下 qiankun 生命周期钩子:
-
`bootstrap`
- 应用初始化,只执行一次
-
`mount`
- 应用挂载,每次进入都会执行
-
`unmount`
- 应用卸载,每次离开都会执行
-
`update`
- 应用更新(可选),主应用下发新 props 时触发
### 环境判断
使用以下方式判断应用是否在 qiankun 环境中运行:
```
typescript
import
{
qiankunWindow
}
from
'vite-plugin-qiankun/dist/helper'
;
if
(
qiankunWindow
.
__POWERED_BY_QIANKUN__
)
{
console
.
log
(
'在基座中运行'
);
}
else
{
console
.
log
(
'独立运行'
);
}
```
## 🔍 常见问题
### 1. 子应用无法加载(白屏)
**原因:**
-
子应用未启动
-
entry 地址配置错误
-
容器 ID 不存在
**解决:**
```
bash
# 确认子应用运行
curl http://localhost:8081
# 检查基座配置
# scrm-base/src/qiankun/apps.ts
entry:
'http://localhost:8081'
// ✅ 使用完整 URL
# 检查容器存在
# scrm-base/src/views/MicroApp.vue
<div
id
=
"subapp-container"
></div> // ✅ 必须存在
```
### 2. CORS 错误
**控制台显示:**
```
Access to fetch at 'http://localhost:8081/' has been blocked by CORS policy
```
**解决:**
-
确认子应用
`vite.config.ts`
中
`cors: true`
-
确认 headers 配置正确
-
重启子应用服务
### 3. 路由跳转异常
**原因:**
-
路由 base 配置错误
-
`routerBase`
未正确传递
**解决:**
```
typescript
// ✅ 已修复:子应用动态创建路由
const
routerBase
=
qiankunWindow
.
__POWERED_BY_QIANKUN__
?
(
props
.
routerBase
||
'/subapp-vue'
)
:
'/'
;
const
router
=
createRouter
(
routerBase
);
```
### 4. 样式冲突
-
qiankun 默认开启了样式隔离
-
建议使用 scoped 样式
-
可以在基座的
`start`
配置中调整样式隔离策略
### 5. 生命周期未触发
**原因:**
-
应用名称不一致
-
生命周期钩子未正确导出
**解决:**
```
typescript
// vite.config.ts
qiankun
(
'subapp-vue'
)
// 必须与基座配置一致
// main.ts
export
async
function
bootstrap
()
{
}
export
async
function
mount
(
props
)
{
}
export
async
function
unmount
(
props
)
{
}
```
**详细排查指南:**
请查看
[
`INTEGRATION_GUIDE.md`
](
./INTEGRATION_GUIDE.md
)
## 📄 License
MIT
## 🤝 贡献
欢迎提交 Issue 和 Pull Request!
apps/frontend-micro/venus-agent-assisent/Readme.md
0 → 100644
View file @
52fe1c5
# **APP_NAME**
该项目由 Venus CLI 脚手架生成,使用 Vite + Vue 3 + TypeScript。
apps/frontend-micro/venus-agent-assisent/env.d.ts
0 → 100644
View file @
52fe1c5
// / <reference types="vite/client" />
declare
module
'*.vue'
{
import
type
{
DefineComponent
}
from
'vue'
;
const
component
:
DefineComponent
<
{},
{},
any
>
;
export
default
component
;
}
// qiankun 相关类型
declare
global
{
interface
Window
{
__INJECTED_PUBLIC_PATH_BY_QIANKUN__
?:
string
;
__POWERED_BY_QIANKUN__
?:
boolean
;
}
}
export
{};
apps/frontend-micro/venus-agent-assisent/index.html
0 → 100644
View file @
52fe1c5
<!doctype html>
<html
lang=
"zh-CN"
>
<head>
<meta
charset=
"UTF-8"
/>
<link
rel=
"icon"
type=
"image/svg+xml"
href=
"/vite.svg"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
<title>
Vue3 微前端子应用
</title>
<meta
name=
"description"
content=
"基于 qiankun + Vue3 + Vite 的微前端子应用模板"
/>
</head>
<body>
<div
id=
"app"
></div>
<script
type=
"module"
src=
"/src/main.ts"
></script>
</body>
</html>
apps/frontend-micro/venus-agent-assisent/package.json
0 → 100644
View file @
52fe1c5
{
"name"
:
"@venus/venus-agent-assisent"
,
"version"
:
"1.0.0"
,
"description"
:
"Vue3 微前端子应用模板,用于与 qiankun 基座集成"
,
"private"
:
true
,
"type"
:
"module"
,
"scripts"
:
{
"dev"
:
"vite --port 8081 --host"
,
"build"
:
"vue-tsc && vite build"
,
"preview"
:
"vite preview --port 8081"
,
"type-check"
:
"vue-tsc --noEmit"
},
"dependencies"
:
{
"@vueuse/core"
:
"catalog:"
,
"axios"
:
"catalog:"
,
"pinia"
:
"catalog:"
,
"vue"
:
"catalog:"
,
"vue-router"
:
"catalog:"
},
"devDependencies"
:
{
"@types/node"
:
"catalog:"
,
"@vitejs/plugin-vue"
:
"catalog:"
,
"@vitejs/plugin-vue-jsx"
:
"catalog:"
,
"typescript"
:
"catalog:"
,
"unplugin-auto-import"
:
"catalog:"
,
"unplugin-vue-components"
:
"catalog:"
,
"vite"
:
"catalog:"
,
"vite-plugin-qiankun"
:
"catalog:"
,
"vue-tsc"
:
"catalog:"
}
}
apps/frontend-micro/venus-agent-assisent/public/vite.svg
0 → 100644
View file @
52fe1c5
<svg
xmlns=
"http://www.w3.org/2000/svg"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
aria-hidden=
"true"
role=
"img"
class=
"iconify iconify--logos"
width=
"31.88"
height=
"32"
preserveAspectRatio=
"xMidYMid meet"
viewBox=
"0 0 256 257"
><defs><linearGradient
id=
"IconifyId1813088fe1fbc01fb466"
x1=
"-.828%"
x2=
"57.636%"
y1=
"7.652%"
y2=
"78.411%"
><stop
offset=
"0%"
stop-color=
"#41D1FF"
></stop><stop
offset=
"100%"
stop-color=
"#BD34FE"
></stop></linearGradient><linearGradient
id=
"IconifyId1813088fe1fbc01fb467"
x1=
"43.376%"
x2=
"50.316%"
y1=
"2.242%"
y2=
"89.03%"
><stop
offset=
"0%"
stop-color=
"#FFEA83"
></stop><stop
offset=
"8.333%"
stop-color=
"#FFDD35"
></stop><stop
offset=
"100%"
stop-color=
"#FFA800"
></stop></linearGradient></defs><path
fill=
"url(#IconifyId1813088fe1fbc01fb466)"
d=
"M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"
></path><path
fill=
"url(#IconifyId1813088fe1fbc01fb467)"
d=
"M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"
></path></svg>
apps/frontend-micro/venus-agent-assisent/src/App.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
{
onMounted
}
from
'vue'
;
onMounted
(()
=>
{
console
.
log
(
'Vue3 微应用已挂载'
);
});
</
script
>
<
template
>
<div
id=
"micro-app"
class=
"micro-app-container"
>
<header
class=
"app-header"
>
<h1>
🚀 Vue3 微前端子应用
</h1>
<nav
class=
"nav-menu"
>
<router-link
to=
"/"
class=
"nav-link"
>
首页
</router-link>
<router-link
to=
"/about"
class=
"nav-link"
>
关于
</router-link>
<router-link
to=
"/communication"
class=
"nav-link"
>
通信示例
</router-link>
<router-link
to=
"/user"
class=
"nav-link"
>
用户管理
</router-link>
<router-link
to=
"/settings"
class=
"nav-link"
>
系统设置
</router-link>
</nav>
</header>
<main
class=
"app-main"
>
<router-view
v-slot=
"
{ Component }">
<transition
name=
"fade"
mode=
"out-in"
>
<component
:is=
"Component"
/>
</transition>
</router-view>
</main>
<footer
class=
"app-footer"
>
<p>
© 2025 Venus 微前端子应用模板
</p>
</footer>
</div>
</
template
>
<
style
scoped
>
.micro-app-container
{
display
:
flex
;
flex-direction
:
column
;
min-height
:
100vh
;
color
:
white
;
background
:
linear-gradient
(
135deg
,
#667eea
0%
,
#764ba2
100%
);
}
.app-header
{
padding
:
1.5rem
2rem
;
background
:
rgb
(
255
255
255
/
10%
);
border-bottom
:
1px
solid
rgb
(
255
255
255
/
20%
);
backdrop-filter
:
blur
(
10px
);
}
.app-header
h1
{
margin
:
0
0
1rem
;
font-size
:
1.8rem
;
font-weight
:
600
;
}
.nav-menu
{
display
:
flex
;
gap
:
1.5rem
;
}
.nav-link
{
padding
:
0.5rem
1rem
;
color
:
white
;
text-decoration
:
none
;
background
:
rgb
(
255
255
255
/
10%
);
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.nav-link
:hover
{
background
:
rgb
(
255
255
255
/
20%
);
transform
:
translateY
(
-2px
);
}
.nav-link.router-link-active
{
font-weight
:
600
;
background
:
rgb
(
255
255
255
/
30%
);
}
.app-main
{
flex
:
1
;
padding
:
2rem
;
}
.app-footer
{
padding
:
1rem
2rem
;
text-align
:
center
;
background
:
rgb
(
0
0
0
/
20%
);
border-top
:
1px
solid
rgb
(
255
255
255
/
10%
);
}
/* 路由过渡动画 */
.fade-enter-active
,
.fade-leave-active
{
transition
:
opacity
0.3s
ease
;
}
.fade-enter-from
,
.fade-leave-to
{
opacity
:
0
;
}
</
style
>
apps/frontend-micro/venus-agent-assisent/src/main.ts
0 → 100644
View file @
52fe1c5
import
type
{
QiankunProps
}
from
'vite-plugin-qiankun/dist/helper'
;
import
type
{
App
as
VueApp
}
from
'vue'
;
import
{
createApp
}
from
'vue'
;
import
{
createPinia
}
from
'pinia'
;
import
{
qiankunWindow
,
renderWithQiankun
,
}
from
'vite-plugin-qiankun/dist/helper'
;
import
App
from
'./App.vue'
;
import
{
createRouter
}
from
'./router'
;
import
'./style.css'
;
let
app
:
null
|
VueApp
<
Element
>
=
null
;
let
router
:
any
=
null
;
/**
* 渲染函数
* @param props qiankun 传递的参数
*/
async
function
render
(
props
:
QiankunProps
=
{})
{
const
{
container
}
=
props
;
app
=
createApp
(
App
);
// 配置 Pinia
app
.
use
(
createPinia
());
// 配置路由 - 根据是否在 qiankun 环境中使用不同的 base
const
routerBase
=
qiankunWindow
.
__POWERED_BY_QIANKUN__
?
props
.
routerBase
||
'/subapp-vue'
:
'/'
;
router
=
createRouter
(
routerBase
);
app
.
use
(
router
);
// 初始化通信管理器(仅在 qiankun 环境中)
if
(
qiankunWindow
.
__POWERED_BY_QIANKUN__
&&
props
.
onGlobalStateChange
)
{
const
{
subAppCommunication
}
=
await
import
(
'./utils/communication'
);
subAppCommunication
.
init
(
props
);
// 将通信管理器挂载到全局属性,方便组件使用
app
.
config
.
globalProperties
.
$communication
=
subAppCommunication
;
}
// 挂载应用
const
containerEl
=
container
?
container
.
querySelector
(
'#app'
)
:
document
.
querySelector
(
'#app'
);
if
(
containerEl
)
{
app
.
mount
(
containerEl
as
Element
);
}
else
{
console
.
error
(
'[Vue3 微应用] 挂载容器未找到'
);
}
}
/**
* 独立运行时
* 直接访问子应用时,不是通过基座加载
*/
if
(
!
qiankunWindow
.
__POWERED_BY_QIANKUN__
)
{
console
.
log
(
'独立运行模式'
);
render
();
}
/**
* qiankun 生命周期钩子 - bootstrap
* 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子
*/
export
async
function
bootstrap
()
{
console
.
log
(
'[Vue3 微应用] bootstrap'
);
}
/**
* qiankun 生命周期钩子 - mount
* 应用每次进入都会调用 mount 方法,通常在这里触发应用的渲染方法
*/
export
async
function
mount
(
props
:
QiankunProps
)
{
console
.
log
(
'Vue3 微应用 mount'
,
props
);
render
(
props
);
}
/**
* qiankun 生命周期钩子 - unmount
* 应用每次切出/卸载都会调用 unmount 方法
*/
export
async
function
unmount
(
props
:
QiankunProps
)
{
console
.
log
(
'[Vue3 微应用] unmount'
,
props
);
// 销毁通信管理器
if
(
qiankunWindow
.
__POWERED_BY_QIANKUN__
)
{
const
{
subAppCommunication
}
=
await
import
(
'./utils/communication'
);
subAppCommunication
.
destroy
();
}
if
(
app
)
{
app
.
unmount
();
app
=
null
;
}
if
(
router
)
{
router
=
null
;
}
}
/**
* qiankun 生命周期钩子 - update (可选)
* 主应用向子应用下发新的props时触发
*/
export
async
function
update
(
props
:
QiankunProps
)
{
console
.
log
(
'[Vue3 微应用] update'
,
props
);
}
// 使用 vite-plugin-qiankun 提供的渲染函数
renderWithQiankun
({
bootstrap
,
mount
,
unmount
,
update
,
});
apps/frontend-micro/venus-agent-assisent/src/router/index.ts
0 → 100644
View file @
52fe1c5
import
type
{
Router
,
RouteRecordRaw
}
from
'vue-router'
;
import
{
createRouter
as
_createRouter
,
createWebHistory
}
from
'vue-router'
;
const
routes
:
RouteRecordRaw
[]
=
[
{
path
:
'/'
,
name
:
'Home'
,
component
:
()
=>
import
(
'@/views/Home.vue'
),
meta
:
{
title
:
'首页'
,
},
},
{
path
:
'/about'
,
name
:
'About'
,
component
:
()
=>
import
(
'@/views/About.vue'
),
meta
:
{
title
:
'关于'
,
},
},
{
path
:
'/user'
,
name
:
'User'
,
component
:
()
=>
import
(
'@/views/User.vue'
),
meta
:
{
title
:
'用户管理'
,
},
},
{
path
:
'/settings'
,
name
:
'Settings'
,
component
:
()
=>
import
(
'@/views/Settings.vue'
),
meta
:
{
title
:
'系统设置'
,
},
},
{
path
:
'/communication'
,
name
:
'Communication'
,
component
:
()
=>
import
(
'@/views/Communication.vue'
),
meta
:
{
title
:
'通信示例'
,
},
},
{
path
:
'/:pathMatch(.*)*'
,
name
:
'NotFound'
,
component
:
()
=>
import
(
'@/views/NotFound.vue'
),
},
];
/**
* 创建路由实例
* @param base 路由 base 路径
*/
export
function
createRouter
(
base
:
string
=
'/'
):
Router
{
const
router
=
_createRouter
({
history
:
createWebHistory
(
base
),
routes
,
});
// 路由守卫
router
.
beforeEach
((
to
,
_from
,
next
)
=>
{
// 设置页面标题
if
(
to
.
meta
.
title
)
{
document
.
title
=
`
${
to
.
meta
.
title
}
- Vue3 微应用`
;
}
next
();
});
router
.
afterEach
((
to
,
from
)
=>
{
console
.
log
(
'[Vue3 微应用] 路由切换:'
,
from
.
path
,
'->'
,
to
.
path
);
});
return
router
;
}
apps/frontend-micro/venus-agent-assisent/src/style.css
0 → 100644
View file @
52fe1c5
/* 全局样式 */
*
{
box-sizing
:
border-box
;
}
:root
{
font-family
:
Inter
,
system-ui
,
Avenir
,
Helvetica
,
Arial
,
sans-serif
;
font-weight
:
400
;
line-height
:
1.5
;
color-scheme
:
light
dark
;
font-synthesis
:
none
;
text-rendering
:
optimizelegibility
;
-webkit-font-smoothing
:
antialiased
;
-moz-osx-font-smoothing
:
grayscale
;
}
html
,
body
{
width
:
100%
;
height
:
100%
;
padding
:
0
;
margin
:
0
;
}
body
{
display
:
flex
;
place-items
:
center
;
min-width
:
320px
;
min-height
:
100vh
;
margin
:
0
;
}
#app
{
width
:
100%
;
min-height
:
100vh
;
}
/* 滚动条样式 */
::-webkit-scrollbar
{
width
:
8px
;
height
:
8px
;
}
::-webkit-scrollbar-track
{
background
:
rgb
(
255
255
255
/
10%
);
}
::-webkit-scrollbar-thumb
{
background
:
rgb
(
255
255
255
/
30%
);
border-radius
:
4px
;
}
::-webkit-scrollbar-thumb:hover
{
background
:
rgb
(
255
255
255
/
50%
);
}
/* 选中文本样式 */
::selection
{
color
:
white
;
background
:
rgb
(
255
255
255
/
30%
);
}
/* 响应式 */
@media
(
max-width
:
768px
)
{
body
{
font-size
:
14px
;
}
}
apps/frontend-micro/venus-agent-assisent/src/utils/communication.ts
0 → 100644
View file @
52fe1c5
import
{
onUnmounted
}
from
'vue'
;
/**
* 全局状态接口定义(与基座保持一致)
*/
export
interface
GlobalState
{
config
:
{
apiBaseUrl
:
string
;
timeout
:
number
;
};
notifications
:
Notification
[];
theme
:
{
mode
:
'dark'
|
'light'
;
primaryColor
:
string
;
};
user
:
null
|
{
avatar
:
string
;
id
:
string
;
name
:
string
;
permissions
:
string
[];
role
:
string
;
};
}
/**
* 通知消息接口
*/
export
interface
Notification
{
from
?:
string
;
id
:
string
;
message
:
string
;
timestamp
:
number
;
title
:
string
;
type
:
'error'
|
'info'
|
'success'
|
'warning'
;
}
/**
* qiankun Props 类型定义
*/
export
interface
QiankunProps
{
[
key
:
string
]:
any
;
container
?:
HTMLElement
;
onGlobalStateChange
?:
(
callback
:
(
state
:
GlobalState
,
prev
:
GlobalState
)
=>
void
,
fireImmediately
?:
boolean
,
)
=>
void
;
routerBase
?:
string
;
setGlobalState
?:
(
state
:
Partial
<
GlobalState
>
)
=>
void
;
}
/**
* 子应用通信管理器
*/
class
SubAppCommunicationManager
{
private
currentState
:
GlobalState
|
null
=
null
;
// 缓存当前状态
private
listeners
:
Array
<
(
state
:
GlobalState
,
prev
:
GlobalState
)
=>
void
>
=
[];
private
props
:
null
|
QiankunProps
=
null
;
private
unsubscribe
:
(()
=>
void
)
|
null
=
null
;
/**
* 销毁
*/
destroy
()
{
if
(
this
.
unsubscribe
)
{
this
.
unsubscribe
();
this
.
unsubscribe
=
null
;
}
this
.
listeners
=
[];
this
.
props
=
null
;
console
.
log
(
'[子应用通信] 通信管理器已销毁'
);
}
/**
* 获取当前全局状态
*/
getCurrentState
():
GlobalState
|
null
{
return
this
.
currentState
;
}
/**
* 初始化通信管理器
* @param props qiankun 传递的 props
*/
init
(
props
:
QiankunProps
)
{
this
.
props
=
props
;
// 监听全局状态变化
if
(
props
.
onGlobalStateChange
)
{
const
unsubscribeFn
=
props
.
onGlobalStateChange
(
(
state
:
GlobalState
,
prev
:
GlobalState
)
=>
{
console
.
log
(
'[子应用通信] 全局状态变化:'
,
state
,
prev
);
// 缓存当前状态
this
.
currentState
=
state
;
// 触发所有监听器
this
.
listeners
.
forEach
((
listener
)
=>
{
listener
(
state
,
prev
);
});
},
true
,
// 立即触发,获取当前状态 - 这确保了微应用一加载就能获取主应用的数据
);
// 只在返回值是函数时才赋值
if
(
typeof
unsubscribeFn
===
'function'
)
{
this
.
unsubscribe
=
unsubscribeFn
;
}
}
console
.
log
(
'[子应用通信] 通信管理器初始化完成'
);
// 额外的保险措施:延迟一点再触发一次所有监听器,确保数据已经传递
setTimeout
(()
=>
{
if
(
this
.
props
?.
onGlobalStateChange
)
{
console
.
log
(
'[子应用通信] 二次确认全局状态同步'
);
}
},
100
);
}
/**
* 监听全局状态变化
* @param callback 回调函数
* @returns 取消监听的函数
*/
onStateChange
(
callback
:
(
state
:
GlobalState
,
prev
:
GlobalState
)
=>
void
,
):
()
=>
void
{
this
.
listeners
.
push
(
callback
);
// 如果已经有缓存的状态,立即调用一次回调
if
(
this
.
currentState
)
{
console
.
log
(
'[子应用通信] 立即触发回调,使用缓存的全局状态'
);
callback
(
this
.
currentState
,
{}
as
GlobalState
);
}
return
()
=>
{
const
index
=
this
.
listeners
.
indexOf
(
callback
);
if
(
index
!==
-
1
)
{
this
.
listeners
.
splice
(
index
,
1
);
}
};
}
/**
* 向基座发送通知
* @param notification 通知消息
*/
sendNotification
(
notification
:
Omit
<
Notification
,
'id'
|
'timestamp'
>
)
{
if
(
!
this
.
props
?.
setGlobalState
)
{
console
.
warn
(
'[子应用通信] 无法发送通知,setGlobalState 方法不可用'
);
return
;
}
// 获取当前通知列表(需要通过 props 或缓存获取)
// 这里简化处理,直接通过 state 添加
const
newNotification
:
Notification
=
{
...
notification
,
id
:
Date
.
now
().
toString
(),
timestamp
:
Date
.
now
(),
from
:
notification
.
from
||
'Vue子应用'
,
};
// 通过修改全局状态来添加通知
// 注意:这里需要基座的 communication manager 来处理通知添加逻辑
// 所以我们实际上是触发一个状态变化,让基座来处理
this
.
setGlobalState
({
notifications
:
[
newNotification
]
as
any
,
// 基座会合并到现有通知列表
});
}
/**
* 设置全局状态(向基座发送数据)
* @param state 要更新的状态
*/
setGlobalState
(
state
:
Partial
<
GlobalState
>
)
{
if
(
this
.
props
?.
setGlobalState
)
{
this
.
props
.
setGlobalState
(
state
);
console
.
log
(
'[子应用通信] 全局状态已更新:'
,
state
);
}
else
{
console
.
warn
(
'[子应用通信] setGlobalState 方法不可用'
);
}
}
}
// 导出单例
export
const
subAppCommunication
=
new
SubAppCommunicationManager
();
/**
* Vue 组合式 API - 使用全局状态
* @param callback 状态变化回调
*/
export
function
useGlobalState
(
callback
:
(
state
:
GlobalState
,
prev
:
GlobalState
)
=>
void
,
)
{
const
unsubscribe
=
subAppCommunication
.
onStateChange
(
callback
);
// 在组件卸载时自动取消订阅
onUnmounted
(()
=>
{
unsubscribe
();
});
return
unsubscribe
;
}
/**
* 便捷方法:发送通知到基座
*/
export
function
notify
(
type
:
Notification
[
'type'
],
title
:
string
,
message
:
string
,
)
{
subAppCommunication
.
sendNotification
({
type
,
title
,
message
,
});
}
apps/frontend-micro/venus-agent-assisent/src/views/About.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
// About 页面
</
script
>
<
template
>
<div
class=
"about-view"
>
<div
class=
"content-card"
>
<h1>
📖 关于本应用
</h1>
<section
class=
"section"
>
<h2>
技术栈
</h2>
<ul
class=
"tech-list"
>
<li><strong>
Vue 3
</strong>
- 渐进式 JavaScript 框架
</li>
<li><strong>
TypeScript
</strong>
- 类型安全的 JavaScript 超集
</li>
<li><strong>
Vite
</strong>
- 新一代前端构建工具
</li>
<li><strong>
Vue Router
</strong>
- 官方路由管理器
</li>
<li><strong>
Pinia
</strong>
- 新一代状态管理库
</li>
<li><strong>
qiankun
</strong>
- 微前端框架
</li>
</ul>
</section>
<section
class=
"section"
>
<h2>
功能特性
</h2>
<ul
class=
"feature-list"
>
<li>
✅ 支持独立运行和基座集成
</li>
<li>
✅ 完整的 TypeScript 支持
</li>
<li>
✅ 自动导入 API 和组件
</li>
<li>
✅ 热模块替换 (HMR)
</li>
<li>
✅ 路由懒加载
</li>
<li>
✅ CSS 样式隔离
</li>
</ul>
</section>
<section
class=
"section"
>
<h2>
快速开始
</h2>
<div
class=
"code-block"
>
<pre><code>
# 安装依赖
pnpm install
# 启动开发服务器
pnpm dev
# 构建生产版本
pnpm build
</code></pre>
</div>
</section>
</div>
</div>
</
template
>
<
style
scoped
>
.about-view
{
max-width
:
900px
;
margin
:
0
auto
;
}
.content-card
{
padding
:
2.5rem
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
}
.content-card
h1
{
margin
:
0
0
2rem
;
font-size
:
2rem
;
}
.section
{
margin-bottom
:
2rem
;
}
.section
h2
{
margin
:
0
0
1rem
;
font-size
:
1.5rem
;
color
:
rgb
(
255
255
255
/
95%
);
}
.tech-list
,
.feature-list
{
padding
:
0
;
margin
:
0
;
list-style
:
none
;
}
.tech-list
li
,
.feature-list
li
{
padding
:
0.5rem
0
;
line-height
:
1.6
;
opacity
:
0.9
;
}
.code-block
{
padding
:
1.5rem
;
overflow-x
:
auto
;
background
:
rgb
(
0
0
0
/
30%
);
border
:
1px
solid
rgb
(
255
255
255
/
10%
);
border-radius
:
0.5rem
;
}
.code-block
pre
{
margin
:
0
;
font-family
:
'Courier New'
,
monospace
;
font-size
:
0.9rem
;
line-height
:
1.6
;
}
.code-block
code
{
color
:
#a8e6cf
;
}
</
style
>
apps/frontend-micro/venus-agent-assisent/src/views/Communication.vue
0 → 100644
View file @
52fe1c5
This diff is collapsed.
Click to expand it.
apps/frontend-micro/venus-agent-assisent/src/views/Home.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
type
{
GlobalState
}
from
'@/utils/communication'
;
import
{
computed
,
ref
}
from
'vue'
;
import
{
useRoute
}
from
'vue-router'
;
import
{
notify
,
useGlobalState
}
from
'@/utils/communication'
;
import
{
qiankunWindow
}
from
'vite-plugin-qiankun/dist/helper'
;
const
route
=
useRoute
();
const
counter
=
ref
(
0
);
const
globalState
=
ref
<
GlobalState
|
null
>
(
null
);
const
runMode
=
computed
(()
=>
{
return
qiankunWindow
.
__POWERED_BY_QIANKUN__
?
'🔗 基座模式'
:
'🏠 独立模式'
;
});
const
currentRoute
=
computed
(()
=>
route
.
fullPath
);
const
increment
=
()
=>
{
counter
.
value
++
;
};
const
decrement
=
()
=>
{
counter
.
value
--
;
};
// 监听主应用传递的全局状态
if
(
qiankunWindow
.
__POWERED_BY_QIANKUN__
)
{
useGlobalState
((
state
,
prev
)
=>
{
console
.
log
(
'📥 接收到主应用数据:'
,
state
);
console
.
log
(
'📝 之前的数据:'
,
prev
);
globalState
.
value
=
state
;
});
}
// 发送测试通知到主应用
const
sendTestNotification
=
()
=>
{
notify
(
'success'
,
'来自微应用的通知'
,
`这是一条测试通知,发送时间:
${
new
Date
().
toLocaleTimeString
()}
`
,
);
};
</
script
>
<
template
>
<div
class=
"home-view"
>
<div
class=
"hero-section"
>
<h1
class=
"hero-title"
>
🎉 欢迎使用 Vue3 微前端子应用AAA
</h1>
<p
class=
"hero-subtitle"
>
基于 qiankun + Vue3 + Vite + TypeScript 构建
</p>
</div>
<div
class=
"cards-grid"
>
<div
class=
"card"
>
<div
class=
"card-icon"
>
🚀
</div>
<h3>
快速启动
</h3>
<p>
使用 Vite 构建,开发体验极速
</p>
</div>
<div
class=
"card"
>
<div
class=
"card-icon"
>
🎯
</div>
<h3>
独立运行
</h3>
<p>
支持独立开发和集成运行两种模式
</p>
</div>
<div
class=
"card"
>
<div
class=
"card-icon"
>
🔧
</div>
<h3>
开箱即用
</h3>
<p>
集成路由、状态管理等常用功能
</p>
</div>
<div
class=
"card"
>
<div
class=
"card-icon"
>
💡
</div>
<h3>
TypeScript
</h3>
<p>
完整的类型支持,开发更安全
</p>
</div>
<div
class=
"card"
>
<div
class=
"card-icon"
>
💡
</div>
<p>
{{
globalState
}}
</p>
</div>
</div>
<div
class=
"info-section"
>
<h2>
运行环境信息
</h2>
<div
class=
"info-content"
>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
运行模式:
</span>
<span
class=
"info-value"
>
{{
runMode
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
当前路由:
</span>
<span
class=
"info-value"
>
{{
currentRoute
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
计数器:
</span>
<span
class=
"info-value"
>
{{
counter
}}
</span>
<button
@
click=
"increment"
class=
"btn-primary"
>
+1
</button>
<button
@
click=
"decrement"
class=
"btn-secondary"
>
-1
</button>
</div>
</div>
</div>
<!-- 主应用数据展示 -->
<div
v-if=
"qiankunWindow.__POWERED_BY_QIANKUN__"
class=
"info-section"
>
<h2>
📡 主应用传递的数据
</h2>
<div
class=
"info-content"
>
<!-- 用户信息 -->
<div
v-if=
"globalState?.user"
class=
"data-group"
>
<h3
class=
"data-group-title"
>
👤 用户信息
</h3>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
用户ID:
</span>
<span
class=
"info-value"
>
{{
globalState
.
user
.
id
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
用户名:
</span>
<span
class=
"info-value"
>
{{
globalState
.
user
.
name
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
角色:
</span>
<span
class=
"info-value"
>
{{
globalState
.
user
.
role
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
权限:
</span>
<span
class=
"info-value"
>
{{
globalState
.
user
.
permissions
.
join
(
', '
)
}}
</span>
</div>
</div>
<!-- 主题配置 -->
<div
v-if=
"globalState?.theme"
class=
"data-group"
>
<h3
class=
"data-group-title"
>
🎨 主题配置
</h3>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
主题模式:
</span>
<span
class=
"info-value"
>
{{
globalState
.
theme
.
mode
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
主色调:
</span>
<span
class=
"info-value"
>
<span
:style=
"
{ color: globalState.theme.primaryColor }">
{{
globalState
.
theme
.
primaryColor
}}
</span>
</span>
</div>
</div>
<!-- 配置信息 -->
<div
v-if=
"globalState?.config"
class=
"data-group"
>
<h3
class=
"data-group-title"
>
⚙️ 配置信息
</h3>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
API地址:
</span>
<span
class=
"info-value"
>
{{
globalState
.
config
.
apiBaseUrl
}}
</span>
</div>
<div
class=
"info-item"
>
<span
class=
"info-label"
>
超时时间:
</span>
<span
class=
"info-value"
>
{{
globalState
.
config
.
timeout
}}
ms
</span>
</div>
</div>
<!-- 通知消息 -->
<div
v-if=
"
globalState?.notifications && globalState.notifications.length > 0
"
class=
"data-group"
>
<h3
class=
"data-group-title"
>
📢 通知消息 (
{{
globalState
.
notifications
.
length
}}
)
</h3>
<div
v-for=
"notification in globalState.notifications.slice(0, 3)"
:key=
"notification.id"
class=
"notification-item"
>
<span
class=
"notification-type"
:class=
"[notification.type]"
>
{{
notification
.
type
}}
</span>
<span
class=
"notification-title"
>
{{
notification
.
title
}}
</span>
<span
class=
"notification-from"
v-if=
"notification.from"
>
来自:
{{
notification
.
from
}}
</span>
</div>
</div>
<!-- 无数据提示 -->
<div
v-if=
"!globalState"
class=
"no-data"
>
<p>
⏳ 等待主应用数据...
</p>
</div>
</div>
<!-- 操作按钮 -->
<div
class=
"actions"
>
<button
@
click=
"sendTestNotification"
class=
"btn-action"
>
📤 发送测试通知到主应用
</button>
</div>
</div>
</div>
</
template
>
<
style
scoped
>
.home-view
{
max-width
:
1200px
;
margin
:
0
auto
;
}
.hero-section
{
padding
:
3rem
0
;
margin-bottom
:
3rem
;
text-align
:
center
;
}
.hero-title
{
margin-bottom
:
1rem
;
font-size
:
2.5rem
;
font-weight
:
700
;
}
.hero-subtitle
{
font-size
:
1.2rem
;
opacity
:
0.9
;
}
.cards-grid
{
display
:
grid
;
grid-template-columns
:
repeat
(
auto-fit
,
minmax
(
250px
,
1
fr
));
gap
:
1.5rem
;
margin-bottom
:
3rem
;
}
.card
{
padding
:
2rem
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
transition
:
all
0.3s
ease
;
}
.card
:hover
{
background
:
rgb
(
255
255
255
/
15%
);
box-shadow
:
0
10px
30px
rgb
(
0
0
0
/
20%
);
transform
:
translateY
(
-5px
);
}
.card-icon
{
margin-bottom
:
1rem
;
font-size
:
3rem
;
}
.card
h3
{
margin
:
0
0
0.5rem
;
font-size
:
1.3rem
;
}
.card
p
{
margin
:
0
;
opacity
:
0.8
;
}
.info-section
{
padding
:
2rem
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
}
.info-section
h2
{
margin
:
0
0
1.5rem
;
font-size
:
1.5rem
;
}
.info-content
{
display
:
flex
;
flex-direction
:
column
;
gap
:
1rem
;
}
.info-item
{
display
:
flex
;
gap
:
1rem
;
align-items
:
center
;
}
.info-label
{
min-width
:
100px
;
font-weight
:
600
;
}
.info-value
{
padding
:
0.5rem
1rem
;
font-family
:
monospace
;
background
:
rgb
(
255
255
255
/
10%
);
border-radius
:
0.5rem
;
}
.btn-primary
,
.btn-secondary
{
padding
:
0.5rem
1rem
;
font-weight
:
600
;
cursor
:
pointer
;
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-primary
{
color
:
white
;
background
:
rgb
(
76
175
80
/
80%
);
}
.btn-primary
:hover
{
background
:
rgb
(
76
175
80
/
100%
);
}
.btn-secondary
{
color
:
white
;
background
:
rgb
(
244
67
54
/
80%
);
}
.btn-secondary
:hover
{
background
:
rgb
(
244
67
54
/
100%
);
}
.data-group
{
padding
:
1rem
;
margin-bottom
:
1.5rem
;
background
:
rgb
(
255
255
255
/
5%
);
border-left
:
3px
solid
rgb
(
255
255
255
/
30%
);
border-radius
:
0.5rem
;
}
.data-group
:last-child
{
margin-bottom
:
0
;
}
.data-group-title
{
margin
:
0
0
1rem
;
font-size
:
1.1rem
;
font-weight
:
600
;
opacity
:
0.9
;
}
.notification-item
{
display
:
flex
;
gap
:
0.75rem
;
align-items
:
center
;
padding
:
0.75rem
;
margin-bottom
:
0.5rem
;
background
:
rgb
(
255
255
255
/
5%
);
border-radius
:
0.375rem
;
}
.notification-item
:last-child
{
margin-bottom
:
0
;
}
.notification-type
{
padding
:
0.25rem
0.5rem
;
font-size
:
0.75rem
;
font-weight
:
600
;
text-transform
:
uppercase
;
border-radius
:
0.25rem
;
}
.notification-type.success
{
color
:
rgb
(
76
175
80
);
background
:
rgb
(
76
175
80
/
20%
);
}
.notification-type.warning
{
color
:
rgb
(
255
152
0
);
background
:
rgb
(
255
152
0
/
20%
);
}
.notification-type.error
{
color
:
rgb
(
244
67
54
);
background
:
rgb
(
244
67
54
/
20%
);
}
.notification-type.info
{
color
:
rgb
(
33
150
243
);
background
:
rgb
(
33
150
243
/
20%
);
}
.notification-title
{
flex
:
1
;
font-weight
:
500
;
}
.notification-from
{
font-size
:
0.875rem
;
opacity
:
0.7
;
}
.no-data
{
padding
:
2rem
;
text-align
:
center
;
opacity
:
0.7
;
}
.no-data
p
{
margin
:
0
;
font-size
:
1.1rem
;
}
.actions
{
display
:
flex
;
gap
:
1rem
;
justify-content
:
center
;
margin-top
:
1.5rem
;
}
.btn-action
{
padding
:
0.75rem
1.5rem
;
font-size
:
1rem
;
font-weight
:
600
;
color
:
white
;
cursor
:
pointer
;
background
:
rgb
(
33
150
243
/
80%
);
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-action
:hover
{
background
:
rgb
(
33
150
243
/
100%
);
box-shadow
:
0
5px
15px
rgb
(
33
150
243
/
30%
);
transform
:
translateY
(
-2px
);
}
</
style
>
apps/frontend-micro/venus-agent-assisent/src/views/NotFound.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
{
useRouter
}
from
'vue-router'
;
const
router
=
useRouter
();
const
goHome
=
()
=>
{
router
.
push
(
'/'
);
};
</
script
>
<
template
>
<div
class=
"notfound-view"
>
<div
class=
"content-card"
>
<div
class=
"error-code"
>
404
</div>
<h1>
页面未找到
</h1>
<p>
抱歉,您访问的页面不存在或已被删除
</p>
<button
@
click=
"goHome"
class=
"btn-home"
>
🏠 返回首页
</button>
</div>
</div>
</
template
>
<
style
scoped
>
.notfound-view
{
display
:
flex
;
align-items
:
center
;
justify-content
:
center
;
max-width
:
600px
;
min-height
:
400px
;
margin
:
0
auto
;
}
.content-card
{
padding
:
3rem
;
text-align
:
center
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
}
.error-code
{
margin-bottom
:
1rem
;
font-size
:
6rem
;
font-weight
:
700
;
background
:
linear-gradient
(
45deg
,
#fff
,
rgb
(
255
255
255
/
60%
));
background-clip
:
text
;
-webkit-text-fill-color
:
transparent
;
}
.content-card
h1
{
margin
:
0
0
1rem
;
font-size
:
2rem
;
}
.content-card
p
{
margin
:
0
0
2rem
;
opacity
:
0.9
;
}
.btn-home
{
padding
:
0.75rem
2rem
;
font-size
:
1rem
;
font-weight
:
600
;
color
:
white
;
cursor
:
pointer
;
background
:
rgb
(
76
175
80
/
80%
);
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-home
:hover
{
background
:
rgb
(
76
175
80
/
100%
);
transform
:
translateY
(
-2px
);
}
</
style
>
apps/frontend-micro/venus-agent-assisent/src/views/Settings.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
{
reactive
}
from
'vue'
;
interface
Settings
{
darkMode
:
boolean
;
language
:
string
;
notifications
:
{
desktop
:
boolean
;
email
:
boolean
;
sms
:
boolean
;
};
security
:
{
sessionTimeout
:
number
;
twoFactor
:
boolean
;
};
theme
:
string
;
timezone
:
string
;
}
const
defaultSettings
:
Settings
=
{
theme
:
'purple'
,
darkMode
:
false
,
notifications
:
{
desktop
:
true
,
email
:
true
,
sms
:
false
,
},
language
:
'zh-CN'
,
timezone
:
'Asia/Shanghai'
,
security
:
{
twoFactor
:
false
,
sessionTimeout
:
30
,
},
};
const
settings
=
reactive
<
Settings
>
({
...
defaultSettings
});
const
saveSettings
=
()
=>
{
console
.
log
(
'保存设置:'
,
settings
);
alert
(
'设置已保存!'
);
};
const
resetSettings
=
()
=>
{
if
(
confirm
(
'确定要重置为默认设置吗?'
))
{
Object
.
assign
(
settings
,
defaultSettings
);
alert
(
'已重置为默认设置!'
);
}
};
</
script
>
<
template
>
<div
class=
"settings-view"
>
<div
class=
"content-card"
>
<h1>
⚙️ 系统设置
</h1>
<div
class=
"settings-grid"
>
<div
class=
"setting-group"
>
<h2>
🎨 主题设置
</h2>
<div
class=
"setting-item"
>
<label>
主题色:
</label>
<select
v-model=
"settings.theme"
class=
"select-input"
>
<option
value=
"purple"
>
紫色
</option>
<option
value=
"blue"
>
蓝色
</option>
<option
value=
"green"
>
绿色
</option>
<option
value=
"orange"
>
橙色
</option>
</select>
</div>
<div
class=
"setting-item"
>
<label>
暗黑模式:
</label>
<input
type=
"checkbox"
v-model=
"settings.darkMode"
class=
"checkbox-input"
/>
</div>
</div>
<div
class=
"setting-group"
>
<h2>
🔔 通知设置
</h2>
<div
class=
"setting-item"
>
<label>
桌面通知:
</label>
<input
type=
"checkbox"
v-model=
"settings.notifications.desktop"
class=
"checkbox-input"
/>
</div>
<div
class=
"setting-item"
>
<label>
邮件通知:
</label>
<input
type=
"checkbox"
v-model=
"settings.notifications.email"
class=
"checkbox-input"
/>
</div>
<div
class=
"setting-item"
>
<label>
短信通知:
</label>
<input
type=
"checkbox"
v-model=
"settings.notifications.sms"
class=
"checkbox-input"
/>
</div>
</div>
<div
class=
"setting-group"
>
<h2>
🌐 语言设置
</h2>
<div
class=
"setting-item"
>
<label>
界面语言:
</label>
<select
v-model=
"settings.language"
class=
"select-input"
>
<option
value=
"zh-CN"
>
简体中文
</option>
<option
value=
"en-US"
>
English
</option>
<option
value=
"ja-JP"
>
日本語
</option>
</select>
</div>
<div
class=
"setting-item"
>
<label>
时区:
</label>
<select
v-model=
"settings.timezone"
class=
"select-input"
>
<option
value=
"Asia/Shanghai"
>
北京时间 (UTC+8)
</option>
<option
value=
"America/New_York"
>
纽约时间 (UTC-5)
</option>
<option
value=
"Europe/London"
>
伦敦时间 (UTC+0)
</option>
</select>
</div>
</div>
<div
class=
"setting-group"
>
<h2>
🔒 安全设置
</h2>
<div
class=
"setting-item"
>
<label>
双因素认证:
</label>
<input
type=
"checkbox"
v-model=
"settings.security.twoFactor"
class=
"checkbox-input"
/>
</div>
<div
class=
"setting-item"
>
<label>
会话超时 (分钟):
</label>
<input
type=
"number"
v-model=
"settings.security.sessionTimeout"
class=
"number-input"
min=
"5"
max=
"120"
/>
</div>
</div>
</div>
<div
class=
"actions"
>
<button
@
click=
"saveSettings"
class=
"btn-save"
>
💾 保存设置
</button>
<button
@
click=
"resetSettings"
class=
"btn-reset"
>
🔄 重置默认
</button>
</div>
<div
class=
"current-settings"
>
<h3>
当前配置 (JSON)
</h3>
<pre>
{{
JSON
.
stringify
(
settings
,
null
,
2
)
}}
</pre>
</div>
</div>
</div>
</
template
>
<
style
scoped
>
.settings-view
{
max-width
:
1200px
;
margin
:
0
auto
;
}
.content-card
{
padding
:
2.5rem
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
}
.content-card
h1
{
margin
:
0
0
2rem
;
font-size
:
2rem
;
}
.settings-grid
{
display
:
grid
;
grid-template-columns
:
repeat
(
auto-fit
,
minmax
(
300px
,
1
fr
));
gap
:
2rem
;
margin-bottom
:
2rem
;
}
.setting-group
{
padding
:
1.5rem
;
background
:
rgb
(
255
255
255
/
5%
);
border
:
1px
solid
rgb
(
255
255
255
/
10%
);
border-radius
:
0.75rem
;
}
.setting-group
h2
{
margin
:
0
0
1rem
;
font-size
:
1.2rem
;
color
:
rgb
(
255
255
255
/
95%
);
}
.setting-item
{
display
:
flex
;
align-items
:
center
;
justify-content
:
space-between
;
margin-bottom
:
1rem
;
}
.setting-item
label
{
font-weight
:
500
;
}
.select-input
,
.number-input
{
padding
:
0.5rem
;
font-size
:
0.9rem
;
color
:
white
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
0.5rem
;
}
.number-input
{
width
:
80px
;
}
.checkbox-input
{
width
:
20px
;
height
:
20px
;
cursor
:
pointer
;
}
.actions
{
display
:
flex
;
gap
:
1rem
;
margin-bottom
:
2rem
;
}
.btn-save
,
.btn-reset
{
padding
:
0.75rem
2rem
;
font-weight
:
600
;
cursor
:
pointer
;
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-save
{
color
:
white
;
background
:
rgb
(
76
175
80
/
80%
);
}
.btn-save
:hover
{
background
:
rgb
(
76
175
80
/
100%
);
transform
:
translateY
(
-2px
);
}
.btn-reset
{
color
:
white
;
background
:
rgb
(
158
158
158
/
80%
);
}
.btn-reset
:hover
{
background
:
rgb
(
158
158
158
/
100%
);
transform
:
translateY
(
-2px
);
}
.current-settings
{
padding
:
1.5rem
;
background
:
rgb
(
0
0
0
/
30%
);
border
:
1px
solid
rgb
(
255
255
255
/
10%
);
border-radius
:
0.75rem
;
}
.current-settings
h3
{
margin
:
0
0
1rem
;
font-size
:
1.1rem
;
}
.current-settings
pre
{
margin
:
0
;
overflow-x
:
auto
;
font-family
:
'Courier New'
,
monospace
;
font-size
:
0.9rem
;
line-height
:
1.6
;
color
:
#a8e6cf
;
}
</
style
>
apps/frontend-micro/venus-agent-assisent/src/views/User.vue
0 → 100644
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
{
ref
}
from
'vue'
;
interface
User
{
active
:
boolean
;
email
:
string
;
id
:
number
;
name
:
string
;
role
:
'admin'
|
'guest'
|
'user'
;
}
const
users
=
ref
<
User
[]
>
([
{
id
:
1
,
name
:
'张三'
,
email
:
'zhangsan@example.com'
,
role
:
'admin'
,
active
:
true
,
},
{
id
:
2
,
name
:
'李四'
,
email
:
'lisi@example.com'
,
role
:
'user'
,
active
:
true
,
},
{
id
:
3
,
name
:
'王五'
,
email
:
'wangwu@example.com'
,
role
:
'user'
,
active
:
false
,
},
{
id
:
4
,
name
:
'赵六'
,
email
:
'zhaoliu@example.com'
,
role
:
'guest'
,
active
:
true
,
},
]);
const
addUser
=
()
=>
{
const
newUser
:
User
=
{
id
:
users
.
value
.
length
+
1
,
name
:
`新用户
${
users
.
value
.
length
+
1
}
`
,
email
:
`user
${
users
.
value
.
length
+
1
}
@example.com`
,
role
:
'user'
,
active
:
true
,
};
users
.
value
.
push
(
newUser
);
};
const
editUser
=
(
user
:
User
)
=>
{
console
.
log
(
'编辑用户:'
,
user
);
alert
(
`编辑用户:
${
user
.
name
}
`
);
};
const
deleteUser
=
(
id
:
number
)
=>
{
const
index
=
users
.
value
.
findIndex
((
u
)
=>
u
.
id
===
id
);
if
(
index
!==
-
1
&&
confirm
(
`确定要删除用户
${
users
.
value
[
index
].
name
}
吗?`
)
)
{
users
.
value
.
splice
(
index
,
1
);
}
};
</
script
>
<
template
>
<div
class=
"user-view"
>
<div
class=
"content-card"
>
<h1>
👥 用户管理
</h1>
<div
class=
"toolbar"
>
<button
@
click=
"addUser"
class=
"btn-add"
>
➕ 新增用户
</button>
</div>
<div
class=
"table-container"
>
<table
class=
"user-table"
>
<thead>
<tr>
<th>
ID
</th>
<th>
姓名
</th>
<th>
邮箱
</th>
<th>
角色
</th>
<th>
状态
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<tr
v-for=
"user in users"
:key=
"user.id"
>
<td>
{{
user
.
id
}}
</td>
<td>
{{
user
.
name
}}
</td>
<td>
{{
user
.
email
}}
</td>
<td>
<span
class=
"badge"
:class=
"`badge-$
{user.role}`">
{{
user
.
role
}}
</span>
</td>
<td>
<span
class=
"status"
:class=
"user.active ? 'status-active' : 'status-inactive'"
>
{{
user
.
active
?
'在线'
:
'离线'
}}
</span>
</td>
<td>
<button
@
click=
"editUser(user)"
class=
"btn-edit"
>
编辑
</button>
<button
@
click=
"deleteUser(user.id)"
class=
"btn-delete"
>
删除
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</
template
>
<
style
scoped
>
.user-view
{
max-width
:
1200px
;
margin
:
0
auto
;
}
.content-card
{
padding
:
2.5rem
;
background
:
rgb
(
255
255
255
/
10%
);
border
:
1px
solid
rgb
(
255
255
255
/
20%
);
border-radius
:
1rem
;
backdrop-filter
:
blur
(
10px
);
}
.content-card
h1
{
margin
:
0
0
1.5rem
;
font-size
:
2rem
;
}
.toolbar
{
margin-bottom
:
1.5rem
;
}
.btn-add
{
padding
:
0.75rem
1.5rem
;
font-weight
:
600
;
color
:
white
;
cursor
:
pointer
;
background
:
rgb
(
76
175
80
/
80%
);
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-add
:hover
{
background
:
rgb
(
76
175
80
/
100%
);
transform
:
translateY
(
-2px
);
}
.table-container
{
overflow-x
:
auto
;
}
.user-table
{
width
:
100%
;
border-collapse
:
collapse
;
}
.user-table
thead
{
background
:
rgb
(
255
255
255
/
10%
);
}
.user-table
th
,
.user-table
td
{
padding
:
1rem
;
text-align
:
left
;
border-bottom
:
1px
solid
rgb
(
255
255
255
/
10%
);
}
.user-table
th
{
font-weight
:
600
;
color
:
rgb
(
255
255
255
/
95%
);
}
.user-table
tbody
tr
{
transition
:
background
0.3s
ease
;
}
.user-table
tbody
tr
:hover
{
background
:
rgb
(
255
255
255
/
5%
);
}
.badge
{
padding
:
0.25rem
0.75rem
;
font-size
:
0.85rem
;
font-weight
:
600
;
border-radius
:
1rem
;
}
.badge-admin
{
background
:
rgb
(
244
67
54
/
80%
);
}
.badge-user
{
background
:
rgb
(
33
150
243
/
80%
);
}
.badge-guest
{
background
:
rgb
(
158
158
158
/
80%
);
}
.status
{
padding
:
0.25rem
0.75rem
;
font-size
:
0.85rem
;
font-weight
:
600
;
border-radius
:
1rem
;
}
.status-active
{
background
:
rgb
(
76
175
80
/
80%
);
}
.status-inactive
{
background
:
rgb
(
158
158
158
/
80%
);
}
.btn-edit
,
.btn-delete
{
padding
:
0.5rem
1rem
;
margin-right
:
0.5rem
;
font-weight
:
600
;
cursor
:
pointer
;
border
:
none
;
border-radius
:
0.5rem
;
transition
:
all
0.3s
ease
;
}
.btn-edit
{
color
:
white
;
background
:
rgb
(
33
150
243
/
80%
);
}
.btn-edit
:hover
{
background
:
rgb
(
33
150
243
/
100%
);
}
.btn-delete
{
color
:
white
;
background
:
rgb
(
244
67
54
/
80%
);
}
.btn-delete
:hover
{
background
:
rgb
(
244
67
54
/
100%
);
}
</
style
>
apps/frontend-micro/venus-agent-assisent/tsconfig.json
0 → 100644
View file @
52fe1c5
{
"compilerOptions"
:
{
"target"
:
"ES2020"
,
"jsx"
:
"preserve"
,
"lib"
:
[
"ES2020"
,
"DOM"
,
"DOM.Iterable"
],
"useDefineForClassFields"
:
true
,
/*
Path
Alias
*/
"baseUrl"
:
"."
,
"module"
:
"ESNext"
,
/*
Bundler
mode
*/
"moduleResolution"
:
"bundler"
,
"paths"
:
{
"@/*"
:
[
"src/*"
]
},
"resolveJsonModule"
:
true
,
"allowImportingTsExtensions"
:
true
,
/*
Linting
*/
"strict"
:
true
,
"noFallthroughCasesInSwitch"
:
true
,
"noUnusedLocals"
:
true
,
"noUnusedParameters"
:
true
,
"noEmit"
:
true
,
"isolatedModules"
:
true
,
"skipLibCheck"
:
true
},
"references"
:
[{
"path"
:
"./tsconfig.node.json"
}],
"include"
:
[
"src/**/*.ts"
,
"src/**/*.d.ts"
,
"src/**/*.tsx"
,
"src/**/*.vue"
]
}
apps/frontend-micro/venus-agent-assisent/tsconfig.node.json
0 → 100644
View file @
52fe1c5
{
"compilerOptions"
:
{
"composite"
:
true
,
"module"
:
"ESNext"
,
"moduleResolution"
:
"bundler"
,
"allowSyntheticDefaultImports"
:
true
,
"skipLibCheck"
:
true
},
"include"
:
[
"vite.config.ts"
]
}
apps/frontend-micro/venus-agent-assisent/vite.config.ts
0 → 100644
View file @
52fe1c5
import
{
resolve
}
from
'node:path'
;
import
vue
from
'@vitejs/plugin-vue'
;
import
vueJsx
from
'@vitejs/plugin-vue-jsx'
;
import
AutoImport
from
'unplugin-auto-import/vite'
;
import
Components
from
'unplugin-vue-components/vite'
;
import
{
defineConfig
}
from
'vite'
;
import
qiankun
from
'vite-plugin-qiankun'
;
const
PORT
=
8081
;
const
APP_NAME
=
'subapp-vue'
;
// 与基座配置的 name 一致
export
default
defineConfig
(({
mode
,
command
})
=>
{
const
isDev
=
mode
===
'development'
;
const
isServe
=
command
===
'serve'
;
return
{
base
:
isDev
&&
isServe
?
`http://localhost:
${
PORT
}
/`
:
`/
${
APP_NAME
}
/`
,
// 生产环境使用应用名作为基础路径
plugins
:
[
vue
(),
vueJsx
(),
// 自动导入 Vue 相关函数
AutoImport
({
imports
:
[
'vue'
,
'vue-router'
,
'pinia'
],
dts
:
'src/auto-imports.d.ts'
,
eslintrc
:
{
enabled
:
false
,
},
}),
// 自动导入组件
Components
({
dts
:
'src/components.d.ts'
,
}),
// qiankun 插件配置
qiankun
(
APP_NAME
,
{
useDevMode
:
isDev
,
// 根据实际环境动态设置
}),
],
resolve
:
{
alias
:
{
'@'
:
resolve
(
__dirname
,
'src'
),
},
},
server
:
{
port
:
PORT
,
cors
:
true
,
// 允许跨域
host
:
true
,
origin
:
`http://localhost:
${
PORT
}
`
,
// 设置资源加载的 origin
headers
:
{
'Access-Control-Allow-Origin'
:
'*'
,
// 允许所有来源
},
},
build
:
{
target
:
'esnext'
,
minify
:
false
,
// 开发环境不压缩,便于调试
cssCodeSplit
:
false
,
// css 不拆分
rollupOptions
:
{
output
:
{
// qiankun 需要的输出格式
format
:
'umd'
,
// UMD 库名称,必须与应用名称一致
name
:
`qiankunApp_
${
APP_NAME
.
replaceAll
(
'-'
,
'_'
)}
`
,
entryFileNames
:
'assets/[name].js'
,
chunkFileNames
:
'assets/[name].[hash].js'
,
assetFileNames
:
'assets/[name].[hash].[ext]'
,
},
},
},
};
});
apps/frontend-micro/venus-base/env.d.ts
View file @
52fe1c5
...
...
@@ -31,11 +31,23 @@ declare module 'glsk-common' {
}
}
declare
module
'glsk-toolkit'
{
export
class
Request
{
constructor
(
config
:
any
);
post
(
url
:
string
,
data
?:
any
,
config
?:
any
):
Promise
<
any
>
;
get
(
url
:
string
,
config
?:
any
):
Promise
<
any
>
;
put
(
url
:
string
,
data
?:
any
,
config
?:
any
):
Promise
<
any
>
;
delete
(
url
:
string
,
config
?:
any
):
Promise
<
any
>
;
[
key
:
string
]:
any
;
}
}
// 扩展 Window 接口,添加全局属性类型定义
declare
global
{
interface
Window
{
$fetchConfig
?:
any
;
// 配置中心返回的配置数据
$gscApi
?:
any
;
// glsk-toolkit Request 实例
/** @deprecated 已废弃,请使用 getGscApi() 从 '@/config/center' 获取实例 */
$gscApi
?:
any
;
// glsk-toolkit Request 实例(已废弃,使用模块级单例替代)
}
}
...
...
apps/frontend-micro/venus-base/src/api/index.ts
View file @
52fe1c5
/**
* API 统一导出
*/
export
*
from
'./user'
;
apps/frontend-micro/venus-base/src/api/test.ts
View file @
52fe1c5
import
{
gscPost
}
from
"./request"
import
gscPost
from
'@/config/gscrequest'
// 数据看板指标统计
export
function
getdataBoard
(
data
:
any
)
{
console
.
log
(
"
AAAAAAA调用
"
);
console
.
log
(
"
SSSSS
"
);
return
gscPost
(
"/dataBoard/index"
,
data
)
}
apps/frontend-micro/venus-base/src/config/center.ts
0 → 100644
View file @
52fe1c5
/**
* 配置中心管理
* 使用 fetch 解决 axios 提前实例化导致 sign 里面的 secret 不能通过配置中心动态获取
*/
import
{
Request
}
from
'glsk-toolkit'
;
// 配置数据
let
baseConfig
:
any
=
{};
// GSC API 请求实例(模块级单例,不挂载到 window)
let
gscApiInstance
:
Request
|
null
=
null
;
// 配置加载完成的 Promise
let
configReadyPromise
:
Promise
<
void
>
|
null
=
null
;
let
configReadyResolve
:
(()
=>
void
)
|
null
=
null
;
// 配置请求 URL
const
CONFIG_URL
=
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config'
;
// 初始化配置就绪 Promise
function
initConfigReadyPromise
()
{
if
(
!
configReadyPromise
)
{
configReadyPromise
=
new
Promise
<
void
>
((
resolve
)
=>
{
configReadyResolve
=
resolve
;
});
}
return
configReadyPromise
;
}
/**
* 获取 GSC API 请求实例
* @returns Request 实例,如果未初始化则返回 null
*/
export
function
getGscApi
():
Request
|
null
{
return
gscApiInstance
;
}
/**
* 等待配置加载完成
* @returns Promise<void>
*/
export
function
waitForConfigReady
():
Promise
<
void
>
{
if
(
gscApiInstance
)
{
return
Promise
.
resolve
();
}
if
(
!
configReadyPromise
)
{
initConfigReadyPromise
();
}
return
configReadyPromise
||
Promise
.
resolve
();
}
/**
* 获取配置中心配置
* @returns Promise<配置数据>
*/
export
async
function
fetchConfig
():
Promise
<
any
>
{
// 初始化配置就绪 Promise
initConfigReadyPromise
();
try
{
const
response
=
await
fetch
(
CONFIG_URL
);
const
result
=
await
response
.
json
();
const
{
code
,
data
}
=
result
;
console
.
log
(
'[配置中心] 响应结果:'
,
code
,
result
);
// 根据 code 决定使用的配置数据
const
configData
=
code
===
'200'
?
data
:
result
;
if
(
code
===
'200'
)
{
console
.
log
(
'[配置中心] 配置数据:'
,
data
);
baseConfig
=
data
;
window
.
$fetchConfig
=
data
;
}
else
{
// 如果 code 不是 200,也保存配置
baseConfig
=
result
;
window
.
$fetchConfig
=
result
;
}
// 统一初始化 GSC API(无论 code 是什么,只要有配置就初始化)
const
gscConfig
=
configData
?.
gsc
||
configData
;
if
(
gscConfig
)
{
// 创建请求实例,存储在模块级变量中,不挂载到 window
gscApiInstance
=
new
Request
({
...
gscConfig
,
session
:
{
requiresSession
:
true
,
sessionId
:
'd5629aee-28c7-4def-a8fa-95d76c978dc7'
,
},
events
:
{
error
:
(
error
:
any
,
requestConfig
:
any
)
=>
{
console
.
error
(
'[配置中心] GSC API 错误:'
,
error
,
requestConfig
);
},
logout
:
(
response
:
any
,
requestConfig
:
any
)
=>
{
console
.
log
(
'[配置中心] GSC API 登出:'
,
response
,
requestConfig
);
},
},
});
console
.
log
(
'[配置中心] GSC API 实例创建成功:'
,
gscApiInstance
);
// 为了向后兼容,同时挂载到 window(可选,如果不需要可以删除)
// window.$gscApi = gscApiInstance;
// 通知配置已就绪
if
(
configReadyResolve
)
{
configReadyResolve
();
configReadyResolve
=
null
;
}
}
else
{
console
.
warn
(
'[配置中心] 未找到 GSC 配置,无法初始化 API 实例'
);
}
return
configData
;
}
catch
(
error
)
{
console
.
error
(
'[配置中心] 获取配置失败:'
,
error
);
throw
error
;
}
}
/**
* 获取当前配置数据
* @returns 配置数据
*/
export
function
getConfig
():
any
{
return
baseConfig
;
}
/**
* 设置配置数据
* @param config 配置数据
*/
export
function
setConfig
(
config
:
any
):
void
{
baseConfig
=
config
;
}
// 导出配置数据(只读)
export
{
baseConfig
};
apps/frontend-micro/venus-base/src/config/gscrequest.ts
0 → 100644
View file @
52fe1c5
/**
* GSC 请求封装
*/
import
{
getGscApi
}
from
'./center'
;
export
const
gscPost
=
(
url
:
string
,
data
:
any
,
_config
=
{})
=>
{
const
gscApi
=
getGscApi
();
if
(
!
gscApi
)
{
const
error
=
new
Error
(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成'
);
console
.
error
(
error
);
return
Promise
.
reject
(
error
);
}
console
.
log
(
'[GSC请求] 发起请求:'
,
url
,
data
);
return
gscApi
.
post
(
url
,
data
,
_config
);
};
// 默认导出
export
default
gscPost
;
apps/frontend-micro/venus-base/src/layouts/BasicLayout.vue
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
type
{
BreadcrumbItem
,
MenuItem
}
from
'@/types/menu'
;
import
{
computed
,
ref
,
watch
}
from
'vue'
;
import
{
useRoute
,
useRouter
}
from
'vue-router'
;
import
NotificationCenter
from
'@/components/NotificationCenter.vue'
;
import
SidebarMenuItem
from
'@/components/SidebarMenuItem.vue'
;
import
UserInfo
from
'@/components/UserInfo.vue'
;
...
...
apps/frontend-micro/venus-base/src/main.ts
View file @
52fe1c5
import
{
createApp
}
from
'vue'
;
import
{
createPinia
}
from
'pinia'
;
import
{
ElMessage
}
from
'element-plus'
;
import
App
from
'./App.vue'
;
import
{
fetchConfig
,
getConfig
}
from
'./config/center'
;
import
{
setupQiankun
}
from
'./qiankun'
;
import
router
from
'./router'
;
import
{
useAppStore
,
useUserStore
}
from
'./stores'
;
import
{
getToken
,
removeToken
}
from
'./utils/auth'
;
import
{
Request
}
from
"glsk-toolkit"
import
{
config
}
from
"./common/baseConfig"
import
{
getToken
}
from
'./utils/auth'
;
import
'./style.css'
;
// 创建应用实例
...
...
@@ -73,58 +73,14 @@ function setupStoreSync() {
});
});
}
let
baseConfig
=
config
// 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取
fetch
(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config"
)
.
then
(
(
response
)
=>
{
// 处理http响应
return
response
.
json
()
},
(
error
)
=>
{
// 处理错误
console
.
log
(
error
)
}
)
.
then
((
response
)
=>
{
const
{
code
,
data
}
=
response
console
.
log
(
"response"
,
code
,
response
)
if
(
code
==
"200"
)
{
console
.
log
(
data
)
baseConfig
=
data
// console.log("baseConfig", baseConfig)
// window.$fetchConfig = data
}
else
{
baseConfig
=
response
window
.
$fetchConfig
=
response
console
.
log
(
response
)
window
.
$gscApi
=
new
Request
({
...
response
.
gsc
,
// baseURL:'http://192.168.3.145:9898/gsc-vcp-web-facade',
// baseURL: 'http://192.168.1.103:5006',
session
:
{
requiresSession
:
true
,
sessionId
:
()
=>
getToken
()
},
events
:
{
error
:
(
error
:
any
)
=>
{
ElMessage
.
error
(
error
.
msg
||
'请求失败'
)
},
logout
:
()
=>
{
const
userStore
=
useUserStore
()
userStore
.
reset
()
removeToken
()
router
.
replace
(
"/login"
)
ElMessage
.
error
(
'登录超时,请重新登录'
)
}
}
})
console
.
log
(
window
.
$gscApi
,
'========'
)
}
// 获取配置中心配置
fetchConfig
()
.
then
((
config
)
=>
{
console
.
log
(
'[基座] 配置中心配置获取成功:'
,
config
);
console
.
log
(
'[基座] 当前配置数据:'
,
getConfig
());
})
.
catch
((
error
)
=>
{
console
.
error
(
'[基座] 配置中心配置获取失败:'
,
error
);
})
.
finally
(()
=>
{
// 初始化应用
...
...
@@ -141,5 +97,5 @@ fetch(
setupQiankun
();
});
});
})
})
;
apps/frontend-micro/venus-base/src/utils/request.ts
View file @
52fe1c5
...
...
@@ -3,10 +3,11 @@
*/
import
axios
,
{
AxiosError
,
AxiosInstance
,
AxiosRequestConfig
,
AxiosResponse
,
type
AxiosError
,
type
AxiosInstance
,
type
AxiosRequestConfig
,
type
AxiosResponse
,
type
InternalAxiosRequestConfig
,
}
from
'axios'
;
import
{
clearAuth
,
getToken
}
from
'./auth'
;
...
...
@@ -22,7 +23,7 @@ const service: AxiosInstance = axios.create({
// 请求拦截器
service
.
interceptors
.
request
.
use
(
(
config
)
=>
{
(
config
:
InternalAxiosRequestConfig
)
=>
{
// 添加 token
const
token
=
getToken
();
if
(
token
&&
config
.
headers
)
{
...
...
@@ -30,7 +31,7 @@ service.interceptors.request.use(
}
// 添加时间戳防止缓存
if
(
config
.
method
===
'get'
)
{
if
(
config
.
method
===
'get'
||
config
.
method
===
'GET'
)
{
config
.
params
=
{
...
config
.
params
,
_t
:
Date
.
now
(),
...
...
@@ -52,20 +53,24 @@ service.interceptors.response.use(
// 根据实际后端接口规范调整
// 假设后端返回格式: { code: number, data: any, message: string }
if
(
res
.
code
!==
undefined
&&
res
.
code
!==
200
&&
res
.
code
!==
0
)
{
console
.
error
(
'接口错误:'
,
res
.
message
||
'未知错误'
);
if
(
res
&&
typeof
res
===
'object'
&&
'code'
in
res
)
{
const
code
=
res
.
code
as
number
;
if
(
code
!==
undefined
&&
code
!==
200
&&
code
!==
0
)
{
const
message
=
(
res
.
message
as
string
)
||
'未知错误'
;
console
.
error
(
'接口错误:'
,
message
);
// 401: 未授权
if
(
code
===
401
)
{
handleUnauthorized
();
}
// 401: 未授权
if
(
res
.
code
===
401
)
{
handleUnauthorized
(
);
}
// 403: 无权限
if
(
code
===
403
)
{
console
.
error
(
'无权限访问'
);
}
// 403: 无权限
if
(
res
.
code
===
403
)
{
console
.
error
(
'无权限访问'
);
return
Promise
.
reject
(
new
Error
(
message
||
'接口请求失败'
));
}
return
Promise
.
reject
(
new
Error
(
res
.
message
||
'接口请求失败'
));
}
return
res
;
...
...
@@ -122,64 +127,72 @@ const handleUnauthorized = () => {
/**
* 通用请求方法
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
request
=
<
T
=
any
>
(
config
:
AxiosRequestConfig
):
Promise
<
T
>
=>
{
return
service
.
request
(
config
);
export
const
request
=
<
T
=
any
>
(
config
:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
request
<
T
,
T
>
(
config
)
as
Promise
<
T
>
;
};
/**
* GET 请求
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
get
=
<
T
=
any
>
(
url
:
string
,
params
?:
any
,
params
?:
Record
<
string
,
any
>
,
config
?:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
get
(
url
,
{
params
,
...
config
})
;
return
service
.
get
<
T
,
T
>
(
url
,
{
params
,
...
config
})
as
Promise
<
T
>
;
};
/**
* POST 请求
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
post
=
<
T
=
any
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
post
(
url
,
data
,
config
)
;
return
service
.
post
<
T
,
T
>
(
url
,
data
,
config
)
as
Promise
<
T
>
;
};
/**
* PUT 请求
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
put
=
<
T
=
any
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
put
(
url
,
data
,
config
)
;
return
service
.
put
<
T
,
T
>
(
url
,
data
,
config
)
as
Promise
<
T
>
;
};
/**
* DELETE 请求
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
del
=
<
T
=
any
>
(
url
:
string
,
params
?:
any
,
params
?:
Record
<
string
,
any
>
,
config
?:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
delete
(
url
,
{
params
,
...
config
})
;
return
service
.
delete
<
T
,
T
>
(
url
,
{
params
,
...
config
})
as
Promise
<
T
>
;
};
/**
* PATCH 请求
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export
const
patch
=
<
T
=
any
>
(
url
:
string
,
data
?:
any
,
config
?:
AxiosRequestConfig
,
):
Promise
<
T
>
=>
{
return
service
.
patch
(
url
,
data
,
config
)
;
return
service
.
patch
<
T
,
T
>
(
url
,
data
,
config
)
as
Promise
<
T
>
;
};
export
default
service
;
apps/frontend-micro/venus-base/src/views/Home.vue
View file @
52fe1c5
...
...
@@ -2,10 +2,10 @@
import
type
{
GlobalState
}
from
'@/qiankun'
;
import
{
onMounted
,
onUnmounted
,
ref
}
from
'vue'
;
import
{
getdataBoard
as
getdateBoardApi
}
from
'@/api/test'
;
// 按需引入 @venus/common-ui-vue 组件库的按钮组件
import
{
GLButton
}
from
'@venus/common-ui-vue'
;
import
{
getdataBoard
}
from
"@/api/test"
import
{
waitForConfigReady
}
from
'@/config/center'
;
import
{
broadcast
,
communicationManager
,
microApps
}
from
'@/qiankun'
;
import
{
Check
,
...
...
@@ -31,9 +31,18 @@ let unsubscribe: (() => void) | null = null;
// GLButton 组件演示相关状态
const
buttonLoading
=
ref
(
false
);
const
clickCount
=
ref
(
0
);
// 初始化:获取全局状态并监听变化
onMounted
(()
=>
{
onMounted
(
async
()
=>
{
// 等待配置加载完成后再发起请求
try
{
await
waitForConfigReady
();
console
.
log
(
'[Home] 配置已就绪,开始请求数据看板...'
);
const
res
=
await
getdataBoard
({
merchantNos
:
''
,
dateType
:
'1'
,
startDate
:
''
,
endDate
:
''
});
console
.
log
(
'[Home] 数据看板请求成功:'
,
res
);
}
catch
(
err
:
any
)
{
console
.
error
(
'[Home] 数据看板请求失败:'
,
err
);
}
// 获取当前全局状态
globalState
.
value
=
communicationManager
.
getGlobalState
();
...
...
@@ -74,10 +83,7 @@ const sendCustomMessage = () => {
};
// 切换主题
const
toggleTheme
=
async
()
=>
{
const
res
=
await
getdateBoardApi
(
0
);
console
.
log
(
"CCCCCCCC阿萨德"
,
res
);
const
toggleTheme
=
()
=>
{
const
currentTheme
=
globalState
.
value
?.
theme
.
mode
||
'light'
;
const
newTheme
=
currentTheme
===
'light'
?
'dark'
:
'light'
;
...
...
apps/frontend-micro/venus-base/src/views/Login.vue
View file @
52fe1c5
...
...
@@ -394,7 +394,7 @@ onMounted(() => {
justify-content
:
center
;
padding
:
60px
40px
;
color
:
#fff
;
background
:
linear-gradient
(
135deg
,
#
667eea
0%
,
#764ba2
100%
);
background
:
linear-gradient
(
135deg
,
#
b2e7ff
0%
,
#026fff
100%
);
}
.info-content
{
...
...
@@ -642,7 +642,7 @@ onMounted(() => {
font-weight
:
600
;
color
:
#fff
;
cursor
:
pointer
;
background
:
linear-gradient
(
135deg
,
#
667eea
0%
,
#764ba2
100%
);
background
:
linear-gradient
(
135deg
,
#
7fd6ff
0%
,
#026fff
100%
);
border
:
none
;
border-radius
:
8px
;
transition
:
all
0.3s
;
...
...
apps/frontend-micro/venus-base/tsconfig.json
View file @
52fe1c5
...
...
@@ -14,6 +14,7 @@
"paths"
:
{
"@/*"
:
[
"src/*"
]
},
"typeRoots"
:
[
"../../node_modules/@types"
,
"./node_modules/@types"
],
"resolveJsonModule"
:
true
,
"allowImportingTsExtensions"
:
true
,
"allowJs"
:
true
,
...
...
apps/frontend-micro/venus-micro-app/src/views/Home.vue
View file @
52fe1c5
<
script
setup
lang=
"ts"
>
import
{
computed
,
onMounted
,
reactive
,
ref
}
from
'vue'
;
import
{
useRoute
}
from
'vue-router'
;
import
{
qiankunWindow
}
from
'vite-plugin-qiankun/dist/helper'
;
import
{
qiankunProps
}
from
'../main'
;
const
route
=
useRoute
();
const
counter
=
ref
(
0
);
...
...
@@ -34,7 +31,7 @@ const globalState = reactive({
});
const
runMode
=
computed
(()
=>
{
return
qiankunWindow
.
__POWERED_BY_QIANKUN__
?
'
🔗 基座模式'
:
'🏠
独立模式'
;
return
qiankunWindow
.
__POWERED_BY_QIANKUN__
?
'
基座模式'
:
'
独立模式'
;
});
const
currentRoute
=
computed
(()
=>
route
.
fullPath
);
...
...
packages/cli/src/index.ts
View file @
52fe1c5
...
...
@@ -3,14 +3,10 @@ import fs from 'node:fs';
import
fsp
from
'node:fs/promises'
;
import
path
from
'node:path'
;
import
{
fileURLToPath
}
from
'node:url'
;
export
const
version
=
'0.0.1'
;
type
Flags
=
Record
<
string
,
boolean
|
string
>
;
type
JsonPrimitive
=
boolean
|
null
|
number
|
string
;
type
JsonValue
=
JsonPrimitive
|
JsonValue
[]
|
{
[
key
:
string
]:
JsonValue
};
function
parseArgs
(
argv
:
string
[]):
Flags
{
const
out
:
Flags
=
{};
for
(
let
i
=
0
;
i
<
argv
.
length
;
i
++
)
{
...
...
@@ -255,6 +251,19 @@ async function runCreate(argv: string[]) {
// Replace placeholders
await
replacePlaceholders
(
destRoot
,
{
__APP_NAME__
:
name
});
// Update package.json name to @venus/<project-name>
const
packageJsonPath
=
path
.
join
(
destRoot
,
'package.json'
);
if
(
fs
.
existsSync
(
packageJsonPath
))
{
const
packageJson
=
JSON
.
parse
(
await
fsp
.
readFile
(
packageJsonPath
,
'utf8'
),
)
as
Record
<
string
,
JsonValue
>
;
packageJson
.
name
=
`@venus/
${
name
}
`
;
await
fsp
.
writeFile
(
packageJsonPath
,
JSON
.
stringify
(
packageJson
,
null
,
2
)
+
'\n'
,
);
}
const
noInstall
=
!!
flags
[
'no-install'
];
if
(
!
noInstall
)
{
console
.
log
(
'安装依赖中 (pnpm install)...'
);
...
...
packages/cli/templates/vue/package.json
View file @
52fe1c5
{
"name"
:
"@venus/
micro-app-template
"
,
"name"
:
"@venus/
__APP_NAME__
"
,
"version"
:
"1.0.0"
,
"description"
:
"Vue3 微前端子应用模板,用于与 qiankun 基座集成"
,
"private"
:
true
,
...
...
pnpm-lock.yaml
View file @
52fe1c5
...
...
@@ -91,7 +91,7 @@ catalogs:
specifier
:
^10.4.21
version
:
10.4.22
axios
:
specifier
:
^1.
10.0
specifier
:
^1.
7.9
version
:
1.13.2
cac
:
specifier
:
^6.7.14
...
...
@@ -473,6 +473,52 @@ importers:
specifier
:
'
catalog:'
version
:
2.2.10(typescript@5.9.3)
apps/frontend-micro/venus-agent-assisent
:
dependencies
:
'
@vueuse/core'
:
specifier
:
'
catalog:'
version
:
13.9.0(vue@3.5.24(typescript@5.9.3))
axios
:
specifier
:
'
catalog:'
version
:
1.13.2
pinia
:
specifier
:
^3.0.3
version
:
3.0.4(typescript@5.9.3)(vue@3.5.24(typescript@5.9.3))
vue
:
specifier
:
^3.5.17
version
:
3.5.24(typescript@5.9.3)
vue-router
:
specifier
:
'
catalog:'
version
:
4.6.3(vue@3.5.24(typescript@5.9.3))
devDependencies
:
'
@types/node'
:
specifier
:
^24.9.2
version
:
24.10.0
'
@vitejs/plugin-vue'
:
specifier
:
'
catalog:'
version
:
6.0.1(vite@7.2.2(@types/node@24.10.0)(jiti@2.6.1)(sass@1.94.0)(terser@5.44.1)(yaml@2.8.1))(vue@3.5.24(typescript@5.9.3))
'
@vitejs/plugin-vue-jsx'
:
specifier
:
'
catalog:'
version
:
5.1.1(vite@7.2.2(@types/node@24.10.0)(jiti@2.6.1)(sass@1.94.0)(terser@5.44.1)(yaml@2.8.1))(vue@3.5.24(typescript@5.9.3))
typescript
:
specifier
:
'
catalog:'
version
:
5.9.3
unplugin-auto-import
:
specifier
:
'
catalog:'
version
:
0.17.8(@vueuse/core@13.9.0(vue@3.5.24(typescript@5.9.3)))(rollup@4.53.2)
unplugin-vue-components
:
specifier
:
'
catalog:'
version
:
0.26.0(@babel/parser@7.28.5)(rollup@4.53.2)(vue@3.5.24(typescript@5.9.3))
vite
:
specifier
:
^7.1.2
version
:
7.2.2(@types/node@24.10.0)(jiti@2.6.1)(sass@1.94.0)(terser@5.44.1)(yaml@2.8.1)
vite-plugin-qiankun
:
specifier
:
'
catalog:'
version
:
1.0.15(typescript@5.9.3)(vite@7.2.2(@types/node@24.10.0)(jiti@2.6.1)(sass@1.94.0)(terser@5.44.1)(yaml@2.8.1))
vue-tsc
:
specifier
:
'
catalog:'
version
:
2.2.10(typescript@5.9.3)
apps/frontend-micro/venus-base
:
dependencies
:
'
@element-plus/icons-vue'
:
...
...
pnpm-workspace.yaml
View file @
52fe1c5
...
...
@@ -42,7 +42,7 @@ catalog:
ant-design-vue
:
^4.2.6
archiver
:
^7.0.1
autoprefixer
:
^10.4.21
axios
:
^1.
10.0
axios
:
^1.
7.9
cac
:
^6.7.14
chalk
:
^5.4.1
circular-dependency-scanner
:
^2.3.0
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment