MicroAppContainer.vue
2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import { getMicroAppByPath } from '../apps';
const route = useRoute();
const loading = ref(true);
const error = ref('');
let timer: null | number = null;
/**
* 初始化微应用容器
*/
onMounted(() => {
// 获取当前路径对应的微应用
const microApp = getMicroAppByPath(route.path);
if (!microApp) {
error.value = '未找到对应的微应用配置';
loading.value = false;
return;
}
// 模拟加载延迟和错误处理
timer = window.setTimeout(() => {
loading.value = false;
// 这里可以添加更多的加载逻辑
console.log('[MicroAppContainer] 微应用容器已准备就绪:', microApp.name);
}, 1000);
});
/**
* 清理定时器
*/
onUnmounted(() => {
if (timer) {
clearTimeout(timer);
timer = null;
}
});
/**
* 重试加载
*/
const handleRetry = () => {
error.value = '';
loading.value = true;
timer = window.setTimeout(() => {
loading.value = false;
}, 1000);
};
</script>
<template>
<div class="micro-app-container">
<!-- 微应用加载状态显示 -->
<!-- <div v-if="loading" class="loading-container">
<div class="loading-spinner"></div>
<p class="loading-text">正在加载微应用...</p>
</div>
-->
<!-- 微应用加载失败提示 -->
<div v-if="error" class="error-container">
<div class="error-icon">⚠️</div>
<p class="error-text">{{ error }}</p>
<button class="retry-button" @click="handleRetry">重试</button>
</div>
</div>
</template>
<style scoped>
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.micro-app-container {
width: 100%;
}
/* 加载状态 */
.loading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.loading-spinner {
width: 48px;
border: 4px solid #f3f3f3;
border-top: 4px solid #1890ff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
.loading-text {
margin-top: 16px;
font-size: 14px;
color: #666;
}
/* 错误状态 */
.error-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 400px;
}
.error-icon {
margin-bottom: 16px;
font-size: 48px;
}
.error-text {
margin-bottom: 16px;
font-size: 14px;
color: #ff4d4f;
}
.retry-button {
padding: 8px 24px;
font-size: 14px;
color: white;
cursor: pointer;
background-color: #1890ff;
border: none;
border-radius: 4px;
transition: background-color 0.3s;
}
.retry-button:hover {
background-color: #40a9ff;
}
.retry-button:active {
background-color: #096dd9;
}
</style>