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,
...@@ -22,27 +22,27 @@ const state = reactive<GlobalState>({ ...@@ -22,27 +22,27 @@ const state = reactive<GlobalState>({
// 通知表单 // 通知表单
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" },
]; ];
// 切换用户 // 切换用户
...@@ -58,43 +58,43 @@ const switchUser = (role: string) => { ...@@ -58,43 +58,43 @@ const switchUser = (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" ? "浅色" : "深色"}模式`,
); );
}; };
...@@ -102,13 +102,12 @@ const toggleThemeMode = () => { ...@@ -102,13 +102,12 @@ const toggleThemeMode = () => {
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;
} }
...@@ -119,21 +118,21 @@ const sendNotification = () => { ...@@ -119,21 +118,21 @@ const sendNotification = () => {
); );
// 清空表单 // 清空表单
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小时",
}, },
}; };
...@@ -144,7 +143,7 @@ const sendQuickNotification = ( ...@@ -144,7 +143,7 @@ const sendQuickNotification = (
// 更新配置 // 更新配置
const updateConfig = () => { const updateConfig = () => {
communicationManager.updateConfig(configForm); communicationManager.updateConfig(configForm);
broadcast('success', '配置更新', '系统配置已更新'); broadcast("success", "配置更新", "系统配置已更新");
}; };
// 监听全局状态变化 // 监听全局状态变化
...@@ -176,7 +175,9 @@ onUnmounted(() => { ...@@ -176,7 +175,9 @@ onUnmounted(() => {
<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">
演示基座与子应用之间的数据通信
</p>
</div> </div>
<div class="demo-container"> <div class="demo-container">
...@@ -208,9 +209,11 @@ onUnmounted(() => { ...@@ -208,9 +209,11 @@ onUnmounted(() => {
</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.permissions.join(', ') state.user.permissions.join(', ')
}}</span> }}
</span>
</div> </div>
</div> </div>
</div> </div>
...@@ -218,17 +221,19 @@ onUnmounted(() => { ...@@ -218,17 +221,19 @@ onUnmounted(() => {
<div class="user-actions"> <div class="user-actions">
<h3>切换用户</h3> <h3>切换用户</h3>
<div class="button-group"> <div class="button-group">
<button @click="switchUser('admin')" class="btn btn-primary"> <button class="btn btn-primary" @click="switchUser('admin')">
切换到管理员 切换到管理员
</button> </button>
<button @click="switchUser('user')" class="btn btn-secondary"> <button class="btn btn-secondary" @click="switchUser('user')">
切换到普通用户 切换到普通用户
</button> </button>
<button @click="switchUser('guest')" class="btn btn-secondary"> <button class="btn btn-secondary" @click="switchUser('guest')">
切换到访客 切换到访客
</button> </button>
</div> </div>
<p class="hint">💡 切换用户后,子应用会实时接收到新的用户信息</p> <p class="hint">
💡 切换用户后,子应用会实时接收到新的用户信息
</p>
</div> </div>
</div> </div>
</div> </div>
...@@ -244,17 +249,18 @@ onUnmounted(() => { ...@@ -244,17 +249,18 @@ onUnmounted(() => {
<h3>当前主题</h3> <h3>当前主题</h3>
<div class="info-row"> <div class="info-row">
<span class="label">模式:</span> <span class="label">模式:</span>
<span class="value">{{ <span class="value">
{{
state.theme.mode === 'light' ? '🌞 浅色' : '🌙 深色' state.theme.mode === 'light' ? '🌞 浅色' : '🌙 深色'
}}</span> }}
</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">
<span <span class="color-preview"
class="color-preview" :style="{ backgroundColor: state.theme.primaryColor }">
:style="{ backgroundColor: state.theme.primaryColor }" </span>
></span>
{{ state.theme.primaryColor }} {{ state.theme.primaryColor }}
</span> </span>
</div> </div>
...@@ -263,27 +269,28 @@ onUnmounted(() => { ...@@ -263,27 +269,28 @@ onUnmounted(() => {
<div class="theme-actions"> <div class="theme-actions">
<h3>切换主题</h3> <h3>切换主题</h3>
<div class="button-group"> <div class="button-group">
<button @click="toggleThemeMode" class="btn btn-primary"> <button class="btn btn-primary" @click="toggleThemeMode">
切换{{ state.theme.mode === 'light' ? '深色' : '浅色' }}模式 切换{{ state.theme.mode === 'light' ? '深色' : '浅色' }}模式
</button> </button>
</div> </div>
<div class="color-picker"> <div class="color-picker">
<label>选择主色调:</label> <label>选择主色调:</label>
<div class="color-options"> <div class="color-options">
<button <button v-for="color in colorOptions"
v-for="color in colorOptions"
:key="color.value" :key="color.value"
:style="{ backgroundColor: color.value }"
class="color-btn" class="color-btn"
:class="[ :class="[
{ active: state.theme.primaryColor === color.value }, { active: state.theme.primaryColor === color.value },
]" ]"
@click="changeColor(color.value)" :style="{ backgroundColor: color.value }"
:title="color.name" :title="color.name"
></button> @click="changeColor(color.value)">
</button>
</div> </div>
</div> </div>
<p class="hint">💡 主题变化会同步到所有子应用</p> <p class="hint">
💡 主题变化会同步到所有子应用
</p>
</div> </div>
</div> </div>
</div> </div>
...@@ -300,31 +307,36 @@ onUnmounted(() => { ...@@ -300,31 +307,36 @@ onUnmounted(() => {
<div class="form-group"> <div class="form-group">
<label>通知类型:</label> <label>通知类型:</label>
<select v-model="notificationForm.type" class="form-control"> <select v-model="notificationForm.type" class="form-control">
<option value="success">✅ 成功</option> <option value="success">
<option value="warning">⚠️ 警告</option> ✅ 成功
<option value="error">❌ 错误</option> </option>
<option value="info">ℹ️ 信息</option> <option value="warning">
⚠️ 警告
</option>
<option value="error">
❌ 错误
</option>
<option value="info">
ℹ️ 信息
</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>标题:</label> <label>标题:</label>
<input <input v-model="notificationForm.title"
v-model="notificationForm.title"
type="text"
class="form-control" class="form-control"
placeholder="请输入通知标题" placeholder="请输入通知标题"
/> type="text" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>内容:</label> <label>内容:</label>
<textarea <textarea v-model="notificationForm.message"
v-model="notificationForm.message"
class="form-control" class="form-control"
rows="3"
placeholder="请输入通知内容" placeholder="请输入通知内容"
></textarea> rows="3">
</textarea>
</div> </div>
<button @click="sendNotification" class="btn btn-primary btn-block"> <button class="btn btn-primary btn-block" @click="sendNotification">
发送通知 发送通知
</button> </button>
<p class="hint"> <p class="hint">
...@@ -335,28 +347,20 @@ onUnmounted(() => { ...@@ -335,28 +347,20 @@ onUnmounted(() => {
<div class="quick-actions"> <div class="quick-actions">
<h3>快速测试</h3> <h3>快速测试</h3>
<div class="button-group"> <div class="button-group">
<button <button class="btn btn-success"
@click="sendQuickNotification('success')" @click="sendQuickNotification('success')">
class="btn btn-success"
>
成功消息 成功消息
</button> </button>
<button <button class="btn btn-warning"
@click="sendQuickNotification('warning')" @click="sendQuickNotification('warning')">
class="btn btn-warning"
>
警告消息 警告消息
</button> </button>
<button <button class="btn btn-danger"
@click="sendQuickNotification('error')" @click="sendQuickNotification('error')">
class="btn btn-danger"
>
错误消息 错误消息
</button> </button>
<button <button class="btn btn-info"
@click="sendQuickNotification('info')" @click="sendQuickNotification('info')">
class="btn btn-info"
>
信息消息 信息消息
</button> </button>
</div> </div>
...@@ -387,24 +391,22 @@ onUnmounted(() => { ...@@ -387,24 +391,22 @@ onUnmounted(() => {
<h3>更新配置</h3> <h3>更新配置</h3>
<div class="form-group"> <div class="form-group">
<label>API 地址:</label> <label>API 地址:</label>
<input <input v-model="configForm.apiBaseUrl"
v-model="configForm.apiBaseUrl"
type="text"
class="form-control" class="form-control"
/> type="text" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>请求超时 (ms):</label> <label>请求超时 (ms):</label>
<input <input v-model.number="configForm.timeout"
v-model.number="configForm.timeout"
type="number"
class="form-control" class="form-control"
/> type="number" />
</div> </div>
<button @click="updateConfig" class="btn btn-primary"> <button class="btn btn-primary" @click="updateConfig">
更新配置 更新配置
</button> </button>
<p class="hint">💡 配置更新后,所有子应用都会收到最新配置</p> <p class="hint">
💡 配置更新后,所有子应用都会收到最新配置
</p>
</div> </div>
</div> </div>
</div> </div>
......
<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,
...@@ -15,7 +15,7 @@ import { ...@@ -15,7 +15,7 @@ import {
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;
...@@ -35,8 +35,7 @@ const clickCount = ref(0); ...@@ -35,8 +35,7 @@ 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();
...@@ -55,55 +54,55 @@ onUnmounted(() => { ...@@ -55,55 +54,55 @@ onUnmounted(() => {
// 发送成功消息 // 发送成功消息
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}`);
}; };
// 清空所有通知 // 清空所有通知
...@@ -119,74 +118,96 @@ const removeNotification = (id: string) => { ...@@ -119,74 +118,96 @@ const removeNotification = (id: string) => {
// 格式化时间 // 格式化时间
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> 欢迎使用
</h1>
<p class="subtitle">
基于 qiankun + Vue3 + Vite 构建的微前端主应用
</p>
</div> </div>
<el-button @click="drawer = true">Open</el-button> <el-button @click="drawer = true">
Open
</el-button>
<div class="feature-section"> <div class="feature-section">
<div class="feature-card"> <div class="feature-card">
<div class="feature-icon">微</div> <div class="feature-icon">
<h3 class="feature-title">微前端架构</h3> 微
</div>
<h3 class="feature-title">
微前端架构
</h3>
<p class="feature-desc"> <p class="feature-desc">
使用 qiankun 实现微前端架构,支持多业务线独立开发与部署。 使用 qiankun 实现微前端架构,支持多业务线独立开发与部署。
</p> </p>
</div> </div>
<div class="feature-card"> <div class="feature-card">
<div class="feature-icon">速</div> <div class="feature-icon">
<h3 class="feature-title">Vue3 + Vite</h3> 速
</div>
<h3 class="feature-title">
Vue3 + Vite
</h3>
<p class="feature-desc"> <p class="feature-desc">
结合 Vue3 组合式 API 与 Vite 极致构建体验,显著提升开发效率。 结合 Vue3 组合式 API 与 Vite 极致构建体验,显著提升开发效率。
</p> </p>
</div> </div>
<div class="feature-card"> <div class="feature-card">
<div class="feature-icon">拓</div> <div class="feature-icon">
<h3 class="feature-title">灵活扩展</h3> 拓
</div>
<h3 class="feature-title">
灵活扩展
</h3>
<p class="feature-desc"> <p class="feature-desc">
支持动态注册微应用,可按需扩展业务模块与发布策略。 支持动态注册微应用,可按需扩展业务模块与发布策略。
</p> </p>
</div> </div>
<div class="feature-card"> <div class="feature-card">
<div class="feature-icon">稳</div> <div class="feature-icon">
<h3 class="feature-title">稳定可靠</h3> 稳
</div>
<h3 class="feature-title">
稳定可靠
</h3>
<p class="feature-desc"> <p class="feature-desc">
提供完善的权限体系与平台级监控,保障微前端运行稳定。 提供完善的权限体系与平台级监控,保障微前端运行稳定。
</p> </p>
...@@ -207,14 +228,14 @@ const handleDebounceClick = () => { ...@@ -207,14 +228,14 @@ const handleDebounceClick = () => {
<div class="info-card"> <div class="info-card">
<h3>微应用列表</h3> <h3>微应用列表</h3>
<ul class="app-list"> <ul class="app-list">
<li v-for="app in apps" :key="app.name" class="app-item"> <li v-for="app in apps"
:key="app.name"
class="app-item">
<span class="app-name">{{ app.name }}</span> <span class="app-name">{{ app.name }}</span>
<span class="app-port">{{ app.entry }}</span> <span class="app-port">{{ app.entry }}</span>
<router-link <router-link v-if="typeof app.activeRule === 'string'"
v-if="typeof app.activeRule === 'string'"
:to="app.activeRule"
class="app-link" class="app-link"
> :to="app.activeRule">
进入 > 进入 >
</router-link> </router-link>
<span v-else class="app-link disabled">暂不可用</span> <span v-else class="app-link disabled">暂不可用</span>
...@@ -233,68 +254,83 @@ const handleDebounceClick = () => { ...@@ -233,68 +254,83 @@ const handleDebounceClick = () => {
<div class="communication-content"> <div class="communication-content">
<!-- 左侧:全局状态展示 --> <!-- 左侧:全局状态展示 -->
<div class="state-panel"> <div class="state-panel">
<h3 class="panel-title">全局共享状态</h3> <h3 class="panel-title">
全局共享状态
</h3>
<div v-if="globalState" class="state-content"> <div v-if="globalState" class="state-content">
<!-- 用户信息 --> <!-- 用户信息 -->
<div class="state-item"> <div class="state-item">
<div class="state-label">👤 当前用户</div> <div class="state-label">
👤 当前用户
</div>
<div class="state-value"> <div class="state-value">
<span class="user-avatar">{{ globalState.user?.avatar }}</span> <span class="user-avatar">{{ globalState.user?.avatar }}</span>
<span <span>
>{{ globalState.user?.name }} ({{ {{ globalState.user?.name }} ({{
globalState.user?.role globalState.user?.role
}})</span }})
> </span>
</div> </div>
</div> </div>
<!-- 主题 --> <!-- 主题 -->
<div class="state-item"> <div class="state-item">
<div class="state-label">🎨 主题模式</div> <div class="state-label">
🎨 主题模式
</div>
<div class="state-value"> <div class="state-value">
{{ {{
globalState.theme.mode === 'light' ? '浅色模式' : '深色模式' globalState.theme.mode === 'light' ? '浅色模式' : '深色模式'
}} }}
<span <span class="theme-color"
class="theme-color" :style="{ backgroundColor: globalState.theme.primaryColor }">
:style="{ backgroundColor: globalState.theme.primaryColor }" </span>
></span>
</div> </div>
</div> </div>
<!-- 通知数量 --> <!-- 通知数量 -->
<div class="state-item"> <div class="state-item">
<div class="state-label">🔔 通知数量</div> <div class="state-label">
🔔 通知数量
</div>
<div class="state-value"> <div class="state-value">
<span class="notification-badge">{{ <span class="notification-badge">
{{
globalState.notifications.length globalState.notifications.length
}}</span> }}
</span>
</div> </div>
</div> </div>
<!-- API 配置 --> <!-- API 配置 -->
<div class="state-item"> <div class="state-item">
<div class="state-label">⚙️ API 配置</div> <div class="state-label">
⚙️ API 配置
</div>
<div class="state-value state-value-small"> <div class="state-value state-value-small">
{{ globalState.config.apiBaseUrl }} {{ globalState.config.apiBaseUrl }}
</div> </div>
</div> </div>
</div> </div>
<div v-else class="state-loading">加载中...</div> <div v-else class="state-loading">
加载中...
</div>
</div> </div>
<!-- 右侧:通信操作区 --> <!-- 右侧:通信操作区 -->
<div class="action-panel"> <div class="action-panel">
<h3 class="panel-title">通信操作</h3> <h3 class="panel-title">
通信操作
</h3>
<!-- 快速发送消息 --> <!-- 快速发送消息 -->
<div class="action-group"> <div class="action-group">
<div class="action-label">快速发送消息到微应用:</div> <div class="action-label">
快速发送消息到微应用:
</div>
<div class="button-group"> <div class="button-group">
<button <button class="action-btn success-btn"
class="action-btn success-btn" @click="sendSuccessMessage">
@click="sendSuccessMessage"
>
✓ 发送成功消息 ✓ 发送成功消息
</button> </button>
</div> </div>
...@@ -302,19 +338,18 @@ const handleDebounceClick = () => { ...@@ -302,19 +338,18 @@ const handleDebounceClick = () => {
<!-- 自定义消息 --> <!-- 自定义消息 -->
<div class="action-group"> <div class="action-group">
<div class="action-label">自定义消息:</div> <div class="action-label">
<input 自定义消息:
v-model="messageTitle" </div>
type="text" <input v-model="messageTitle"
class="input-field" class="input-field"
placeholder="消息标题" placeholder="消息标题"
/> type="text" />
<textarea <textarea v-model="messageContent"
v-model="messageContent"
class="textarea-field" class="textarea-field"
placeholder="消息内容" placeholder="消息内容"
rows="3" rows="3">
></textarea> </textarea>
<button class="action-btn primary-btn" @click="sendCustomMessage"> <button class="action-btn primary-btn" @click="sendCustomMessage">
📤 发送自定义消息 📤 发送自定义消息
</button> </button>
...@@ -322,7 +357,9 @@ const handleDebounceClick = () => { ...@@ -322,7 +357,9 @@ const handleDebounceClick = () => {
<!-- 状态更新操作 --> <!-- 状态更新操作 -->
<div class="action-group"> <div class="action-group">
<div class="action-label">更新全局状态:</div> <div class="action-label">
更新全局状态:
</div>
<div class="button-group"> <div class="button-group">
<button class="action-btn theme-btn" @click="toggleTheme"> <button class="action-btn theme-btn" @click="toggleTheme">
🎨 切换主题 🎨 切换主题
...@@ -338,23 +375,21 @@ const handleDebounceClick = () => { ...@@ -338,23 +375,21 @@ const handleDebounceClick = () => {
<!-- 通知消息列表 --> <!-- 通知消息列表 -->
<div class="notification-panel"> <div class="notification-panel">
<div class="notification-header"> <div class="notification-header">
<h3 class="panel-title">📬 消息通知列表</h3> <h3 class="panel-title">
<button 📬 消息通知列表
v-if="globalState?.notifications.length" </h3>
<button v-if="globalState?.notifications.length"
class="clear-btn" class="clear-btn"
@click="clearAllNotifications" @click="clearAllNotifications">
>
清空全部 清空全部
</button> </button>
</div> </div>
<div v-if="globalState?.notifications.length" class="notification-list"> <div v-if="globalState?.notifications.length" class="notification-list">
<div <div v-for="notification in globalState.notifications"
v-for="notification in globalState.notifications"
:key="notification.id" :key="notification.id"
class="notification-item" class="notification-item"
:class="[`notification-${notification.type}`]" :class="[`notification-${notification.type}`]">
>
<div class="notification-icon"> <div class="notification-icon">
<span v-if="notification.type === 'success'">✓</span> <span v-if="notification.type === 'success'">✓</span>
<span v-else-if="notification.type === 'warning'">⚠</span> <span v-else-if="notification.type === 'warning'">⚠</span>
...@@ -362,29 +397,38 @@ const handleDebounceClick = () => { ...@@ -362,29 +397,38 @@ const handleDebounceClick = () => {
<span v-else>ℹ</span> <span v-else>ℹ</span>
</div> </div>
<div class="notification-content"> <div class="notification-content">
<div class="notification-title">{{ notification.title }}</div> <div class="notification-title">
<div class="notification-message">{{ notification.message }}</div> {{ notification.title }}
</div>
<div class="notification-message">
{{ notification.message }}
</div>
<div class="notification-meta"> <div class="notification-meta">
<span v-if="notification.from" class="notification-from" <span v-if="notification.from"
>来自: {{ notification.from }}</span class="notification-from">
> 来自: {{ notification.from }}
<span class="notification-time">{{ </span>
<span class="notification-time">
{{
formatTime(notification.timestamp) formatTime(notification.timestamp)
}}</span> }}
</span>
</div> </div>
</div> </div>
<button <button class="notification-close"
class="notification-close" @click="removeNotification(notification.id)">
@click="removeNotification(notification.id)"
>
✕ ✕
</button> </button>
</div> </div>
</div> </div>
<div v-else class="notification-empty"> <div v-else class="notification-empty">
<div class="empty-icon">📭</div> <div class="empty-icon">
<div class="empty-text">暂无消息通知</div> 📭
</div>
<div class="empty-text">
暂无消息通知
</div>
<div class="empty-hint"> <div class="empty-hint">
点击上方按钮发送消息,微应用也可以发送消息到这里 点击上方按钮发送消息,微应用也可以发送消息到这里
</div> </div>
...@@ -396,16 +440,13 @@ const handleDebounceClick = () => { ...@@ -396,16 +440,13 @@ const handleDebounceClick = () => {
<h4>💡 使用说明</h4> <h4>💡 使用说明</h4>
<ul> <ul>
<li> <li>
<strong>全局状态:</strong <strong>全局状态:</strong>主应用和微应用共享的状态,任何一方修改都会实时同步。
>主应用和微应用共享的状态,任何一方修改都会实时同步。
</li> </li>
<li> <li>
<strong>消息通知:</strong <strong>消息通知:</strong>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
</li> </li>
<li> <li>
<strong>实时监听:</strong <strong>实时监听:</strong>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
</li> </li>
<li> <li>
<strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用 <strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用
...@@ -417,42 +458,70 @@ const handleDebounceClick = () => { ...@@ -417,42 +458,70 @@ const handleDebounceClick = () => {
<!-- Element Plus 原生按钮示例 --> <!-- Element Plus 原生按钮示例 -->
<div class="component-demo"> <div class="component-demo">
<h4 class="demo-title">📦 Element Plus 原生按钮</h4> <h4 class="demo-title">
📦 Element Plus 原生按钮
</h4>
<div class="button-demo-group"> <div class="button-demo-group">
<el-button type="primary">Primary</el-button> <el-button type="primary">
<el-button type="success">Success</el-button> Primary
<el-button type="info">Info</el-button> </el-button>
<el-button type="warning">Warning</el-button> <el-button type="success">
<el-button type="danger">Danger</el-button> Success
</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>
</div> </div>
<!-- GLButton 组件库按钮示例 --> <!-- GLButton 组件库按钮示例 -->
<div class="component-demo"> <div class="component-demo">
<h4 class="demo-title">🎨 @venus/common-ui-vue GLButton 组件</h4> <h4 class="demo-title">
🎨 @venus/common-ui-vue GLButton 组件
</h4>
<!-- 基础按钮 --> <!-- 基础按钮 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">基础样式</h5> <h5 class="section-subtitle">
基础样式
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton type="primary">主要按钮</GLButton> <GLButton type="primary">
<GLButton type="success">成功按钮</GLButton> 主要按钮
<GLButton type="info">信息按钮</GLButton> </GLButton>
<GLButton type="warning">警告按钮</GLButton> <GLButton type="success">
<GLButton type="danger">危险按钮</GLButton> 成功按钮
</GLButton>
<GLButton type="info">
信息按钮
</GLButton>
<GLButton type="warning">
警告按钮
</GLButton>
<GLButton type="danger">
危险按钮
</GLButton>
</div> </div>
</div> </div>
<!-- 加载状态 --> <!-- 加载状态 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">加载状态</h5> <h5 class="section-subtitle">
加载状态
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton type="primary" loading>加载中</GLButton> <GLButton loading type="primary">
<GLButton 加载中
</GLButton>
<GLButton :loading="buttonLoading"
type="success" type="success"
:loading="buttonLoading" @click="handleAsyncClick">
@click="handleAsyncClick"
>
点击模拟异步操作 点击模拟异步操作
</GLButton> </GLButton>
</div> </div>
...@@ -460,29 +529,33 @@ const handleDebounceClick = () => { ...@@ -460,29 +529,33 @@ const handleDebounceClick = () => {
<!-- 禁用状态 --> <!-- 禁用状态 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">禁用状态</h5> <h5 class="section-subtitle">
禁用状态
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton type="primary" disabled>禁用按钮</GLButton> <GLButton disabled type="primary">
<GLButton type="success" disabled>禁用按钮</GLButton> 禁用按钮
</GLButton>
<GLButton disabled type="success">
禁用按钮
</GLButton>
</div> </div>
</div> </div>
<!-- 确认提示 --> <!-- 确认提示 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">确认提示</h5> <h5 class="section-subtitle">
确认提示
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton <GLButton confirm-text="确定要执行这个操作吗?"
type="warning" type="warning"
confirm-text="确定要执行这个操作吗?" @click="handleConfirmClick">
@click="handleConfirmClick"
>
点击需要确认 点击需要确认
</GLButton> </GLButton>
<GLButton <GLButton confirm-text="确定要删除吗?此操作不可恢复!"
type="danger" type="danger"
confirm-text="确定要删除吗?此操作不可恢复!" @click="handleDeleteClick">
@click="handleDeleteClick"
>
删除操作 删除操作
</GLButton> </GLButton>
</div> </div>
...@@ -490,13 +563,13 @@ const handleDebounceClick = () => { ...@@ -490,13 +563,13 @@ const handleDebounceClick = () => {
<!-- 防抖 --> <!-- 防抖 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">防抖功能(1秒)</h5> <h5 class="section-subtitle">
防抖功能(1秒)
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton <GLButton :debounce="1000"
type="primary" type="primary"
:debounce="1000" @click="handleDebounceClick">
@click="handleDebounceClick"
>
防抖按钮 (1s) 防抖按钮 (1s)
</GLButton> </GLButton>
<span class="demo-tip">点击次数: {{ clickCount }}</span> <span class="demo-tip">点击次数: {{ clickCount }}</span>
...@@ -505,26 +578,40 @@ const handleDebounceClick = () => { ...@@ -505,26 +578,40 @@ const handleDebounceClick = () => {
<!-- 图标按钮 --> <!-- 图标按钮 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">图标按钮</h5> <h5 class="section-subtitle">
图标按钮
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton type="primary" :icon="Search">搜索</GLButton> <GLButton :icon="Search" type="primary">
<GLButton type="success" :icon="Check">确认</GLButton> 搜索
<GLButton type="warning" :icon="Edit">编辑</GLButton> </GLButton>
<GLButton type="danger" :icon="Delete">删除</GLButton> <GLButton :icon="Check" type="success">
<GLButton type="info" :icon="Message" circle /> 确认
<GLButton type="primary" :icon="Star" circle /> </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> </div>
<!-- 插槽 --> <!-- 插槽 -->
<div class="demo-section"> <div class="demo-section">
<h5 class="section-subtitle">防抖功能(1秒)</h5> <h5 class="section-subtitle">
防抖功能(1秒)
</h5>
<div class="button-demo-group"> <div class="button-demo-group">
<GLButton <GLButton :debounce="1000"
type="primary" type="primary"
:debounce="1000" @click="handleDebounceClick">
@click="handleDebounceClick"
>
<template #icon> <template #icon>
<span>这是图标</span> <span>这是图标</span>
</template> </template>
...@@ -535,7 +622,9 @@ const handleDebounceClick = () => { ...@@ -535,7 +622,9 @@ const handleDebounceClick = () => {
</div> </div>
</div> </div>
</div> </div>
<el-drawer v-model="drawer" title="I am the title" :with-header="false"> <el-drawer v-model="drawer"
title="I am the title"
:with-header="false">
<span>Hi there!</span> <span>Hi there!</span>
</el-drawer> </el-drawer>
</div> </div>
......
<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>
......
# 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!