@ysgroup/ui 0.1.35 → 0.1.36

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.36",
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>
@@ -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
  }