@ysgroup/ui 0.1.36 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
YsServiceStatus —— 服务状态与无感升级。放在 YsPageLayout 的 #toolbar 最前面(登录页也可放一个)。
|
|
3
|
+
状态由 @ysgroup/core 的 store 提供:connected、disconnectedAt、restarting、updateAvailable。
|
|
4
|
+
|
|
5
|
+
- 断开 3 秒内不提示;之后顶栏小标签「正在重新连接…」,服务端主动重启时立即显示「系统正在更新…」。
|
|
6
|
+
- 断开超过 15 秒弹出不可关闭的维护弹窗(一次部署通常 10 秒内恢复,只看到顶栏标签),说明情况和已等待时长,可立即重试;
|
|
7
|
+
超过 60 秒再给「刷新页面」兜底。还没发出的请求在 core 里排队,恢复后自动继续。
|
|
8
|
+
- 恢复后短暂显示「已恢复」。发现新版本前端时:没有正在编辑就直接 emit("reload");
|
|
9
|
+
正在编辑(打开了弹窗或焦点在输入框)就显示提示条,等用户保存后切换页面或点「立即刷新」。
|
|
10
|
+
-->
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
13
|
+
import { Loading } from "@element-plus/icons-vue";
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
connected: boolean;
|
|
18
|
+
disconnectedAt: number;
|
|
19
|
+
restarting?: boolean;
|
|
20
|
+
updateAvailable?: boolean;
|
|
21
|
+
/** 顶栏小标签。登录页没有顶栏时传 false,只保留弹窗。 */
|
|
22
|
+
badge?: boolean;
|
|
23
|
+
/** 判断用户是否正在编辑;不传用默认规则(有打开的弹窗或焦点在输入框)。 */
|
|
24
|
+
isBusy?: () => boolean;
|
|
25
|
+
}>(),
|
|
26
|
+
{ restarting: false, updateAvailable: false, badge: true, isBusy: undefined },
|
|
27
|
+
);
|
|
28
|
+
const emit = defineEmits<{ retry: []; reload: [] }>();
|
|
29
|
+
|
|
30
|
+
const BADGE_AFTER_MS = 3_000;
|
|
31
|
+
/** 一次部署通常 10 秒内恢复:只看顶栏标签,不为几秒的停机闪一下弹窗。 */
|
|
32
|
+
const DIALOG_AFTER_MS = 15_000;
|
|
33
|
+
const MANUAL_REFRESH_AFTER_MS = 60_000;
|
|
34
|
+
|
|
35
|
+
const now = ref(Date.now());
|
|
36
|
+
const recovered = ref(false);
|
|
37
|
+
const deferred = ref(false);
|
|
38
|
+
let tick: ReturnType<typeof setInterval> | undefined;
|
|
39
|
+
/** 本次断开的开始时间和是否提示过「正在更新」。store 连上后会把 disconnectedAt 清零,所以这里自己记。 */
|
|
40
|
+
let downSince = 0;
|
|
41
|
+
let restartSeen = false;
|
|
42
|
+
let recoveredTimer: ReturnType<typeof setTimeout> | undefined;
|
|
43
|
+
|
|
44
|
+
const elapsed = computed(() =>
|
|
45
|
+
props.connected || !props.disconnectedAt
|
|
46
|
+
? 0
|
|
47
|
+
: Math.max(0, now.value - props.disconnectedAt),
|
|
48
|
+
);
|
|
49
|
+
const showDialog = computed(
|
|
50
|
+
() => !props.connected && elapsed.value >= DIALOG_AFTER_MS,
|
|
51
|
+
);
|
|
52
|
+
const badgeText = computed(() => {
|
|
53
|
+
if (props.connected) return recovered.value ? "已恢复" : "";
|
|
54
|
+
if (props.restarting) return "系统正在更新…";
|
|
55
|
+
return elapsed.value >= BADGE_AFTER_MS ? "正在重新连接…" : "";
|
|
56
|
+
});
|
|
57
|
+
const seconds = computed(() => Math.floor(elapsed.value / 1000));
|
|
58
|
+
const manualRefresh = computed(() => elapsed.value >= MANUAL_REFRESH_AFTER_MS);
|
|
59
|
+
|
|
60
|
+
function defaultBusy(): boolean {
|
|
61
|
+
if (typeof document === "undefined") return false;
|
|
62
|
+
const overlays = document.querySelectorAll<HTMLElement>(
|
|
63
|
+
".el-overlay, .el-message-box__wrapper, .el-drawer__wrapper",
|
|
64
|
+
);
|
|
65
|
+
for (const overlay of overlays) {
|
|
66
|
+
if (overlay.closest(".ys-service-status__dialog-overlay")) continue;
|
|
67
|
+
if (getComputedStyle(overlay).display !== "none") return true;
|
|
68
|
+
}
|
|
69
|
+
const active = document.activeElement as HTMLElement | null;
|
|
70
|
+
if (!active) return false;
|
|
71
|
+
return (
|
|
72
|
+
active.isContentEditable ||
|
|
73
|
+
["INPUT", "TEXTAREA", "SELECT"].includes(active.tagName)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function busy(): boolean {
|
|
78
|
+
return (props.isBusy ?? defaultBusy)();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 有新版本且连接正常时:不打扰用户就直接重载,否则提示,下次切换页面或用户点击时再重载。 */
|
|
82
|
+
function tryReload() {
|
|
83
|
+
if (!props.updateAvailable || !props.connected) return;
|
|
84
|
+
if (busy()) {
|
|
85
|
+
deferred.value = true;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
emit("reload");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
watch(
|
|
92
|
+
() => props.connected,
|
|
93
|
+
(connected, before) => {
|
|
94
|
+
if (tick) clearInterval(tick);
|
|
95
|
+
tick = undefined;
|
|
96
|
+
if (!connected) {
|
|
97
|
+
now.value = Date.now();
|
|
98
|
+
downSince = props.disconnectedAt || Date.now();
|
|
99
|
+
tick = setInterval(() => (now.value = Date.now()), 1_000);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// 只有真正提示过(标签或弹窗)才显示「已恢复」,短暂抖动不打扰。
|
|
103
|
+
const shown =
|
|
104
|
+
restartSeen ||
|
|
105
|
+
(downSince > 0 && Date.now() - downSince >= BADGE_AFTER_MS);
|
|
106
|
+
downSince = 0;
|
|
107
|
+
restartSeen = false;
|
|
108
|
+
if (before === false && shown) {
|
|
109
|
+
recovered.value = true;
|
|
110
|
+
if (recoveredTimer) clearTimeout(recoveredTimer);
|
|
111
|
+
recoveredTimer = setTimeout(() => (recovered.value = false), 2_000);
|
|
112
|
+
}
|
|
113
|
+
tryReload();
|
|
114
|
+
},
|
|
115
|
+
{ immediate: true },
|
|
116
|
+
);
|
|
117
|
+
watch(() => props.updateAvailable, tryReload);
|
|
118
|
+
watch(
|
|
119
|
+
() => props.restarting,
|
|
120
|
+
(value) => {
|
|
121
|
+
if (value && !props.connected) restartSeen = true;
|
|
122
|
+
},
|
|
123
|
+
{ immediate: true },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
onBeforeUnmount(() => {
|
|
127
|
+
if (tick) clearInterval(tick);
|
|
128
|
+
if (recoveredTimer) clearTimeout(recoveredTimer);
|
|
129
|
+
});
|
|
130
|
+
</script>
|
|
131
|
+
|
|
132
|
+
<template>
|
|
133
|
+
<span
|
|
134
|
+
v-if="badge && badgeText"
|
|
135
|
+
class="ys-service-status__badge"
|
|
136
|
+
:class="{ 'is-recovered': connected }"
|
|
137
|
+
role="status"
|
|
138
|
+
aria-live="polite"
|
|
139
|
+
>
|
|
140
|
+
<span class="ys-service-status__dot" />{{ badgeText }}
|
|
141
|
+
</span>
|
|
142
|
+
|
|
143
|
+
<el-dialog
|
|
144
|
+
:model-value="showDialog"
|
|
145
|
+
:show-close="false"
|
|
146
|
+
:close-on-click-modal="false"
|
|
147
|
+
:close-on-press-escape="false"
|
|
148
|
+
width="420px"
|
|
149
|
+
align-center
|
|
150
|
+
append-to-body
|
|
151
|
+
modal-class="ys-service-status__dialog-overlay"
|
|
152
|
+
class="ys-service-status__dialog"
|
|
153
|
+
>
|
|
154
|
+
<div class="ys-service-status__body">
|
|
155
|
+
<el-icon class="is-loading ys-service-status__spinner" :size="28"
|
|
156
|
+
><Loading
|
|
157
|
+
/></el-icon>
|
|
158
|
+
<h3 class="ys-service-status__title">
|
|
159
|
+
{{ restarting ? "系统正在更新" : "暂时连不上服务" }}
|
|
160
|
+
</h3>
|
|
161
|
+
<p class="ys-service-status__text">
|
|
162
|
+
{{
|
|
163
|
+
restarting
|
|
164
|
+
? "新版本正在部署,通常 1 分钟内完成。页面和填写中的内容都会保留,恢复后自动继续,无需刷新。"
|
|
165
|
+
: "可能是网络中断或服务正在重启。页面和填写中的内容都会保留,恢复连接后自动继续。"
|
|
166
|
+
}}
|
|
167
|
+
</p>
|
|
168
|
+
<p class="ys-service-status__elapsed">
|
|
169
|
+
已等待 {{ seconds }} 秒,正在自动重连…
|
|
170
|
+
</p>
|
|
171
|
+
<p v-if="manualRefresh" class="ys-service-status__hint">
|
|
172
|
+
如果一直没有恢复,可以刷新页面重试;未保存的内容会丢失。
|
|
173
|
+
</p>
|
|
174
|
+
</div>
|
|
175
|
+
<template #footer>
|
|
176
|
+
<el-button v-if="manualRefresh" @click="emit('reload')"
|
|
177
|
+
>刷新页面</el-button
|
|
178
|
+
>
|
|
179
|
+
<el-button type="primary" @click="emit('retry')">立即重试</el-button>
|
|
180
|
+
</template>
|
|
181
|
+
</el-dialog>
|
|
182
|
+
|
|
183
|
+
<Teleport to="body">
|
|
184
|
+
<div
|
|
185
|
+
v-if="deferred && updateAvailable"
|
|
186
|
+
class="ys-service-status__update"
|
|
187
|
+
role="status"
|
|
188
|
+
>
|
|
189
|
+
<span>系统已更新到新版本。保存当前内容后,切换页面时会自动更新。</span>
|
|
190
|
+
<el-button type="primary" link @click="emit('reload')"
|
|
191
|
+
>立即刷新</el-button
|
|
192
|
+
>
|
|
193
|
+
</div>
|
|
194
|
+
</Teleport>
|
|
195
|
+
</template>
|
|
196
|
+
|
|
197
|
+
<style scoped>
|
|
198
|
+
.ys-service-status__badge {
|
|
199
|
+
display: inline-flex;
|
|
200
|
+
align-items: center;
|
|
201
|
+
gap: 6px;
|
|
202
|
+
margin-right: 12px;
|
|
203
|
+
padding: 0 10px;
|
|
204
|
+
border-radius: 10px;
|
|
205
|
+
background: color-mix(in srgb, var(--ys-color-warning) 14%, transparent);
|
|
206
|
+
color: var(--ys-color-warning);
|
|
207
|
+
font-size: 12px;
|
|
208
|
+
line-height: 22px;
|
|
209
|
+
white-space: nowrap;
|
|
210
|
+
}
|
|
211
|
+
.ys-service-status__badge.is-recovered {
|
|
212
|
+
background: color-mix(in srgb, var(--ys-color-success) 14%, transparent);
|
|
213
|
+
color: var(--ys-color-success);
|
|
214
|
+
}
|
|
215
|
+
.ys-service-status__dot {
|
|
216
|
+
width: 6px;
|
|
217
|
+
height: 6px;
|
|
218
|
+
border-radius: 50%;
|
|
219
|
+
background: currentColor;
|
|
220
|
+
animation: ys-service-pulse 1.2s ease-in-out infinite;
|
|
221
|
+
}
|
|
222
|
+
.ys-service-status__badge.is-recovered .ys-service-status__dot {
|
|
223
|
+
animation: none;
|
|
224
|
+
}
|
|
225
|
+
@keyframes ys-service-pulse {
|
|
226
|
+
50% {
|
|
227
|
+
opacity: 0.3;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
.ys-service-status__body {
|
|
231
|
+
display: grid;
|
|
232
|
+
justify-items: center;
|
|
233
|
+
gap: 8px;
|
|
234
|
+
text-align: center;
|
|
235
|
+
}
|
|
236
|
+
.ys-service-status__spinner {
|
|
237
|
+
color: var(--ys-color-primary);
|
|
238
|
+
}
|
|
239
|
+
.ys-service-status__title {
|
|
240
|
+
margin: 4px 0 0;
|
|
241
|
+
color: var(--ys-color-text-1);
|
|
242
|
+
font-size: 16px;
|
|
243
|
+
font-weight: 600;
|
|
244
|
+
}
|
|
245
|
+
.ys-service-status__text,
|
|
246
|
+
.ys-service-status__elapsed,
|
|
247
|
+
.ys-service-status__hint {
|
|
248
|
+
margin: 0;
|
|
249
|
+
color: var(--ys-color-text-2);
|
|
250
|
+
line-height: 1.7;
|
|
251
|
+
}
|
|
252
|
+
.ys-service-status__elapsed {
|
|
253
|
+
color: var(--ys-color-text-3);
|
|
254
|
+
font-size: 12px;
|
|
255
|
+
}
|
|
256
|
+
.ys-service-status__hint {
|
|
257
|
+
color: var(--ys-color-warning);
|
|
258
|
+
font-size: 12px;
|
|
259
|
+
}
|
|
260
|
+
.ys-service-status__update {
|
|
261
|
+
position: fixed;
|
|
262
|
+
z-index: 3000;
|
|
263
|
+
top: 62px;
|
|
264
|
+
left: 50%;
|
|
265
|
+
display: flex;
|
|
266
|
+
align-items: center;
|
|
267
|
+
gap: 12px;
|
|
268
|
+
padding: 6px 8px 6px 14px;
|
|
269
|
+
border: 1px solid
|
|
270
|
+
color-mix(in srgb, var(--ys-color-primary) 30%, var(--ys-color-border));
|
|
271
|
+
border-radius: var(--ys-radius-m);
|
|
272
|
+
background: var(--ys-color-bg-elevated);
|
|
273
|
+
box-shadow: 0 6px 18px color-mix(in srgb, #0f172a 12%, transparent);
|
|
274
|
+
color: var(--ys-color-text-1);
|
|
275
|
+
font-size: 13px;
|
|
276
|
+
transform: translateX(-50%);
|
|
277
|
+
white-space: nowrap;
|
|
278
|
+
}
|
|
279
|
+
@media (prefers-reduced-motion: reduce) {
|
|
280
|
+
.ys-service-status__dot {
|
|
281
|
+
animation: none;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
</style>
|
|
@@ -134,8 +134,11 @@ const emit = defineEmits<{ navigate: [key: string]; toggle: [key: string] }>();
|
|
|
134
134
|
color: var(--ys-color-text-2);
|
|
135
135
|
text-align: left;
|
|
136
136
|
}
|
|
137
|
+
/* 名称占满剩余宽度、左对齐;有数量时角标贴右。不能用 space-between,否则二级菜单没有角标时名称会被推到右边。 */
|
|
137
138
|
.ys-side-menu__label {
|
|
139
|
+
flex: 1;
|
|
138
140
|
min-width: 0;
|
|
141
|
+
text-align: left;
|
|
139
142
|
overflow: hidden;
|
|
140
143
|
text-overflow: ellipsis;
|
|
141
144
|
white-space: nowrap;
|
|
@@ -202,7 +205,6 @@ const emit = defineEmits<{ navigate: [key: string]; toggle: [key: string] }>();
|
|
|
202
205
|
.ys-side-menu__child {
|
|
203
206
|
display: flex;
|
|
204
207
|
align-items: center;
|
|
205
|
-
justify-content: space-between;
|
|
206
208
|
gap: 8px;
|
|
207
209
|
width: 100%;
|
|
208
210
|
padding: 7px 12px 7px 8px;
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type {
|
|
|
15
15
|
} from "./components/YsSideMenu.vue";
|
|
16
16
|
export { default as YsPageHeader } from "./components/YsPageHeader.vue";
|
|
17
17
|
export { default as YsLoginPage } from "./components/YsLoginPage.vue";
|
|
18
|
+
export { default as YsServiceStatus } from "./components/YsServiceStatus.vue";
|
|
18
19
|
export { default as YsSettingsCenterDialog } from "./components/YsSettingsCenterDialog.vue";
|
|
19
20
|
export { default as YsPortalGrid } from "./components/YsPortalGrid.vue";
|
|
20
21
|
export { default as YsRoleTag } from "./components/YsRoleTag.vue";
|