Commit fc88fa2f by Lin

fix: 文件修改更新

1 parent 89ef67dd
<script setup lang="ts"> <script setup lang="ts">
import type { GlobalState } from '../qiankun'; import type { GlobalState } from "../qiankun";
import { onMounted, onUnmounted, reactive } from 'vue'; import { onMounted, onUnmounted, reactive } from "vue";
import { broadcast, communicationManager } from '../qiankun'; import { broadcast, communicationManager } from "../qiankun";
// 全局状态 // 全局状态
const state = reactive<GlobalState>({ const state = reactive<GlobalState>({
user: null, user: null,
theme: { theme: {
mode: 'light', mode: "light",
primaryColor: '#1890ff', primaryColor: "#1890ff",
}, },
notifications: [], notifications: [],
config: { config: {
apiBaseUrl: '', apiBaseUrl: "",
timeout: 5000, timeout: 5000,
}, },
currentMenu: null, currentMenu: null,
}); });
// 通知表单 // 通知表单
const notificationForm = reactive({ const notificationForm = reactive({
type: 'info' as 'error' | 'info' | 'success' | 'warning', type: "info" as "error" | "info" | "success" | "warning",
title: '', title: "",
message: '', message: "",
}); });
// 配置表单 // 配置表单
const configForm = reactive({ const configForm = reactive({
apiBaseUrl: '', apiBaseUrl: "",
timeout: 5000, timeout: 5000,
}); });
// 颜色选项 // 颜色选项
const colorOptions = [ const colorOptions = [
{ name: '拂晓蓝', value: '#1890ff' }, { name: "拂晓蓝", value: "#1890ff" },
{ name: '薄暮', value: '#f5222d' }, { name: "薄暮", value: "#f5222d" },
{ name: '火山', value: '#fa541c' }, { name: "火山", value: "#fa541c" },
{ name: '日暮', value: '#faad14' }, { name: "日暮", value: "#faad14" },
{ name: '极光绿', value: '#52c41a' }, { name: "极光绿", value: "#52c41a" },
{ name: '明青', value: '#13c2c2' }, { name: "明青", value: "#13c2c2" },
{ name: '极客蓝', value: '#2f54eb' }, { name: "极客蓝", value: "#2f54eb" },
{ name: '酱紫', value: '#722ed1' }, { name: "酱紫", value: "#722ed1" },
]; ];
// 切换用户 // 切换用户
const switchUser = (role: string) => { const switchUser = (role: string) => {
const users: Record< const users: Record<
string, string,
{ {
avatar: string; avatar: string;
...@@ -57,400 +57,402 @@ const switchUser = (role: string) => { ...@@ -57,400 +57,402 @@ const switchUser = (role: string) => {
role: string; role: string;
} }
> = { > = {
admin: { admin: {
id: '001', id: "001",
name: '张三', name: "张三",
avatar: '👨‍💼', avatar: "👨‍💼",
role: 'admin', role: "admin",
permissions: ['read', 'write', 'delete', 'admin'], permissions: [ "read", "write", "delete", "admin" ],
}, },
user: { user: {
id: '002', id: "002",
name: '李四', name: "李四",
avatar: '👤', avatar: "👤",
role: 'user', role: "user",
permissions: ['read', 'write'], permissions: [ "read", "write" ],
}, },
guest: { guest: {
id: '003', id: "003",
name: '访客', name: "访客",
avatar: '👥', avatar: "👥",
role: 'guest', role: "guest",
permissions: ['read'], permissions: [ "read" ],
}, },
}; };
const user = users[role]; const user = users[role];
communicationManager.updateUser(user); communicationManager.updateUser(user);
broadcast('success', '用户切换', `已切换到: ${user.name} (${user.role})`); broadcast("success", "用户切换", `已切换到: ${user.name} (${user.role})`);
}; };
// 切换主题模式 // 切换主题模式
const toggleThemeMode = () => { const toggleThemeMode = () => {
const newMode = state.theme.mode === 'light' ? 'dark' : 'light'; const newMode = state.theme.mode === "light" ? "dark" : "light";
communicationManager.updateTheme({ mode: newMode }); communicationManager.updateTheme({ mode: newMode });
broadcast( broadcast(
'info', "info",
'主题切换', "主题切换",
`已切换到${newMode === 'light' ? '浅色' : '深色'}模式`, `已切换到${newMode === "light" ? "浅色" : "深色"}模式`,
); );
}; };
// 改变主色调 // 改变主色调
const changeColor = (color: string) => { const changeColor = (color: string) => {
communicationManager.updateTheme({ primaryColor: color }); communicationManager.updateTheme({ primaryColor: color });
broadcast('info', '主题颜色', `主色调已更新为 ${color}`); broadcast("info", "主题颜色", `主色调已更新为 ${color}`);
}; };
// 发送通知 // 发送通知
const sendNotification = () => { const sendNotification = () => {
if (!notificationForm.title || !notificationForm.message) { if (!notificationForm.title || !notificationForm.message) {
alert('请填写标题和内容'); return;
return; }
}
broadcast(
broadcast( notificationForm.type,
notificationForm.type, notificationForm.title,
notificationForm.title, notificationForm.message,
notificationForm.message, );
);
// 清空表单
// 清空表单 notificationForm.title = "";
notificationForm.title = ''; notificationForm.message = "";
notificationForm.message = '';
}; };
// 快速发送通知 // 快速发送通知
const sendQuickNotification = ( const sendQuickNotification = (
type: 'error' | 'info' | 'success' | 'warning', type: "error" | "info" | "success" | "warning",
) => { ) => {
const messages = { const messages = {
success: { title: '操作成功', message: '数据已成功保存到服务器' }, success: { title: "操作成功", message: "数据已成功保存到服务器" },
warning: { title: '警告提示', message: '您的会话即将过期,请注意保存数据' }, warning: { title: "警告提示", message: "您的会话即将过期,请注意保存数据" },
error: { title: '操作失败', message: '网络连接失败,请检查您的网络设置' }, error: { title: "操作失败", message: "网络连接失败,请检查您的网络设置" },
info: { info: {
title: '系统提示', title: "系统提示",
message: '系统将在今晚23:00进行维护,预计持续1小时', message: "系统将在今晚23:00进行维护,预计持续1小时",
}, },
}; };
const msg = messages[type]; const msg = messages[type];
broadcast(type, msg.title, msg.message); broadcast(type, msg.title, msg.message);
}; };
// 更新配置 // 更新配置
const updateConfig = () => { const updateConfig = () => {
communicationManager.updateConfig(configForm); communicationManager.updateConfig(configForm);
broadcast('success', '配置更新', '系统配置已更新'); broadcast("success", "配置更新", "系统配置已更新");
}; };
// 监听全局状态变化 // 监听全局状态变化
let unsubscribe: (() => void) | null = null; let unsubscribe: (() => void) | null = null;
onMounted(() => { onMounted(() => {
// 初始化状态 // 初始化状态
const currentState = communicationManager.getGlobalState(); const currentState = communicationManager.getGlobalState();
Object.assign(state, currentState); Object.assign(state, currentState);
// 初始化配置表单 // 初始化配置表单
configForm.apiBaseUrl = currentState.config.apiBaseUrl; configForm.apiBaseUrl = currentState.config.apiBaseUrl;
configForm.timeout = currentState.config.timeout; configForm.timeout = currentState.config.timeout;
// 监听状态变化 // 监听状态变化
unsubscribe = communicationManager.onStateChange((newState) => { unsubscribe = communicationManager.onStateChange((newState) => {
Object.assign(state, newState); Object.assign(state, newState);
}); });
}); });
onUnmounted(() => { onUnmounted(() => {
if (unsubscribe) { if (unsubscribe) {
unsubscribe(); unsubscribe();
} }
}); });
</script> </script>
<template> <template>
<div class="communication-demo"> <div class="communication-demo">
<div class="page-header"> <div class="page-header">
<h1>📡 微前端通信示例</h1> <h1>📡 微前端通信示例</h1>
<p class="subtitle">演示基座与子应用之间的数据通信</p> <p class="subtitle">
</div> 演示基座与子应用之间的数据通信
</p>
<div class="demo-container">
<!-- 用户信息管理 -->
<div class="demo-section">
<div class="section-header">
<h2>👤 用户信息管理</h2>
<span class="tag">全局状态共享</span>
</div>
<div class="section-content">
<div class="current-user">
<h3>当前用户信息</h3>
<div v-if="state.user" class="user-display">
<div class="info-row">
<span class="label">用户头像:</span>
<span class="value avatar">{{ state.user.avatar }}</span>
</div>
<div class="info-row">
<span class="label">用户名:</span>
<span class="value">{{ state.user.name }}</span>
</div>
<div class="info-row">
<span class="label">用户ID:</span>
<span class="value">{{ state.user.id }}</span>
</div>
<div class="info-row">
<span class="label">角色:</span>
<span class="value">{{ state.user.role }}</span>
</div>
<div class="info-row">
<span class="label">权限:</span>
<span class="value">{{
state.user.permissions.join(', ')
}}</span>
</div>
</div>
</div>
<div class="user-actions">
<h3>切换用户</h3>
<div class="button-group">
<button @click="switchUser('admin')" class="btn btn-primary">
切换到管理员
</button>
<button @click="switchUser('user')" class="btn btn-secondary">
切换到普通用户
</button>
<button @click="switchUser('guest')" class="btn btn-secondary">
切换到访客
</button>
</div>
<p class="hint">💡 切换用户后,子应用会实时接收到新的用户信息</p>
</div>
</div> </div>
</div>
<!-- 主题管理 --> <div class="demo-container">
<div class="demo-section"> <!-- 用户信息管理 -->
<div class="section-header"> <div class="demo-section">
<h2>🎨 主题管理</h2> <div class="section-header">
<span class="tag">全局状态共享</span> <h2>👤 用户信息管理</h2>
</div> <span class="tag">全局状态共享</span>
<div class="section-content"> </div>
<div class="theme-display"> <div class="section-content">
<h3>当前主题</h3> <div class="current-user">
<div class="info-row"> <h3>当前用户信息</h3>
<span class="label">模式:</span> <div v-if="state.user" class="user-display">
<span class="value">{{ <div class="info-row">
state.theme.mode === 'light' ? '🌞 浅色' : '🌙 深色' <span class="label">用户头像:</span>
}}</span> <span class="value avatar">{{ state.user.avatar }}</span>
</div> </div>
<div class="info-row"> <div class="info-row">
<span class="label">主色调:</span> <span class="label">用户名:</span>
<span class="value"> <span class="value">{{ state.user.name }}</span>
<span </div>
class="color-preview" <div class="info-row">
:style="{ backgroundColor: state.theme.primaryColor }" <span class="label">用户ID:</span>
></span> <span class="value">{{ state.user.id }}</span>
{{ state.theme.primaryColor }} </div>
</span> <div class="info-row">
</div> <span class="label">角色:</span>
</div> <span class="value">{{ state.user.role }}</span>
</div>
<div class="theme-actions"> <div class="info-row">
<h3>切换主题</h3> <span class="label">权限:</span>
<div class="button-group"> <span class="value">
<button @click="toggleThemeMode" class="btn btn-primary"> {{
切换{{ state.theme.mode === 'light' ? '深色' : '浅色' }}模式 state.user.permissions.join(', ')
</button> }}
</div> </span>
<div class="color-picker"> </div>
<label>选择主色调:</label> </div>
<div class="color-options"> </div>
<button
v-for="color in colorOptions" <div class="user-actions">
:key="color.value" <h3>切换用户</h3>
:style="{ backgroundColor: color.value }" <div class="button-group">
class="color-btn" <button class="btn btn-primary" @click="switchUser('admin')">
:class="[ 切换到管理员
{ active: state.theme.primaryColor === color.value }, </button>
]" <button class="btn btn-secondary" @click="switchUser('user')">
@click="changeColor(color.value)" 切换到普通用户
:title="color.name" </button>
></button> <button class="btn btn-secondary" @click="switchUser('guest')">
</div> 切换到访客
</button>
</div>
<p class="hint">
💡 切换用户后,子应用会实时接收到新的用户信息
</p>
</div>
</div>
</div> </div>
<p class="hint">💡 主题变化会同步到所有子应用</p>
</div>
</div>
</div>
<!-- 消息通知 --> <!-- 主题管理 -->
<div class="demo-section"> <div class="demo-section">
<div class="section-header"> <div class="section-header">
<h2>📢 消息通知</h2> <h2>🎨 主题管理</h2>
<span class="tag">基座向子应用广播</span> <span class="tag">全局状态共享</span>
</div> </div>
<div class="section-content"> <div class="section-content">
<div class="notification-form"> <div class="theme-display">
<h3>发送通知</h3> <h3>当前主题</h3>
<div class="form-group"> <div class="info-row">
<label>通知类型:</label> <span class="label">模式:</span>
<select v-model="notificationForm.type" class="form-control"> <span class="value">
<option value="success">✅ 成功</option> {{
<option value="warning">⚠️ 警告</option> state.theme.mode === 'light' ? '🌞 浅色' : '🌙 深色'
<option value="error">❌ 错误</option> }}
<option value="info">ℹ️ 信息</option> </span>
</select> </div>
</div> <div class="info-row">
<div class="form-group"> <span class="label">主色调:</span>
<label>标题:</label> <span class="value">
<input <span class="color-preview"
v-model="notificationForm.title" :style="{ backgroundColor: state.theme.primaryColor }">
type="text" </span>
class="form-control" {{ state.theme.primaryColor }}
placeholder="请输入通知标题" </span>
/> </div>
</div> </div>
<div class="form-group">
<label>内容:</label> <div class="theme-actions">
<textarea <h3>切换主题</h3>
v-model="notificationForm.message" <div class="button-group">
class="form-control" <button class="btn btn-primary" @click="toggleThemeMode">
rows="3" 切换{{ state.theme.mode === 'light' ? '深色' : '浅色' }}模式
placeholder="请输入通知内容" </button>
></textarea> </div>
<div class="color-picker">
<label>选择主色调:</label>
<div class="color-options">
<button v-for="color in colorOptions"
:key="color.value"
class="color-btn"
:class="[
{ active: state.theme.primaryColor === color.value },
]"
:style="{ backgroundColor: color.value }"
:title="color.name"
@click="changeColor(color.value)">
</button>
</div>
</div>
<p class="hint">
💡 主题变化会同步到所有子应用
</p>
</div>
</div>
</div> </div>
<button @click="sendNotification" class="btn btn-primary btn-block">
发送通知
</button>
<p class="hint">
💡 发送的通知会显示在右上角的通知中心,所有应用都能看到
</p>
</div>
<div class="quick-actions">
<h3>快速测试</h3>
<div class="button-group">
<button
@click="sendQuickNotification('success')"
class="btn btn-success"
>
成功消息
</button>
<button
@click="sendQuickNotification('warning')"
class="btn btn-warning"
>
警告消息
</button>
<button
@click="sendQuickNotification('error')"
class="btn btn-danger"
>
错误消息
</button>
<button
@click="sendQuickNotification('info')"
class="btn btn-info"
>
信息消息
</button>
</div>
</div>
</div>
</div>
<!-- 系统配置 --> <!-- 消息通知 -->
<div class="demo-section"> <div class="demo-section">
<div class="section-header"> <div class="section-header">
<h2>⚙️ 系统配置</h2> <h2>📢 消息通知</h2>
<span class="tag">全局配置共享</span> <span class="tag">基座向子应用广播</span>
</div> </div>
<div class="section-content"> <div class="section-content">
<div class="config-display"> <div class="notification-form">
<h3>当前配置</h3> <h3>发送通知</h3>
<div class="info-row"> <div class="form-group">
<span class="label">API 地址:</span> <label>通知类型:</label>
<span class="value code">{{ state.config.apiBaseUrl }}</span> <select v-model="notificationForm.type" class="form-control">
<option value="success">
✅ 成功
</option>
<option value="warning">
⚠️ 警告
</option>
<option value="error">
❌ 错误
</option>
<option value="info">
ℹ️ 信息
</option>
</select>
</div>
<div class="form-group">
<label>标题:</label>
<input v-model="notificationForm.title"
class="form-control"
placeholder="请输入通知标题"
type="text" />
</div>
<div class="form-group">
<label>内容:</label>
<textarea v-model="notificationForm.message"
class="form-control"
placeholder="请输入通知内容"
rows="3">
</textarea>
</div>
<button class="btn btn-primary btn-block" @click="sendNotification">
发送通知
</button>
<p class="hint">
💡 发送的通知会显示在右上角的通知中心,所有应用都能看到
</p>
</div>
<div class="quick-actions">
<h3>快速测试</h3>
<div class="button-group">
<button class="btn btn-success"
@click="sendQuickNotification('success')">
成功消息
</button>
<button class="btn btn-warning"
@click="sendQuickNotification('warning')">
警告消息
</button>
<button class="btn btn-danger"
@click="sendQuickNotification('error')">
错误消息
</button>
<button class="btn btn-info"
@click="sendQuickNotification('info')">
信息消息
</button>
</div>
</div>
</div>
</div> </div>
<div class="info-row">
<span class="label">请求超时:</span> <!-- 系统配置 -->
<span class="value">{{ state.config.timeout }}ms</span> <div class="demo-section">
</div> <div class="section-header">
</div> <h2>⚙️ 系统配置</h2>
<span class="tag">全局配置共享</span>
<div class="config-actions"> </div>
<h3>更新配置</h3> <div class="section-content">
<div class="form-group"> <div class="config-display">
<label>API 地址:</label> <h3>当前配置</h3>
<input <div class="info-row">
v-model="configForm.apiBaseUrl" <span class="label">API 地址:</span>
type="text" <span class="value code">{{ state.config.apiBaseUrl }}</span>
class="form-control" </div>
/> <div class="info-row">
</div> <span class="label">请求超时:</span>
<div class="form-group"> <span class="value">{{ state.config.timeout }}ms</span>
<label>请求超时 (ms):</label> </div>
<input </div>
v-model.number="configForm.timeout"
type="number" <div class="config-actions">
class="form-control" <h3>更新配置</h3>
/> <div class="form-group">
<label>API 地址:</label>
<input v-model="configForm.apiBaseUrl"
class="form-control"
type="text" />
</div>
<div class="form-group">
<label>请求超时 (ms):</label>
<input v-model.number="configForm.timeout"
class="form-control"
type="number" />
</div>
<button class="btn btn-primary" @click="updateConfig">
更新配置
</button>
<p class="hint">
💡 配置更新后,所有子应用都会收到最新配置
</p>
</div>
</div>
</div> </div>
<button @click="updateConfig" class="btn btn-primary">
更新配置
</button>
<p class="hint">💡 配置更新后,所有子应用都会收到最新配置</p>
</div>
</div>
</div>
<!-- 通信说明 --> <!-- 通信说明 -->
<div class="demo-section info-section"> <div class="demo-section info-section">
<div class="section-header"> <div class="section-header">
<h2>📚 通信方式说明</h2> <h2>📚 通信方式说明</h2>
</div> </div>
<div class="section-content"> <div class="section-content">
<div class="info-card"> <div class="info-card">
<h3>1. 全局状态管理 (Global State)</h3> <h3>1. 全局状态管理 (Global State)</h3>
<p> <p>
使用 qiankun 的 使用 qiankun 的
<code>initGlobalState</code> API,实现基座和子应用之间的状态共享。 <code>initGlobalState</code> API,实现基座和子应用之间的状态共享。
</p> </p>
<ul> <ul>
<li>✅ 双向通信:基座和子应用都可以修改状态</li> <li>✅ 双向通信:基座和子应用都可以修改状态</li>
<li>✅ 实时同步:状态变化会立即通知所有订阅者</li> <li>✅ 实时同步:状态变化会立即通知所有订阅者</li>
<li>✅ 类型安全:使用 TypeScript 定义状态结构</li> <li>✅ 类型安全:使用 TypeScript 定义状态结构</li>
</ul> </ul>
</div> </div>
<div class="info-card"> <div class="info-card">
<h3>2. Props 传递</h3> <h3>2. Props 传递</h3>
<p>基座在注册子应用时,可以通过 props 向子应用传递数据。</p> <p>基座在注册子应用时,可以通过 props 向子应用传递数据。</p>
<ul> <ul>
<li>✅ 单向数据流:基座向子应用传递</li> <li>✅ 单向数据流:基座向子应用传递</li>
<li>✅ 配置传递:适合传递路由配置、权限等静态数据</li> <li>✅ 配置传递:适合传递路由配置、权限等静态数据</li>
<li>✅ 生命周期传递:在 mount、update 时传递</li> <li>✅ 生命周期传递:在 mount、update 时传递</li>
</ul> </ul>
</div> </div>
<div class="info-card"> <div class="info-card">
<h3>3. Actions 通信</h3> <h3>3. Actions 通信</h3>
<p>通过全局状态管理器,实现消息通知、事件广播等功能。</p> <p>通过全局状态管理器,实现消息通知、事件广播等功能。</p>
<ul> <ul>
<li>✅ 事件驱动:基于发布订阅模式</li> <li>✅ 事件驱动:基于发布订阅模式</li>
<li>✅ 广播消息:一对多通信</li> <li>✅ 广播消息:一对多通信</li>
<li>✅ 解耦合:应用之间不直接依赖</li> <li>✅ 解耦合:应用之间不直接依赖</li>
</ul> </ul>
</div> </div>
</div>
</div>
</div> </div>
</div>
</div> </div>
</div>
</template> </template>
<style scoped> <style scoped>
......
<script setup lang="ts"> <script setup lang="ts">
import type { GlobalState } from '@/qiankun'; import type { GlobalState } from "@/qiankun";
import { onMounted, onUnmounted, ref } from 'vue'; import { onMounted, onUnmounted, ref } from "vue";
// 按需引入 @venus/common-ui-vue 组件库的按钮组件 // 按需引入 @venus/common-ui-vue 组件库的按钮组件
import { GLButton } from '@venus/common-ui-vue'; import { GLButton } from "@venus/common-ui-vue";
import { waitForConfigReady } from '@/config/center'; import { waitForConfigReady } from "@/config/center";
import { broadcast, communicationManager, microApps } from '@/qiankun'; import { broadcast, communicationManager, microApps } from "@/qiankun";
import { import {
Check, Check,
Delete, Delete,
Edit, Edit,
Message, Message,
Search, Search,
Star, Star,
} from '@element-plus/icons-vue'; } from "@element-plus/icons-vue";
const apps = microApps; const apps = microApps;
...@@ -23,8 +23,8 @@ const apps = microApps; ...@@ -23,8 +23,8 @@ const apps = microApps;
const globalState = ref<GlobalState | null>(null); const globalState = ref<GlobalState | null>(null);
// 消息输入 // 消息输入
const messageTitle = ref('来自主应用的消息'); const messageTitle = ref("来自主应用的消息");
const messageContent = ref('Hello from Main App!'); const messageContent = ref("Hello from Main App!");
const drawer = ref(false); const drawer = ref(false);
// 监听器的取消函数 // 监听器的取消函数
let unsubscribe: (() => void) | null = null; let unsubscribe: (() => void) | null = null;
...@@ -33,512 +33,601 @@ let unsubscribe: (() => void) | null = null; ...@@ -33,512 +33,601 @@ let unsubscribe: (() => void) | null = null;
const buttonLoading = ref(false); const buttonLoading = ref(false);
const clickCount = ref(0); const clickCount = ref(0);
onMounted(async () => { onMounted(async () => {
try { try {
await waitForConfigReady(); await waitForConfigReady();
} catch (error: any) { } catch {}
} // 获取当前全局状态
// 获取当前全局状态 globalState.value = communicationManager.getGlobalState();
globalState.value = communicationManager.getGlobalState();
// 监听全局状态变化
// 监听全局状态变化 unsubscribe = communicationManager.onStateChange((state) => {
unsubscribe = communicationManager.onStateChange((state) => { globalState.value = state;
globalState.value = state; });
});
}); });
// 组件卸载时取消监听 // 组件卸载时取消监听
onUnmounted(() => { onUnmounted(() => {
if (unsubscribe) { if (unsubscribe) {
unsubscribe(); unsubscribe();
} }
}); });
// 发送成功消息 // 发送成功消息
const sendSuccessMessage = () => { const sendSuccessMessage = () => {
broadcast('success', '操作成功', '这是一条来自主应用的成功消息!'); broadcast("success", "操作成功", "这是一条来自主应用的成功消息!");
}; };
// 发送自定义消息 // 发送自定义消息
const sendCustomMessage = () => { const sendCustomMessage = () => {
if (!messageTitle.value || !messageContent.value) { if (!messageTitle.value || !messageContent.value) {
broadcast('error', '发送失败', '标题和内容不能为空!'); broadcast("error", "发送失败", "标题和内容不能为空!");
return; return;
} }
communicationManager.addNotification({ communicationManager.addNotification({
type: 'info', type: "info",
title: messageTitle.value, title: messageTitle.value,
message: messageContent.value, message: messageContent.value,
from: '主应用', from: "主应用",
}); });
messageTitle.value = ''; messageTitle.value = "";
messageContent.value = ''; messageContent.value = "";
}; };
// 切换主题 // 切换主题
const toggleTheme = () => { const toggleTheme = () => {
const currentTheme = globalState.value?.theme.mode || 'light'; const currentTheme = globalState.value?.theme.mode || "light";
const newTheme = currentTheme === 'light' ? 'dark' : 'light'; const newTheme = currentTheme === "light" ? "dark" : "light";
communicationManager.updateTheme({ communicationManager.updateTheme({
mode: newTheme, mode: newTheme,
}); });
broadcast( broadcast(
'success', "success",
'主题切换', "主题切换",
`已切换到${newTheme === 'dark' ? '深色' : '浅色'}模式`, `已切换到${newTheme === "dark" ? "深色" : "浅色"}模式`,
); );
}; };
// 更新用户信息 // 更新用户信息
const updateUserInfo = () => { const updateUserInfo = () => {
const newUser = { const newUser = {
id: '001', id: "001",
name: '李四', name: "李四",
avatar: '👨‍💻', avatar: "👨‍💻",
role: 'developer', role: "developer",
permissions: ['read', 'write'], permissions: [ "read", "write" ],
}; };
communicationManager.updateUser(newUser); communicationManager.updateUser(newUser);
broadcast('success', '用户更新', `用户信息已更新为: ${newUser.name}`); broadcast("success", "用户更新", `用户信息已更新为: ${newUser.name}`);
}; };
// 清空所有通知 // 清空所有通知
const clearAllNotifications = () => { const clearAllNotifications = () => {
communicationManager.clearNotifications(); communicationManager.clearNotifications();
}; };
// 删除单个通知 // 删除单个通知
const removeNotification = (id: string) => { const removeNotification = (id: string) => {
communicationManager.removeNotification(id); communicationManager.removeNotification(id);
}; };
// 格式化时间 // 格式化时间
const formatTime = (timestamp: number) => { const formatTime = (timestamp: number) => {
const date = new Date(timestamp); const date = new Date(timestamp);
return date.toLocaleTimeString('zh-CN'); return date.toLocaleTimeString("zh-CN");
}; };
// GLButton 组件演示方法 // GLButton 组件演示方法
// 模拟异步操作 // 模拟异步操作
const handleAsyncClick = async () => { const handleAsyncClick = async () => {
buttonLoading.value = true; buttonLoading.value = true;
broadcast('info', '异步操作', '正在处理异步操作...'); broadcast("info", "异步操作", "正在处理异步操作...");
// 模拟 2 秒的异步操作 // 模拟 2 秒的异步操作
await new Promise((resolve) => setTimeout(resolve, 2000)); await new Promise((resolve) => setTimeout(resolve, 2000));
buttonLoading.value = false; buttonLoading.value = false;
broadcast('success', '操作成功', '异步操作已完成!'); broadcast("success", "操作成功", "异步操作已完成!");
}; };
// 确认操作 // 确认操作
const handleConfirmClick = () => { const handleConfirmClick = () => {
broadcast('success', '确认成功', '你已确认执行该操作'); broadcast("success", "确认成功", "你已确认执行该操作");
}; };
// 删除操作 // 删除操作
const handleDeleteClick = () => { const handleDeleteClick = () => {
broadcast('success', '删除成功', '删除操作已执行'); broadcast("success", "删除成功", "删除操作已执行");
}; };
// 防抖点击 // 防抖点击
const handleDebounceClick = () => { const handleDebounceClick = () => {
clickCount.value++; clickCount.value++;
broadcast('info', '防抖按钮', `第 ${clickCount.value} 次有效点击`); broadcast("info", "防抖按钮", `第 ${clickCount.value} 次有效点击`);
}; };
</script> </script>
<template> <template>
<div class="home-page"> <div class="home-page">
<div class="welcome-section"> <div class="welcome-section">
<h1 class="title">欢迎使用</h1> <h1 class="title">
<p class="subtitle">基于 qiankun + Vue3 + Vite 构建的微前端主应用</p> 欢迎使用
</div> </h1>
<el-button @click="drawer = true">Open</el-button> <p class="subtitle">
<div class="feature-section"> 基于 qiankun + Vue3 + Vite 构建的微前端主应用
<div class="feature-card"> </p>
<div class="feature-icon">微</div> </div>
<h3 class="feature-title">微前端架构</h3> <el-button @click="drawer = true">
<p class="feature-desc"> Open
使用 qiankun 实现微前端架构,支持多业务线独立开发与部署。 </el-button>
</p> <div class="feature-section">
</div> <div class="feature-card">
<div class="feature-icon">
<div class="feature-card"> 微
<div class="feature-icon">速</div> </div>
<h3 class="feature-title">Vue3 + Vite</h3> <h3 class="feature-title">
<p class="feature-desc"> 微前端架构
结合 Vue3 组合式 API 与 Vite 极致构建体验,显著提升开发效率。 </h3>
</p> <p class="feature-desc">
</div> 使用 qiankun 实现微前端架构,支持多业务线独立开发与部署。
</p>
<div class="feature-card">
<div class="feature-icon">拓</div>
<h3 class="feature-title">灵活扩展</h3>
<p class="feature-desc">
支持动态注册微应用,可按需扩展业务模块与发布策略。
</p>
</div>
<div class="feature-card">
<div class="feature-icon">稳</div>
<h3 class="feature-title">稳定可靠</h3>
<p class="feature-desc">
提供完善的权限体系与平台级监控,保障微前端运行稳定。
</p>
</div>
</div>
<div class="info-section">
<div class="info-card">
<h3>快速开始</h3>
<ul class="info-list">
<li>1. 执行 <code>pnpm install</code> 安装依赖</li>
<li>2. 运行 <code>pnpm dev</code> 启动主应用</li>
<li>3. 启动所需的微应用服务</li>
<li>4. 在 <code>src/qiankun/apps.ts</code> 中注册微应用</li>
</ul>
</div>
<div class="info-card">
<h3>微应用列表</h3>
<ul class="app-list">
<li v-for="app in apps" :key="app.name" class="app-item">
<span class="app-name">{{ app.name }}</span>
<span class="app-port">{{ app.entry }}</span>
<router-link
v-if="typeof app.activeRule === 'string'"
:to="app.activeRule"
class="app-link"
>
进入 >
</router-link>
<span v-else class="app-link disabled">暂不可用</span>
</li>
</ul>
</div>
</div>
<!-- 通信示例区域 -->
<div class="communication-section">
<h2 class="section-title">
<span class="title-icon">📡</span>
主应用 ↔ 微应用通讯演示
</h2>
<div class="communication-content">
<!-- 左侧:全局状态展示 -->
<div class="state-panel">
<h3 class="panel-title">全局共享状态</h3>
<div v-if="globalState" class="state-content">
<!-- 用户信息 -->
<div class="state-item">
<div class="state-label">👤 当前用户</div>
<div class="state-value">
<span class="user-avatar">{{ globalState.user?.avatar }}</span>
<span
>{{ globalState.user?.name }} ({{
globalState.user?.role
}})</span
>
</div>
</div> </div>
<!-- 主题 --> <div class="feature-card">
<div class="state-item"> <div class="feature-icon">
<div class="state-label">🎨 主题模式</div> 速
<div class="state-value"> </div>
{{ <h3 class="feature-title">
globalState.theme.mode === 'light' ? '浅色模式' : '深色模式' Vue3 + Vite
}} </h3>
<span <p class="feature-desc">
class="theme-color" 结合 Vue3 组合式 API 与 Vite 极致构建体验,显著提升开发效率。
:style="{ backgroundColor: globalState.theme.primaryColor }" </p>
></span>
</div>
</div> </div>
<!-- 通知数量 --> <div class="feature-card">
<div class="state-item"> <div class="feature-icon">
<div class="state-label">🔔 通知数量</div> 拓
<div class="state-value"> </div>
<span class="notification-badge">{{ <h3 class="feature-title">
globalState.notifications.length 灵活扩展
}}</span> </h3>
</div> <p class="feature-desc">
支持动态注册微应用,可按需扩展业务模块与发布策略。
</p>
</div> </div>
<!-- API 配置 --> <div class="feature-card">
<div class="state-item"> <div class="feature-icon">
<div class="state-label">⚙️ API 配置</div> 稳
<div class="state-value state-value-small"> </div>
{{ globalState.config.apiBaseUrl }} <h3 class="feature-title">
</div> 稳定可靠
</h3>
<p class="feature-desc">
提供完善的权限体系与平台级监控,保障微前端运行稳定。
</p>
</div> </div>
</div>
<div v-else class="state-loading">加载中...</div>
</div> </div>
<!-- 右侧:通信操作区 --> <div class="info-section">
<div class="action-panel"> <div class="info-card">
<h3 class="panel-title">通信操作</h3> <h3>快速开始</h3>
<ul class="info-list">
<!-- 快速发送消息 --> <li>1. 执行 <code>pnpm install</code> 安装依赖</li>
<div class="action-group"> <li>2. 运行 <code>pnpm dev</code> 启动主应用</li>
<div class="action-label">快速发送消息到微应用:</div> <li>3. 启动所需的微应用服务</li>
<div class="button-group"> <li>4. 在 <code>src/qiankun/apps.ts</code> 中注册微应用</li>
<button </ul>
class="action-btn success-btn"
@click="sendSuccessMessage"
>
✓ 发送成功消息
</button>
</div> </div>
</div>
<!-- 自定义消息 -->
<div class="action-group">
<div class="action-label">自定义消息:</div>
<input
v-model="messageTitle"
type="text"
class="input-field"
placeholder="消息标题"
/>
<textarea
v-model="messageContent"
class="textarea-field"
placeholder="消息内容"
rows="3"
></textarea>
<button class="action-btn primary-btn" @click="sendCustomMessage">
📤 发送自定义消息
</button>
</div>
<!-- 状态更新操作 -->
<div class="action-group">
<div class="action-label">更新全局状态:</div>
<div class="button-group">
<button class="action-btn theme-btn" @click="toggleTheme">
🎨 切换主题
</button>
<button class="action-btn user-btn" @click="updateUserInfo">
👤 更新用户
</button>
</div>
</div>
</div>
</div>
<!-- 通知消息列表 -->
<div class="notification-panel">
<div class="notification-header">
<h3 class="panel-title">📬 消息通知列表</h3>
<button
v-if="globalState?.notifications.length"
class="clear-btn"
@click="clearAllNotifications"
>
清空全部
</button>
</div>
<div v-if="globalState?.notifications.length" class="notification-list"> <div class="info-card">
<div <h3>微应用列表</h3>
v-for="notification in globalState.notifications" <ul class="app-list">
:key="notification.id" <li v-for="app in apps"
class="notification-item" :key="app.name"
:class="[`notification-${notification.type}`]" class="app-item">
> <span class="app-name">{{ app.name }}</span>
<div class="notification-icon"> <span class="app-port">{{ app.entry }}</span>
<span v-if="notification.type === 'success'">✓</span> <router-link v-if="typeof app.activeRule === 'string'"
<span v-else-if="notification.type === 'warning'">⚠</span> class="app-link"
<span v-else-if="notification.type === 'error'">✕</span> :to="app.activeRule">
<span v-else>ℹ</span> 进入 >
</div> </router-link>
<div class="notification-content"> <span v-else class="app-link disabled">暂不可用</span>
<div class="notification-title">{{ notification.title }}</div> </li>
<div class="notification-message">{{ notification.message }}</div> </ul>
<div class="notification-meta">
<span v-if="notification.from" class="notification-from"
>来自: {{ notification.from }}</span
>
<span class="notification-time">{{
formatTime(notification.timestamp)
}}</span>
</div>
</div> </div>
<button
class="notification-close"
@click="removeNotification(notification.id)"
>
✕
</button>
</div>
</div> </div>
<div v-else class="notification-empty"> <!-- 通信示例区域 -->
<div class="empty-icon">📭</div> <div class="communication-section">
<div class="empty-text">暂无消息通知</div> <h2 class="section-title">
<div class="empty-hint"> <span class="title-icon">📡</span>
点击上方按钮发送消息,微应用也可以发送消息到这里 主应用 ↔ 微应用通讯演示
</div> </h2>
</div>
</div> <div class="communication-content">
<!-- 左侧:全局状态展示 -->
<!-- 使用说明 --> <div class="state-panel">
<div class="usage-tips"> <h3 class="panel-title">
<h4>💡 使用说明</h4> 全局共享状态
<ul> </h3>
<li> <div v-if="globalState" class="state-content">
<strong>全局状态:</strong <!-- 用户信息 -->
>主应用和微应用共享的状态,任何一方修改都会实时同步。 <div class="state-item">
</li> <div class="state-label">
<li> 👤 当前用户
<strong>消息通知:</strong </div>
>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。 <div class="state-value">
</li> <span class="user-avatar">{{ globalState.user?.avatar }}</span>
<li> <span>
<strong>实时监听:</strong {{ globalState.user?.name }} ({{
>状态变化会实时反映在界面上,打开控制台可以看到详细日志。 globalState.user?.role
</li> }})
<li> </span>
<strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用 </div>
<code>actions.setGlobalState()</code> 和 </div>
<code>actions.onGlobalStateChange()</code> 进行通信。
</li> <!-- 主题 -->
</ul> <div class="state-item">
</div> <div class="state-label">
🎨 主题模式
<!-- Element Plus 原生按钮示例 --> </div>
<div class="component-demo"> <div class="state-value">
<h4 class="demo-title">📦 Element Plus 原生按钮</h4> {{
<div class="button-demo-group"> globalState.theme.mode === 'light' ? '浅色模式' : '深色模式'
<el-button type="primary">Primary</el-button> }}
<el-button type="success">Success</el-button> <span class="theme-color"
<el-button type="info">Info</el-button> :style="{ backgroundColor: globalState.theme.primaryColor }">
<el-button type="warning">Warning</el-button> </span>
<el-button type="danger">Danger</el-button> </div>
</div> </div>
</div>
<!-- 通知数量 -->
<!-- GLButton 组件库按钮示例 --> <div class="state-item">
<div class="component-demo"> <div class="state-label">
<h4 class="demo-title">🎨 @venus/common-ui-vue GLButton 组件</h4> 🔔 通知数量
</div>
<!-- 基础按钮 --> <div class="state-value">
<div class="demo-section"> <span class="notification-badge">
<h5 class="section-subtitle">基础样式</h5> {{
<div class="button-demo-group"> globalState.notifications.length
<GLButton type="primary">主要按钮</GLButton> }}
<GLButton type="success">成功按钮</GLButton> </span>
<GLButton type="info">信息按钮</GLButton> </div>
<GLButton type="warning">警告按钮</GLButton> </div>
<GLButton type="danger">危险按钮</GLButton>
</div> <!-- API 配置 -->
</div> <div class="state-item">
<div class="state-label">
<!-- 加载状态 --> ⚙️ API 配置
<div class="demo-section"> </div>
<h5 class="section-subtitle">加载状态</h5> <div class="state-value state-value-small">
<div class="button-demo-group"> {{ globalState.config.apiBaseUrl }}
<GLButton type="primary" loading>加载中</GLButton> </div>
<GLButton </div>
type="success" </div>
:loading="buttonLoading" <div v-else class="state-loading">
@click="handleAsyncClick" 加载中...
> </div>
点击模拟异步操作 </div>
</GLButton>
</div> <!-- 右侧:通信操作区 -->
</div> <div class="action-panel">
<h3 class="panel-title">
<!-- 禁用状态 --> 通信操作
<div class="demo-section"> </h3>
<h5 class="section-subtitle">禁用状态</h5>
<div class="button-demo-group"> <!-- 快速发送消息 -->
<GLButton type="primary" disabled>禁用按钮</GLButton> <div class="action-group">
<GLButton type="success" disabled>禁用按钮</GLButton> <div class="action-label">
</div> 快速发送消息到微应用:
</div> </div>
<div class="button-group">
<button class="action-btn success-btn"
@click="sendSuccessMessage">
✓ 发送成功消息
</button>
</div>
</div>
<!-- 自定义消息 -->
<div class="action-group">
<div class="action-label">
自定义消息:
</div>
<input v-model="messageTitle"
class="input-field"
placeholder="消息标题"
type="text" />
<textarea v-model="messageContent"
class="textarea-field"
placeholder="消息内容"
rows="3">
</textarea>
<button class="action-btn primary-btn" @click="sendCustomMessage">
📤 发送自定义消息
</button>
</div>
<!-- 状态更新操作 -->
<div class="action-group">
<div class="action-label">
更新全局状态:
</div>
<div class="button-group">
<button class="action-btn theme-btn" @click="toggleTheme">
🎨 切换主题
</button>
<button class="action-btn user-btn" @click="updateUserInfo">
👤 更新用户
</button>
</div>
</div>
</div>
</div>
<!-- 确认提示 --> <!-- 通知消息列表 -->
<div class="demo-section"> <div class="notification-panel">
<h5 class="section-subtitle">确认提示</h5> <div class="notification-header">
<div class="button-demo-group"> <h3 class="panel-title">
<GLButton 📬 消息通知列表
type="warning" </h3>
confirm-text="确定要执行这个操作吗?" <button v-if="globalState?.notifications.length"
@click="handleConfirmClick" class="clear-btn"
> @click="clearAllNotifications">
点击需要确认 清空全部
</GLButton> </button>
<GLButton </div>
type="danger"
confirm-text="确定要删除吗?此操作不可恢复!" <div v-if="globalState?.notifications.length" class="notification-list">
@click="handleDeleteClick" <div v-for="notification in globalState.notifications"
> :key="notification.id"
删除操作 class="notification-item"
</GLButton> :class="[`notification-${notification.type}`]">
</div> <div class="notification-icon">
</div> <span v-if="notification.type === 'success'">✓</span>
<span v-else-if="notification.type === 'warning'">⚠</span>
<span v-else-if="notification.type === 'error'">✕</span>
<span v-else>ℹ</span>
</div>
<div class="notification-content">
<div class="notification-title">
{{ notification.title }}
</div>
<div class="notification-message">
{{ notification.message }}
</div>
<div class="notification-meta">
<span v-if="notification.from"
class="notification-from">
来自: {{ notification.from }}
</span>
<span class="notification-time">
{{
formatTime(notification.timestamp)
}}
</span>
</div>
</div>
<button class="notification-close"
@click="removeNotification(notification.id)">
✕
</button>
</div>
</div>
<div v-else class="notification-empty">
<div class="empty-icon">
📭
</div>
<div class="empty-text">
暂无消息通知
</div>
<div class="empty-hint">
点击上方按钮发送消息,微应用也可以发送消息到这里
</div>
</div>
</div>
<!-- 防抖 --> <!-- 使用说明 -->
<div class="demo-section"> <div class="usage-tips">
<h5 class="section-subtitle">防抖功能(1秒)</h5> <h4>💡 使用说明</h4>
<div class="button-demo-group"> <ul>
<GLButton <li>
type="primary" <strong>全局状态:</strong>主应用和微应用共享的状态,任何一方修改都会实时同步。
:debounce="1000" </li>
@click="handleDebounceClick" <li>
> <strong>消息通知:</strong>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
防抖按钮 (1s) </li>
</GLButton> <li>
<span class="demo-tip">点击次数: {{ clickCount }}</span> <strong>实时监听:</strong>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
</div> </li>
</div> <li>
<strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用
<code>actions.setGlobalState()</code> 和
<code>actions.onGlobalStateChange()</code> 进行通信。
</li>
</ul>
</div>
<!-- 图标按钮 --> <!-- Element Plus 原生按钮示例 -->
<div class="demo-section"> <div class="component-demo">
<h5 class="section-subtitle">图标按钮</h5> <h4 class="demo-title">
<div class="button-demo-group"> 📦 Element Plus 原生按钮
<GLButton type="primary" :icon="Search">搜索</GLButton> </h4>
<GLButton type="success" :icon="Check">确认</GLButton> <div class="button-demo-group">
<GLButton type="warning" :icon="Edit">编辑</GLButton> <el-button type="primary">
<GLButton type="danger" :icon="Delete">删除</GLButton> Primary
<GLButton type="info" :icon="Message" circle /> </el-button>
<GLButton type="primary" :icon="Star" circle /> <el-button type="success">
</div> Success
</div> </el-button>
<el-button type="info">
Info
</el-button>
<el-button type="warning">
Warning
</el-button>
<el-button type="danger">
Danger
</el-button>
</div>
</div>
<!-- 插槽 --> <!-- GLButton 组件库按钮示例 -->
<div class="demo-section"> <div class="component-demo">
<h5 class="section-subtitle">防抖功能(1秒)</h5> <h4 class="demo-title">
<div class="button-demo-group"> 🎨 @venus/common-ui-vue GLButton 组件
<GLButton </h4>
type="primary"
:debounce="1000" <!-- 基础按钮 -->
@click="handleDebounceClick" <div class="demo-section">
> <h5 class="section-subtitle">
<template #icon> 基础样式
<span>这是图标</span> </h5>
</template> <div class="button-demo-group">
防抖按钮 (1s) <GLButton type="primary">
</GLButton> 主要按钮
<span class="demo-tip">点击次数: {{ clickCount }}</span> </GLButton>
</div> <GLButton type="success">
成功按钮
</GLButton>
<GLButton type="info">
信息按钮
</GLButton>
<GLButton type="warning">
警告按钮
</GLButton>
<GLButton type="danger">
危险按钮
</GLButton>
</div>
</div>
<!-- 加载状态 -->
<div class="demo-section">
<h5 class="section-subtitle">
加载状态
</h5>
<div class="button-demo-group">
<GLButton loading type="primary">
加载中
</GLButton>
<GLButton :loading="buttonLoading"
type="success"
@click="handleAsyncClick">
点击模拟异步操作
</GLButton>
</div>
</div>
<!-- 禁用状态 -->
<div class="demo-section">
<h5 class="section-subtitle">
禁用状态
</h5>
<div class="button-demo-group">
<GLButton disabled type="primary">
禁用按钮
</GLButton>
<GLButton disabled type="success">
禁用按钮
</GLButton>
</div>
</div>
<!-- 确认提示 -->
<div class="demo-section">
<h5 class="section-subtitle">
确认提示
</h5>
<div class="button-demo-group">
<GLButton confirm-text="确定要执行这个操作吗?"
type="warning"
@click="handleConfirmClick">
点击需要确认
</GLButton>
<GLButton confirm-text="确定要删除吗?此操作不可恢复!"
type="danger"
@click="handleDeleteClick">
删除操作
</GLButton>
</div>
</div>
<!-- 防抖 -->
<div class="demo-section">
<h5 class="section-subtitle">
防抖功能(1秒)
</h5>
<div class="button-demo-group">
<GLButton :debounce="1000"
type="primary"
@click="handleDebounceClick">
防抖按钮 (1s)
</GLButton>
<span class="demo-tip">点击次数: {{ clickCount }}</span>
</div>
</div>
<!-- 图标按钮 -->
<div class="demo-section">
<h5 class="section-subtitle">
图标按钮
</h5>
<div class="button-demo-group">
<GLButton :icon="Search" type="primary">
搜索
</GLButton>
<GLButton :icon="Check" type="success">
确认
</GLButton>
<GLButton :icon="Edit" type="warning">
编辑
</GLButton>
<GLButton :icon="Delete" type="danger">
删除
</GLButton>
<GLButton circle
:icon="Message"
type="info" />
<GLButton circle
:icon="Star"
type="primary" />
</div>
</div>
<!-- 插槽 -->
<div class="demo-section">
<h5 class="section-subtitle">
防抖功能(1秒)
</h5>
<div class="button-demo-group">
<GLButton :debounce="1000"
type="primary"
@click="handleDebounceClick">
<template #icon>
<span>这是图标</span>
</template>
防抖按钮 (1s)
</GLButton>
<span class="demo-tip">点击次数: {{ clickCount }}</span>
</div>
</div>
</div>
</div> </div>
</div> <el-drawer v-model="drawer"
title="I am the title"
:with-header="false">
<span>Hi there!</span>
</el-drawer>
</div> </div>
<el-drawer v-model="drawer" title="I am the title" :with-header="false">
<span>Hi there!</span>
</el-drawer>
</div>
</template> </template>
<style scoped> <style scoped>
......
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted, nextTick } from 'vue'; import { nextTick, onMounted, onUnmounted } from "vue";
import { useRoute } from 'vue-router'; import { useRoute } from "vue-router";
import GlobalLoading from '@/components/GlobalLoading.vue'; import GlobalLoading from "@/components/GlobalLoading.vue";
const route = useRoute(); const route = useRoute();
onMounted(async () => { onMounted(async () => {
console.log('[基座] 微应用容器组件已挂载,当前路由:', route.path); console.log("[基座] 微应用容器组件已挂载,当前路由:", route.path);
// 等待 DOM 完全更新 // 等待 DOM 完全更新
await nextTick(); await nextTick();
// 确认容器元素已存在 // 确认容器元素已存在
const container = document.getElementById('subapp-container'); const container = document.querySelector("#subapp-container");
if (container) { if (container) {
console.log('[基座] 微应用容器 DOM 已就绪'); console.log("[基座] 微应用容器 DOM 已就绪");
} else { } else {
console.error('[基座] 微应用容器 DOM 未找到,可能导致微应用加载失败'); console.error("[基座] 微应用容器 DOM 未找到,可能导致微应用加载失败");
} }
}); });
onUnmounted(() => { onUnmounted(() => {
console.log('[基座] 微应用容器已卸载'); console.log("[基座] 微应用容器已卸载");
}); });
</script> </script>
<template> <template>
<div class="micro-app-wrapper"> <div class="micro-app-wrapper">
<!-- qiankun 微应用容器 - 作为唯一的微应用挂载点 --> <!-- qiankun 微应用容器 - 作为唯一的微应用挂载点 -->
<div id="subapp-container" class="micro-app-container"></div> <div id="subapp-container" class="micro-app-container"></div>
<!-- 子应用加载中的 loading --> <!-- 子应用加载中的 loading -->
<GlobalLoading /> <GlobalLoading />
</div> </div>
</template> </template>
<style scoped> <style scoped>
......
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://lefthook.dev/configuration/
#
# pre-push:
# jobs:
# - name: packages audit
# tags:
# - frontend
# - security
# run: yarn audit
#
# - name: gems audit
# tags:
# - backend
# - security
# run: bundle audit
#
# pre-commit:
# parallel: true
# jobs:
# - run: yarn eslint {staged_files}
# glob: "*.{js,ts,jsx,tsx}"
#
# - name: rubocop
# glob: "*.rb"
# exclude:
# - config/application.rb
# - config/routes.rb
# run: bundle exec rubocop --force-exclusion {all_files}
#
# - name: govet
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
#
# - script: "hello.js"
# runner: node
#
# - script: "hello.go"
# runner: go run
pre-commit: pre-commit:
parallel: true parallel: true
commands: commands:
code-workspace: code-workspace:
run: pnpm vsh code-workspace --auto-commit run: pnpm vsh code-workspace --auto-commit
# lint-staged: lint-staged:
# run: pnpm lint-staged run: pnpm lint-staged
post-merge: post-merge:
commands: commands:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!