@ysgroup/ui 0.1.35 → 0.1.37

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgroup/ui",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,16 +1,29 @@
1
1
  <!-- YsLoginPage —— 统一登录页。口令由 @ysgroup/core 密封后提交。 -->
2
2
  <script setup lang="ts">
3
3
  import { ref } from "vue";
4
- import { Loading } from "@element-plus/icons-vue";
4
+ import { Loading, Moon, Sunny } from "@element-plus/icons-vue";
5
+ import { applyTheme, type ThemeMode } from "@ysgroup/theme";
5
6
 
6
- const props = defineProps<{
7
- appTitle: string;
8
- hint?: string;
9
- logoUrl?: string;
10
- error?: string;
11
- loading?: boolean;
12
- restoring?: boolean;
13
- }>();
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ appTitle: string;
10
+ hint?: string;
11
+ logoUrl?: string;
12
+ error?: string;
13
+ loading?: boolean;
14
+ restoring?: boolean;
15
+ /** 右上角亮色/暗色切换,默认显示。登录前选好的模式登录后沿用。 */
16
+ themeSwitch?: boolean;
17
+ }>(),
18
+ {
19
+ hint: "",
20
+ logoUrl: "",
21
+ error: "",
22
+ loading: false,
23
+ restoring: false,
24
+ themeSwitch: true,
25
+ },
26
+ );
14
27
  const emit = defineEmits<{
15
28
  login: [username: string, password: string];
16
29
  }>();
@@ -18,6 +31,23 @@ const emit = defineEmits<{
18
31
  const username = ref("");
19
32
  const password = ref("");
20
33
  const validationError = ref("");
34
+ const mode = ref<ThemeMode>(
35
+ document.documentElement.getAttribute("data-theme") === "dark"
36
+ ? "dark"
37
+ : "light",
38
+ );
39
+ const themeMenu = ref<{ handleClose: () => void } | null>(null);
40
+
41
+ function selectTheme(next: ThemeMode) {
42
+ if (next !== "light" && next !== "dark") return;
43
+ mode.value = next;
44
+ applyTheme(next);
45
+ }
46
+
47
+ function toggleTheme() {
48
+ themeMenu.value?.handleClose();
49
+ selectTheme(mode.value === "dark" ? "light" : "dark");
50
+ }
21
51
 
22
52
  function submit() {
23
53
  if (props.loading || props.restoring) return;
@@ -33,25 +63,97 @@ function submit() {
33
63
 
34
64
  <template>
35
65
  <div class="ys-login">
66
+ <!-- 与登录后顶栏换肤按钮同一位置、外观和交互:悬停出菜单,直接点击切换并关闭菜单。 -->
67
+ <div v-if="themeSwitch" class="ys-login__theme">
68
+ <el-dropdown
69
+ ref="themeMenu"
70
+ trigger="hover"
71
+ popper-class="ys-app-theme-menu"
72
+ @command="selectTheme"
73
+ >
74
+ <button
75
+ type="button"
76
+ class="ys-login__theme-button"
77
+ :aria-label="mode === 'dark' ? '切换到亮色模式' : '切换到暗色模式'"
78
+ @click="toggleTheme"
79
+ >
80
+ <el-icon :size="18"
81
+ ><Sunny v-if="mode === 'light'" /><Moon v-else
82
+ /></el-icon>
83
+ </button>
84
+ <template #dropdown>
85
+ <el-dropdown-menu>
86
+ <el-dropdown-item
87
+ command="light"
88
+ :class="{ 'is-current': mode === 'light' }"
89
+ >亮色模式</el-dropdown-item
90
+ >
91
+ <el-dropdown-item
92
+ command="dark"
93
+ divided
94
+ :class="{ 'is-current': mode === 'dark' }"
95
+ >暗色模式</el-dropdown-item
96
+ >
97
+ </el-dropdown-menu>
98
+ </template>
99
+ </el-dropdown>
100
+ </div>
36
101
  <div class="ys-login__card">
37
- <span class="ys-login__ambient" aria-hidden="true"></span>
38
102
  <img v-if="logoUrl" :src="logoUrl" class="ys-login__logo" alt="logo" />
39
103
  <p v-if="hint" class="ys-login__hint">{{ hint }}</p>
40
104
  <h2 v-else class="ys-login__title">{{ appTitle }}</h2>
41
- <div v-if="restoring" class="ys-login__pending" role="status" aria-live="polite" aria-busy="true">
105
+ <div
106
+ v-if="restoring"
107
+ class="ys-login__pending"
108
+ role="status"
109
+ aria-live="polite"
110
+ aria-busy="true"
111
+ >
42
112
  <el-icon class="is-loading" :size="20"><Loading /></el-icon>
43
113
  <span>正在安全进入{{ appTitle }}</span>
44
114
  </div>
45
115
  <template v-else>
46
- <el-form :disabled="loading" :aria-busy="!!loading" @submit.prevent="submit">
116
+ <el-form
117
+ :disabled="loading"
118
+ :aria-busy="!!loading"
119
+ @submit.prevent="submit"
120
+ >
47
121
  <el-form-item>
48
- <el-input v-model="username" placeholder="用户名" aria-label="用户名" autocomplete="username" size="large" />
122
+ <el-input
123
+ v-model="username"
124
+ placeholder="用户名"
125
+ aria-label="用户名"
126
+ autocomplete="username"
127
+ size="large"
128
+ />
49
129
  </el-form-item>
50
130
  <el-form-item>
51
- <el-input v-model="password" type="password" placeholder="密码" aria-label="密码" autocomplete="current-password" size="large" show-password />
131
+ <el-input
132
+ v-model="password"
133
+ type="password"
134
+ placeholder="密码"
135
+ aria-label="密码"
136
+ autocomplete="current-password"
137
+ size="large"
138
+ show-password
139
+ />
52
140
  </el-form-item>
53
- <el-alert v-if="validationError || error" :title="validationError || error || ''" type="error" :closable="false" show-icon />
54
- <el-button type="primary" size="large" native-type="submit" :loading="loading" class="ys-login__submit"> 登录 </el-button>
141
+ <el-alert
142
+ v-if="validationError || error"
143
+ :title="validationError || error || ''"
144
+ type="error"
145
+ :closable="false"
146
+ show-icon
147
+ />
148
+ <el-button
149
+ type="primary"
150
+ size="large"
151
+ native-type="submit"
152
+ :loading="loading"
153
+ class="ys-login__submit"
154
+ >
155
+ 登录
156
+ </el-button>
55
157
  </el-form>
56
158
  </template>
57
159
  </div>
@@ -81,6 +183,22 @@ function submit() {
81
183
  text-align: center;
82
184
  transform: translateY(clamp(-200px, calc(248px - 50dvh), 0px));
83
185
  }
186
+ /*
187
+ * 立体浮起 + 彩色光晕转圈呼吸:
188
+ * - 面板用多层投影(贴地细影 + 带一点主色的远影)和顶部一道高光,像一张悬浮的卡片。
189
+ * - 面板背后一层蓝、紫、粉、青的柔光,模糊后从四周透出约 16px,不画清晰的边框线;
190
+ * 颜色绕面板 10 秒转一圈,同时 6 秒一轮明暗呼吸。
191
+ * - 只改颜色角度和透明度,不位移、不缩放,光的范围固定,不会晕。
192
+ * 文字和表单不动;输入聚焦时暂停,减少动态效果时静止。
193
+ */
194
+ @property --ys-login-glow-angle {
195
+ syntax: "<angle>";
196
+ inherits: true;
197
+ initial-value: 0deg;
198
+ }
199
+ .ys-login__card {
200
+ animation: ys-login-glow-turn 10s linear infinite;
201
+ }
84
202
  .ys-login__card::after {
85
203
  content: "";
86
204
  position: absolute;
@@ -89,43 +207,82 @@ function submit() {
89
207
  border-radius: inherit;
90
208
  background: var(--ys-color-bg-elevated);
91
209
  box-shadow:
92
- 0 3px 8px rgba(0, 0, 0, 0.04),
93
- 0 14px 28px rgba(0, 0, 0, 0.12);
210
+ inset 0 1px 0 color-mix(in srgb, #fff 70%, transparent),
211
+ 0 1px 2px color-mix(in srgb, #0f172a 6%, transparent),
212
+ 0 8px 16px -6px color-mix(in srgb, #0f172a 10%, transparent),
213
+ 0 28px 48px -18px
214
+ color-mix(in srgb, var(--ys-color-primary) 26%, transparent);
94
215
  pointer-events: none;
95
216
  }
96
- .ys-login__card::before,
97
- .ys-login__ambient {
217
+ html[data-theme="dark"] .ys-login__card::after {
218
+ box-shadow:
219
+ inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent),
220
+ 0 1px 2px color-mix(in srgb, #000 30%, transparent),
221
+ 0 28px 48px -18px color-mix(in srgb, #000 60%, transparent);
222
+ }
223
+ .ys-login__card::before {
98
224
  content: "";
99
225
  position: absolute;
100
226
  z-index: -2;
101
- inset: 12px;
102
- border-radius: 24px;
227
+ inset: 0;
228
+ border-radius: calc(var(--ys-radius-m) + 2px);
103
229
  pointer-events: none;
104
- opacity: 0.32;
105
- animation: ys-login-breathe 7s ease-in-out infinite;
230
+ background: conic-gradient(
231
+ from var(--ys-login-glow-angle),
232
+ #4f8cff,
233
+ #8b6cff 25%,
234
+ #e07bd6 38%,
235
+ #3fc6e8 62%,
236
+ #6aa8ff 82%,
237
+ #4f8cff
238
+ );
239
+ filter: blur(16px);
240
+ opacity: 0.3;
241
+ animation: ys-login-glow-breathe 6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
106
242
  }
107
- .ys-login__card::before {
108
- box-shadow: -3px -3px 22px 8px color-mix(in srgb, #3478ff 26%, transparent);
109
- }
110
- .ys-login__ambient {
111
- box-shadow: 3px 6px 26px 10px color-mix(in srgb, #5294ff 22%, transparent);
112
- animation-delay: -3.5s;
113
- }
114
- .ys-login__card:focus-within::before,
115
- .ys-login__card:focus-within .ys-login__ambient {
243
+ .ys-login__card:focus-within,
244
+ .ys-login__card:focus-within::before {
116
245
  animation-play-state: paused;
117
246
  }
118
- @keyframes ys-login-breathe {
247
+ @keyframes ys-login-glow-turn {
248
+ to {
249
+ --ys-login-glow-angle: 360deg;
250
+ }
251
+ }
252
+ @keyframes ys-login-glow-breathe {
119
253
  0%,
120
254
  100% {
121
- opacity: 0.32;
122
- transform: scale(1);
255
+ opacity: 0.25;
123
256
  }
124
257
  50% {
125
- opacity: 0.8;
126
- transform: translateY(-1px) scale(1.012);
258
+ opacity: 0.65;
127
259
  }
128
260
  }
261
+ .ys-login__theme {
262
+ position: fixed;
263
+ z-index: 10;
264
+ top: 11px;
265
+ right: 16px;
266
+ }
267
+ .ys-login__theme-button {
268
+ display: inline-flex;
269
+ align-items: center;
270
+ justify-content: center;
271
+ width: 32px;
272
+ height: 32px;
273
+ padding: 0;
274
+ border: 0;
275
+ border-radius: var(--ys-radius-m);
276
+ background: transparent;
277
+ color: color-mix(in srgb, var(--ys-color-text-2) 62%, var(--ys-color-text-3));
278
+ cursor: pointer;
279
+ }
280
+ .ys-login__theme-button:hover,
281
+ .ys-login__theme-button:focus-visible {
282
+ outline: none;
283
+ background: var(--ys-color-bg-hover);
284
+ color: var(--ys-color-primary);
285
+ }
129
286
  .ys-login__logo {
130
287
  width: 68px;
131
288
  height: 68px;
@@ -167,10 +324,12 @@ function submit() {
167
324
  }
168
325
  }
169
326
  @media (prefers-reduced-motion: reduce) {
170
- .ys-login__card::before,
171
- .ys-login__ambient {
327
+ .ys-login__card,
328
+ .ys-login__card::before {
172
329
  animation: none;
173
- opacity: 0.32;
330
+ }
331
+ .ys-login__card::before {
332
+ opacity: 0.35;
174
333
  }
175
334
  }
176
335
  </style>
@@ -1,7 +1,6 @@
1
1
  <!-- YsPageLayout —— 统一布局骨架:顶栏(logo/app名/工具条) + 侧栏 + 内容。 -->
2
2
  <script setup lang="ts">
3
3
  import { computed, ref } from "vue";
4
- import { Fold, Expand } from "@element-plus/icons-vue";
5
4
 
6
5
  const props = withDefaults(
7
6
  defineProps<{
@@ -40,7 +39,11 @@ function toggleSidebar() {
40
39
  <template>
41
40
  <div class="ys-layout" :class="{ 'is-collapsed': collapsed }">
42
41
  <header class="ys-layout__top">
43
- <div class="ys-layout__brand">
42
+ <!-- 品牌在前、收起按钮在品牌列最右,收起侧栏后顶栏布局不变。
43
+ 顶栏右边有业务系统标签时,品牌列右侧补一条与侧栏同色的竖线把两块分开;没有标签时不画。 -->
44
+ <div class="ys-layout__brand" :class="{ 'has-sidebar': hasSidebar }">
45
+ <img v-if="logoUrl" :src="logoUrl" class="ys-layout__logo" alt="logo" />
46
+ <span class="ys-layout__title">{{ appTitle }}</span>
44
47
  <el-tooltip
45
48
  v-if="hasSidebar"
46
49
  :content="collapsed ? '展开导航栏' : '收起导航栏'"
@@ -54,14 +57,25 @@ function toggleSidebar() {
54
57
  :aria-expanded="!collapsed"
55
58
  @click="toggleSidebar"
56
59
  >
57
- <el-icon :size="18"
58
- ><Expand v-if="collapsed" /><Fold v-else
59
- /></el-icon>
60
+ <!-- 图标画的就是页面布局:展开时「上左右」,收起后「上下」。 -->
61
+ <svg
62
+ class="ys-layout__toggle-icon"
63
+ viewBox="0 0 24 24"
64
+ fill="none"
65
+ stroke="currentColor"
66
+ stroke-width="1.5"
67
+ stroke-linecap="round"
68
+ stroke-linejoin="round"
69
+ aria-hidden="true"
70
+ >
71
+ <rect x="3.5" y="4.5" width="17" height="15" rx="2.5" />
72
+ <path
73
+ :d="collapsed ? 'M3.5 9.5h17' : 'M3.5 9.5h17M9.5 9.5v10'"
74
+ />
75
+ </svg>
60
76
  </button>
61
77
  </span>
62
78
  </el-tooltip>
63
- <img v-if="logoUrl" :src="logoUrl" class="ys-layout__logo" alt="logo" />
64
- <span class="ys-layout__title">{{ appTitle }}</span>
65
79
  </div>
66
80
  <div class="ys-layout__switcher"><slot name="switcher" /></div>
67
81
  <div v-if="$slots.toolbar" class="ys-layout__toolbar">
@@ -126,20 +140,29 @@ function toggleSidebar() {
126
140
  .ys-layout__brand {
127
141
  display: flex;
128
142
  align-items: center;
129
- gap: 10px;
143
+ gap: 8px;
130
144
  box-sizing: border-box;
131
145
  width: 100%;
146
+ height: 100%;
132
147
  min-width: 0;
133
- padding-left: 16px;
148
+ padding: 0 8px 0 20px;
134
149
  overflow: hidden;
135
150
  }
151
+ /* 业务切换插槽里没有内容时(不属于业务系统分组,只渲染出注释节点):empty 成立,不画竖线。 */
152
+ .ys-layout__brand.has-sidebar:has(+ .ys-layout__switcher:not(:empty)) {
153
+ box-shadow: inset -1px 0 var(--ys-color-border);
154
+ }
136
155
  .ys-layout__logo {
137
- width: 30px;
138
- height: 26px;
156
+ flex: none;
157
+ width: 28px;
158
+ height: 28px;
139
159
  object-fit: contain;
140
160
  }
141
161
  .ys-layout__title {
162
+ min-width: 0;
163
+ font-size: 15px;
142
164
  font-weight: 600;
165
+ letter-spacing: 0.02em;
143
166
  color: var(--ys-color-text-1);
144
167
  white-space: nowrap;
145
168
  overflow: hidden;
@@ -147,30 +170,43 @@ function toggleSidebar() {
147
170
  }
148
171
  .ys-layout__toggle-wrap {
149
172
  display: inline-flex;
150
- flex: 0 0 30px;
173
+ flex: 0 0 32px;
174
+ margin-left: auto;
151
175
  }
152
176
  .ys-layout__toggle {
153
177
  display: inline-flex;
154
178
  align-items: center;
155
179
  justify-content: center;
156
- flex: 0 0 30px;
157
- height: 30px;
180
+ flex: 0 0 32px;
181
+ width: 32px;
182
+ height: 32px;
183
+ padding: 0;
158
184
  border: 0;
159
- border-radius: 6px;
185
+ border-radius: var(--ys-radius-m);
160
186
  background: transparent;
161
- color: var(--ys-color-text-2);
187
+ color: color-mix(in srgb, var(--ys-color-text-2) 62%, var(--ys-color-text-3));
162
188
  cursor: pointer;
163
189
  }
164
190
  .ys-layout__toggle:hover,
165
191
  .ys-layout__toggle:focus-visible {
192
+ outline: none;
166
193
  color: var(--ys-color-primary);
167
194
  background: var(--ys-color-bg-hover);
168
195
  }
196
+ .ys-layout__toggle-icon {
197
+ width: 18px;
198
+ height: 18px;
199
+ }
169
200
  .ys-layout__switcher {
170
201
  min-width: 0;
171
202
  height: 100%;
172
203
  display: flex;
173
204
  align-items: center;
205
+ box-sizing: border-box;
206
+ }
207
+ /* 与品牌列竖线留出和内容区一样的 16px,和线左边的收起按钮对称。 */
208
+ .ys-layout__switcher:not(:empty) {
209
+ padding-left: 16px;
174
210
  }
175
211
  .ys-layout__toolbar {
176
212
  flex: none;
@@ -8,6 +8,8 @@ const props = withDefaults(
8
8
  role?: string;
9
9
  label?: string;
10
10
  size?: "small" | "default" | "large";
11
+ /** 扩展角色的标签颜色(#RRGGBB)。内置角色颜色固定,传了也不用。 */
12
+ color?: string;
11
13
  }>(),
12
14
  {
13
15
  role: "Initiate",
@@ -19,13 +21,42 @@ const props = withDefaults(
19
21
  const roleCode = computed(() => props.role.trim() || "Initiate");
20
22
  const roleClass = computed(() => {
21
23
  const builtin = ["Root", "Admin", "Manager", "Editor", "Viewer", "Initiate"];
22
- return builtin.includes(roleCode.value) ? roleCode.value.toLowerCase() : "custom";
24
+ return builtin.includes(roleCode.value)
25
+ ? roleCode.value.toLowerCase()
26
+ : "custom";
23
27
  });
24
- const displayLabel = computed(() => props.label || enumLabel("UserRole" as never, roleCode.value) || roleCode.value);
28
+ /**
29
+ * 扩展角色与内置角色同一做法:浅色底、深色字、浅色边。暗色主题下也保持浅底,
30
+ * 所以底色和边框按白色调配,不能按当前主题背景调配,否则深字压在深底上看不清。
31
+ */
32
+ const customStyle = computed(() => {
33
+ if (
34
+ roleClass.value !== "custom" ||
35
+ !/^#[0-9a-fA-F]{6}$/.test(props.color ?? "")
36
+ )
37
+ return undefined;
38
+ return {
39
+ "--ys-role-text": props.color,
40
+ "--ys-role-border": `color-mix(in srgb, ${props.color} 42%, #fff)`,
41
+ "--ys-role-bg": `color-mix(in srgb, ${props.color} 8%, #fff)`,
42
+ };
43
+ });
44
+ const displayLabel = computed(
45
+ () =>
46
+ props.label ||
47
+ enumLabel("UserRole" as never, roleCode.value) ||
48
+ roleCode.value,
49
+ );
25
50
  </script>
26
51
 
27
52
  <template>
28
- <el-tag :size="size" class="ys-role-tag" :class="`ys-role-tag--${roleClass}`" effect="plain">
53
+ <el-tag
54
+ :size="size"
55
+ class="ys-role-tag"
56
+ :class="`ys-role-tag--${roleClass}`"
57
+ :style="customStyle"
58
+ effect="plain"
59
+ >
29
60
  {{ displayLabel }}
30
61
  </el-tag>
31
62
  </template>
@@ -0,0 +1,287 @@
1
+ <!--
2
+ YsServiceStatus —— 服务状态与无感升级。放在 YsPageLayout 的 #toolbar 最前面(登录页也可放一个)。
3
+ 状态由 @ysgroup/core 的 store 提供:connected、disconnectedAt、restarting、updateAvailable。
4
+
5
+ - 断开 3 秒内不提示;之后顶栏小标签「正在重新连接…」,服务端主动重启时立即显示「系统正在更新…」。
6
+ - 断开较久(重启 8 秒、其他 15 秒)弹出不可关闭的维护弹窗,说明情况和已等待时长,可立即重试;
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
+ const DIALOG_AFTER_RESTART_MS = 8_000;
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
+ () =>
51
+ !props.connected &&
52
+ elapsed.value >=
53
+ (props.restarting ? DIALOG_AFTER_RESTART_MS : DIALOG_AFTER_MS),
54
+ );
55
+ const badgeText = computed(() => {
56
+ if (props.connected) return recovered.value ? "已恢复" : "";
57
+ if (props.restarting) return "系统正在更新…";
58
+ return elapsed.value >= BADGE_AFTER_MS ? "正在重新连接…" : "";
59
+ });
60
+ const seconds = computed(() => Math.floor(elapsed.value / 1000));
61
+ const manualRefresh = computed(() => elapsed.value >= MANUAL_REFRESH_AFTER_MS);
62
+
63
+ function defaultBusy(): boolean {
64
+ if (typeof document === "undefined") return false;
65
+ const overlays = document.querySelectorAll<HTMLElement>(
66
+ ".el-overlay, .el-message-box__wrapper, .el-drawer__wrapper",
67
+ );
68
+ for (const overlay of overlays) {
69
+ if (overlay.closest(".ys-service-status__dialog-overlay")) continue;
70
+ if (getComputedStyle(overlay).display !== "none") return true;
71
+ }
72
+ const active = document.activeElement as HTMLElement | null;
73
+ if (!active) return false;
74
+ return (
75
+ active.isContentEditable ||
76
+ ["INPUT", "TEXTAREA", "SELECT"].includes(active.tagName)
77
+ );
78
+ }
79
+
80
+ function busy(): boolean {
81
+ return (props.isBusy ?? defaultBusy)();
82
+ }
83
+
84
+ /** 有新版本且连接正常时:不打扰用户就直接重载,否则提示,下次切换页面或用户点击时再重载。 */
85
+ function tryReload() {
86
+ if (!props.updateAvailable || !props.connected) return;
87
+ if (busy()) {
88
+ deferred.value = true;
89
+ return;
90
+ }
91
+ emit("reload");
92
+ }
93
+
94
+ watch(
95
+ () => props.connected,
96
+ (connected, before) => {
97
+ if (tick) clearInterval(tick);
98
+ tick = undefined;
99
+ if (!connected) {
100
+ now.value = Date.now();
101
+ downSince = props.disconnectedAt || Date.now();
102
+ tick = setInterval(() => (now.value = Date.now()), 1_000);
103
+ return;
104
+ }
105
+ // 只有真正提示过(标签或弹窗)才显示「已恢复」,短暂抖动不打扰。
106
+ const shown =
107
+ restartSeen ||
108
+ (downSince > 0 && Date.now() - downSince >= BADGE_AFTER_MS);
109
+ downSince = 0;
110
+ restartSeen = false;
111
+ if (before === false && shown) {
112
+ recovered.value = true;
113
+ if (recoveredTimer) clearTimeout(recoveredTimer);
114
+ recoveredTimer = setTimeout(() => (recovered.value = false), 2_000);
115
+ }
116
+ tryReload();
117
+ },
118
+ { immediate: true },
119
+ );
120
+ watch(() => props.updateAvailable, tryReload);
121
+ watch(
122
+ () => props.restarting,
123
+ (value) => {
124
+ if (value && !props.connected) restartSeen = true;
125
+ },
126
+ { immediate: true },
127
+ );
128
+
129
+ onBeforeUnmount(() => {
130
+ if (tick) clearInterval(tick);
131
+ if (recoveredTimer) clearTimeout(recoveredTimer);
132
+ });
133
+ </script>
134
+
135
+ <template>
136
+ <span
137
+ v-if="badge && badgeText"
138
+ class="ys-service-status__badge"
139
+ :class="{ 'is-recovered': connected }"
140
+ role="status"
141
+ aria-live="polite"
142
+ >
143
+ <span class="ys-service-status__dot" />{{ badgeText }}
144
+ </span>
145
+
146
+ <el-dialog
147
+ :model-value="showDialog"
148
+ :show-close="false"
149
+ :close-on-click-modal="false"
150
+ :close-on-press-escape="false"
151
+ width="420px"
152
+ align-center
153
+ append-to-body
154
+ modal-class="ys-service-status__dialog-overlay"
155
+ class="ys-service-status__dialog"
156
+ >
157
+ <div class="ys-service-status__body">
158
+ <el-icon class="is-loading ys-service-status__spinner" :size="28"
159
+ ><Loading
160
+ /></el-icon>
161
+ <h3 class="ys-service-status__title">
162
+ {{ restarting ? "系统正在更新" : "暂时连不上服务" }}
163
+ </h3>
164
+ <p class="ys-service-status__text">
165
+ {{
166
+ restarting
167
+ ? "新版本正在部署,通常 1 分钟内完成。页面和填写中的内容都会保留,恢复后自动继续,无需刷新。"
168
+ : "可能是网络中断或服务正在重启。页面和填写中的内容都会保留,恢复连接后自动继续。"
169
+ }}
170
+ </p>
171
+ <p class="ys-service-status__elapsed">
172
+ 已等待 {{ seconds }} 秒,正在自动重连…
173
+ </p>
174
+ <p v-if="manualRefresh" class="ys-service-status__hint">
175
+ 如果一直没有恢复,可以刷新页面重试;未保存的内容会丢失。
176
+ </p>
177
+ </div>
178
+ <template #footer>
179
+ <el-button v-if="manualRefresh" @click="emit('reload')"
180
+ >刷新页面</el-button
181
+ >
182
+ <el-button type="primary" @click="emit('retry')">立即重试</el-button>
183
+ </template>
184
+ </el-dialog>
185
+
186
+ <Teleport to="body">
187
+ <div
188
+ v-if="deferred && updateAvailable"
189
+ class="ys-service-status__update"
190
+ role="status"
191
+ >
192
+ <span>系统已更新到新版本。保存当前内容后,切换页面时会自动更新。</span>
193
+ <el-button type="primary" link @click="emit('reload')"
194
+ >立即刷新</el-button
195
+ >
196
+ </div>
197
+ </Teleport>
198
+ </template>
199
+
200
+ <style scoped>
201
+ .ys-service-status__badge {
202
+ display: inline-flex;
203
+ align-items: center;
204
+ gap: 6px;
205
+ margin-right: 12px;
206
+ padding: 0 10px;
207
+ border-radius: 10px;
208
+ background: color-mix(in srgb, var(--ys-color-warning) 14%, transparent);
209
+ color: var(--ys-color-warning);
210
+ font-size: 12px;
211
+ line-height: 22px;
212
+ white-space: nowrap;
213
+ }
214
+ .ys-service-status__badge.is-recovered {
215
+ background: color-mix(in srgb, var(--ys-color-success) 14%, transparent);
216
+ color: var(--ys-color-success);
217
+ }
218
+ .ys-service-status__dot {
219
+ width: 6px;
220
+ height: 6px;
221
+ border-radius: 50%;
222
+ background: currentColor;
223
+ animation: ys-service-pulse 1.2s ease-in-out infinite;
224
+ }
225
+ .ys-service-status__badge.is-recovered .ys-service-status__dot {
226
+ animation: none;
227
+ }
228
+ @keyframes ys-service-pulse {
229
+ 50% {
230
+ opacity: 0.3;
231
+ }
232
+ }
233
+ .ys-service-status__body {
234
+ display: grid;
235
+ justify-items: center;
236
+ gap: 8px;
237
+ text-align: center;
238
+ }
239
+ .ys-service-status__spinner {
240
+ color: var(--ys-color-primary);
241
+ }
242
+ .ys-service-status__title {
243
+ margin: 4px 0 0;
244
+ color: var(--ys-color-text-1);
245
+ font-size: 16px;
246
+ font-weight: 600;
247
+ }
248
+ .ys-service-status__text,
249
+ .ys-service-status__elapsed,
250
+ .ys-service-status__hint {
251
+ margin: 0;
252
+ color: var(--ys-color-text-2);
253
+ line-height: 1.7;
254
+ }
255
+ .ys-service-status__elapsed {
256
+ color: var(--ys-color-text-3);
257
+ font-size: 12px;
258
+ }
259
+ .ys-service-status__hint {
260
+ color: var(--ys-color-warning);
261
+ font-size: 12px;
262
+ }
263
+ .ys-service-status__update {
264
+ position: fixed;
265
+ z-index: 3000;
266
+ top: 62px;
267
+ left: 50%;
268
+ display: flex;
269
+ align-items: center;
270
+ gap: 12px;
271
+ padding: 6px 8px 6px 14px;
272
+ border: 1px solid
273
+ color-mix(in srgb, var(--ys-color-primary) 30%, var(--ys-color-border));
274
+ border-radius: var(--ys-radius-m);
275
+ background: var(--ys-color-bg-elevated);
276
+ box-shadow: 0 6px 18px color-mix(in srgb, #0f172a 12%, transparent);
277
+ color: var(--ys-color-text-1);
278
+ font-size: 13px;
279
+ transform: translateX(-50%);
280
+ white-space: nowrap;
281
+ }
282
+ @media (prefers-reduced-motion: reduce) {
283
+ .ys-service-status__dot {
284
+ animation: none;
285
+ }
286
+ }
287
+ </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;
@@ -11,7 +11,14 @@ const emit = defineEmits<{
11
11
 
12
12
  <template>
13
13
  <div class="ys-table-toolbar">
14
- <el-input :model-value="keyword" :placeholder="placeholder || '搜索'" clearable class="ys-table-toolbar__search" @update:model-value="emit('update:keyword', String($event))" />
14
+ <el-input
15
+ :model-value="keyword"
16
+ :placeholder="placeholder || '搜索'"
17
+ clearable
18
+ class="ys-table-toolbar__search"
19
+ @update:model-value="emit('update:keyword', String($event))"
20
+ />
21
+ <!-- 检索区从左到右固定为:搜索框 → 下拉框 → 复选框;主操作放 #actions 在最右。 -->
15
22
  <slot />
16
23
  <div class="ys-table-toolbar__spacer" />
17
24
  <slot name="actions" />
@@ -29,6 +36,10 @@ const emit = defineEmits<{
29
36
  .ys-table-toolbar__search {
30
37
  width: 200px;
31
38
  }
39
+ /* 复选框之间不留 Element Plus 默认的 30px 右边距,间距统一由 gap 控制。 */
40
+ .ys-table-toolbar :deep(.el-checkbox) {
41
+ margin-right: 0;
42
+ }
32
43
  .ys-table-toolbar__spacer {
33
44
  flex: 1;
34
45
  }
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";